]> git.karo-electronics.de Git - linux-beck.git/blob - include/linux/ceph/osd_client.h
486d681694c4c383a5dfd03392865fc8f1d50e57
[linux-beck.git] / include / linux / ceph / osd_client.h
1 #ifndef _FS_CEPH_OSD_CLIENT_H
2 #define _FS_CEPH_OSD_CLIENT_H
3
4 #include <linux/completion.h>
5 #include <linux/kref.h>
6 #include <linux/mempool.h>
7 #include <linux/rbtree.h>
8
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>
14
15 struct ceph_msg;
16 struct ceph_snap_context;
17 struct ceph_osd_request;
18 struct ceph_osd_client;
19
20 /*
21  * completion callback for async writepages
22  */
23 typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);
24 typedef void (*ceph_osdc_unsafe_callback_t)(struct ceph_osd_request *, bool);
25
26 #define CEPH_HOMELESS_OSD       -1
27
28 /* a given osd we're communicating with */
29 struct ceph_osd {
30         atomic_t o_ref;
31         struct ceph_osd_client *o_osdc;
32         int o_osd;
33         int o_incarnation;
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;
42 };
43
44 #define CEPH_OSD_SLAB_OPS       2
45 #define CEPH_OSD_MAX_OPS        16
46
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,
51 #ifdef CONFIG_BLOCK
52         CEPH_OSD_DATA_TYPE_BIO,
53 #endif /* CONFIG_BLOCK */
54 };
55
56 struct ceph_osd_data {
57         enum ceph_osd_data_type type;
58         union {
59                 struct {
60                         struct page     **pages;
61                         u64             length;
62                         u32             alignment;
63                         bool            pages_from_pool;
64                         bool            own_pages;
65                 };
66                 struct ceph_pagelist    *pagelist;
67 #ifdef CONFIG_BLOCK
68                 struct {
69                         struct bio      *bio;           /* list of bios */
70                         size_t          bio_length;     /* total in list */
71                 };
72 #endif /* CONFIG_BLOCK */
73         };
74 };
75
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 */
81         s32 rval;
82
83         union {
84                 struct ceph_osd_data raw_data_in;
85                 struct {
86                         u64 offset, length;
87                         u64 truncate_size;
88                         u32 truncate_seq;
89                         struct ceph_osd_data osd_data;
90                 } extent;
91                 struct {
92                         u32 name_len;
93                         u32 value_len;
94                         __u8 cmp_op;       /* CEPH_OSD_CMPXATTR_OP_* */
95                         __u8 cmp_mode;     /* CEPH_OSD_CMPXATTR_MODE_* */
96                         struct ceph_osd_data osd_data;
97                 } xattr;
98                 struct {
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;
104                         __u8 class_len;
105                         __u8 method_len;
106                         u32 indata_len;
107                 } cls;
108                 struct {
109                         u64 cookie;
110                         u64 ver;
111                         u32 prot_ver;
112                         u32 timeout;
113                         __u8 flag;
114                 } watch;
115                 struct {
116                         u64 expected_object_size;
117                         u64 expected_write_size;
118                 } alloc_hint;
119         };
120 };
121
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;
127
128         struct ceph_pg pgid;
129         u32 pg_num;
130         u32 pg_num_mask;
131         struct ceph_osds acting;
132         struct ceph_osds up;
133         int size;
134         int min_size;
135         bool sort_bitwise;
136
137         unsigned int flags;                /* CEPH_OSD_FLAG_* */
138         bool paused;
139
140         int osd;
141 };
142
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;
152
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
157
158         struct ceph_msg  *r_request, *r_reply;
159         u32               r_sent;      /* >0 if r_request is sending/sent */
160
161         /* request osd ops array  */
162         unsigned int            r_num_ops;
163
164         int               r_result;
165         bool              r_got_reply;
166         int               r_linger;
167
168         struct ceph_osd_client *r_osdc;
169         struct kref       r_kref;
170         bool              r_mempool;
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;
176
177         struct inode *r_inode;                /* for use by callbacks */
178         void *r_priv;                         /* ditto */
179
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 */
185
186         /* internal */
187         unsigned long r_stamp;                /* jiffies, send or check time */
188         int r_attempts;
189         struct ceph_eversion r_replay_version; /* aka reassert_version */
190         u32 r_last_force_resend;
191
192         struct ceph_osd_req_op r_ops[];
193 };
194
195 struct ceph_request_redirect {
196         struct ceph_object_locator oloc;
197 };
198
199 struct ceph_osd_event {
200         u64 cookie;
201         int one_shot;
202         struct ceph_osd_client *osdc;
203         void (*cb)(u64, u64, u8, void *);
204         void *data;
205         struct rb_node node;
206         struct list_head osd_node;
207         struct kref kref;
208 };
209
210 struct ceph_osd_event_work {
211         struct work_struct work;
212         struct ceph_osd_event *event;
213         u64 ver;
214         u64 notify_id;
215         u8 opcode;
216 };
217
218 struct ceph_osd_client {
219         struct ceph_client     *client;
220
221         struct ceph_osdmap     *osdmap;       /* current map */
222         struct rw_semaphore    map_sem;
223
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 */
234         int                    num_requests;
235         struct delayed_work    timeout_work;
236         struct delayed_work    osds_timeout_work;
237 #ifdef CONFIG_DEBUG_FS
238         struct dentry          *debugfs_file;
239 #endif
240
241         mempool_t              *req_mempool;
242
243         struct ceph_msgpool     msgpool_op;
244         struct ceph_msgpool     msgpool_op_reply;
245
246         spinlock_t              event_lock;
247         struct rb_root          event_tree;
248         u64                     event_count;
249
250         struct workqueue_struct *notify_wq;
251 };
252
253 extern int ceph_osdc_setup(void);
254 extern void ceph_osdc_cleanup(void);
255
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);
259
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);
264
265 extern void osd_req_op_init(struct ceph_osd_request *osd_req,
266                             unsigned int which, u16 opcode, u32 flags);
267
268 extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
269                                         unsigned int which,
270                                         struct page **pages, u64 length,
271                                         u32 alignment, bool pages_from_pool,
272                                         bool own_pages);
273
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);
282
283 extern struct ceph_osd_data *osd_req_op_extent_osd_data(
284                                         struct ceph_osd_request *osd_req,
285                                         unsigned int which);
286
287 extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
288                                         unsigned int which,
289                                         struct page **pages, u64 length,
290                                         u32 alignment, bool pages_from_pool,
291                                         bool own_pages);
292 extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
293                                         unsigned int which,
294                                         struct ceph_pagelist *pagelist);
295 #ifdef CONFIG_BLOCK
296 extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
297                                         unsigned int which,
298                                         struct bio *bio, size_t bio_length);
299 #endif /* CONFIG_BLOCK */
300
301 extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
302                                         unsigned int which,
303                                         struct ceph_pagelist *pagelist);
304 extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
305                                         unsigned int which,
306                                         struct page **pages, u64 length,
307                                         u32 alignment, bool pages_from_pool,
308                                         bool own_pages);
309 extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
310                                         unsigned int which,
311                                         struct page **pages, u64 length,
312                                         u32 alignment, bool pages_from_pool,
313                                         bool own_pages);
314
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,
325                                        unsigned int which,
326                                        u64 expected_object_size,
327                                        u64 expected_write_size);
328
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,
332                                                bool use_mempool,
333                                                gfp_t gfp_flags);
334 int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
335
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,
344                                       bool use_mempool);
345
346 extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
347                                          struct ceph_osd_request *req);
348
349 extern void ceph_osdc_get_request(struct ceph_osd_request *req);
350 extern void ceph_osdc_put_request(struct ceph_osd_request *req);
351
352 extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
353                                    struct ceph_osd_request *req,
354                                    bool nofail);
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);
359
360 extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
361
362 extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
363                                struct ceph_vino vino,
364                                struct ceph_file_layout *layout,
365                                u64 off, u64 *plen,
366                                u32 truncate_seq, u64 truncate_size,
367                                struct page **pages, int nr_pages,
368                                int page_align);
369
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,
374                                 u64 off, u64 len,
375                                 u32 truncate_seq, u64 truncate_size,
376                                 struct timespec *mtime,
377                                 struct page **pages, int nr_pages);
378
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);
385 #endif
386