mds_client.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. #ifndef _FS_CEPH_MDS_CLIENT_H
  2. #define _FS_CEPH_MDS_CLIENT_H
  3. #include <linux/completion.h>
  4. #include <linux/list.h>
  5. #include <linux/mutex.h>
  6. #include <linux/radix-tree.h>
  7. #include <linux/spinlock.h>
  8. #include "types.h"
  9. #include "messenger.h"
  10. #include "mdsmap.h"
  11. /*
  12. * Some lock dependencies:
  13. *
  14. * session->s_mutex
  15. * mdsc->mutex
  16. *
  17. * mdsc->snap_rwsem
  18. *
  19. * inode->i_lock
  20. * mdsc->snap_flush_lock
  21. * mdsc->cap_delay_lock
  22. *
  23. */
  24. struct ceph_client;
  25. struct ceph_cap;
  26. /*
  27. * parsed info about a single inode. pointers are into the encoded
  28. * on-wire structures within the mds reply message payload.
  29. */
  30. struct ceph_mds_reply_info_in {
  31. struct ceph_mds_reply_inode *in;
  32. u32 symlink_len;
  33. char *symlink;
  34. u32 xattr_len;
  35. char *xattr_data;
  36. };
  37. /*
  38. * parsed info about an mds reply, including information about the
  39. * target inode and/or its parent directory and dentry, and directory
  40. * contents (for readdir results).
  41. */
  42. struct ceph_mds_reply_info_parsed {
  43. struct ceph_mds_reply_head *head;
  44. struct ceph_mds_reply_info_in diri, targeti;
  45. struct ceph_mds_reply_dirfrag *dirfrag;
  46. char *dname;
  47. u32 dname_len;
  48. struct ceph_mds_reply_lease *dlease;
  49. struct ceph_mds_reply_dirfrag *dir_dir;
  50. int dir_nr;
  51. char **dir_dname;
  52. u32 *dir_dname_len;
  53. struct ceph_mds_reply_lease **dir_dlease;
  54. struct ceph_mds_reply_info_in *dir_in;
  55. u8 dir_complete, dir_end;
  56. /* encoded blob describing snapshot contexts for certain
  57. operations (e.g., open) */
  58. void *snapblob;
  59. int snapblob_len;
  60. };
  61. /*
  62. * cap releases are batched and sent to the MDS en masse.
  63. */
  64. #define CEPH_CAPS_PER_RELEASE ((PAGE_CACHE_SIZE - \
  65. sizeof(struct ceph_mds_cap_release)) / \
  66. sizeof(struct ceph_mds_cap_item))
  67. /*
  68. * state associated with each MDS<->client session
  69. */
  70. enum {
  71. CEPH_MDS_SESSION_NEW = 1,
  72. CEPH_MDS_SESSION_OPENING = 2,
  73. CEPH_MDS_SESSION_OPEN = 3,
  74. CEPH_MDS_SESSION_HUNG = 4,
  75. CEPH_MDS_SESSION_CLOSING = 5,
  76. CEPH_MDS_SESSION_RESTARTING = 6,
  77. CEPH_MDS_SESSION_RECONNECTING = 7,
  78. };
  79. struct ceph_mds_session {
  80. struct ceph_mds_client *s_mdsc;
  81. int s_mds;
  82. int s_state;
  83. unsigned long s_ttl; /* time until mds kills us */
  84. u64 s_seq; /* incoming msg seq # */
  85. struct mutex s_mutex; /* serialize session messages */
  86. struct ceph_connection s_con;
  87. /* protected by s_cap_lock */
  88. spinlock_t s_cap_lock;
  89. u32 s_cap_gen; /* inc each time we get mds stale msg */
  90. unsigned long s_cap_ttl; /* when session caps expire */
  91. struct list_head s_caps; /* all caps issued by this session */
  92. int s_nr_caps, s_trim_caps;
  93. int s_num_cap_releases;
  94. struct list_head s_cap_releases; /* waiting cap_release messages */
  95. struct list_head s_cap_releases_done; /* ready to send */
  96. /* protected by mutex */
  97. struct list_head s_cap_flushing; /* inodes w/ flushing caps */
  98. struct list_head s_cap_snaps_flushing;
  99. unsigned long s_renew_requested; /* last time we sent a renew req */
  100. u64 s_renew_seq;
  101. atomic_t s_ref;
  102. struct list_head s_waiting; /* waiting requests */
  103. struct list_head s_unsafe; /* unsafe requests */
  104. };
  105. /*
  106. * modes of choosing which MDS to send a request to
  107. */
  108. enum {
  109. USE_ANY_MDS,
  110. USE_RANDOM_MDS,
  111. USE_AUTH_MDS, /* prefer authoritative mds for this metadata item */
  112. };
  113. struct ceph_mds_request;
  114. struct ceph_mds_client;
  115. /*
  116. * request completion callback
  117. */
  118. typedef void (*ceph_mds_request_callback_t) (struct ceph_mds_client *mdsc,
  119. struct ceph_mds_request *req);
  120. /*
  121. * an in-flight mds request
  122. */
  123. struct ceph_mds_request {
  124. u64 r_tid; /* transaction id */
  125. int r_op; /* mds op code */
  126. int r_mds;
  127. /* operation on what? */
  128. struct inode *r_inode; /* arg1 */
  129. struct dentry *r_dentry; /* arg1 */
  130. struct dentry *r_old_dentry; /* arg2: rename from or link from */
  131. char *r_path1, *r_path2;
  132. struct ceph_vino r_ino1, r_ino2;
  133. struct inode *r_locked_dir; /* dir (if any) i_mutex locked by vfs */
  134. struct inode *r_target_inode; /* resulting inode */
  135. union ceph_mds_request_args r_args;
  136. int r_fmode; /* file mode, if expecting cap */
  137. /* for choosing which mds to send this request to */
  138. int r_direct_mode;
  139. u32 r_direct_hash; /* choose dir frag based on this dentry hash */
  140. bool r_direct_is_hash; /* true if r_direct_hash is valid */
  141. /* data payload is used for xattr ops */
  142. struct page **r_pages;
  143. int r_num_pages;
  144. int r_data_len;
  145. /* what caps shall we drop? */
  146. int r_inode_drop, r_inode_unless;
  147. int r_dentry_drop, r_dentry_unless;
  148. int r_old_dentry_drop, r_old_dentry_unless;
  149. struct inode *r_old_inode;
  150. int r_old_inode_drop, r_old_inode_unless;
  151. struct ceph_msg *r_request; /* original request */
  152. struct ceph_msg *r_reply;
  153. struct ceph_mds_reply_info_parsed r_reply_info;
  154. int r_err;
  155. unsigned long r_timeout; /* optional. jiffies */
  156. unsigned long r_started; /* start time to measure timeout against */
  157. unsigned long r_request_started; /* start time for mds request only,
  158. used to measure lease durations */
  159. /* link unsafe requests to parent directory, for fsync */
  160. struct inode *r_unsafe_dir;
  161. struct list_head r_unsafe_dir_item;
  162. struct ceph_mds_session *r_session;
  163. int r_attempts; /* resend attempts */
  164. int r_num_fwd; /* number of forward attempts */
  165. int r_num_stale;
  166. int r_resend_mds; /* mds to resend to next, if any*/
  167. atomic_t r_ref;
  168. struct list_head r_wait;
  169. struct completion r_completion;
  170. struct completion r_safe_completion;
  171. ceph_mds_request_callback_t r_callback;
  172. struct list_head r_unsafe_item; /* per-session unsafe list item */
  173. bool r_got_unsafe, r_got_safe;
  174. bool r_did_prepopulate;
  175. u32 r_readdir_offset;
  176. struct ceph_cap_reservation r_caps_reservation;
  177. int r_num_caps;
  178. };
  179. /*
  180. * mds client state
  181. */
  182. struct ceph_mds_client {
  183. struct ceph_client *client;
  184. struct mutex mutex; /* all nested structures */
  185. struct ceph_mdsmap *mdsmap;
  186. struct completion safe_umount_waiters, session_close_waiters;
  187. struct list_head waiting_for_map;
  188. struct ceph_mds_session **sessions; /* NULL for mds if no session */
  189. int max_sessions; /* len of s_mds_sessions */
  190. int stopping; /* true if shutting down */
  191. /*
  192. * snap_rwsem will cover cap linkage into snaprealms, and
  193. * realm snap contexts. (later, we can do per-realm snap
  194. * contexts locks..) the empty list contains realms with no
  195. * references (implying they contain no inodes with caps) that
  196. * should be destroyed.
  197. */
  198. struct rw_semaphore snap_rwsem;
  199. struct radix_tree_root snap_realms;
  200. struct list_head snap_empty;
  201. spinlock_t snap_empty_lock; /* protect snap_empty */
  202. u64 last_tid; /* most recent mds request */
  203. struct radix_tree_root request_tree; /* pending mds requests */
  204. struct delayed_work delayed_work; /* delayed work */
  205. unsigned long last_renew_caps; /* last time we renewed our caps */
  206. struct list_head cap_delay_list; /* caps with delayed release */
  207. spinlock_t cap_delay_lock; /* protects cap_delay_list */
  208. struct list_head snap_flush_list; /* cap_snaps ready to flush */
  209. spinlock_t snap_flush_lock;
  210. u64 cap_flush_seq;
  211. struct list_head cap_dirty; /* inodes with dirty caps */
  212. int num_cap_flushing; /* # caps we are flushing */
  213. spinlock_t cap_dirty_lock; /* protects above items */
  214. wait_queue_head_t cap_flushing_wq;
  215. #ifdef CONFIG_DEBUG_FS
  216. struct dentry *debugfs_file;
  217. #endif
  218. spinlock_t dentry_lru_lock;
  219. struct list_head dentry_lru;
  220. int num_dentry;
  221. };
  222. extern const char *ceph_mds_op_name(int op);
  223. extern struct ceph_mds_session *
  224. __ceph_lookup_mds_session(struct ceph_mds_client *, int mds);
  225. static inline struct ceph_mds_session *
  226. ceph_get_mds_session(struct ceph_mds_session *s)
  227. {
  228. atomic_inc(&s->s_ref);
  229. return s;
  230. }
  231. extern void ceph_put_mds_session(struct ceph_mds_session *s);
  232. extern int ceph_send_msg_mds(struct ceph_mds_client *mdsc,
  233. struct ceph_msg *msg, int mds);
  234. extern void ceph_mdsc_init(struct ceph_mds_client *mdsc,
  235. struct ceph_client *client);
  236. extern void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc);
  237. extern void ceph_mdsc_stop(struct ceph_mds_client *mdsc);
  238. extern void ceph_mdsc_sync(struct ceph_mds_client *mdsc);
  239. extern void ceph_mdsc_lease_release(struct ceph_mds_client *mdsc,
  240. struct inode *inode,
  241. struct dentry *dn, int mask);
  242. extern struct ceph_mds_request *
  243. ceph_mdsc_create_request(struct ceph_mds_client *mdsc, int op, int mode);
  244. extern void ceph_mdsc_submit_request(struct ceph_mds_client *mdsc,
  245. struct ceph_mds_request *req);
  246. extern int ceph_mdsc_do_request(struct ceph_mds_client *mdsc,
  247. struct inode *dir,
  248. struct ceph_mds_request *req);
  249. static inline void ceph_mdsc_get_request(struct ceph_mds_request *req)
  250. {
  251. atomic_inc(&req->r_ref);
  252. }
  253. extern void ceph_mdsc_put_request(struct ceph_mds_request *req);
  254. extern void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc);
  255. extern char *ceph_mdsc_build_path(struct dentry *dentry, int *plen, u64 *base,
  256. int stop_on_nosnap);
  257. extern void __ceph_mdsc_drop_dentry_lease(struct dentry *dentry);
  258. extern void ceph_mdsc_lease_send_msg(struct ceph_mds_session *session,
  259. struct inode *inode,
  260. struct dentry *dentry, char action,
  261. u32 seq);
  262. extern void ceph_mdsc_handle_map(struct ceph_mds_client *mdsc,
  263. struct ceph_msg *msg);
  264. #endif