blob: ac7bcbf195743ddb0ec729490c7f0727a241a701 [file] [log] [blame]
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001#include <linux/ceph/ceph_debug.h>
Sage Weilf24e9982009-10-06 11:31:10 -07002
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07003#include <linux/module.h>
Sage Weilf24e9982009-10-06 11:31:10 -07004#include <linux/err.h>
5#include <linux/highmem.h>
6#include <linux/mm.h>
7#include <linux/pagemap.h>
8#include <linux/slab.h>
9#include <linux/uaccess.h>
Yehuda Sadeh68b44762010-04-06 15:01:27 -070010#ifdef CONFIG_BLOCK
11#include <linux/bio.h>
12#endif
Sage Weilf24e9982009-10-06 11:31:10 -070013
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070014#include <linux/ceph/libceph.h>
15#include <linux/ceph/osd_client.h>
16#include <linux/ceph/messenger.h>
17#include <linux/ceph/decode.h>
18#include <linux/ceph/auth.h>
19#include <linux/ceph/pagelist.h>
Sage Weilf24e9982009-10-06 11:31:10 -070020
Sage Weilc16e7862010-03-01 13:02:00 -080021#define OSD_OP_FRONT_LEN 4096
22#define OSD_OPREPLY_FRONT_LEN 512
Yehuda Sadeh0d59ab82010-01-13 17:03:23 -080023
Tobias Klauser9e327892010-05-20 10:40:19 +020024static const struct ceph_connection_operations osd_con_ops;
Sage Weilf24e9982009-10-06 11:31:10 -070025
Alex Elderf9d25192013-02-15 11:42:29 -060026static void __send_queued(struct ceph_osd_client *osdc);
Sage Weil6f6c7002011-01-17 20:34:08 -080027static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -070028static void __register_request(struct ceph_osd_client *osdc,
29 struct ceph_osd_request *req);
30static void __unregister_linger_request(struct ceph_osd_client *osdc,
31 struct ceph_osd_request *req);
Sage Weil56e925b2012-01-03 12:34:34 -080032static void __send_request(struct ceph_osd_client *osdc,
33 struct ceph_osd_request *req);
Sage Weilf24e9982009-10-06 11:31:10 -070034
Yehuda Sadeh68b44762010-04-06 15:01:27 -070035static int op_has_extent(int op)
36{
37 return (op == CEPH_OSD_OP_READ ||
38 op == CEPH_OSD_OP_WRITE);
39}
40
Sage Weilf24e9982009-10-06 11:31:10 -070041/*
42 * Implement client access to distributed object storage cluster.
43 *
44 * All data objects are stored within a cluster/cloud of OSDs, or
45 * "object storage devices." (Note that Ceph OSDs have _nothing_ to
46 * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply
47 * remote daemons serving up and coordinating consistent and safe
48 * access to storage.
49 *
50 * Cluster membership and the mapping of data objects onto storage devices
51 * are described by the osd map.
52 *
53 * We keep track of pending OSD requests (read, write), resubmit
54 * requests to different OSDs when the cluster topology/data layout
55 * change, or retry the affected requests when the communications
56 * channel with an OSD is reset.
57 */
58
59/*
60 * calculate the mapping of a file extent onto an object, and fill out the
61 * request accordingly. shorten extent as necessary if it crosses an
62 * object boundary.
63 *
64 * fill osd op in request message.
65 */
Alex Eldere75b45c2012-11-13 21:11:14 -060066static int calc_layout(struct ceph_vino vino,
Sage Weild63b77f2012-09-24 20:59:48 -070067 struct ceph_file_layout *layout,
68 u64 off, u64 *plen,
69 struct ceph_osd_request *req,
70 struct ceph_osd_req_op *op)
Sage Weilf24e9982009-10-06 11:31:10 -070071{
Alex Elder60e56f12013-02-15 11:42:29 -060072 u64 orig_len = *plen;
73 u64 bno = 0;
74 u64 objoff = 0;
75 u64 objlen = 0;
Sage Weild63b77f2012-09-24 20:59:48 -070076 int r;
Sage Weilf24e9982009-10-06 11:31:10 -070077
Alex Elder60e56f12013-02-15 11:42:29 -060078 /* object extent? */
79 r = ceph_calc_file_object_mapping(layout, off, orig_len, &bno,
80 &objoff, &objlen);
Sage Weild63b77f2012-09-24 20:59:48 -070081 if (r < 0)
82 return r;
Alex Elder60e56f12013-02-15 11:42:29 -060083 if (objlen < orig_len) {
84 *plen = objlen;
85 dout(" skipping last %llu, final file extent %llu~%llu\n",
86 orig_len - *plen, off, *plen);
87 }
88
89 if (op_has_extent(op->op)) {
90 u32 osize = le32_to_cpu(layout->fl_object_size);
91 op->extent.offset = objoff;
92 op->extent.length = objlen;
93 if (op->extent.truncate_size <= off - objoff) {
94 op->extent.truncate_size = 0;
95 } else {
96 op->extent.truncate_size -= off - objoff;
97 if (op->extent.truncate_size > osize)
98 op->extent.truncate_size = osize;
99 }
100 }
101 req->r_num_pages = calc_pages_for(off, *plen);
102 req->r_page_alignment = off & ~PAGE_MASK;
103 if (op->op == CEPH_OSD_OP_WRITE)
104 op->payload_len = *plen;
105
106 dout("calc_layout bno=%llx %llu~%llu (%d pages)\n",
107 bno, objoff, objlen, req->r_num_pages);
Sage Weilf24e9982009-10-06 11:31:10 -0700108
Sage Weil2dab0362011-05-12 14:29:51 -0700109 snprintf(req->r_oid, sizeof(req->r_oid), "%llx.%08llx", vino.ino, bno);
Sage Weilf24e9982009-10-06 11:31:10 -0700110 req->r_oid_len = strlen(req->r_oid);
Sage Weild63b77f2012-09-24 20:59:48 -0700111
112 return r;
Sage Weilf24e9982009-10-06 11:31:10 -0700113}
114
Sage Weilf24e9982009-10-06 11:31:10 -0700115/*
116 * requests
117 */
Sage Weil415e49a2009-12-07 13:37:03 -0800118void ceph_osdc_release_request(struct kref *kref)
Sage Weilf24e9982009-10-06 11:31:10 -0700119{
Sage Weil415e49a2009-12-07 13:37:03 -0800120 struct ceph_osd_request *req = container_of(kref,
121 struct ceph_osd_request,
122 r_kref);
123
124 if (req->r_request)
125 ceph_msg_put(req->r_request);
Yehuda Sadeh0d59ab82010-01-13 17:03:23 -0800126 if (req->r_con_filling_msg) {
Alex Elder9cbb1d72013-01-31 16:02:00 -0600127 dout("%s revoking msg %p from con %p\n", __func__,
128 req->r_reply, req->r_con_filling_msg);
Alex Elder8921d112012-06-01 14:56:43 -0500129 ceph_msg_revoke_incoming(req->r_reply);
Sage Weil0d477662012-05-31 20:22:18 -0700130 req->r_con_filling_msg->ops->put(req->r_con_filling_msg);
Alex Elder9cbb1d72013-01-31 16:02:00 -0600131 req->r_con_filling_msg = NULL;
Sage Weil350b1c32009-12-22 10:45:45 -0800132 }
Alex Elderab8cb342012-06-04 14:43:32 -0500133 if (req->r_reply)
134 ceph_msg_put(req->r_reply);
Sage Weil415e49a2009-12-07 13:37:03 -0800135 if (req->r_own_pages)
136 ceph_release_page_vector(req->r_pages,
137 req->r_num_pages);
138 ceph_put_snap_context(req->r_snapc);
Alex Elderc8858372012-11-13 21:11:15 -0600139 ceph_pagelist_release(&req->r_trail);
Sage Weil415e49a2009-12-07 13:37:03 -0800140 if (req->r_mempool)
141 mempool_free(req, req->r_osdc->req_mempool);
142 else
143 kfree(req);
Sage Weilf24e9982009-10-06 11:31:10 -0700144}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700145EXPORT_SYMBOL(ceph_osdc_release_request);
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700146
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700147struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700148 struct ceph_snap_context *snapc,
Alex Elderae7ca4a32012-11-13 21:11:15 -0600149 unsigned int num_op,
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700150 bool use_mempool,
Alex Elder54a54002012-11-13 21:11:15 -0600151 gfp_t gfp_flags)
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700152{
153 struct ceph_osd_request *req;
154 struct ceph_msg *msg;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700155 size_t msg_size = sizeof(struct ceph_osd_request_head);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700156
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700157 msg_size += num_op*sizeof(struct ceph_osd_op);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700158
159 if (use_mempool) {
160 req = mempool_alloc(osdc->req_mempool, gfp_flags);
161 memset(req, 0, sizeof(*req));
162 } else {
163 req = kzalloc(sizeof(*req), gfp_flags);
164 }
165 if (req == NULL)
166 return NULL;
167
168 req->r_osdc = osdc;
169 req->r_mempool = use_mempool;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700170
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700171 kref_init(&req->r_kref);
172 init_completion(&req->r_completion);
173 init_completion(&req->r_safe_completion);
Alex Eldera978fa22012-12-17 12:23:48 -0600174 RB_CLEAR_NODE(&req->r_node);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700175 INIT_LIST_HEAD(&req->r_unsafe_item);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700176 INIT_LIST_HEAD(&req->r_linger_item);
177 INIT_LIST_HEAD(&req->r_linger_osd);
Sage Weil935b639a2011-09-16 11:13:17 -0700178 INIT_LIST_HEAD(&req->r_req_lru_item);
Sage Weilcd430452012-07-09 14:31:41 -0700179 INIT_LIST_HEAD(&req->r_osd_item);
180
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700181 /* create reply message */
182 if (use_mempool)
183 msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0);
184 else
185 msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY,
Sage Weilb61c2762011-08-09 15:03:46 -0700186 OSD_OPREPLY_FRONT_LEN, gfp_flags, true);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700187 if (!msg) {
188 ceph_osdc_put_request(req);
189 return NULL;
190 }
191 req->r_reply = msg;
192
Alex Elderc8858372012-11-13 21:11:15 -0600193 ceph_pagelist_init(&req->r_trail);
Sage Weild50b4092012-07-09 14:22:34 -0700194
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700195 /* create request message; allow space for oid */
Stratos Psomadakis224736d2011-11-10 15:45:37 +0200196 msg_size += MAX_OBJ_NAME_SIZE;
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700197 if (snapc)
198 msg_size += sizeof(u64) * snapc->num_snaps;
199 if (use_mempool)
200 msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
201 else
Sage Weilb61c2762011-08-09 15:03:46 -0700202 msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags, true);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700203 if (!msg) {
204 ceph_osdc_put_request(req);
205 return NULL;
206 }
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700207
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700208 memset(msg->front.iov_base, 0, msg->front.iov_len);
209
210 req->r_request = msg;
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700211
212 return req;
213}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700214EXPORT_SYMBOL(ceph_osdc_alloc_request);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700215
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700216static void osd_req_encode_op(struct ceph_osd_request *req,
217 struct ceph_osd_op *dst,
218 struct ceph_osd_req_op *src)
219{
220 dst->op = cpu_to_le16(src->op);
221
Alex Elder065a68f2012-04-20 15:49:43 -0500222 switch (src->op) {
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700223 case CEPH_OSD_OP_READ:
224 case CEPH_OSD_OP_WRITE:
225 dst->extent.offset =
226 cpu_to_le64(src->extent.offset);
227 dst->extent.length =
228 cpu_to_le64(src->extent.length);
229 dst->extent.truncate_size =
230 cpu_to_le64(src->extent.truncate_size);
231 dst->extent.truncate_seq =
232 cpu_to_le32(src->extent.truncate_seq);
233 break;
234
235 case CEPH_OSD_OP_GETXATTR:
236 case CEPH_OSD_OP_SETXATTR:
237 case CEPH_OSD_OP_CMPXATTR:
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700238 dst->xattr.name_len = cpu_to_le32(src->xattr.name_len);
239 dst->xattr.value_len = cpu_to_le32(src->xattr.value_len);
240 dst->xattr.cmp_op = src->xattr.cmp_op;
241 dst->xattr.cmp_mode = src->xattr.cmp_mode;
Alex Elderc8858372012-11-13 21:11:15 -0600242 ceph_pagelist_append(&req->r_trail, src->xattr.name,
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700243 src->xattr.name_len);
Alex Elderc8858372012-11-13 21:11:15 -0600244 ceph_pagelist_append(&req->r_trail, src->xattr.val,
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700245 src->xattr.value_len);
246 break;
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700247 case CEPH_OSD_OP_CALL:
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700248 dst->cls.class_len = src->cls.class_len;
249 dst->cls.method_len = src->cls.method_len;
250 dst->cls.indata_len = cpu_to_le32(src->cls.indata_len);
251
Alex Elderc8858372012-11-13 21:11:15 -0600252 ceph_pagelist_append(&req->r_trail, src->cls.class_name,
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700253 src->cls.class_len);
Alex Elderc8858372012-11-13 21:11:15 -0600254 ceph_pagelist_append(&req->r_trail, src->cls.method_name,
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700255 src->cls.method_len);
Alex Elderc8858372012-11-13 21:11:15 -0600256 ceph_pagelist_append(&req->r_trail, src->cls.indata,
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700257 src->cls.indata_len);
258 break;
259 case CEPH_OSD_OP_ROLLBACK:
260 dst->snap.snapid = cpu_to_le64(src->snap.snapid);
261 break;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700262 case CEPH_OSD_OP_STARTSYNC:
263 break;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700264 case CEPH_OSD_OP_NOTIFY:
265 {
266 __le32 prot_ver = cpu_to_le32(src->watch.prot_ver);
267 __le32 timeout = cpu_to_le32(src->watch.timeout);
268
Alex Elderc8858372012-11-13 21:11:15 -0600269 ceph_pagelist_append(&req->r_trail,
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700270 &prot_ver, sizeof(prot_ver));
Alex Elderc8858372012-11-13 21:11:15 -0600271 ceph_pagelist_append(&req->r_trail,
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700272 &timeout, sizeof(timeout));
273 }
274 case CEPH_OSD_OP_NOTIFY_ACK:
275 case CEPH_OSD_OP_WATCH:
276 dst->watch.cookie = cpu_to_le64(src->watch.cookie);
277 dst->watch.ver = cpu_to_le64(src->watch.ver);
278 dst->watch.flag = src->watch.flag;
279 break;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700280 default:
281 pr_err("unrecognized osd opcode %d\n", dst->op);
282 WARN_ON(1);
283 break;
Alex Elder4c464592013-02-15 11:42:30 -0600284 case CEPH_OSD_OP_STAT:
285 case CEPH_OSD_OP_MAPEXT:
286 case CEPH_OSD_OP_MASKTRUNC:
287 case CEPH_OSD_OP_SPARSE_READ:
288 case CEPH_OSD_OP_ASSERT_VER:
289 case CEPH_OSD_OP_WRITEFULL:
290 case CEPH_OSD_OP_TRUNCATE:
291 case CEPH_OSD_OP_ZERO:
292 case CEPH_OSD_OP_DELETE:
293 case CEPH_OSD_OP_APPEND:
294 case CEPH_OSD_OP_SETTRUNC:
295 case CEPH_OSD_OP_TRIMTRUNC:
296 case CEPH_OSD_OP_TMAPUP:
297 case CEPH_OSD_OP_TMAPPUT:
298 case CEPH_OSD_OP_TMAPGET:
299 case CEPH_OSD_OP_CREATE:
300 case CEPH_OSD_OP_OMAPGETKEYS:
301 case CEPH_OSD_OP_OMAPGETVALS:
302 case CEPH_OSD_OP_OMAPGETHEADER:
303 case CEPH_OSD_OP_OMAPGETVALSBYKEYS:
304 case CEPH_OSD_OP_MODE_RD:
305 case CEPH_OSD_OP_OMAPSETVALS:
306 case CEPH_OSD_OP_OMAPSETHEADER:
307 case CEPH_OSD_OP_OMAPCLEAR:
308 case CEPH_OSD_OP_OMAPRMKEYS:
309 case CEPH_OSD_OP_OMAP_CMP:
310 case CEPH_OSD_OP_CLONERANGE:
311 case CEPH_OSD_OP_ASSERT_SRC_VERSION:
312 case CEPH_OSD_OP_SRC_CMPXATTR:
313 case CEPH_OSD_OP_GETXATTRS:
314 case CEPH_OSD_OP_SETXATTRS:
315 case CEPH_OSD_OP_RESETXATTRS:
316 case CEPH_OSD_OP_RMXATTR:
317 case CEPH_OSD_OP_PULL:
318 case CEPH_OSD_OP_PUSH:
319 case CEPH_OSD_OP_BALANCEREADS:
320 case CEPH_OSD_OP_UNBALANCEREADS:
321 case CEPH_OSD_OP_SCRUB:
322 case CEPH_OSD_OP_SCRUB_RESERVE:
323 case CEPH_OSD_OP_SCRUB_UNRESERVE:
324 case CEPH_OSD_OP_SCRUB_STOP:
325 case CEPH_OSD_OP_SCRUB_MAP:
326 case CEPH_OSD_OP_WRLOCK:
327 case CEPH_OSD_OP_WRUNLOCK:
328 case CEPH_OSD_OP_RDLOCK:
329 case CEPH_OSD_OP_RDUNLOCK:
330 case CEPH_OSD_OP_UPLOCK:
331 case CEPH_OSD_OP_DNLOCK:
332 case CEPH_OSD_OP_PGLS:
333 case CEPH_OSD_OP_PGLS_FILTER:
334 pr_err("unsupported osd opcode %s\n",
335 ceph_osd_op_name(dst->op));
336 WARN_ON(1);
337 break;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700338 }
339 dst->payload_len = cpu_to_le32(src->payload_len);
340}
341
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700342/*
343 * build new request AND message
344 *
345 */
346void ceph_osdc_build_request(struct ceph_osd_request *req,
Alex Elderae7ca4a32012-11-13 21:11:15 -0600347 u64 off, u64 len, unsigned int num_op,
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700348 struct ceph_osd_req_op *src_ops,
Alex Elder4d6b2502012-11-13 21:11:15 -0600349 struct ceph_snap_context *snapc, u64 snap_id,
Alex Elderaf77f262012-11-09 08:43:15 -0600350 struct timespec *mtime)
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700351{
352 struct ceph_msg *msg = req->r_request;
353 struct ceph_osd_request_head *head;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700354 struct ceph_osd_req_op *src_op;
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700355 struct ceph_osd_op *op;
356 void *p;
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700357 size_t msg_size = sizeof(*head) + num_op*sizeof(*op);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700358 int flags = req->r_flags;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700359 u64 data_len = 0;
360 int i;
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700361
Alex Elderd178a9e2012-11-13 21:11:15 -0600362 WARN_ON((flags & (CEPH_OSD_FLAG_READ|CEPH_OSD_FLAG_WRITE)) == 0);
363
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700364 head = msg->front.iov_base;
Alex Elder4d6b2502012-11-13 21:11:15 -0600365 head->snapid = cpu_to_le64(snap_id);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700366 op = (void *)(head + 1);
367 p = (void *)(op + num_op);
368
369 req->r_snapc = ceph_get_snap_context(snapc);
370
371 head->client_inc = cpu_to_le32(1); /* always, for now. */
372 head->flags = cpu_to_le32(flags);
373 if (flags & CEPH_OSD_FLAG_WRITE)
374 ceph_encode_timespec(&head->mtime, mtime);
Alex Elderae7ca4a32012-11-13 21:11:15 -0600375 BUG_ON(num_op > (unsigned int) ((u16) -1));
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700376 head->num_ops = cpu_to_le16(num_op);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700377
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700378 /* fill in oid */
Alex Elderaf77f262012-11-09 08:43:15 -0600379 head->object_len = cpu_to_le32(req->r_oid_len);
380 memcpy(p, req->r_oid, req->r_oid_len);
381 p += req->r_oid_len;
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700382
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700383 src_op = src_ops;
Alex Elderae7ca4a32012-11-13 21:11:15 -0600384 while (num_op--)
385 osd_req_encode_op(req, op++, src_op++);
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700386
Alex Elderc8858372012-11-13 21:11:15 -0600387 data_len += req->r_trail.length;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700388
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700389 if (snapc) {
390 head->snap_seq = cpu_to_le64(snapc->seq);
391 head->num_snaps = cpu_to_le32(snapc->num_snaps);
392 for (i = 0; i < snapc->num_snaps; i++) {
393 put_unaligned_le64(snapc->snaps[i], p);
394 p += sizeof(u64);
395 }
396 }
397
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700398 if (flags & CEPH_OSD_FLAG_WRITE) {
399 req->r_request->hdr.data_off = cpu_to_le16(off);
Alex Elder0120be32012-11-14 09:38:19 -0600400 req->r_request->hdr.data_len = cpu_to_le32(len + data_len);
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700401 } else if (data_len) {
402 req->r_request->hdr.data_off = 0;
403 req->r_request->hdr.data_len = cpu_to_le32(data_len);
404 }
405
Sage Weilc5c6b192010-11-09 12:40:00 -0800406 req->r_request->page_alignment = req->r_page_alignment;
407
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700408 BUG_ON(p > msg->front.iov_base + msg->front.iov_len);
409 msg_size = p - msg->front.iov_base;
410 msg->front.iov_len = msg_size;
411 msg->hdr.front_len = cpu_to_le32(msg_size);
412 return;
413}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700414EXPORT_SYMBOL(ceph_osdc_build_request);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700415
Sage Weilf24e9982009-10-06 11:31:10 -0700416/*
417 * build new request AND message, calculate layout, and adjust file
418 * extent as needed.
419 *
420 * if the file was recently truncated, we include information about its
421 * old and new size so that the object can be updated appropriately. (we
422 * avoid synchronously deleting truncated objects because it's slow.)
423 *
424 * if @do_sync, include a 'startsync' command so that the osd will flush
425 * data quickly.
426 */
427struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
428 struct ceph_file_layout *layout,
429 struct ceph_vino vino,
430 u64 off, u64 *plen,
431 int opcode, int flags,
432 struct ceph_snap_context *snapc,
433 int do_sync,
434 u32 truncate_seq,
435 u64 truncate_size,
436 struct timespec *mtime,
Alex Eldera3bea472013-02-15 11:42:29 -0600437 bool use_mempool,
Sage Weilb7495fc2010-11-09 12:43:12 -0800438 int page_align)
Sage Weilf24e9982009-10-06 11:31:10 -0700439{
Alex Elderae7ca4a32012-11-13 21:11:15 -0600440 struct ceph_osd_req_op ops[2];
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700441 struct ceph_osd_request *req;
Alex Elderae7ca4a32012-11-13 21:11:15 -0600442 unsigned int num_op = 1;
Sage Weil68162822012-09-24 21:01:02 -0700443 int r;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700444
Alex Elderae7ca4a32012-11-13 21:11:15 -0600445 memset(&ops, 0, sizeof ops);
446
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700447 ops[0].op = opcode;
448 ops[0].extent.truncate_seq = truncate_seq;
449 ops[0].extent.truncate_size = truncate_size;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700450
451 if (do_sync) {
452 ops[1].op = CEPH_OSD_OP_STARTSYNC;
Alex Elderae7ca4a32012-11-13 21:11:15 -0600453 num_op++;
454 }
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700455
Alex Elderae7ca4a32012-11-13 21:11:15 -0600456 req = ceph_osdc_alloc_request(osdc, snapc, num_op, use_mempool,
457 GFP_NOFS);
Sage Weil4ad12622011-05-03 09:23:36 -0700458 if (!req)
Sage Weil68162822012-09-24 21:01:02 -0700459 return ERR_PTR(-ENOMEM);
Alex Elderd178a9e2012-11-13 21:11:15 -0600460 req->r_flags = flags;
Sage Weilf24e9982009-10-06 11:31:10 -0700461
462 /* calculate max write size */
Alex Eldere75b45c2012-11-13 21:11:14 -0600463 r = calc_layout(vino, layout, off, plen, req, ops);
Sage Weil68162822012-09-24 21:01:02 -0700464 if (r < 0)
465 return ERR_PTR(r);
Sage Weilf24e9982009-10-06 11:31:10 -0700466 req->r_file_layout = *layout; /* keep a copy */
467
Sage Weil9bb0ce22011-06-13 16:20:18 -0700468 /* in case it differs from natural (file) alignment that
469 calc_layout filled in for us */
470 req->r_num_pages = calc_pages_for(page_align, *plen);
Sage Weilb7495fc2010-11-09 12:43:12 -0800471 req->r_page_alignment = page_align;
472
Alex Elderae7ca4a32012-11-13 21:11:15 -0600473 ceph_osdc_build_request(req, off, *plen, num_op, ops,
474 snapc, vino.snap, mtime);
Sage Weilf24e9982009-10-06 11:31:10 -0700475
Sage Weilf24e9982009-10-06 11:31:10 -0700476 return req;
477}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700478EXPORT_SYMBOL(ceph_osdc_new_request);
Sage Weilf24e9982009-10-06 11:31:10 -0700479
480/*
481 * We keep osd requests in an rbtree, sorted by ->r_tid.
482 */
483static void __insert_request(struct ceph_osd_client *osdc,
484 struct ceph_osd_request *new)
485{
486 struct rb_node **p = &osdc->requests.rb_node;
487 struct rb_node *parent = NULL;
488 struct ceph_osd_request *req = NULL;
489
490 while (*p) {
491 parent = *p;
492 req = rb_entry(parent, struct ceph_osd_request, r_node);
493 if (new->r_tid < req->r_tid)
494 p = &(*p)->rb_left;
495 else if (new->r_tid > req->r_tid)
496 p = &(*p)->rb_right;
497 else
498 BUG();
499 }
500
501 rb_link_node(&new->r_node, parent, p);
502 rb_insert_color(&new->r_node, &osdc->requests);
503}
504
505static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc,
506 u64 tid)
507{
508 struct ceph_osd_request *req;
509 struct rb_node *n = osdc->requests.rb_node;
510
511 while (n) {
512 req = rb_entry(n, struct ceph_osd_request, r_node);
513 if (tid < req->r_tid)
514 n = n->rb_left;
515 else if (tid > req->r_tid)
516 n = n->rb_right;
517 else
518 return req;
519 }
520 return NULL;
521}
522
523static struct ceph_osd_request *
524__lookup_request_ge(struct ceph_osd_client *osdc,
525 u64 tid)
526{
527 struct ceph_osd_request *req;
528 struct rb_node *n = osdc->requests.rb_node;
529
530 while (n) {
531 req = rb_entry(n, struct ceph_osd_request, r_node);
532 if (tid < req->r_tid) {
533 if (!n->rb_left)
534 return req;
535 n = n->rb_left;
536 } else if (tid > req->r_tid) {
537 n = n->rb_right;
538 } else {
539 return req;
540 }
541 }
542 return NULL;
543}
544
Sage Weil6f6c7002011-01-17 20:34:08 -0800545/*
546 * Resubmit requests pending on the given osd.
547 */
548static void __kick_osd_requests(struct ceph_osd_client *osdc,
549 struct ceph_osd *osd)
550{
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700551 struct ceph_osd_request *req, *nreq;
Sage Weil6f6c7002011-01-17 20:34:08 -0800552 int err;
553
554 dout("__kick_osd_requests osd%d\n", osd->o_osd);
555 err = __reset_osd(osdc, osd);
Alex Elder685a7552012-12-07 09:57:58 -0600556 if (err)
Sage Weil6f6c7002011-01-17 20:34:08 -0800557 return;
558
559 list_for_each_entry(req, &osd->o_requests, r_osd_item) {
560 list_move(&req->r_req_lru_item, &osdc->req_unsent);
561 dout("requeued %p tid %llu osd%d\n", req, req->r_tid,
562 osd->o_osd);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700563 if (!req->r_linger)
564 req->r_flags |= CEPH_OSD_FLAG_RETRY;
565 }
566
567 list_for_each_entry_safe(req, nreq, &osd->o_linger_requests,
568 r_linger_osd) {
Sage Weil77f38e02011-04-06 09:09:16 -0700569 /*
570 * reregister request prior to unregistering linger so
571 * that r_osd is preserved.
572 */
573 BUG_ON(!list_empty(&req->r_req_lru_item));
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700574 __register_request(osdc, req);
Sage Weil77f38e02011-04-06 09:09:16 -0700575 list_add(&req->r_req_lru_item, &osdc->req_unsent);
576 list_add(&req->r_osd_item, &req->r_osd->o_requests);
577 __unregister_linger_request(osdc, req);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700578 dout("requeued lingering %p tid %llu osd%d\n", req, req->r_tid,
579 osd->o_osd);
Sage Weil6f6c7002011-01-17 20:34:08 -0800580 }
581}
582
Sage Weilf24e9982009-10-06 11:31:10 -0700583/*
Sage Weil81b024e2009-10-09 10:29:18 -0700584 * If the osd connection drops, we need to resubmit all requests.
Sage Weilf24e9982009-10-06 11:31:10 -0700585 */
586static void osd_reset(struct ceph_connection *con)
587{
588 struct ceph_osd *osd = con->private;
589 struct ceph_osd_client *osdc;
590
591 if (!osd)
592 return;
593 dout("osd_reset osd%d\n", osd->o_osd);
594 osdc = osd->o_osdc;
Sage Weilf24e9982009-10-06 11:31:10 -0700595 down_read(&osdc->map_sem);
Sage Weil83aff952012-11-28 12:28:24 -0800596 mutex_lock(&osdc->request_mutex);
597 __kick_osd_requests(osdc, osd);
Alex Elderf9d25192013-02-15 11:42:29 -0600598 __send_queued(osdc);
Sage Weil83aff952012-11-28 12:28:24 -0800599 mutex_unlock(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -0700600 up_read(&osdc->map_sem);
601}
602
603/*
604 * Track open sessions with osds.
605 */
Alex Eldere10006f2012-05-26 23:26:43 -0500606static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
Sage Weilf24e9982009-10-06 11:31:10 -0700607{
608 struct ceph_osd *osd;
609
610 osd = kzalloc(sizeof(*osd), GFP_NOFS);
611 if (!osd)
612 return NULL;
613
614 atomic_set(&osd->o_ref, 1);
615 osd->o_osdc = osdc;
Alex Eldere10006f2012-05-26 23:26:43 -0500616 osd->o_osd = onum;
Alex Elderf4077312012-12-06 07:22:04 -0600617 RB_CLEAR_NODE(&osd->o_node);
Sage Weilf24e9982009-10-06 11:31:10 -0700618 INIT_LIST_HEAD(&osd->o_requests);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700619 INIT_LIST_HEAD(&osd->o_linger_requests);
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800620 INIT_LIST_HEAD(&osd->o_osd_lru);
Sage Weilf24e9982009-10-06 11:31:10 -0700621 osd->o_incarnation = 1;
622
Sage Weilb7a9e5d2012-06-27 12:24:08 -0700623 ceph_con_init(&osd->o_con, osd, &osd_con_ops, &osdc->client->msgr);
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800624
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800625 INIT_LIST_HEAD(&osd->o_keepalive_item);
Sage Weilf24e9982009-10-06 11:31:10 -0700626 return osd;
627}
628
629static struct ceph_osd *get_osd(struct ceph_osd *osd)
630{
631 if (atomic_inc_not_zero(&osd->o_ref)) {
632 dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1,
633 atomic_read(&osd->o_ref));
634 return osd;
635 } else {
636 dout("get_osd %p FAIL\n", osd);
637 return NULL;
638 }
639}
640
641static void put_osd(struct ceph_osd *osd)
642{
643 dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref),
644 atomic_read(&osd->o_ref) - 1);
Alex Eldera2556512012-05-16 15:16:39 -0500645 if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) {
Sage Weil79494d12010-05-27 14:15:49 -0700646 struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth;
647
Alex Eldera2556512012-05-16 15:16:39 -0500648 if (ac->ops && ac->ops->destroy_authorizer)
Alex Elder6c4a1912012-05-16 15:16:38 -0500649 ac->ops->destroy_authorizer(ac, osd->o_auth.authorizer);
Sage Weilf24e9982009-10-06 11:31:10 -0700650 kfree(osd);
Sage Weil79494d12010-05-27 14:15:49 -0700651 }
Sage Weilf24e9982009-10-06 11:31:10 -0700652}
653
654/*
655 * remove an osd from our map
656 */
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800657static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
Sage Weilf24e9982009-10-06 11:31:10 -0700658{
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800659 dout("__remove_osd %p\n", osd);
Sage Weilf24e9982009-10-06 11:31:10 -0700660 BUG_ON(!list_empty(&osd->o_requests));
661 rb_erase(&osd->o_node, &osdc->osds);
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800662 list_del_init(&osd->o_osd_lru);
Sage Weilf24e9982009-10-06 11:31:10 -0700663 ceph_con_close(&osd->o_con);
664 put_osd(osd);
665}
666
Sage Weilaca420b2011-08-31 14:45:53 -0700667static void remove_all_osds(struct ceph_osd_client *osdc)
668{
Jiaju Zhang048a9d22012-07-20 08:18:36 -0500669 dout("%s %p\n", __func__, osdc);
Sage Weilaca420b2011-08-31 14:45:53 -0700670 mutex_lock(&osdc->request_mutex);
671 while (!RB_EMPTY_ROOT(&osdc->osds)) {
672 struct ceph_osd *osd = rb_entry(rb_first(&osdc->osds),
673 struct ceph_osd, o_node);
674 __remove_osd(osdc, osd);
675 }
676 mutex_unlock(&osdc->request_mutex);
677}
678
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800679static void __move_osd_to_lru(struct ceph_osd_client *osdc,
680 struct ceph_osd *osd)
681{
682 dout("__move_osd_to_lru %p\n", osd);
683 BUG_ON(!list_empty(&osd->o_osd_lru));
684 list_add_tail(&osd->o_osd_lru, &osdc->osd_lru);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700685 osd->lru_ttl = jiffies + osdc->client->options->osd_idle_ttl * HZ;
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800686}
687
688static void __remove_osd_from_lru(struct ceph_osd *osd)
689{
690 dout("__remove_osd_from_lru %p\n", osd);
691 if (!list_empty(&osd->o_osd_lru))
692 list_del_init(&osd->o_osd_lru);
693}
694
Sage Weilaca420b2011-08-31 14:45:53 -0700695static void remove_old_osds(struct ceph_osd_client *osdc)
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800696{
697 struct ceph_osd *osd, *nosd;
698
699 dout("__remove_old_osds %p\n", osdc);
700 mutex_lock(&osdc->request_mutex);
701 list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) {
Sage Weilaca420b2011-08-31 14:45:53 -0700702 if (time_before(jiffies, osd->lru_ttl))
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800703 break;
704 __remove_osd(osdc, osd);
705 }
706 mutex_unlock(&osdc->request_mutex);
707}
708
Sage Weilf24e9982009-10-06 11:31:10 -0700709/*
710 * reset osd connect
711 */
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800712static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
Sage Weilf24e9982009-10-06 11:31:10 -0700713{
Alex Elderc3acb182012-12-07 09:57:58 -0600714 struct ceph_entity_addr *peer_addr;
Sage Weilf24e9982009-10-06 11:31:10 -0700715
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800716 dout("__reset_osd %p osd%d\n", osd, osd->o_osd);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700717 if (list_empty(&osd->o_requests) &&
718 list_empty(&osd->o_linger_requests)) {
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800719 __remove_osd(osdc, osd);
Alex Elderc3acb182012-12-07 09:57:58 -0600720
721 return -ENODEV;
722 }
723
724 peer_addr = &osdc->osdmap->osd_addr[osd->o_osd];
725 if (!memcmp(peer_addr, &osd->o_con.peer_addr, sizeof (*peer_addr)) &&
726 !ceph_con_opened(&osd->o_con)) {
727 struct ceph_osd_request *req;
728
Sage Weil87b315a2010-03-22 14:51:18 -0700729 dout(" osd addr hasn't changed and connection never opened,"
730 " letting msgr retry");
731 /* touch each r_stamp for handle_timeout()'s benfit */
732 list_for_each_entry(req, &osd->o_requests, r_osd_item)
733 req->r_stamp = jiffies;
Alex Elderc3acb182012-12-07 09:57:58 -0600734
735 return -EAGAIN;
Sage Weilf24e9982009-10-06 11:31:10 -0700736 }
Alex Elderc3acb182012-12-07 09:57:58 -0600737
738 ceph_con_close(&osd->o_con);
739 ceph_con_open(&osd->o_con, CEPH_ENTITY_TYPE_OSD, osd->o_osd, peer_addr);
740 osd->o_incarnation++;
741
742 return 0;
Sage Weilf24e9982009-10-06 11:31:10 -0700743}
744
745static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new)
746{
747 struct rb_node **p = &osdc->osds.rb_node;
748 struct rb_node *parent = NULL;
749 struct ceph_osd *osd = NULL;
750
Sage Weilaca420b2011-08-31 14:45:53 -0700751 dout("__insert_osd %p osd%d\n", new, new->o_osd);
Sage Weilf24e9982009-10-06 11:31:10 -0700752 while (*p) {
753 parent = *p;
754 osd = rb_entry(parent, struct ceph_osd, o_node);
755 if (new->o_osd < osd->o_osd)
756 p = &(*p)->rb_left;
757 else if (new->o_osd > osd->o_osd)
758 p = &(*p)->rb_right;
759 else
760 BUG();
761 }
762
763 rb_link_node(&new->o_node, parent, p);
764 rb_insert_color(&new->o_node, &osdc->osds);
765}
766
767static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o)
768{
769 struct ceph_osd *osd;
770 struct rb_node *n = osdc->osds.rb_node;
771
772 while (n) {
773 osd = rb_entry(n, struct ceph_osd, o_node);
774 if (o < osd->o_osd)
775 n = n->rb_left;
776 else if (o > osd->o_osd)
777 n = n->rb_right;
778 else
779 return osd;
780 }
781 return NULL;
782}
783
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800784static void __schedule_osd_timeout(struct ceph_osd_client *osdc)
785{
786 schedule_delayed_work(&osdc->timeout_work,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700787 osdc->client->options->osd_keepalive_timeout * HZ);
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800788}
789
790static void __cancel_osd_timeout(struct ceph_osd_client *osdc)
791{
792 cancel_delayed_work(&osdc->timeout_work);
793}
Sage Weilf24e9982009-10-06 11:31:10 -0700794
795/*
796 * Register request, assign tid. If this is the first request, set up
797 * the timeout event.
798 */
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700799static void __register_request(struct ceph_osd_client *osdc,
800 struct ceph_osd_request *req)
Sage Weilf24e9982009-10-06 11:31:10 -0700801{
Sage Weilf24e9982009-10-06 11:31:10 -0700802 req->r_tid = ++osdc->last_tid;
Sage Weil6df058c2009-12-22 11:24:33 -0800803 req->r_request->hdr.tid = cpu_to_le64(req->r_tid);
Sage Weil77f38e02011-04-06 09:09:16 -0700804 dout("__register_request %p tid %lld\n", req, req->r_tid);
Sage Weilf24e9982009-10-06 11:31:10 -0700805 __insert_request(osdc, req);
806 ceph_osdc_get_request(req);
807 osdc->num_requests++;
Sage Weilf24e9982009-10-06 11:31:10 -0700808 if (osdc->num_requests == 1) {
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800809 dout(" first request, scheduling timeout\n");
810 __schedule_osd_timeout(osdc);
Sage Weilf24e9982009-10-06 11:31:10 -0700811 }
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700812}
813
814static void register_request(struct ceph_osd_client *osdc,
815 struct ceph_osd_request *req)
816{
817 mutex_lock(&osdc->request_mutex);
818 __register_request(osdc, req);
Sage Weilf24e9982009-10-06 11:31:10 -0700819 mutex_unlock(&osdc->request_mutex);
820}
821
822/*
823 * called under osdc->request_mutex
824 */
825static void __unregister_request(struct ceph_osd_client *osdc,
826 struct ceph_osd_request *req)
827{
Sage Weil35f9f8a2012-05-16 15:16:38 -0500828 if (RB_EMPTY_NODE(&req->r_node)) {
829 dout("__unregister_request %p tid %lld not registered\n",
830 req, req->r_tid);
831 return;
832 }
833
Sage Weilf24e9982009-10-06 11:31:10 -0700834 dout("__unregister_request %p tid %lld\n", req, req->r_tid);
835 rb_erase(&req->r_node, &osdc->requests);
836 osdc->num_requests--;
837
Sage Weil0ba64782009-10-08 16:57:16 -0700838 if (req->r_osd) {
839 /* make sure the original request isn't in flight. */
Alex Elder6740a842012-06-01 14:56:43 -0500840 ceph_msg_revoke(req->r_request);
Sage Weil0ba64782009-10-08 16:57:16 -0700841
842 list_del_init(&req->r_osd_item);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700843 if (list_empty(&req->r_osd->o_requests) &&
844 list_empty(&req->r_osd->o_linger_requests)) {
845 dout("moving osd to %p lru\n", req->r_osd);
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800846 __move_osd_to_lru(osdc, req->r_osd);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700847 }
Sage Weilfbdb9192011-03-29 12:11:06 -0700848 if (list_empty(&req->r_linger_item))
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700849 req->r_osd = NULL;
Sage Weil0ba64782009-10-08 16:57:16 -0700850 }
Sage Weilf24e9982009-10-06 11:31:10 -0700851
Alex Elder7d5f2482012-11-29 08:37:03 -0600852 list_del_init(&req->r_req_lru_item);
Sage Weilf24e9982009-10-06 11:31:10 -0700853 ceph_osdc_put_request(req);
854
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -0800855 if (osdc->num_requests == 0) {
856 dout(" no requests, canceling timeout\n");
857 __cancel_osd_timeout(osdc);
Sage Weilf24e9982009-10-06 11:31:10 -0700858 }
859}
860
861/*
862 * Cancel a previously queued request message
863 */
864static void __cancel_request(struct ceph_osd_request *req)
865{
Sage Weil6bc18872010-09-27 10:18:52 -0700866 if (req->r_sent && req->r_osd) {
Alex Elder6740a842012-06-01 14:56:43 -0500867 ceph_msg_revoke(req->r_request);
Sage Weilf24e9982009-10-06 11:31:10 -0700868 req->r_sent = 0;
869 }
870}
871
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700872static void __register_linger_request(struct ceph_osd_client *osdc,
873 struct ceph_osd_request *req)
874{
875 dout("__register_linger_request %p\n", req);
876 list_add_tail(&req->r_linger_item, &osdc->req_linger);
Sage Weil6194ea82012-07-30 16:19:28 -0700877 if (req->r_osd)
878 list_add_tail(&req->r_linger_osd,
879 &req->r_osd->o_linger_requests);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700880}
881
882static void __unregister_linger_request(struct ceph_osd_client *osdc,
883 struct ceph_osd_request *req)
884{
885 dout("__unregister_linger_request %p\n", req);
Alex Elder61c74032012-12-06 09:37:23 -0600886 list_del_init(&req->r_linger_item);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700887 if (req->r_osd) {
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700888 list_del_init(&req->r_linger_osd);
889
890 if (list_empty(&req->r_osd->o_requests) &&
891 list_empty(&req->r_osd->o_linger_requests)) {
892 dout("moving osd to %p lru\n", req->r_osd);
893 __move_osd_to_lru(osdc, req->r_osd);
894 }
Sage Weilfbdb9192011-03-29 12:11:06 -0700895 if (list_empty(&req->r_osd_item))
896 req->r_osd = NULL;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700897 }
898}
899
900void ceph_osdc_unregister_linger_request(struct ceph_osd_client *osdc,
901 struct ceph_osd_request *req)
902{
903 mutex_lock(&osdc->request_mutex);
904 if (req->r_linger) {
905 __unregister_linger_request(osdc, req);
906 ceph_osdc_put_request(req);
907 }
908 mutex_unlock(&osdc->request_mutex);
909}
910EXPORT_SYMBOL(ceph_osdc_unregister_linger_request);
911
912void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
913 struct ceph_osd_request *req)
914{
915 if (!req->r_linger) {
916 dout("set_request_linger %p\n", req);
917 req->r_linger = 1;
918 /*
919 * caller is now responsible for calling
920 * unregister_linger_request
921 */
922 ceph_osdc_get_request(req);
923 }
924}
925EXPORT_SYMBOL(ceph_osdc_set_request_linger);
926
Sage Weilf24e9982009-10-06 11:31:10 -0700927/*
928 * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
929 * (as needed), and set the request r_osd appropriately. If there is
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300930 * no up osd, set r_osd to NULL. Move the request to the appropriate list
Sage Weil6f6c7002011-01-17 20:34:08 -0800931 * (unsent, homeless) or leave on in-flight lru.
Sage Weilf24e9982009-10-06 11:31:10 -0700932 *
933 * Return 0 if unchanged, 1 if changed, or negative on error.
934 *
935 * Caller should hold map_sem for read and request_mutex.
936 */
Sage Weil6f6c7002011-01-17 20:34:08 -0800937static int __map_request(struct ceph_osd_client *osdc,
Sage Weil38d64532011-10-14 13:33:55 -0700938 struct ceph_osd_request *req, int force_resend)
Sage Weilf24e9982009-10-06 11:31:10 -0700939{
940 struct ceph_osd_request_head *reqhead = req->r_request->front.iov_base;
Sage Weil51042122009-11-04 11:39:12 -0800941 struct ceph_pg pgid;
Sage Weild85b7052010-05-10 10:24:48 -0700942 int acting[CEPH_PG_MAX_SIZE];
943 int o = -1, num = 0;
Sage Weilf24e9982009-10-06 11:31:10 -0700944 int err;
Sage Weilf24e9982009-10-06 11:31:10 -0700945
Sage Weil6f6c7002011-01-17 20:34:08 -0800946 dout("map_request %p tid %lld\n", req, req->r_tid);
Sage Weilf24e9982009-10-06 11:31:10 -0700947 err = ceph_calc_object_layout(&reqhead->layout, req->r_oid,
948 &req->r_file_layout, osdc->osdmap);
Sage Weil6f6c7002011-01-17 20:34:08 -0800949 if (err) {
950 list_move(&req->r_req_lru_item, &osdc->req_notarget);
Sage Weilf24e9982009-10-06 11:31:10 -0700951 return err;
Sage Weil6f6c7002011-01-17 20:34:08 -0800952 }
Sage Weil51042122009-11-04 11:39:12 -0800953 pgid = reqhead->layout.ol_pgid;
Sage Weil7740a422010-01-08 15:58:25 -0800954 req->r_pgid = pgid;
955
Sage Weild85b7052010-05-10 10:24:48 -0700956 err = ceph_calc_pg_acting(osdc->osdmap, pgid, acting);
957 if (err > 0) {
958 o = acting[0];
959 num = err;
960 }
Sage Weilf24e9982009-10-06 11:31:10 -0700961
Sage Weil38d64532011-10-14 13:33:55 -0700962 if ((!force_resend &&
963 req->r_osd && req->r_osd->o_osd == o &&
Sage Weild85b7052010-05-10 10:24:48 -0700964 req->r_sent >= req->r_osd->o_incarnation &&
965 req->r_num_pg_osds == num &&
966 memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) ||
Sage Weilf24e9982009-10-06 11:31:10 -0700967 (req->r_osd == NULL && o == -1))
968 return 0; /* no change */
969
Sage Weil6f6c7002011-01-17 20:34:08 -0800970 dout("map_request tid %llu pgid %d.%x osd%d (was osd%d)\n",
Sage Weil51042122009-11-04 11:39:12 -0800971 req->r_tid, le32_to_cpu(pgid.pool), le16_to_cpu(pgid.ps), o,
Sage Weilf24e9982009-10-06 11:31:10 -0700972 req->r_osd ? req->r_osd->o_osd : -1);
973
Sage Weild85b7052010-05-10 10:24:48 -0700974 /* record full pg acting set */
975 memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num);
976 req->r_num_pg_osds = num;
977
Sage Weilf24e9982009-10-06 11:31:10 -0700978 if (req->r_osd) {
979 __cancel_request(req);
980 list_del_init(&req->r_osd_item);
Sage Weilf24e9982009-10-06 11:31:10 -0700981 req->r_osd = NULL;
982 }
983
984 req->r_osd = __lookup_osd(osdc, o);
985 if (!req->r_osd && o >= 0) {
Sage Weilc99eb1c2010-02-26 09:37:33 -0800986 err = -ENOMEM;
Alex Eldere10006f2012-05-26 23:26:43 -0500987 req->r_osd = create_osd(osdc, o);
Sage Weil6f6c7002011-01-17 20:34:08 -0800988 if (!req->r_osd) {
989 list_move(&req->r_req_lru_item, &osdc->req_notarget);
Sage Weilc99eb1c2010-02-26 09:37:33 -0800990 goto out;
Sage Weil6f6c7002011-01-17 20:34:08 -0800991 }
Sage Weilf24e9982009-10-06 11:31:10 -0700992
Sage Weil6f6c7002011-01-17 20:34:08 -0800993 dout("map_request osd %p is osd%d\n", req->r_osd, o);
Sage Weilf24e9982009-10-06 11:31:10 -0700994 __insert_osd(osdc, req->r_osd);
995
Sage Weilb7a9e5d2012-06-27 12:24:08 -0700996 ceph_con_open(&req->r_osd->o_con,
997 CEPH_ENTITY_TYPE_OSD, o,
998 &osdc->osdmap->osd_addr[o]);
Sage Weilf24e9982009-10-06 11:31:10 -0700999 }
1000
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001001 if (req->r_osd) {
1002 __remove_osd_from_lru(req->r_osd);
Sage Weilf24e9982009-10-06 11:31:10 -07001003 list_add(&req->r_osd_item, &req->r_osd->o_requests);
Sage Weil6f6c7002011-01-17 20:34:08 -08001004 list_move(&req->r_req_lru_item, &osdc->req_unsent);
1005 } else {
1006 list_move(&req->r_req_lru_item, &osdc->req_notarget);
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001007 }
Sage Weild85b7052010-05-10 10:24:48 -07001008 err = 1; /* osd or pg changed */
Sage Weilf24e9982009-10-06 11:31:10 -07001009
1010out:
Sage Weilf24e9982009-10-06 11:31:10 -07001011 return err;
1012}
1013
1014/*
1015 * caller should hold map_sem (for read) and request_mutex
1016 */
Sage Weil56e925b2012-01-03 12:34:34 -08001017static void __send_request(struct ceph_osd_client *osdc,
1018 struct ceph_osd_request *req)
Sage Weilf24e9982009-10-06 11:31:10 -07001019{
1020 struct ceph_osd_request_head *reqhead;
Sage Weilf24e9982009-10-06 11:31:10 -07001021
1022 dout("send_request %p tid %llu to osd%d flags %d\n",
1023 req, req->r_tid, req->r_osd->o_osd, req->r_flags);
1024
1025 reqhead = req->r_request->front.iov_base;
1026 reqhead->osdmap_epoch = cpu_to_le32(osdc->osdmap->epoch);
1027 reqhead->flags |= cpu_to_le32(req->r_flags); /* e.g., RETRY */
1028 reqhead->reassert_version = req->r_reassert_version;
1029
Sage Weil3dd72fc2010-03-22 14:42:30 -07001030 req->r_stamp = jiffies;
Henry C Chang07a27e22010-08-22 21:34:27 -07001031 list_move_tail(&req->r_req_lru_item, &osdc->req_lru);
Sage Weilf24e9982009-10-06 11:31:10 -07001032
1033 ceph_msg_get(req->r_request); /* send consumes a ref */
1034 ceph_con_send(&req->r_osd->o_con, req->r_request);
1035 req->r_sent = req->r_osd->o_incarnation;
Sage Weilf24e9982009-10-06 11:31:10 -07001036}
1037
1038/*
Sage Weil6f6c7002011-01-17 20:34:08 -08001039 * Send any requests in the queue (req_unsent).
1040 */
Alex Elderf9d25192013-02-15 11:42:29 -06001041static void __send_queued(struct ceph_osd_client *osdc)
Sage Weil6f6c7002011-01-17 20:34:08 -08001042{
1043 struct ceph_osd_request *req, *tmp;
1044
Alex Elderf9d25192013-02-15 11:42:29 -06001045 dout("__send_queued\n");
1046 list_for_each_entry_safe(req, tmp, &osdc->req_unsent, r_req_lru_item)
Sage Weil6f6c7002011-01-17 20:34:08 -08001047 __send_request(osdc, req);
Sage Weil6f6c7002011-01-17 20:34:08 -08001048}
1049
1050/*
Sage Weilf24e9982009-10-06 11:31:10 -07001051 * Timeout callback, called every N seconds when 1 or more osd
1052 * requests has been active for more than N seconds. When this
1053 * happens, we ping all OSDs with requests who have timed out to
1054 * ensure any communications channel reset is detected. Reset the
1055 * request timeouts another N seconds in the future as we go.
1056 * Reschedule the timeout event another N seconds in future (unless
1057 * there are no open requests).
1058 */
1059static void handle_timeout(struct work_struct *work)
1060{
1061 struct ceph_osd_client *osdc =
1062 container_of(work, struct ceph_osd_client, timeout_work.work);
Sage Weil83aff952012-11-28 12:28:24 -08001063 struct ceph_osd_request *req;
Sage Weilf24e9982009-10-06 11:31:10 -07001064 struct ceph_osd *osd;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001065 unsigned long keepalive =
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001066 osdc->client->options->osd_keepalive_timeout * HZ;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001067 struct list_head slow_osds;
Sage Weilf24e9982009-10-06 11:31:10 -07001068 dout("timeout\n");
1069 down_read(&osdc->map_sem);
1070
1071 ceph_monc_request_next_osdmap(&osdc->client->monc);
1072
1073 mutex_lock(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -07001074
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001075 /*
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001076 * ping osds that are a bit slow. this ensures that if there
1077 * is a break in the TCP connection we will notice, and reopen
1078 * a connection with that osd (from the fault callback).
1079 */
1080 INIT_LIST_HEAD(&slow_osds);
1081 list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) {
Sage Weil3dd72fc2010-03-22 14:42:30 -07001082 if (time_before(jiffies, req->r_stamp + keepalive))
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001083 break;
1084
1085 osd = req->r_osd;
1086 BUG_ON(!osd);
1087 dout(" tid %llu is slow, will send keepalive on osd%d\n",
Sage Weilf24e9982009-10-06 11:31:10 -07001088 req->r_tid, osd->o_osd);
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001089 list_move_tail(&osd->o_keepalive_item, &slow_osds);
1090 }
1091 while (!list_empty(&slow_osds)) {
1092 osd = list_entry(slow_osds.next, struct ceph_osd,
1093 o_keepalive_item);
1094 list_del_init(&osd->o_keepalive_item);
Sage Weilf24e9982009-10-06 11:31:10 -07001095 ceph_con_keepalive(&osd->o_con);
1096 }
1097
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001098 __schedule_osd_timeout(osdc);
Alex Elderf9d25192013-02-15 11:42:29 -06001099 __send_queued(osdc);
Sage Weilf24e9982009-10-06 11:31:10 -07001100 mutex_unlock(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -07001101 up_read(&osdc->map_sem);
1102}
1103
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001104static void handle_osds_timeout(struct work_struct *work)
1105{
1106 struct ceph_osd_client *osdc =
1107 container_of(work, struct ceph_osd_client,
1108 osds_timeout_work.work);
1109 unsigned long delay =
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001110 osdc->client->options->osd_idle_ttl * HZ >> 2;
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001111
1112 dout("osds timeout\n");
1113 down_read(&osdc->map_sem);
Sage Weilaca420b2011-08-31 14:45:53 -07001114 remove_old_osds(osdc);
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001115 up_read(&osdc->map_sem);
1116
1117 schedule_delayed_work(&osdc->osds_timeout_work,
1118 round_jiffies_relative(delay));
1119}
1120
Sage Weil25845472011-06-03 09:37:09 -07001121static void complete_request(struct ceph_osd_request *req)
1122{
1123 if (req->r_safe_callback)
1124 req->r_safe_callback(req, NULL);
1125 complete_all(&req->r_safe_completion); /* fsync waiter */
1126}
1127
Sage Weilf24e9982009-10-06 11:31:10 -07001128/*
1129 * handle osd op reply. either call the callback if it is specified,
1130 * or do the completion to wake up the waiting thread.
1131 */
Sage Weil350b1c32009-12-22 10:45:45 -08001132static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
1133 struct ceph_connection *con)
Sage Weilf24e9982009-10-06 11:31:10 -07001134{
1135 struct ceph_osd_reply_head *rhead = msg->front.iov_base;
1136 struct ceph_osd_request *req;
1137 u64 tid;
1138 int numops, object_len, flags;
Sage Weil0ceed5d2010-05-11 09:53:18 -07001139 s32 result;
Sage Weilf24e9982009-10-06 11:31:10 -07001140
Sage Weil6df058c2009-12-22 11:24:33 -08001141 tid = le64_to_cpu(msg->hdr.tid);
Sage Weilf24e9982009-10-06 11:31:10 -07001142 if (msg->front.iov_len < sizeof(*rhead))
1143 goto bad;
Sage Weilf24e9982009-10-06 11:31:10 -07001144 numops = le32_to_cpu(rhead->num_ops);
1145 object_len = le32_to_cpu(rhead->object_len);
Sage Weil0ceed5d2010-05-11 09:53:18 -07001146 result = le32_to_cpu(rhead->result);
Sage Weilf24e9982009-10-06 11:31:10 -07001147 if (msg->front.iov_len != sizeof(*rhead) + object_len +
1148 numops * sizeof(struct ceph_osd_op))
1149 goto bad;
Sage Weil0ceed5d2010-05-11 09:53:18 -07001150 dout("handle_reply %p tid %llu result %d\n", msg, tid, (int)result);
Sage Weilf24e9982009-10-06 11:31:10 -07001151 /* lookup */
1152 mutex_lock(&osdc->request_mutex);
1153 req = __lookup_request(osdc, tid);
1154 if (req == NULL) {
1155 dout("handle_reply tid %llu dne\n", tid);
1156 mutex_unlock(&osdc->request_mutex);
1157 return;
1158 }
1159 ceph_osdc_get_request(req);
1160 flags = le32_to_cpu(rhead->flags);
1161
Sage Weil350b1c32009-12-22 10:45:45 -08001162 /*
Yehuda Sadeh0d59ab82010-01-13 17:03:23 -08001163 * if this connection filled our message, drop our reference now, to
Sage Weil350b1c32009-12-22 10:45:45 -08001164 * avoid a (safe but slower) revoke later.
1165 */
Yehuda Sadeh0d59ab82010-01-13 17:03:23 -08001166 if (req->r_con_filling_msg == con && req->r_reply == msg) {
Sage Weilc16e7862010-03-01 13:02:00 -08001167 dout(" dropping con_filling_msg ref %p\n", con);
Yehuda Sadeh0d59ab82010-01-13 17:03:23 -08001168 req->r_con_filling_msg = NULL;
Sage Weil0d477662012-05-31 20:22:18 -07001169 con->ops->put(con);
Sage Weil350b1c32009-12-22 10:45:45 -08001170 }
1171
Sage Weilf24e9982009-10-06 11:31:10 -07001172 if (!req->r_got_reply) {
Eric Dumazet95c96172012-04-15 05:58:06 +00001173 unsigned int bytes;
Sage Weilf24e9982009-10-06 11:31:10 -07001174
1175 req->r_result = le32_to_cpu(rhead->result);
1176 bytes = le32_to_cpu(msg->hdr.data_len);
1177 dout("handle_reply result %d bytes %d\n", req->r_result,
1178 bytes);
1179 if (req->r_result == 0)
1180 req->r_result = bytes;
1181
1182 /* in case this is a write and we need to replay, */
1183 req->r_reassert_version = rhead->reassert_version;
1184
1185 req->r_got_reply = 1;
1186 } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) {
1187 dout("handle_reply tid %llu dup ack\n", tid);
Sage Weil34b43a52009-12-01 12:23:54 -08001188 mutex_unlock(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -07001189 goto done;
1190 }
1191
1192 dout("handle_reply tid %llu flags %d\n", tid, flags);
1193
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001194 if (req->r_linger && (flags & CEPH_OSD_FLAG_ONDISK))
1195 __register_linger_request(osdc, req);
1196
Sage Weilf24e9982009-10-06 11:31:10 -07001197 /* either this is a read, or we got the safe response */
Sage Weil0ceed5d2010-05-11 09:53:18 -07001198 if (result < 0 ||
1199 (flags & CEPH_OSD_FLAG_ONDISK) ||
Sage Weilf24e9982009-10-06 11:31:10 -07001200 ((flags & CEPH_OSD_FLAG_WRITE) == 0))
1201 __unregister_request(osdc, req);
1202
1203 mutex_unlock(&osdc->request_mutex);
1204
1205 if (req->r_callback)
1206 req->r_callback(req, msg);
1207 else
Yehuda Sadeh03066f22010-07-27 13:11:08 -07001208 complete_all(&req->r_completion);
Sage Weilf24e9982009-10-06 11:31:10 -07001209
Sage Weil25845472011-06-03 09:37:09 -07001210 if (flags & CEPH_OSD_FLAG_ONDISK)
1211 complete_request(req);
Sage Weilf24e9982009-10-06 11:31:10 -07001212
1213done:
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001214 dout("req=%p req->r_linger=%d\n", req, req->r_linger);
Sage Weilf24e9982009-10-06 11:31:10 -07001215 ceph_osdc_put_request(req);
1216 return;
1217
1218bad:
1219 pr_err("corrupt osd_op_reply got %d %d expected %d\n",
1220 (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len),
1221 (int)sizeof(*rhead));
Sage Weil9ec7cab2009-12-14 15:13:47 -08001222 ceph_msg_dump(msg);
Sage Weilf24e9982009-10-06 11:31:10 -07001223}
1224
Sage Weil6f6c7002011-01-17 20:34:08 -08001225static void reset_changed_osds(struct ceph_osd_client *osdc)
Sage Weilf24e9982009-10-06 11:31:10 -07001226{
Sage Weilf24e9982009-10-06 11:31:10 -07001227 struct rb_node *p, *n;
Sage Weilf24e9982009-10-06 11:31:10 -07001228
Sage Weil6f6c7002011-01-17 20:34:08 -08001229 for (p = rb_first(&osdc->osds); p; p = n) {
1230 struct ceph_osd *osd = rb_entry(p, struct ceph_osd, o_node);
Sage Weilf24e9982009-10-06 11:31:10 -07001231
Sage Weil6f6c7002011-01-17 20:34:08 -08001232 n = rb_next(p);
1233 if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) ||
1234 memcmp(&osd->o_con.peer_addr,
1235 ceph_osd_addr(osdc->osdmap,
1236 osd->o_osd),
1237 sizeof(struct ceph_entity_addr)) != 0)
1238 __reset_osd(osdc, osd);
Sage Weilf24e9982009-10-06 11:31:10 -07001239 }
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001240}
1241
1242/*
Sage Weil6f6c7002011-01-17 20:34:08 -08001243 * Requeue requests whose mapping to an OSD has changed. If requests map to
1244 * no osd, request a new map.
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001245 *
Alex Eldere6d50f62012-12-26 14:31:40 -06001246 * Caller should hold map_sem for read.
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001247 */
Sage Weil38d64532011-10-14 13:33:55 -07001248static void kick_requests(struct ceph_osd_client *osdc, int force_resend)
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001249{
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001250 struct ceph_osd_request *req, *nreq;
Sage Weil6f6c7002011-01-17 20:34:08 -08001251 struct rb_node *p;
1252 int needmap = 0;
1253 int err;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001254
Sage Weil38d64532011-10-14 13:33:55 -07001255 dout("kick_requests %s\n", force_resend ? " (force resend)" : "");
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001256 mutex_lock(&osdc->request_mutex);
Sage Weil6194ea82012-07-30 16:19:28 -07001257 for (p = rb_first(&osdc->requests); p; ) {
Sage Weil6f6c7002011-01-17 20:34:08 -08001258 req = rb_entry(p, struct ceph_osd_request, r_node);
Sage Weil6194ea82012-07-30 16:19:28 -07001259 p = rb_next(p);
Alex Elderab60b162012-12-19 15:52:36 -06001260
1261 /*
1262 * For linger requests that have not yet been
1263 * registered, move them to the linger list; they'll
1264 * be sent to the osd in the loop below. Unregister
1265 * the request before re-registering it as a linger
1266 * request to ensure the __map_request() below
1267 * will decide it needs to be sent.
1268 */
1269 if (req->r_linger && list_empty(&req->r_linger_item)) {
1270 dout("%p tid %llu restart on osd%d\n",
1271 req, req->r_tid,
1272 req->r_osd ? req->r_osd->o_osd : -1);
1273 __unregister_request(osdc, req);
1274 __register_linger_request(osdc, req);
1275 continue;
1276 }
1277
Sage Weil38d64532011-10-14 13:33:55 -07001278 err = __map_request(osdc, req, force_resend);
Sage Weil6f6c7002011-01-17 20:34:08 -08001279 if (err < 0)
1280 continue; /* error */
1281 if (req->r_osd == NULL) {
1282 dout("%p tid %llu maps to no osd\n", req, req->r_tid);
1283 needmap++; /* request a newer map */
1284 } else if (err > 0) {
Sage Weil6194ea82012-07-30 16:19:28 -07001285 if (!req->r_linger) {
1286 dout("%p tid %llu requeued on osd%d\n", req,
1287 req->r_tid,
1288 req->r_osd ? req->r_osd->o_osd : -1);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001289 req->r_flags |= CEPH_OSD_FLAG_RETRY;
Sage Weil6194ea82012-07-30 16:19:28 -07001290 }
1291 }
Sage Weil6f6c7002011-01-17 20:34:08 -08001292 }
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001293
1294 list_for_each_entry_safe(req, nreq, &osdc->req_linger,
1295 r_linger_item) {
1296 dout("linger req=%p req->r_osd=%p\n", req, req->r_osd);
1297
Sage Weil38d64532011-10-14 13:33:55 -07001298 err = __map_request(osdc, req, force_resend);
Alex Elderab60b162012-12-19 15:52:36 -06001299 dout("__map_request returned %d\n", err);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001300 if (err == 0)
1301 continue; /* no change and no osd was specified */
1302 if (err < 0)
1303 continue; /* hrm! */
1304 if (req->r_osd == NULL) {
1305 dout("tid %llu maps to no valid osd\n", req->r_tid);
1306 needmap++; /* request a newer map */
1307 continue;
1308 }
1309
1310 dout("kicking lingering %p tid %llu osd%d\n", req, req->r_tid,
1311 req->r_osd ? req->r_osd->o_osd : -1);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001312 __register_request(osdc, req);
Alex Elderc89ce052012-12-06 07:22:04 -06001313 __unregister_linger_request(osdc, req);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001314 }
Sage Weilf24e9982009-10-06 11:31:10 -07001315 mutex_unlock(&osdc->request_mutex);
1316
1317 if (needmap) {
1318 dout("%d requests for down osds, need new map\n", needmap);
1319 ceph_monc_request_next_osdmap(&osdc->client->monc);
1320 }
Alex Eldere6d50f62012-12-26 14:31:40 -06001321 reset_changed_osds(osdc);
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001322}
Sage Weil6f6c7002011-01-17 20:34:08 -08001323
1324
Sage Weilf24e9982009-10-06 11:31:10 -07001325/*
1326 * Process updated osd map.
1327 *
1328 * The message contains any number of incremental and full maps, normally
1329 * indicating some sort of topology change in the cluster. Kick requests
1330 * off to different OSDs as needed.
1331 */
1332void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
1333{
1334 void *p, *end, *next;
1335 u32 nr_maps, maplen;
1336 u32 epoch;
1337 struct ceph_osdmap *newmap = NULL, *oldmap;
1338 int err;
1339 struct ceph_fsid fsid;
1340
1341 dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0);
1342 p = msg->front.iov_base;
1343 end = p + msg->front.iov_len;
1344
1345 /* verify fsid */
1346 ceph_decode_need(&p, end, sizeof(fsid), bad);
1347 ceph_decode_copy(&p, &fsid, sizeof(fsid));
Sage Weil07433042009-11-18 16:50:41 -08001348 if (ceph_check_fsid(osdc->client, &fsid) < 0)
1349 return;
Sage Weilf24e9982009-10-06 11:31:10 -07001350
1351 down_write(&osdc->map_sem);
1352
1353 /* incremental maps */
1354 ceph_decode_32_safe(&p, end, nr_maps, bad);
1355 dout(" %d inc maps\n", nr_maps);
1356 while (nr_maps > 0) {
1357 ceph_decode_need(&p, end, 2*sizeof(u32), bad);
Sage Weilc89136e2009-10-14 09:59:09 -07001358 epoch = ceph_decode_32(&p);
1359 maplen = ceph_decode_32(&p);
Sage Weilf24e9982009-10-06 11:31:10 -07001360 ceph_decode_need(&p, end, maplen, bad);
1361 next = p + maplen;
1362 if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) {
1363 dout("applying incremental map %u len %d\n",
1364 epoch, maplen);
1365 newmap = osdmap_apply_incremental(&p, next,
1366 osdc->osdmap,
Alex Elder15d98822012-05-26 23:26:43 -05001367 &osdc->client->msgr);
Sage Weilf24e9982009-10-06 11:31:10 -07001368 if (IS_ERR(newmap)) {
1369 err = PTR_ERR(newmap);
1370 goto bad;
1371 }
Sage Weil30dc6382009-12-21 14:49:37 -08001372 BUG_ON(!newmap);
Sage Weilf24e9982009-10-06 11:31:10 -07001373 if (newmap != osdc->osdmap) {
1374 ceph_osdmap_destroy(osdc->osdmap);
1375 osdc->osdmap = newmap;
1376 }
Sage Weil38d64532011-10-14 13:33:55 -07001377 kick_requests(osdc, 0);
Sage Weilf24e9982009-10-06 11:31:10 -07001378 } else {
1379 dout("ignoring incremental map %u len %d\n",
1380 epoch, maplen);
1381 }
1382 p = next;
1383 nr_maps--;
1384 }
1385 if (newmap)
1386 goto done;
1387
1388 /* full maps */
1389 ceph_decode_32_safe(&p, end, nr_maps, bad);
1390 dout(" %d full maps\n", nr_maps);
1391 while (nr_maps) {
1392 ceph_decode_need(&p, end, 2*sizeof(u32), bad);
Sage Weilc89136e2009-10-14 09:59:09 -07001393 epoch = ceph_decode_32(&p);
1394 maplen = ceph_decode_32(&p);
Sage Weilf24e9982009-10-06 11:31:10 -07001395 ceph_decode_need(&p, end, maplen, bad);
1396 if (nr_maps > 1) {
1397 dout("skipping non-latest full map %u len %d\n",
1398 epoch, maplen);
1399 } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) {
1400 dout("skipping full map %u len %d, "
1401 "older than our %u\n", epoch, maplen,
1402 osdc->osdmap->epoch);
1403 } else {
Sage Weil38d64532011-10-14 13:33:55 -07001404 int skipped_map = 0;
1405
Sage Weilf24e9982009-10-06 11:31:10 -07001406 dout("taking full map %u len %d\n", epoch, maplen);
1407 newmap = osdmap_decode(&p, p+maplen);
1408 if (IS_ERR(newmap)) {
1409 err = PTR_ERR(newmap);
1410 goto bad;
1411 }
Sage Weil30dc6382009-12-21 14:49:37 -08001412 BUG_ON(!newmap);
Sage Weilf24e9982009-10-06 11:31:10 -07001413 oldmap = osdc->osdmap;
1414 osdc->osdmap = newmap;
Sage Weil38d64532011-10-14 13:33:55 -07001415 if (oldmap) {
1416 if (oldmap->epoch + 1 < newmap->epoch)
1417 skipped_map = 1;
Sage Weilf24e9982009-10-06 11:31:10 -07001418 ceph_osdmap_destroy(oldmap);
Sage Weil38d64532011-10-14 13:33:55 -07001419 }
1420 kick_requests(osdc, skipped_map);
Sage Weilf24e9982009-10-06 11:31:10 -07001421 }
1422 p += maplen;
1423 nr_maps--;
1424 }
1425
1426done:
1427 downgrade_write(&osdc->map_sem);
1428 ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch);
Sage Weilcd634fb2011-05-12 09:29:18 -07001429
1430 /*
1431 * subscribe to subsequent osdmap updates if full to ensure
1432 * we find out when we are no longer full and stop returning
1433 * ENOSPC.
1434 */
1435 if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL))
1436 ceph_monc_request_next_osdmap(&osdc->client->monc);
1437
Alex Elderf9d25192013-02-15 11:42:29 -06001438 mutex_lock(&osdc->request_mutex);
1439 __send_queued(osdc);
1440 mutex_unlock(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -07001441 up_read(&osdc->map_sem);
Yehuda Sadeh03066f22010-07-27 13:11:08 -07001442 wake_up_all(&osdc->client->auth_wq);
Sage Weilf24e9982009-10-06 11:31:10 -07001443 return;
1444
1445bad:
1446 pr_err("osdc handle_map corrupt msg\n");
Sage Weil9ec7cab2009-12-14 15:13:47 -08001447 ceph_msg_dump(msg);
Sage Weilf24e9982009-10-06 11:31:10 -07001448 up_write(&osdc->map_sem);
1449 return;
1450}
1451
Sage Weilf24e9982009-10-06 11:31:10 -07001452/*
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001453 * watch/notify callback event infrastructure
1454 *
1455 * These callbacks are used both for watch and notify operations.
1456 */
1457static void __release_event(struct kref *kref)
1458{
1459 struct ceph_osd_event *event =
1460 container_of(kref, struct ceph_osd_event, kref);
1461
1462 dout("__release_event %p\n", event);
1463 kfree(event);
1464}
1465
1466static void get_event(struct ceph_osd_event *event)
1467{
1468 kref_get(&event->kref);
1469}
1470
1471void ceph_osdc_put_event(struct ceph_osd_event *event)
1472{
1473 kref_put(&event->kref, __release_event);
1474}
1475EXPORT_SYMBOL(ceph_osdc_put_event);
1476
1477static void __insert_event(struct ceph_osd_client *osdc,
1478 struct ceph_osd_event *new)
1479{
1480 struct rb_node **p = &osdc->event_tree.rb_node;
1481 struct rb_node *parent = NULL;
1482 struct ceph_osd_event *event = NULL;
1483
1484 while (*p) {
1485 parent = *p;
1486 event = rb_entry(parent, struct ceph_osd_event, node);
1487 if (new->cookie < event->cookie)
1488 p = &(*p)->rb_left;
1489 else if (new->cookie > event->cookie)
1490 p = &(*p)->rb_right;
1491 else
1492 BUG();
1493 }
1494
1495 rb_link_node(&new->node, parent, p);
1496 rb_insert_color(&new->node, &osdc->event_tree);
1497}
1498
1499static struct ceph_osd_event *__find_event(struct ceph_osd_client *osdc,
1500 u64 cookie)
1501{
1502 struct rb_node **p = &osdc->event_tree.rb_node;
1503 struct rb_node *parent = NULL;
1504 struct ceph_osd_event *event = NULL;
1505
1506 while (*p) {
1507 parent = *p;
1508 event = rb_entry(parent, struct ceph_osd_event, node);
1509 if (cookie < event->cookie)
1510 p = &(*p)->rb_left;
1511 else if (cookie > event->cookie)
1512 p = &(*p)->rb_right;
1513 else
1514 return event;
1515 }
1516 return NULL;
1517}
1518
1519static void __remove_event(struct ceph_osd_event *event)
1520{
1521 struct ceph_osd_client *osdc = event->osdc;
1522
1523 if (!RB_EMPTY_NODE(&event->node)) {
1524 dout("__remove_event removed %p\n", event);
1525 rb_erase(&event->node, &osdc->event_tree);
1526 ceph_osdc_put_event(event);
1527 } else {
1528 dout("__remove_event didn't remove %p\n", event);
1529 }
1530}
1531
1532int ceph_osdc_create_event(struct ceph_osd_client *osdc,
1533 void (*event_cb)(u64, u64, u8, void *),
Alex Elder3c663bb2013-02-15 11:42:30 -06001534 void *data, struct ceph_osd_event **pevent)
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001535{
1536 struct ceph_osd_event *event;
1537
1538 event = kmalloc(sizeof(*event), GFP_NOIO);
1539 if (!event)
1540 return -ENOMEM;
1541
1542 dout("create_event %p\n", event);
1543 event->cb = event_cb;
Alex Elder3c663bb2013-02-15 11:42:30 -06001544 event->one_shot = 0;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001545 event->data = data;
1546 event->osdc = osdc;
1547 INIT_LIST_HEAD(&event->osd_node);
Alex Elder3ee52342012-12-17 12:23:48 -06001548 RB_CLEAR_NODE(&event->node);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001549 kref_init(&event->kref); /* one ref for us */
1550 kref_get(&event->kref); /* one ref for the caller */
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001551
1552 spin_lock(&osdc->event_lock);
1553 event->cookie = ++osdc->event_count;
1554 __insert_event(osdc, event);
1555 spin_unlock(&osdc->event_lock);
1556
1557 *pevent = event;
1558 return 0;
1559}
1560EXPORT_SYMBOL(ceph_osdc_create_event);
1561
1562void ceph_osdc_cancel_event(struct ceph_osd_event *event)
1563{
1564 struct ceph_osd_client *osdc = event->osdc;
1565
1566 dout("cancel_event %p\n", event);
1567 spin_lock(&osdc->event_lock);
1568 __remove_event(event);
1569 spin_unlock(&osdc->event_lock);
1570 ceph_osdc_put_event(event); /* caller's */
1571}
1572EXPORT_SYMBOL(ceph_osdc_cancel_event);
1573
1574
1575static void do_event_work(struct work_struct *work)
1576{
1577 struct ceph_osd_event_work *event_work =
1578 container_of(work, struct ceph_osd_event_work, work);
1579 struct ceph_osd_event *event = event_work->event;
1580 u64 ver = event_work->ver;
1581 u64 notify_id = event_work->notify_id;
1582 u8 opcode = event_work->opcode;
1583
1584 dout("do_event_work completing %p\n", event);
1585 event->cb(ver, notify_id, opcode, event->data);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001586 dout("do_event_work completed %p\n", event);
1587 ceph_osdc_put_event(event);
1588 kfree(event_work);
1589}
1590
1591
1592/*
1593 * Process osd watch notifications
1594 */
Alex Elder3c663bb2013-02-15 11:42:30 -06001595static void handle_watch_notify(struct ceph_osd_client *osdc,
1596 struct ceph_msg *msg)
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001597{
1598 void *p, *end;
1599 u8 proto_ver;
1600 u64 cookie, ver, notify_id;
1601 u8 opcode;
1602 struct ceph_osd_event *event;
1603 struct ceph_osd_event_work *event_work;
1604
1605 p = msg->front.iov_base;
1606 end = p + msg->front.iov_len;
1607
1608 ceph_decode_8_safe(&p, end, proto_ver, bad);
1609 ceph_decode_8_safe(&p, end, opcode, bad);
1610 ceph_decode_64_safe(&p, end, cookie, bad);
1611 ceph_decode_64_safe(&p, end, ver, bad);
1612 ceph_decode_64_safe(&p, end, notify_id, bad);
1613
1614 spin_lock(&osdc->event_lock);
1615 event = __find_event(osdc, cookie);
1616 if (event) {
Alex Elder3c663bb2013-02-15 11:42:30 -06001617 BUG_ON(event->one_shot);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001618 get_event(event);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001619 }
1620 spin_unlock(&osdc->event_lock);
1621 dout("handle_watch_notify cookie %lld ver %lld event %p\n",
1622 cookie, ver, event);
1623 if (event) {
1624 event_work = kmalloc(sizeof(*event_work), GFP_NOIO);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001625 if (!event_work) {
1626 dout("ERROR: could not allocate event_work\n");
1627 goto done_err;
1628 }
Mariusz Kozlowski6b0ae402011-03-26 19:29:34 +01001629 INIT_WORK(&event_work->work, do_event_work);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001630 event_work->event = event;
1631 event_work->ver = ver;
1632 event_work->notify_id = notify_id;
1633 event_work->opcode = opcode;
1634 if (!queue_work(osdc->notify_wq, &event_work->work)) {
1635 dout("WARNING: failed to queue notify event work\n");
1636 goto done_err;
1637 }
1638 }
1639
1640 return;
1641
1642done_err:
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001643 ceph_osdc_put_event(event);
1644 return;
1645
1646bad:
1647 pr_err("osdc handle_watch_notify corrupt msg\n");
1648 return;
1649}
1650
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001651/*
Sage Weilf24e9982009-10-06 11:31:10 -07001652 * Register request, send initial attempt.
1653 */
1654int ceph_osdc_start_request(struct ceph_osd_client *osdc,
1655 struct ceph_osd_request *req,
1656 bool nofail)
1657{
Sage Weilc1ea8822009-10-08 16:55:47 -07001658 int rc = 0;
Sage Weilf24e9982009-10-06 11:31:10 -07001659
1660 req->r_request->pages = req->r_pages;
1661 req->r_request->nr_pages = req->r_num_pages;
Yehuda Sadeh68b44762010-04-06 15:01:27 -07001662#ifdef CONFIG_BLOCK
1663 req->r_request->bio = req->r_bio;
1664#endif
Alex Elderc8858372012-11-13 21:11:15 -06001665 req->r_request->trail = &req->r_trail;
Sage Weilf24e9982009-10-06 11:31:10 -07001666
1667 register_request(osdc, req);
1668
1669 down_read(&osdc->map_sem);
1670 mutex_lock(&osdc->request_mutex);
Sage Weilc1ea8822009-10-08 16:55:47 -07001671 /*
1672 * a racing kick_requests() may have sent the message for us
1673 * while we dropped request_mutex above, so only send now if
1674 * the request still han't been touched yet.
1675 */
1676 if (req->r_sent == 0) {
Sage Weil38d64532011-10-14 13:33:55 -07001677 rc = __map_request(osdc, req, 0);
Sage Weil9d6fcb02011-05-12 15:48:16 -07001678 if (rc < 0) {
1679 if (nofail) {
1680 dout("osdc_start_request failed map, "
1681 " will retry %lld\n", req->r_tid);
1682 rc = 0;
1683 }
Dan Carpenter234af26f2011-03-29 06:25:59 +03001684 goto out_unlock;
Sage Weil9d6fcb02011-05-12 15:48:16 -07001685 }
Sage Weil6f6c7002011-01-17 20:34:08 -08001686 if (req->r_osd == NULL) {
1687 dout("send_request %p no up osds in pg\n", req);
1688 ceph_monc_request_next_osdmap(&osdc->client->monc);
1689 } else {
Sage Weil56e925b2012-01-03 12:34:34 -08001690 __send_request(osdc, req);
Sage Weilf24e9982009-10-06 11:31:10 -07001691 }
Sage Weil56e925b2012-01-03 12:34:34 -08001692 rc = 0;
Sage Weilf24e9982009-10-06 11:31:10 -07001693 }
Dan Carpenter234af26f2011-03-29 06:25:59 +03001694
1695out_unlock:
Sage Weilf24e9982009-10-06 11:31:10 -07001696 mutex_unlock(&osdc->request_mutex);
1697 up_read(&osdc->map_sem);
1698 return rc;
1699}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001700EXPORT_SYMBOL(ceph_osdc_start_request);
Sage Weilf24e9982009-10-06 11:31:10 -07001701
1702/*
1703 * wait for a request to complete
1704 */
1705int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
1706 struct ceph_osd_request *req)
1707{
1708 int rc;
1709
1710 rc = wait_for_completion_interruptible(&req->r_completion);
1711 if (rc < 0) {
1712 mutex_lock(&osdc->request_mutex);
1713 __cancel_request(req);
Sage Weil529cfcc2009-12-22 10:29:39 -08001714 __unregister_request(osdc, req);
Sage Weilf24e9982009-10-06 11:31:10 -07001715 mutex_unlock(&osdc->request_mutex);
Sage Weil25845472011-06-03 09:37:09 -07001716 complete_request(req);
Sage Weil529cfcc2009-12-22 10:29:39 -08001717 dout("wait_request tid %llu canceled/timed out\n", req->r_tid);
Sage Weilf24e9982009-10-06 11:31:10 -07001718 return rc;
1719 }
1720
1721 dout("wait_request tid %llu result %d\n", req->r_tid, req->r_result);
1722 return req->r_result;
1723}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001724EXPORT_SYMBOL(ceph_osdc_wait_request);
Sage Weilf24e9982009-10-06 11:31:10 -07001725
1726/*
1727 * sync - wait for all in-flight requests to flush. avoid starvation.
1728 */
1729void ceph_osdc_sync(struct ceph_osd_client *osdc)
1730{
1731 struct ceph_osd_request *req;
1732 u64 last_tid, next_tid = 0;
1733
1734 mutex_lock(&osdc->request_mutex);
1735 last_tid = osdc->last_tid;
1736 while (1) {
1737 req = __lookup_request_ge(osdc, next_tid);
1738 if (!req)
1739 break;
1740 if (req->r_tid > last_tid)
1741 break;
1742
1743 next_tid = req->r_tid + 1;
1744 if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0)
1745 continue;
1746
1747 ceph_osdc_get_request(req);
1748 mutex_unlock(&osdc->request_mutex);
1749 dout("sync waiting on tid %llu (last is %llu)\n",
1750 req->r_tid, last_tid);
1751 wait_for_completion(&req->r_safe_completion);
1752 mutex_lock(&osdc->request_mutex);
1753 ceph_osdc_put_request(req);
1754 }
1755 mutex_unlock(&osdc->request_mutex);
1756 dout("sync done (thru tid %llu)\n", last_tid);
1757}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001758EXPORT_SYMBOL(ceph_osdc_sync);
Sage Weilf24e9982009-10-06 11:31:10 -07001759
1760/*
1761 * init, shutdown
1762 */
1763int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
1764{
1765 int err;
1766
1767 dout("init\n");
1768 osdc->client = client;
1769 osdc->osdmap = NULL;
1770 init_rwsem(&osdc->map_sem);
1771 init_completion(&osdc->map_waiters);
1772 osdc->last_requested_map = 0;
1773 mutex_init(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -07001774 osdc->last_tid = 0;
1775 osdc->osds = RB_ROOT;
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001776 INIT_LIST_HEAD(&osdc->osd_lru);
Sage Weilf24e9982009-10-06 11:31:10 -07001777 osdc->requests = RB_ROOT;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001778 INIT_LIST_HEAD(&osdc->req_lru);
Sage Weil6f6c7002011-01-17 20:34:08 -08001779 INIT_LIST_HEAD(&osdc->req_unsent);
1780 INIT_LIST_HEAD(&osdc->req_notarget);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001781 INIT_LIST_HEAD(&osdc->req_linger);
Sage Weilf24e9982009-10-06 11:31:10 -07001782 osdc->num_requests = 0;
1783 INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout);
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001784 INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001785 spin_lock_init(&osdc->event_lock);
1786 osdc->event_tree = RB_ROOT;
1787 osdc->event_count = 0;
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001788
1789 schedule_delayed_work(&osdc->osds_timeout_work,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001790 round_jiffies_relative(osdc->client->options->osd_idle_ttl * HZ));
Sage Weilf24e9982009-10-06 11:31:10 -07001791
Sage Weil5f44f142009-11-18 14:52:18 -08001792 err = -ENOMEM;
Sage Weilf24e9982009-10-06 11:31:10 -07001793 osdc->req_mempool = mempool_create_kmalloc_pool(10,
1794 sizeof(struct ceph_osd_request));
1795 if (!osdc->req_mempool)
Sage Weil5f44f142009-11-18 14:52:18 -08001796 goto out;
Sage Weilf24e9982009-10-06 11:31:10 -07001797
Sage Weild50b4092012-07-09 14:22:34 -07001798 err = ceph_msgpool_init(&osdc->msgpool_op, CEPH_MSG_OSD_OP,
1799 OSD_OP_FRONT_LEN, 10, true,
Sage Weil4f482802010-04-24 09:56:35 -07001800 "osd_op");
Sage Weilf24e9982009-10-06 11:31:10 -07001801 if (err < 0)
Sage Weil5f44f142009-11-18 14:52:18 -08001802 goto out_mempool;
Sage Weild50b4092012-07-09 14:22:34 -07001803 err = ceph_msgpool_init(&osdc->msgpool_op_reply, CEPH_MSG_OSD_OPREPLY,
Sage Weil4f482802010-04-24 09:56:35 -07001804 OSD_OPREPLY_FRONT_LEN, 10, true,
1805 "osd_op_reply");
Sage Weilc16e7862010-03-01 13:02:00 -08001806 if (err < 0)
1807 goto out_msgpool;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001808
1809 osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify");
1810 if (IS_ERR(osdc->notify_wq)) {
1811 err = PTR_ERR(osdc->notify_wq);
1812 osdc->notify_wq = NULL;
1813 goto out_msgpool;
1814 }
Sage Weilf24e9982009-10-06 11:31:10 -07001815 return 0;
Sage Weil5f44f142009-11-18 14:52:18 -08001816
Sage Weilc16e7862010-03-01 13:02:00 -08001817out_msgpool:
1818 ceph_msgpool_destroy(&osdc->msgpool_op);
Sage Weil5f44f142009-11-18 14:52:18 -08001819out_mempool:
1820 mempool_destroy(osdc->req_mempool);
1821out:
1822 return err;
Sage Weilf24e9982009-10-06 11:31:10 -07001823}
1824
1825void ceph_osdc_stop(struct ceph_osd_client *osdc)
1826{
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001827 flush_workqueue(osdc->notify_wq);
1828 destroy_workqueue(osdc->notify_wq);
Sage Weilf24e9982009-10-06 11:31:10 -07001829 cancel_delayed_work_sync(&osdc->timeout_work);
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001830 cancel_delayed_work_sync(&osdc->osds_timeout_work);
Sage Weilf24e9982009-10-06 11:31:10 -07001831 if (osdc->osdmap) {
1832 ceph_osdmap_destroy(osdc->osdmap);
1833 osdc->osdmap = NULL;
1834 }
Sage Weilaca420b2011-08-31 14:45:53 -07001835 remove_all_osds(osdc);
Sage Weilf24e9982009-10-06 11:31:10 -07001836 mempool_destroy(osdc->req_mempool);
1837 ceph_msgpool_destroy(&osdc->msgpool_op);
Sage Weilc16e7862010-03-01 13:02:00 -08001838 ceph_msgpool_destroy(&osdc->msgpool_op_reply);
Sage Weilf24e9982009-10-06 11:31:10 -07001839}
1840
1841/*
1842 * Read some contiguous pages. If we cross a stripe boundary, shorten
1843 * *plen. Return number of bytes read, or error.
1844 */
1845int ceph_osdc_readpages(struct ceph_osd_client *osdc,
1846 struct ceph_vino vino, struct ceph_file_layout *layout,
1847 u64 off, u64 *plen,
1848 u32 truncate_seq, u64 truncate_size,
Sage Weilb7495fc2010-11-09 12:43:12 -08001849 struct page **pages, int num_pages, int page_align)
Sage Weilf24e9982009-10-06 11:31:10 -07001850{
1851 struct ceph_osd_request *req;
1852 int rc = 0;
1853
1854 dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
1855 vino.snap, off, *plen);
1856 req = ceph_osdc_new_request(osdc, layout, vino, off, plen,
1857 CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
1858 NULL, 0, truncate_seq, truncate_size, NULL,
Alex Eldera3bea472013-02-15 11:42:29 -06001859 false, page_align);
Sage Weil68162822012-09-24 21:01:02 -07001860 if (IS_ERR(req))
1861 return PTR_ERR(req);
Sage Weilf24e9982009-10-06 11:31:10 -07001862
1863 /* it may be a short read due to an object boundary */
1864 req->r_pages = pages;
Sage Weilf24e9982009-10-06 11:31:10 -07001865
Sage Weilb7495fc2010-11-09 12:43:12 -08001866 dout("readpages final extent is %llu~%llu (%d pages align %d)\n",
1867 off, *plen, req->r_num_pages, page_align);
Sage Weilf24e9982009-10-06 11:31:10 -07001868
1869 rc = ceph_osdc_start_request(osdc, req, false);
1870 if (!rc)
1871 rc = ceph_osdc_wait_request(osdc, req);
1872
1873 ceph_osdc_put_request(req);
1874 dout("readpages result %d\n", rc);
1875 return rc;
1876}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001877EXPORT_SYMBOL(ceph_osdc_readpages);
Sage Weilf24e9982009-10-06 11:31:10 -07001878
1879/*
1880 * do a synchronous write on N pages
1881 */
1882int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
1883 struct ceph_file_layout *layout,
1884 struct ceph_snap_context *snapc,
1885 u64 off, u64 len,
1886 u32 truncate_seq, u64 truncate_size,
1887 struct timespec *mtime,
Alex Elder24808822013-02-15 11:42:29 -06001888 struct page **pages, int num_pages)
Sage Weilf24e9982009-10-06 11:31:10 -07001889{
1890 struct ceph_osd_request *req;
1891 int rc = 0;
Sage Weilb7495fc2010-11-09 12:43:12 -08001892 int page_align = off & ~PAGE_MASK;
Sage Weilf24e9982009-10-06 11:31:10 -07001893
1894 BUG_ON(vino.snap != CEPH_NOSNAP);
1895 req = ceph_osdc_new_request(osdc, layout, vino, off, &len,
1896 CEPH_OSD_OP_WRITE,
Alex Elder24808822013-02-15 11:42:29 -06001897 CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
Alex Elderfbf86852013-02-15 11:42:29 -06001898 snapc, 0,
Sage Weilf24e9982009-10-06 11:31:10 -07001899 truncate_seq, truncate_size, mtime,
Alex Eldera3bea472013-02-15 11:42:29 -06001900 true, page_align);
Sage Weil68162822012-09-24 21:01:02 -07001901 if (IS_ERR(req))
1902 return PTR_ERR(req);
Sage Weilf24e9982009-10-06 11:31:10 -07001903
1904 /* it may be a short write due to an object boundary */
1905 req->r_pages = pages;
Sage Weilf24e9982009-10-06 11:31:10 -07001906 dout("writepages %llu~%llu (%d pages)\n", off, len,
1907 req->r_num_pages);
1908
Alex Elder87f979d2013-02-15 11:42:29 -06001909 rc = ceph_osdc_start_request(osdc, req, true);
Sage Weilf24e9982009-10-06 11:31:10 -07001910 if (!rc)
1911 rc = ceph_osdc_wait_request(osdc, req);
1912
1913 ceph_osdc_put_request(req);
1914 if (rc == 0)
1915 rc = len;
1916 dout("writepages result %d\n", rc);
1917 return rc;
1918}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001919EXPORT_SYMBOL(ceph_osdc_writepages);
Sage Weilf24e9982009-10-06 11:31:10 -07001920
1921/*
1922 * handle incoming message
1923 */
1924static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
1925{
1926 struct ceph_osd *osd = con->private;
Julia Lawall32c895e2009-11-21 16:53:16 +01001927 struct ceph_osd_client *osdc;
Sage Weilf24e9982009-10-06 11:31:10 -07001928 int type = le16_to_cpu(msg->hdr.type);
1929
1930 if (!osd)
Sage Weil4a32f932010-06-13 10:27:53 -07001931 goto out;
Julia Lawall32c895e2009-11-21 16:53:16 +01001932 osdc = osd->o_osdc;
Sage Weilf24e9982009-10-06 11:31:10 -07001933
1934 switch (type) {
1935 case CEPH_MSG_OSD_MAP:
1936 ceph_osdc_handle_map(osdc, msg);
1937 break;
1938 case CEPH_MSG_OSD_OPREPLY:
Sage Weil350b1c32009-12-22 10:45:45 -08001939 handle_reply(osdc, msg, con);
Sage Weilf24e9982009-10-06 11:31:10 -07001940 break;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001941 case CEPH_MSG_WATCH_NOTIFY:
1942 handle_watch_notify(osdc, msg);
1943 break;
Sage Weilf24e9982009-10-06 11:31:10 -07001944
1945 default:
1946 pr_err("received unknown message type %d %s\n", type,
1947 ceph_msg_type_name(type));
1948 }
Sage Weil4a32f932010-06-13 10:27:53 -07001949out:
Sage Weilf24e9982009-10-06 11:31:10 -07001950 ceph_msg_put(msg);
1951}
1952
Sage Weil5b3a4db2010-02-19 21:43:23 -08001953/*
Sage Weil21b667f2010-03-04 10:22:59 -08001954 * lookup and return message for incoming reply. set up reply message
1955 * pages.
Sage Weil5b3a4db2010-02-19 21:43:23 -08001956 */
1957static struct ceph_msg *get_reply(struct ceph_connection *con,
Yehuda Sadeh24504182010-01-08 13:58:34 -08001958 struct ceph_msg_header *hdr,
1959 int *skip)
Sage Weilf24e9982009-10-06 11:31:10 -07001960{
1961 struct ceph_osd *osd = con->private;
1962 struct ceph_osd_client *osdc = osd->o_osdc;
Yehuda Sadeh24504182010-01-08 13:58:34 -08001963 struct ceph_msg *m;
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08001964 struct ceph_osd_request *req;
Sage Weil5b3a4db2010-02-19 21:43:23 -08001965 int front = le32_to_cpu(hdr->front_len);
1966 int data_len = le32_to_cpu(hdr->data_len);
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08001967 u64 tid;
Sage Weilf24e9982009-10-06 11:31:10 -07001968
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08001969 tid = le64_to_cpu(hdr->tid);
1970 mutex_lock(&osdc->request_mutex);
1971 req = __lookup_request(osdc, tid);
1972 if (!req) {
1973 *skip = 1;
1974 m = NULL;
Sage Weil756a16a2012-07-30 16:26:13 -07001975 dout("get_reply unknown tid %llu from osd%d\n", tid,
1976 osd->o_osd);
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08001977 goto out;
1978 }
Sage Weilc16e7862010-03-01 13:02:00 -08001979
1980 if (req->r_con_filling_msg) {
Alex Elder8921d112012-06-01 14:56:43 -05001981 dout("%s revoking msg %p from old con %p\n", __func__,
Sage Weilc16e7862010-03-01 13:02:00 -08001982 req->r_reply, req->r_con_filling_msg);
Alex Elder8921d112012-06-01 14:56:43 -05001983 ceph_msg_revoke_incoming(req->r_reply);
Sage Weil0d477662012-05-31 20:22:18 -07001984 req->r_con_filling_msg->ops->put(req->r_con_filling_msg);
Sage Weil6f46cb22010-03-24 21:30:19 -07001985 req->r_con_filling_msg = NULL;
Sage Weilf24e9982009-10-06 11:31:10 -07001986 }
Yehuda Sadeh24504182010-01-08 13:58:34 -08001987
Sage Weilc16e7862010-03-01 13:02:00 -08001988 if (front > req->r_reply->front.iov_len) {
1989 pr_warning("get_reply front %d > preallocated %d\n",
1990 front, (int)req->r_reply->front.iov_len);
Sage Weilb61c2762011-08-09 15:03:46 -07001991 m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front, GFP_NOFS, false);
Sage Weila79832f2010-04-01 16:06:19 -07001992 if (!m)
Sage Weilc16e7862010-03-01 13:02:00 -08001993 goto out;
1994 ceph_msg_put(req->r_reply);
1995 req->r_reply = m;
1996 }
1997 m = ceph_msg_get(req->r_reply);
1998
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08001999 if (data_len > 0) {
Sage Weilb7495fc2010-11-09 12:43:12 -08002000 int want = calc_pages_for(req->r_page_alignment, data_len);
Sage Weil21b667f2010-03-04 10:22:59 -08002001
Alex Elder9cbb1d72013-01-31 16:02:00 -06002002 if (req->r_pages && unlikely(req->r_num_pages < want)) {
Sage Weil9bb0ce22011-06-13 16:20:18 -07002003 pr_warning("tid %lld reply has %d bytes %d pages, we"
2004 " had only %d pages ready\n", tid, data_len,
2005 want, req->r_num_pages);
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002006 *skip = 1;
2007 ceph_msg_put(m);
Sage Weila79832f2010-04-01 16:06:19 -07002008 m = NULL;
Sage Weil21b667f2010-03-04 10:22:59 -08002009 goto out;
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002010 }
Sage Weil21b667f2010-03-04 10:22:59 -08002011 m->pages = req->r_pages;
2012 m->nr_pages = req->r_num_pages;
Sage Weilc5c6b192010-11-09 12:40:00 -08002013 m->page_alignment = req->r_page_alignment;
Yehuda Sadeh68b44762010-04-06 15:01:27 -07002014#ifdef CONFIG_BLOCK
2015 m->bio = req->r_bio;
2016#endif
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002017 }
Sage Weil5b3a4db2010-02-19 21:43:23 -08002018 *skip = 0;
Sage Weil0d477662012-05-31 20:22:18 -07002019 req->r_con_filling_msg = con->ops->get(con);
Sage Weilc16e7862010-03-01 13:02:00 -08002020 dout("get_reply tid %lld %p\n", tid, m);
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002021
2022out:
2023 mutex_unlock(&osdc->request_mutex);
Yehuda Sadeh24504182010-01-08 13:58:34 -08002024 return m;
Sage Weil5b3a4db2010-02-19 21:43:23 -08002025
2026}
2027
2028static struct ceph_msg *alloc_msg(struct ceph_connection *con,
2029 struct ceph_msg_header *hdr,
2030 int *skip)
2031{
2032 struct ceph_osd *osd = con->private;
2033 int type = le16_to_cpu(hdr->type);
2034 int front = le32_to_cpu(hdr->front_len);
2035
Alex Elder1c20f2d2012-06-04 14:43:32 -05002036 *skip = 0;
Sage Weil5b3a4db2010-02-19 21:43:23 -08002037 switch (type) {
2038 case CEPH_MSG_OSD_MAP:
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002039 case CEPH_MSG_WATCH_NOTIFY:
Sage Weilb61c2762011-08-09 15:03:46 -07002040 return ceph_msg_new(type, front, GFP_NOFS, false);
Sage Weil5b3a4db2010-02-19 21:43:23 -08002041 case CEPH_MSG_OSD_OPREPLY:
2042 return get_reply(con, hdr, skip);
2043 default:
2044 pr_info("alloc_msg unexpected msg type %d from osd%d\n", type,
2045 osd->o_osd);
2046 *skip = 1;
2047 return NULL;
2048 }
Sage Weilf24e9982009-10-06 11:31:10 -07002049}
2050
2051/*
2052 * Wrappers to refcount containing ceph_osd struct
2053 */
2054static struct ceph_connection *get_osd_con(struct ceph_connection *con)
2055{
2056 struct ceph_osd *osd = con->private;
2057 if (get_osd(osd))
2058 return con;
2059 return NULL;
2060}
2061
2062static void put_osd_con(struct ceph_connection *con)
2063{
2064 struct ceph_osd *osd = con->private;
2065 put_osd(osd);
2066}
2067
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002068/*
2069 * authentication
2070 */
Alex Eldera3530df2012-05-16 15:16:39 -05002071/*
2072 * Note: returned pointer is the address of a structure that's
2073 * managed separately. Caller must *not* attempt to free it.
2074 */
2075static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
Alex Elder8f43fb52012-05-16 15:16:39 -05002076 int *proto, int force_new)
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002077{
2078 struct ceph_osd *o = con->private;
2079 struct ceph_osd_client *osdc = o->o_osdc;
2080 struct ceph_auth_client *ac = osdc->client->monc.auth;
Alex Elder74f18692012-05-16 15:16:39 -05002081 struct ceph_auth_handshake *auth = &o->o_auth;
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002082
Alex Elder74f18692012-05-16 15:16:39 -05002083 if (force_new && auth->authorizer) {
Alex Eldera2556512012-05-16 15:16:39 -05002084 if (ac->ops && ac->ops->destroy_authorizer)
2085 ac->ops->destroy_authorizer(ac, auth->authorizer);
Alex Elder74f18692012-05-16 15:16:39 -05002086 auth->authorizer = NULL;
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002087 }
Alex Eldera2556512012-05-16 15:16:39 -05002088 if (!auth->authorizer && ac->ops && ac->ops->create_authorizer) {
Alex Eldera3530df2012-05-16 15:16:39 -05002089 int ret = ac->ops->create_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
2090 auth);
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002091 if (ret)
Alex Eldera3530df2012-05-16 15:16:39 -05002092 return ERR_PTR(ret);
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002093 }
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002094 *proto = ac->protocol;
Alex Elder74f18692012-05-16 15:16:39 -05002095
Alex Eldera3530df2012-05-16 15:16:39 -05002096 return auth;
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002097}
2098
2099
2100static int verify_authorizer_reply(struct ceph_connection *con, int len)
2101{
2102 struct ceph_osd *o = con->private;
2103 struct ceph_osd_client *osdc = o->o_osdc;
2104 struct ceph_auth_client *ac = osdc->client->monc.auth;
2105
Alex Eldera2556512012-05-16 15:16:39 -05002106 /*
2107 * XXX If ac->ops or ac->ops->verify_authorizer_reply is null,
2108 * XXX which do we do: succeed or fail?
2109 */
Alex Elder6c4a1912012-05-16 15:16:38 -05002110 return ac->ops->verify_authorizer_reply(ac, o->o_auth.authorizer, len);
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002111}
2112
Sage Weil9bd2e6f2010-02-02 16:21:06 -08002113static int invalidate_authorizer(struct ceph_connection *con)
2114{
2115 struct ceph_osd *o = con->private;
2116 struct ceph_osd_client *osdc = o->o_osdc;
2117 struct ceph_auth_client *ac = osdc->client->monc.auth;
2118
Alex Eldera2556512012-05-16 15:16:39 -05002119 if (ac->ops && ac->ops->invalidate_authorizer)
Sage Weil9bd2e6f2010-02-02 16:21:06 -08002120 ac->ops->invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
2121
2122 return ceph_monc_validate_auth(&osdc->client->monc);
2123}
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002124
Tobias Klauser9e327892010-05-20 10:40:19 +02002125static const struct ceph_connection_operations osd_con_ops = {
Sage Weilf24e9982009-10-06 11:31:10 -07002126 .get = get_osd_con,
2127 .put = put_osd_con,
2128 .dispatch = dispatch,
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002129 .get_authorizer = get_authorizer,
2130 .verify_authorizer_reply = verify_authorizer_reply,
Sage Weil9bd2e6f2010-02-02 16:21:06 -08002131 .invalidate_authorizer = invalidate_authorizer,
Sage Weilf24e9982009-10-06 11:31:10 -07002132 .alloc_msg = alloc_msg,
Sage Weil81b024e2009-10-09 10:29:18 -07002133 .fault = osd_reset,
Sage Weilf24e9982009-10-06 11:31:10 -07002134};