super.h 29.0 KB
Newer Older
S
Sage Weil 已提交
1 2 3
#ifndef _FS_CEPH_SUPER_H
#define _FS_CEPH_SUPER_H

4
#include <linux/ceph/ceph_debug.h>
S
Sage Weil 已提交
5 6 7 8 9 10 11 12 13

#include <asm/unaligned.h>
#include <linux/backing-dev.h>
#include <linux/completion.h>
#include <linux/exportfs.h>
#include <linux/fs.h>
#include <linux/mempool.h>
#include <linux/pagemap.h>
#include <linux/wait.h>
14
#include <linux/writeback.h>
15
#include <linux/slab.h>
16
#include <linux/posix_acl.h>
S
Sage Weil 已提交
17

18
#include <linux/ceph/libceph.h>
S
Sage Weil 已提交
19

20 21 22 23
#ifdef CONFIG_CEPH_FSCACHE
#include <linux/fscache.h>
#endif

S
Sage Weil 已提交
24 25 26 27 28
/* f_type in struct statfs */
#define CEPH_SUPER_MAGIC 0x00c36400

/* large granularity for statfs utilization stats to facilitate
 * large volume sizes on 32-bit machines. */
S
Sage Weil 已提交
29
#define CEPH_BLOCK_SHIFT   22  /* 4 MB */
S
Sage Weil 已提交
30 31
#define CEPH_BLOCK         (1 << CEPH_BLOCK_SHIFT)

32 33 34
#define CEPH_MOUNT_OPT_DIRSTAT         (1<<4) /* `cat dirname` for stats */
#define CEPH_MOUNT_OPT_RBYTES          (1<<5) /* dir st_bytes = rbytes */
#define CEPH_MOUNT_OPT_NOASYNCREADDIR  (1<<7) /* no dcache readdir */
Y
Yehuda Sadeh 已提交
35
#define CEPH_MOUNT_OPT_INO32           (1<<8) /* 32 bit inos */
36
#define CEPH_MOUNT_OPT_DCACHE          (1<<9) /* use dcache for readdir etc */
37
#define CEPH_MOUNT_OPT_FSCACHE         (1<<10) /* use fscache */
38

39
#define CEPH_MOUNT_OPT_DEFAULT    (CEPH_MOUNT_OPT_RBYTES)
S
Sage Weil 已提交
40

41 42 43 44
#define ceph_set_mount_opt(fsc, opt) \
	(fsc)->mount_options->flags |= CEPH_MOUNT_OPT_##opt;
