osd_client.h 11 KB

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