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>
9 #include <linux/ceph/types.h>
10 #include <linux/ceph/osdmap.h>
11 #include <linux/ceph/messenger.h>
12 #include <linux/ceph/auth.h>
13 #include <linux/ceph/pagelist.h>
16 struct ceph_snap_context;
17 struct ceph_osd_request;
18 struct ceph_osd_client;
21 * completion callback for async writepages
23 typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);
24 typedef void (*ceph_osdc_unsafe_callback_t)(struct ceph_osd_request *, bool);
26 #define CEPH_HOMELESS_OSD -1
28 /* a given osd we're communicating with */
31 struct ceph_osd_client *o_osdc;
34 struct rb_node o_node;
35 struct ceph_connection o_con;
36 struct list_head o_requests;
37 struct list_head o_linger_requests;
38 struct list_head o_osd_lru;
39 struct ceph_auth_handshake o_auth;
40 unsigned long lru_ttl;
41 struct list_head o_keepalive_item;
44 #define CEPH_OSD_SLAB_OPS 2
45 #define CEPH_OSD_MAX_OPS 16
47 enum ceph_osd_data_type {
48 CEPH_OSD_DATA_TYPE_NONE = 0,
49 CEPH_OSD_DATA_TYPE_PAGES,
50 CEPH_OSD_DATA_TYPE_PAGELIST,
52 CEPH_OSD_DATA_TYPE_BIO,
53 #endif /* CONFIG_BLOCK */
56 struct ceph_osd_data {
57 enum ceph_osd_data_type type;
66 struct ceph_pagelist *pagelist;
69 struct bio *bio; /* list of bios */
70 size_t bio_length; /* total in list */
72 #endif /* CONFIG_BLOCK */
76 struct ceph_osd_req_op {
77 u16 op; /* CEPH_OSD_OP_* */
78 u32 flags; /* CEPH_OSD_OP_FLAG_* */
79 u32 indata_len; /* request */
80 u32 outdata_len; /* reply */
84 struct ceph_osd_data raw_data_in;
89 struct ceph_osd_data osd_data;
94 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
95 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
96 struct ceph_osd_data osd_data;
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;
116 u64 expected_object_size;
117 u64 expected_write_size;
122 struct ceph_osd_request_target {
123 struct ceph_object_id base_oid;
124 struct ceph_object_locator base_oloc;
125 struct ceph_object_id target_oid;
126 struct ceph_object_locator target_oloc;
131 struct ceph_osds acting;
137 unsigned int flags; /* CEPH_OSD_FLAG_* */
143 /* an in-flight request */
144 struct ceph_osd_request {
145 u64 r_tid; /* unique for this client */
146 struct rb_node r_node;
147 struct list_head r_req_lru_item;
148 struct list_head r_osd_item;
149 struct list_head r_linger_item;
150 struct list_head r_linger_osd_item;
151 struct ceph_osd *r_osd;
153 struct ceph_osd_request_target r_t;
154 #define r_base_oid r_t.base_oid
155 #define r_base_oloc r_t.base_oloc
156 #define r_flags r_t.flags
158 struct ceph_msg *r_request, *r_reply;
159 u32 r_sent; /* >0 if r_request is sending/sent */
161 /* request osd ops array */
162 unsigned int r_num_ops;
168 struct ceph_osd_client *r_osdc;
171 struct completion r_completion;
172 struct completion r_safe_completion; /* fsync waiter */
173 ceph_osdc_callback_t r_callback;
174 ceph_osdc_unsafe_callback_t r_unsafe_callback;
175 struct list_head r_unsafe_item;
177 struct inode *r_inode; /* for use by callbacks */
178 void *r_priv; /* ditto */
180 /* set by submitter */
181 u64 r_snapid; /* for reads, CEPH_NOSNAP o/w */
182 struct ceph_snap_context *r_snapc; /* for writes */
183 struct timespec r_mtime; /* ditto */
184 u64 r_data_offset; /* ditto */
187 unsigned long r_stamp; /* jiffies, send or check time */
189 struct ceph_eversion r_replay_version; /* aka reassert_version */
190 u32 r_last_force_resend;
192 struct ceph_osd_req_op r_ops[];
195 struct ceph_request_redirect {
196 struct ceph_object_locator oloc;
199 struct ceph_osd_event {
202 struct ceph_osd_client *osdc;
203 void (*cb)(u64, u64, u8, void *);
206 struct list_head osd_node;
210 struct ceph_osd_event_work {
211 struct work_struct work;
212 struct ceph_osd_event *event;
218 struct ceph_osd_client {
219 struct ceph_client *client;
221 struct ceph_osdmap *osdmap; /* current map */
222 struct rw_semaphore map_sem;
224 struct mutex request_mutex;
225 struct rb_root osds; /* osds */
226 struct list_head osd_lru; /* idle osds */
227 spinlock_t osd_lru_lock;
228 u64 last_tid; /* tid of last request */
229 struct rb_root requests; /* pending requests */
230 struct list_head req_lru; /* in-flight lru */
231 struct list_head req_unsent; /* unsent/need-resend queue */
232 struct list_head req_notarget; /* map to no osd */
233 struct list_head req_linger; /* lingering requests */
235 struct delayed_work timeout_work;
236 struct delayed_work osds_timeout_work;
237 #ifdef CONFIG_DEBUG_FS
238 struct dentry *debugfs_file;
241 mempool_t *req_mempool;
243 struct ceph_msgpool msgpool_op;
244 struct ceph_msgpool msgpool_op_reply;
246 spinlock_t event_lock;
247 struct rb_root event_tree;
250 struct workqueue_struct *notify_wq;
253 extern int ceph_osdc_setup(void);
254 extern void ceph_osdc_cleanup(void);
256 extern int ceph_osdc_init(struct ceph_osd_client *osdc,
257 struct ceph_client *client);
258 extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
260 extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
261 struct ceph_msg *msg);
262 extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
263 struct ceph_msg *msg);
265 extern void osd_req_op_init(struct ceph_osd_request *osd_req,
266 unsigned int which, u16 opcode, u32 flags);
268 extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
270 struct page **pages, u64 length,
271 u32 alignment, bool pages_from_pool,
274 extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
275 unsigned int which, u16 opcode,
276 u64 offset, u64 length,
277 u64 truncate_size, u32 truncate_seq);
278 extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
279 unsigned int which, u64 length);
280 extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
281 unsigned int which, u64 offset_inc);
283 extern struct ceph_osd_data *osd_req_op_extent_osd_data(
284 struct ceph_osd_request *osd_req,
287 extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
289 struct page **pages, u64 length,
290 u32 alignment, bool pages_from_pool,
292 extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
294 struct ceph_pagelist *pagelist);
296 extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
298 struct bio *bio, size_t bio_length);
299 #endif /* CONFIG_BLOCK */
301 extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
303 struct ceph_pagelist *pagelist);
304 extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
306 struct page **pages, u64 length,
307 u32 alignment, bool pages_from_pool,
309 extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
311 struct page **pages, u64 length,
312 u32 alignment, bool pages_from_pool,
315 extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
316 unsigned int which, u16 opcode,
317 const char *class, const char *method);
318 extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
319 u16 opcode, const char *name, const void *value,
320 size_t size, u8 cmp_op, u8 cmp_mode);
321 extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
322 unsigned int which, u16 opcode,
323 u64 cookie, u64 version, int flag);
324 extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
326 u64 expected_object_size,
327 u64 expected_write_size);
329 extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
330 struct ceph_snap_context *snapc,
331 unsigned int num_ops,
334 int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
336 extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
337 struct ceph_file_layout *layout,
338 struct ceph_vino vino,
339 u64 offset, u64 *len,
340 unsigned int which, int num_ops,
341 int opcode, int flags,
342 struct ceph_snap_context *snapc,
343 u32 truncate_seq, u64 truncate_size,
346 extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
347 struct ceph_osd_request *req);
349 extern void ceph_osdc_get_request(struct ceph_osd_request *req);
350 extern void ceph_osdc_put_request(struct ceph_osd_request *req);
352 extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
353 struct ceph_osd_request *req,
355 extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
356 extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
357 struct ceph_osd_request *req);
358 extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
360 extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
362 extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
363 struct ceph_vino vino,
364 struct ceph_file_layout *layout,
366 u32 truncate_seq, u64 truncate_size,
367 struct page **pages, int nr_pages,
370 extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
371 struct ceph_vino vino,
372 struct ceph_file_layout *layout,
373 struct ceph_snap_context *sc,
375 u32 truncate_seq, u64 truncate_size,
376 struct timespec *mtime,
377 struct page **pages, int nr_pages);
379 /* watch/notify events */
380 extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
381 void (*event_cb)(u64, u64, u8, void *),
382 void *data, struct ceph_osd_event **pevent);
383 extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
384 extern void ceph_osdc_put_event(struct ceph_osd_event *event);