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 u64 last_tid; /* tid of last request */
228 struct rb_root requests; /* pending requests */
229 struct list_head req_lru; /* in-flight lru */
230 struct list_head req_unsent; /* unsent/need-resend queue */
231 struct list_head req_notarget; /* map to no osd */
232 struct list_head req_linger; /* lingering requests */
234 struct delayed_work timeout_work;
235 struct delayed_work osds_timeout_work;
236 #ifdef CONFIG_DEBUG_FS
237 struct dentry *debugfs_file;
240 mempool_t *req_mempool;
242 struct ceph_msgpool msgpool_op;
243 struct ceph_msgpool msgpool_op_reply;
245 spinlock_t event_lock;
246 struct rb_root event_tree;
249 struct workqueue_struct *notify_wq;
252 extern int ceph_osdc_setup(void);
253 extern void ceph_osdc_cleanup(void);
255 extern int ceph_osdc_init(struct ceph_osd_client *osdc,
256 struct ceph_client *client);
257 extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
259 extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
260 struct ceph_msg *msg);
261 extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
262 struct ceph_msg *msg);
264 extern void osd_req_op_init(struct ceph_osd_request *osd_req,
265 unsigned int which, u16 opcode, u32 flags);
267 extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
269 struct page **pages, u64 length,
270 u32 alignment, bool pages_from_pool,
273 extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
274 unsigned int which, u16 opcode,
275 u64 offset, u64 length,
276 u64 truncate_size, u32 truncate_seq);
277 extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
278 unsigned int which, u64 length);
279 extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
280 unsigned int which, u64 offset_inc);
282 extern struct ceph_osd_data *osd_req_op_extent_osd_data(
283 struct ceph_osd_request *osd_req,
286 extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
288 struct page **pages, u64 length,
289 u32 alignment, bool pages_from_pool,
291 extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
293 struct ceph_pagelist *pagelist);
295 extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
297 struct bio *bio, size_t bio_length);
298 #endif /* CONFIG_BLOCK */
300 extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
302 struct ceph_pagelist *pagelist);
303 extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
305 struct page **pages, u64 length,
306 u32 alignment, bool pages_from_pool,
308 extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
310 struct page **pages, u64 length,
311 u32 alignment, bool pages_from_pool,
314 extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
315 unsigned int which, u16 opcode,
316 const char *class, const char *method);
317 extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
318 u16 opcode, const char *name, const void *value,
319 size_t size, u8 cmp_op, u8 cmp_mode);
320 extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
321 unsigned int which, u16 opcode,
322 u64 cookie, u64 version, int flag);
323 extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
325 u64 expected_object_size,
326 u64 expected_write_size);
328 extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
329 struct ceph_snap_context *snapc,
330 unsigned int num_ops,
333 int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
335 extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
336 struct ceph_file_layout *layout,
337 struct ceph_vino vino,
338 u64 offset, u64 *len,
339 unsigned int which, int num_ops,
340 int opcode, int flags,
341 struct ceph_snap_context *snapc,
342 u32 truncate_seq, u64 truncate_size,
345 extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
346 struct ceph_osd_request *req);
348 extern void ceph_osdc_get_request(struct ceph_osd_request *req);
349 extern void ceph_osdc_put_request(struct ceph_osd_request *req);
351 extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
352 struct ceph_osd_request *req,
354 extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
355 extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
356 struct ceph_osd_request *req);
357 extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
359 extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
361 extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
362 struct ceph_vino vino,
363 struct ceph_file_layout *layout,
365 u32 truncate_seq, u64 truncate_size,
366 struct page **pages, int nr_pages,
369 extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
370 struct ceph_vino vino,
371 struct ceph_file_layout *layout,
372 struct ceph_snap_context *sc,
374 u32 truncate_seq, u64 truncate_size,
375 struct timespec *mtime,
376 struct page **pages, int nr_pages);
378 /* watch/notify events */
379 extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
380 void (*event_cb)(u64, u64, u8, void *),
381 void *data, struct ceph_osd_event **pevent);
382 extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
383 extern void ceph_osdc_put_event(struct ceph_osd_event *event);