blob: 3bebd60e7f9fcecb6328b3c4cf89c2ece6555b38 [file] [log] [blame]
Sage Weilf24e9982009-10-06 11:31:10 -07001#ifndef _FS_CEPH_OSD_CLIENT_H
2#define _FS_CEPH_OSD_CLIENT_H
3
4#include <linux/completion.h>
Sage Weil415e49a2009-12-07 13:37:03 -08005#include <linux/kref.h>
Sage Weilf24e9982009-10-06 11:31:10 -07006#include <linux/mempool.h>
7#include <linux/rbtree.h>
8
Alex Elder6c4a1912012-05-16 15:16:38 -05009#include <linux/ceph/types.h>
10#include <linux/ceph/osdmap.h>
11#include <linux/ceph/messenger.h>
12#include <linux/ceph/auth.h>
Alex Elderc8858372012-11-13 21:11:15 -060013#include <linux/ceph/pagelist.h>
Sage Weilf24e9982009-10-06 11:31:10 -070014
15struct ceph_msg;
16struct ceph_snap_context;
17struct ceph_osd_request;
18struct ceph_osd_client;
19
20/*
21 * completion callback for async writepages
22 */
Ilya Dryomov85e084f2016-04-28 16:07:24 +020023typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *);
Alex Elder26be8802013-04-15 11:20:42 -050024typedef void (*ceph_osdc_unsafe_callback_t)(struct ceph_osd_request *, bool);
Sage Weilf24e9982009-10-06 11:31:10 -070025
Ilya Dryomov63244fa2016-04-28 16:07:23 +020026#define CEPH_HOMELESS_OSD -1
27
Sage Weilf24e9982009-10-06 11:31:10 -070028/* a given osd we're communicating with */
29struct ceph_osd {
30 atomic_t o_ref;
31 struct ceph_osd_client *o_osdc;
32 int o_osd;
33 int o_incarnation;
34 struct rb_node o_node;
35 struct ceph_connection o_con;
36 struct list_head o_requests;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -070037 struct list_head o_linger_requests;
Yehuda Sadehf5a20412010-02-03 11:00:26 -080038 struct list_head o_osd_lru;
Alex Elder6c4a1912012-05-16 15:16:38 -050039 struct ceph_auth_handshake o_auth;
Yehuda Sadehf5a20412010-02-03 11:00:26 -080040 unsigned long lru_ttl;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -080041 struct list_head o_keepalive_item;
Sage Weilf24e9982009-10-06 11:31:10 -070042};
43
Ilya Dryomov3f1af422016-02-09 17:50:15 +010044#define CEPH_OSD_SLAB_OPS 2
45#define CEPH_OSD_MAX_OPS 16
Sage Weil1b83bef2013-02-25 16:11:12 -080046
Alex Elder2ac2b7a2013-02-14 12:16:43 -060047enum ceph_osd_data_type {
Alex Elderec9123c2013-04-05 01:27:12 -050048 CEPH_OSD_DATA_TYPE_NONE = 0,
Alex Elder2ac2b7a2013-02-14 12:16:43 -060049 CEPH_OSD_DATA_TYPE_PAGES,
Alex Elder9a5e6d02013-03-08 13:35:36 -060050 CEPH_OSD_DATA_TYPE_PAGELIST,
Alex Elder2ac2b7a2013-02-14 12:16:43 -060051#ifdef CONFIG_BLOCK
52 CEPH_OSD_DATA_TYPE_BIO,
53#endif /* CONFIG_BLOCK */
54};
55
Alex Elder2794a82a2013-02-14 12:16:43 -060056struct ceph_osd_data {
Alex Elder2ac2b7a2013-02-14 12:16:43 -060057 enum ceph_osd_data_type type;
58 union {
Alex Elder2794a82a2013-02-14 12:16:43 -060059 struct {
60 struct page **pages;
Alex Eldere0c59482013-03-07 15:38:25 -060061 u64 length;
Alex Elder2794a82a2013-02-14 12:16:43 -060062 u32 alignment;
63 bool pages_from_pool;
64 bool own_pages;
65 };
Alex Elder9a5e6d02013-03-08 13:35:36 -060066 struct ceph_pagelist *pagelist;
Alex Elder2794a82a2013-02-14 12:16:43 -060067#ifdef CONFIG_BLOCK
Alex Elderfdce58c2013-03-14 14:09:06 -050068 struct {
69 struct bio *bio; /* list of bios */
70 size_t bio_length; /* total in list */
71 };
Alex Elder2794a82a2013-02-14 12:16:43 -060072#endif /* CONFIG_BLOCK */
73 };
74};
75
Alex Elder79528732013-04-03 21:32:51 -050076struct ceph_osd_req_op {
77 u16 op; /* CEPH_OSD_OP_* */
Ilya Dryomov7b25bf52014-02-25 16:22:26 +020078 u32 flags; /* CEPH_OSD_OP_FLAG_* */
Ilya Dryomovde2aa102016-02-08 13:39:46 +010079 u32 indata_len; /* request */
Yan, Zheng7665d852016-01-07 16:48:57 +080080 u32 outdata_len; /* reply */
81 s32 rval;
82
Alex Elder79528732013-04-03 21:32:51 -050083 union {
Alex Elder49719772013-02-11 12:33:24 -060084 struct ceph_osd_data raw_data_in;
Alex Elder79528732013-04-03 21:32:51 -050085 struct {
86 u64 offset, length;
87 u64 truncate_size;
88 u32 truncate_seq;
Alex Elder54764922013-04-05 01:27:12 -050089 struct ceph_osd_data osd_data;
Alex Elder79528732013-04-03 21:32:51 -050090 } extent;
91 struct {
Ilya Dryomovd7d5a002014-12-19 14:00:41 +030092 u32 name_len;
93 u32 value_len;
Yan, Zhengd74b50b2014-11-12 14:00:43 +080094 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
95 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
96 struct ceph_osd_data osd_data;
97 } xattr;
98 struct {
Alex Elder79528732013-04-03 21:32:51 -050099 const char *class_name;
100 const char *method_name;
Alex Elder54764922013-04-05 01:27:12 -0500101 struct ceph_osd_data request_info;
Alex Elder04017e22013-04-05 14:46:02 -0500102 struct ceph_osd_data request_data;
Alex Elder54764922013-04-05 01:27:12 -0500103 struct ceph_osd_data response_data;
Alex Elder79528732013-04-03 21:32:51 -0500104 __u8 class_len;
105 __u8 method_len;
Ilya Dryomovbb873b52016-05-26 00:29:52 +0200106 u32 indata_len;
Alex Elder79528732013-04-03 21:32:51 -0500107 } cls;
108 struct {
109 u64 cookie;
110 u64 ver;
111 u32 prot_ver;
112 u32 timeout;
113 __u8 flag;
114 } watch;
Ilya Dryomovc647b8a2014-02-25 16:22:27 +0200115 struct {
116 u64 expected_object_size;
117 u64 expected_write_size;
118 } alloc_hint;
Alex Elder79528732013-04-03 21:32:51 -0500119 };
120};
121
Ilya Dryomov63244fa2016-04-28 16:07:23 +0200122struct ceph_osd_request_target {
123 struct ceph_object_id base_oid;
124 struct ceph_object_locator base_oloc;
125 struct ceph_object_id target_oid;
126 struct ceph_object_locator target_oloc;
127
128 struct ceph_pg pgid;
129 u32 pg_num;
130 u32 pg_num_mask;
131 struct ceph_osds acting;
132 struct ceph_osds up;
133 int size;
134 int min_size;
135 bool sort_bitwise;
136
137 unsigned int flags; /* CEPH_OSD_FLAG_* */
138 bool paused;
139
140 int osd;
141};
142
Sage Weilf24e9982009-10-06 11:31:10 -0700143/* an in-flight request */
144struct ceph_osd_request {
145 u64 r_tid; /* unique for this client */
146 struct rb_node r_node;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800147 struct list_head r_req_lru_item;
Sage Weilf24e9982009-10-06 11:31:10 -0700148 struct list_head r_osd_item;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700149 struct list_head r_linger_item;
Ilya Dryomov1d0326b2014-06-20 14:14:41 +0400150 struct list_head r_linger_osd_item;
Sage Weilf24e9982009-10-06 11:31:10 -0700151 struct ceph_osd *r_osd;
Ilya Dryomova66dd382016-04-28 16:07:23 +0200152
153 struct ceph_osd_request_target r_t;
154#define r_base_oid r_t.base_oid
155#define r_base_oloc r_t.base_oloc
156#define r_flags r_t.flags
Sage Weilf24e9982009-10-06 11:31:10 -0700157
158 struct ceph_msg *r_request, *r_reply;
Sage Weilf24e9982009-10-06 11:31:10 -0700159 u32 r_sent; /* >0 if r_request is sending/sent */
Sage Weil1b83bef2013-02-25 16:11:12 -0800160
Alex Elder79528732013-04-03 21:32:51 -0500161 /* request osd ops array */
162 unsigned int r_num_ops;
Alex Elder79528732013-04-03 21:32:51 -0500163
Sage Weil1b83bef2013-02-25 16:11:12 -0800164 int r_result;
Sage Weil350b1c32009-12-22 10:45:45 -0800165 int r_got_reply;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700166 int r_linger;
Sage Weilf24e9982009-10-06 11:31:10 -0700167
168 struct ceph_osd_client *r_osdc;
Sage Weil415e49a2009-12-07 13:37:03 -0800169 struct kref r_kref;
Sage Weilf24e9982009-10-06 11:31:10 -0700170 bool r_mempool;
171 struct completion r_completion, r_safe_completion;
Alex Elder26be8802013-04-15 11:20:42 -0500172 ceph_osdc_callback_t r_callback;
173 ceph_osdc_unsafe_callback_t r_unsafe_callback;
Sage Weilf24e9982009-10-06 11:31:10 -0700174 struct list_head r_unsafe_item;
175
176 struct inode *r_inode; /* for use by callbacks */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700177 void *r_priv; /* ditto */
Sage Weilf24e9982009-10-06 11:31:10 -0700178
Ilya Dryomovbb873b52016-05-26 00:29:52 +0200179 /* set by submitter */
180 u64 r_snapid; /* for reads, CEPH_NOSNAP o/w */
181 struct ceph_snap_context *r_snapc; /* for writes */
182 struct timespec r_mtime; /* ditto */
183 u64 r_data_offset; /* ditto */
Sage Weilf24e9982009-10-06 11:31:10 -0700184
Ilya Dryomovbb873b52016-05-26 00:29:52 +0200185 /* internal */
186 unsigned long r_stamp; /* jiffies, send or check time */
187 int r_attempts;
188 struct ceph_eversion r_replay_version; /* aka reassert_version */
189 u32 r_last_force_resend;
Ilya Dryomov3f1af422016-02-09 17:50:15 +0100190
191 struct ceph_osd_req_op r_ops[];
Sage Weilf24e9982009-10-06 11:31:10 -0700192};
193
Ilya Dryomov205ee1182014-01-27 17:40:20 +0200194struct ceph_request_redirect {
195 struct ceph_object_locator oloc;
196};
197
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700198struct ceph_osd_event {
199 u64 cookie;
200 int one_shot;
201 struct ceph_osd_client *osdc;
202 void (*cb)(u64, u64, u8, void *);
203 void *data;
204 struct rb_node node;
205 struct list_head osd_node;
206 struct kref kref;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700207};
208
209struct ceph_osd_event_work {
210 struct work_struct work;
211 struct ceph_osd_event *event;
212 u64 ver;
213 u64 notify_id;
214 u8 opcode;
215};
216
Sage Weilf24e9982009-10-06 11:31:10 -0700217struct ceph_osd_client {
218 struct ceph_client *client;
219
220 struct ceph_osdmap *osdmap; /* current map */
221 struct rw_semaphore map_sem;
Sage Weilf24e9982009-10-06 11:31:10 -0700222
223 struct mutex request_mutex;
224 struct rb_root osds; /* osds */
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800225 struct list_head osd_lru; /* idle osds */
Sage Weilf24e9982009-10-06 11:31:10 -0700226 u64 last_tid; /* tid of last request */
227 struct rb_root requests; /* pending requests */
Sage Weil6f6c7002011-01-17 20:34:08 -0800228 struct list_head req_lru; /* in-flight lru */
229 struct list_head req_unsent; /* unsent/need-resend queue */
230 struct list_head req_notarget; /* map to no osd */
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700231 struct list_head req_linger; /* lingering requests */
Sage Weilf24e9982009-10-06 11:31:10 -0700232 int num_requests;
233 struct delayed_work timeout_work;
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800234 struct delayed_work osds_timeout_work;
Sage Weil039934b2009-11-12 15:05:52 -0800235#ifdef CONFIG_DEBUG_FS
Sage Weilf24e9982009-10-06 11:31:10 -0700236 struct dentry *debugfs_file;
Sage Weil039934b2009-11-12 15:05:52 -0800237#endif
Sage Weilf24e9982009-10-06 11:31:10 -0700238
239 mempool_t *req_mempool;
240
Yehuda Sadeh0d59ab82010-01-13 17:03:23 -0800241 struct ceph_msgpool msgpool_op;
Sage Weilc16e7862010-03-01 13:02:00 -0800242 struct ceph_msgpool msgpool_op_reply;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700243
244 spinlock_t event_lock;
245 struct rb_root event_tree;
246 u64 event_count;
247
248 struct workqueue_struct *notify_wq;
Sage Weilf24e9982009-10-06 11:31:10 -0700249};
250
Alex Elder5522ae02013-05-01 12:43:04 -0500251extern int ceph_osdc_setup(void);
252extern void ceph_osdc_cleanup(void);
253
Sage Weilf24e9982009-10-06 11:31:10 -0700254extern int ceph_osdc_init(struct ceph_osd_client *osdc,
255 struct ceph_client *client);
256extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
257
258extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
259 struct ceph_msg *msg);
260extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
261 struct ceph_msg *msg);
262
Alex Elder49719772013-02-11 12:33:24 -0600263extern void osd_req_op_init(struct ceph_osd_request *osd_req,
Yan, Zheng144cba12015-04-27 11:09:54 +0800264 unsigned int which, u16 opcode, u32 flags);
Alex Elder49719772013-02-11 12:33:24 -0600265
266extern void osd_req_op_raw_data_in_pages(struct ceph_osd_request *,
267 unsigned int which,
268 struct page **pages, u64 length,
269 u32 alignment, bool pages_from_pool,
270 bool own_pages);
271
Alex Elderc99d2d42013-04-05 01:27:11 -0500272extern void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
273 unsigned int which, u16 opcode,
Alex Elder33803f32013-03-13 20:50:00 -0500274 u64 offset, u64 length,
275 u64 truncate_size, u32 truncate_seq);
Alex Elderc99d2d42013-04-05 01:27:11 -0500276extern void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
277 unsigned int which, u64 length);
Yan, Zheng2c63f492016-01-07 17:32:54 +0800278extern void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
279 unsigned int which, u64 offset_inc);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500280
281extern struct ceph_osd_data *osd_req_op_extent_osd_data(
282 struct ceph_osd_request *osd_req,
Alex Elder406e2c92013-04-15 14:50:36 -0500283 unsigned int which);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500284
285extern void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *,
Alex Elder406e2c92013-04-15 14:50:36 -0500286 unsigned int which,
Alex Eldera4ce40a2013-04-05 01:27:12 -0500287 struct page **pages, u64 length,
288 u32 alignment, bool pages_from_pool,
289 bool own_pages);
290extern void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *,
Alex Elder406e2c92013-04-15 14:50:36 -0500291 unsigned int which,
Alex Eldera4ce40a2013-04-05 01:27:12 -0500292 struct ceph_pagelist *pagelist);
293#ifdef CONFIG_BLOCK
294extern void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *,
Alex Elder406e2c92013-04-15 14:50:36 -0500295 unsigned int which,
Alex Eldera4ce40a2013-04-05 01:27:12 -0500296 struct bio *bio, size_t bio_length);
297#endif /* CONFIG_BLOCK */
298
Alex Elder04017e22013-04-05 14:46:02 -0500299extern void osd_req_op_cls_request_data_pagelist(struct ceph_osd_request *,
300 unsigned int which,
301 struct ceph_pagelist *pagelist);
Alex Elder6c57b552013-04-19 15:34:49 -0500302extern void osd_req_op_cls_request_data_pages(struct ceph_osd_request *,
303 unsigned int which,
304 struct page **pages, u64 length,
305 u32 alignment, bool pages_from_pool,
306 bool own_pages);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500307extern void osd_req_op_cls_response_data_pages(struct ceph_osd_request *,
Alex Elderc99d2d42013-04-05 01:27:11 -0500308 unsigned int which,
Alex Eldera4ce40a2013-04-05 01:27:12 -0500309 struct page **pages, u64 length,
310 u32 alignment, bool pages_from_pool,
311 bool own_pages);
312
Alex Elderc99d2d42013-04-05 01:27:11 -0500313extern void osd_req_op_cls_init(struct ceph_osd_request *osd_req,
314 unsigned int which, u16 opcode,
Alex Elder04017e22013-04-05 14:46:02 -0500315 const char *class, const char *method);
Yan, Zhengd74b50b2014-11-12 14:00:43 +0800316extern int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
317 u16 opcode, const char *name, const void *value,
318 size_t size, u8 cmp_op, u8 cmp_mode);
Alex Elderc99d2d42013-04-05 01:27:11 -0500319extern void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
320 unsigned int which, u16 opcode,
Alex Elder33803f32013-03-13 20:50:00 -0500321 u64 cookie, u64 version, int flag);
Ilya Dryomovc647b8a2014-02-25 16:22:27 +0200322extern void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
323 unsigned int which,
324 u64 expected_object_size,
325 u64 expected_write_size);
Alex Elder33803f32013-03-13 20:50:00 -0500326
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700327extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700328 struct ceph_snap_context *snapc,
Alex Elderacead002013-03-14 14:09:05 -0500329 unsigned int num_ops,
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700330 bool use_mempool,
Alex Elder54a54002012-11-13 21:11:15 -0600331 gfp_t gfp_flags);
Ilya Dryomov13d1ad12016-04-27 14:15:51 +0200332int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700333
Sage Weilf24e9982009-10-06 11:31:10 -0700334extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
335 struct ceph_file_layout *layout,
336 struct ceph_vino vino,
Alex Elderacead002013-03-14 14:09:05 -0500337 u64 offset, u64 *len,
Yan, Zheng715e4cd2014-11-13 14:40:37 +0800338 unsigned int which, int num_ops,
339 int opcode, int flags,
Sage Weilf24e9982009-10-06 11:31:10 -0700340 struct ceph_snap_context *snapc,
Alex Elderacead002013-03-14 14:09:05 -0500341 u32 truncate_seq, u64 truncate_size,
Alex Elder153e5162013-03-01 18:00:15 -0600342 bool use_mempool);
Sage Weilf24e9982009-10-06 11:31:10 -0700343
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700344extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
345 struct ceph_osd_request *req);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700346
Ilya Dryomov9e94af22014-06-20 14:14:42 +0400347extern void ceph_osdc_get_request(struct ceph_osd_request *req);
348extern void ceph_osdc_put_request(struct ceph_osd_request *req);
Sage Weilf24e9982009-10-06 11:31:10 -0700349
350extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
351 struct ceph_osd_request *req,
352 bool nofail);
Ilya Dryomovc9f9b932014-06-19 11:38:13 +0400353extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
Sage Weilf24e9982009-10-06 11:31:10 -0700354extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
355 struct ceph_osd_request *req);
356extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
357
Josh Durgindd935f42013-08-28 21:43:09 -0700358extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
359
Sage Weilf24e9982009-10-06 11:31:10 -0700360extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
361 struct ceph_vino vino,
362 struct ceph_file_layout *layout,
363 u64 off, u64 *plen,
364 u32 truncate_seq, u64 truncate_size,
Sage Weilb7495fc2010-11-09 12:43:12 -0800365 struct page **pages, int nr_pages,
366 int page_align);
Sage Weilf24e9982009-10-06 11:31:10 -0700367
368extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
369 struct ceph_vino vino,
370 struct ceph_file_layout *layout,
371 struct ceph_snap_context *sc,
372 u64 off, u64 len,
373 u32 truncate_seq, u64 truncate_size,
374 struct timespec *mtime,
Alex Elder24808822013-02-15 11:42:29 -0600375 struct page **pages, int nr_pages);
Sage Weilf24e9982009-10-06 11:31:10 -0700376
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700377/* watch/notify events */
378extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
379 void (*event_cb)(u64, u64, u8, void *),
Alex Elder3c663bb2013-02-15 11:42:30 -0600380 void *data, struct ceph_osd_event **pevent);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700381extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700382extern void ceph_osdc_put_event(struct ceph_osd_event *event);
Sage Weilf24e9982009-10-06 11:31:10 -0700383#endif
384