#define ceph_test_mount_opt(fsc, opt) \
	(!!((fsc)->mount_options->flags & CEPH_MOUNT_OPT_##opt))
S
Sage Weil 已提交
45

S
Sage Weil 已提交
46 47
#define CEPH_RSIZE_DEFAULT             0           /* max read size */
#define CEPH_RASIZE_DEFAULT            (8192*1024) /* readahead */
48 49 50
#define CEPH_MAX_READDIR_DEFAULT        1024
#define CEPH_MAX_READDIR_BYTES_DEFAULT  (512*1024)
#define CEPH_SNAPDIRNAME_DEFAULT        ".snap"
S
Sage Weil 已提交
51

52
struct ceph_mount_options {
53
	int flags;
54 55
	int sb_flags;

S
Sage Weil 已提交
56 57 58
	int wsize;            /* max write size */
	int rsize;            /* max read size */
	int rasize;           /* max readahead */
59 60 61
	int congestion_kb;    /* max writeback in flight */
	int caps_wanted_delay_min, caps_wanted_delay_max;
	int cap_release_safety;
62 63
	int max_readdir;       /* max readdir result (entires) */
	int max_readdir_bytes; /* max readdir result (bytes) */
S
Sage Weil 已提交
64

65 66 67 68
	/*
	 * everything above this point can be memcmp'd; everything below
	 * is handled in compare_mount_options()
	 */
S
Sage Weil 已提交
69

70 71
	char *snapdir_name;   /* default ".snap" */
};
S
Sage Weil 已提交
72

73
struct ceph_fs_client {
S
Sage Weil 已提交
74 75
	struct super_block *sb;

76 77
	struct ceph_mount_options *mount_options;
	struct ceph_client *client;
S
Sage Weil 已提交
78

79
	unsigned long mount_state;
80 81
	int min_caps;                  /* min caps i added */

82
	struct ceph_mds_client *mdsc;
S
Sage Weil 已提交
83 84 85 86 87 88

	/* writeback */
	mempool_t *wb_pagevec_pool;
	struct workqueue_struct *wb_wq;
	struct workqueue_struct *pg_inv_wq;
	struct workqueue_struct *trunc_wq;
Y
Yehuda Sadeh 已提交
89
	atomic_long_t writeback_count;
S
Sage Weil 已提交
90 91

	struct backing_dev_info backing_dev_info;
92 93

#ifdef CONFIG_DEBUG_FS
94
	struct dentry *debugfs_dentry_lru, *debugfs_caps;
Y
Yehuda Sadeh 已提交
95
	struct dentry *debugfs_congestion_kb;
S
Sage Weil 已提交
96
	struct dentry *debugfs_bdi;
97
	struct dentry *debugfs_mdsc, *debugfs_mdsmap;
J
John Spray 已提交
98
	struct dentry *debugfs_mds_sessions;
99
#endif
100 101 102 103 104

#ifdef CONFIG_CEPH_FSCACHE
	struct fscache_cookie *fscache;
	struct workqueue_struct *revalidate_wq;
#endif
S
Sage Weil 已提交
105 106
};

107

S
Sage Weil 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
/*
 * File i/o capability.  This tracks shared state with the metadata
 * server that allows us to cache or writeback attributes or to read
 * and write data.  For any given inode, we should have one or more
 * capabilities, one issued by each metadata server, and our
 * cumulative access is the OR of all issued capabilities.
 *
 * Each cap is referenced by the inode's i_caps rbtree and by per-mds
 * session capability lists.
 */
struct ceph_cap {
	struct ceph_inode_info *ci;
	struct rb_node ci_node;          /* per-ci cap tree */
	struct ceph_mds_session *session;
	struct list_head session_caps;   /* per-session caplist */
	int mds;
	u64 cap_id;       /* unique cap id (mds provided) */
	int issued;       /* latest, from the mds */
	int implemented;  /* implemented superset of issued (for revocation) */
	int mds_wanted;
128 129
	u32 seq, issue_seq, mseq;
	u32 cap_gen;      /* active/stale cycle */
S
Sage Weil 已提交
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
	unsigned long last_used;
	struct list_head caps_item;
};

#define CHECK_CAPS_NODELAY    1  /* do not delay any further */
#define CHECK_CAPS_AUTHONLY   2  /* only check auth cap */
#define CHECK_CAPS_FLUSH      4  /* flush any dirty caps */

/*
 * Snapped cap state that is pending flush to mds.  When a snapshot occurs,
 * we first complete any in-process sync writes and writeback any dirty
 * data before flushing the snapped state (tracked here) back to the MDS.
 */
struct ceph_cap_snap {
	atomic_t nref;
	struct ceph_inode_info *ci;
	struct list_head ci_item, flushing_item;

	u64 follows, flush_tid;
	int issued, dirty;
	struct ceph_snap_context *context;

A
Al Viro 已提交
152
	umode_t mode;
153 154
	kuid_t uid;
	kgid_t gid;
S
Sage Weil 已提交
155

156
	struct ceph_buffer *xattr_blob;
S
Sage Weil 已提交
157 158 159 160 161 162 163
	u64 xattr_version;

	u64 size;
	struct timespec mtime, atime, ctime;
	u64 time_warp_seq;
	int writing;   /* a sync write is still in progress */
	int dirty_pages;     /* dirty pages awaiting writeback */
Y
Yan, Zheng 已提交
164
	bool inline_data;
S
Sage Weil 已提交
165 166 167 168
};

static inline void ceph_put_cap_snap(struct ceph_cap_snap *capsnap)
{
169 170 171
	if (atomic_dec_and_test(&capsnap->nref)) {
		if (capsnap->xattr_blob)
			ceph_buffer_put(capsnap->xattr_blob);
S
Sage Weil 已提交
172
		kfree(capsnap);
173
	}
S
Sage Weil 已提交
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
}

/*
 * The frag tree describes how a directory is fragmented, potentially across
 * multiple metadata servers.  It is also used to indicate points where
 * metadata authority is delegated, and whether/where metadata is replicated.
 *
 * A _leaf_ frag will be present in the i_fragtree IFF there is
 * delegation info.  That is, if mds >= 0 || ndist > 0.
 */
#define CEPH_MAX_DIRFRAG_REP 4

struct ceph_inode_frag {
	struct rb_node node;

	/* fragtree state */
	u32 frag;
	int split_by;         /* i.e. 2^(split_by) children */

	/* delegation and replication info */
	int mds;              /* -1 if same authority as parent */
	int ndist;            /* >0 if replicated */
	int dist[CEPH_MAX_DIRFRAG_REP];
};

/*
 * We cache inode xattrs as an encoded blob until they are first used,
 * at which point we parse them into an rbtree.
 */
struct ceph_inode_xattr {
	struct rb_node node;

	const char *name;
	int name_len;
	const char *val;
	int val_len;
	int dirty;

	int should_free_name;
	int should_free_val;
};

216 217 218 219 220 221 222 223 224 225 226 227 228 229
/*
 * Ceph dentry state
 */
struct ceph_dentry_info {
	struct ceph_mds_session *lease_session;
	u32 lease_gen, lease_shared_gen;
	u32 lease_seq;
	unsigned long lease_renew_after, lease_renew_from;
	struct list_head lru;
	struct dentry *dentry;
	u64 time;
	u64 offset;
};

S
Sage Weil 已提交
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
struct ceph_inode_xattrs_info {
	/*
	 * (still encoded) xattr blob. we avoid the overhead of parsing
	 * this until someone actually calls getxattr, etc.
	 *
	 * blob->vec.iov_len == 4 implies there are no xattrs; blob ==
	 * NULL means we don't know.
	*/
	struct ceph_buffer *blob, *prealloc_blob;

	struct rb_root index;
	bool dirty;
	int count;
	int names_size;
	int vals_size;
	u64 version, index_version;
};

/*
 * Ceph inode.
 */
struct ceph_inode_info {
	struct ceph_vino i_vino;   /* ceph ino + snap */

254 255
	spinlock_t i_ceph_lock;

S
Sage Weil 已提交
256
	u64 i_version;
Y
Yan, Zheng 已提交
257
	u64 i_inline_version;
S
Sage Weil 已提交
258 259 260
	u32 i_time_warp_seq;

	unsigned i_ceph_flags;
261
	int i_ordered_count;
262 263
	atomic_t i_release_count;
	atomic_t i_complete_count;
S
Sage Weil 已提交
264

S
Sage Weil 已提交
265
	struct ceph_dir_layout i_dir_layout;
S
Sage Weil 已提交
266 267 268 269 270 271 272 273 274 275 276 277 278
	struct ceph_file_layout i_layout;
	char *i_symlink;

	/* for dirs */
	struct timespec i_rctime;
	u64 i_rbytes, i_rfiles, i_rsubdirs;
	u64 i_files, i_subdirs;

	struct rb_root i_fragtree;
	struct mutex i_fragtree_mutex;

	struct ceph_inode_xattrs_info i_xattrs;

279
	/* capabilities.  protected _both_ by i_ceph_lock and cap->session's
S
Sage Weil 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
	 * s_mutex. */
	struct rb_root i_caps;           /* cap list */
	struct ceph_cap *i_auth_cap;     /* authoritative cap, if any */
	unsigned i_dirty_caps, i_flushing_caps;     /* mask of dirtied fields */
	struct list_head i_dirty_item, i_flushing_item;
	u64 i_cap_flush_seq;
	/* we need to track cap writeback on a per-cap-bit basis, to allow
	 * overlapping, pipelined cap flushes to the mds.  we can probably
	 * reduce the tid to 8 bits if we're concerned about inode size. */
	u16 i_cap_flush_last_tid, i_cap_flush_tid[CEPH_CAP_BITS];
	wait_queue_head_t i_cap_wq;      /* threads waiting on a capability */
	unsigned long i_hold_caps_min; /* jiffies */
	unsigned long i_hold_caps_max; /* jiffies */
	struct list_head i_cap_delay_list;  /* for delayed cap release to mds */
	struct ceph_cap_reservation i_cap_migration_resv;
	struct list_head i_cap_snaps;   /* snapped state pending flush to mds */
296 297
	struct ceph_snap_context *i_head_snapc;  /* set if wr_buffer_head > 0 or
						    dirty|flushing caps */
S
Sage Weil 已提交
298 299 300 301
	unsigned i_snap_caps;           /* cap bits for snapped files */

	int i_nr_by_mode[CEPH_FILE_MODE_NUM];  /* open file counts */

Y
Yan, Zheng 已提交
302
	struct mutex i_truncate_mutex;
S
Sage Weil 已提交
303 304 305 306 307 308 309 310 311 312 313
	u32 i_truncate_seq;        /* last truncate to smaller size */
	u64 i_truncate_size;       /*  and the size we last truncated down to */
	int i_truncate_pending;    /*  still need to call vmtruncate */

	u64 i_max_size;            /* max file size authorized by mds */
	u64 i_reported_size; /* (max_)size reported to or requested of mds */
	u64 i_wanted_max_size;     /* offset we'd like to write too */
	u64 i_requested_max_size;  /* max_size we've requested */

	/* held references to caps */
	int i_pin_ref;
314
	int i_rd_ref, i_rdcache_ref, i_wr_ref, i_wb_ref;
S
Sage Weil 已提交
315 316
	int i_wrbuffer_ref, i_wrbuffer_ref_head;
	u32 i_shared_gen;       /* increment each time we get FILE_SHARED */
317
	u32 i_rdcache_gen;      /* incremented each time we get FILE_CACHE. */
S
Sage Weil 已提交
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
	u32 i_rdcache_revoking; /* RDCACHE gen to async invalidate, if any */

	struct list_head i_unsafe_writes; /* uncommitted sync writes */
	struct list_head i_unsafe_dirops; /* uncommitted mds dir ops */
	spinlock_t i_unsafe_lock;

	struct ceph_snap_realm *i_snap_realm; /* snap realm (if caps) */
	int i_snap_realm_counter; /* snap realm (if caps) */
	struct list_head i_snap_realm_item;
	struct list_head i_snap_flush_item;

	struct work_struct i_wb_work;  /* writeback work */
	struct work_struct i_pg_inv_work;  /* page invalidation work */

	struct work_struct i_vmtruncate_work;

334 335 336 337 338
#ifdef CONFIG_CEPH_FSCACHE
	struct fscache_cookie *fscache;
	u32 i_fscache_gen; /* sequence, for delayed fscache validate */
	struct work_struct i_revalidate_work;
#endif
S
Sage Weil 已提交
339 340 341 342 343
	struct inode vfs_inode; /* at end */
};

static inline struct ceph_inode_info *ceph_inode(struct inode *inode)
{
344
	return container_of(inode, struct ceph_inode_info, vfs_inode);
S
Sage Weil 已提交
345 346
}

Y
Yehuda Sadeh 已提交
347 348 349 350 351 352 353 354 355 356
static inline struct ceph_fs_client *ceph_inode_to_client(struct inode *inode)
{
	return (struct ceph_fs_client *)inode->i_sb->s_fs_info;
}

static inline struct ceph_fs_client *ceph_sb_to_client(struct super_block *sb)
{
	return (struct ceph_fs_client *)sb->s_fs_info;
}

357 358 359 360 361 362 363 364
static inline struct ceph_vino ceph_vino(struct inode *inode)
{
	return ceph_inode(inode)->i_vino;
}

/*
 * ino_t is <64 bits on many architectures, blech.
 *
Y
Yehuda Sadeh 已提交
365 366 367 368 369
 *               i_ino (kernel inode)   st_ino (userspace)
 * i386          32                     32
 * x86_64+ino32  64                     32
 * x86_64        64                     64
 */
A
Amon Ott 已提交
370
static inline u32 ceph_ino_to_ino32(__u64 vino)
Y
Yehuda Sadeh 已提交
371
{
A
Amon Ott 已提交
372 373
	u32 ino = vino & 0xffffffff;
	ino ^= vino >> 32;
Y
Yehuda Sadeh 已提交
374
	if (!ino)
375
		ino = 2;
Y
Yehuda Sadeh 已提交
376 377 378 379 380
	return ino;
}

/*
 * kernel i_ino value
381 382 383 384
 */
static inline ino_t ceph_vino_to_ino(struct ceph_vino vino)
{
#if BITS_PER_LONG == 32
A
Amon Ott 已提交
385 386 387
	return ceph_ino_to_ino32(vino.ino);
#else
	return (ino_t)vino.ino;
388 389 390
#endif
}

Y
Yehuda Sadeh 已提交
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
/*
 * user-visible ino (stat, filldir)
 */
#if BITS_PER_LONG == 32
static inline ino_t ceph_translate_ino(struct super_block *sb, ino_t ino)
{
	return ino;
}
#else
static inline ino_t ceph_translate_ino(struct super_block *sb, ino_t ino)
{
	if (ceph_test_mount_opt(ceph_sb_to_client(sb), INO32))
		ino = ceph_ino_to_ino32(ino);
	return ino;
}
#endif


409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
/* for printf-style formatting */
#define ceph_vinop(i) ceph_inode(i)->i_vino.ino, ceph_inode(i)->i_vino.snap

static inline u64 ceph_ino(struct inode *inode)
{
	return ceph_inode(inode)->i_vino.ino;
}
static inline u64 ceph_snap(struct inode *inode)
{
	return ceph_inode(inode)->i_vino.snap;
}

static inline int ceph_ino_compare(struct inode *inode, void *data)
{
	struct ceph_vino *pvino = (struct ceph_vino *)data;
	struct ceph_inode_info *ci = ceph_inode(inode);
	return ci->i_vino.ino == pvino->ino &&
		ci->i_vino.snap == pvino->snap;
}

static inline struct inode *ceph_find_inode(struct super_block *sb,
					    struct ceph_vino vino)
{
	ino_t t = ceph_vino_to_ino(vino);
	return ilookup5(sb, t, ceph_ino_compare, &vino);
}


/*
 * Ceph inode.
 */
440 441 442 443
#define CEPH_I_DIR_ORDERED	1  /* dentries in dir are ordered */
#define CEPH_I_NODELAY		4  /* do not delay cap release */
#define CEPH_I_FLUSH		8  /* do not delay flush of dirty metadata */
#define CEPH_I_NOFLUSH		16 /* do not flush dirty caps */
444

445
static inline void __ceph_dir_set_complete(struct ceph_inode_info *ci,
446
					   int release_count, int ordered_count)
S
Sage Weil 已提交
447
{
448
	atomic_set(&ci->i_complete_count, release_count);
449 450 451 452
	if (ci->i_ordered_count == ordered_count)
		ci->i_ceph_flags |= CEPH_I_DIR_ORDERED;
	else
		ci->i_ceph_flags &= ~CEPH_I_DIR_ORDERED;
S
Sage Weil 已提交
453 454
}

455
static inline void __ceph_dir_clear_complete(struct ceph_inode_info *ci)
S
Sage Weil 已提交
456
{
457 458
	atomic_inc(&ci->i_release_count);
}
S
Sage Weil 已提交
459

460 461 462 463
static inline bool __ceph_dir_is_complete(struct ceph_inode_info *ci)
{
	return atomic_read(&ci->i_complete_count) ==
		atomic_read(&ci->i_release_count);
S
Sage Weil 已提交
464 465
}

466 467 468 469 470 471
static inline bool __ceph_dir_is_complete_ordered(struct ceph_inode_info *ci)
{
	return __ceph_dir_is_complete(ci) &&
		(ci->i_ceph_flags & CEPH_I_DIR_ORDERED);
}

472
static inline void ceph_dir_clear_complete(struct inode *inode)
S
Sage Weil 已提交
473
{
474 475
	__ceph_dir_clear_complete(ceph_inode(inode));
}
S
Sage Weil 已提交
476

477
static inline void ceph_dir_clear_ordered(struct inode *inode)
478
{
479 480 481 482 483
	struct ceph_inode_info *ci = ceph_inode(inode);
	spin_lock(&ci->i_ceph_lock);
	ci->i_ordered_count++;
	ci->i_ceph_flags &= ~CEPH_I_DIR_ORDERED;
	spin_unlock(&ci->i_ceph_lock);
S
Sage Weil 已提交
484 485
}

486 487 488 489 490 491 492 493 494
static inline bool ceph_dir_is_complete_ordered(struct inode *inode)
{
	struct ceph_inode_info *ci = ceph_inode(inode);
	bool ret;
	spin_lock(&ci->i_ceph_lock);
	ret = __ceph_dir_is_complete_ordered(ci);
	spin_unlock(&ci->i_ceph_lock);
	return ret;
}
S
Sage Weil 已提交
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533

/* find a specific frag @f */
extern struct ceph_inode_frag *__ceph_find_frag(struct ceph_inode_info *ci,
						u32 f);

/*
 * choose fragment for value @v.  copy frag content to pfrag, if leaf
 * exists
 */
extern u32 ceph_choose_frag(struct ceph_inode_info *ci, u32 v,
			    struct ceph_inode_frag *pfrag,
			    int *found);

static inline struct ceph_dentry_info *ceph_dentry(struct dentry *dentry)
{
	return (struct ceph_dentry_info *)dentry->d_fsdata;
}

static inline loff_t ceph_make_fpos(unsigned frag, unsigned off)
{
	return ((loff_t)frag << 32) | (loff_t)off;
}

/*
 * caps helpers
 */
static inline bool __ceph_is_any_real_caps(struct ceph_inode_info *ci)
{
	return !RB_EMPTY_ROOT(&ci->i_caps);
}

extern int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented);
extern int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int t);
extern int __ceph_caps_issued_other(struct ceph_inode_info *ci,
				    struct ceph_cap *cap);

