osd_client.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. #ifndef _FS_CEPH_OSD_CLIENT_H
  2. #define _FS_CEPH_OSD_CLIENT_H
  3. #include <linux/completion.h>
  4. #include <linux/kref.h>
  5. #include <linux/mempool.h>
  6. #include <linux/rbtree.h>
  7. #include <linux/ceph/types.h>
  8. #include <linux/ceph/osdmap.h>
  9. #include <linux/ceph/messenger.h>
  10. #include <linux/ceph/auth.h>
  11. #include <linux/ceph/pagelist.h>
  12. struct ceph_msg;
  13. struct ceph_snap_context;
  14. struct ceph_osd_request;
  15. struct ceph_osd_client;
  16. struct ceph_authorizer;
  17. /*
  18. * completion callback for async writepages
  19. */
  20. typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *,
  21. struct ceph_msg *);
  22. typedef void (*ceph_osdc_unsafe_callback_t)(struct ceph_osd_request *, bool);
  23. /* a given osd we're communicating with */
  24. struct ceph_osd {
  25. atomic_t o_ref;
  26. struct ceph_osd_client *o_osdc;
  27. int o_osd;
  28. int o_incarnation;
  29. struct rb_node o_node;
  30. struct ceph_connection o_con;
  31. struct list_head o_requests;
  32. struct list_head o_linger_requests;
  33. struct list_head o_osd_lru;
  34. struct ceph_auth_handshake o_auth;
  35. unsigned long lru_ttl;
  36. int o_marked_for_keepalive;
  37. struct list_head o_keepalive_item;
  38. };
  39. #define CEPH_OSD_MAX_OP 2
  40. enum ceph_osd_data_type {
  41. CEPH_OSD_DATA_TYPE_NONE = 0,
  42. CEPH_OSD_DATA_TYPE_PAGES,
  43. CEPH_OSD_DATA_TYPE_PAGELIST,
  44. #ifdef CONFIG_BLOCK
  45. CEPH_OSD_DATA_TYPE_BIO,
  46. #endif /* CONFIG_BLOCK */
  47. };
  48. struct ceph_osd_data {
  49. enum ceph_osd_data_type type;
  50. union {
  51. struct {
  52. struct page **pages;
  53. u64 length;
  54. u32 alignment;
  55. bool pages_from_pool;
  56. bool own_pages;
  57. };
  58. struct ceph_pagelist *pagelist;
  59. #ifdef CONFIG_BLOCK
  60. struct {
  61. struct bio *bio; /* list of bios */
  62. size_t bio_length; /* total in list */
  63. };
  64. #endif /* CONFIG_BLOCK */
  65. };
  66. };
  67. struct ceph_osd_req_op {
  68. u16 op; /* CEPH_OSD_OP_* */
  69. u32 payload_len;
  70. union {
  71. struct ceph_osd_data raw_data_in;
  72. struct {
  73. u64 offset, length;
  74. u64 truncate_size;
  75. u32 truncate_seq;
  76. struct ceph_osd_data osd_data;
  77. } extent;
  78. struct {
  79. const char *class_name;
  80. const char *method_name;
  81. struct ceph_osd_data request_info;
  82. struct ceph_osd_data request_data;
  83. struct ceph_osd_data response_data;
  84. __u8 class_len;
  85. __u8 method_len;
  86. __u8 argc;
  87. } cls;
  88. struct {
  89. u64 cookie;
  90. u64 ver;
  91. u32 prot_ver;
  92. u32 timeout;
  93. __u8 flag;
  94. } watch;
  95. };
  96. };
  97. /* an in-flight request */
  98. struct ceph_osd_request {
  99. u64 r_tid; /* unique for this client */
  100. struct rb_node r_node;
  101. struct list_head r_req_lru_item;
  102. struct list_head r_osd_item;
  103. struct list_head r_linger_item;
  104. struct list_head r_linger_osd;
  105. struct ceph_osd *r_osd;
  106. struct ceph_pg r_pgid;
  107. int r_pg_osds[CEPH_PG_MAX_SIZE];
  108. int r_num_pg_osds;
  109. struct ceph_msg *r_request, *r_reply;
  110. int r_flags; /* any additional flags for the osd */
  111. u32 r_sent; /* >0 if r_request is sending/sent */
  112. /* request osd ops array */
  113. unsigned int r_num_ops;
  114. struct ceph_osd_req_op r_ops[CEPH_OSD_MAX_OP];
  115. /* these are updated on each send */
  116. __le32 *r_request_osdmap_epoch;
  117. __le32 *r_request_flags;
  118. __le64 *r_request_pool;
  119. void *r_request_pgid;
  120. __le32 *r_request_attempts;
  121. bool r_paused;
  122. struct ceph_eversion *r_request_reassert_version;
  123. int r_result;
  124. int r_reply_op_len[CEPH_OSD_MAX_OP];
  125. s32 r_reply_op_result[CEPH_OSD_MAX_OP];
  126. int r_got_reply;
  127. int r_linger;
  128. struct ceph_osd_client *r_osdc;
  129. struct kref r_kref;
  130. bool r_mempool;
  131. struct completion r_completion, r_safe_completion;
  132. ceph_osdc_callback_t r_callback;
  133. ceph_osdc_unsafe_callback_t r_unsafe_callback;
  134. struct ceph_eversion r_reassert_version;
  135. struct list_head r_unsafe_item;
  136. struct inode *r_inode; /* for use by callbacks */
  137. void *r_priv; /* ditto */
  138. struct ceph_object_locator r_base_oloc;
  139. struct ceph_object_id r_base_oid;
  140. struct ceph_object_locator r_target_oloc;
  141. struct ceph_object_id r_target_oid;
  142. u64 r_snapid;
  143. unsigned long r_stamp; /* send OR check time */
  144. struct ceph_snap_context *r_snapc; /* snap context for writes */
  145. };
  146. struct ceph_request_redirect {
  147. struct ceph_object_locator oloc;
  148. };
  149. struct ceph_osd_event {
  150. u64 cookie;
  151. int one_shot;
  152. struct ceph_osd_client *osdc;
  153. void (*cb)(u64, u64, u8, void *);
  154. void *data;
  155. struct rb_node node;
  156. struct list_head osd_node;
  157. struct kref kref;
  158. };
  159. struct ceph_osd_event_work {
  160. struct work_struct work;
  161. struct ceph_osd_event *event;
  162. u64 ver;
  163. u64 notify_id;
  164. u8 opcode;
  165. };
  166. struct ceph_osd_client {
  167. struct ceph_client *client;
  168. struct ceph_osdmap *osdmap; /* current map */
  169. struct rw_semaphore map_sem;
  170. struct completion map_waiters;
  171. u64 last_requested_map;
  172. struct mutex request_mutex;
  173. struct rb_root osds; /* osds */
  174. struct list_head osd_lru; /* idle osds */
  175. u64 timeout_tid; /* tid of timeout triggering rq */
  176. u64 last_tid; /* tid of last request */
  177. struct rb_root requests; /* pending requests */
  178. struct list_head req_lru; /* in-flight lru */
  179. struct list_head req_unsent; /* unsent/need-resend queue */
  180. struct list_head req_notarget; /* map to no osd */
  181. struct list_head req_linger; /* lingering requests */
  182. int num_requests;
  183. struct delayed_work timeout_work;
  184. struct delayed_work osds_timeout_work;
  185. #ifdef CONFIG_DEBUG_FS
  186. struct dentry *debugfs_file;
  187. #endif
  188. mempool_t *req_mempool;
  189. struct ceph_msgpool msgpool_op;
  190. struct ceph_msgpool msgpool_op_reply;
  191. spinlock_t event_lock;
  192. struct rb_root event_tree;
  193. u64 event_count;
  194. struct workqueue_struct *notify_wq;
  195. };
  196. extern int ceph_osdc_setup(void);
  197. extern void ceph_osdc_cleanup(void);
  198. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  199. struct ceph_client *client);
  200. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  201. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  202. struct ceph_msg *msg);
  203. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  204. struct ceph_msg *msg);
  205. extern void osd_req_op_init(struct ceph_osd_request *osd_req,
  206. unsigned int which, u16 opcode);
  207. extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
  208. unsigned int which,
  209. struct page **pages, u64 length,
  210. u32 alignment, bool pages_from_pool,
  211. bool own_pages);
  212. extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
  213. unsigned int which, u16 opcode,
  214. u64 offset, u64 length,
  215. u64 truncate_size, u32 truncate_seq);
  216. extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
  217. unsigned int which, u64 length);
  218. extern struct ceph_osd_data *osd_req_op_extent_osd_data(
  219. struct ceph_osd_request *osd_req,
  220. unsigned int which);
  221. extern struct ceph_osd_data *osd_req_op_cls_response_data(
  222. struct ceph_osd_request *osd_req,
  223. unsigned int which);
  224. extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
  225. unsigned int which,
  226. struct page **pages, u64 length,
  227. u32 alignment, bool pages_from_pool,
  228. bool own_pages);
  229. extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
  230. unsigned int which,
  231. struct ceph_pagelist *pagelist);
  232. #ifdef CONFIG_BLOCK
  233. extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
  234. unsigned int which,
  235. struct bio *bio, size_t bio_length);
  236. #endif /* CONFIG_BLOCK */
  237. extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
  238. unsigned int which,
  239. struct ceph_pagelist *pagelist);
  240. extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
  241. unsigned int which,
  242. struct page **pages, u64 length,
  243. u32 alignment, bool pages_from_pool,
  244. bool own_pages);
  245. extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
  246. unsigned int which,
  247. struct page **pages, u64 length,
  248. u32 alignment, bool pages_from_pool,
  249. bool own_pages);
  250. extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
  251. unsigned int which, u16 opcode,
  252. const char *class, const char *method);
  253. extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
  254. unsigned int which, u16 opcode,
  255. u64 cookie, u64 version, int flag);
  256. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  257. struct ceph_snap_context *snapc,
  258. unsigned int num_ops,
  259. bool use_mempool,
  260. gfp_t gfp_flags);
  261. extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
  262. struct ceph_snap_context *snapc,
  263. u64 snap_id,
  264. struct timespec *mtime);
  265. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  266. struct ceph_file_layout *layout,
  267. struct ceph_vino vino,
  268. u64 offset, u64 *len,
  269. int num_ops, int opcode, int flags,
  270. struct ceph_snap_context *snapc,
  271. u32 truncate_seq, u64 truncate_size,
  272. bool use_mempool);
  273. extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
  274. struct ceph_osd_request *req);
  275. extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
  276. struct ceph_osd_request *req);
  277. static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
  278. {
  279. kref_get(&req->r_kref);
  280. }
  281. extern void ceph_osdc_release_request(struct kref *kref);
  282. static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
  283. {
  284. kref_put(&req->r_kref, ceph_osdc_release_request);
  285. }
  286. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  287. struct ceph_osd_request *req,
  288. bool nofail);
  289. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  290. struct ceph_osd_request *req);
  291. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  292. extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
  293. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  294. struct ceph_vino vino,
  295. struct ceph_file_layout *layout,
  296. u64 off, u64 *plen,
  297. u32 truncate_seq, u64 truncate_size,
  298. struct page **pages, int nr_pages,
  299. int page_align);
  300. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  301. struct ceph_vino vino,
  302. struct ceph_file_layout *layout,
  303. struct ceph_snap_context *sc,
  304. u64 off, u64 len,
  305. u32 truncate_seq, u64 truncate_size,
  306. struct timespec *mtime,
  307. struct page **pages, int nr_pages);
  308. /* watch/notify events */
  309. extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
  310. void (*event_cb)(u64, u64, u8, void *),
  311. void *data, struct ceph_osd_event **pevent);
  312. extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
  313. extern void ceph_osdc_put_event(struct ceph_osd_event *event);
  314. #endif