osd_client.h 11 KB

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