blob: f88eacb111d4151dc5491797fe0e03faaadc26a9 [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
9#include "types.h"
10#include "osdmap.h"
11#include "messenger.h"
12
13struct ceph_msg;
14struct ceph_snap_context;
15struct ceph_osd_request;
16struct ceph_osd_client;
Sage Weil4e7a5dc2009-11-18 16:19:57 -080017struct ceph_authorizer;
Yehuda Sadeh68b44762010-04-06 15:01:27 -070018struct ceph_pagelist;
Sage Weilf24e9982009-10-06 11:31:10 -070019
20/*
21 * completion callback for async writepages
22 */
23typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *,
24 struct ceph_msg *);
25
26/* a given osd we're communicating with */
27struct ceph_osd {
28 atomic_t o_ref;
29 struct ceph_osd_client *o_osdc;
30 int o_osd;
31 int o_incarnation;
32 struct rb_node o_node;
33 struct ceph_connection o_con;
34 struct list_head o_requests;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -070035 struct list_head o_linger_requests;
Yehuda Sadehf5a20412010-02-03 11:00:26 -080036 struct list_head o_osd_lru;
Sage Weil4e7a5dc2009-11-18 16:19:57 -080037 struct ceph_authorizer *o_authorizer;
38 void *o_authorizer_buf, *o_authorizer_reply_buf;
39 size_t o_authorizer_buf_len, o_authorizer_reply_buf_len;
Yehuda Sadehf5a20412010-02-03 11:00:26 -080040 unsigned long lru_ttl;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -080041 int o_marked_for_keepalive;
42 struct list_head o_keepalive_item;
Sage Weilf24e9982009-10-06 11:31:10 -070043};
44
45/* an in-flight request */
46struct ceph_osd_request {
47 u64 r_tid; /* unique for this client */
48 struct rb_node r_node;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -080049 struct list_head r_req_lru_item;
Sage Weilf24e9982009-10-06 11:31:10 -070050 struct list_head r_osd_item;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -070051 struct list_head r_linger_item;
52 struct list_head r_linger_osd;
Sage Weilf24e9982009-10-06 11:31:10 -070053 struct ceph_osd *r_osd;
Sage Weil7740a422010-01-08 15:58:25 -080054 struct ceph_pg r_pgid;
Sage Weild85b7052010-05-10 10:24:48 -070055 int r_pg_osds[CEPH_PG_MAX_SIZE];
56 int r_num_pg_osds;
Sage Weilf24e9982009-10-06 11:31:10 -070057
Yehuda Sadeh0d59ab82010-01-13 17:03:23 -080058 struct ceph_connection *r_con_filling_msg;
Sage Weil350b1c32009-12-22 10:45:45 -080059
Sage Weilf24e9982009-10-06 11:31:10 -070060 struct ceph_msg *r_request, *r_reply;
61 int r_result;
62 int r_flags; /* any additional flags for the osd */
63 u32 r_sent; /* >0 if r_request is sending/sent */
Sage Weil350b1c32009-12-22 10:45:45 -080064 int r_got_reply;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -070065 int r_linger;
Sage Weilf24e9982009-10-06 11:31:10 -070066
67 struct ceph_osd_client *r_osdc;
Sage Weil415e49a2009-12-07 13:37:03 -080068 struct kref r_kref;
Sage Weilf24e9982009-10-06 11:31:10 -070069 bool r_mempool;
70 struct completion r_completion, r_safe_completion;
71 ceph_osdc_callback_t r_callback, r_safe_callback;
72 struct ceph_eversion r_reassert_version;
73 struct list_head r_unsafe_item;
74
75 struct inode *r_inode; /* for use by callbacks */
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070076 void *r_priv; /* ditto */
Sage Weilf24e9982009-10-06 11:31:10 -070077
78 char r_oid[40]; /* object name */
79 int r_oid_len;
Sage Weil3dd72fc2010-03-22 14:42:30 -070080 unsigned long r_stamp; /* send OR check time */
Sage Weilf24e9982009-10-06 11:31:10 -070081
82 struct ceph_file_layout r_file_layout;
83 struct ceph_snap_context *r_snapc; /* snap context for writes */
84 unsigned r_num_pages; /* size of page array (follows) */
Sage Weilb7495fc2010-11-09 12:43:12 -080085 unsigned r_page_alignment; /* io offset in first page */
Sage Weilf24e9982009-10-06 11:31:10 -070086 struct page **r_pages; /* pages for data payload */
87 int r_pages_from_pool;
88 int r_own_pages; /* if true, i own page list */
Yehuda Sadeh68b44762010-04-06 15:01:27 -070089#ifdef CONFIG_BLOCK
90 struct bio *r_bio; /* instead of pages */
91#endif
92
93 struct ceph_pagelist *r_trail; /* trailing part of the data */
Sage Weilf24e9982009-10-06 11:31:10 -070094};
95
Yehuda Sadeha40c4f12011-03-21 15:07:16 -070096struct ceph_osd_event {
97 u64 cookie;
98 int one_shot;
99 struct ceph_osd_client *osdc;
100 void (*cb)(u64, u64, u8, void *);
101 void *data;
102 struct rb_node node;
103 struct list_head osd_node;
104 struct kref kref;
105 struct completion completion;
106};
107
108struct ceph_osd_event_work {
109 struct work_struct work;
110 struct ceph_osd_event *event;
111 u64 ver;
112 u64 notify_id;
113 u8 opcode;
114};
115
Sage Weilf24e9982009-10-06 11:31:10 -0700116struct ceph_osd_client {
117 struct ceph_client *client;
118
119 struct ceph_osdmap *osdmap; /* current map */
120 struct rw_semaphore map_sem;
121 struct completion map_waiters;
122 u64 last_requested_map;
123
124 struct mutex request_mutex;
125 struct rb_root osds; /* osds */
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800126 struct list_head osd_lru; /* idle osds */
Sage Weilf24e9982009-10-06 11:31:10 -0700127 u64 timeout_tid; /* tid of timeout triggering rq */
128 u64 last_tid; /* tid of last request */
129 struct rb_root requests; /* pending requests */
Sage Weil6f6c7002011-01-17 20:34:08 -0800130 struct list_head req_lru; /* in-flight lru */
131 struct list_head req_unsent; /* unsent/need-resend queue */
132 struct list_head req_notarget; /* map to no osd */
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700133 struct list_head req_linger; /* lingering requests */
Sage Weilf24e9982009-10-06 11:31:10 -0700134 int num_requests;
135 struct delayed_work timeout_work;
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800136 struct delayed_work osds_timeout_work;
Sage Weil039934b2009-11-12 15:05:52 -0800137#ifdef CONFIG_DEBUG_FS
Sage Weilf24e9982009-10-06 11:31:10 -0700138 struct dentry *debugfs_file;
Sage Weil039934b2009-11-12 15:05:52 -0800139#endif
Sage Weilf24e9982009-10-06 11:31:10 -0700140
141 mempool_t *req_mempool;
142
Yehuda Sadeh0d59ab82010-01-13 17:03:23 -0800143 struct ceph_msgpool msgpool_op;
Sage Weilc16e7862010-03-01 13:02:00 -0800144 struct ceph_msgpool msgpool_op_reply;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700145
146 spinlock_t event_lock;
147 struct rb_root event_tree;
148 u64 event_count;
149
150 struct workqueue_struct *notify_wq;
Sage Weilf24e9982009-10-06 11:31:10 -0700151};
152
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700153struct ceph_osd_req_op {
154 u16 op; /* CEPH_OSD_OP_* */
155 u32 flags; /* CEPH_OSD_FLAG_* */
156 union {
157 struct {
158 u64 offset, length;
159 u64 truncate_size;
160 u32 truncate_seq;
161 } extent;
162 struct {
163 const char *name;
164 u32 name_len;
165 const char *val;
166 u32 value_len;
167 __u8 cmp_op; /* CEPH_OSD_CMPXATTR_OP_* */
168 __u8 cmp_mode; /* CEPH_OSD_CMPXATTR_MODE_* */
169 } xattr;
170 struct {
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700171 const char *class_name;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700172 __u8 class_len;
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700173 const char *method_name;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700174 __u8 method_len;
175 __u8 argc;
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700176 const char *indata;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700177 u32 indata_len;
178 } cls;
179 struct {
180 u64 cookie, count;
181 } pgls;
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700182 struct {
183 u64 snapid;
184 } snap;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700185 struct {
186 u64 cookie;
187 u64 ver;
188 __u8 flag;
189 u32 prot_ver;
190 u32 timeout;
191 } watch;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700192 };
193 u32 payload_len;
194};
195
Sage Weilf24e9982009-10-06 11:31:10 -0700196extern int ceph_osdc_init(struct ceph_osd_client *osdc,
197 struct ceph_client *client);
198extern void ceph_osdc_stop(struct ceph_osd_client *osdc);
199
200extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
201 struct ceph_msg *msg);
202extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
203 struct ceph_msg *msg);
204
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700205extern void ceph_calc_raw_layout(struct ceph_osd_client *osdc,
206 struct ceph_file_layout *layout,
207 u64 snapid,
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700208 u64 off, u64 *plen, u64 *bno,
209 struct ceph_osd_request *req,
210 struct ceph_osd_req_op *op);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700211
212extern struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
213 int flags,
214 struct ceph_snap_context *snapc,
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700215 struct ceph_osd_req_op *ops,
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700216 bool use_mempool,
217 gfp_t gfp_flags,
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700218 struct page **pages,
219 struct bio *bio);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700220
221extern void ceph_osdc_build_request(struct ceph_osd_request *req,
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700222 u64 off, u64 *plen,
223 struct ceph_osd_req_op *src_ops,
224 struct ceph_snap_context *snapc,
225 struct timespec *mtime,
226 const char *oid,
227 int oid_len);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700228
Sage Weilf24e9982009-10-06 11:31:10 -0700229extern struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *,
230 struct ceph_file_layout *layout,
231 struct ceph_vino vino,
232 u64 offset, u64 *len, int op, int flags,
233 struct ceph_snap_context *snapc,
234 int do_sync, u32 truncate_seq,
235 u64 truncate_size,
236 struct timespec *mtime,
Sage Weilb7495fc2010-11-09 12:43:12 -0800237 bool use_mempool, int num_reply,
238 int page_align);
Sage Weilf24e9982009-10-06 11:31:10 -0700239
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700240extern void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
241 struct ceph_osd_request *req);
242extern void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
243 struct ceph_osd_request *req);
244
Sage Weilf24e9982009-10-06 11:31:10 -0700245static inline void ceph_osdc_get_request(struct ceph_osd_request *req)
246{
Sage Weil415e49a2009-12-07 13:37:03 -0800247 kref_get(&req->r_kref);
Sage Weilf24e9982009-10-06 11:31:10 -0700248}
Sage Weil415e49a2009-12-07 13:37:03 -0800249extern void ceph_osdc_release_request(struct kref *kref);
250static inline void ceph_osdc_put_request(struct ceph_osd_request *req)
251{
252 kref_put(&req->r_kref, ceph_osdc_release_request);
253}
Sage Weilf24e9982009-10-06 11:31:10 -0700254
255extern int ceph_osdc_start_request(struct ceph_osd_client *osdc,
256 struct ceph_osd_request *req,
257 bool nofail);
258extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
259 struct ceph_osd_request *req);
260extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
261
262extern int ceph_osdc_readpages(struct ceph_osd_client *osdc,
263 struct ceph_vino vino,
264 struct ceph_file_layout *layout,
265 u64 off, u64 *plen,
266 u32 truncate_seq, u64 truncate_size,
Sage Weilb7495fc2010-11-09 12:43:12 -0800267 struct page **pages, int nr_pages,
268 int page_align);
Sage Weilf24e9982009-10-06 11:31:10 -0700269
270extern int ceph_osdc_writepages(struct ceph_osd_client *osdc,
271 struct ceph_vino vino,
272 struct ceph_file_layout *layout,
273 struct ceph_snap_context *sc,
274 u64 off, u64 len,
275 u32 truncate_seq, u64 truncate_size,
276 struct timespec *mtime,
277 struct page **pages, int nr_pages,
278 int flags, int do_sync, bool nofail);
279
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700280/* watch/notify events */
281extern int ceph_osdc_create_event(struct ceph_osd_client *osdc,
282 void (*event_cb)(u64, u64, u8, void *),
283 int one_shot, void *data,
284 struct ceph_osd_event **pevent);
285extern void ceph_osdc_cancel_event(struct ceph_osd_event *event);
286extern int ceph_osdc_wait_event(struct ceph_osd_event *event,
287 unsigned long timeout);
288extern void ceph_osdc_put_event(struct ceph_osd_event *event);
Sage Weilf24e9982009-10-06 11:31:10 -0700289#endif
290