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