osd_client.h 13 KB

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