static inline int ceph_caps_issued(struct ceph_inode_info *ci)
{
	int issued;
534
	spin_lock(&ci->i_ceph_lock);
S
Sage Weil 已提交
535
	issued = __ceph_caps_issued(ci, NULL);
536
	spin_unlock(&ci->i_ceph_lock);
S
Sage Weil 已提交
537 538 539 540 541 542 543
	return issued;
}

static inline int ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask,
					int touch)
{
	int r;
544
	spin_lock(&ci->i_ceph_lock);
S
Sage Weil 已提交
545
	r = __ceph_caps_issued_mask(ci, mask, touch);
546
	spin_unlock(&ci->i_ceph_lock);
S
Sage Weil 已提交
547 548 549 550 551 552 553
	return r;
}

static inline int __ceph_caps_dirty(struct ceph_inode_info *ci)
{
	return ci->i_dirty_caps | ci->i_flushing_caps;
}
554
extern int __ceph_mark_dirty_caps(struct ceph_inode_info *ci, int mask);
S
Sage Weil 已提交
555

Y
Yan, Zheng 已提交
556 557
extern int __ceph_caps_revoking_other(struct ceph_inode_info *ci,
				      struct ceph_cap *ocap, int mask);
S
Sage Weil 已提交
558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576
extern int ceph_caps_revoking(struct ceph_inode_info *ci, int mask);
extern int __ceph_caps_used(struct ceph_inode_info *ci);

