1 #ifndef _FS_CEPH_OSD_CLIENT_H
2 #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>
11 #include <linux/ceph/types.h>
12 #include <linux/ceph/osdmap.h>
13 #include <linux/ceph/messenger.h>
14 #include <linux/ceph/msgpool.h>
15 #include <linux/ceph/auth.h>
16 #include <linux/ceph/pagelist.h>
19 struct ceph_snap_context
;
20 struct ceph_osd_request
;
21 struct ceph_osd_client
;
24 * completion callback for async writepages
26 typedef void (*ceph_osdc_callback_t
)(struct ceph_osd_request
*);
28 #define CEPH_HOMELESS_OSD -1
30 /* a given osd we're communicating with */
33 struct ceph_osd_client
*o_osdc
;
36 struct rb_node o_node
;
37 struct ceph_connection o_con
;
38 struct rb_root o_requests
;
39 struct rb_root o_linger_requests
;
40 struct rb_root o_backoff_mappings
;
41 struct rb_root o_backoffs_by_id
;
42 struct list_head o_osd_lru
;
43 struct ceph_auth_handshake o_auth
;
44 unsigned long lru_ttl
;
45 struct list_head o_keepalive_item
;
49 #define CEPH_OSD_SLAB_OPS 2
50 #define CEPH_OSD_MAX_OPS 16
52 enum ceph_osd_data_type
{
53 CEPH_OSD_DATA_TYPE_NONE
= 0,
54 CEPH_OSD_DATA_TYPE_PAGES
,
55 CEPH_OSD_DATA_TYPE_PAGELIST
,
57 CEPH_OSD_DATA_TYPE_BIO
,
58 #endif /* CONFIG_BLOCK */
61 struct ceph_osd_data
{
62 enum ceph_osd_data_type type
;
71 struct ceph_pagelist
*pagelist
;
74 struct bio
*bio
; /* list of bios */
75 size_t bio_length
; /* total in list */
77 #endif /* CONFIG_BLOCK */
81 struct ceph_osd_req_op
{
82 u16 op
; /* CEPH_OSD_OP_* */
83 u32 flags
; /* CEPH_OSD_OP_FLAG_* */
84 u32 indata_len
; /* request */
85 u32 outdata_len
; /* reply */
89 struct ceph_osd_data raw_data_in
;
94 struct ceph_osd_data osd_data
;
99 __u8 cmp_op
; /* CEPH_OSD_CMPXATTR_OP_* */
100 __u8 cmp_mode
; /* CEPH_OSD_CMPXATTR_MODE_* */
101 struct ceph_osd_data osd_data
;
104 const char *class_name
;
105 const char *method_name
;
106 struct ceph_osd_data request_info
;
107 struct ceph_osd_data request_data
;
108 struct ceph_osd_data response_data
;
115 __u8 op
; /* CEPH_OSD_WATCH_OP_ */
119 struct ceph_osd_data request_data
;
123 struct ceph_osd_data request_data
;
124 struct ceph_osd_data response_data
;
127 struct ceph_osd_data response_data
;
130 u64 expected_object_size
;
131 u64 expected_write_size
;
136 struct ceph_osd_request_target
{
137 struct ceph_object_id base_oid
;
138 struct ceph_object_locator base_oloc
;
139 struct ceph_object_id target_oid
;
140 struct ceph_object_locator target_oloc
;
142 struct ceph_pg pgid
; /* last raw pg we mapped to */
143 struct ceph_spg spgid
; /* last actual spg we mapped to */
146 struct ceph_osds acting
;
151 bool recovery_deletes
;
153 unsigned int flags
; /* CEPH_OSD_FLAG_* */
157 u32 last_force_resend
;
162 /* an in-flight request */
163 struct ceph_osd_request
{
164 u64 r_tid
; /* unique for this client */
165 struct rb_node r_node
;
166 struct rb_node r_mc_node
; /* map check */
167 struct ceph_osd
*r_osd
;
169 struct ceph_osd_request_target r_t
;
170 #define r_base_oid r_t.base_oid
171 #define r_base_oloc r_t.base_oloc
172 #define r_flags r_t.flags
174 struct ceph_msg
*r_request
, *r_reply
;
175 u32 r_sent
; /* >0 if r_request is sending/sent */
177 /* request osd ops array */
178 unsigned int r_num_ops
;
182 struct ceph_osd_client
*r_osdc
;
185 struct completion r_completion
; /* private to osd_client.c */
186 ceph_osdc_callback_t r_callback
;
187 struct list_head r_unsafe_item
;
189 struct inode
*r_inode
; /* for use by callbacks */
190 void *r_priv
; /* ditto */
192 /* set by submitter */
193 u64 r_snapid
; /* for reads, CEPH_NOSNAP o/w */
194 struct ceph_snap_context
*r_snapc
; /* for writes */
195 struct timespec r_mtime
; /* ditto */
196 u64 r_data_offset
; /* ditto */
197 bool r_linger
; /* don't resend on failure */
198 bool r_abort_on_full
; /* return ENOSPC when full */
201 unsigned long r_stamp
; /* jiffies, send or check time */
202 unsigned long r_start_stamp
; /* jiffies */
206 struct ceph_osd_req_op r_ops
[];
209 struct ceph_request_redirect
{
210 struct ceph_object_locator oloc
;
214 * osd request identifier
216 * caller name + incarnation# + tid to unique identify this request
218 struct ceph_osd_reqid
{
219 struct ceph_entity_name name
;
224 struct ceph_blkin_trace_info
{
227 __le64 parent_span_id
;
230 typedef void (*rados_watchcb2_t
)(void *arg
, u64 notify_id
, u64 cookie
,
231 u64 notifier_id
, void *data
, size_t data_len
);
232 typedef void (*rados_watcherrcb_t
)(void *arg
, u64 cookie
, int err
);
234 struct ceph_osd_linger_request
{
235 struct ceph_osd_client
*osdc
;
238 bool is_watch
; /* watch or notify */
240 struct ceph_osd
*osd
;
241 struct ceph_osd_request
*reg_req
;
242 struct ceph_osd_request
*ping_req
;
243 unsigned long ping_sent
;
244 unsigned long watch_valid_thru
;
245 struct list_head pending_lworks
;
247 struct ceph_osd_request_target t
;
250 struct timespec mtime
;
254 struct rb_node node
; /* osd */
255 struct rb_node osdc_node
; /* osdc */
256 struct rb_node mc_node
; /* map check */
257 struct list_head scan_item
;
259 struct completion reg_commit_wait
;
260 struct completion notify_finish_wait
;
261 int reg_commit_error
;
262 int notify_finish_error
;
268 rados_watchcb2_t wcb
;
269 rados_watcherrcb_t errcb
;
272 struct page
***preply_pages
;
276 struct ceph_watch_item
{
277 struct ceph_entity_name name
;
279 struct ceph_entity_addr addr
;
282 struct ceph_spg_mapping
{
284 struct ceph_spg spgid
;
286 struct rb_root backoffs
;
289 struct ceph_hobject_id
{
302 u32 hash_reverse_bits
;
305 static inline void ceph_hoid_build_hash_cache(struct ceph_hobject_id
*hoid
)
307 hoid
->hash_reverse_bits
= bitrev32(hoid
->hash
);
311 * PG-wide backoff: [begin, end)
312 * per-object backoff: begin == end
314 struct ceph_osd_backoff
{
315 struct rb_node spg_node
;
316 struct rb_node id_node
;
318 struct ceph_spg spgid
;
320 struct ceph_hobject_id
*begin
;
321 struct ceph_hobject_id
*end
;
324 #define CEPH_LINGER_ID_START 0xffff000000000000ULL
326 struct ceph_osd_client
{
327 struct ceph_client
*client
;
329 struct ceph_osdmap
*osdmap
; /* current map */
330 struct rw_semaphore lock
;
332 struct rb_root osds
; /* osds */
333 struct list_head osd_lru
; /* idle osds */
334 spinlock_t osd_lru_lock
;
336 struct ceph_osd homeless_osd
;
337 atomic64_t last_tid
; /* tid of last request */
339 struct rb_root linger_requests
; /* lingering requests */
340 struct rb_root map_checks
;
341 struct rb_root linger_map_checks
;
342 atomic_t num_requests
;
343 atomic_t num_homeless
;
344 struct delayed_work timeout_work
;
345 struct delayed_work osds_timeout_work
;
346 #ifdef CONFIG_DEBUG_FS
347 struct dentry
*debugfs_file
;
350 mempool_t
*req_mempool
;
352 struct ceph_msgpool msgpool_op
;
353 struct ceph_msgpool msgpool_op_reply
;
355 struct workqueue_struct
*notify_wq
;
358 static inline bool ceph_osdmap_flag(struct ceph_osd_client
*osdc
, int flag
)
360 return osdc
->osdmap
->flags
& flag
;
363 extern int ceph_osdc_setup(void);
364 extern void ceph_osdc_cleanup(void);
366 extern int ceph_osdc_init(struct ceph_osd_client
*osdc
,
367 struct ceph_client
*client
);
368 extern void ceph_osdc_stop(struct ceph_osd_client
*osdc
);
370 extern void ceph_osdc_handle_reply(struct ceph_osd_client
*osdc
,
371 struct ceph_msg
*msg
);
372 extern void ceph_osdc_handle_map(struct ceph_osd_client
*osdc
,
373 struct ceph_msg
*msg
);
374 void ceph_osdc_update_epoch_barrier(struct ceph_osd_client
*osdc
, u32 eb
);
376 extern void osd_req_op_init(struct ceph_osd_request
*osd_req
,
377 unsigned int which
, u16 opcode
, u32 flags
);
379 extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request
*,
381 struct page
**pages
, u64 length
,
382 u32 alignment
, bool pages_from_pool
,
385 extern void osd_req_op_extent_init(struct ceph_osd_request
*osd_req
,
386 unsigned int which
, u16 opcode
,
387 u64 offset
, u64 length
,
388 u64 truncate_size
, u32 truncate_seq
);
389 extern void osd_req_op_extent_update(struct ceph_osd_request
*osd_req
,
390 unsigned int which
, u64 length
);
391 extern void osd_req_op_extent_dup_last(struct ceph_osd_request
*osd_req
,
392 unsigned int which
, u64 offset_inc
);
394 extern struct ceph_osd_data
*osd_req_op_extent_osd_data(
395 struct ceph_osd_request
*osd_req
,
398 extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request
*,
400 struct page
**pages
, u64 length
,
401 u32 alignment
, bool pages_from_pool
,
403 extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request
*,
405 struct ceph_pagelist
*pagelist
);
407 extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request
*,
409 struct bio
*bio
, size_t bio_length
);
410 #endif /* CONFIG_BLOCK */
412 extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request
*,
414 struct ceph_pagelist
*pagelist
);
415 extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request
*,
417 struct page
**pages
, u64 length
,
418 u32 alignment
, bool pages_from_pool
,
420 extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request
*,
422 struct page
**pages
, u64 length
,
423 u32 alignment
, bool pages_from_pool
,
425 extern void osd_req_op_cls_init(struct ceph_osd_request
*osd_req
,
426 unsigned int which
, u16 opcode
,
427 const char *class, const char *method
);
428 extern int osd_req_op_xattr_init(struct ceph_osd_request
*osd_req
, unsigned int which
,
429 u16 opcode
, const char *name
, const void *value
,
430 size_t size
, u8 cmp_op
, u8 cmp_mode
);
431 extern void osd_req_op_alloc_hint_init(struct ceph_osd_request
*osd_req
,
433 u64 expected_object_size
,
434 u64 expected_write_size
);
436 extern struct ceph_osd_request
*ceph_osdc_alloc_request(struct ceph_osd_client
*osdc
,
437 struct ceph_snap_context
*snapc
,
438 unsigned int num_ops
,
441 int ceph_osdc_alloc_messages(struct ceph_osd_request
*req
, gfp_t gfp
);
443 extern struct ceph_osd_request
*ceph_osdc_new_request(struct ceph_osd_client
*,
444 struct ceph_file_layout
*layout
,
445 struct ceph_vino vino
,
446 u64 offset
, u64
*len
,
447 unsigned int which
, int num_ops
,
448 int opcode
, int flags
,
449 struct ceph_snap_context
*snapc
,
450 u32 truncate_seq
, u64 truncate_size
,
453 extern void ceph_osdc_get_request(struct ceph_osd_request
*req
);
454 extern void ceph_osdc_put_request(struct ceph_osd_request
*req
);
456 extern int ceph_osdc_start_request(struct ceph_osd_client
*osdc
,
457 struct ceph_osd_request
*req
,
459 extern void ceph_osdc_cancel_request(struct ceph_osd_request
*req
);
460 extern int ceph_osdc_wait_request(struct ceph_osd_client
*osdc
,
461 struct ceph_osd_request
*req
);
462 extern void ceph_osdc_sync(struct ceph_osd_client
*osdc
);
464 extern void ceph_osdc_flush_notifies(struct ceph_osd_client
*osdc
);
465 void ceph_osdc_maybe_request_map(struct ceph_osd_client
*osdc
);
467 int ceph_osdc_call(struct ceph_osd_client
*osdc
,
468 struct ceph_object_id
*oid
,
469 struct ceph_object_locator
*oloc
,
470 const char *class, const char *method
,
472 struct page
*req_page
, size_t req_len
,
473 struct page
*resp_page
, size_t *resp_len
);
475 extern int ceph_osdc_readpages(struct ceph_osd_client
*osdc
,
476 struct ceph_vino vino
,
477 struct ceph_file_layout
*layout
,
479 u32 truncate_seq
, u64 truncate_size
,
480 struct page
**pages
, int nr_pages
,
483 extern int ceph_osdc_writepages(struct ceph_osd_client
*osdc
,
484 struct ceph_vino vino
,
485 struct ceph_file_layout
*layout
,
486 struct ceph_snap_context
*sc
,
488 u32 truncate_seq
, u64 truncate_size
,
489 struct timespec
*mtime
,
490 struct page
**pages
, int nr_pages
);
493 struct ceph_osd_linger_request
*
494 ceph_osdc_watch(struct ceph_osd_client
*osdc
,
495 struct ceph_object_id
*oid
,
496 struct ceph_object_locator
*oloc
,
497 rados_watchcb2_t wcb
,
498 rados_watcherrcb_t errcb
,
500 int ceph_osdc_unwatch(struct ceph_osd_client
*osdc
,
501 struct ceph_osd_linger_request
*lreq
);
503 int ceph_osdc_notify_ack(struct ceph_osd_client
*osdc
,
504 struct ceph_object_id
*oid
,
505 struct ceph_object_locator
*oloc
,
510 int ceph_osdc_notify(struct ceph_osd_client
*osdc
,
511 struct ceph_object_id
*oid
,
512 struct ceph_object_locator
*oloc
,
516 struct page
***preply_pages
,
518 int ceph_osdc_watch_check(struct ceph_osd_client
*osdc
,
519 struct ceph_osd_linger_request
*lreq
);
520 int ceph_osdc_list_watchers(struct ceph_osd_client
*osdc
,
521 struct ceph_object_id
*oid
,
522 struct ceph_object_locator
*oloc
,
523 struct ceph_watch_item
**watchers
,