super.h 34 KB

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