]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/blame - include/linux/ceph/osd_client.h
libceph: pi->min_size, pi->last_force_request_resend
[mirror_ubuntu-focal-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
4#include <linux/completion.h>
415e49a9 5#include <linux/kref.h>
f24e9980
SW
6#include <linux/mempool.h>
7#include <linux/rbtree.h>
8
6c4a1915
AE
9#include <linux/ceph/types.h>
10#include <linux/ceph/osdmap.h>
11#include <linux/ceph/messenger.h>
12#include <linux/ceph/auth.h>
c885837f 13#include <linux/ceph/pagelist.h>
f24e9980
SW
14
15struct ceph_msg;
16struct ceph_snap_context;
17struct ceph_osd_request;
18struct ceph_osd_client;
19
20/*
21 * completion callback for async writepages
22 */
23typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *,
24 struct ceph_msg *);
26be8808 25typedef void (*ceph_osdc_unsafe_callback_t)(struct ceph_osd_request *, bool);
f24e9980
SW
26
27/* a given osd we're communicating with */
28struct ceph_osd {
29 atomic_t o_ref;
30 struct ceph_osd_client *o_osdc;
31 int o_osd;
32 int o_incarnation;
33 struct rb_node o_node;
34 struct ceph_connection o_con;
35 struct list_head o_requests;
a40c4f10 36 struct list_head o_linger_requests;
f5a2041b 37 struct list_head o_osd_lru;
6c4a1915 38 struct ceph_auth_handshake o_auth;
f5a2041b 39 unsigned long lru_ttl;
422d2cb8 40 struct list_head o_keepalive_item;
f24e9980
SW
41};
42
3f1af42a
ID
43#define CEPH_OSD_SLAB_OPS 2
44#define CEPH_OSD_MAX_OPS 16
1b83bef2 45
2ac2b7a6 46enum ceph_osd_data_type {
ec9123c5 47 CEPH_OSD_DATA_TYPE_NONE = 0,
2ac2b7a6 48 CEPH_OSD_DATA_TYPE_PAGES,
9a5e6d09 49 CEPH_OSD_DATA_TYPE_PAGELIST,
2ac2b7a6
AE
50#ifdef CONFIG_BLOCK
51 CEPH_OSD_DATA_TYPE_BIO,
52#endif /* CONFIG_BLOCK */
53};
54
2794a82a 55struct ceph_osd_data {
2ac2b7a6
AE
56 enum ceph_osd_data_type type;
57 union {
2794a82a
AE
58 struct {
59 struct page **pages;
e0c59487 60 u64 length;
2794a82a
AE
61 u32 alignment;
62 bool pages_from_pool;
63 bool own_pages;
64 };
9a5e6d09 65 struct ceph_pagelist *pagelist;
2794a82a 66#ifdef CONFIG_BLOCK
fdce58cc
AE
67 struct {
68 struct bio *bio; /* list of bios */
69 size_t bio_length; /* total in list */
70 };
2794a82a
AE
71#endif /* CONFIG_BLOCK */
72 };
73};
74
79528734
AE
75struct ceph_osd_req_op {
76 u16 op; /* CEPH_OSD_OP_* */
7b25bf5f 77 u32 flags; /* CEPH_OSD_OP_FLAG_* */
de2aa102 78 u32 indata_len; /* request */
7665d85b
YZ
79 u32 outdata_len; /* reply */
80 s32 rval;
81
79528734 82 union {
49719778 83 struct ceph_osd_data raw_data_in;
79528734
AE
84 struct {
85 u64 offset, length;
86 u64 truncate_size;
87 u32 truncate_seq;
5476492f 88 struct ceph_osd_data osd_data;
79528734 89 } extent;
d74b50be 90 struct {
d7d5a007
ID
91 u32 name_len;
92 u32 value_len;
d74b50be
YZ
93 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
94 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
95 struct ceph_osd_data osd_data;
96 } xattr;
79528734
AE
97 struct {
98 const char *class_name;
99 const char *method_name;
5476492f 100 struct ceph_osd_data request_info;
04017e29 101 struct ceph_osd_data request_data;
5476492f 102 struct ceph_osd_data response_data;
79528734
AE
103 __u8 class_len;
104 __u8 method_len;
105 __u8 argc;
106 } cls;
107 struct {
108 u64 cookie;
109 u64 ver;
110 u32 prot_ver;
111 u32 timeout;
112 __u8 flag;
113 } watch;
c647b8a8
ID
114 struct {
115 u64 expected_object_size;
116 u64 expected_write_size;
117 } alloc_hint;
79528734
AE
118 };
119};
120
f24e9980
SW
121/* an in-flight request */
122struct ceph_osd_request {
123 u64 r_tid; /* unique for this client */
124 struct rb_node r_node;
422d2cb8 125 struct list_head r_req_lru_item;
f24e9980 126 struct list_head r_osd_item;
a40c4f10 127 struct list_head r_linger_item;
1d0326b1 128 struct list_head r_linger_osd_item;
f24e9980 129 struct ceph_osd *r_osd;
5b191d99 130 struct ceph_pg r_pgid;
d85b7056
SW
131 int r_pg_osds[CEPH_PG_MAX_SIZE];
132 int r_num_pg_osds;
f24e9980
SW
133
134 struct ceph_msg *r_request, *r_reply;
f24e9980
SW
135 int r_flags; /* any additional flags for the osd */
136 u32 r_sent; /* >0 if r_request is sending/sent */
1b83bef2 137
79528734
AE
138 /* request osd ops array */
139 unsigned int r_num_ops;
79528734 140
1b83bef2
SW
141 /* these are updated on each send */
142 __le32 *r_request_osdmap_epoch;
143 __le32 *r_request_flags;
144 __le64 *r_request_pool;
145 void *r_request_pgid;
146 __le32 *r_request_attempts;
d29adb34 147 bool r_paused;
1b83bef2
SW
148 struct ceph_eversion *r_request_reassert_version;
149
150 int r_result;
350b1c32 151 int r_got_reply;
a40c4f10 152 int r_linger;
f24e9980
SW
153
154 struct ceph_osd_client *r_osdc;
415e49a9 155 struct kref r_kref;
f24e9980
SW
156 bool r_mempool;
157 struct completion r_completion, r_safe_completion;
26be8808
AE
158 ceph_osdc_callback_t r_callback;
159 ceph_osdc_unsafe_callback_t r_unsafe_callback;
f24e9980
SW
160 struct ceph_eversion r_reassert_version;
161 struct list_head r_unsafe_item;
162
163 struct inode *r_inode; /* for use by callbacks */
3d14c5d2 164 void *r_priv; /* ditto */
f24e9980 165
3c972c95
ID
166 struct ceph_object_locator r_base_oloc;
167 struct ceph_object_id r_base_oid;
205ee118
ID
168 struct ceph_object_locator r_target_oloc;
169 struct ceph_object_id r_target_oid;
22116525 170
2169aea6 171 u64 r_snapid;
3dd72fc0 172 unsigned long r_stamp; /* send OR check time */
f24e9980 173
f24e9980 174 struct ceph_snap_context *r_snapc; /* snap context for writes */
3f1af42a
ID
175
176 struct ceph_osd_req_op r_ops[];
f24e9980
SW
177};
178
205ee118
ID
179struct ceph_request_redirect {
180 struct ceph_object_locator oloc;
181};
182
a40c4f10
YS
183struct ceph_osd_event {
184 u64 cookie;
185 int one_shot;
186 struct ceph_osd_client *osdc;
187 void (*cb)(u64, u64, u8, void *);
188 void *data;
189 struct rb_node node;
190 struct list_head osd_node;
191 struct kref kref;
a40c4f10
YS
192};
193
194struct ceph_osd_event_work {
195 struct work_struct work;
196 struct ceph_osd_event *event;
197 u64 ver;
198 u64 notify_id;
199 u8 opcode;
200};
201
f24e9980
SW
202struct ceph_osd_client {
203 struct ceph_client *client;
204
205 struct ceph_osdmap *osdmap; /* current map */
206 struct rw_semaphore map_sem;
f24e9980
SW
207
208 struct mutex request_mutex;
209 struct rb_root osds; /* osds */
f5a2041b 210 struct list_head osd_lru; /* idle osds */
f24e9980
SW
211 u64 last_tid; /* tid of last request */
212 struct rb_root requests; /* pending requests */
6f6c7006
SW
213 struct list_head req_lru; /* in-flight lru */
214 struct list_head req_unsent; /* unsent/need-resend queue */
215 struct list_head req_notarget; /* map to no osd */
a40c4f10 216 struct list_head req_linger; /* lingering requests */
f24e9980
SW
217 int num_requests;
218 struct delayed_work timeout_work;
f5a2041b 219 struct delayed_work osds_timeout_work;
039934b8 220#ifdef CONFIG_DEBUG_FS
f24e9980 221 struct dentry *debugfs_file;
039934b8 222#endif
f24e9980
SW
223
224 mempool_t *req_mempool;
225
0d59ab81 226 struct ceph_msgpool msgpool_op;
c16e7869 227 struct ceph_msgpool msgpool_op_reply;
a40c4f10
YS
228
229 spinlock_t event_lock;
230 struct rb_root event_tree;
231 u64 event_count;
232
233 struct workqueue_struct *notify_wq;
f24e9980
SW
234};
235
5522ae0b
AE
236extern int ceph_osdc_setup(void);
237extern void ceph_osdc_cleanup(void);
238
f24e9980
SW
239extern int ceph_osdc_init(struct ceph_osd_client *osdc,
240 struct ceph_client *client);
241extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
242
243extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
244 struct ceph_msg *msg);
245extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
246 struct ceph_msg *msg);
247
49719778 248extern void osd_req_op_init(struct ceph_osd_request *osd_req,
144cba14 249 unsigned int which, u16 opcode, u32 flags);
49719778
AE
250
251extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
252 unsigned int which,
253 struct page **pages, u64 length,
254 u32 alignment, bool pages_from_pool,
255 bool own_pages);
256
c99d2d4a
AE
257extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
258 unsigned int which, u16 opcode,
33803f33
AE
259 u64 offset, u64 length,
260 u64 truncate_size, u32 truncate_seq);
c99d2d4a
AE
261extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
262 unsigned int which, u64 length);
2c63f49a
YZ
263extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
264 unsigned int which, u64 offset_inc);
a4ce40a9
AE
265
266extern struct ceph_osd_data *osd_req_op_extent_osd_data(
267 struct ceph_osd_request *osd_req,
406e2c9f 268 unsigned int which);
a4ce40a9
AE
269
270extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
406e2c9f 271 unsigned int which,
a4ce40a9
AE
272 struct page **pages, u64 length,
273 u32 alignment, bool pages_from_pool,
274 bool own_pages);
275extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
406e2c9f 276 unsigned int which,
a4ce40a9
AE
277 struct ceph_pagelist *pagelist);
278#ifdef CONFIG_BLOCK
279extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
406e2c9f 280 unsigned int which,
a4ce40a9
AE
281 struct bio *bio, size_t bio_length);
282#endif /* CONFIG_BLOCK */
283
04017e29
AE
284extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
285 unsigned int which,
286 struct ceph_pagelist *pagelist);
6c57b554
AE
287extern void osd_req_op_cls_request_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);
a4ce40a9 292extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
c99d2d4a 293 unsigned int which,
a4ce40a9
AE
294 struct page **pages, u64 length,
295 u32 alignment, bool pages_from_pool,
296 bool own_pages);
297
c99d2d4a
AE
298extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
299 unsigned int which, u16 opcode,
04017e29 300 const char *class, const char *method);
d74b50be
YZ
301extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
302 u16 opcode, const char *name, const void *value,
303 size_t size, u8 cmp_op, u8 cmp_mode);
c99d2d4a
AE
304extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
305 unsigned int which, u16 opcode,
33803f33 306 u64 cookie, u64 version, int flag);
c647b8a8
ID
307extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
308 unsigned int which,
309 u64 expected_object_size,
310 u64 expected_write_size);
33803f33 311
3499e8a5 312extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
3499e8a5 313 struct ceph_snap_context *snapc,
acead002 314 unsigned int num_ops,
3499e8a5 315 bool use_mempool,
54a54007 316 gfp_t gfp_flags);
13d1ad16 317int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
3499e8a5 318
175face2 319extern void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
68b4476b 320 struct ceph_snap_context *snapc,
4d6b250b 321 u64 snap_id,
af77f26c 322 struct timespec *mtime);
3499e8a5 323
f24e9980
SW
324extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
325 struct ceph_file_layout *layout,
326 struct ceph_vino vino,
acead002 327 u64 offset, u64 *len,
715e4cd4
YZ
328 unsigned int which, int num_ops,
329 int opcode, int flags,
f24e9980 330 struct ceph_snap_context *snapc,
acead002 331 u32 truncate_seq, u64 truncate_size,
153e5167 332 bool use_mempool);
f24e9980 333
a40c4f10
YS
334extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
335 struct ceph_osd_request *req);
a40c4f10 336
9e94af20
ID
337extern void ceph_osdc_get_request(struct ceph_osd_request *req);
338extern void ceph_osdc_put_request(struct ceph_osd_request *req);
f24e9980
SW
339
340extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
341 struct ceph_osd_request *req,
342 bool nofail);
c9f9b93d 343extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
f24e9980
SW
344extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
345 struct ceph_osd_request *req);
346extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
347
dd935f44
JD
348extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
349
f24e9980
SW
350extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
351 struct ceph_vino vino,
352 struct ceph_file_layout *layout,
353 u64 off, u64 *plen,
354 u32 truncate_seq, u64 truncate_size,
b7495fc2
SW
355 struct page **pages, int nr_pages,
356 int page_align);
f24e9980
SW
357
358extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
359 struct ceph_vino vino,
360 struct ceph_file_layout *layout,
361 struct ceph_snap_context *sc,
362 u64 off, u64 len,
363 u32 truncate_seq, u64 truncate_size,
364 struct timespec *mtime,
24808826 365 struct page **pages, int nr_pages);
f24e9980 366
a40c4f10
YS
367/* watch/notify events */
368extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
369 void (*event_cb)(u64, u64, u8, void *),
3c663bbd 370 void *data, struct ceph_osd_event **pevent);
a40c4f10 371extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
a40c4f10 372extern void ceph_osdc_put_event(struct ceph_osd_event *event);
f24e9980
SW
373#endif
374