osd_client.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. #define CEPH_OSD_MAX_OP 10
  44. enum ceph_osd_data_type {
  45. CEPH_OSD_DATA_TYPE_NONE,
  46. CEPH_OSD_DATA_TYPE_PAGES,
  47. CEPH_OSD_DATA_TYPE_PAGELIST,
  48. #ifdef CONFIG_BLOCK
  49. CEPH_OSD_DATA_TYPE_BIO,
  50. #endif /* CONFIG_BLOCK */
  51. };
  52. struct ceph_osd_data {
  53. enum ceph_osd_data_type type;
  54. union {
  55. struct {
  56. struct page **pages;
  57. u64 length;
  58. u32 alignment;
  59. bool pages_from_pool;
  60. bool own_pages;
  61. };
  62. struct ceph_pagelist *pagelist;
  63. #ifdef CONFIG_BLOCK
  64. struct {
  65. struct bio *bio; /* list of bios */
  66. size_t bio_length; /* total in list */
  67. };
  68. #endif /* CONFIG_BLOCK */
  69. };
  70. };
  71. /* an in-flight request */
  72. struct ceph_osd_request {
  73. u64 r_tid; /* unique for this client */
  74. struct rb_node r_node;
  75. struct list_head r_req_lru_item;
  76. struct list_head r_osd_item;
  77. struct list_head r_linger_item;
  78. struct list_head r_linger_osd;
  79. struct ceph_osd *r_osd;
  80. struct ceph_pg r_pgid;
  81. int r_pg_osds[CEPH_PG_MAX_SIZE];
  82. int r_num_pg_osds;
  83. struct ceph_msg *r_request, *r_reply;
  84. int r_flags; /* any additional flags for the osd */
  85. u32 r_sent; /* >0 if r_request is sending/sent */
  86. int r_num_ops;
  87. /* encoded message content */
  88. struct ceph_osd_op *r_request_ops;
  89. /* these are updated on each send */
  90. __le32 *r_request_osdmap_epoch;
  91. __le32 *r_request_flags;
  92. __le64 *r_request_pool;
  93. void *r_request_pgid;
  94. __le32 *r_request_attempts;
  95. struct ceph_eversion *r_request_reassert_version;
  96. int r_result;
  97. int r_reply_op_len[CEPH_OSD_MAX_OP];
  98. s32 r_reply_op_result[CEPH_OSD_MAX_OP];
  99. int r_got_reply;
  100. int r_linger;
  101. int r_completed;
  102. struct ceph_osd_client *r_osdc;
  103. struct kref r_kref;
  104. bool r_mempool;
  105. struct completion r_completion, r_safe_completion;
  106. ceph_osdc_callback_t r_callback, r_safe_callback;
  107. struct ceph_eversion r_reassert_version;
  108. struct list_head r_unsafe_item;
  109. struct inode *r_inode; /* for use by callbacks */
  110. void *r_priv; /* ditto */
  111. char r_oid[MAX_OBJ_NAME_SIZE]; /* object name */
  112. int r_oid_len;
  113. u64 r_snapid;
  114. unsigned long r_stamp; /* send OR check time */
  115. struct ceph_file_layout r_file_layout;
  116. struct ceph_snap_context *r_snapc; /* snap context for writes */
  117. struct ceph_osd_data r_data_in;
  118. struct ceph_osd_data r_data_out;
  119. };
  120. struct ceph_osd_event {
  121. u64 cookie;
  122. int one_shot;
  123. struct ceph_osd_client *osdc;
  124. void (*cb)(u64, u64, u8, void *);
  125. void *data;
  126. struct rb_node node;
  127. struct list_head osd_node;
  128. struct kref kref;
  129. };
  130. struct ceph_osd_event_work {
  131. struct work_struct work;
  132. struct ceph_osd_event *event;
  133. u64 ver;
  134. u64 notify_id;
  135. u8 opcode;
  136. };
  137. struct ceph_osd_client {
  138. struct ceph_client *client;
  139. struct ceph_osdmap *osdmap; /* current map */
  140. struct rw_semaphore map_sem;
  141. struct completion map_waiters;
  142. u64 last_requested_map;
  143. struct mutex request_mutex;
  144. struct rb_root osds; /* osds */
  145. struct list_head osd_lru; /* idle osds */
  146. u64 timeout_tid; /* tid of timeout triggering rq */
  147. u64 last_tid; /* tid of last request */
  148. struct rb_root requests; /* pending requests */
  149. struct list_head req_lru; /* in-flight lru */
  150. struct list_head req_unsent; /* unsent/need-resend queue */
  151. struct list_head req_notarget; /* map to no osd */
  152. struct list_head req_linger; /* lingering requests */
  153. int num_requests;
  154. struct delayed_work timeout_work;
  155. struct delayed_work osds_timeout_work;
  156. #ifdef CONFIG_DEBUG_FS
  157. struct dentry *debugfs_file;
  158. #endif
  159. mempool_t *req_mempool;
  160. struct ceph_msgpool msgpool_op;
  161. struct ceph_msgpool msgpool_op_reply;
  162. spinlock_t event_lock;
  163. struct rb_root event_tree;
  164. u64 event_count;
  165. struct workqueue_struct *notify_wq;
  166. };
  167. struct ceph_osd_req_op {
  168. u16 op; /* CEPH_OSD_OP_* */
  169. u32 payload_len;
  170. union {
  171. struct {
  172. u64 offset, length;
  173. u64 truncate_size;
  174. u32 truncate_seq;
  175. } extent;
  176. struct {
  177. const char *class_name;
  178. const char *method_name;
  179. const void *indata;
  180. u32 indata_len;
  181. __u8 class_len;
  182. __u8 method_len;
  183. __u8 argc;
  184. } cls;
  185. struct {
  186. u64 cookie;
  187. u64 ver;
  188. u32 prot_ver;
  189. u32 timeout;
  190. __u8 flag;
  191. } watch;
  192. };
  193. };
  194. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  195. struct ceph_client *client);
  196. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  197. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  198. struct ceph_msg *msg);
  199. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  200. struct ceph_msg *msg);
  201. extern void osd_req_op_init(struct ceph_osd_req_op *op, u16 opcode);
  202. extern void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode,
  203. u64 offset, u64 length,
  204. u64 truncate_size, u32 truncate_seq);
  205. extern void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
  206. const char *class, const char *method,
  207. const void *request_data,
  208. size_t request_data_size);
  209. extern void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode,
  210. u64 cookie, u64 version, int flag);
  211. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  212. struct ceph_snap_context *snapc,
  213. unsigned int num_ops,
  214. bool use_mempool,
  215. gfp_t gfp_flags);
  216. extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
  217. unsigned int num_ops,
  218. struct ceph_osd_req_op *src_ops,
  219. struct ceph_snap_context *snapc,
  220. u64 snap_id,
  221. struct timespec *mtime);
  222. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  223. struct ceph_file_layout *layout,
  224. struct ceph_vino vino,
  225. u64 offset, u64 *len,
  226. int num_ops, struct ceph_osd_req_op *ops,
  227. int opcode, int flags,
  228. struct ceph_snap_context *snapc,
  229. u32 truncate_seq, u64 truncate_size,
  230. bool use_mempool);
  231. extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
  232. struct ceph_osd_request *req);
  233. extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
  234. struct ceph_osd_request *req);
  235. static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
  236. {
  237. kref_get(&req->r_kref);
  238. }
  239. extern void ceph_osdc_release_request(struct kref *kref);
  240. static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
  241. {
  242. kref_put(&req->r_kref, ceph_osdc_release_request);
  243. }
  244. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  245. struct ceph_osd_request *req,
  246. bool nofail);
  247. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  248. struct ceph_osd_request *req);
  249. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  250. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  251. struct ceph_vino vino,
  252. struct ceph_file_layout *layout,
  253. u64 off, u64 *plen,
  254. u32 truncate_seq, u64 truncate_size,
  255. struct page **pages, int nr_pages,
  256. int page_align);
  257. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  258. struct ceph_vino vino,
  259. struct ceph_file_layout *layout,
  260. struct ceph_snap_context *sc,
  261. u64 off, u64 len,
  262. u32 truncate_seq, u64 truncate_size,
  263. struct timespec *mtime,
  264. struct page **pages, int nr_pages);
  265. /* watch/notify events */
  266. extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
  267. void (*event_cb)(u64, u64, u8, void *),
  268. void *data, struct ceph_osd_event **pevent);
  269. extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
  270. extern void ceph_osdc_put_event(struct ceph_osd_event *event);
  271. #endif