osd_client.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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 3
  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 flags; /* CEPH_OSD_OP_FLAG_* */
  70. u32 payload_len;
  71. union {
  72. struct ceph_osd_data raw_data_in;
  73. struct {
  74. u64 offset, length;
  75. u64 truncate_size;
  76. u32 truncate_seq;
  77. struct ceph_osd_data osd_data;
  78. } extent;
  79. struct {
  80. const char *class_name;
  81. const char *method_name;
  82. struct ceph_osd_data request_info;
  83. struct ceph_osd_data request_data;
  84. struct ceph_osd_data response_data;
  85. __u8 class_len;
  86. __u8 method_len;
  87. __u8 argc;
  88. } cls;
  89. struct {
  90. u64 cookie;
  91. u64 ver;
  92. u32 prot_ver;
  93. u32 timeout;
  94. __u8 flag;
  95. } watch;
  96. struct {
  97. u64 expected_object_size;
  98. u64 expected_write_size;
  99. } alloc_hint;
  100. };
  101. };
  102. /* an in-flight request */
  103. struct ceph_osd_request {
  104. u64 r_tid; /* unique for this client */
  105. struct rb_node r_node;
  106. struct list_head r_req_lru_item;
  107. struct list_head r_osd_item;
  108. struct list_head r_linger_item;
  109. struct list_head r_linger_osd_item;
  110. struct ceph_osd *r_osd;
  111. struct ceph_pg r_pgid;
  112. int r_pg_osds[CEPH_PG_MAX_SIZE];
  113. int r_num_pg_osds;
  114. struct ceph_msg *r_request, *r_reply;
  115. int r_flags; /* any additional flags for the osd */
  116. u32 r_sent; /* >0 if r_request is sending/sent */
  117. /* request osd ops array */
  118. unsigned int r_num_ops;
  119. struct ceph_osd_req_op r_ops[CEPH_OSD_MAX_OP];
  120. /* these are updated on each send */
  121. __le32 *r_request_osdmap_epoch;
  122. __le32 *r_request_flags;
  123. __le64 *r_request_pool;
  124. void *r_request_pgid;
  125. __le32 *r_request_attempts;
  126. bool r_paused;
  127. struct ceph_eversion *r_request_reassert_version;
  128. int r_result;
  129. int r_reply_op_len[CEPH_OSD_MAX_OP];
  130. s32 r_reply_op_result[CEPH_OSD_MAX_OP];
  131. int r_got_reply;
  132. int r_linger;
  133. struct ceph_osd_client *r_osdc;
  134. struct kref r_kref;
  135. bool r_mempool;
  136. struct completion r_completion, r_safe_completion;
  137. ceph_osdc_callback_t r_callback;
  138. ceph_osdc_unsafe_callback_t r_unsafe_callback;
  139. struct ceph_eversion r_reassert_version;
  140. struct list_head r_unsafe_item;
  141. struct inode *r_inode; /* for use by callbacks */
  142. void *r_priv; /* ditto */
  143. struct ceph_object_locator r_base_oloc;
  144. struct ceph_object_id r_base_oid;
  145. struct ceph_object_locator r_target_oloc;
  146. struct ceph_object_id r_target_oid;
  147. u64 r_snapid;
  148. unsigned long r_stamp; /* send OR check time */
  149. struct ceph_snap_context *r_snapc; /* snap context for writes */
  150. };
  151. struct ceph_request_redirect {
  152. struct ceph_object_locator oloc;
  153. };
  154. struct ceph_osd_event {
  155. u64 cookie;
  156. int one_shot;
  157. struct ceph_osd_client *osdc;
  158. void (*cb)(u64, u64, u8, void *);
  159. void *data;
  160. struct rb_node node;
  161. struct list_head osd_node;
  162. struct kref kref;
  163. };
  164. struct ceph_osd_event_work {
  165. struct work_struct work;
  166. struct ceph_osd_event *event;
  167. u64 ver;
  168. u64 notify_id;
  169. u8 opcode;
  170. };
  171. struct ceph_osd_client {
  172. struct ceph_client *client;
  173. struct ceph_osdmap *osdmap; /* current map */
  174. struct rw_semaphore map_sem;
  175. struct completion map_waiters;
  176. u64 last_requested_map;
  177. struct mutex request_mutex;
  178. struct rb_root osds; /* osds */
  179. struct list_head osd_lru; /* idle osds */
  180. u64 timeout_tid; /* tid of timeout triggering rq */
  181. u64 last_tid; /* tid of last request */
  182. struct rb_root requests; /* pending requests */
  183. struct list_head req_lru; /* in-flight lru */
  184. struct list_head req_unsent; /* unsent/need-resend queue */
  185. struct list_head req_notarget; /* map to no osd */
  186. struct list_head req_linger; /* lingering requests */
  187. int num_requests;
  188. struct delayed_work timeout_work;
  189. struct delayed_work osds_timeout_work;
  190. #ifdef CONFIG_DEBUG_FS
  191. struct dentry *debugfs_file;
  192. #endif
  193. mempool_t *req_mempool;
  194. struct ceph_msgpool msgpool_op;
  195. struct ceph_msgpool msgpool_op_reply;
  196. spinlock_t event_lock;
  197. struct rb_root event_tree;
  198. u64 event_count;
  199. struct workqueue_struct *notify_wq;
  200. };
  201. extern int ceph_osdc_setup(void);
  202. extern void ceph_osdc_cleanup(void);
  203. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  204. struct ceph_client *client);
  205. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  206. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  207. struct ceph_msg *msg);
  208. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  209. struct ceph_msg *msg);
  210. extern void osd_req_op_init(struct ceph_osd_request *osd_req,
  211. unsigned int which, u16 opcode);
  212. extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
  213. unsigned int which,
  214. struct page **pages, u64 length,
  215. u32 alignment, bool pages_from_pool,
  216. bool own_pages);
  217. extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
  218. unsigned int which, u16 opcode,
  219. u64 offset, u64 length,
  220. u64 truncate_size, u32 truncate_seq);
  221. extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
  222. unsigned int which, u64 length);
  223. extern struct ceph_osd_data *osd_req_op_extent_osd_data(
  224. struct ceph_osd_request *osd_req,
  225. unsigned int which);
  226. extern struct ceph_osd_data *osd_req_op_cls_response_data(
  227. struct ceph_osd_request *osd_req,
  228. unsigned int which);
  229. extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
  230. unsigned int which,
  231. struct page **pages, u64 length,
  232. u32 alignment, bool pages_from_pool,
  233. bool own_pages);
  234. extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
  235. unsigned int which,
  236. struct ceph_pagelist *pagelist);
  237. #ifdef CONFIG_BLOCK
  238. extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
  239. unsigned int which,
  240. struct bio *bio, size_t bio_length);
  241. #endif /* CONFIG_BLOCK */
  242. extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
  243. unsigned int which,
  244. struct ceph_pagelist *pagelist);
  245. extern void osd_req_op_cls_request_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_response_data_pages(struct ceph_osd_request *,
  251. unsigned int which,
  252. struct page **pages, u64 length,
  253. u32 alignment, bool pages_from_pool,
  254. bool own_pages);
  255. extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
  256. unsigned int which, u16 opcode,
  257. const char *class, const char *method);
  258. extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
  259. unsigned int which, u16 opcode,
  260. u64 cookie, u64 version, int flag);
  261. extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
  262. unsigned int which,
  263. u64 expected_object_size,
  264. u64 expected_write_size);
  265. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  266. struct ceph_snap_context *snapc,
  267. unsigned int num_ops,
  268. bool use_mempool,
  269. gfp_t gfp_flags);
  270. extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
  271. struct ceph_snap_context *snapc,
  272. u64 snap_id,
  273. struct timespec *mtime);
  274. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  275. struct ceph_file_layout *layout,
  276. struct ceph_vino vino,
  277. u64 offset, u64 *len,
  278. int num_ops, int opcode, int flags,
  279. struct ceph_snap_context *snapc,
  280. u32 truncate_seq, u64 truncate_size,
  281. bool use_mempool);
  282. extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
  283. struct ceph_osd_request *req);
  284. extern void ceph_osdc_get_request(struct ceph_osd_request *req);
  285. extern void ceph_osdc_put_request(struct ceph_osd_request *req);
  286. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  287. struct ceph_osd_request *req,
  288. bool nofail);
  289. extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
  290. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  291. struct ceph_osd_request *req);
  292. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  293. extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
  294. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  295. struct ceph_vino vino,
  296. struct ceph_file_layout *layout,
  297. u64 off, u64 *plen,
  298. u32 truncate_seq, u64 truncate_size,
  299. struct page **pages, int nr_pages,
  300. int page_align);
  301. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  302. struct ceph_vino vino,
  303. struct ceph_file_layout *layout,
  304. struct ceph_snap_context *sc,
  305. u64 off, u64 len,
  306. u32 truncate_seq, u64 truncate_size,
  307. struct timespec *mtime,
  308. struct page **pages, int nr_pages);
  309. /* watch/notify events */
  310. extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
  311. void (*event_cb)(u64, u64, u8, void *),
  312. void *data, struct ceph_osd_event **pevent);
  313. extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
  314. extern void ceph_osdc_put_event(struct ceph_osd_event *event);
  315. #endif