extern int __ceph_caps_file_wanted(struct ceph_inode_info *ci);

/*
 * wanted, by virtue of open file modes AND cap refs (buffered/cached data)
 */
static inline int __ceph_caps_wanted(struct ceph_inode_info *ci)
{
	int w = __ceph_caps_file_wanted(ci) | __ceph_caps_used(ci);
	if (w & CEPH_CAP_FILE_BUFFER)
		w |= CEPH_CAP_FILE_EXCL;  /* we want EXCL if dirty data */
	return w;
}

/* what the mds thinks we want */
extern int __ceph_caps_mds_wanted(struct ceph_inode_info *ci);

577 578 579
extern void ceph_caps_init(struct ceph_mds_client *mdsc);
extern void ceph_caps_finalize(struct ceph_mds_client *mdsc);
extern void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta);
580
extern void ceph_reserve_caps(struct ceph_mds_client *mdsc,
581 582 583
			     struct ceph_cap_reservation *ctx, int need);
extern int ceph_unreserve_caps(struct ceph_mds_client *mdsc,
			       struct ceph_cap_reservation *ctx);
584
extern void ceph_reservation_status(struct ceph_fs_client *client,
S
Sage Weil 已提交
585
				    int *total, int *avail, int *used,
586
				    int *reserved, int *min);
