osd_client.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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 "types.h"
  8. #include "osdmap.h"
  9. #include "messenger.h"
  10. struct ceph_msg;
  11. struct ceph_snap_context;
  12. struct ceph_osd_request;
  13. struct ceph_osd_client;
  14. struct ceph_authorizer;
  15. struct ceph_pagelist;
  16. /*
  17. * completion callback for async writepages
  18. */
  19. typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *,
  20. struct ceph_msg *);
  21. /* a given osd we're communicating with */
  22. struct ceph_osd {
  23. atomic_t o_ref;
  24. struct ceph_osd_client *o_osdc;
  25. int o_osd;
  26. int o_incarnation;
  27. struct rb_node o_node;
  28. struct ceph_connection o_con;
  29. struct list_head o_requests;
  30. struct list_head o_linger_requests;
  31. struct list_head o_osd_lru;
  32. struct ceph_authorizer *o_authorizer;
  33. void *o_authorizer_buf, *o_authorizer_reply_buf;
  34. size_t o_authorizer_buf_len, o_authorizer_reply_buf_len;
  35. unsigned long lru_ttl;
  36. int o_marked_for_keepalive;
  37. struct list_head o_keepalive_item;
  38. };
  39. /* an in-flight request */
  40. struct ceph_osd_request {
  41. u64 r_tid; /* unique for this client */
  42. struct rb_node r_node;
  43. struct list_head r_req_lru_item;
  44. struct list_head r_osd_item;
  45. struct list_head r_linger_item;
  46. struct list_head r_linger_osd;
  47. struct ceph_osd *r_osd;
  48. struct ceph_pg r_pgid;
  49. int r_pg_osds[CEPH_PG_MAX_SIZE];
  50. int r_num_pg_osds;
  51. struct ceph_connection *r_con_filling_msg;
  52. struct ceph_msg *r_request, *r_reply;
  53. int r_result;
  54. int r_flags; /* any additional flags for the osd */
  55. u32 r_sent; /* >0 if r_request is sending/sent */
  56. int r_got_reply;
  57. int r_linger;
  58. struct ceph_osd_client *r_osdc;
  59. struct kref r_kref;
  60. bool r_mempool;
  61. struct completion r_completion, r_safe_completion;
  62. ceph_osdc_callback_t r_callback, r_safe_callback;
  63. struct ceph_eversion r_reassert_version;
  64. struct list_head r_unsafe_item;
  65. struct inode *r_inode; /* for use by callbacks */
  66. void *r_priv; /* ditto */
  67. char r_oid[40]; /* object name */
  68. int r_oid_len;
  69. unsigned long r_stamp; /* send OR check time */
  70. struct ceph_file_layout r_file_layout;
  71. struct ceph_snap_context *r_snapc; /* snap context for writes */
  72. unsigned r_num_pages; /* size of page array (follows) */
  73. unsigned r_page_alignment; /* io offset in first page */
  74. struct page **r_pages; /* pages for data payload */
  75. int r_pages_from_pool;
  76. int r_own_pages; /* if true, i own page list */
  77. #ifdef CONFIG_BLOCK
  78. struct bio *r_bio; /* instead of pages */
  79. #endif
  80. struct ceph_pagelist *r_trail; /* trailing part of the data */
  81. };
  82. struct ceph_osd_event {
  83. u64 cookie;
  84. int one_shot;
  85. struct ceph_osd_client *osdc;
  86. void (*cb)(u64, u64, u8, void *);
  87. void *data;
  88. struct rb_node node;
  89. struct list_head osd_node;
  90. struct kref kref;
  91. struct completion completion;
  92. };
  93. struct ceph_osd_event_work {
  94. struct work_struct work;
  95. struct ceph_osd_event *event;
  96. u64 ver;
  97. u64 notify_id;
  98. u8 opcode;
  99. };
  100. struct ceph_osd_client {
  101. struct ceph_client *client;
  102. struct ceph_osdmap *osdmap; /* current map */
  103. struct rw_semaphore map_sem;
  104. struct completion map_waiters;
  105. u64 last_requested_map;
  106. struct mutex request_mutex;
  107. struct rb_root osds; /* osds */
  108. struct list_head osd_lru; /* idle osds */
  109. u64 timeout_tid; /* tid of timeout triggering rq */
  110. u64 last_tid; /* tid of last request */
  111. struct rb_root requests; /* pending requests */
  112. struct list_head req_lru; /* in-flight lru */
  113. struct list_head req_unsent; /* unsent/need-resend queue */
  114. struct list_head req_notarget; /* map to no osd */
  115. struct list_head req_linger; /* lingering requests */
  116. int num_requests;
  117. struct delayed_work timeout_work;
  118. struct delayed_work osds_timeout_work;
  119. #ifdef CONFIG_DEBUG_FS
  120. struct dentry *debugfs_file;
  121. #endif
  122. mempool_t *req_mempool;
  123. struct ceph_msgpool msgpool_op;
  124. struct ceph_msgpool msgpool_op_reply;
  125. spinlock_t event_lock;
  126. struct rb_root event_tree;
  127. u64 event_count;
  128. struct workqueue_struct *notify_wq;
  129. };
  130. struct ceph_osd_req_op {
  131. u16 op; /* CEPH_OSD_OP_* */
  132. u32 flags; /* CEPH_OSD_FLAG_* */
  133. union {
  134. struct {
  135. u64 offset, length;
  136. u64 truncate_size;
  137. u32 truncate_seq;
  138. } extent;
  139. struct {
  140. const char *name;
  141. u32 name_len;
  142. const char *val;
  143. u32 value_len;
  144. __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
  145. __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
  146. } xattr;
  147. struct {
  148. const char *class_name;
  149. __u8 class_len;
  150. const char *method_name;
  151. __u8 method_len;
  152. __u8 argc;
  153. const char *indata;
  154. u32 indata_len;
  155. } cls;
  156. struct {
  157. u64 cookie, count;
  158. } pgls;
  159. struct {
  160. u64 snapid;
  161. } snap;
  162. struct {
  163. u64 cookie;
  164. u64 ver;
  165. __u8 flag;
  166. u32 prot_ver;
  167. u32 timeout;
  168. } watch;
  169. };
  170. u32 payload_len;
  171. };
  172. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  173. struct ceph_client *client);
  174. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  175. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  176. struct ceph_msg *msg);
  177. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  178. struct ceph_msg *msg);
  179. extern void ceph_calc_raw_layout(struct ceph_osd_client *osdc,
  180. struct ceph_file_layout *layout,
  181. u64 snapid,
  182. u64 off, u64 *plen, u64 *bno,
  183. struct ceph_osd_request *req,
  184. struct ceph_osd_req_op *op);
  185. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  186. int flags,
  187. struct ceph_snap_context *snapc,
  188. struct ceph_osd_req_op *ops,
  189. bool use_mempool,
  190. gfp_t gfp_flags,
  191. struct page **pages,
  192. struct bio *bio);
  193. extern void ceph_osdc_build_request(struct ceph_osd_request *req,
  194. u64 off, u64 *plen,
  195. struct ceph_osd_req_op *src_ops,
  196. struct ceph_snap_context *snapc,
  197. struct timespec *mtime,
  198. const char *oid,
  199. int oid_len);
  200. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  201. struct ceph_file_layout *layout,
  202. struct ceph_vino vino,
  203. u64 offset, u64 *len, int op, int flags,
  204. struct ceph_snap_context *snapc,
  205. int do_sync, u32 truncate_seq,
  206. u64 truncate_size,
  207. struct timespec *mtime,
  208. bool use_mempool, int num_reply,
  209. int page_align);
  210. extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
  211. struct ceph_osd_request *req);
  212. extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
  213. struct ceph_osd_request *req);
  214. static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
  215. {
  216. kref_get(&req->r_kref);
  217. }
  218. extern void ceph_osdc_release_request(struct kref *kref);
  219. static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
  220. {
  221. kref_put(&req->r_kref, ceph_osdc_release_request);
  222. }
  223. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  224. struct ceph_osd_request *req,
  225. bool nofail);
  226. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  227. struct ceph_osd_request *req);
  228. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  229. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  230. struct ceph_vino vino,
  231. struct ceph_file_layout *layout,
  232. u64 off, u64 *plen,
  233. u32 truncate_seq, u64 truncate_size,
  234. struct page **pages, int nr_pages,
  235. int page_align);
  236. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  237. struct ceph_vino vino,
  238. struct ceph_file_layout *layout,
  239. struct ceph_snap_context *sc,
  240. u64 off, u64 len,
  241. u32 truncate_seq, u64 truncate_size,
  242. struct timespec *mtime,
  243. struct page **pages, int nr_pages,
  244. int flags, int do_sync, bool nofail);
  245. /* watch/notify events */
  246. extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
  247. void (*event_cb)(u64, u64, u8, void *),
  248. int one_shot, void *data,
  249. struct ceph_osd_event **pevent);
  250. extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
  251. extern int ceph_osdc_wait_event(struct ceph_osd_event *event,
  252. unsigned long timeout);
  253. extern void ceph_osdc_put_event(struct ceph_osd_event *event);
  254. #endif