osd_client.h 11 KB

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