S
Sage Weil 已提交
587 588 589 590 591 592



/*
 * we keep buffered readdir results attached to file->private_data
 */
593
#define CEPH_F_SYNC     1
594
#define CEPH_F_ATEND    2
595

S
Sage Weil 已提交
596
struct ceph_file_info {
S
Sage Weil 已提交
597 598
	short fmode;     /* initialized on open */
	short flags;     /* CEPH_F_* */
S
Sage Weil 已提交
599 600 601 602 603 604 605

	/* readdir: position within the dir */
	u32 frag;
	struct ceph_mds_request *last_readdir;

	/* readdir: position within a frag */
	unsigned offset;       /* offset of last chunk, adjusted for . and .. */
Y
Yan, Zheng 已提交
606
	unsigned next_offset;  /* offset of next chunk (last_name's + 1) */
S
Sage Weil 已提交
607 608
	char *last_name;       /* last entry in previous chunk */
	struct dentry *dentry; /* next dentry (for dcache readdir) */
609
	int dir_release_count;
610
	int dir_ordered_count;
S
Sage Weil 已提交
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630

	/* used for -o dirstat read() on directory thing */
	char *dir_info;
	int dir_info_len;
};



/*
 * A "snap realm" describes a subset of the file hierarchy sharing
 * the same set of snapshots that apply to it.  The realms themselves
 * are organized into a hierarchy, such that children inherit (some of)
 * the snapshots of their parents.
 *
 * All inodes within the realm that have capabilities are linked into a
 * per-realm list.
 */
