osd_client.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  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/msgpool.h>
  11. #include <linux/ceph/auth.h>
  12. #include <linux/ceph/pagelist.h>
  13. struct ceph_msg;
  14. struct ceph_snap_context;
  15. struct ceph_osd_request;
  16. struct ceph_osd_client;
  17. /*
  18. * completion callback for async writepages
  19. */
  20. typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);
  21. typedef void (*ceph_osdc_unsafe_callback_t)(struct ceph_osd_request *, bool);
  22. #define CEPH_HOMELESS_OSD -1
  23. /* a given osd we're communicating with */
  24. struct ceph_osd {
  25. atomic_t o_ref;
  26. struct ceph_osd_client *o_osdc;
  27. int o_osd;
  28. int o_incarnation;
  29. struct rb_node o_node;
  30. struct ceph_connection o_con;
  31. struct rb_root o_requests;
  32. struct rb_root o_linger_requests;
  33. struct list_head o_osd_lru;
  34. struct ceph_auth_handshake o_auth;
  35. unsigned long lru_ttl;
  36. struct list_head o_keepalive_item;
  37. struct mutex lock;
  38. };
  39. #define CEPH_OSD_SLAB_OPS 2
  40. #define CEPH_OSD_MAX_OPS 16
  41. enum ceph_osd_data_type {
  42. CEPH_OSD_DATA_TYPE_NONE = 0,
  43. CEPH_OSD_DATA_TYPE_PAGES,
  44. CEPH_OSD_DATA_TYPE_PAGELIST,
  45. #ifdef CONFIG_BLOCK
  46. CEPH_OSD_DATA_TYPE_BIO,
  47. #endif /* CONFIG_BLOCK */
  48. };
  49. struct ceph_osd_data {
  50. enum ceph_osd_data_type type;
  51. union {
  52. struct {
  53. struct page **pages;
  54. u64 length;
  55. u32 alignment;
  56. bool pages_from_pool;
  57. bool own_pages;
  58. };
  59. struct ceph_pagelist *pagelist;
  60. #ifdef CONFIG_BLOCK
  61. struct {
  62. struct bio *bio; /* list of bios */
  63. size_t bio_length; /* total in list */
  64. };
  65. #endif /* CONFIG_BLOCK */
  66. };
  67. };
  68. struct ceph_osd_req_op {
  69. u16 op; /* CEPH_OSD_OP_* */
  70. u32 flags; /* CEPH_OSD_OP_FLAG_* */
  71. u32 indata_len; /* request */
  72. u32 outdata_len; /* reply */
  73. s32 rval;
  74. union {
  75. struct ceph_osd_data raw_data_in;
  76. struct {
  77. u64 offset, length;
  78. u64 truncate_size;
  79. u32 truncate_seq;
  80. struct ceph_osd_data osd_data;
  81. } extent;
  82. struct {
  83. u32 name_len;
  84. u32 value_len;
  85. __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
  86. __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
  87. struct ceph_osd_data osd_data;
  88. } xattr;
  89. struct {
  90. const char *class_name;
  91. const char *method_name;
  92. struct ceph_osd_data request_info;
  93. struct ceph_osd_data request_data;
  94. struct ceph_osd_data response_data;
  95. __u8 class_len;
  96. __u8 method_len;
  97. u32 indata_len;
  98. } cls;
  99. struct {
  100. u64 cookie;
  101. __u8 op; /* CEPH_OSD_WATCH_OP_ */
  102. u32 gen;
  103. } watch;
  104. struct {
  105. struct ceph_osd_data request_data;
  106. } notify_ack;
  107. struct {
  108. u64 cookie;
  109. struct ceph_osd_data request_data;
  110. struct ceph_osd_data response_data;
  111. } notify;
  112. struct {
  113. struct ceph_osd_data response_data;
  114. } list_watchers;
  115. struct {
  116. u64 expected_object_size;
  117. u64 expected_write_size;
  118. } alloc_hint;
  119. };
  120. };
  121. struct ceph_osd_request_target {
  122. struct ceph_object_id base_oid;
  123. struct ceph_object_locator base_oloc;
  124. struct ceph_object_id target_oid;
  125. struct ceph_object_locator target_oloc;
  126. struct ceph_pg pgid;
  127. u32 pg_num;
  128. u32 pg_num_mask;
  129. struct ceph_osds acting;
  130. struct ceph_osds up;
  131. int size;
  132. int min_size;
  133. bool sort_bitwise;
  134. unsigned int flags; /* CEPH_OSD_FLAG_* */
  135. bool paused;
  136. int osd;
  137. };
  138. /* an in-flight request */
  139. struct ceph_osd_request {
  140. u64 r_tid; /* unique for this client */
  141. struct rb_node r_node;
  142. struct rb_node r_mc_node; /* map check */
  143. struct ceph_osd *r_osd;
  144. struct ceph_osd_request_target r_t;
  145. #define r_base_oid r_t.base_oid
  146. #define r_base_oloc r_t.base_oloc
  147. #define r_flags r_t.flags
  148. struct ceph_msg *r_request, *r_reply;
  149. u32 r_sent; /* >0 if r_request is sending/sent */
  150. /* request osd ops array */
  151. unsigned int r_num_ops;
  152. int r_result;
  153. bool r_got_reply;
  154. struct ceph_osd_client *r_osdc;
  155. struct kref r_kref;
  156. bool r_mempool;
  157. struct completion r_completion;
  158. struct completion r_safe_completion; /* fsync waiter */
  159. ceph_osdc_callback_t r_callback;
  160. ceph_osdc_unsafe_callback_t r_unsafe_callback;
  161. struct list_head r_unsafe_item;
  162. struct inode *r_inode; /* for use by callbacks */
  163. void *r_priv; /* ditto */
  164. /* set by submitter */
  165. u64 r_snapid; /* for reads, CEPH_NOSNAP o/w */
  166. struct ceph_snap_context *r_snapc; /* for writes */
  167. struct timespec r_mtime; /* ditto */
  168. u64 r_data_offset; /* ditto */
  169. bool r_linger; /* don't resend on failure */
  170. /* internal */
  171. unsigned long r_stamp; /* jiffies, send or check time */
  172. int r_attempts;
  173. struct ceph_eversion r_replay_version; /* aka reassert_version */
  174. u32 r_last_force_resend;
  175. u32 r_map_dne_bound;
  176. struct ceph_osd_req_op r_ops[];
  177. };
  178. struct ceph_request_redirect {
  179. struct ceph_object_locator oloc;
  180. };
  181. typedef void (*rados_watchcb2_t)(void *arg, u64 notify_id, u64 cookie,
  182. u64 notifier_id, void *data, size_t data_len);
  183. typedef void (*rados_watcherrcb_t)(void *arg, u64 cookie, int err);
  184. struct ceph_osd_linger_request {
  185. struct ceph_osd_client *osdc;
  186. u64 linger_id;
  187. bool committed;
  188. bool is_watch; /* watch or notify */
  189. struct ceph_osd *osd;
  190. struct ceph_osd_request *reg_req;
  191. struct ceph_osd_request *ping_req;
  192. unsigned long ping_sent;
  193. unsigned long watch_valid_thru;
  194. struct list_head pending_lworks;
  195. struct ceph_osd_request_target t;
  196. u32 last_force_resend;
  197. u32 map_dne_bound;
  198. struct timespec mtime;
  199. struct kref kref;
  200. struct mutex lock;
  201. struct rb_node node; /* osd */
  202. struct rb_node osdc_node; /* osdc */
  203. struct rb_node mc_node; /* map check */
  204. struct list_head scan_item;
  205. struct completion reg_commit_wait;
  206. struct completion notify_finish_wait;
  207. int reg_commit_error;
  208. int notify_finish_error;
  209. int last_error;
  210. u32 register_gen;
  211. u64 notify_id;
  212. rados_watchcb2_t wcb;
  213. rados_watcherrcb_t errcb;
  214. void *data;
  215. struct page ***preply_pages;
  216. size_t *preply_len;
  217. };
  218. struct ceph_watch_item {
  219. struct ceph_entity_name name;
  220. u64 cookie;
  221. struct ceph_entity_addr addr;
  222. };
  223. #define CEPH_LINGER_ID_START 0xffff000000000000ULL
  224. struct ceph_osd_client {
  225. struct ceph_client *client;
  226. struct ceph_osdmap *osdmap; /* current map */
  227. struct rw_semaphore lock;
  228. struct rb_root osds; /* osds */
  229. struct list_head osd_lru; /* idle osds */
  230. spinlock_t osd_lru_lock;
  231. struct ceph_osd homeless_osd;
  232. atomic64_t last_tid; /* tid of last request */
  233. u64 last_linger_id;
  234. struct rb_root linger_requests; /* lingering requests */
  235. struct rb_root map_checks;
  236. struct rb_root linger_map_checks;
  237. atomic_t num_requests;
  238. atomic_t num_homeless;
  239. struct delayed_work timeout_work;
  240. struct delayed_work osds_timeout_work;
  241. #ifdef CONFIG_DEBUG_FS
  242. struct dentry *debugfs_file;
  243. #endif
  244. mempool_t *req_mempool;
  245. struct ceph_msgpool msgpool_op;
  246. struct ceph_msgpool msgpool_op_reply;
  247. struct workqueue_struct *notify_wq;
  248. };
  249. static inline bool ceph_osdmap_flag(struct ceph_osd_client *osdc, int flag)
  250. {
  251. return osdc->osdmap->flags & flag;
  252. }
  253. extern int ceph_osdc_setup(void);
  254. extern void ceph_osdc_cleanup(void);
  255. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  256. struct ceph_client *client);
  257. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  258. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  259. struct ceph_msg *msg);
  260. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  261. struct ceph_msg *msg);
  262. extern void osd_req_op_init(struct ceph_osd_request *osd_req,
  263. unsigned int which, u16 opcode, u32 flags);
  264. extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
  265. unsigned int which,
  266. struct page **pages, u64 length,
  267. u32 alignment, bool pages_from_pool,
  268. bool own_pages);
  269. extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
  270. unsigned int which, u16 opcode,
  271. u64 offset, u64 length,
  272. u64 truncate_size, u32 truncate_seq);
  273. extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
  274. unsigned int which, u64 length);
  275. extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
  276. unsigned int which, u64 offset_inc);
  277. extern struct ceph_osd_data *osd_req_op_extent_osd_data(
  278. struct ceph_osd_request *osd_req,
  279. unsigned int which);
  280. extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
  281. unsigned int which,
  282. struct page **pages, u64 length,
  283. u32 alignment, bool pages_from_pool,
  284. bool own_pages);
  285. extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
  286. unsigned int which,
  287. struct ceph_pagelist *pagelist);
  288. #ifdef CONFIG_BLOCK
  289. extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
  290. unsigned int which,
  291. struct bio *bio, size_t bio_length);
  292. #endif /* CONFIG_BLOCK */
  293. extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
  294. unsigned int which,
  295. struct ceph_pagelist *pagelist);
  296. extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
  297. unsigned int which,
  298. struct page **pages, u64 length,
  299. u32 alignment, bool pages_from_pool,
  300. bool own_pages);
  301. extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
  302. unsigned int which,
  303. struct page **pages, u64 length,
  304. u32 alignment, bool pages_from_pool,
  305. bool own_pages);
  306. extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
  307. unsigned int which, u16 opcode,
  308. const char *class, const char *method);
  309. extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
  310. u16 opcode, const char *name, const void *value,
  311. size_t size, u8 cmp_op, u8 cmp_mode);
  312. extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
  313. unsigned int which,
  314. u64 expected_object_size,
  315. u64 expected_write_size);
  316. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  317. struct ceph_snap_context *snapc,
  318. unsigned int num_ops,
  319. bool use_mempool,
  320. gfp_t gfp_flags);
  321. int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
  322. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  323. struct ceph_file_layout *layout,
  324. struct ceph_vino vino,
  325. u64 offset, u64 *len,
  326. unsigned int which, int num_ops,
  327. int opcode, int flags,
  328. struct ceph_snap_context *snapc,
  329. u32 truncate_seq, u64 truncate_size,
  330. bool use_mempool);
  331. extern void ceph_osdc_get_request(struct ceph_osd_request *req);
  332. extern void ceph_osdc_put_request(struct ceph_osd_request *req);
  333. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  334. struct ceph_osd_request *req,
  335. bool nofail);
  336. extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
  337. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  338. struct ceph_osd_request *req);
  339. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  340. extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
  341. void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc);
  342. int ceph_osdc_call(struct ceph_osd_client *osdc,
  343. struct ceph_object_id *oid,
  344. struct ceph_object_locator *oloc,
  345. const char *class, const char *method,
  346. unsigned int flags,
  347. struct page *req_page, size_t req_len,
  348. struct page *resp_page, size_t *resp_len);
  349. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  350. struct ceph_vino vino,
  351. struct ceph_file_layout *layout,
  352. u64 off, u64 *plen,
  353. u32 truncate_seq, u64 truncate_size,
  354. struct page **pages, int nr_pages,
  355. int page_align);
  356. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  357. struct ceph_vino vino,
  358. struct ceph_file_layout *layout,
  359. struct ceph_snap_context *sc,
  360. u64 off, u64 len,
  361. u32 truncate_seq, u64 truncate_size,
  362. struct timespec *mtime,
  363. struct page **pages, int nr_pages);
  364. /* watch/notify */
  365. struct ceph_osd_linger_request *
  366. ceph_osdc_watch(struct ceph_osd_client *osdc,
  367. struct ceph_object_id *oid,
  368. struct ceph_object_locator *oloc,
  369. rados_watchcb2_t wcb,
  370. rados_watcherrcb_t errcb,
  371. void *data);
  372. int ceph_osdc_unwatch(struct ceph_osd_client *osdc,
  373. struct ceph_osd_linger_request *lreq);
  374. int ceph_osdc_notify_ack(struct ceph_osd_client *osdc,
  375. struct ceph_object_id *oid,
  376. struct ceph_object_locator *oloc,
  377. u64 notify_id,
  378. u64 cookie,
  379. void *payload,
  380. size_t payload_len);
  381. int ceph_osdc_notify(struct ceph_osd_client *osdc,
  382. struct ceph_object_id *oid,
  383. struct ceph_object_locator *oloc,
  384. void *payload,
  385. size_t payload_len,
  386. u32 timeout,
  387. struct page ***preply_pages,
  388. size_t *preply_len);
  389. int ceph_osdc_watch_check(struct ceph_osd_client *osdc,
  390. struct ceph_osd_linger_request *lreq);
  391. int ceph_osdc_list_watchers(struct ceph_osd_client *osdc,
  392. struct ceph_object_id *oid,
  393. struct ceph_object_locator *oloc,
  394. struct ceph_watch_item **watchers,
  395. u32 *num_watchers);
  396. #endif