1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _FS_CEPH_OSD_CLIENT_H
3 #define _FS_CEPH_OSD_CLIENT_H
5 #include <linux/bitrev.h>
6 #include <linux/completion.h>
7 #include <linux/kref.h>
8 #include <linux/mempool.h>
9 #include <linux/rbtree.h>
10 #include <linux/refcount.h>
12 #include <linux/ceph/types.h>
13 #include <linux/ceph/osdmap.h>
14 #include <linux/ceph/messenger.h>
15 #include <linux/ceph/msgpool.h>
16 #include <linux/ceph/auth.h>
17 #include <linux/ceph/pagelist.h>
20 struct ceph_snap_context;
21 struct ceph_osd_request;
22 struct ceph_osd_client;
25 * completion callback for async writepages
27 typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);
29 #define CEPH_HOMELESS_OSD -1
31 /* a given osd we're communicating with */
34 struct ceph_osd_client *o_osdc;
37 struct rb_node o_node;
38 struct ceph_connection o_con;
39 struct rb_root o_requests;
40 struct rb_root o_linger_requests;
41 struct rb_root o_backoff_mappings;
42 struct rb_root o_backoffs_by_id;
43 struct list_head o_osd_lru;
44 struct ceph_auth_handshake o_auth;
45 unsigned long lru_ttl;
46 struct list_head o_keepalive_item;
50 #define CEPH_OSD_SLAB_OPS 2
51 #define CEPH_OSD_MAX_OPS 16
53 enum ceph_osd_data_type {
54 CEPH_OSD_DATA_TYPE_NONE = 0,
55 CEPH_OSD_DATA_TYPE_PAGES,
56 CEPH_OSD_DATA_TYPE_PAGELIST,
58 CEPH_OSD_DATA_TYPE_BIO,
59 #endif /* CONFIG_BLOCK */
60 CEPH_OSD_DATA_TYPE_BVECS,
63 struct ceph_osd_data {
64 enum ceph_osd_data_type type;
73 struct ceph_pagelist *pagelist;
76 struct ceph_bio_iter bio_pos;
79 #endif /* CONFIG_BLOCK */
81 struct ceph_bvec_iter bvec_pos;
87 struct ceph_osd_req_op {
88 u16 op; /* CEPH_OSD_OP_* */
89 u32 flags; /* CEPH_OSD_OP_FLAG_* */
90 u32 indata_len; /* request */
91 u32 outdata_len; /* reply */
95 struct ceph_osd_data raw_data_in;
100 struct ceph_osd_data osd_data;
105 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
106 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
107 struct ceph_osd_data osd_data;
110 const char *class_name;
111 const char *method_name;
112 struct ceph_osd_data request_info;
113 struct ceph_osd_data request_data;
114 struct ceph_osd_data response_data;
121 __u8 op; /* CEPH_OSD_WATCH_OP_ */
125 struct ceph_osd_data request_data;
129 struct ceph_osd_data request_data;
130 struct ceph_osd_data response_data;
133 struct ceph_osd_data response_data;
136 u64 expected_object_size;
137 u64 expected_write_size;
143 u32 src_fadvise_flags;
144 struct ceph_osd_data osd_data;
149 struct ceph_osd_request_target {
150 struct ceph_object_id base_oid;
151 struct ceph_object_locator base_oloc;
152 struct ceph_object_id target_oid;
153 struct ceph_object_locator target_oloc;
155 struct ceph_pg pgid; /* last raw pg we mapped to */
156 struct ceph_spg spgid; /* last actual spg we mapped to */
159 struct ceph_osds acting;
164 bool recovery_deletes;
166 unsigned int flags; /* CEPH_OSD_FLAG_* */
170 u32 last_force_resend;
175 /* an in-flight request */
176 struct ceph_osd_request {
177 u64 r_tid; /* unique for this client */
178 struct rb_node r_node;
179 struct rb_node r_mc_node; /* map check */
180 struct work_struct r_complete_work;
181 struct ceph_osd *r_osd;
183 struct ceph_osd_request_target r_t;
184 #define r_base_oid r_t.base_oid
185 #define r_base_oloc r_t.base_oloc
186 #define r_flags r_t.flags
188 struct ceph_msg *r_request, *r_reply;
189 u32 r_sent; /* >0 if r_request is sending/sent */
191 /* request osd ops array */
192 unsigned int r_num_ops;
196 struct ceph_osd_client *r_osdc;
199 struct completion r_completion; /* private to osd_client.c */
200 ceph_osdc_callback_t r_callback;
202 struct inode *r_inode; /* for use by callbacks */
203 struct list_head r_private_item; /* ditto */
204 void *r_priv; /* ditto */
206 /* set by submitter */
207 u64 r_snapid; /* for reads, CEPH_NOSNAP o/w */
208 struct ceph_snap_context *r_snapc; /* for writes */
209 struct timespec64 r_mtime; /* ditto */
210 u64 r_data_offset; /* ditto */
211 bool r_linger; /* don't resend on failure */
214 unsigned long r_stamp; /* jiffies, send or check time */
215 unsigned long r_start_stamp; /* jiffies */
219 struct ceph_osd_req_op r_ops[];
222 struct ceph_request_redirect {
223 struct ceph_object_locator oloc;
227 * osd request identifier
229 * caller name + incarnation# + tid to unique identify this request
231 struct ceph_osd_reqid {
232 struct ceph_entity_name name;
237 struct ceph_blkin_trace_info {
240 __le64 parent_span_id;
243 typedef void (*rados_watchcb2_t)(void *arg, u64 notify_id, u64 cookie,
244 u64 notifier_id, void *data, size_t data_len);
245 typedef void (*rados_watcherrcb_t)(void *arg, u64 cookie, int err);
247 struct ceph_osd_linger_request {
248 struct ceph_osd_client *osdc;
251 bool is_watch; /* watch or notify */
253 struct ceph_osd *osd;
254 struct ceph_osd_request *reg_req;
255 struct ceph_osd_request *ping_req;
256 unsigned long ping_sent;
257 unsigned long watch_valid_thru;
258 struct list_head pending_lworks;
260 struct ceph_osd_request_target t;
263 struct timespec64 mtime;
267 struct rb_node node; /* osd */
268 struct rb_node osdc_node; /* osdc */
269 struct rb_node mc_node; /* map check */
270 struct list_head scan_item;
272 struct completion reg_commit_wait;
273 struct completion notify_finish_wait;
274 int reg_commit_error;
275 int notify_finish_error;
281 rados_watchcb2_t wcb;
282 rados_watcherrcb_t errcb;
285 struct page ***preply_pages;
289 struct ceph_watch_item {
290 struct ceph_entity_name name;
292 struct ceph_entity_addr addr;
295 struct ceph_spg_mapping {
297 struct ceph_spg spgid;
299 struct rb_root backoffs;
302 struct ceph_hobject_id {
315 u32 hash_reverse_bits;
318 static inline void ceph_hoid_build_hash_cache(struct ceph_hobject_id *hoid)
320 hoid->hash_reverse_bits = bitrev32(hoid->hash);
324 * PG-wide backoff: [begin, end)
325 * per-object backoff: begin == end
327 struct ceph_osd_backoff {
328 struct rb_node spg_node;
329 struct rb_node id_node;
331 struct ceph_spg spgid;
333 struct ceph_hobject_id *begin;
334 struct ceph_hobject_id *end;
337 #define CEPH_LINGER_ID_START 0xffff000000000000ULL
339 struct ceph_osd_client {
340 struct ceph_client *client;
342 struct ceph_osdmap *osdmap; /* current map */
343 struct rw_semaphore lock;
345 struct rb_root osds; /* osds */
346 struct list_head osd_lru; /* idle osds */
347 spinlock_t osd_lru_lock;
349 struct ceph_osd homeless_osd;
350 atomic64_t last_tid; /* tid of last request */
352 struct rb_root linger_requests; /* lingering requests */
353 struct rb_root map_checks;
354 struct rb_root linger_map_checks;
355 atomic_t num_requests;
356 atomic_t num_homeless;
358 struct delayed_work timeout_work;
359 struct delayed_work osds_timeout_work;
360 #ifdef CONFIG_DEBUG_FS
361 struct dentry *debugfs_file;
364 mempool_t *req_mempool;
366 struct ceph_msgpool msgpool_op;
367 struct ceph_msgpool msgpool_op_reply;
369 struct workqueue_struct *notify_wq;
370 struct workqueue_struct *completion_wq;
373 static inline bool ceph_osdmap_flag(struct ceph_osd_client *osdc, int flag)
375 return osdc->osdmap->flags & flag;
378 extern int ceph_osdc_setup(void);
379 extern void ceph_osdc_cleanup(void);
381 extern int ceph_osdc_init(struct ceph_osd_client *osdc,
382 struct ceph_client *client);
383 extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
384 extern void ceph_osdc_reopen_osds(struct ceph_osd_client *osdc);
386 extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
387 struct ceph_msg *msg);
388 extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
389 struct ceph_msg *msg);
390 void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
391 void ceph_osdc_abort_requests(struct ceph_osd_client *osdc, int err);
392 void ceph_osdc_clear_abort_err(struct ceph_osd_client *osdc);
394 #define osd_req_op_data(oreq, whch, typ, fld) \
396 struct ceph_osd_request *__oreq = (oreq); \
397 unsigned int __whch = (whch); \
398 BUG_ON(__whch >= __oreq->r_num_ops); \
399 &__oreq->r_ops[__whch].typ.fld; \
402 extern void osd_req_op_init(struct ceph_osd_request *osd_req,
403 unsigned int which, u16 opcode, u32 flags);
405 extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
407 struct page **pages, u64 length,
408 u32 alignment, bool pages_from_pool,
411 extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
412 unsigned int which, u16 opcode,
413 u64 offset, u64 length,
414 u64 truncate_size, u32 truncate_seq);
415 extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
416 unsigned int which, u64 length);
417 extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
418 unsigned int which, u64 offset_inc);
420 extern struct ceph_osd_data *osd_req_op_extent_osd_data(
421 struct ceph_osd_request *osd_req,
424 extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
426 struct page **pages, u64 length,
427 u32 alignment, bool pages_from_pool,
429 extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
431 struct ceph_pagelist *pagelist);
433 void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *osd_req,
435 struct ceph_bio_iter *bio_pos,
437 #endif /* CONFIG_BLOCK */
438 void osd_req_op_extent_osd_data_bvecs(struct ceph_osd_request *osd_req,
440 struct bio_vec *bvecs, u32 num_bvecs,
442 void osd_req_op_extent_osd_data_bvec_pos(struct ceph_osd_request *osd_req,
444 struct ceph_bvec_iter *bvec_pos);
446 extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
448 struct ceph_pagelist *pagelist);
449 extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
451 struct page **pages, u64 length,
452 u32 alignment, bool pages_from_pool,
454 void osd_req_op_cls_request_data_bvecs(struct ceph_osd_request *osd_req,
456 struct bio_vec *bvecs, u32 num_bvecs,
458 extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
460 struct page **pages, u64 length,
461 u32 alignment, bool pages_from_pool,
463 int osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
464 const char *class, const char *method);
465 extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
466 u16 opcode, const char *name, const void *value,
467 size_t size, u8 cmp_op, u8 cmp_mode);
468 extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
470 u64 expected_object_size,
471 u64 expected_write_size);
473 extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
474 struct ceph_snap_context *snapc,
475 unsigned int num_ops,
478 int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
480 extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
481 struct ceph_file_layout *layout,
482 struct ceph_vino vino,
483 u64 offset, u64 *len,
484 unsigned int which, int num_ops,
485 int opcode, int flags,
486 struct ceph_snap_context *snapc,
487 u32 truncate_seq, u64 truncate_size,
490 extern void ceph_osdc_get_request(struct ceph_osd_request *req);
491 extern void ceph_osdc_put_request(struct ceph_osd_request *req);
493 extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
494 struct ceph_osd_request *req,
496 extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
497 extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
498 struct ceph_osd_request *req);
499 extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
501 extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
502 void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc);
504 int ceph_osdc_call(struct ceph_osd_client *osdc,
505 struct ceph_object_id *oid,
506 struct ceph_object_locator *oloc,
507 const char *class, const char *method,
509 struct page *req_page, size_t req_len,
510 struct page **resp_pages, size_t *resp_len);
512 extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
513 struct ceph_vino vino,
514 struct ceph_file_layout *layout,
516 u32 truncate_seq, u64 truncate_size,
517 struct page **pages, int nr_pages,
520 extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
521 struct ceph_vino vino,
522 struct ceph_file_layout *layout,
523 struct ceph_snap_context *sc,
525 u32 truncate_seq, u64 truncate_size,
526 struct timespec64 *mtime,
527 struct page **pages, int nr_pages);
529 int ceph_osdc_copy_from(struct ceph_osd_client *osdc,
530 u64 src_snapid, u64 src_version,
531 struct ceph_object_id *src_oid,
532 struct ceph_object_locator *src_oloc,
533 u32 src_fadvise_flags,
534 struct ceph_object_id *dst_oid,
535 struct ceph_object_locator *dst_oloc,
536 u32 dst_fadvise_flags,
540 struct ceph_osd_linger_request *
541 ceph_osdc_watch(struct ceph_osd_client *osdc,
542 struct ceph_object_id *oid,
543 struct ceph_object_locator *oloc,
544 rados_watchcb2_t wcb,
545 rados_watcherrcb_t errcb,
547 int ceph_osdc_unwatch(struct ceph_osd_client *osdc,
548 struct ceph_osd_linger_request *lreq);
550 int ceph_osdc_notify_ack(struct ceph_osd_client *osdc,
551 struct ceph_object_id *oid,
552 struct ceph_object_locator *oloc,
557 int ceph_osdc_notify(struct ceph_osd_client *osdc,
558 struct ceph_object_id *oid,
559 struct ceph_object_locator *oloc,
563 struct page ***preply_pages,
565 int ceph_osdc_watch_check(struct ceph_osd_client *osdc,
566 struct ceph_osd_linger_request *lreq);
567 int ceph_osdc_list_watchers(struct ceph_osd_client *osdc,
568 struct ceph_object_id *oid,
569 struct ceph_object_locator *oloc,
570 struct ceph_watch_item **watchers,