osd_client.h 8.1 KB

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