osd_client.h 8.6 KB

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