osd_client.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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_osd_lru;
  31. struct ceph_authorizer *o_authorizer;
  32. void *o_authorizer_buf, *o_authorizer_reply_buf;
  33. size_t o_authorizer_buf_len, o_authorizer_reply_buf_len;
  34. unsigned long lru_ttl;
  35. int o_marked_for_keepalive;
  36. struct list_head o_keepalive_item;
  37. };
  38. /* an in-flight request */
  39. struct ceph_osd_request {
  40. u64 r_tid; /* unique for this client */
  41. struct rb_node r_node;
  42. struct list_head r_req_lru_item;
  43. struct list_head r_osd_item;
  44. struct ceph_osd *r_osd;
  45. struct ceph_pg r_pgid;
  46. int r_pg_osds[CEPH_PG_MAX_SIZE];
  47. int r_num_pg_osds;
  48. struct ceph_connection *r_con_filling_msg;
  49. struct ceph_msg *r_request, *r_reply;
  50. int r_result;
  51. int r_flags; /* any additional flags for the osd */
  52. u32 r_sent; /* >0 if r_request is sending/sent */
  53. int r_got_reply;
  54. struct ceph_osd_client *r_osdc;
  55. struct kref r_kref;
  56. bool r_mempool;
  57. struct completion r_completion, r_safe_completion;
  58. ceph_osdc_callback_t r_callback, r_safe_callback;
  59. struct ceph_eversion r_reassert_version;
  60. struct list_head r_unsafe_item;
  61. struct inode *r_inode; /* for use by callbacks */
  62. void *r_priv; /* ditto */
  63. char r_oid[40]; /* object name */
  64. int r_oid_len;
  65. unsigned long r_stamp; /* send OR check time */
  66. struct ceph_file_layout r_file_layout;
  67. struct ceph_snap_context *r_snapc; /* snap context for writes */
  68. unsigned r_num_pages; /* size of page array (follows) */
  69. unsigned r_page_alignment; /* io offset in first page */
  70. struct page **r_pages; /* pages for data payload */
  71. int r_pages_from_pool;
  72. int r_own_pages; /* if true, i own page list */
  73. #ifdef CONFIG_BLOCK
  74. struct bio *r_bio; /* instead of pages */
  75. #endif
  76. struct ceph_pagelist *r_trail; /* trailing part of the data */
  77. };
  78. struct ceph_osd_client {
  79. struct ceph_client *client;
  80. struct ceph_osdmap *osdmap; /* current map */
  81. struct rw_semaphore map_sem;
  82. struct completion map_waiters;
  83. u64 last_requested_map;
  84. struct mutex request_mutex;
  85. struct rb_root osds; /* osds */
  86. struct list_head osd_lru; /* idle osds */
  87. u64 timeout_tid; /* tid of timeout triggering rq */
  88. u64 last_tid; /* tid of last request */
  89. struct rb_root requests; /* pending requests */
  90. struct list_head req_lru; /* in-flight lru */
  91. struct list_head req_unsent; /* unsent/need-resend queue */
  92. struct list_head req_notarget; /* map to no osd */
  93. int num_requests;
  94. struct delayed_work timeout_work;
  95. struct delayed_work osds_timeout_work;
  96. #ifdef CONFIG_DEBUG_FS
  97. struct dentry *debugfs_file;
  98. #endif
  99. mempool_t *req_mempool;
  100. struct ceph_msgpool msgpool_op;
  101. struct ceph_msgpool msgpool_op_reply;
  102. };
  103. struct ceph_osd_req_op {
  104. u16 op; /* CEPH_OSD_OP_* */
  105. u32 flags; /* CEPH_OSD_FLAG_* */
  106. union {
  107. struct {
  108. u64 offset, length;
  109. u64 truncate_size;
  110. u32 truncate_seq;
  111. } extent;
  112. struct {
  113. const char *name;
  114. u32 name_len;
  115. const char *val;
  116. u32 value_len;
  117. __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
  118. __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
  119. } xattr;
  120. struct {
  121. const char *class_name;
  122. __u8 class_len;
  123. const char *method_name;
  124. __u8 method_len;
  125. __u8 argc;
  126. const char *indata;
  127. u32 indata_len;
  128. } cls;
  129. struct {
  130. u64 cookie, count;
  131. } pgls;
  132. struct {
  133. u64 snapid;
  134. } snap;
  135. };
  136. u32 payload_len;
  137. };
  138. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  139. struct ceph_client *client);
  140. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  141. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  142. struct ceph_msg *msg);
  143. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  144. struct ceph_msg *msg);
  145. extern void ceph_calc_raw_layout(struct ceph_osd_client *osdc,
  146. struct ceph_file_layout *layout,
  147. u64 snapid,
  148. u64 off, u64 *plen, u64 *bno,
  149. struct ceph_osd_request *req,
  150. struct ceph_osd_req_op *op);
  151. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  152. int flags,
  153. struct ceph_snap_context *snapc,
  154. struct ceph_osd_req_op *ops,
  155. bool use_mempool,
  156. gfp_t gfp_flags,
  157. struct page **pages,
  158. struct bio *bio);
  159. extern void ceph_osdc_build_request(struct ceph_osd_request *req,
  160. u64 off, u64 *plen,
  161. struct ceph_osd_req_op *src_ops,
  162. struct ceph_snap_context *snapc,
  163. struct timespec *mtime,
  164. const char *oid,
  165. int oid_len);
  166. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  167. struct ceph_file_layout *layout,
  168. struct ceph_vino vino,
  169. u64 offset, u64 *len, int op, int flags,
  170. struct ceph_snap_context *snapc,
  171. int do_sync, u32 truncate_seq,
  172. u64 truncate_size,
  173. struct timespec *mtime,
  174. bool use_mempool, int num_reply,
  175. int page_align);
  176. static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
  177. {
  178. kref_get(&req->r_kref);
  179. }
  180. extern void ceph_osdc_release_request(struct kref *kref);
  181. static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
  182. {
  183. kref_put(&req->r_kref, ceph_osdc_release_request);
  184. }
  185. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  186. struct ceph_osd_request *req,
  187. bool nofail);
  188. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  189. struct ceph_osd_request *req);
  190. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  191. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  192. struct ceph_vino vino,
  193. struct ceph_file_layout *layout,
  194. u64 off, u64 *plen,
  195. u32 truncate_seq, u64 truncate_size,
  196. struct page **pages, int nr_pages,
  197. int page_align);
  198. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  199. struct ceph_vino vino,
  200. struct ceph_file_layout *layout,
  201. struct ceph_snap_context *sc,
  202. u64 off, u64 len,
  203. u32 truncate_seq, u64 truncate_size,
  204. struct timespec *mtime,
  205. struct page **pages, int nr_pages,
  206. int flags, int do_sync, bool nofail);
  207. #endif