osd_client.h 10 KB

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