osd_client.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. int r_completed;
  133. struct ceph_osd_client *r_osdc;
  134. struct kref r_kref;
  135. bool r_mempool;
  136. struct completion r_completion, r_safe_completion;
  137. ceph_osdc_callback_t r_callback;
  138. ceph_osdc_unsafe_callback_t r_unsafe_callback;
  139. struct ceph_eversion r_reassert_version;
  140. struct list_head r_unsafe_item;
  141. struct inode *r_inode; /* for use by callbacks */
  142. void *r_priv; /* ditto */
  143. char r_oid[MAX_OBJ_NAME_SIZE]; /* object name */
  144. int r_oid_len;
  145. u64 r_snapid;
  146. unsigned long r_stamp; /* send OR check time */
  147. struct ceph_file_layout r_file_layout;
  148. struct ceph_snap_context *r_snapc; /* snap context for writes */
  149. };
  150. struct ceph_osd_event {
  151. u64 cookie;
  152. int one_shot;
  153. struct ceph_osd_client *osdc;
  154. void (*cb)(u64, u64, u8, void *);
  155. void *data;
  156. struct rb_node node;
  157. struct list_head osd_node;
  158. struct kref kref;
  159. };
  160. struct ceph_osd_event_work {
  161. struct work_struct work;
  162. struct ceph_osd_event *event;
  163. u64 ver;
  164. u64 notify_id;
  165. u8 opcode;
  166. };
  167. struct ceph_osd_client {
  168. struct ceph_client *client;
  169. struct ceph_osdmap *osdmap; /* current map */
  170. struct rw_semaphore map_sem;
  171. struct completion map_waiters;
  172. u64 last_requested_map;
  173. struct mutex request_mutex;
  174. struct rb_root osds; /* osds */
  175. struct list_head osd_lru; /* idle osds */
  176. u64 timeout_tid; /* tid of timeout triggering rq */
  177. u64 last_tid; /* tid of last request */
  178. struct rb_root requests; /* pending requests */
  179. struct list_head req_lru; /* in-flight lru */
  180. struct list_head req_unsent; /* unsent/need-resend queue */
  181. struct list_head req_notarget; /* map to no osd */
  182. struct list_head req_linger; /* lingering requests */
  183. int num_requests;
  184. struct delayed_work timeout_work;
  185. struct delayed_work osds_timeout_work;
  186. #ifdef CONFIG_DEBUG_FS
  187. struct dentry *debugfs_file;
  188. #endif
  189. mempool_t *req_mempool;
  190. struct ceph_msgpool msgpool_op;
  191. struct ceph_msgpool msgpool_op_reply;
  192. spinlock_t event_lock;
  193. struct rb_root event_tree;
  194. u64 event_count;
  195. struct workqueue_struct *notify_wq;
  196. };
  197. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  198. struct ceph_client *client);
  199. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  200. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  201. struct ceph_msg *msg);
  202. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  203. struct ceph_msg *msg);
  204. extern void osd_req_op_init(struct ceph_osd_request *osd_req,
  205. unsigned int which, u16 opcode);
  206. extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
  207. unsigned int which,
  208. struct page **pages, u64 length,
  209. u32 alignment, bool pages_from_pool,
  210. bool own_pages);
  211. extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
  212. unsigned int which, u16 opcode,
  213. u64 offset, u64 length,
  214. u64 truncate_size, u32 truncate_seq);
  215. extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
  216. unsigned int which, u64 length);
  217. extern struct ceph_osd_data *osd_req_op_extent_osd_data(
  218. struct ceph_osd_request *osd_req,
  219. unsigned int which);
  220. extern struct ceph_osd_data *osd_req_op_cls_response_data(
  221. struct ceph_osd_request *osd_req,
  222. unsigned int which);
  223. extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
  224. unsigned int which,
  225. struct page **pages, u64 length,
  226. u32 alignment, bool pages_from_pool,
  227. bool own_pages);
  228. extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
  229. unsigned int which,
  230. struct ceph_pagelist *pagelist);
  231. #ifdef CONFIG_BLOCK
  232. extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
  233. unsigned int which,
  234. struct bio *bio, size_t bio_length);
  235. #endif /* CONFIG_BLOCK */
  236. extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
  237. unsigned int which,
  238. struct ceph_pagelist *pagelist);
  239. extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
  240. unsigned int which,
  241. struct page **pages, u64 length,
  242. u32 alignment, bool pages_from_pool,
  243. bool own_pages);
  244. extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
  245. unsigned int which, u16 opcode,
  246. const char *class, const char *method);
  247. extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
  248. unsigned int which, u16 opcode,
  249. u64 cookie, u64 version, int flag);
  250. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  251. struct ceph_snap_context *snapc,
  252. unsigned int num_ops,
  253. bool use_mempool,
  254. gfp_t gfp_flags);
  255. extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
  256. struct ceph_snap_context *snapc,
  257. u64 snap_id,
  258. struct timespec *mtime);
  259. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  260. struct ceph_file_layout *layout,
  261. struct ceph_vino vino,
  262. u64 offset, u64 *len,
  263. int num_ops, int opcode, int flags,
  264. struct ceph_snap_context *snapc,
  265. u32 truncate_seq, u64 truncate_size,
  266. bool use_mempool);
  267. extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
  268. struct ceph_osd_request *req);
  269. extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
  270. struct ceph_osd_request *req);
  271. static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
  272. {
  273. kref_get(&req->r_kref);
  274. }
  275. extern void ceph_osdc_release_request(struct kref *kref);
  276. static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
  277. {
  278. kref_put(&req->r_kref, ceph_osdc_release_request);
  279. }
  280. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  281. struct ceph_osd_request *req,
  282. bool nofail);
  283. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  284. struct ceph_osd_request *req);
  285. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  286. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  287. struct ceph_vino vino,
  288. struct ceph_file_layout *layout,
  289. u64 off, u64 *plen,
  290. u32 truncate_seq, u64 truncate_size,
  291. struct page **pages, int nr_pages,
  292. int page_align);
  293. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  294. struct ceph_vino vino,
  295. struct ceph_file_layout *layout,
  296. struct ceph_snap_context *sc,
  297. u64 off, u64 len,
  298. u32 truncate_seq, u64 truncate_size,
  299. struct timespec *mtime,
  300. struct page **pages, int nr_pages);
  301. /* watch/notify events */
  302. extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
  303. void (*event_cb)(u64, u64, u8, void *),
  304. void *data, struct ceph_osd_event **pevent);
  305. extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
  306. extern void ceph_osdc_put_event(struct ceph_osd_event *event);
  307. #endif