super.h 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _FS_CEPH_SUPER_H
  3. #define _FS_CEPH_SUPER_H
  4. #include <linux/ceph/ceph_debug.h>
  5. #include <asm/unaligned.h>
  6. #include <linux/backing-dev.h>
  7. #include <linux/completion.h>
  8. #include <linux/exportfs.h>
  9. #include <linux/fs.h>
  10. #include <linux/mempool.h>
  11. #include <linux/pagemap.h>
  12. #include <linux/wait.h>
  13. #include <linux/writeback.h>
  14. #include <linux/slab.h>
  15. #include <linux/posix_acl.h>
  16. #include <linux/refcount.h>
  17. #include <linux/ceph/libceph.h>
  18. #ifdef CONFIG_CEPH_FSCACHE
  19. #include <linux/fscache.h>
  20. #endif
  21. /* f_type in struct statfs */
  22. #define CEPH_SUPER_MAGIC 0x00c36400
  23. /* large granularity for statfs utilization stats to facilitate
  24. * large volume sizes on 32-bit machines. */
  25. #define CEPH_BLOCK_SHIFT 22 /* 4 MB */
  26. #define CEPH_BLOCK (1 << CEPH_BLOCK_SHIFT)
  27. #define CEPH_MOUNT_OPT_DIRSTAT (1<<4) /* `cat dirname` for stats */
  28. #define CEPH_MOUNT_OPT_RBYTES (1<<5) /* dir st_bytes = rbytes */
  29. #define CEPH_MOUNT_OPT_NOASYNCREADDIR (1<<7) /* no dcache readdir */
  30. #define CEPH_MOUNT_OPT_INO32 (1<<8) /* 32 bit inos */
  31. #define CEPH_MOUNT_OPT_DCACHE (1<<9) /* use dcache for readdir etc */
  32. #define CEPH_MOUNT_OPT_FSCACHE (1<<10) /* use fscache */
  33. #define CEPH_MOUNT_OPT_NOPOOLPERM (1<<11) /* no pool permission check */
  34. #define CEPH_MOUNT_OPT_MOUNTWAIT (1<<12) /* mount waits if no mds is up */
  35. #define CEPH_MOUNT_OPT_NOQUOTADF (1<<13) /* no root dir quota in statfs */
  36. #define CEPH_MOUNT_OPT_DEFAULT CEPH_MOUNT_OPT_DCACHE
  37. #define ceph_set_mount_opt(fsc, opt) \
  38. (fsc)->mount_options->flags |= CEPH_MOUNT_OPT_##opt;
  39. #define ceph_test_mount_opt(fsc, opt) \
  40. (!!((fsc)->mount_options->flags & CEPH_MOUNT_OPT_##opt))
  41. /* max size of osd read request, limited by libceph */
  42. #define CEPH_MAX_READ_SIZE CEPH_MSG_MAX_DATA_LEN
  43. /* osd has a configurable limitaion of max write size.
  44. * CEPH_MSG_MAX_DATA_LEN should be small enough. */
  45. #define CEPH_MAX_WRITE_SIZE CEPH_MSG_MAX_DATA_LEN
  46. #define CEPH_RASIZE_DEFAULT (8192*1024) /* max readahead */
  47. #define CEPH_MAX_READDIR_DEFAULT 1024
  48. #define CEPH_MAX_READDIR_BYTES_DEFAULT (512*1024)
  49. #define CEPH_SNAPDIRNAME_DEFAULT ".snap"
  50. /*
  51. * Delay telling the MDS we no longer want caps, in case we reopen
  52. * the file. Delay a minimum amount of time, even if we send a cap
  53. * message for some other reason. Otherwise, take the oppotunity to
  54. * update the mds to avoid sending another message later.
  55. */
  56. #define CEPH_CAPS_WANTED_DELAY_MIN_DEFAULT 5 /* cap release delay */
  57. #define CEPH_CAPS_WANTED_DELAY_MAX_DEFAULT 60 /* cap release delay */
  58. struct ceph_mount_options {
  59. int flags;
  60. int sb_flags;
  61. int wsize; /* max write size */
  62. int rsize; /* max read size */
  63. int rasize; /* max readahead */
  64. int congestion_kb; /* max writeback in flight */
  65. int caps_wanted_delay_min, caps_wanted_delay_max;
  66. int max_readdir; /* max readdir result (entires) */
  67. int max_readdir_bytes; /* max readdir result (bytes) */
  68. /*
  69. * everything above this point can be memcmp'd; everything below
  70. * is handled in compare_mount_options()
  71. */
  72. char *snapdir_name; /* default ".snap" */
  73. char *mds_namespace; /* default NULL */
  74. char *server_path; /* default "/" */
  75. char *fscache_uniq; /* default NULL */
  76. };
  77. struct ceph_fs_client {
  78. struct super_block *sb;
  79. struct ceph_mount_options *mount_options;
  80. struct ceph_client *client;
  81. unsigned long mount_state;
  82. int min_caps; /* min caps i added */
  83. struct ceph_mds_client *mdsc;
  84. /* writeback */
  85. mempool_t *wb_pagevec_pool;
  86. struct workqueue_struct *wb_wq;
  87. struct workqueue_struct *pg_inv_wq;
  88. struct workqueue_struct *trunc_wq;
  89. atomic_long_t writeback_count;
  90. #ifdef CONFIG_DEBUG_FS
  91. struct dentry *debugfs_dentry_lru, *debugfs_caps;
  92. struct dentry *debugfs_congestion_kb;
  93. struct dentry *debugfs_bdi;
  94. struct dentry *debugfs_mdsc, *debugfs_mdsmap;
  95. struct dentry *debugfs_mds_sessions;
  96. #endif
  97. #ifdef CONFIG_CEPH_FSCACHE
  98. struct fscache_cookie *fscache;
  99. #endif
  100. };
  101. /*
  102. * File i/o capability. This tracks shared state with the metadata
  103. * server that allows us to cache or writeback attributes or to read
  104. * and write data. For any given inode, we should have one or more
  105. * capabilities, one issued by each metadata server, and our
  106. * cumulative access is the OR of all issued capabilities.
  107. *
  108. * Each cap is referenced by the inode's i_caps rbtree and by per-mds
  109. * session capability lists.
  110. */
  111. struct ceph_cap {
  112. struct ceph_inode_info *ci;
  113. struct rb_node ci_node; /* per-ci cap tree */
  114. struct ceph_mds_session *session;
  115. struct list_head session_caps; /* per-session caplist */
  116. u64 cap_id; /* unique cap id (mds provided) */
  117. union {
  118. /* in-use caps */
  119. struct {
  120. int issued; /* latest, from the mds */
  121. int implemented; /* implemented superset of
  122. issued (for revocation) */
  123. int mds, mds_wanted;
  124. };
  125. /* caps to release */
  126. struct {
  127. u64 cap_ino;
  128. int queue_release;
  129. };
  130. };
  131. u32 seq, issue_seq, mseq;
  132. u32 cap_gen; /* active/stale cycle */
  133. unsigned long last_used;
  134. struct list_head caps_item;
  135. };
  136. #define CHECK_CAPS_NODELAY 1 /* do not delay any further */
  137. #define CHECK_CAPS_AUTHONLY 2 /* only check auth cap */
  138. #define CHECK_CAPS_FLUSH 4 /* flush any dirty caps */
  139. struct ceph_cap_flush {
  140. u64 tid;
  141. int caps; /* 0 means capsnap */
  142. bool wake; /* wake up flush waiters when finish ? */
  143. struct list_head g_list; // global
  144. struct list_head i_list; // per inode
  145. };
  146. /*
  147. * Snapped cap state that is pending flush to mds. When a snapshot occurs,
  148. * we first complete any in-process sync writes and writeback any dirty
  149. * data before flushing the snapped state (tracked here) back to the MDS.
  150. */
  151. struct ceph_cap_snap {
  152. refcount_t nref;
  153. struct list_head ci_item;
  154. struct ceph_cap_flush cap_flush;
  155. u64 follows;
  156. int issued, dirty;
  157. struct ceph_snap_context *context;
  158. umode_t mode;
  159. kuid_t uid;
  160. kgid_t gid;
  161. struct ceph_buffer *xattr_blob;
  162. u64 xattr_version;
  163. u64 size;
  164. struct timespec mtime, atime, ctime;
  165. u64 time_warp_seq;
  166. u64 truncate_size;
  167. u32 truncate_seq;
  168. int writing; /* a sync write is still in progress */
  169. int dirty_pages; /* dirty pages awaiting writeback */
  170. bool inline_data;
  171. bool need_flush;
  172. };
  173. static inline void ceph_put_cap_snap(struct ceph_cap_snap *capsnap)
  174. {
  175. if (refcount_dec_and_test(&capsnap->nref)) {
  176. if (capsnap->xattr_blob)
  177. ceph_buffer_put(capsnap->xattr_blob);
  178. kfree(capsnap);
  179. }
  180. }
  181. /*
  182. * The frag tree describes how a directory is fragmented, potentially across
  183. * multiple metadata servers. It is also used to indicate points where
  184. * metadata authority is delegated, and whether/where metadata is replicated.
  185. *
  186. * A _leaf_ frag will be present in the i_fragtree IFF there is
  187. * delegation info. That is, if mds >= 0 || ndist > 0.
  188. */
  189. #define CEPH_MAX_DIRFRAG_REP 4
  190. struct ceph_inode_frag {
  191. struct rb_node node;
  192. /* fragtree state */
  193. u32 frag;
  194. int split_by; /* i.e. 2^(split_by) children */
  195. /* delegation and replication info */
  196. int mds; /* -1 if same authority as parent */
  197. int ndist; /* >0 if replicated */
  198. int dist[CEPH_MAX_DIRFRAG_REP];
  199. };
  200. /*
  201. * We cache inode xattrs as an encoded blob until they are first used,
  202. * at which point we parse them into an rbtree.
  203. */
  204. struct ceph_inode_xattr {
  205. struct rb_node node;
  206. const char *name;
  207. int name_len;
  208. const char *val;
  209. int val_len;
  210. int dirty;
  211. int should_free_name;
  212. int should_free_val;
  213. };
  214. /*
  215. * Ceph dentry state
  216. */
  217. struct ceph_dentry_info {
  218. struct ceph_mds_session *lease_session;
  219. int lease_shared_gen;
  220. u32 lease_gen;
  221. u32 lease_seq;
  222. unsigned long lease_renew_after, lease_renew_from;
  223. struct list_head lru;
  224. struct dentry *dentry;
  225. unsigned long time;
  226. u64 offset;
  227. };
  228. struct ceph_inode_xattrs_info {
  229. /*
  230. * (still encoded) xattr blob. we avoid the overhead of parsing
  231. * this until someone actually calls getxattr, etc.
  232. *
  233. * blob->vec.iov_len == 4 implies there are no xattrs; blob ==
  234. * NULL means we don't know.
  235. */
  236. struct ceph_buffer *blob, *prealloc_blob;
  237. struct rb_root index;
  238. bool dirty;
  239. int count;
  240. int names_size;
  241. int vals_size;
  242. u64 version, index_version;
  243. };
  244. /*
  245. * Ceph inode.
  246. */
  247. struct ceph_inode_info {
  248. struct ceph_vino i_vino; /* ceph ino + snap */
  249. spinlock_t i_ceph_lock;
  250. u64 i_version;
  251. u64 i_inline_version;
  252. u32 i_time_warp_seq;
  253. unsigned i_ceph_flags;
  254. atomic64_t i_release_count;
  255. atomic64_t i_ordered_count;
  256. atomic64_t i_complete_seq[2];
  257. struct ceph_dir_layout i_dir_layout;
  258. struct ceph_file_layout i_layout;
  259. char *i_symlink;
  260. /* for dirs */
  261. struct timespec i_rctime;
  262. u64 i_rbytes, i_rfiles, i_rsubdirs;
  263. u64 i_files, i_subdirs;
  264. /* quotas */
  265. u64 i_max_bytes, i_max_files;
  266. struct rb_root i_fragtree;
  267. int i_fragtree_nsplits;
  268. struct mutex i_fragtree_mutex;
  269. struct ceph_inode_xattrs_info i_xattrs;
  270. /* capabilities. protected _both_ by i_ceph_lock and cap->session's
  271. * s_mutex. */
  272. struct rb_root i_caps; /* cap list */
  273. struct ceph_cap *i_auth_cap; /* authoritative cap, if any */
  274. unsigned i_dirty_caps, i_flushing_caps; /* mask of dirtied fields */
  275. struct list_head i_dirty_item, i_flushing_item;
  276. /* we need to track cap writeback on a per-cap-bit basis, to allow
  277. * overlapping, pipelined cap flushes to the mds. we can probably
  278. * reduce the tid to 8 bits if we're concerned about inode size. */
  279. struct ceph_cap_flush *i_prealloc_cap_flush;
  280. struct list_head i_cap_flush_list;
  281. wait_queue_head_t i_cap_wq; /* threads waiting on a capability */
  282. unsigned long i_hold_caps_min; /* jiffies */
  283. unsigned long i_hold_caps_max; /* jiffies */
  284. struct list_head i_cap_delay_list; /* for delayed cap release to mds */
  285. struct ceph_cap_reservation i_cap_migration_resv;
  286. struct list_head i_cap_snaps; /* snapped state pending flush to mds */
  287. struct ceph_snap_context *i_head_snapc; /* set if wr_buffer_head > 0 or
  288. dirty|flushing caps */
  289. unsigned i_snap_caps; /* cap bits for snapped files */
  290. int i_nr_by_mode[CEPH_FILE_MODE_BITS]; /* open file counts */
  291. struct mutex i_truncate_mutex;
  292. u32 i_truncate_seq; /* last truncate to smaller size */
  293. u64 i_truncate_size; /* and the size we last truncated down to */
  294. int i_truncate_pending; /* still need to call vmtruncate */
  295. u64 i_max_size; /* max file size authorized by mds */
  296. u64 i_reported_size; /* (max_)size reported to or requested of mds */
  297. u64 i_wanted_max_size; /* offset we'd like to write too */
  298. u64 i_requested_max_size; /* max_size we've requested */
  299. /* held references to caps */
  300. int i_pin_ref;
  301. int i_rd_ref, i_rdcache_ref, i_wr_ref, i_wb_ref;
  302. int i_wrbuffer_ref, i_wrbuffer_ref_head;
  303. atomic_t i_filelock_ref;
  304. atomic_t i_shared_gen; /* increment each time we get FILE_SHARED */
  305. u32 i_rdcache_gen; /* incremented each time we get FILE_CACHE. */
  306. u32 i_rdcache_revoking; /* RDCACHE gen to async invalidate, if any */
  307. struct list_head i_unsafe_dirops; /* uncommitted mds dir ops */
  308. struct list_head i_unsafe_iops; /* uncommitted mds inode ops */
  309. spinlock_t i_unsafe_lock;
  310. struct ceph_snap_realm *i_snap_realm; /* snap realm (if caps) */
  311. int i_snap_realm_counter; /* snap realm (if caps) */
  312. struct list_head i_snap_realm_item;
  313. struct list_head i_snap_flush_item;
  314. struct work_struct i_wb_work; /* writeback work */
  315. struct work_struct i_pg_inv_work; /* page invalidation work */
  316. struct work_struct i_vmtruncate_work;
  317. #ifdef CONFIG_CEPH_FSCACHE
  318. struct fscache_cookie *fscache;
  319. u32 i_fscache_gen;
  320. #endif
  321. struct inode vfs_inode; /* at end */
  322. };
  323. static inline struct ceph_inode_info *ceph_inode(struct inode *inode)
  324. {
  325. return container_of(inode, struct ceph_inode_info, vfs_inode);
  326. }
  327. static inline struct ceph_fs_client *ceph_inode_to_client(struct inode *inode)
  328. {
  329. return (struct ceph_fs_client *)inode->i_sb->s_fs_info;
  330. }
  331. static inline struct ceph_fs_client *ceph_sb_to_client(struct super_block *sb)
  332. {
  333. return (struct ceph_fs_client *)sb->s_fs_info;
  334. }
  335. static inline struct ceph_vino ceph_vino(struct inode *inode)
  336. {
  337. return ceph_inode(inode)->i_vino;
  338. }
  339. /*
  340. * ino_t is <64 bits on many architectures, blech.
  341. *
  342. * i_ino (kernel inode) st_ino (userspace)
  343. * i386 32 32
  344. * x86_64+ino32 64 32
  345. * x86_64 64 64
  346. */
  347. static inline u32 ceph_ino_to_ino32(__u64 vino)
  348. {
  349. u32 ino = vino & 0xffffffff;
  350. ino ^= vino >> 32;
  351. if (!ino)
  352. ino = 2;
  353. return ino;
  354. }
  355. /*
  356. * kernel i_ino value
  357. */
  358. static inline ino_t ceph_vino_to_ino(struct ceph_vino vino)
  359. {
  360. #if BITS_PER_LONG == 32
  361. return ceph_ino_to_ino32(vino.ino);
  362. #else
  363. return (ino_t)vino.ino;
  364. #endif
  365. }
  366. /*
  367. * user-visible ino (stat, filldir)
  368. */
  369. #if BITS_PER_LONG == 32
  370. static inline ino_t ceph_translate_ino(struct super_block *sb, ino_t ino)
  371. {
  372. return ino;
  373. }
  374. #else
  375. static inline ino_t ceph_translate_ino(struct super_block *sb, ino_t ino)
  376. {
  377. if (ceph_test_mount_opt(ceph_sb_to_client(sb), INO32))
  378. ino = ceph_ino_to_ino32(ino);
  379. return ino;
  380. }
  381. #endif
  382. /* for printf-style formatting */
  383. #define ceph_vinop(i) ceph_inode(i)->i_vino.ino, ceph_inode(i)->i_vino.snap
  384. static inline u64 ceph_ino(struct inode *inode)
  385. {
  386. return ceph_inode(inode)->i_vino.ino;
  387. }
  388. static inline u64 ceph_snap(struct inode *inode)
  389. {
  390. return ceph_inode(inode)->i_vino.snap;
  391. }
  392. static inline int ceph_ino_compare(struct inode *inode, void *data)
  393. {
  394. struct ceph_vino *pvino = (struct ceph_vino *)data;
  395. struct ceph_inode_info *ci = ceph_inode(inode);
  396. return ci->i_vino.ino == pvino->ino &&
  397. ci->i_vino.snap == pvino->snap;
  398. }
  399. static inline struct inode *ceph_find_inode(struct super_block *sb,
  400. struct ceph_vino vino)
  401. {
  402. ino_t t = ceph_vino_to_ino(vino);
  403. return ilookup5(sb, t, ceph_ino_compare, &vino);
  404. }
  405. /*
  406. * Ceph inode.
  407. */
  408. #define CEPH_I_DIR_ORDERED (1 << 0) /* dentries in dir are ordered */
  409. #define CEPH_I_NODELAY (1 << 1) /* do not delay cap release */
  410. #define CEPH_I_FLUSH (1 << 2) /* do not delay flush of dirty metadata */
  411. #define CEPH_I_NOFLUSH (1 << 3) /* do not flush dirty caps */
  412. #define CEPH_I_POOL_PERM (1 << 4) /* pool rd/wr bits are valid */
  413. #define CEPH_I_POOL_RD (1 << 5) /* can read from pool */
  414. #define CEPH_I_POOL_WR (1 << 6) /* can write to pool */
  415. #define CEPH_I_SEC_INITED (1 << 7) /* security initialized */
  416. #define CEPH_I_CAP_DROPPED (1 << 8) /* caps were forcibly dropped */
  417. #define CEPH_I_KICK_FLUSH (1 << 9) /* kick flushing caps */
  418. #define CEPH_I_FLUSH_SNAPS (1 << 10) /* need flush snapss */
  419. #define CEPH_I_ERROR_WRITE (1 << 11) /* have seen write errors */
  420. #define CEPH_I_ERROR_FILELOCK (1 << 12) /* have seen file lock errors */
  421. /*
  422. * We set the ERROR_WRITE bit when we start seeing write errors on an inode
  423. * and then clear it when they start succeeding. Note that we do a lockless
  424. * check first, and only take the lock if it looks like it needs to be changed.
  425. * The write submission code just takes this as a hint, so we're not too
  426. * worried if a few slip through in either direction.
  427. */
  428. static inline void ceph_set_error_write(struct ceph_inode_info *ci)
  429. {
  430. if (!(READ_ONCE(ci->i_ceph_flags) & CEPH_I_ERROR_WRITE)) {
  431. spin_lock(&ci->i_ceph_lock);
  432. ci->i_ceph_flags |= CEPH_I_ERROR_WRITE;
  433. spin_unlock(&ci->i_ceph_lock);
  434. }
  435. }
  436. static inline void ceph_clear_error_write(struct ceph_inode_info *ci)
  437. {
  438. if (READ_ONCE(ci->i_ceph_flags) & CEPH_I_ERROR_WRITE) {
  439. spin_lock(&ci->i_ceph_lock);
  440. ci->i_ceph_flags &= ~CEPH_I_ERROR_WRITE;
  441. spin_unlock(&ci->i_ceph_lock);
  442. }
  443. }
  444. static inline void __ceph_dir_set_complete(struct ceph_inode_info *ci,
  445. long long release_count,
  446. long long ordered_count)
  447. {
  448. smp_mb__before_atomic();
  449. atomic64_set(&ci->i_complete_seq[0], release_count);
  450. atomic64_set(&ci->i_complete_seq[1], ordered_count);
  451. }
  452. static inline void __ceph_dir_clear_complete(struct ceph_inode_info *ci)
  453. {
  454. atomic64_inc(&ci->i_release_count);
  455. }
  456. static inline void __ceph_dir_clear_ordered(struct ceph_inode_info *ci)
  457. {
  458. atomic64_inc(&ci->i_ordered_count);
  459. }
  460. static inline bool __ceph_dir_is_complete(struct ceph_inode_info *ci)
  461. {
  462. return atomic64_read(&ci->i_complete_seq[0]) ==
  463. atomic64_read(&ci->i_release_count);
  464. }
  465. static inline bool __ceph_dir_is_complete_ordered(struct ceph_inode_info *ci)
  466. {
  467. return atomic64_read(&ci->i_complete_seq[0]) ==
  468. atomic64_read(&ci->i_release_count) &&
  469. atomic64_read(&ci->i_complete_seq[1]) ==
  470. atomic64_read(&ci->i_ordered_count);
  471. }
  472. static inline void ceph_dir_clear_complete(struct inode *inode)
  473. {
  474. __ceph_dir_clear_complete(ceph_inode(inode));
  475. }
  476. static inline void ceph_dir_clear_ordered(struct inode *inode)
  477. {
  478. __ceph_dir_clear_ordered(ceph_inode(inode));
  479. }
  480. static inline bool ceph_dir_is_complete_ordered(struct inode *inode)
  481. {
  482. bool ret = __ceph_dir_is_complete_ordered(ceph_inode(inode));
  483. smp_rmb();
  484. return ret;
  485. }
  486. /* find a specific frag @f */
  487. extern struct ceph_inode_frag *__ceph_find_frag(struct ceph_inode_info *ci,
  488. u32 f);
  489. /*
  490. * choose fragment for value @v. copy frag content to pfrag, if leaf
  491. * exists
  492. */
  493. extern u32 ceph_choose_frag(struct ceph_inode_info *ci, u32 v,
  494. struct ceph_inode_frag *pfrag,
  495. int *found);
  496. static inline struct ceph_dentry_info *ceph_dentry(struct dentry *dentry)
  497. {
  498. return (struct ceph_dentry_info *)dentry->d_fsdata;
  499. }
  500. /*
  501. * caps helpers
  502. */
  503. static inline bool __ceph_is_any_real_caps(struct ceph_inode_info *ci)
  504. {
  505. return !RB_EMPTY_ROOT(&ci->i_caps);
  506. }
  507. extern int __ceph_caps_issued(struct ceph_inode_info *ci, int *implemented);
  508. extern int __ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask, int t);
  509. extern int __ceph_caps_issued_other(struct ceph_inode_info *ci,
  510. struct ceph_cap *cap);
  511. static inline int ceph_caps_issued(struct ceph_inode_info *ci)
  512. {
  513. int issued;
  514. spin_lock(&ci->i_ceph_lock);
  515. issued = __ceph_caps_issued(ci, NULL);
  516. spin_unlock(&ci->i_ceph_lock);
  517. return issued;
  518. }
  519. static inline int ceph_caps_issued_mask(struct ceph_inode_info *ci, int mask,
  520. int touch)
  521. {
  522. int r;
  523. spin_lock(&ci->i_ceph_lock);
  524. r = __ceph_caps_issued_mask(ci, mask, touch);
  525. spin_unlock(&ci->i_ceph_lock);
  526. return r;
  527. }
  528. static inline int __ceph_caps_dirty(struct ceph_inode_info *ci)
  529. {
  530. return ci->i_dirty_caps | ci->i_flushing_caps;
  531. }
  532. extern struct ceph_cap_flush *ceph_alloc_cap_flush(void);
  533. extern void ceph_free_cap_flush(struct ceph_cap_flush *cf);
  534. extern int __ceph_mark_dirty_caps(struct ceph_inode_info *ci, int mask,
  535. struct ceph_cap_flush **pcf);
  536. extern int __ceph_caps_revoking_other(struct ceph_inode_info *ci,
  537. struct ceph_cap *ocap, int mask);
  538. extern int ceph_caps_revoking(struct ceph_inode_info *ci, int mask);
  539. extern int __ceph_caps_used(struct ceph_inode_info *ci);
  540. extern int __ceph_caps_file_wanted(struct ceph_inode_info *ci);
  541. /*
  542. * wanted, by virtue of open file modes AND cap refs (buffered/cached data)
  543. */
  544. static inline int __ceph_caps_wanted(struct ceph_inode_info *ci)
  545. {
  546. int w = __ceph_caps_file_wanted(ci) | __ceph_caps_used(ci);
  547. if (w & CEPH_CAP_FILE_BUFFER)
  548. w |= CEPH_CAP_FILE_EXCL; /* we want EXCL if dirty data */
  549. return w;
  550. }
  551. /* what the mds thinks we want */
  552. extern int __ceph_caps_mds_wanted(struct ceph_inode_info *ci, bool check);
  553. extern void ceph_caps_init(struct ceph_mds_client *mdsc);
  554. extern void ceph_caps_finalize(struct ceph_mds_client *mdsc);
  555. extern void ceph_adjust_min_caps(struct ceph_mds_client *mdsc, int delta);
  556. extern int ceph_reserve_caps(struct ceph_mds_client *mdsc,
  557. struct ceph_cap_reservation *ctx, int need);
  558. extern int ceph_unreserve_caps(struct ceph_mds_client *mdsc,
  559. struct ceph_cap_reservation *ctx);
  560. extern void ceph_reservation_status(struct ceph_fs_client *client,
  561. int *total, int *avail, int *used,
  562. int *reserved, int *min);
  563. /*
  564. * we keep buffered readdir results attached to file->private_data
  565. */
  566. #define CEPH_F_SYNC 1
  567. #define CEPH_F_ATEND 2
  568. struct ceph_file_info {
  569. short fmode; /* initialized on open */
  570. short flags; /* CEPH_F_* */
  571. spinlock_t rw_contexts_lock;
  572. struct list_head rw_contexts;
  573. };
  574. struct ceph_dir_file_info {
  575. struct ceph_file_info file_info;
  576. /* readdir: position within the dir */
  577. u32 frag;
  578. struct ceph_mds_request *last_readdir;
  579. /* readdir: position within a frag */
  580. unsigned next_offset; /* offset of next chunk (last_name's + 1) */
  581. char *last_name; /* last entry in previous chunk */
  582. long long dir_release_count;
  583. long long dir_ordered_count;
  584. int readdir_cache_idx;
  585. /* used for -o dirstat read() on directory thing */
  586. char *dir_info;
  587. int dir_info_len;
  588. };
  589. struct ceph_rw_context {
  590. struct list_head list;
  591. struct task_struct *thread;
  592. int caps;
  593. };
  594. #define CEPH_DEFINE_RW_CONTEXT(_name, _caps) \
  595. struct ceph_rw_context _name = { \
  596. .thread = current, \
  597. .caps = _caps, \
  598. }
  599. static inline void ceph_add_rw_context(struct ceph_file_info *cf,
  600. struct ceph_rw_context *ctx)
  601. {
  602. spin_lock(&cf->rw_contexts_lock);
  603. list_add(&ctx->list, &cf->rw_contexts);
  604. spin_unlock(&cf->rw_contexts_lock);
  605. }
  606. static inline void ceph_del_rw_context(struct ceph_file_info *cf,
  607. struct ceph_rw_context *ctx)
  608. {
  609. spin_lock(&cf->rw_contexts_lock);
  610. list_del(&ctx->list);
  611. spin_unlock(&cf->rw_contexts_lock);
  612. }
  613. static inline struct ceph_rw_context*
  614. ceph_find_rw_context(struct ceph_file_info *cf)
  615. {
  616. struct ceph_rw_context *ctx, *found = NULL;
  617. spin_lock(&cf->rw_contexts_lock);
  618. list_for_each_entry(ctx, &cf->rw_contexts, list) {
  619. if (ctx->thread == current) {
  620. found = ctx;
  621. break;
  622. }
  623. }
  624. spin_unlock(&cf->rw_contexts_lock);
  625. return found;
  626. }
  627. struct ceph_readdir_cache_control {
  628. struct page *page;
  629. struct dentry **dentries;
  630. int index;
  631. };
  632. /*
  633. * A "snap realm" describes a subset of the file hierarchy sharing
  634. * the same set of snapshots that apply to it. The realms themselves
  635. * are organized into a hierarchy, such that children inherit (some of)
  636. * the snapshots of their parents.
  637. *
  638. * All inodes within the realm that have capabilities are linked into a
  639. * per-realm list.
  640. */
  641. struct ceph_snap_realm {
  642. u64 ino;
  643. struct inode *inode;
  644. atomic_t nref;
  645. struct rb_node node;
  646. u64 created, seq;
  647. u64 parent_ino;
  648. u64 parent_since; /* snapid when our current parent became so */
  649. u64 *prior_parent_snaps; /* snaps inherited from any parents we */
  650. u32 num_prior_parent_snaps; /* had prior to parent_since */
  651. u64 *snaps; /* snaps specific to this realm */
  652. u32 num_snaps;
  653. struct ceph_snap_realm *parent;
  654. struct list_head children; /* list of child realms */
  655. struct list_head child_item;
  656. struct list_head empty_item; /* if i have ref==0 */
  657. struct list_head dirty_item; /* if realm needs new context */
  658. /* the current set of snaps for this realm */
  659. struct ceph_snap_context *cached_context;
  660. struct list_head inodes_with_caps;
  661. spinlock_t inodes_with_caps_lock;
  662. };
  663. static inline int default_congestion_kb(void)
  664. {
  665. int congestion_kb;
  666. /*
  667. * Copied from NFS
  668. *
  669. * congestion size, scale with available memory.
  670. *
  671. * 64MB: 8192k
  672. * 128MB: 11585k
  673. * 256MB: 16384k
  674. * 512MB: 23170k
  675. * 1GB: 32768k
  676. * 2GB: 46340k
  677. * 4GB: 65536k
  678. * 8GB: 92681k
  679. * 16GB: 131072k
  680. *
  681. * This allows larger machines to have larger/more transfers.
  682. * Limit the default to 256M
  683. */
  684. congestion_kb = (16*int_sqrt(totalram_pages)) << (PAGE_SHIFT-10);
  685. if (congestion_kb > 256*1024)
  686. congestion_kb = 256*1024;
  687. return congestion_kb;
  688. }
  689. /* snap.c */
  690. struct ceph_snap_realm *ceph_lookup_snap_realm(struct ceph_mds_client *mdsc,
  691. u64 ino);
  692. extern void ceph_get_snap_realm(struct ceph_mds_client *mdsc,
  693. struct ceph_snap_realm *realm);
  694. extern void ceph_put_snap_realm(struct ceph_mds_client *mdsc,
  695. struct ceph_snap_realm *realm);
  696. extern int ceph_update_snap_trace(struct ceph_mds_client *m,
  697. void *p, void *e, bool deletion,
  698. struct ceph_snap_realm **realm_ret);
  699. extern void ceph_handle_snap(struct ceph_mds_client *mdsc,
  700. struct ceph_mds_session *session,
  701. struct ceph_msg *msg);
  702. extern void ceph_queue_cap_snap(struct ceph_inode_info *ci);
  703. extern int __ceph_finish_cap_snap(struct ceph_inode_info *ci,
  704. struct ceph_cap_snap *capsnap);
  705. extern void ceph_cleanup_empty_realms(struct ceph_mds_client *mdsc);
  706. /*
  707. * a cap_snap is "pending" if it is still awaiting an in-progress
  708. * sync write (that may/may not still update size, mtime, etc.).
  709. */
  710. static inline bool __ceph_have_pending_cap_snap(struct ceph_inode_info *ci)
  711. {
  712. return !list_empty(&ci->i_cap_snaps) &&
  713. list_last_entry(&ci->i_cap_snaps, struct ceph_cap_snap,
  714. ci_item)->writing;
  715. }
  716. /* inode.c */
  717. extern const struct inode_operations ceph_file_iops;
  718. extern struct inode *ceph_alloc_inode(struct super_block *sb);
  719. extern void ceph_destroy_inode(struct inode *inode);
  720. extern int ceph_drop_inode(struct inode *inode);
  721. extern struct inode *ceph_get_inode(struct super_block *sb,
  722. struct ceph_vino vino);
  723. extern struct inode *ceph_get_snapdir(struct inode *parent);
  724. extern int ceph_fill_file_size(struct inode *inode, int issued,
  725. u32 truncate_seq, u64 truncate_size, u64 size);
  726. extern void ceph_fill_file_time(struct inode *inode, int issued,
  727. u64 time_warp_seq, struct timespec *ctime,
  728. struct timespec *mtime, struct timespec *atime);
  729. extern int ceph_fill_trace(struct super_block *sb,
  730. struct ceph_mds_request *req);
  731. extern int ceph_readdir_prepopulate(struct ceph_mds_request *req,
  732. struct ceph_mds_session *session);
  733. extern int ceph_inode_holds_cap(struct inode *inode, int mask);
  734. extern bool ceph_inode_set_size(struct inode *inode, loff_t size);
  735. extern void __ceph_do_pending_vmtruncate(struct inode *inode);
  736. extern void ceph_queue_vmtruncate(struct inode *inode);
  737. extern void ceph_queue_invalidate(struct inode *inode);
  738. extern void ceph_queue_writeback(struct inode *inode);
  739. extern int __ceph_do_getattr(struct inode *inode, struct page *locked_page,
  740. int mask, bool force);
  741. static inline int ceph_do_getattr(struct inode *inode, int mask, bool force)
  742. {
  743. return __ceph_do_getattr(inode, NULL, mask, force);
  744. }
  745. extern int ceph_permission(struct inode *inode, int mask);
  746. extern int __ceph_setattr(struct inode *inode, struct iattr *attr);
  747. extern int ceph_setattr(struct dentry *dentry, struct iattr *attr);
  748. extern int ceph_getattr(const struct path *path, struct kstat *stat,
  749. u32 request_mask, unsigned int flags);
  750. /* xattr.c */
  751. int __ceph_setxattr(struct inode *, const char *, const void *, size_t, int);
  752. ssize_t __ceph_getxattr(struct inode *, const char *, void *, size_t);
  753. extern ssize_t ceph_listxattr(struct dentry *, char *, size_t);
  754. extern void __ceph_build_xattrs_blob(struct ceph_inode_info *ci);
  755. extern void __ceph_destroy_xattrs(struct ceph_inode_info *ci);
  756. extern void __init ceph_xattr_init(void);
  757. extern void ceph_xattr_exit(void);
  758. extern const struct xattr_handler *ceph_xattr_handlers[];
  759. #ifdef CONFIG_SECURITY
  760. extern bool ceph_security_xattr_deadlock(struct inode *in);
  761. extern bool ceph_security_xattr_wanted(struct inode *in);
  762. #else
  763. static inline bool ceph_security_xattr_deadlock(struct inode *in)
  764. {
  765. return false;
  766. }
  767. static inline bool ceph_security_xattr_wanted(struct inode *in)
  768. {
  769. return false;
  770. }
  771. #endif
  772. /* acl.c */
  773. struct ceph_acls_info {
  774. void *default_acl;
  775. void *acl;
  776. struct ceph_pagelist *pagelist;
  777. };
  778. #ifdef CONFIG_CEPH_FS_POSIX_ACL
  779. struct posix_acl *ceph_get_acl(struct inode *, int);
  780. int ceph_set_acl(struct inode *inode, struct posix_acl *acl, int type);
  781. int ceph_pre_init_acls(struct inode *dir, umode_t *mode,
  782. struct ceph_acls_info *info);
  783. void ceph_init_inode_acls(struct inode *inode, struct ceph_acls_info *info);
  784. void ceph_release_acls_info(struct ceph_acls_info *info);
  785. static inline void ceph_forget_all_cached_acls(struct inode *inode)
  786. {
  787. forget_all_cached_acls(inode);
  788. }
  789. #else
  790. #define ceph_get_acl NULL
  791. #define ceph_set_acl NULL
  792. static inline int ceph_pre_init_acls(struct inode *dir, umode_t *mode,
  793. struct ceph_acls_info *info)
  794. {
  795. return 0;
  796. }
  797. static inline void ceph_init_inode_acls(struct inode *inode,
  798. struct ceph_acls_info *info)
  799. {
  800. }
  801. static inline void ceph_release_acls_info(struct ceph_acls_info *info)
  802. {
  803. }
  804. static inline int ceph_acl_chmod(struct dentry *dentry, struct inode *inode)
  805. {
  806. return 0;
  807. }
  808. static inline void ceph_forget_all_cached_acls(struct inode *inode)
  809. {
  810. }
  811. #endif
  812. /* caps.c */
  813. extern const char *ceph_cap_string(int c);
  814. extern void ceph_handle_caps(struct ceph_mds_session *session,
  815. struct ceph_msg *msg);
  816. extern struct ceph_cap *ceph_get_cap(struct ceph_mds_client *mdsc,
  817. struct ceph_cap_reservation *ctx);
  818. extern void ceph_add_cap(struct inode *inode,
  819. struct ceph_mds_session *session, u64 cap_id,
  820. int fmode, unsigned issued, unsigned wanted,
  821. unsigned cap, unsigned seq, u64 realmino, int flags,
  822. struct ceph_cap **new_cap);
  823. extern void __ceph_remove_cap(struct ceph_cap *cap, bool queue_release);
  824. extern void ceph_put_cap(struct ceph_mds_client *mdsc,
  825. struct ceph_cap *cap);
  826. extern int ceph_is_any_caps(struct inode *inode);
  827. extern void ceph_queue_caps_release(struct inode *inode);
  828. extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc);
  829. extern int ceph_fsync(struct file *file, loff_t start, loff_t end,
  830. int datasync);
  831. extern void ceph_early_kick_flushing_caps(struct ceph_mds_client *mdsc,
  832. struct ceph_mds_session *session);
  833. extern void ceph_kick_flushing_caps(struct ceph_mds_client *mdsc,
  834. struct ceph_mds_session *session);
  835. extern struct ceph_cap *ceph_get_cap_for_mds(struct ceph_inode_info *ci,
  836. int mds);
  837. extern int ceph_get_cap_mds(struct inode *inode);
  838. extern void ceph_get_cap_refs(struct ceph_inode_info *ci, int caps);
  839. extern void ceph_put_cap_refs(struct ceph_inode_info *ci, int had);
  840. extern void ceph_put_wrbuffer_cap_refs(struct ceph_inode_info *ci, int nr,
  841. struct ceph_snap_context *snapc);
  842. extern void ceph_flush_snaps(struct ceph_inode_info *ci,
  843. struct ceph_mds_session **psession);
  844. extern bool __ceph_should_report_size(struct ceph_inode_info *ci);
  845. extern void ceph_check_caps(struct ceph_inode_info *ci, int flags,
  846. struct ceph_mds_session *session);
  847. extern void ceph_check_delayed_caps(struct ceph_mds_client *mdsc);
  848. extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc);
  849. extern int ceph_drop_caps_for_unlink(struct inode *inode);
  850. extern int ceph_encode_inode_release(void **p, struct inode *inode,
  851. int mds, int drop, int unless, int force);
  852. extern int ceph_encode_dentry_release(void **p, struct dentry *dn,
  853. struct inode *dir,
  854. int mds, int drop, int unless);
  855. extern int ceph_get_caps(struct ceph_inode_info *ci, int need, int want,
  856. loff_t endoff, int *got, struct page **pinned_page);
  857. extern int ceph_try_get_caps(struct ceph_inode_info *ci,
  858. int need, int want, int *got);
  859. /* for counting open files by mode */
  860. extern void __ceph_get_fmode(struct ceph_inode_info *ci, int mode);
  861. extern void ceph_put_fmode(struct ceph_inode_info *ci, int mode);
  862. /* addr.c */
  863. extern const struct address_space_operations ceph_aops;
  864. extern int ceph_mmap(struct file *file, struct vm_area_struct *vma);
  865. extern int ceph_uninline_data(struct file *filp, struct page *locked_page);
  866. extern int ceph_pool_perm_check(struct ceph_inode_info *ci, int need);
  867. extern void ceph_pool_perm_destroy(struct ceph_mds_client* mdsc);
  868. /* file.c */
  869. extern const struct file_operations ceph_file_fops;
  870. extern int ceph_renew_caps(struct inode *inode);
  871. extern int ceph_open(struct inode *inode, struct file *file);
  872. extern int ceph_atomic_open(struct inode *dir, struct dentry *dentry,
  873. struct file *file, unsigned flags, umode_t mode,
  874. int *opened);
  875. extern int ceph_release(struct inode *inode, struct file *filp);
  876. extern void ceph_fill_inline_data(struct inode *inode, struct page *locked_page,
  877. char *data, size_t len);
  878. /* dir.c */
  879. extern const struct file_operations ceph_dir_fops;
  880. extern const struct file_operations ceph_snapdir_fops;
  881. extern const struct inode_operations ceph_dir_iops;
  882. extern const struct inode_operations ceph_snapdir_iops;
  883. extern const struct dentry_operations ceph_dentry_ops;
  884. extern loff_t ceph_make_fpos(unsigned high, unsigned off, bool hash_order);
  885. extern int ceph_handle_notrace_create(struct inode *dir, struct dentry *dentry);
  886. extern int ceph_handle_snapdir(struct ceph_mds_request *req,
  887. struct dentry *dentry, int err);
  888. extern struct dentry *ceph_finish_lookup(struct ceph_mds_request *req,
  889. struct dentry *dentry, int err);
  890. extern void ceph_dentry_lru_add(struct dentry *dn);
  891. extern void ceph_dentry_lru_touch(struct dentry *dn);
  892. extern void ceph_dentry_lru_del(struct dentry *dn);
  893. extern void ceph_invalidate_dentry_lease(struct dentry *dentry);
  894. extern unsigned ceph_dentry_hash(struct inode *dir, struct dentry *dn);
  895. extern void ceph_readdir_cache_release(struct ceph_readdir_cache_control *ctl);
  896. /* ioctl.c */
  897. extern long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg);
  898. /* export.c */
  899. extern const struct export_operations ceph_export_ops;
  900. /* locks.c */
  901. extern __init void ceph_flock_init(void);
  902. extern int ceph_lock(struct file *file, int cmd, struct file_lock *fl);
  903. extern int ceph_flock(struct file *file, int cmd, struct file_lock *fl);
  904. extern void ceph_count_locks(struct inode *inode, int *p_num, int *f_num);
  905. extern int ceph_encode_locks_to_buffer(struct inode *inode,
  906. struct ceph_filelock *flocks,
  907. int num_fcntl_locks,
  908. int num_flock_locks);
  909. extern int ceph_locks_to_pagelist(struct ceph_filelock *flocks,
  910. struct ceph_pagelist *pagelist,
  911. int num_fcntl_locks, int num_flock_locks);
  912. /* debugfs.c */
  913. extern int ceph_fs_debugfs_init(struct ceph_fs_client *client);
  914. extern void ceph_fs_debugfs_cleanup(struct ceph_fs_client *client);
  915. /* quota.c */
  916. static inline bool __ceph_has_any_quota(struct ceph_inode_info *ci)
  917. {
  918. return ci->i_max_files || ci->i_max_bytes;
  919. }
  920. extern void ceph_adjust_quota_realms_count(struct inode *inode, bool inc);
  921. static inline void __ceph_update_quota(struct ceph_inode_info *ci,
  922. u64 max_bytes, u64 max_files)
  923. {
  924. bool had_quota, has_quota;
  925. had_quota = __ceph_has_any_quota(ci);
  926. ci->i_max_bytes = max_bytes;
  927. ci->i_max_files = max_files;
  928. has_quota = __ceph_has_any_quota(ci);
  929. if (had_quota != has_quota)
  930. ceph_adjust_quota_realms_count(&ci->vfs_inode, has_quota);
  931. }
  932. extern void ceph_handle_quota(struct ceph_mds_client *mdsc,
  933. struct ceph_mds_session *session,
  934. struct ceph_msg *msg);
  935. extern bool ceph_quota_is_max_files_exceeded(struct inode *inode);
  936. extern bool ceph_quota_is_same_realm(struct inode *old, struct inode *new);
  937. extern bool ceph_quota_is_max_bytes_exceeded(struct inode *inode,
  938. loff_t newlen);
  939. extern bool ceph_quota_is_max_bytes_approaching(struct inode *inode,
  940. loff_t newlen);
  941. extern bool ceph_quota_update_statfs(struct ceph_fs_client *fsc,
  942. struct kstatfs *buf);
  943. #endif /* _FS_CEPH_SUPER_H */