1 #ifndef _FS_CEPH_OSD_CLIENT_H
2 #define _FS_CEPH_OSD_CLIENT_H
4 #include <linux/completion.h>
5 #include <linux/kref.h>
6 #include <linux/mempool.h>
7 #include <linux/rbtree.h>
11 #include "messenger.h"
14 struct ceph_snap_context
;
15 struct ceph_osd_request
;
16 struct ceph_osd_client
;
17 struct ceph_authorizer
;
21 * completion callback for async writepages
23 typedef void (*ceph_osdc_callback_t
)(struct ceph_osd_request
*,
26 /* a given osd we're communicating with */
29 struct ceph_osd_client
*o_osdc
;
32 struct rb_node o_node
;
33 struct ceph_connection o_con
;
34 struct list_head o_requests
;
35 struct list_head o_linger_requests
;
36 struct list_head o_osd_lru
;
37 struct ceph_authorizer
*o_authorizer
;
38 void *o_authorizer_buf
, *o_authorizer_reply_buf
;
39 size_t o_authorizer_buf_len
, o_authorizer_reply_buf_len
;
40 unsigned long lru_ttl
;
41 int o_marked_for_keepalive
;
42 struct list_head o_keepalive_item
;
45 /* an in-flight request */
46 struct ceph_osd_request
{
47 u64 r_tid
; /* unique for this client */
48 struct rb_node r_node
;
49 struct list_head r_req_lru_item
;
50 struct list_head r_osd_item
;
51 struct list_head r_linger_item
;
52 struct list_head r_linger_osd
;
53 struct ceph_osd
*r_osd
;
54 struct ceph_pg r_pgid
;
55 int r_pg_osds
[CEPH_PG_MAX_SIZE
];
58 struct ceph_connection
*r_con_filling_msg
;
60 struct ceph_msg
*r_request
, *r_reply
;
62 int r_flags
; /* any additional flags for the osd */
63 u32 r_sent
; /* >0 if r_request is sending/sent */
67 struct ceph_osd_client
*r_osdc
;
70 struct completion r_completion
, r_safe_completion
;
71 ceph_osdc_callback_t r_callback
, r_safe_callback
;
72 struct ceph_eversion r_reassert_version
;
73 struct list_head r_unsafe_item
;
75 struct inode
*r_inode
; /* for use by callbacks */
76 void *r_priv
; /* ditto */
78 char r_oid
[40]; /* object name */
80 unsigned long r_stamp
; /* send OR check time */
82 struct ceph_file_layout r_file_layout
;
83 struct ceph_snap_context
*r_snapc
; /* snap context for writes */
84 unsigned r_num_pages
; /* size of page array (follows) */
85 unsigned r_page_alignment
; /* io offset in first page */
86 struct page
**r_pages
; /* pages for data payload */
87 int r_pages_from_pool
;
88 int r_own_pages
; /* if true, i own page list */
90 struct bio
*r_bio
; /* instead of pages */
93 struct ceph_pagelist
*r_trail
; /* trailing part of the data */
96 struct ceph_osd_event
{
99 struct ceph_osd_client
*osdc
;
100 void (*cb
)(u64
, u64
, u8
, void *);
103 struct list_head osd_node
;
105 struct completion completion
;
108 struct ceph_osd_event_work
{
109 struct work_struct work
;
110 struct ceph_osd_event
*event
;
116 struct ceph_osd_client
{
117 struct ceph_client
*client
;
119 struct ceph_osdmap
*osdmap
; /* current map */
120 struct rw_semaphore map_sem
;
121 struct completion map_waiters
;
122 u64 last_requested_map
;
124 struct mutex request_mutex
;
125 struct rb_root osds
; /* osds */
126 struct list_head osd_lru
; /* idle osds */
127 u64 timeout_tid
; /* tid of timeout triggering rq */
128 u64 last_tid
; /* tid of last request */
129 struct rb_root requests
; /* pending requests */
130 struct list_head req_lru
; /* in-flight lru */
131 struct list_head req_unsent
; /* unsent/need-resend queue */
132 struct list_head req_notarget
; /* map to no osd */
133 struct list_head req_linger
; /* lingering requests */
135 struct delayed_work timeout_work
;
136 struct delayed_work osds_timeout_work
;
137 #ifdef CONFIG_DEBUG_FS
138 struct dentry
*debugfs_file
;
141 mempool_t
*req_mempool
;
143 struct ceph_msgpool msgpool_op
;
144 struct ceph_msgpool msgpool_op_reply
;
146 spinlock_t event_lock
;
147 struct rb_root event_tree
;
150 struct workqueue_struct
*notify_wq
;
153 struct ceph_osd_req_op
{
154 u16 op
; /* CEPH_OSD_OP_* */
155 u32 flags
; /* CEPH_OSD_FLAG_* */
167 __u8 cmp_op
; /* CEPH_OSD_CMPXATTR_OP_* */
168 __u8 cmp_mode
; /* CEPH_OSD_CMPXATTR_MODE_* */
171 const char *class_name
;
173 const char *method_name
;
196 extern int ceph_osdc_init(struct ceph_osd_client
*osdc
,
197 struct ceph_client
*client
);
198 extern void ceph_osdc_stop(struct ceph_osd_client
*osdc
);
200 extern void ceph_osdc_handle_reply(struct ceph_osd_client
*osdc
,
201 struct ceph_msg
*msg
);
202 extern void ceph_osdc_handle_map(struct ceph_osd_client
*osdc
,
203 struct ceph_msg
*msg
);
205 extern void ceph_calc_raw_layout(struct ceph_osd_client
*osdc
,
206 struct ceph_file_layout
*layout
,
208 u64 off
, u64
*plen
, u64
*bno
,
209 struct ceph_osd_request
*req
,
210 struct ceph_osd_req_op
*op
);
212 extern struct ceph_osd_request
*ceph_osdc_alloc_request(struct ceph_osd_client
*osdc
,
214 struct ceph_snap_context
*snapc
,
215 struct ceph_osd_req_op
*ops
,
221 extern void ceph_osdc_build_request(struct ceph_osd_request
*req
,
223 struct ceph_osd_req_op
*src_ops
,
224 struct ceph_snap_context
*snapc
,
225 struct timespec
*mtime
,
229 extern struct ceph_osd_request
*ceph_osdc_new_request(struct ceph_osd_client
*,
230 struct ceph_file_layout
*layout
,
231 struct ceph_vino vino
,
232 u64 offset
, u64
*len
, int op
, int flags
,
233 struct ceph_snap_context
*snapc
,
234 int do_sync
, u32 truncate_seq
,
236 struct timespec
*mtime
,
237 bool use_mempool
, int num_reply
,
240 extern void ceph_osdc_set_request_linger(struct ceph_osd_client
*osdc
,
241 struct ceph_osd_request
*req
);
242 extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client
*osdc
,
243 struct ceph_osd_request
*req
);
245 static inline void ceph_osdc_get_request(struct ceph_osd_request
*req
)
247 kref_get(&req
->r_kref
);
249 extern void ceph_osdc_release_request(struct kref
*kref
);
250 static inline void ceph_osdc_put_request(struct ceph_osd_request
*req
)
252 kref_put(&req
->r_kref
, ceph_osdc_release_request
);
255 extern int ceph_osdc_start_request(struct ceph_osd_client
*osdc
,
256 struct ceph_osd_request
*req
,
258 extern int ceph_osdc_wait_request(struct ceph_osd_client
*osdc
,
259 struct ceph_osd_request
*req
);
260 extern void ceph_osdc_sync(struct ceph_osd_client
*osdc
);
262 extern int ceph_osdc_readpages(struct ceph_osd_client
*osdc
,
263 struct ceph_vino vino
,
264 struct ceph_file_layout
*layout
,
266 u32 truncate_seq
, u64 truncate_size
,
267 struct page
**pages
, int nr_pages
,
270 extern int ceph_osdc_writepages(struct ceph_osd_client
*osdc
,
271 struct ceph_vino vino
,
272 struct ceph_file_layout
*layout
,
273 struct ceph_snap_context
*sc
,
275 u32 truncate_seq
, u64 truncate_size
,
276 struct timespec
*mtime
,
277 struct page
**pages
, int nr_pages
,
278 int flags
, int do_sync
, bool nofail
);
280 /* watch/notify events */
281 extern int ceph_osdc_create_event(struct ceph_osd_client
*osdc
,
282 void (*event_cb
)(u64
, u64
, u8
, void *),
283 int one_shot
, void *data
,
284 struct ceph_osd_event
**pevent
);
285 extern void ceph_osdc_cancel_event(struct ceph_osd_event
*event
);
286 extern int ceph_osdc_wait_event(struct ceph_osd_event
*event
,
287 unsigned long timeout
);
288 extern void ceph_osdc_put_event(struct ceph_osd_event
*event
);