osd_client.h 8.6 KB

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