osd_client.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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,
  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. u32 request_data_len;
  86. struct ceph_osd_data *response_data;
  87. __u8 class_len;
  88. __u8 method_len;
  89. __u8 argc;
  90. } cls;
  91. struct {
  92. u64 cookie;
  93. u64 ver;
  94. u32 prot_ver;
  95. u32 timeout;
  96. __u8 flag;
  97. } watch;
  98. };
  99. };
  100. /* an in-flight request */
  101. struct ceph_osd_request {
  102. u64 r_tid; /* unique for this client */
  103. struct rb_node r_node;
  104. struct list_head r_req_lru_item;
  105. struct list_head r_osd_item;
  106. struct list_head r_linger_item;
  107. struct list_head r_linger_osd;
  108. struct ceph_osd *r_osd;
  109. struct ceph_pg r_pgid;
  110. int r_pg_osds[CEPH_PG_MAX_SIZE];
  111. int r_num_pg_osds;
  112. struct ceph_msg *r_request, *r_reply;
  113. int r_flags; /* any additional flags for the osd */
  114. u32 r_sent; /* >0 if r_request is sending/sent */
  115. /* request osd ops array */
  116. unsigned int r_num_ops;
  117. struct ceph_osd_req_op r_ops[CEPH_OSD_MAX_OP];
  118. /* these are updated on each send */
  119. __le32 *r_request_osdmap_epoch;
  120. __le32 *r_request_flags;
  121. __le64 *r_request_pool;
  122. void *r_request_pgid;
  123. __le32 *r_request_attempts;
  124. struct ceph_eversion *r_request_reassert_version;
  125. int r_result;
  126. int r_reply_op_len[CEPH_OSD_MAX_OP];
  127. s32 r_reply_op_result[CEPH_OSD_MAX_OP];
  128. int r_got_reply;
  129. int r_linger;
  130. int r_completed;
  131. struct ceph_osd_client *r_osdc;
  132. struct kref r_kref;
  133. bool r_mempool;
  134. struct completion r_completion, r_safe_completion;
  135. ceph_osdc_callback_t r_callback, r_safe_callback;
  136. struct ceph_eversion r_reassert_version;
  137. struct list_head r_unsafe_item;
  138. struct inode *r_inode; /* for use by callbacks */
  139. void *r_priv; /* ditto */
  140. char r_oid[MAX_OBJ_NAME_SIZE]; /* object name */
  141. int r_oid_len;
  142. u64 r_snapid;
  143. unsigned long r_stamp; /* send OR check time */
  144. struct ceph_file_layout r_file_layout;
  145. struct ceph_snap_context *r_snapc; /* snap context for writes */
  146. struct ceph_osd_data r_data_in;
  147. struct ceph_osd_data r_data_out;
  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_init(struct ceph_osd_client *osdc,
  197. struct ceph_client *client);
  198. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  199. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  200. struct ceph_msg *msg);
  201. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  202. struct ceph_msg *msg);
  203. extern void osd_req_op_init(struct ceph_osd_req_op *op, u16 opcode);
  204. extern void osd_req_op_extent_init(struct ceph_osd_req_op *op, u16 opcode,
  205. u64 offset, u64 length,
  206. u64 truncate_size, u32 truncate_seq);
  207. extern void osd_req_op_extent_update(struct ceph_osd_req_op *op, u64 length);
  208. extern void osd_req_op_extent_osd_data(struct ceph_osd_req_op *op,
  209. struct ceph_osd_data *osd_data);
  210. extern void osd_req_op_cls_init(struct ceph_osd_req_op *op, u16 opcode,
  211. const char *class, const char *method,
  212. const void *request_data,
  213. size_t request_data_size);
  214. extern void osd_req_op_cls_response_data(struct ceph_osd_req_op *op,
  215. struct ceph_osd_data *response_data);
  216. extern void osd_req_op_watch_init(struct ceph_osd_req_op *op, u16 opcode,
  217. u64 cookie, u64 version, int flag);
  218. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  219. struct ceph_snap_context *snapc,
  220. unsigned int num_ops,
  221. bool use_mempool,
  222. gfp_t gfp_flags);
  223. extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
  224. struct ceph_snap_context *snapc,
  225. u64 snap_id,
  226. struct timespec *mtime);
  227. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  228. struct ceph_file_layout *layout,
  229. struct ceph_vino vino,
  230. u64 offset, u64 *len,
  231. int num_ops, int opcode, int flags,
  232. struct ceph_snap_context *snapc,
  233. u32 truncate_seq, u64 truncate_size,
  234. bool use_mempool);
  235. extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
  236. struct ceph_osd_request *req);
  237. extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
  238. struct ceph_osd_request *req);
  239. static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
  240. {
  241. kref_get(&req->r_kref);
  242. }
  243. extern void ceph_osdc_release_request(struct kref *kref);
  244. static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
  245. {
  246. kref_put(&req->r_kref, ceph_osdc_release_request);
  247. }
  248. extern void ceph_osd_data_pages_init(struct ceph_osd_data *osd_data,
  249. struct page **pages, u64 length,
  250. u32 alignment, bool pages_from_pool,
  251. bool own_pages);
  252. extern void ceph_osd_data_pagelist_init(struct ceph_osd_data *osd_data,
  253. struct ceph_pagelist *pagelist);
  254. #ifdef CONFIG_BLOCK
  255. extern void ceph_osd_data_bio_init(struct ceph_osd_data *osd_data,
  256. struct bio *bio, size_t bio_length);
  257. #endif /* CONFIG_BLOCK */
  258. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  259. struct ceph_osd_request *req,
  260. bool nofail);
  261. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  262. struct ceph_osd_request *req);
  263. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  264. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  265. struct ceph_vino vino,
  266. struct ceph_file_layout *layout,
  267. u64 off, u64 *plen,
  268. u32 truncate_seq, u64 truncate_size,
  269. struct page **pages, int nr_pages,
  270. int page_align);
  271. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  272. struct ceph_vino vino,
  273. struct ceph_file_layout *layout,
  274. struct ceph_snap_context *sc,
  275. u64 off, u64 len,
  276. u32 truncate_seq, u64 truncate_size,
  277. struct timespec *mtime,
  278. struct page **pages, int nr_pages);
  279. /* watch/notify events */
  280. extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
  281. void (*event_cb)(u64, u64, u8, void *),
  282. void *data, struct ceph_osd_event **pevent);
  283. extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
  284. extern void ceph_osdc_put_event(struct ceph_osd_event *event);
  285. #endif