osd_client.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _FS_CEPH_OSD_CLIENT_H
  3. #define _FS_CEPH_OSD_CLIENT_H
  4. #include <linux/bitrev.h>
  5. #include <linux/completion.h>
  6. #include <linux/kref.h>
  7. #include <linux/mempool.h>
  8. #include <linux/rbtree.h>
  9. #include <linux/refcount.h>
  10. #include <linux/ceph/types.h>
  11. #include <linux/ceph/osdmap.h>
  12. #include <linux/ceph/messenger.h>
  13. #include <linux/ceph/msgpool.h>
  14. #include <linux/ceph/auth.h>
  15. #include <linux/ceph/pagelist.h>
  16. struct ceph_msg;
  17. struct ceph_snap_context;
  18. struct ceph_osd_request;
  19. struct ceph_osd_client;
  20. /*
  21. * completion callback for async writepages
  22. */
  23. typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);
  24. #define CEPH_HOMELESS_OSD -1
  25. /* a given osd we're communicating with */
  26. struct ceph_osd {
  27. refcount_t o_ref;
  28. struct ceph_osd_client *o_osdc;
  29. int o_osd;
  30. int o_incarnation;
  31. struct rb_node o_node;
  32. struct ceph_connection o_con;
  33. struct rb_root o_requests;
  34. struct rb_root o_linger_requests;
  35. struct rb_root o_backoff_mappings;
  36. struct rb_root o_backoffs_by_id;
  37. struct list_head o_osd_lru;
  38. struct ceph_auth_handshake o_auth;
  39. unsigned long lru_ttl;
  40. struct list_head o_keepalive_item;
  41. struct mutex lock;
  42. };
  43. #define CEPH_OSD_SLAB_OPS 2
  44. #define CEPH_OSD_MAX_OPS 16
  45. enum ceph_osd_data_type {
  46. CEPH_OSD_DATA_TYPE_NONE = 0,
  47. CEPH_OSD_DATA_TYPE_PAGES,
  48. CEPH_OSD_DATA_TYPE_PAGELIST,
  49. #ifdef CONFIG_BLOCK
  50. CEPH_OSD_DATA_TYPE_BIO,
  51. #endif /* CONFIG_BLOCK */
  52. CEPH_OSD_DATA_TYPE_BVECS,
  53. };
  54. struct ceph_osd_data {
  55. enum ceph_osd_data_type type;
  56. union {
  57. struct {
  58. struct page **pages;
  59. u64 length;
  60. u32 alignment;
  61. bool pages_from_pool;
  62. bool own_pages;
  63. };
  64. struct ceph_pagelist *pagelist;
  65. #ifdef CONFIG_BLOCK
  66. struct {
  67. struct ceph_bio_iter bio_pos;
  68. u32 bio_length;
  69. };
  70. #endif /* CONFIG_BLOCK */
  71. struct {
  72. struct ceph_bvec_iter bvec_pos;
  73. u32 num_bvecs;
  74. };
  75. };
  76. };
  77. struct ceph_osd_req_op {
  78. u16 op; /* CEPH_OSD_OP_* */
  79. u32 flags; /* CEPH_OSD_OP_FLAG_* */
  80. u32 indata_len; /* request */
  81. u32 outdata_len; /* reply */
  82. s32 rval;
  83. union {
  84. struct ceph_osd_data raw_data_in;
  85. struct {
  86. u64 offset, length;
  87. u64 truncate_size;
  88. u32 truncate_seq;
  89. struct ceph_osd_data osd_data;
  90. } extent;
  91. struct {
  92. u32 name_len;
  93. u32 value_len;
  94. __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
  95. __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
  96. struct ceph_osd_data osd_data;
  97. } xattr;
  98. struct {
  99. const char *class_name;
  100. const char *method_name;
  101. struct ceph_osd_data request_info;
  102. struct ceph_osd_data request_data;
  103. struct ceph_osd_data response_data;
  104. __u8 class_len;
  105. __u8 method_len;
  106. u32 indata_len;
  107. } cls;
  108. struct {
  109. u64 cookie;
  110. __u8 op; /* CEPH_OSD_WATCH_OP_ */
  111. u32 gen;
  112. } watch;
  113. struct {
  114. struct ceph_osd_data request_data;
  115. } notify_ack;
  116. struct {
  117. u64 cookie;
  118. struct ceph_osd_data request_data;
  119. struct ceph_osd_data response_data;
  120. } notify;
  121. struct {
  122. struct ceph_osd_data response_data;
  123. } list_watchers;
  124. struct {
  125. u64 expected_object_size;
  126. u64 expected_write_size;
  127. } alloc_hint;
  128. };
  129. };
  130. struct ceph_osd_request_target {
  131. struct ceph_object_id base_oid;
  132. struct ceph_object_locator base_oloc;
  133. struct ceph_object_id target_oid;
  134. struct ceph_object_locator target_oloc;
  135. struct ceph_pg pgid; /* last raw pg we mapped to */
  136. struct ceph_spg spgid; /* last actual spg we mapped to */
  137. u32 pg_num;
  138. u32 pg_num_mask;
  139. struct ceph_osds acting;
  140. struct ceph_osds up;
  141. int size;
  142. int min_size;
  143. bool sort_bitwise;
  144. bool recovery_deletes;
  145. unsigned int flags; /* CEPH_OSD_FLAG_* */
  146. bool paused;
  147. u32 epoch;
  148. u32 last_force_resend;
  149. int osd;
  150. };
  151. /* an in-flight request */
  152. struct ceph_osd_request {
  153. u64 r_tid; /* unique for this client */
  154. struct rb_node r_node;
  155. struct rb_node r_mc_node; /* map check */
  156. struct work_struct r_complete_work;
  157. struct ceph_osd *r_osd;
  158. struct ceph_osd_request_target r_t;
  159. #define r_base_oid r_t.base_oid
  160. #define r_base_oloc r_t.base_oloc
  161. #define r_flags r_t.flags
  162. struct ceph_msg *r_request, *r_reply;
  163. u32 r_sent; /* >0 if r_request is sending/sent */
  164. /* request osd ops array */
  165. unsigned int r_num_ops;
  166. int r_result;
  167. struct ceph_osd_client *r_osdc;
  168. struct kref r_kref;
  169. bool r_mempool;
  170. struct completion r_completion; /* private to osd_client.c */
  171. ceph_osdc_callback_t r_callback;
  172. struct list_head r_unsafe_item;
  173. struct inode *r_inode; /* for use by callbacks */
  174. void *r_priv; /* ditto */
  175. /* set by submitter */
  176. u64 r_snapid; /* for reads, CEPH_NOSNAP o/w */
  177. struct ceph_snap_context *r_snapc; /* for writes */
  178. struct timespec r_mtime; /* ditto */
  179. u64 r_data_offset; /* ditto */
  180. bool r_linger; /* don't resend on failure */
  181. /* internal */
  182. unsigned long r_stamp; /* jiffies, send or check time */
  183. unsigned long r_start_stamp; /* jiffies */
  184. int r_attempts;
  185. u32 r_map_dne_bound;
  186. struct ceph_osd_req_op r_ops[];
  187. };
  188. struct ceph_request_redirect {
  189. struct ceph_object_locator oloc;
  190. };
  191. /*
  192. * osd request identifier
  193. *
  194. * caller name + incarnation# + tid to unique identify this request
  195. */
  196. struct ceph_osd_reqid {
  197. struct ceph_entity_name name;
  198. __le64 tid;
  199. __le32 inc;
  200. } __packed;
  201. struct ceph_blkin_trace_info {
  202. __le64 trace_id;
  203. __le64 span_id;
  204. __le64 parent_span_id;
  205. } __packed;
  206. typedef void (*rados_watchcb2_t)(void *arg, u64 notify_id, u64 cookie,
  207. u64 notifier_id, void *data, size_t data_len);
  208. typedef void (*rados_watcherrcb_t)(void *arg, u64 cookie, int err);
  209. struct ceph_osd_linger_request {
  210. struct ceph_osd_client *osdc;
  211. u64 linger_id;
  212. bool committed;
  213. bool is_watch; /* watch or notify */
  214. struct ceph_osd *osd;
  215. struct ceph_osd_request *reg_req;
  216. struct ceph_osd_request *ping_req;
  217. unsigned long ping_sent;
  218. unsigned long watch_valid_thru;
  219. struct list_head pending_lworks;
  220. struct ceph_osd_request_target t;
  221. u32 map_dne_bound;
  222. struct timespec mtime;
  223. struct kref kref;
  224. struct mutex lock;
  225. struct rb_node node; /* osd */
  226. struct rb_node osdc_node; /* osdc */
  227. struct rb_node mc_node; /* map check */
  228. struct list_head scan_item;
  229. struct completion reg_commit_wait;
  230. struct completion notify_finish_wait;
  231. int reg_commit_error;
  232. int notify_finish_error;
  233. int last_error;
  234. u32 register_gen;
  235. u64 notify_id;
  236. rados_watchcb2_t wcb;
  237. rados_watcherrcb_t errcb;
  238. void *data;
  239. struct page ***preply_pages;
  240. size_t *preply_len;
  241. };
  242. struct ceph_watch_item {
  243. struct ceph_entity_name name;
  244. u64 cookie;
  245. struct ceph_entity_addr addr;
  246. };
  247. struct ceph_spg_mapping {
  248. struct rb_node node;
  249. struct ceph_spg spgid;
  250. struct rb_root backoffs;
  251. };
  252. struct ceph_hobject_id {
  253. void *key;
  254. size_t key_len;
  255. void *oid;
  256. size_t oid_len;
  257. u64 snapid;
  258. u32 hash;
  259. u8 is_max;
  260. void *nspace;
  261. size_t nspace_len;
  262. s64 pool;
  263. /* cache */
  264. u32 hash_reverse_bits;
  265. };
  266. static inline void ceph_hoid_build_hash_cache(struct ceph_hobject_id *hoid)
  267. {
  268. hoid->hash_reverse_bits = bitrev32(hoid->hash);
  269. }
  270. /*
  271. * PG-wide backoff: [begin, end)
  272. * per-object backoff: begin == end
  273. */
  274. struct ceph_osd_backoff {
  275. struct rb_node spg_node;
  276. struct rb_node id_node;
  277. struct ceph_spg spgid;
  278. u64 id;
  279. struct ceph_hobject_id *begin;
  280. struct ceph_hobject_id *end;
  281. };
  282. #define CEPH_LINGER_ID_START 0xffff000000000000ULL
  283. struct ceph_osd_client {
  284. struct ceph_client *client;
  285. struct ceph_osdmap *osdmap; /* current map */
  286. struct rw_semaphore lock;
  287. struct rb_root osds; /* osds */
  288. struct list_head osd_lru; /* idle osds */
  289. spinlock_t osd_lru_lock;
  290. u32 epoch_barrier;
  291. struct ceph_osd homeless_osd;
  292. atomic64_t last_tid; /* tid of last request */
  293. u64 last_linger_id;
  294. struct rb_root linger_requests; /* lingering requests */
  295. struct rb_root map_checks;
  296. struct rb_root linger_map_checks;
  297. atomic_t num_requests;
  298. atomic_t num_homeless;
  299. bool abort_on_full; /* abort w/ ENOSPC when full */
  300. int abort_err;
  301. struct delayed_work timeout_work;
  302. struct delayed_work osds_timeout_work;
  303. #ifdef CONFIG_DEBUG_FS
  304. struct dentry *debugfs_file;
  305. #endif
  306. mempool_t *req_mempool;
  307. struct ceph_msgpool msgpool_op;
  308. struct ceph_msgpool msgpool_op_reply;
  309. struct workqueue_struct *notify_wq;
  310. struct workqueue_struct *completion_wq;
  311. };
  312. static inline bool ceph_osdmap_flag(struct ceph_osd_client *osdc, int flag)
  313. {
  314. return osdc->osdmap->flags & flag;
  315. }
  316. extern int ceph_osdc_setup(void);
  317. extern void ceph_osdc_cleanup(void);
  318. extern int ceph_osdc_init(struct ceph_osd_client *osdc,
  319. struct ceph_client *client);
  320. extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
  321. extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
  322. struct ceph_msg *msg);
  323. extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
  324. struct ceph_msg *msg);
  325. void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
  326. void ceph_osdc_abort_requests(struct ceph_osd_client *osdc, int err);
  327. extern void osd_req_op_init(struct ceph_osd_request *osd_req,
  328. unsigned int which, u16 opcode, u32 flags);
  329. extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
  330. unsigned int which,
  331. struct page **pages, u64 length,
  332. u32 alignment, bool pages_from_pool,
  333. bool own_pages);
  334. extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
  335. unsigned int which, u16 opcode,
  336. u64 offset, u64 length,
  337. u64 truncate_size, u32 truncate_seq);
  338. extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
  339. unsigned int which, u64 length);
  340. extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
  341. unsigned int which, u64 offset_inc);
  342. extern struct ceph_osd_data *osd_req_op_extent_osd_data(
  343. struct ceph_osd_request *osd_req,
  344. unsigned int which);
  345. extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
  346. unsigned int which,
  347. struct page **pages, u64 length,
  348. u32 alignment, bool pages_from_pool,
  349. bool own_pages);
  350. extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
  351. unsigned int which,
  352. struct ceph_pagelist *pagelist);
  353. #ifdef CONFIG_BLOCK
  354. void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *osd_req,
  355. unsigned int which,
  356. struct ceph_bio_iter *bio_pos,
  357. u32 bio_length);
  358. #endif /* CONFIG_BLOCK */
  359. void osd_req_op_extent_osd_data_bvecs(struct ceph_osd_request *osd_req,
  360. unsigned int which,
  361. struct bio_vec *bvecs, u32 num_bvecs,
  362. u32 bytes);
  363. void osd_req_op_extent_osd_data_bvec_pos(struct ceph_osd_request *osd_req,
  364. unsigned int which,
  365. struct ceph_bvec_iter *bvec_pos);
  366. extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
  367. unsigned int which,
  368. struct ceph_pagelist *pagelist);
  369. extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
  370. unsigned int which,
  371. struct page **pages, u64 length,
  372. u32 alignment, bool pages_from_pool,
  373. bool own_pages);
  374. void osd_req_op_cls_request_data_bvecs(struct ceph_osd_request *osd_req,
  375. unsigned int which,
  376. struct bio_vec *bvecs, u32 num_bvecs,
  377. u32 bytes);
  378. extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
  379. unsigned int which,
  380. struct page **pages, u64 length,
  381. u32 alignment, bool pages_from_pool,
  382. bool own_pages);
  383. extern int osd_req_op_cls_init(struct ceph_osd_request *osd_req,
  384. unsigned int which, u16 opcode,
  385. const char *class, const char *method);
  386. extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
  387. u16 opcode, const char *name, const void *value,
  388. size_t size, u8 cmp_op, u8 cmp_mode);
  389. extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
  390. unsigned int which,
  391. u64 expected_object_size,
  392. u64 expected_write_size);
  393. extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
  394. struct ceph_snap_context *snapc,
  395. unsigned int num_ops,
  396. bool use_mempool,
  397. gfp_t gfp_flags);
  398. int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
  399. extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
  400. struct ceph_file_layout *layout,
  401. struct ceph_vino vino,
  402. u64 offset, u64 *len,
  403. unsigned int which, int num_ops,
  404. int opcode, int flags,
  405. struct ceph_snap_context *snapc,
  406. u32 truncate_seq, u64 truncate_size,
  407. bool use_mempool);
  408. extern void ceph_osdc_get_request(struct ceph_osd_request *req);
  409. extern void ceph_osdc_put_request(struct ceph_osd_request *req);
  410. extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
  411. struct ceph_osd_request *req,
  412. bool nofail);
  413. extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
  414. extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
  415. struct ceph_osd_request *req);
  416. extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
  417. extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
  418. void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc);
  419. int ceph_osdc_call(struct ceph_osd_client *osdc,
  420. struct ceph_object_id *oid,
  421. struct ceph_object_locator *oloc,
  422. const char *class, const char *method,
  423. unsigned int flags,
  424. struct page *req_page, size_t req_len,
  425. struct page *resp_page, size_t *resp_len);
  426. extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
  427. struct ceph_vino vino,
  428. struct ceph_file_layout *layout,
  429. u64 off, u64 *plen,
  430. u32 truncate_seq, u64 truncate_size,
  431. struct page **pages, int nr_pages,
  432. int page_align);
  433. extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
  434. struct ceph_vino vino,
  435. struct ceph_file_layout *layout,
  436. struct ceph_snap_context *sc,
  437. u64 off, u64 len,
  438. u32 truncate_seq, u64 truncate_size,
  439. struct timespec *mtime,
  440. struct page **pages, int nr_pages);
  441. /* watch/notify */
  442. struct ceph_osd_linger_request *
  443. ceph_osdc_watch(struct ceph_osd_client *osdc,
  444. struct ceph_object_id *oid,
  445. struct ceph_object_locator *oloc,
  446. rados_watchcb2_t wcb,
  447. rados_watcherrcb_t errcb,
  448. void *data);
  449. int ceph_osdc_unwatch(struct ceph_osd_client *osdc,
  450. struct ceph_osd_linger_request *lreq);
  451. int ceph_osdc_notify_ack(struct ceph_osd_client *osdc,
  452. struct ceph_object_id *oid,
  453. struct ceph_object_locator *oloc,
  454. u64 notify_id,
  455. u64 cookie,
  456. void *payload,
  457. size_t payload_len);
  458. int ceph_osdc_notify(struct ceph_osd_client *osdc,
  459. struct ceph_object_id *oid,
  460. struct ceph_object_locator *oloc,
  461. void *payload,
  462. size_t payload_len,
  463. u32 timeout,
  464. struct page ***preply_pages,
  465. size_t *preply_len);
  466. int ceph_osdc_watch_check(struct ceph_osd_client *osdc,
  467. struct ceph_osd_linger_request *lreq);
  468. int ceph_osdc_list_watchers(struct ceph_osd_client *osdc,
  469. struct ceph_object_id *oid,
  470. struct ceph_object_locator *oloc,
  471. struct ceph_watch_item **watchers,
  472. u32 *num_watchers);
  473. #endif