super.h 32 KB

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