struct ceph_snap_realm {
	u64 ino;
	atomic_t nref;
S
Sage Weil 已提交
631 632
	struct rb_node node;

S
Sage Weil 已提交
633 634 635 636 637
	u64 created, seq;
	u64 parent_ino;
	u64 parent_since;   /* snapid when our current parent became so */

	u64 *prior_parent_snaps;      /* snaps inherited from any parents we */
638
	u32 num_prior_parent_snaps;   /*  had prior to parent_since */
S
Sage Weil 已提交
639
	u64 *snaps;                   /* snaps specific to this realm */
640
	u32 num_snaps;
S
Sage Weil 已提交
641 642 643 644 645 646 647

	struct ceph_snap_realm *parent;
	struct list_head children;       /* list of child realms */
	struct list_head child_item;

	struct list_head empty_item;     /* if i have ref==0 */

S
Sage Weil 已提交
648 649
	struct list_head dirty_item;     /* if realm needs new context */

S
Sage Weil 已提交
650 651 652 653 654 655 656
	/* the current set of snaps for this realm */
	struct ceph_snap_context *cached_context;

	struct list_head inodes_with_caps;
	spinlock_t inodes_with_caps_lock;
};

657
static inline int default_congestion_kb(void)
S
Sage Weil 已提交
658
{
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
	int congestion_kb;

	/*
	 * Copied from NFS
	 *
	 * congestion size, scale with available memory.
	 *
	 *  64MB:    8192k
	 * 128MB:   11585k
	 * 256MB:   16384k
	 * 512MB:   23170k
	 *   1GB:   32768k
	 *   2GB:   46340k
	 *   4GB:   65536k
	 *   8GB:   92681k
	 *  16GB:  131072k
	 *
	 * This allows larger machines to have larger/more transfers.
	 * Limit the default to 256M
	 */
	congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
	if (congestion_kb > 256*1024)
		congestion_kb = 256*1024;

	return congestion_kb;
S
Sage Weil 已提交
684 685 686 687 688 689 690 691 692 693 694 695
}



/* snap.c */
struct ceph_snap_realm *ceph_lookup_snap_realm(struct ceph_mds_client *mdsc,
					       u64 ino);
extern void ceph_get_snap_realm(struct ceph_mds_client *mdsc,
				struct ceph_snap_realm *realm);
extern void ceph_put_snap_realm(struct ceph_mds_client *mdsc,
				struct ceph_snap_realm *realm);
extern int ceph_update_snap_trace(struct ceph_mds_client *m,
696 697
				  void *p, void *e, bool deletion,
				  struct ceph_snap_realm **realm_ret);
S
Sage Weil 已提交
698
extern void ceph_handle_snap(struct ceph_mds_client *mdsc,
699
			     struct ceph_mds_session *session,
S
Sage Weil 已提交
700
			     struct ceph_msg *msg);
701
extern void ceph_queue_cap_snap(struct ceph_inode_info *ci);
S
Sage Weil 已提交
702 703 704
extern int __ceph_finish_cap_snap(struct ceph_inode_info *ci,
				  struct ceph_cap_snap *capsnap);
extern void ceph_cleanup_empty_realms(struct ceph_mds_client *mdsc);
705 706
extern int ceph_snap_init(void);
extern void ceph_snap_exit(void);
S
Sage Weil 已提交
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723

/*
 * a cap_snap is "pending" if it is still awaiting an in-progress
 * sync write (that may/may not still update size, mtime, etc.).
 */
static inline bool __ceph_have_pending_cap_snap(struct ceph_inode_info *ci)
{
	return !list_empty(&ci->i_cap_snaps) &&
		list_entry(ci->i_cap_snaps.prev, struct ceph_cap_snap,
			   ci_item)->writing;
}

/* inode.c */
extern const struct inode_operations ceph_file_iops;

extern struct inode *ceph_alloc_inode(struct super_block *sb);
extern void ceph_destroy_inode(struct inode *inode);
Y
Yan, Zheng 已提交
724
extern int ceph_drop_inode(struct inode *inode);
S
Sage Weil 已提交
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742

extern struct inode *ceph_get_inode(struct super_block *sb,
				    struct ceph_vino vino);
extern struct inode *ceph_get_snapdir(struct inode *parent);
extern int ceph_fill_file_size(struct inode *inode, int issued,
			       u32 truncate_seq, u64 truncate_size, u64 size);
extern void ceph_fill_file_time(struct inode *inode, int issued,
				u64 time_warp_seq, struct timespec *ctime,
				struct timespec *mtime, struct timespec *atime);
extern int ceph_fill_trace(struct super_block *sb,
			   struct ceph_mds_request *req,
			   struct ceph_mds_session *session);
extern int ceph_readdir_prepopulate(struct ceph_mds_request *req,
				    struct ceph_mds_session *session);

extern int ceph_inode_holds_cap(struct inode *inode, int mask);

