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 */
62 struct ceph_osd_data
{
63 enum ceph_osd_data_type type
;
72 struct ceph_pagelist
*pagelist
;
75 struct bio
*bio
; /* list of bios */
76 size_t bio_length
; /* total in list */
78 #endif /* CONFIG_BLOCK */
82 struct ceph_osd_req_op
{
83 u16 op
; /* CEPH_OSD_OP_* */
84 u32 flags
; /* CEPH_OSD_OP_FLAG_* */
85 u32 indata_len
; /* request */
86 u32 outdata_len
; /* reply */
90 struct ceph_osd_data raw_data_in
;
95 struct ceph_osd_data osd_data
;
100 __u8 cmp_op
; /* CEPH_OSD_CMPXATTR_OP_* */
101 __u8 cmp_mode
; /* CEPH_OSD_CMPXATTR_MODE_* */
102 struct ceph_osd_data osd_data
;
105 const char *class_name
;
106 const char *method_name
;
107 struct ceph_osd_data request_info
;
108 struct ceph_osd_data request_data
;
109 struct ceph_osd_data response_data
;
116 __u8 op
; /* CEPH_OSD_WATCH_OP_ */
120 struct ceph_osd_data request_data
;
124 struct ceph_osd_data request_data
;
125 struct ceph_osd_data response_data
;
128 struct ceph_osd_data response_data
;
131 u64 expected_object_size
;
132 u64 expected_write_size
;
137 struct ceph_osd_request_target
{
138 struct ceph_object_id base_oid
;
139 struct ceph_object_locator base_oloc
;
140 struct ceph_object_id target_oid
;
141 struct ceph_object_locator target_oloc
;
143 struct ceph_pg pgid
; /* last raw pg we mapped to */
144 struct ceph_spg spgid
; /* last actual spg we mapped to */
147 struct ceph_osds acting
;
152 bool recovery_deletes
;
154 unsigned int flags
; /* CEPH_OSD_FLAG_* */
158 u32 last_force_resend
;
163 /* an in-flight request */
164 struct ceph_osd_request
{
165 u64 r_tid
; /* unique for this client */
166 struct rb_node r_node
;
167 struct rb_node r_mc_node
; /* map check */
168 struct ceph_osd
*r_osd
;
170 struct ceph_osd_request_target r_t
;
171 #define r_base_oid r_t.base_oid
172 #define r_base_oloc r_t.base_oloc
173 #define r_flags r_t.flags
175 struct ceph_msg
*r_request
, *r_reply
;
176 u32 r_sent
; /* >0 if r_request is sending/sent */
178 /* request osd ops array */
179 unsigned int r_num_ops
;
183 struct ceph_osd_client
*r_osdc
;
186 struct completion r_completion
; /* private to osd_client.c */
187 ceph_osdc_callback_t r_callback
;
188 struct list_head r_unsafe_item
;
190 struct inode
*r_inode
; /* for use by callbacks */
191 void *r_priv
; /* ditto */
193 /* set by submitter */
194 u64 r_snapid
; /* for reads, CEPH_NOSNAP o/w */
195 struct ceph_snap_context
*r_snapc
; /* for writes */
196 struct timespec r_mtime
; /* ditto */
197 u64 r_data_offset
; /* ditto */
198 bool r_linger
; /* don't resend on failure */
199 bool r_abort_on_full
; /* return ENOSPC when full */
202 unsigned long r_stamp
; /* jiffies, send or check time */
203 unsigned long r_start_stamp
; /* jiffies */
207 struct ceph_osd_req_op r_ops
[];
210 struct ceph_request_redirect
{
211 struct ceph_object_locator oloc
;
215 * osd request identifier
217 * caller name + incarnation# + tid to unique identify this request
219 struct ceph_osd_reqid
{
220 struct ceph_entity_name name
;
225 struct ceph_blkin_trace_info
{
228 __le64 parent_span_id
;
231 typedef void (*rados_watchcb2_t
)(void *arg
, u64 notify_id
, u64 cookie
,
232 u64 notifier_id
, void *data
, size_t data_len
);
233 typedef void (*rados_watcherrcb_t
)(void *arg
, u64 cookie
, int err
);
235 struct ceph_osd_linger_request
{
236 struct ceph_osd_client
*osdc
;
239 bool is_watch
; /* watch or notify */
241 struct ceph_osd
*osd
;
242 struct ceph_osd_request
*reg_req
;
243 struct ceph_osd_request
*ping_req
;
244 unsigned long ping_sent
;
245 unsigned long watch_valid_thru
;
246 struct list_head pending_lworks
;
248 struct ceph_osd_request_target t
;
251 struct timespec mtime
;
255 struct rb_node node
; /* osd */
256 struct rb_node osdc_node
; /* osdc */
257 struct rb_node mc_node
; /* map check */
258 struct list_head scan_item
;
260 struct completion reg_commit_wait
;
261 struct completion notify_finish_wait
;
262 int reg_commit_error
;
263 int notify_finish_error
;
269 rados_watchcb2_t wcb
;
270 rados_watcherrcb_t errcb
;
273 struct page
***preply_pages
;
277 struct ceph_watch_item
{
278 struct ceph_entity_name name
;
280 struct ceph_entity_addr addr
;
283 struct ceph_spg_mapping
{
285 struct ceph_spg spgid
;
287 struct rb_root backoffs
;
290 struct ceph_hobject_id
{
303 u32 hash_reverse_bits
;
306 static inline void ceph_hoid_build_hash_cache(struct ceph_hobject_id
*hoid
)
308 hoid
->hash_reverse_bits
= bitrev32(hoid
->hash
);
312 * PG-wide backoff: [begin, end)
313 * per-object backoff: begin == end
315 struct ceph_osd_backoff
{
316 struct rb_node spg_node
;
317 struct rb_node id_node
;
319 struct ceph_spg spgid
;
321 struct ceph_hobject_id
*begin
;
322 struct ceph_hobject_id
*end
;
325 #define CEPH_LINGER_ID_START 0xffff000000000000ULL
327 struct ceph_osd_client
{
328 struct ceph_client
*client
;
330 struct ceph_osdmap
*osdmap
; /* current map */
331 struct rw_semaphore lock
;
333 struct rb_root osds
; /* osds */
334 struct list_head osd_lru
; /* idle osds */
335 spinlock_t osd_lru_lock
;
337 struct ceph_osd homeless_osd
;
338 atomic64_t last_tid
; /* tid of last request */
340 struct rb_root linger_requests
; /* lingering requests */
341 struct rb_root map_checks
;
342 struct rb_root linger_map_checks
;
343 atomic_t num_requests
;
344 atomic_t num_homeless
;
345 struct delayed_work timeout_work
;
346 struct delayed_work osds_timeout_work
;
347 #ifdef CONFIG_DEBUG_FS
348 struct dentry
*debugfs_file
;
351 mempool_t
*req_mempool
;
353 struct ceph_msgpool msgpool_op
;
354 struct ceph_msgpool msgpool_op_reply
;
356 struct workqueue_struct
*notify_wq
;
359 static inline bool ceph_osdmap_flag(struct ceph_osd_client
*osdc
, int flag
)
361 return osdc
->osdmap
->flags
& flag
;
364 extern int ceph_osdc_setup(void);
365 extern void ceph_osdc_cleanup(void);
367 extern int ceph_osdc_init(struct ceph_osd_client
*osdc
,
368 struct ceph_client
*client
);
369 extern void ceph_osdc_stop(struct ceph_osd_client
*osdc
);
371 extern void ceph_osdc_handle_reply(struct ceph_osd_client
*osdc
,
372 struct ceph_msg
*msg
);
373 extern void ceph_osdc_handle_map(struct ceph_osd_client
*osdc
,
374 struct ceph_msg
*msg
);
375 void ceph_osdc_update_epoch_barrier(struct ceph_osd_client
*osdc
, u32 eb
);
377 extern void osd_req_op_init(struct ceph_osd_request
*osd_req
,
378 unsigned int which
, u16 opcode
, u32 flags
);
380 extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request
*,
382 struct page
**pages
, u64 length
,
383 u32 alignment
, bool pages_from_pool
,
386 extern void osd_req_op_extent_init(struct ceph_osd_request
*osd_req
,
387 unsigned int which
, u16 opcode
,
388 u64 offset
, u64 length
,
389 u64 truncate_size
, u32 truncate_seq
);
390 extern void osd_req_op_extent_update(struct ceph_osd_request
*osd_req
,
391 unsigned int which
, u64 length
);
392 extern void osd_req_op_extent_dup_last(struct ceph_osd_request
*osd_req
,
393 unsigned int which
, u64 offset_inc
);
395 extern struct ceph_osd_data
*osd_req_op_extent_osd_data(
396 struct ceph_osd_request
*osd_req
,
399 extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request
*,
401 struct page
**pages
, u64 length
,
402 u32 alignment
, bool pages_from_pool
,
404 extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request
*,
406 struct ceph_pagelist
*pagelist
);
408 extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request
*,
410 struct bio
*bio
, size_t bio_length
);
411 #endif /* CONFIG_BLOCK */
413 extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request
*,
415 struct ceph_pagelist
*pagelist
);
416 extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request
*,
418 struct page
**pages
, u64 length
,
419 u32 alignment
, bool pages_from_pool
,
421 extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request
*,
423 struct page
**pages
, u64 length
,
424 u32 alignment
, bool pages_from_pool
,
426 extern void osd_req_op_cls_init(struct ceph_osd_request
*osd_req
,
427 unsigned int which
, u16 opcode
,
428 const char *class, const char *method
);
429 extern int osd_req_op_xattr_init(struct ceph_osd_request
*osd_req
, unsigned int which
,
430 u16 opcode
, const char *name
, const void *value
,
431 size_t size
, u8 cmp_op
, u8 cmp_mode
);
432 extern void osd_req_op_alloc_hint_init(struct ceph_osd_request
*osd_req
,
434 u64 expected_object_size
,
435 u64 expected_write_size
);
437 extern struct ceph_osd_request
*ceph_osdc_alloc_request(struct ceph_osd_client
*osdc
,
438 struct ceph_snap_context
*snapc
,
439 unsigned int num_ops
,
442 int ceph_osdc_alloc_messages(struct ceph_osd_request
*req
, gfp_t gfp
);
444 extern struct ceph_osd_request
*ceph_osdc_new_request(struct ceph_osd_client
*,
445 struct ceph_file_layout
*layout
,
446 struct ceph_vino vino
,
447 u64 offset
, u64
*len
,
448 unsigned int which
, int num_ops
,
449 int opcode
, int flags
,
450 struct ceph_snap_context
*snapc
,
451 u32 truncate_seq
, u64 truncate_size
,
454 extern void ceph_osdc_get_request(struct ceph_osd_request
*req
);
455 extern void ceph_osdc_put_request(struct ceph_osd_request
*req
);
457 extern int ceph_osdc_start_request(struct ceph_osd_client
*osdc
,
458 struct ceph_osd_request
*req
,
460 extern void ceph_osdc_cancel_request(struct ceph_osd_request
*req
);
461 extern int ceph_osdc_wait_request(struct ceph_osd_client
*osdc
,
462 struct ceph_osd_request
*req
);
463 extern void ceph_osdc_sync(struct ceph_osd_client
*osdc
);
465 extern void ceph_osdc_flush_notifies(struct ceph_osd_client
*osdc
);
466 void ceph_osdc_maybe_request_map(struct ceph_osd_client
*osdc
);
468 int ceph_osdc_call(struct ceph_osd_client
*osdc
,
469 struct ceph_object_id
*oid
,
470 struct ceph_object_locator
*oloc
,
471 const char *class, const char *method
,
473 struct page
*req_page
, size_t req_len
,
474 struct page
*resp_page
, size_t *resp_len
);
476 extern int ceph_osdc_readpages(struct ceph_osd_client
*osdc
,
477 struct ceph_vino vino
,
478 struct ceph_file_layout
*layout
,
480 u32 truncate_seq
, u64 truncate_size
,
481 struct page
**pages
, int nr_pages
,
484 extern int ceph_osdc_writepages(struct ceph_osd_client
*osdc
,
485 struct ceph_vino vino
,
486 struct ceph_file_layout
*layout
,
487 struct ceph_snap_context
*sc
,
489 u32 truncate_seq
, u64 truncate_size
,
490 struct timespec
*mtime
,
491 struct page
**pages
, int nr_pages
);
494 struct ceph_osd_linger_request
*
495 ceph_osdc_watch(struct ceph_osd_client
*osdc
,
496 struct ceph_object_id
*oid
,
497 struct ceph_object_locator
*oloc
,
498 rados_watchcb2_t wcb
,
499 rados_watcherrcb_t errcb
,
501 int ceph_osdc_unwatch(struct ceph_osd_client
*osdc
,
502 struct ceph_osd_linger_request
*lreq
);
504 int ceph_osdc_notify_ack(struct ceph_osd_client
*osdc
,
505 struct ceph_object_id
*oid
,
506 struct ceph_object_locator
*oloc
,
511 int ceph_osdc_notify(struct ceph_osd_client
*osdc
,
512 struct ceph_object_id
*oid
,
513 struct ceph_object_locator
*oloc
,
517 struct page
***preply_pages
,
519 int ceph_osdc_watch_check(struct ceph_osd_client
*osdc
,
520 struct ceph_osd_linger_request
*lreq
);
521 int ceph_osdc_list_watchers(struct ceph_osd_client
*osdc
,
522 struct ceph_object_id
*oid
,
523 struct ceph_object_locator
*oloc
,
524 struct ceph_watch_item
**watchers
,