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