extern int ceph_inode_set_size(struct inode *inode, loff_t size);
Y
Yan, Zheng 已提交
743
extern void __ceph_do_pending_vmtruncate(struct inode *inode);
744 745 746 747
extern void ceph_queue_vmtruncate(struct inode *inode);

extern void ceph_queue_invalidate(struct inode *inode);
extern void ceph_queue_writeback(struct inode *inode);
S
Sage Weil 已提交
748

749 750 751 752 753 754
extern int __ceph_do_getattr(struct inode *inode, struct page *locked_page,
			     int mask, bool force);
static inline int ceph_do_getattr(struct inode *inode, int mask, bool force)
{
	return __ceph_do_getattr(inode, NULL, mask, force);
}
755
extern int ceph_permission(struct inode *inode, int mask);
S
Sage Weil 已提交
756 757 758 759 760 761 762
extern int ceph_setattr(struct dentry *dentry, struct iattr *attr);
extern int ceph_getattr(struct vfsmount *mnt, struct dentry *dentry,
			struct kstat *stat);

/* xattr.c */
extern int ceph_setxattr(struct dentry *, const char *, const void *,
			 size_t, int);
G
Guangliang Zhao 已提交
763 764 765
int __ceph_setxattr(struct dentry *, const char *, const void *, size_t, int);
ssize_t __ceph_getxattr(struct inode *, const char *, void *, size_t);
int __ceph_removexattr(struct dentry *, const char *);
S
Sage Weil 已提交
766 767 768 769 770
extern ssize_t ceph_getxattr(struct dentry *, const char *, void *, size_t);
extern ssize_t ceph_listxattr(struct dentry *, char *, size_t);
extern int ceph_removexattr(struct dentry *, const char *);
extern void __ceph_build_xattrs_blob(struct ceph_inode_info *ci);
extern void __ceph_destroy_xattrs(struct ceph_inode_info *ci);
771 772
extern void __init ceph_xattr_init(void);
extern void ceph_xattr_exit(void);
773
extern const struct xattr_handler *ceph_xattr_handlers[];
S
Sage Weil 已提交
774

G
Guangliang Zhao 已提交
775
/* acl.c */
776 777 778 779 780
struct ceph_acls_info {
	void *default_acl;
	void *acl;
	struct ceph_pagelist *pagelist;
};
G
Guangliang Zhao 已提交
781 782 783 784

#ifdef CONFIG_CEPH_FS_POSIX_ACL

struct posix_acl *ceph_get_acl(struct inode *, int);
S
Sage Weil 已提交
785
int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type);
786 787 788 789
int ceph_pre_init_acls(struct inode *dir, umode_t *mode,
		       struct ceph_acls_info *info);
void ceph_init_inode_acls(struct inode *inode, struct ceph_acls_info *info);
void ceph_release_acls_info(struct ceph_acls_info *info);
790 791 792 793 794

static inline void ceph_forget_all_cached_acls(struct inode *inode)
{
       forget_all_cached_acls(inode);
}
G
Guangliang Zhao 已提交
795 796 797 798

#else

#define ceph_get_acl NULL
S
Sage Weil 已提交
799
#define ceph_set_acl NULL
G
Guangliang Zhao 已提交
800

801 802
static inline int ceph_pre_init_acls(struct inode *dir, umode_t *mode,
				     struct ceph_acls_info *info)
G
Guangliang Zhao 已提交
803 804 805
{
	return 0;
}
806 807 808 809 810 811 812
static inline void ceph_init_inode_acls(struct inode *inode,
					struct ceph_acls_info *info)
{
}
static inline void ceph_release_acls_info(struct ceph_acls_info *info)
{
}
G
Guangliang Zhao 已提交
813 814 815 816 817 818 819 820 821 822 823
static inline int ceph_acl_chmod(struct dentry *dentry, struct inode *inode)
{
	return 0;
}

static inline void ceph_forget_all_cached_acls(struct inode *inode)
{
}

#endif

S
Sage Weil 已提交
824 825 826 827
/* caps.c */
extern const char *ceph_cap_string(int c);
extern void ceph_handle_caps(struct ceph_mds_session *session,
			     struct ceph_msg *msg);
828 829 830 831 832 833 834
extern struct ceph_cap *ceph_get_cap(struct ceph_mds_client *mdsc,
				     struct ceph_cap_reservation *ctx);
extern void ceph_add_cap(struct inode *inode,
			 struct ceph_mds_session *session, u64 cap_id,
			 int fmode, unsigned issued, unsigned wanted,
			 unsigned cap, unsigned seq, u64 realmino, int flags,
			 struct ceph_cap **new_cap);
835
extern void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release);
836 837
extern void ceph_put_cap(struct ceph_mds_client *mdsc,
			 struct ceph_cap *cap);
838
extern int ceph_is_any_caps(struct inode *inode);
S
Sage Weil 已提交
839

840 841
extern void __queue_cap_release(struct ceph_mds_session *session, u64 ino,
				u64 cap_id, u32 migrate_seq, u32 issue_seq);
S
Sage Weil 已提交
842
extern void ceph_queue_caps_release(struct inode *inode);
843
extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc);
844 845
extern int ceph_fsync(struct file *file, loff_t start, loff_t end,
		      int datasync);
