super.h 40 KB

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