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