S
Sage Weil 已提交
846 847
extern void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc,
				    struct ceph_mds_session *session);
848 849
extern struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci,
					     int mds);
S
Sage Weil 已提交
850 851 852 853 854 855
extern int ceph_get_cap_mds(struct inode *inode);
extern void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps);
extern void ceph_put_cap_refs(struct ceph_inode_info *ci, int had);
extern void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr,
				       struct ceph_snap_context *snapc);
extern void __ceph_flush_snaps(struct ceph_inode_info *ci,
856 857
			       struct ceph_mds_session **psession,
			       int again);
S
Sage Weil 已提交
858 859
extern void ceph_check_caps(struct ceph_inode_info *ci, int flags,
			    struct ceph_mds_session *session);
860 861
extern void ceph_check_delayed_caps(struct ceph_mds_client *mdsc);
extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc);
S
Sage Weil 已提交
862 863 864 865 866 867 868

extern int ceph_encode_inode_release(void **p, struct inode *inode,
				     int mds, int drop, int unless, int force);
extern int ceph_encode_dentry_release(void **p, struct dentry *dn,
				      int mds, int drop, int unless);

extern int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
Y
Yan, Zheng 已提交
869
			 loff_t endoff, int *got, struct page **pinned_page);
S
Sage Weil 已提交
870 871 872 873 874 875 876 877 878 879 880 881 882 883 884

/* for counting open files by mode */
static inline void __ceph_get_fmode(struct ceph_inode_info *ci, int mode)
{
	ci->i_nr_by_mode[mode]++;
}
extern void ceph_put_fmode(struct ceph_inode_info *ci, int mode);

/* addr.c */
extern const struct address_space_operations ceph_aops;
extern int ceph_mmap(struct file *file, struct vm_area_struct *vma);

/* file.c */
extern const struct file_operations ceph_file_fops;
extern const struct address_space_operations ceph_aops;
885

S
Sage Weil 已提交
886
extern int ceph_open(struct inode *inode, struct file *file);
S
Sage Weil 已提交
887 888 889
extern int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
			    struct file *file, unsigned flags, umode_t mode,
			    int *opened);
S
Sage Weil 已提交
890
extern int ceph_release(struct inode *inode, struct file *filp);
Y
Yan, Zheng 已提交
891 892
extern void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
				  char *data, size_t len);
893
int ceph_uninline_data(struct file *filp, struct page *locked_page);
S
Sage Weil 已提交
894 895
/* dir.c */
extern const struct file_operations ceph_dir_fops;
896
extern const struct file_operations ceph_snapdir_fops;
S
Sage Weil 已提交
897
extern const struct inode_operations ceph_dir_iops;
898
extern const struct inode_operations ceph_snapdir_iops;
S
Sage Weil 已提交
899
extern const struct dentry_operations ceph_dentry_ops, ceph_snap_dentry_ops,
S
Sage Weil 已提交
900 901 902
	ceph_snapdir_dentry_ops;

extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry);
903 904
extern int ceph_handle_snapdir(struct ceph_mds_request *req,
			       struct dentry *dentry, int err);
S
Sage Weil 已提交
905 906 907 908 909 910
extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
					 struct dentry *dentry, int err);

extern void ceph_dentry_lru_add(struct dentry *dn);
extern void ceph_dentry_lru_touch(struct dentry *dn);
extern void ceph_dentry_lru_del(struct dentry *dn);
911
extern void ceph_invalidate_dentry_lease(struct dentry *dentry);
912
extern unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn);
S
Sage Weil 已提交
913
extern struct inode *ceph_get_dentry_parent_inode(struct dentry *dentry);
S
Sage Weil 已提交
914 915 916 917 918 919 920 921 922 923 924 925 926 927

/*
 * our d_ops vary depending on whether the inode is live,
 * snapshotted (read-only), or a virtual ".snap" directory.
 */
int ceph_init_dentry(struct dentry *dentry);


/* ioctl.c */
extern long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg);

/* export.c */
extern const struct export_operations ceph_export_ops;

G
Greg Farnum 已提交
928
/* locks.c */
929
extern __init void ceph_flock_init(void);
G
Greg Farnum 已提交
930 931 932
extern int ceph_lock(struct file *file, int cmd, struct file_lock *fl);
extern int ceph_flock(struct file *file, int cmd, struct file_lock *fl);
extern void ceph_count_locks(struct inode *inode, int *p_num, int *f_num);
933 934 935 936 937 938 939
extern int ceph_encode_locks_to_buffer(struct inode *inode,
				       struct ceph_filelock *flocks,
				       int num_fcntl_locks,
				       int num_flock_locks);
extern int ceph_locks_to_pagelist(struct ceph_filelock *flocks,
				  struct ceph_pagelist *pagelist,
				  int num_fcntl_locks, int num_flock_locks);
G
Greg Farnum 已提交
940 941
extern int lock_to_ceph_filelock(struct file_lock *fl, struct ceph_filelock *c);

942 943 944 945
/* debugfs.c */
extern int ceph_fs_debugfs_init(struct ceph_fs_client *client);
extern void ceph_fs_debugfs_cleanup(struct ceph_fs_client *client);

S
Sage Weil 已提交
946
#endif /* _FS_CEPH_SUPER_H */