]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/ceph/osd_client.h
Merge tag 'for-linus-20170825' of git://git.infradead.org/linux-mtd
[mirror_ubuntu-artful-kernel.git] / include / linux / ceph / osd_client.h
CommitLineData
f24e9980
SW
1#ifndef _FS_CEPH_OSD_CLIENT_H
2#define _FS_CEPH_OSD_CLIENT_H
3
a02a946d 4#include <linux/bitrev.h>
f24e9980 5#include <linux/completion.h>
415e49a9 6#include <linux/kref.h>
f24e9980
SW
7#include <linux/mempool.h>
8#include <linux/rbtree.h>
02113a0f 9#include <linux/refcount.h>
f24e9980 10
6c4a1915
AE
11#include <linux/ceph/types.h>
12#include <linux/ceph/osdmap.h>
13#include <linux/ceph/messenger.h>
b2aa5d0b 14#include <linux/ceph/msgpool.h>
6c4a1915 15#include <linux/ceph/auth.h>
c885837f 16#include <linux/ceph/pagelist.h>
f24e9980
SW
17
18struct ceph_msg;
19struct ceph_snap_context;
20struct ceph_osd_request;
21struct ceph_osd_client;
22
23/*
24 * completion callback for async writepages
25 */
85e084fe 26typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);
f24e9980 27
63244fa1
ID
28#define CEPH_HOMELESS_OSD -1
29
f24e9980
SW
30/* a given osd we're communicating with */
31struct ceph_osd {
02113a0f 32 refcount_t o_ref;
f24e9980
SW
33 struct ceph_osd_client *o_osdc;
34 int o_osd;
35 int o_incarnation;
36 struct rb_node o_node;
37 struct ceph_connection o_con;
5aea3dcd 38 struct rb_root o_requests;
922dab61 39 struct rb_root o_linger_requests;
a02a946d
ID
40 struct rb_root o_backoff_mappings;
41 struct rb_root o_backoffs_by_id;
f5a2041b 42 struct list_head o_osd_lru;
6c4a1915 43 struct ceph_auth_handshake o_auth;
f5a2041b 44 unsigned long lru_ttl;
422d2cb8 45 struct list_head o_keepalive_item;
5aea3dcd 46 struct mutex lock;
f24e9980
SW
47};
48
3f1af42a
ID
49#define CEPH_OSD_SLAB_OPS 2
50#define CEPH_OSD_MAX_OPS 16
1b83bef2 51
2ac2b7a6 52enum ceph_osd_data_type {
ec9123c5 53 CEPH_OSD_DATA_TYPE_NONE = 0,
2ac2b7a6 54 CEPH_OSD_DATA_TYPE_PAGES,
9a5e6d09 55 CEPH_OSD_DATA_TYPE_PAGELIST,
2ac2b7a6
AE
56#ifdef CONFIG_BLOCK
57 CEPH_OSD_DATA_TYPE_BIO,
58#endif /* CONFIG_BLOCK */
59};
60
2794a82a 61struct ceph_osd_data {
2ac2b7a6
AE
62 enum ceph_osd_data_type type;
63 union {
2794a82a
AE
64 struct {
65 struct page **pages;
e0c59487 66 u64 length;
2794a82a
AE
67 u32 alignment;
68 bool pages_from_pool;
69 bool own_pages;
70 };
9a5e6d09 71 struct ceph_pagelist *pagelist;
2794a82a 72#ifdef CONFIG_BLOCK
fdce58cc
AE
73 struct {
74 struct bio *bio; /* list of bios */
75 size_t bio_length; /* total in list */
76 };
2794a82a
AE
77#endif /* CONFIG_BLOCK */
78 };
79};
80
79528734
AE
81struct ceph_osd_req_op {
82 u16 op; /* CEPH_OSD_OP_* */
7b25bf5f 83 u32 flags; /* CEPH_OSD_OP_FLAG_* */
de2aa102 84 u32 indata_len; /* request */
7665d85b
YZ
85 u32 outdata_len; /* reply */
86 s32 rval;
87
79528734 88 union {
49719778 89 struct ceph_osd_data raw_data_in;
79528734
AE
90 struct {
91 u64 offset, length;
92 u64 truncate_size;
93 u32 truncate_seq;
5476492f 94 struct ceph_osd_data osd_data;
79528734 95 } extent;
d74b50be 96 struct {
d7d5a007
ID
97 u32 name_len;
98 u32 value_len;
d74b50be
YZ
99 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
100 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
101 struct ceph_osd_data osd_data;
102 } xattr;
79528734
AE
103 struct {
104 const char *class_name;
105 const char *method_name;
5476492f 106 struct ceph_osd_data request_info;
04017e29 107 struct ceph_osd_data request_data;
5476492f 108 struct ceph_osd_data response_data;
79528734
AE
109 __u8 class_len;
110 __u8 method_len;
bb873b53 111 u32 indata_len;
79528734
AE
112 } cls;
113 struct {
114 u64 cookie;
922dab61
ID
115 __u8 op; /* CEPH_OSD_WATCH_OP_ */
116 u32 gen;
79528734 117 } watch;
922dab61
ID
118 struct {
119 struct ceph_osd_data request_data;
120 } notify_ack;
19079203
ID
121 struct {
122 u64 cookie;
123 struct ceph_osd_data request_data;
124 struct ceph_osd_data response_data;
125 } notify;
a4ed38d7
DF
126 struct {
127 struct ceph_osd_data response_data;
128 } list_watchers;
c647b8a8
ID
129 struct {
130 u64 expected_object_size;
131 u64 expected_write_size;
132 } alloc_hint;
79528734
AE
133 };
134};
135
63244fa1
ID
136struct 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;
141
dc98ff72
ID
142 struct ceph_pg pgid; /* last raw pg we mapped to */
143 struct ceph_spg spgid; /* last actual spg we mapped to */
63244fa1
ID
144 u32 pg_num;
145 u32 pg_num_mask;
146 struct ceph_osds acting;
147 struct ceph_osds up;
148 int size;
149 int min_size;
150 bool sort_bitwise;
ae78dd81 151 bool recovery_deletes;
63244fa1
ID
152
153 unsigned int flags; /* CEPH_OSD_FLAG_* */
154 bool paused;
155
04c7d789 156 u32 epoch;
dc93e0e2
ID
157 u32 last_force_resend;
158
63244fa1
ID
159 int osd;
160};
161
f24e9980
SW
162/* an in-flight request */
163struct ceph_osd_request {
164 u64 r_tid; /* unique for this client */
165 struct rb_node r_node;
4609245e 166 struct rb_node r_mc_node; /* map check */
f24e9980 167 struct ceph_osd *r_osd;
a66dd383
ID
168
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
f24e9980
SW
173
174 struct ceph_msg *r_request, *r_reply;
f24e9980 175 u32 r_sent; /* >0 if r_request is sending/sent */
1b83bef2 176
79528734
AE
177 /* request osd ops array */
178 unsigned int r_num_ops;
79528734 179
1b83bef2 180 int r_result;
f24e9980
SW
181
182 struct ceph_osd_client *r_osdc;
415e49a9 183 struct kref r_kref;
f24e9980 184 bool r_mempool;
b18b9550 185 struct completion r_completion; /* private to osd_client.c */
26be8808 186 ceph_osdc_callback_t r_callback;
f24e9980
SW
187 struct list_head r_unsafe_item;
188
189 struct inode *r_inode; /* for use by callbacks */
3d14c5d2 190 void *r_priv; /* ditto */
f24e9980 191
bb873b53
ID
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 */
922dab61 197 bool r_linger; /* don't resend on failure */
a1f4020a 198 bool r_abort_on_full; /* return ENOSPC when full */
f24e9980 199
bb873b53
ID
200 /* internal */
201 unsigned long r_stamp; /* jiffies, send or check time */
7cc5e38f 202 unsigned long r_start_stamp; /* jiffies */
bb873b53 203 int r_attempts;
4609245e 204 u32 r_map_dne_bound;
3f1af42a
ID
205
206 struct ceph_osd_req_op r_ops[];
f24e9980
SW
207};
208
205ee118
ID
209struct ceph_request_redirect {
210 struct ceph_object_locator oloc;
211};
212
8cb441c0
ID
213/*
214 * osd request identifier
215 *
216 * caller name + incarnation# + tid to unique identify this request
217 */
218struct ceph_osd_reqid {
219 struct ceph_entity_name name;
220 __le64 tid;
221 __le32 inc;
222} __packed;
223
224struct ceph_blkin_trace_info {
225 __le64 trace_id;
226 __le64 span_id;
227 __le64 parent_span_id;
228} __packed;
229
922dab61
ID
230typedef void (*rados_watchcb2_t)(void *arg, u64 notify_id, u64 cookie,
231 u64 notifier_id, void *data, size_t data_len);
232typedef void (*rados_watcherrcb_t)(void *arg, u64 cookie, int err);
233
234struct ceph_osd_linger_request {
a40c4f10 235 struct ceph_osd_client *osdc;
922dab61
ID
236 u64 linger_id;
237 bool committed;
19079203 238 bool is_watch; /* watch or notify */
922dab61
ID
239
240 struct ceph_osd *osd;
241 struct ceph_osd_request *reg_req;
242 struct ceph_osd_request *ping_req;
243 unsigned long ping_sent;
b07d3c4b
ID
244 unsigned long watch_valid_thru;
245 struct list_head pending_lworks;
922dab61
ID
246
247 struct ceph_osd_request_target t;
4609245e 248 u32 map_dne_bound;
922dab61
ID
249
250 struct timespec mtime;
251
a40c4f10 252 struct kref kref;
922dab61
ID
253 struct mutex lock;
254 struct rb_node node; /* osd */
255 struct rb_node osdc_node; /* osdc */
4609245e 256 struct rb_node mc_node; /* map check */
922dab61
ID
257 struct list_head scan_item;
258
259 struct completion reg_commit_wait;
19079203 260 struct completion notify_finish_wait;
922dab61 261 int reg_commit_error;
19079203 262 int notify_finish_error;
922dab61
ID
263 int last_error;
264
265 u32 register_gen;
19079203 266 u64 notify_id;
a40c4f10 267
922dab61
ID
268 rados_watchcb2_t wcb;
269 rados_watcherrcb_t errcb;
270 void *data;
19079203
ID
271
272 struct page ***preply_pages;
273 size_t *preply_len;
a40c4f10
YS
274};
275
a4ed38d7
DF
276struct ceph_watch_item {
277 struct ceph_entity_name name;
278 u64 cookie;
279 struct ceph_entity_addr addr;
280};
281
a02a946d
ID
282struct ceph_spg_mapping {
283 struct rb_node node;
284 struct ceph_spg spgid;
285
286 struct rb_root backoffs;
287};
288
289struct ceph_hobject_id {
290 void *key;
291 size_t key_len;
292 void *oid;
293 size_t oid_len;
294 u64 snapid;
295 u32 hash;
296 u8 is_max;
297 void *nspace;
298 size_t nspace_len;
299 s64 pool;
300
301 /* cache */
302 u32 hash_reverse_bits;
303};
304
305static inline void ceph_hoid_build_hash_cache(struct ceph_hobject_id *hoid)
306{
307 hoid->hash_reverse_bits = bitrev32(hoid->hash);
308}
309
310/*
311 * PG-wide backoff: [begin, end)
312 * per-object backoff: begin == end
313 */
314struct ceph_osd_backoff {
315 struct rb_node spg_node;
316 struct rb_node id_node;
317
318 struct ceph_spg spgid;
319 u64 id;
320 struct ceph_hobject_id *begin;
321 struct ceph_hobject_id *end;
322};
323
264048af
ID
324#define CEPH_LINGER_ID_START 0xffff000000000000ULL
325
f24e9980
SW
326struct ceph_osd_client {
327 struct ceph_client *client;
328
329 struct ceph_osdmap *osdmap; /* current map */
5aea3dcd 330 struct rw_semaphore lock;
f24e9980 331
f24e9980 332 struct rb_root osds; /* osds */
f5a2041b 333 struct list_head osd_lru; /* idle osds */
9dd2845c 334 spinlock_t osd_lru_lock;
58eb7932 335 u32 epoch_barrier;
5aea3dcd
ID
336 struct ceph_osd homeless_osd;
337 atomic64_t last_tid; /* tid of last request */
922dab61
ID
338 u64 last_linger_id;
339 struct rb_root linger_requests; /* lingering requests */
4609245e
ID
340 struct rb_root map_checks;
341 struct rb_root linger_map_checks;
5aea3dcd
ID
342 atomic_t num_requests;
343 atomic_t num_homeless;
f24e9980 344 struct delayed_work timeout_work;
f5a2041b 345 struct delayed_work osds_timeout_work;
039934b8 346#ifdef CONFIG_DEBUG_FS
f24e9980 347 struct dentry *debugfs_file;
039934b8 348#endif
f24e9980
SW
349
350 mempool_t *req_mempool;
351
0d59ab81 352 struct ceph_msgpool msgpool_op;
c16e7869 353 struct ceph_msgpool msgpool_op_reply;
a40c4f10 354
a40c4f10 355 struct workqueue_struct *notify_wq;
f24e9980
SW
356};
357
b7ec35b3
ID
358static inline bool ceph_osdmap_flag(struct ceph_osd_client *osdc, int flag)
359{
360 return osdc->osdmap->flags & flag;
361}
362
5522ae0b
AE
363extern int ceph_osdc_setup(void);
364extern void ceph_osdc_cleanup(void);
365
f24e9980
SW
366extern int ceph_osdc_init(struct ceph_osd_client *osdc,
367 struct ceph_client *client);
368extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
369
370extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
371 struct ceph_msg *msg);
372extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
373 struct ceph_msg *msg);
58eb7932 374void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
f24e9980 375
49719778 376extern void osd_req_op_init(struct ceph_osd_request *osd_req,
144cba14 377 unsigned int which, u16 opcode, u32 flags);
49719778
AE
378
379extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
380 unsigned int which,
381 struct page **pages, u64 length,
382 u32 alignment, bool pages_from_pool,
383 bool own_pages);
384
c99d2d4a
AE
385extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
386 unsigned int which, u16 opcode,
33803f33
AE
387 u64 offset, u64 length,
388 u64 truncate_size, u32 truncate_seq);
c99d2d4a
AE
389extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
390 unsigned int which, u64 length);
2c63f49a
YZ
391extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
392 unsigned int which, u64 offset_inc);
a4ce40a9
AE
393
394extern struct ceph_osd_data *osd_req_op_extent_osd_data(
395 struct ceph_osd_request *osd_req,
406e2c9f 396 unsigned int which);
a4ce40a9
AE
397
398extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
406e2c9f 399 unsigned int which,
a4ce40a9
AE
400 struct page **pages, u64 length,
401 u32 alignment, bool pages_from_pool,
402 bool own_pages);
403extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
406e2c9f 404 unsigned int which,
a4ce40a9
AE
405 struct ceph_pagelist *pagelist);
406#ifdef CONFIG_BLOCK
407extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
406e2c9f 408 unsigned int which,
a4ce40a9
AE
409 struct bio *bio, size_t bio_length);
410#endif /* CONFIG_BLOCK */
411
04017e29
AE
412extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
413 unsigned int which,
414 struct ceph_pagelist *pagelist);
6c57b554
AE
415extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
416 unsigned int which,
417 struct page **pages, u64 length,
418 u32 alignment, bool pages_from_pool,
419 bool own_pages);
a4ce40a9 420extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
c99d2d4a 421 unsigned int which,
a4ce40a9
AE
422 struct page **pages, u64 length,
423 u32 alignment, bool pages_from_pool,
424 bool own_pages);
c99d2d4a
AE
425extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
426 unsigned int which, u16 opcode,
04017e29 427 const char *class, const char *method);
d74b50be
YZ
428extern 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);
c647b8a8
ID
431extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
432 unsigned int which,
433 u64 expected_object_size,
434 u64 expected_write_size);
33803f33 435
3499e8a5 436extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
3499e8a5 437 struct ceph_snap_context *snapc,
acead002 438 unsigned int num_ops,
3499e8a5 439 bool use_mempool,
54a54007 440 gfp_t gfp_flags);
13d1ad16 441int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
3499e8a5 442
f24e9980
SW
443extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
444 struct ceph_file_layout *layout,
445 struct ceph_vino vino,
acead002 446 u64 offset, u64 *len,
715e4cd4
YZ
447 unsigned int which, int num_ops,
448 int opcode, int flags,
f24e9980 449 struct ceph_snap_context *snapc,
acead002 450 u32 truncate_seq, u64 truncate_size,
153e5167 451 bool use_mempool);
f24e9980 452
9e94af20
ID
453extern void ceph_osdc_get_request(struct ceph_osd_request *req);
454extern void ceph_osdc_put_request(struct ceph_osd_request *req);
f24e9980
SW
455
456extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
457 struct ceph_osd_request *req,
458 bool nofail);
c9f9b93d 459extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
f24e9980
SW
460extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
461 struct ceph_osd_request *req);
462extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
463
dd935f44 464extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
7cca78c9 465void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc);
dd935f44 466
428a7158
DF
467int 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,
471 unsigned int flags,
472 struct page *req_page, size_t req_len,
473 struct page *resp_page, size_t *resp_len);
474
f24e9980
SW
475extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
476 struct ceph_vino vino,
477 struct ceph_file_layout *layout,
478 u64 off, u64 *plen,
479 u32 truncate_seq, u64 truncate_size,
b7495fc2
SW
480 struct page **pages, int nr_pages,
481 int page_align);
f24e9980
SW
482
483extern 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,
487 u64 off, u64 len,
488 u32 truncate_seq, u64 truncate_size,
489 struct timespec *mtime,
24808826 490 struct page **pages, int nr_pages);
f24e9980 491
922dab61
ID
492/* watch/notify */
493struct ceph_osd_linger_request *
494ceph_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,
499 void *data);
500int ceph_osdc_unwatch(struct ceph_osd_client *osdc,
501 struct ceph_osd_linger_request *lreq);
502
503int ceph_osdc_notify_ack(struct ceph_osd_client *osdc,
504 struct ceph_object_id *oid,
505 struct ceph_object_locator *oloc,
506 u64 notify_id,
507 u64 cookie,
508 void *payload,
509 size_t payload_len);
19079203
ID
510int ceph_osdc_notify(struct ceph_osd_client *osdc,
511 struct ceph_object_id *oid,
512 struct ceph_object_locator *oloc,
513 void *payload,
514 size_t payload_len,
515 u32 timeout,
516 struct page ***preply_pages,
517 size_t *preply_len);
b07d3c4b
ID
518int ceph_osdc_watch_check(struct ceph_osd_client *osdc,
519 struct ceph_osd_linger_request *lreq);
a4ed38d7
DF
520int 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,
524 u32 *num_watchers);
f24e9980
SW
525#endif
526