osd_client.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. bool r_resend; /* msg send failed, needs retry */
  67. struct ceph_file_layout r_file_layout;
  68. struct ceph_snap_context *r_snapc; /* snap context for writes */
  69. unsigned r_num_pages; /* size of page array (follows) */
  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; /* pending requests lru */
  91. int num_requests;
  92. struct delayed_work timeout_work;
  93. struct delayed_work osds_timeout_work;
  94. #ifdef CONFIG_DEBUG_FS
  95. struct dentry *debugfs_file;
  96. #endif
  97. mempool_t *req_mempool;
  98. struct ceph_msgpool msgpool_op;
  99. struct ceph_msgpool msgpool_op_reply;
  100. };
  101. struct ceph_osd_req_op {
  102. u16 op; /* CEPH_OSD_OP_* */
  103. u32 flags; /* CEPH_OSD_FLAG_* */
  104. union {
  105. struct {
  106. u64 offset, length;
  107. u64 truncate_size;
  108. u32 truncate_seq;
  109. } extent;
  110. struct {
  111. const char *name;
  112. u32 name_len;
  113. const char *val;
  114. u32 value_len;
  115. __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
  116. __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
  117. } xattr;
  118. struct {
  119. const char *class_name;
  120. __u8 class_len;
  121. const char *method_name;
  122. __u8 method_len;
  123. __u8 argc;
  124. const char *indata;
  125. u32 indata_len;
  126. } cls;
  127. struct {
  128. u64 cookie, count;
  129. } pgls;
  130. struct {
  131. u64 snapid;
  132. } snap;
  133. };
  134. u32 payload_len;
  135. };
  136. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  137. struct ceph_client *client);
  138. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  139. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  140. struct ceph_msg *msg);
  141. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  142. struct ceph_msg *msg);
  143. extern void ceph_calc_raw_layout(struct ceph_osd_client *osdc,
  144. struct ceph_file_layout *layout,
  145. u64 snapid,
  146. u64 off, u64 *plen, u64 *bno,
  147. struct ceph_osd_request *req,
  148. struct ceph_osd_req_op *op);
  149. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  150. int flags,
  151. struct ceph_snap_context *snapc,
  152. struct ceph_osd_req_op *ops,
  153. bool use_mempool,
  154. gfp_t gfp_flags,
  155. struct page **pages,
  156. struct bio *bio);
  157. extern void ceph_osdc_build_request(struct ceph_osd_request *req,
  158. u64 off, u64 *plen,
  159. struct ceph_osd_req_op *src_ops,
  160. struct ceph_snap_context *snapc,
  161. struct timespec *mtime,
  162. const char *oid,
  163. int oid_len);
  164. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  165. struct ceph_file_layout *layout,
  166. struct ceph_vino vino,
  167. u64 offset, u64 *len, int op, int flags,
  168. struct ceph_snap_context *snapc,
  169. int do_sync, u32 truncate_seq,
  170. u64 truncate_size,
  171. struct timespec *mtime,
  172. bool use_mempool, int num_reply);
  173. static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
  174. {
  175. kref_get(&req->r_kref);
  176. }
  177. extern void ceph_osdc_release_request(struct kref *kref);
  178. static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
  179. {
  180. kref_put(&req->r_kref, ceph_osdc_release_request);
  181. }
  182. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  183. struct ceph_osd_request *req,
  184. bool nofail);
  185. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  186. struct ceph_osd_request *req);
  187. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  188. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  189. struct ceph_vino vino,
  190. struct ceph_file_layout *layout,
  191. u64 off, u64 *plen,
  192. u32 truncate_seq, u64 truncate_size,
  193. struct page **pages, int nr_pages);
  194. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  195. struct ceph_vino vino,
  196. struct ceph_file_layout *layout,
  197. struct ceph_snap_context *sc,
  198. u64 off, u64 len,
  199. u32 truncate_seq, u64 truncate_size,
  200. struct timespec *mtime,
  201. struct page **pages, int nr_pages,
  202. int flags, int do_sync, bool nofail);
  203. #endif