blob: 648a215d734e8f1e22a93e17eb210fff69014e3c [file] [log] [blame]
Alex Eldera4ce40a2013-04-05 01:27:12 -05001
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002#include <linux/ceph/ceph_debug.h>
Sage Weilf24e9982009-10-06 11:31:10 -07003
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07004#include <linux/module.h>
Sage Weilf24e9982009-10-06 11:31:10 -07005#include <linux/err.h>
6#include <linux/highmem.h>
7#include <linux/mm.h>
8#include <linux/pagemap.h>
9#include <linux/slab.h>
10#include <linux/uaccess.h>
Yehuda Sadeh68b44762010-04-06 15:01:27 -070011#ifdef CONFIG_BLOCK
12#include <linux/bio.h>
13#endif
Sage Weilf24e9982009-10-06 11:31:10 -070014
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -070015#include <linux/ceph/libceph.h>
16#include <linux/ceph/osd_client.h>
17#include <linux/ceph/messenger.h>
18#include <linux/ceph/decode.h>
19#include <linux/ceph/auth.h>
20#include <linux/ceph/pagelist.h>
Sage Weilf24e9982009-10-06 11:31:10 -070021
Sage Weilc16e7862010-03-01 13:02:00 -080022#define OSD_OP_FRONT_LEN 4096
23#define OSD_OPREPLY_FRONT_LEN 512
Yehuda Sadeh0d59ab82010-01-13 17:03:23 -080024
Alex Elder5522ae02013-05-01 12:43:04 -050025static struct kmem_cache *ceph_osd_request_cache;
26
Tobias Klauser9e327892010-05-20 10:40:19 +020027static const struct ceph_connection_operations osd_con_ops;
Sage Weilf24e9982009-10-06 11:31:10 -070028
Alex Elderf9d25192013-02-15 11:42:29 -060029static void __send_queued(struct ceph_osd_client *osdc);
Sage Weil6f6c7002011-01-17 20:34:08 -080030static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -070031static void __register_request(struct ceph_osd_client *osdc,
32 struct ceph_osd_request *req);
33static void __unregister_linger_request(struct ceph_osd_client *osdc,
34 struct ceph_osd_request *req);
Sage Weil56e925b2012-01-03 12:34:34 -080035static void __send_request(struct ceph_osd_client *osdc,
36 struct ceph_osd_request *req);
Sage Weilf24e9982009-10-06 11:31:10 -070037
38/*
39 * Implement client access to distributed object storage cluster.
40 *
41 * All data objects are stored within a cluster/cloud of OSDs, or
42 * "object storage devices." (Note that Ceph OSDs have _nothing_ to
43 * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply
44 * remote daemons serving up and coordinating consistent and safe
45 * access to storage.
46 *
47 * Cluster membership and the mapping of data objects onto storage devices
48 * are described by the osd map.
49 *
50 * We keep track of pending OSD requests (read, write), resubmit
51 * requests to different OSDs when the cluster topology/data layout
52 * change, or retry the affected requests when the communications
53 * channel with an OSD is reset.
54 */
55
56/*
57 * calculate the mapping of a file extent onto an object, and fill out the
58 * request accordingly. shorten extent as necessary if it crosses an
59 * object boundary.
60 *
61 * fill osd op in request message.
62 */
Alex Elderdbe0fc42013-02-15 22:10:17 -060063static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen,
Alex Eldera19dadf2013-03-13 20:50:01 -050064 u64 *objnum, u64 *objoff, u64 *objlen)
Sage Weilf24e9982009-10-06 11:31:10 -070065{
Alex Elder60e56f12013-02-15 11:42:29 -060066 u64 orig_len = *plen;
Sage Weild63b77f2012-09-24 20:59:48 -070067 int r;
Sage Weilf24e9982009-10-06 11:31:10 -070068
Alex Elder60e56f12013-02-15 11:42:29 -060069 /* object extent? */
Alex Elder75d1c942013-03-13 20:50:00 -050070 r = ceph_calc_file_object_mapping(layout, off, orig_len, objnum,
71 objoff, objlen);
Sage Weild63b77f2012-09-24 20:59:48 -070072 if (r < 0)
73 return r;
Alex Elder75d1c942013-03-13 20:50:00 -050074 if (*objlen < orig_len) {
75 *plen = *objlen;
Alex Elder60e56f12013-02-15 11:42:29 -060076 dout(" skipping last %llu, final file extent %llu~%llu\n",
77 orig_len - *plen, off, *plen);
78 }
79
Alex Elder75d1c942013-03-13 20:50:00 -050080 dout("calc_layout objnum=%llx %llu~%llu\n", *objnum, *objoff, *objlen);
Sage Weilf24e9982009-10-06 11:31:10 -070081
Alex Elder3ff5f382013-02-15 22:10:17 -060082 return 0;
Sage Weilf24e9982009-10-06 11:31:10 -070083}
84
Alex Elderc54d47b2013-04-03 01:28:57 -050085static void ceph_osd_data_init(struct ceph_osd_data *osd_data)
86{
87 memset(osd_data, 0, sizeof (*osd_data));
88 osd_data->type = CEPH_OSD_DATA_TYPE_NONE;
89}
90
Alex Eldera4ce40a2013-04-05 01:27:12 -050091static void ceph_osd_data_pages_init(struct ceph_osd_data *osd_data,
Alex Elder43bfe5d2013-04-03 01:28:57 -050092 struct page **pages, u64 length, u32 alignment,
93 bool pages_from_pool, bool own_pages)
94{
95 osd_data->type = CEPH_OSD_DATA_TYPE_PAGES;
96 osd_data->pages = pages;
97 osd_data->length = length;
98 osd_data->alignment = alignment;
99 osd_data->pages_from_pool = pages_from_pool;
100 osd_data->own_pages = own_pages;
101}
Alex Elder43bfe5d2013-04-03 01:28:57 -0500102
Alex Eldera4ce40a2013-04-05 01:27:12 -0500103static void ceph_osd_data_pagelist_init(struct ceph_osd_data *osd_data,
Alex Elder43bfe5d2013-04-03 01:28:57 -0500104 struct ceph_pagelist *pagelist)
105{
106 osd_data->type = CEPH_OSD_DATA_TYPE_PAGELIST;
107 osd_data->pagelist = pagelist;
108}
Alex Elder43bfe5d2013-04-03 01:28:57 -0500109
110#ifdef CONFIG_BLOCK
Alex Eldera4ce40a2013-04-05 01:27:12 -0500111static void ceph_osd_data_bio_init(struct ceph_osd_data *osd_data,
Alex Elder43bfe5d2013-04-03 01:28:57 -0500112 struct bio *bio, size_t bio_length)
113{
114 osd_data->type = CEPH_OSD_DATA_TYPE_BIO;
115 osd_data->bio = bio;
116 osd_data->bio_length = bio_length;
117}
Alex Elder43bfe5d2013-04-03 01:28:57 -0500118#endif /* CONFIG_BLOCK */
119
Alex Elder863c7eb2013-04-15 14:50:36 -0500120#define osd_req_op_data(oreq, whch, typ, fld) \
121 ({ \
122 BUG_ON(whch >= (oreq)->r_num_ops); \
123 &(oreq)->r_ops[whch].typ.fld; \
124 })
125
Alex Elder49719772013-02-11 12:33:24 -0600126static struct ceph_osd_data *
127osd_req_op_raw_data_in(struct ceph_osd_request *osd_req, unsigned int which)
128{
129 BUG_ON(which >= osd_req->r_num_ops);
130
131 return &osd_req->r_ops[which].raw_data_in;
132}
133
Alex Eldera4ce40a2013-04-05 01:27:12 -0500134struct ceph_osd_data *
135osd_req_op_extent_osd_data(struct ceph_osd_request *osd_req,
Alex Elder406e2c92013-04-15 14:50:36 -0500136 unsigned int which)
Alex Eldera4ce40a2013-04-05 01:27:12 -0500137{
Alex Elder863c7eb2013-04-15 14:50:36 -0500138 return osd_req_op_data(osd_req, which, extent, osd_data);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500139}
140EXPORT_SYMBOL(osd_req_op_extent_osd_data);
141
142struct ceph_osd_data *
Alex Eldera4ce40a2013-04-05 01:27:12 -0500143osd_req_op_cls_response_data(struct ceph_osd_request *osd_req,
144 unsigned int which)
145{
Alex Elder863c7eb2013-04-15 14:50:36 -0500146 return osd_req_op_data(osd_req, which, cls, response_data);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500147}
148EXPORT_SYMBOL(osd_req_op_cls_response_data); /* ??? */
149
Alex Elder49719772013-02-11 12:33:24 -0600150void osd_req_op_raw_data_in_pages(struct ceph_osd_request *osd_req,
151 unsigned int which, struct page **pages,
152 u64 length, u32 alignment,
153 bool pages_from_pool, bool own_pages)
154{
155 struct ceph_osd_data *osd_data;
156
157 osd_data = osd_req_op_raw_data_in(osd_req, which);
158 ceph_osd_data_pages_init(osd_data, pages, length, alignment,
159 pages_from_pool, own_pages);
160}
161EXPORT_SYMBOL(osd_req_op_raw_data_in_pages);
162
Alex Eldera4ce40a2013-04-05 01:27:12 -0500163void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *osd_req,
Alex Elder406e2c92013-04-15 14:50:36 -0500164 unsigned int which, struct page **pages,
165 u64 length, u32 alignment,
Alex Eldera4ce40a2013-04-05 01:27:12 -0500166 bool pages_from_pool, bool own_pages)
167{
168 struct ceph_osd_data *osd_data;
169
Alex Elder863c7eb2013-04-15 14:50:36 -0500170 osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500171 ceph_osd_data_pages_init(osd_data, pages, length, alignment,
172 pages_from_pool, own_pages);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500173}
174EXPORT_SYMBOL(osd_req_op_extent_osd_data_pages);
175
176void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *osd_req,
Alex Elder406e2c92013-04-15 14:50:36 -0500177 unsigned int which, struct ceph_pagelist *pagelist)
Alex Eldera4ce40a2013-04-05 01:27:12 -0500178{
179 struct ceph_osd_data *osd_data;
180
Alex Elder863c7eb2013-04-15 14:50:36 -0500181 osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500182 ceph_osd_data_pagelist_init(osd_data, pagelist);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500183}
184EXPORT_SYMBOL(osd_req_op_extent_osd_data_pagelist);
185
186#ifdef CONFIG_BLOCK
187void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *osd_req,
Alex Elder406e2c92013-04-15 14:50:36 -0500188 unsigned int which, struct bio *bio, size_t bio_length)
Alex Eldera4ce40a2013-04-05 01:27:12 -0500189{
190 struct ceph_osd_data *osd_data;
Alex Elder863c7eb2013-04-15 14:50:36 -0500191
192 osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500193 ceph_osd_data_bio_init(osd_data, bio, bio_length);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500194}
195EXPORT_SYMBOL(osd_req_op_extent_osd_data_bio);
196#endif /* CONFIG_BLOCK */
197
198static void osd_req_op_cls_request_info_pagelist(
199 struct ceph_osd_request *osd_req,
200 unsigned int which, struct ceph_pagelist *pagelist)
201{
202 struct ceph_osd_data *osd_data;
203
Alex Elder863c7eb2013-04-15 14:50:36 -0500204 osd_data = osd_req_op_data(osd_req, which, cls, request_info);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500205 ceph_osd_data_pagelist_init(osd_data, pagelist);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500206}
207
Alex Elder04017e22013-04-05 14:46:02 -0500208void osd_req_op_cls_request_data_pagelist(
209 struct ceph_osd_request *osd_req,
210 unsigned int which, struct ceph_pagelist *pagelist)
211{
212 struct ceph_osd_data *osd_data;
213
Alex Elder863c7eb2013-04-15 14:50:36 -0500214 osd_data = osd_req_op_data(osd_req, which, cls, request_data);
Alex Elder04017e22013-04-05 14:46:02 -0500215 ceph_osd_data_pagelist_init(osd_data, pagelist);
216}
217EXPORT_SYMBOL(osd_req_op_cls_request_data_pagelist);
218
Alex Elder6c57b552013-04-19 15:34:49 -0500219void osd_req_op_cls_request_data_pages(struct ceph_osd_request *osd_req,
220 unsigned int which, struct page **pages, u64 length,
221 u32 alignment, bool pages_from_pool, bool own_pages)
222{
223 struct ceph_osd_data *osd_data;
224
225 osd_data = osd_req_op_data(osd_req, which, cls, request_data);
226 ceph_osd_data_pages_init(osd_data, pages, length, alignment,
227 pages_from_pool, own_pages);
228}
229EXPORT_SYMBOL(osd_req_op_cls_request_data_pages);
230
Alex Eldera4ce40a2013-04-05 01:27:12 -0500231void osd_req_op_cls_response_data_pages(struct ceph_osd_request *osd_req,
232 unsigned int which, struct page **pages, u64 length,
233 u32 alignment, bool pages_from_pool, bool own_pages)
234{
235 struct ceph_osd_data *osd_data;
236
Alex Elder863c7eb2013-04-15 14:50:36 -0500237 osd_data = osd_req_op_data(osd_req, which, cls, response_data);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500238 ceph_osd_data_pages_init(osd_data, pages, length, alignment,
239 pages_from_pool, own_pages);
Alex Eldera4ce40a2013-04-05 01:27:12 -0500240}
241EXPORT_SYMBOL(osd_req_op_cls_response_data_pages);
242
Alex Elder23c08a9cb2013-04-03 01:28:58 -0500243static u64 ceph_osd_data_length(struct ceph_osd_data *osd_data)
244{
245 switch (osd_data->type) {
246 case CEPH_OSD_DATA_TYPE_NONE:
247 return 0;
248 case CEPH_OSD_DATA_TYPE_PAGES:
249 return osd_data->length;
250 case CEPH_OSD_DATA_TYPE_PAGELIST:
251 return (u64)osd_data->pagelist->length;
252#ifdef CONFIG_BLOCK
253 case CEPH_OSD_DATA_TYPE_BIO:
254 return (u64)osd_data->bio_length;
255#endif /* CONFIG_BLOCK */
256 default:
257 WARN(true, "unrecognized data type %d\n", (int)osd_data->type);
258 return 0;
259 }
260}
261
Alex Elderc54d47b2013-04-03 01:28:57 -0500262static void ceph_osd_data_release(struct ceph_osd_data *osd_data)
263{
Alex Elder54764922013-04-05 01:27:12 -0500264 if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES && osd_data->own_pages) {
Alex Elderc54d47b2013-04-03 01:28:57 -0500265 int num_pages;
266
267 num_pages = calc_pages_for((u64)osd_data->alignment,
268 (u64)osd_data->length);
269 ceph_release_page_vector(osd_data->pages, num_pages);
270 }
Alex Elder54764922013-04-05 01:27:12 -0500271 ceph_osd_data_init(osd_data);
272}
273
274static void osd_req_op_data_release(struct ceph_osd_request *osd_req,
275 unsigned int which)
276{
277 struct ceph_osd_req_op *op;
278
279 BUG_ON(which >= osd_req->r_num_ops);
280 op = &osd_req->r_ops[which];
281
282 switch (op->op) {
283 case CEPH_OSD_OP_READ:
284 case CEPH_OSD_OP_WRITE:
285 ceph_osd_data_release(&op->extent.osd_data);
286 break;
287 case CEPH_OSD_OP_CALL:
288 ceph_osd_data_release(&op->cls.request_info);
Alex Elder04017e22013-04-05 14:46:02 -0500289 ceph_osd_data_release(&op->cls.request_data);
Alex Elder54764922013-04-05 01:27:12 -0500290 ceph_osd_data_release(&op->cls.response_data);
291 break;
292 default:
293 break;
294 }
Alex Elderc54d47b2013-04-03 01:28:57 -0500295}
296
Sage Weilf24e9982009-10-06 11:31:10 -0700297/*
298 * requests
299 */
Ilya Dryomov9e94af22014-06-20 14:14:42 +0400300static void ceph_osdc_release_request(struct kref *kref)
Sage Weilf24e9982009-10-06 11:31:10 -0700301{
Ilya Dryomov9e94af22014-06-20 14:14:42 +0400302 struct ceph_osd_request *req = container_of(kref,
303 struct ceph_osd_request, r_kref);
Alex Elder54764922013-04-05 01:27:12 -0500304 unsigned int which;
Sage Weil415e49a2009-12-07 13:37:03 -0800305
Ilya Dryomov9e94af22014-06-20 14:14:42 +0400306 dout("%s %p (r_request %p r_reply %p)\n", __func__, req,
307 req->r_request, req->r_reply);
Ilya Dryomov6562d662014-06-20 14:14:42 +0400308 WARN_ON(!RB_EMPTY_NODE(&req->r_node));
309 WARN_ON(!list_empty(&req->r_req_lru_item));
310 WARN_ON(!list_empty(&req->r_osd_item));
311 WARN_ON(!list_empty(&req->r_linger_item));
312 WARN_ON(!list_empty(&req->r_linger_osd_item));
313 WARN_ON(req->r_osd);
Ilya Dryomov9e94af22014-06-20 14:14:42 +0400314
Sage Weil415e49a2009-12-07 13:37:03 -0800315 if (req->r_request)
316 ceph_msg_put(req->r_request);
Alex Elderace6d3a2013-04-01 16:12:14 -0500317 if (req->r_reply) {
Alex Elder8921d112012-06-01 14:56:43 -0500318 ceph_msg_revoke_incoming(req->r_reply);
Alex Elderab8cb342012-06-04 14:43:32 -0500319 ceph_msg_put(req->r_reply);
Alex Elderace6d3a2013-04-01 16:12:14 -0500320 }
Alex Elder0fff87e2013-02-14 12:16:43 -0600321
Alex Elder54764922013-04-05 01:27:12 -0500322 for (which = 0; which < req->r_num_ops; which++)
323 osd_req_op_data_release(req, which);
Alex Elder0fff87e2013-02-14 12:16:43 -0600324
Sage Weil415e49a2009-12-07 13:37:03 -0800325 ceph_put_snap_context(req->r_snapc);
326 if (req->r_mempool)
327 mempool_free(req, req->r_osdc->req_mempool);
328 else
Alex Elder5522ae02013-05-01 12:43:04 -0500329 kmem_cache_free(ceph_osd_request_cache, req);
330
Sage Weilf24e9982009-10-06 11:31:10 -0700331}
Ilya Dryomov9e94af22014-06-20 14:14:42 +0400332
333void ceph_osdc_get_request(struct ceph_osd_request *req)
334{
335 dout("%s %p (was %d)\n", __func__, req,
336 atomic_read(&req->r_kref.refcount));
337 kref_get(&req->r_kref);
338}
339EXPORT_SYMBOL(ceph_osdc_get_request);
340
341void ceph_osdc_put_request(struct ceph_osd_request *req)
342{
343 dout("%s %p (was %d)\n", __func__, req,
344 atomic_read(&req->r_kref.refcount));
345 kref_put(&req->r_kref, ceph_osdc_release_request);
346}
347EXPORT_SYMBOL(ceph_osdc_put_request);
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700348
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700349struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700350 struct ceph_snap_context *snapc,
Sage Weil1b83bef2013-02-25 16:11:12 -0800351 unsigned int num_ops,
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700352 bool use_mempool,
Alex Elder54a54002012-11-13 21:11:15 -0600353 gfp_t gfp_flags)
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700354{
355 struct ceph_osd_request *req;
356 struct ceph_msg *msg;
Sage Weil1b83bef2013-02-25 16:11:12 -0800357 size_t msg_size;
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700358
Alex Elder79528732013-04-03 21:32:51 -0500359 BUILD_BUG_ON(CEPH_OSD_MAX_OP > U16_MAX);
360 BUG_ON(num_ops > CEPH_OSD_MAX_OP);
361
Sage Weil1b83bef2013-02-25 16:11:12 -0800362 msg_size = 4 + 4 + 8 + 8 + 4+8;
363 msg_size += 2 + 4 + 8 + 4 + 4; /* oloc */
364 msg_size += 1 + 8 + 4 + 4; /* pg_t */
Ilya Dryomov2d0ebc52014-01-27 17:40:18 +0200365 msg_size += 4 + CEPH_MAX_OID_NAME_LEN; /* oid */
Sage Weil1b83bef2013-02-25 16:11:12 -0800366 msg_size += 2 + num_ops*sizeof(struct ceph_osd_op);
367 msg_size += 8; /* snapid */
368 msg_size += 8; /* snap_seq */
369 msg_size += 8 * (snapc ? snapc->num_snaps : 0); /* snaps */
370 msg_size += 4;
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700371
372 if (use_mempool) {
373 req = mempool_alloc(osdc->req_mempool, gfp_flags);
374 memset(req, 0, sizeof(*req));
375 } else {
Alex Elder5522ae02013-05-01 12:43:04 -0500376 req = kmem_cache_zalloc(ceph_osd_request_cache, gfp_flags);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700377 }
378 if (req == NULL)
379 return NULL;
380
381 req->r_osdc = osdc;
382 req->r_mempool = use_mempool;
Alex Elder79528732013-04-03 21:32:51 -0500383 req->r_num_ops = num_ops;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700384
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700385 kref_init(&req->r_kref);
386 init_completion(&req->r_completion);
387 init_completion(&req->r_safe_completion);
Alex Eldera978fa22012-12-17 12:23:48 -0600388 RB_CLEAR_NODE(&req->r_node);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700389 INIT_LIST_HEAD(&req->r_unsafe_item);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700390 INIT_LIST_HEAD(&req->r_linger_item);
Ilya Dryomov1d0326b2014-06-20 14:14:41 +0400391 INIT_LIST_HEAD(&req->r_linger_osd_item);
Sage Weil935b6392011-09-16 11:13:17 -0700392 INIT_LIST_HEAD(&req->r_req_lru_item);
Sage Weilcd430452012-07-09 14:31:41 -0700393 INIT_LIST_HEAD(&req->r_osd_item);
394
Ilya Dryomov3c972c92014-01-27 17:40:20 +0200395 req->r_base_oloc.pool = -1;
Ilya Dryomov205ee1182014-01-27 17:40:20 +0200396 req->r_target_oloc.pool = -1;
Ilya Dryomov221165252014-01-27 17:40:18 +0200397
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700398 /* create reply message */
399 if (use_mempool)
400 msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0);
401 else
402 msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY,
Sage Weilb61c2762011-08-09 15:03:46 -0700403 OSD_OPREPLY_FRONT_LEN, gfp_flags, true);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700404 if (!msg) {
405 ceph_osdc_put_request(req);
406 return NULL;
407 }
408 req->r_reply = msg;
409
410 /* create request message; allow space for oid */
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700411 if (use_mempool)
412 msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
413 else
Sage Weilb61c2762011-08-09 15:03:46 -0700414 msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp_flags, true);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700415 if (!msg) {
416 ceph_osdc_put_request(req);
417 return NULL;
418 }
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700419
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700420 memset(msg->front.iov_base, 0, msg->front.iov_len);
421
422 req->r_request = msg;
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700423
424 return req;
425}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700426EXPORT_SYMBOL(ceph_osdc_alloc_request);
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700427
Alex Eldera8dd0a32013-03-13 20:50:00 -0500428static bool osd_req_opcode_valid(u16 opcode)
429{
430 switch (opcode) {
431 case CEPH_OSD_OP_READ:
432 case CEPH_OSD_OP_STAT:
433 case CEPH_OSD_OP_MAPEXT:
434 case CEPH_OSD_OP_MASKTRUNC:
435 case CEPH_OSD_OP_SPARSE_READ:
436 case CEPH_OSD_OP_NOTIFY:
437 case CEPH_OSD_OP_NOTIFY_ACK:
438 case CEPH_OSD_OP_ASSERT_VER:
439 case CEPH_OSD_OP_WRITE:
440 case CEPH_OSD_OP_WRITEFULL:
441 case CEPH_OSD_OP_TRUNCATE:
442 case CEPH_OSD_OP_ZERO:
443 case CEPH_OSD_OP_DELETE:
444 case CEPH_OSD_OP_APPEND:
445 case CEPH_OSD_OP_STARTSYNC:
446 case CEPH_OSD_OP_SETTRUNC:
447 case CEPH_OSD_OP_TRIMTRUNC:
448 case CEPH_OSD_OP_TMAPUP:
449 case CEPH_OSD_OP_TMAPPUT:
450 case CEPH_OSD_OP_TMAPGET:
451 case CEPH_OSD_OP_CREATE:
452 case CEPH_OSD_OP_ROLLBACK:
453 case CEPH_OSD_OP_WATCH:
454 case CEPH_OSD_OP_OMAPGETKEYS:
455 case CEPH_OSD_OP_OMAPGETVALS:
456 case CEPH_OSD_OP_OMAPGETHEADER:
457 case CEPH_OSD_OP_OMAPGETVALSBYKEYS:
458 case CEPH_OSD_OP_OMAPSETVALS:
459 case CEPH_OSD_OP_OMAPSETHEADER:
460 case CEPH_OSD_OP_OMAPCLEAR:
461 case CEPH_OSD_OP_OMAPRMKEYS:
462 case CEPH_OSD_OP_OMAP_CMP:
Ilya Dryomovc647b8a2014-02-25 16:22:27 +0200463 case CEPH_OSD_OP_SETALLOCHINT:
Alex Eldera8dd0a32013-03-13 20:50:00 -0500464 case CEPH_OSD_OP_CLONERANGE:
465 case CEPH_OSD_OP_ASSERT_SRC_VERSION:
466 case CEPH_OSD_OP_SRC_CMPXATTR:
467 case CEPH_OSD_OP_GETXATTR:
468 case CEPH_OSD_OP_GETXATTRS:
469 case CEPH_OSD_OP_CMPXATTR:
470 case CEPH_OSD_OP_SETXATTR:
471 case CEPH_OSD_OP_SETXATTRS:
472 case CEPH_OSD_OP_RESETXATTRS:
473 case CEPH_OSD_OP_RMXATTR:
474 case CEPH_OSD_OP_PULL:
475 case CEPH_OSD_OP_PUSH:
476 case CEPH_OSD_OP_BALANCEREADS:
477 case CEPH_OSD_OP_UNBALANCEREADS:
478 case CEPH_OSD_OP_SCRUB:
479 case CEPH_OSD_OP_SCRUB_RESERVE:
480 case CEPH_OSD_OP_SCRUB_UNRESERVE:
481 case CEPH_OSD_OP_SCRUB_STOP:
482 case CEPH_OSD_OP_SCRUB_MAP:
483 case CEPH_OSD_OP_WRLOCK:
484 case CEPH_OSD_OP_WRUNLOCK:
485 case CEPH_OSD_OP_RDLOCK:
486 case CEPH_OSD_OP_RDUNLOCK:
487 case CEPH_OSD_OP_UPLOCK:
488 case CEPH_OSD_OP_DNLOCK:
489 case CEPH_OSD_OP_CALL:
490 case CEPH_OSD_OP_PGLS:
491 case CEPH_OSD_OP_PGLS_FILTER:
492 return true;
493 default:
494 return false;
495 }
496}
497
Alex Elder33803f32013-03-13 20:50:00 -0500498/*
499 * This is an osd op init function for opcodes that have no data or
500 * other information associated with them. It also serves as a
501 * common init routine for all the other init functions, below.
502 */
Alex Elderc99d2d42013-04-05 01:27:11 -0500503static struct ceph_osd_req_op *
Alex Elder49719772013-02-11 12:33:24 -0600504_osd_req_op_init(struct ceph_osd_request *osd_req, unsigned int which,
Alex Elderc99d2d42013-04-05 01:27:11 -0500505 u16 opcode)
Alex Elder33803f32013-03-13 20:50:00 -0500506{
Alex Elderc99d2d42013-04-05 01:27:11 -0500507 struct ceph_osd_req_op *op;
508
509 BUG_ON(which >= osd_req->r_num_ops);
Alex Elder33803f32013-03-13 20:50:00 -0500510 BUG_ON(!osd_req_opcode_valid(opcode));
511
Alex Elderc99d2d42013-04-05 01:27:11 -0500512 op = &osd_req->r_ops[which];
Alex Elder33803f32013-03-13 20:50:00 -0500513 memset(op, 0, sizeof (*op));
Alex Elder33803f32013-03-13 20:50:00 -0500514 op->op = opcode;
Alex Elderc99d2d42013-04-05 01:27:11 -0500515
516 return op;
Alex Elder33803f32013-03-13 20:50:00 -0500517}
518
Alex Elder49719772013-02-11 12:33:24 -0600519void osd_req_op_init(struct ceph_osd_request *osd_req,
520 unsigned int which, u16 opcode)
521{
522 (void)_osd_req_op_init(osd_req, which, opcode);
523}
524EXPORT_SYMBOL(osd_req_op_init);
525
Alex Elderc99d2d42013-04-05 01:27:11 -0500526void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
527 unsigned int which, u16 opcode,
Alex Elder33803f32013-03-13 20:50:00 -0500528 u64 offset, u64 length,
529 u64 truncate_size, u32 truncate_seq)
530{
Alex Elder49719772013-02-11 12:33:24 -0600531 struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, opcode);
Alex Elder33803f32013-03-13 20:50:00 -0500532 size_t payload_len = 0;
533
Li Wangad7a60d2013-08-15 11:51:44 +0800534 BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE &&
535 opcode != CEPH_OSD_OP_DELETE && opcode != CEPH_OSD_OP_ZERO &&
536 opcode != CEPH_OSD_OP_TRUNCATE);
Alex Elder33803f32013-03-13 20:50:00 -0500537
Alex Elder33803f32013-03-13 20:50:00 -0500538 op->extent.offset = offset;
539 op->extent.length = length;
540 op->extent.truncate_size = truncate_size;
541 op->extent.truncate_seq = truncate_seq;
542 if (opcode == CEPH_OSD_OP_WRITE)
543 payload_len += length;
544
545 op->payload_len = payload_len;
546}
547EXPORT_SYMBOL(osd_req_op_extent_init);
548
Alex Elderc99d2d42013-04-05 01:27:11 -0500549void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
550 unsigned int which, u64 length)
Alex Eldere5975c72013-03-14 14:09:05 -0500551{
Alex Elderc99d2d42013-04-05 01:27:11 -0500552 struct ceph_osd_req_op *op;
553 u64 previous;
554
555 BUG_ON(which >= osd_req->r_num_ops);
556 op = &osd_req->r_ops[which];
557 previous = op->extent.length;
Alex Eldere5975c72013-03-14 14:09:05 -0500558
559 if (length == previous)
560 return; /* Nothing to do */
561 BUG_ON(length > previous);
562
563 op->extent.length = length;
564 op->payload_len -= previous - length;
565}
566EXPORT_SYMBOL(osd_req_op_extent_update);
567
Alex Elderc99d2d42013-04-05 01:27:11 -0500568void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
Alex Elder04017e22013-04-05 14:46:02 -0500569 u16 opcode, const char *class, const char *method)
Alex Elder33803f32013-03-13 20:50:00 -0500570{
Alex Elder49719772013-02-11 12:33:24 -0600571 struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, opcode);
Alex Elder5f562df2013-04-05 01:27:12 -0500572 struct ceph_pagelist *pagelist;
Alex Elder33803f32013-03-13 20:50:00 -0500573 size_t payload_len = 0;
574 size_t size;
575
576 BUG_ON(opcode != CEPH_OSD_OP_CALL);
577
Alex Elder5f562df2013-04-05 01:27:12 -0500578 pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
579 BUG_ON(!pagelist);
580 ceph_pagelist_init(pagelist);
581
Alex Elder33803f32013-03-13 20:50:00 -0500582 op->cls.class_name = class;
583 size = strlen(class);
584 BUG_ON(size > (size_t) U8_MAX);
585 op->cls.class_len = size;
Alex Elder5f562df2013-04-05 01:27:12 -0500586 ceph_pagelist_append(pagelist, class, size);
Alex Elder33803f32013-03-13 20:50:00 -0500587 payload_len += size;
588
589 op->cls.method_name = method;
590 size = strlen(method);
591 BUG_ON(size > (size_t) U8_MAX);
592 op->cls.method_len = size;
Alex Elder5f562df2013-04-05 01:27:12 -0500593 ceph_pagelist_append(pagelist, method, size);
Alex Elder33803f32013-03-13 20:50:00 -0500594 payload_len += size;
595
Alex Eldera4ce40a2013-04-05 01:27:12 -0500596 osd_req_op_cls_request_info_pagelist(osd_req, which, pagelist);
Alex Elder5f562df2013-04-05 01:27:12 -0500597
Alex Elder33803f32013-03-13 20:50:00 -0500598 op->cls.argc = 0; /* currently unused */
599
600 op->payload_len = payload_len;
601}
602EXPORT_SYMBOL(osd_req_op_cls_init);
Alex Elder8c042b02013-04-03 01:28:58 -0500603
Alex Elderc99d2d42013-04-05 01:27:11 -0500604void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
605 unsigned int which, u16 opcode,
Alex Elder33803f32013-03-13 20:50:00 -0500606 u64 cookie, u64 version, int flag)
607{
Alex Elder49719772013-02-11 12:33:24 -0600608 struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which, opcode);
Alex Elder33803f32013-03-13 20:50:00 -0500609
Alex Elderc99d2d42013-04-05 01:27:11 -0500610 BUG_ON(opcode != CEPH_OSD_OP_NOTIFY_ACK && opcode != CEPH_OSD_OP_WATCH);
Alex Elder33803f32013-03-13 20:50:00 -0500611
612 op->watch.cookie = cookie;
Alex Elder9ef1ee52013-04-21 16:51:50 -0500613 op->watch.ver = version;
Alex Elder33803f32013-03-13 20:50:00 -0500614 if (opcode == CEPH_OSD_OP_WATCH && flag)
Alex Elderc99d2d42013-04-05 01:27:11 -0500615 op->watch.flag = (u8)1;
Alex Elder33803f32013-03-13 20:50:00 -0500616}
617EXPORT_SYMBOL(osd_req_op_watch_init);
618
Ilya Dryomovc647b8a2014-02-25 16:22:27 +0200619void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
620 unsigned int which,
621 u64 expected_object_size,
622 u64 expected_write_size)
623{
624 struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which,
625 CEPH_OSD_OP_SETALLOCHINT);
626
627 op->alloc_hint.expected_object_size = expected_object_size;
628 op->alloc_hint.expected_write_size = expected_write_size;
629
630 /*
631 * CEPH_OSD_OP_SETALLOCHINT op is advisory and therefore deemed
632 * not worth a feature bit. Set FAILOK per-op flag to make
633 * sure older osds don't trip over an unsupported opcode.
634 */
635 op->flags |= CEPH_OSD_OP_FLAG_FAILOK;
636}
637EXPORT_SYMBOL(osd_req_op_alloc_hint_init);
638
Alex Elder90af3602013-04-05 14:46:01 -0500639static void ceph_osdc_msg_data_add(struct ceph_msg *msg,
Alex Elderec9123c2013-04-05 01:27:12 -0500640 struct ceph_osd_data *osd_data)
641{
642 u64 length = ceph_osd_data_length(osd_data);
643
644 if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
645 BUG_ON(length > (u64) SIZE_MAX);
646 if (length)
Alex Elder90af3602013-04-05 14:46:01 -0500647 ceph_msg_data_add_pages(msg, osd_data->pages,
Alex Elderec9123c2013-04-05 01:27:12 -0500648 length, osd_data->alignment);
649 } else if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGELIST) {
650 BUG_ON(!length);
Alex Elder90af3602013-04-05 14:46:01 -0500651 ceph_msg_data_add_pagelist(msg, osd_data->pagelist);
Alex Elderec9123c2013-04-05 01:27:12 -0500652#ifdef CONFIG_BLOCK
653 } else if (osd_data->type == CEPH_OSD_DATA_TYPE_BIO) {
Alex Elder90af3602013-04-05 14:46:01 -0500654 ceph_msg_data_add_bio(msg, osd_data->bio, length);
Alex Elderec9123c2013-04-05 01:27:12 -0500655#endif
656 } else {
657 BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_NONE);
658 }
659}
660
Alex Elder175face2013-03-08 13:35:36 -0600661static u64 osd_req_encode_op(struct ceph_osd_request *req,
Alex Elder79528732013-04-03 21:32:51 -0500662 struct ceph_osd_op *dst, unsigned int which)
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700663{
Alex Elder79528732013-04-03 21:32:51 -0500664 struct ceph_osd_req_op *src;
Alex Elder04017e22013-04-05 14:46:02 -0500665 struct ceph_osd_data *osd_data;
Alex Elder54d50642013-04-03 01:28:58 -0500666 u64 request_data_len = 0;
Alex Elder04017e22013-04-05 14:46:02 -0500667 u64 data_length;
Alex Elder175face2013-03-08 13:35:36 -0600668
Alex Elder79528732013-04-03 21:32:51 -0500669 BUG_ON(which >= req->r_num_ops);
670 src = &req->r_ops[which];
Alex Eldera8dd0a32013-03-13 20:50:00 -0500671 if (WARN_ON(!osd_req_opcode_valid(src->op))) {
672 pr_err("unrecognized osd opcode %d\n", src->op);
673
674 return 0;
675 }
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700676
Alex Elder065a68f2012-04-20 15:49:43 -0500677 switch (src->op) {
Alex Elderfbfab532013-02-08 09:55:48 -0600678 case CEPH_OSD_OP_STAT:
Alex Elder49719772013-02-11 12:33:24 -0600679 osd_data = &src->raw_data_in;
680 ceph_osdc_msg_data_add(req->r_reply, osd_data);
Alex Elderfbfab532013-02-08 09:55:48 -0600681 break;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700682 case CEPH_OSD_OP_READ:
683 case CEPH_OSD_OP_WRITE:
Li Wangad7a60d2013-08-15 11:51:44 +0800684 case CEPH_OSD_OP_ZERO:
685 case CEPH_OSD_OP_DELETE:
686 case CEPH_OSD_OP_TRUNCATE:
Alex Elder175face2013-03-08 13:35:36 -0600687 if (src->op == CEPH_OSD_OP_WRITE)
Alex Elder54d50642013-04-03 01:28:58 -0500688 request_data_len = src->extent.length;
Alex Elder175face2013-03-08 13:35:36 -0600689 dst->extent.offset = cpu_to_le64(src->extent.offset);
690 dst->extent.length = cpu_to_le64(src->extent.length);
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700691 dst->extent.truncate_size =
692 cpu_to_le64(src->extent.truncate_size);
693 dst->extent.truncate_seq =
694 cpu_to_le32(src->extent.truncate_seq);
Alex Elder04017e22013-04-05 14:46:02 -0500695 osd_data = &src->extent.osd_data;
Alex Elder54764922013-04-05 01:27:12 -0500696 if (src->op == CEPH_OSD_OP_WRITE)
Alex Elder04017e22013-04-05 14:46:02 -0500697 ceph_osdc_msg_data_add(req->r_request, osd_data);
Alex Elder54764922013-04-05 01:27:12 -0500698 else
Alex Elder04017e22013-04-05 14:46:02 -0500699 ceph_osdc_msg_data_add(req->r_reply, osd_data);
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700700 break;
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700701 case CEPH_OSD_OP_CALL:
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700702 dst->cls.class_len = src->cls.class_len;
703 dst->cls.method_len = src->cls.method_len;
Alex Elder04017e22013-04-05 14:46:02 -0500704 osd_data = &src->cls.request_info;
705 ceph_osdc_msg_data_add(req->r_request, osd_data);
706 BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_PAGELIST);
707 request_data_len = osd_data->pagelist->length;
708
709 osd_data = &src->cls.request_data;
710 data_length = ceph_osd_data_length(osd_data);
711 if (data_length) {
712 BUG_ON(osd_data->type == CEPH_OSD_DATA_TYPE_NONE);
713 dst->cls.indata_len = cpu_to_le32(data_length);
714 ceph_osdc_msg_data_add(req->r_request, osd_data);
715 src->payload_len += data_length;
716 request_data_len += data_length;
717 }
718 osd_data = &src->cls.response_data;
719 ceph_osdc_msg_data_add(req->r_reply, osd_data);
Yehuda Sadehae1533b2010-05-18 16:38:08 -0700720 break;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700721 case CEPH_OSD_OP_STARTSYNC:
722 break;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700723 case CEPH_OSD_OP_NOTIFY_ACK:
724 case CEPH_OSD_OP_WATCH:
725 dst->watch.cookie = cpu_to_le64(src->watch.cookie);
726 dst->watch.ver = cpu_to_le64(src->watch.ver);
727 dst->watch.flag = src->watch.flag;
728 break;
Ilya Dryomovc647b8a2014-02-25 16:22:27 +0200729 case CEPH_OSD_OP_SETALLOCHINT:
730 dst->alloc_hint.expected_object_size =
731 cpu_to_le64(src->alloc_hint.expected_object_size);
732 dst->alloc_hint.expected_write_size =
733 cpu_to_le64(src->alloc_hint.expected_write_size);
734 break;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700735 default:
Alex Elder4c464592013-02-15 11:42:30 -0600736 pr_err("unsupported osd opcode %s\n",
Alex Elder8f63ca22013-03-04 11:08:29 -0600737 ceph_osd_op_name(src->op));
Alex Elder4c464592013-02-15 11:42:30 -0600738 WARN_ON(1);
Alex Eldera8dd0a32013-03-13 20:50:00 -0500739
740 return 0;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700741 }
Ilya Dryomov7b25bf52014-02-25 16:22:26 +0200742
Alex Eldera8dd0a32013-03-13 20:50:00 -0500743 dst->op = cpu_to_le16(src->op);
Ilya Dryomov7b25bf52014-02-25 16:22:26 +0200744 dst->flags = cpu_to_le32(src->flags);
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700745 dst->payload_len = cpu_to_le32(src->payload_len);
Alex Elder175face2013-03-08 13:35:36 -0600746
Alex Elder54d50642013-04-03 01:28:58 -0500747 return request_data_len;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700748}
749
Yehuda Sadeh3499e8a2010-04-06 14:51:47 -0700750/*
Sage Weilf24e9982009-10-06 11:31:10 -0700751 * build new request AND message, calculate layout, and adjust file
752 * extent as needed.
753 *
754 * if the file was recently truncated, we include information about its
755 * old and new size so that the object can be updated appropriately. (we
756 * avoid synchronously deleting truncated objects because it's slow.)
757 *
758 * if @do_sync, include a 'startsync' command so that the osd will flush
759 * data quickly.
760 */
761struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
762 struct ceph_file_layout *layout,
763 struct ceph_vino vino,
Alex Elderacead002013-03-14 14:09:05 -0500764 u64 off, u64 *plen, int num_ops,
Sage Weilf24e9982009-10-06 11:31:10 -0700765 int opcode, int flags,
766 struct ceph_snap_context *snapc,
Sage Weilf24e9982009-10-06 11:31:10 -0700767 u32 truncate_seq,
768 u64 truncate_size,
Alex Elder153e5162013-03-01 18:00:15 -0600769 bool use_mempool)
Sage Weilf24e9982009-10-06 11:31:10 -0700770{
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700771 struct ceph_osd_request *req;
Alex Elder75d1c942013-03-13 20:50:00 -0500772 u64 objnum = 0;
773 u64 objoff = 0;
774 u64 objlen = 0;
Alex Elderd18d1e22013-03-13 20:50:01 -0500775 u32 object_size;
776 u64 object_base;
Sage Weil68162822012-09-24 21:01:02 -0700777 int r;
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700778
Li Wangad7a60d2013-08-15 11:51:44 +0800779 BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE &&
780 opcode != CEPH_OSD_OP_DELETE && opcode != CEPH_OSD_OP_ZERO &&
781 opcode != CEPH_OSD_OP_TRUNCATE);
Yehuda Sadeh68b44762010-04-06 15:01:27 -0700782
Alex Elderacead002013-03-14 14:09:05 -0500783 req = ceph_osdc_alloc_request(osdc, snapc, num_ops, use_mempool,
Alex Elderae7ca4a32012-11-13 21:11:15 -0600784 GFP_NOFS);
Sage Weil4ad12622011-05-03 09:23:36 -0700785 if (!req)
Sage Weil68162822012-09-24 21:01:02 -0700786 return ERR_PTR(-ENOMEM);
Alex Elder79528732013-04-03 21:32:51 -0500787
Alex Elderd178a9e2012-11-13 21:11:15 -0600788 req->r_flags = flags;
Sage Weilf24e9982009-10-06 11:31:10 -0700789
790 /* calculate max write size */
Alex Eldera19dadf2013-03-13 20:50:01 -0500791 r = calc_layout(layout, off, plen, &objnum, &objoff, &objlen);
Alex Elder3ff5f382013-02-15 22:10:17 -0600792 if (r < 0) {
793 ceph_osdc_put_request(req);
Sage Weil68162822012-09-24 21:01:02 -0700794 return ERR_PTR(r);
Alex Elder3ff5f382013-02-15 22:10:17 -0600795 }
Alex Eldera19dadf2013-03-13 20:50:01 -0500796
Alex Elderd18d1e22013-03-13 20:50:01 -0500797 object_size = le32_to_cpu(layout->fl_object_size);
798 object_base = off - objoff;
Yan, Zhengccca4e32013-06-02 18:40:23 +0800799 if (!(truncate_seq == 1 && truncate_size == -1ULL)) {
800 if (truncate_size <= object_base) {
801 truncate_size = 0;
802 } else {
803 truncate_size -= object_base;
804 if (truncate_size > object_size)
805 truncate_size = object_size;
806 }
Alex Eldera19dadf2013-03-13 20:50:01 -0500807 }
Alex Elderd18d1e22013-03-13 20:50:01 -0500808
Alex Elderc99d2d42013-04-05 01:27:11 -0500809 osd_req_op_extent_init(req, 0, opcode, objoff, objlen,
Alex Elderb0270322013-03-13 20:50:01 -0500810 truncate_size, truncate_seq);
Alex Elder8c042b02013-04-03 01:28:58 -0500811
Alex Elderacead002013-03-14 14:09:05 -0500812 /*
813 * A second op in the ops array means the caller wants to
814 * also issue a include a 'startsync' command so that the
815 * osd will flush data quickly.
816 */
817 if (num_ops > 1)
Alex Elderc99d2d42013-04-05 01:27:11 -0500818 osd_req_op_init(req, 1, CEPH_OSD_OP_STARTSYNC);
Alex Elderd18d1e22013-03-13 20:50:01 -0500819
Ilya Dryomov3c972c92014-01-27 17:40:20 +0200820 req->r_base_oloc.pool = ceph_file_layout_pg_pool(*layout);
Sage Weilf24e9982009-10-06 11:31:10 -0700821
Ilya Dryomov3c972c92014-01-27 17:40:20 +0200822 snprintf(req->r_base_oid.name, sizeof(req->r_base_oid.name),
Ilya Dryomov4295f222014-01-27 17:40:18 +0200823 "%llx.%08llx", vino.ino, objnum);
Ilya Dryomov3c972c92014-01-27 17:40:20 +0200824 req->r_base_oid.name_len = strlen(req->r_base_oid.name);
Alex Elderdbe0fc42013-02-15 22:10:17 -0600825
Sage Weilf24e9982009-10-06 11:31:10 -0700826 return req;
827}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -0700828EXPORT_SYMBOL(ceph_osdc_new_request);
Sage Weilf24e9982009-10-06 11:31:10 -0700829
830/*
831 * We keep osd requests in an rbtree, sorted by ->r_tid.
832 */
833static void __insert_request(struct ceph_osd_client *osdc,
834 struct ceph_osd_request *new)
835{
836 struct rb_node **p = &osdc->requests.rb_node;
837 struct rb_node *parent = NULL;
838 struct ceph_osd_request *req = NULL;
839
840 while (*p) {
841 parent = *p;
842 req = rb_entry(parent, struct ceph_osd_request, r_node);
843 if (new->r_tid < req->r_tid)
844 p = &(*p)->rb_left;
845 else if (new->r_tid > req->r_tid)
846 p = &(*p)->rb_right;
847 else
848 BUG();
849 }
850
851 rb_link_node(&new->r_node, parent, p);
852 rb_insert_color(&new->r_node, &osdc->requests);
853}
854
855static struct ceph_osd_request *__lookup_request(struct ceph_osd_client *osdc,
856 u64 tid)
857{
858 struct ceph_osd_request *req;
859 struct rb_node *n = osdc->requests.rb_node;
860
861 while (n) {
862 req = rb_entry(n, struct ceph_osd_request, r_node);
863 if (tid < req->r_tid)
864 n = n->rb_left;
865 else if (tid > req->r_tid)
866 n = n->rb_right;
867 else
868 return req;
869 }
870 return NULL;
871}
872
873static struct ceph_osd_request *
874__lookup_request_ge(struct ceph_osd_client *osdc,
875 u64 tid)
876{
877 struct ceph_osd_request *req;
878 struct rb_node *n = osdc->requests.rb_node;
879
880 while (n) {
881 req = rb_entry(n, struct ceph_osd_request, r_node);
882 if (tid < req->r_tid) {
883 if (!n->rb_left)
884 return req;
885 n = n->rb_left;
886 } else if (tid > req->r_tid) {
887 n = n->rb_right;
888 } else {
889 return req;
890 }
891 }
892 return NULL;
893}
894
Sage Weil6f6c7002011-01-17 20:34:08 -0800895/*
896 * Resubmit requests pending on the given osd.
897 */
898static void __kick_osd_requests(struct ceph_osd_client *osdc,
899 struct ceph_osd *osd)
900{
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700901 struct ceph_osd_request *req, *nreq;
Alex Eldere02493c2013-03-25 18:16:11 -0500902 LIST_HEAD(resend);
Sage Weil6f6c7002011-01-17 20:34:08 -0800903 int err;
904
905 dout("__kick_osd_requests osd%d\n", osd->o_osd);
906 err = __reset_osd(osdc, osd);
Alex Elder685a7552012-12-07 09:57:58 -0600907 if (err)
Sage Weil6f6c7002011-01-17 20:34:08 -0800908 return;
Alex Eldere02493c2013-03-25 18:16:11 -0500909 /*
910 * Build up a list of requests to resend by traversing the
911 * osd's list of requests. Requests for a given object are
912 * sent in tid order, and that is also the order they're
913 * kept on this list. Therefore all requests that are in
914 * flight will be found first, followed by all requests that
915 * have not yet been sent. And to resend requests while
916 * preserving this order we will want to put any sent
917 * requests back on the front of the osd client's unsent
918 * list.
919 *
920 * So we build a separate ordered list of already-sent
921 * requests for the affected osd and splice it onto the
922 * front of the osd client's unsent list. Once we've seen a
923 * request that has not yet been sent we're done. Those
924 * requests are already sitting right where they belong.
925 */
Sage Weil6f6c7002011-01-17 20:34:08 -0800926 list_for_each_entry(req, &osd->o_requests, r_osd_item) {
Alex Eldere02493c2013-03-25 18:16:11 -0500927 if (!req->r_sent)
928 break;
929 list_move_tail(&req->r_req_lru_item, &resend);
930 dout("requeueing %p tid %llu osd%d\n", req, req->r_tid,
Sage Weil6f6c7002011-01-17 20:34:08 -0800931 osd->o_osd);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700932 if (!req->r_linger)
933 req->r_flags |= CEPH_OSD_FLAG_RETRY;
934 }
Alex Eldere02493c2013-03-25 18:16:11 -0500935 list_splice(&resend, &osdc->req_unsent);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700936
Alex Eldere02493c2013-03-25 18:16:11 -0500937 /*
938 * Linger requests are re-registered before sending, which
939 * sets up a new tid for each. We add them to the unsent
940 * list at the end to keep things in tid order.
941 */
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700942 list_for_each_entry_safe(req, nreq, &osd->o_linger_requests,
Ilya Dryomov1d0326b2014-06-20 14:14:41 +0400943 r_linger_osd_item) {
Sage Weil77f38e02011-04-06 09:09:16 -0700944 /*
945 * reregister request prior to unregistering linger so
946 * that r_osd is preserved.
947 */
948 BUG_ON(!list_empty(&req->r_req_lru_item));
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700949 __register_request(osdc, req);
Alex Eldere02493c2013-03-25 18:16:11 -0500950 list_add_tail(&req->r_req_lru_item, &osdc->req_unsent);
Alex Elderad885922013-03-25 18:16:11 -0500951 list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
Sage Weil77f38e02011-04-06 09:09:16 -0700952 __unregister_linger_request(osdc, req);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700953 dout("requeued lingering %p tid %llu osd%d\n", req, req->r_tid,
954 osd->o_osd);
Sage Weil6f6c7002011-01-17 20:34:08 -0800955 }
956}
957
Sage Weilf24e9982009-10-06 11:31:10 -0700958/*
Sage Weil81b024e2009-10-09 10:29:18 -0700959 * If the osd connection drops, we need to resubmit all requests.
Sage Weilf24e9982009-10-06 11:31:10 -0700960 */
961static void osd_reset(struct ceph_connection *con)
962{
963 struct ceph_osd *osd = con->private;
964 struct ceph_osd_client *osdc;
965
966 if (!osd)
967 return;
968 dout("osd_reset osd%d\n", osd->o_osd);
969 osdc = osd->o_osdc;
Sage Weilf24e9982009-10-06 11:31:10 -0700970 down_read(&osdc->map_sem);
Sage Weil83aff952012-11-28 12:28:24 -0800971 mutex_lock(&osdc->request_mutex);
972 __kick_osd_requests(osdc, osd);
Alex Elderf9d25192013-02-15 11:42:29 -0600973 __send_queued(osdc);
Sage Weil83aff952012-11-28 12:28:24 -0800974 mutex_unlock(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -0700975 up_read(&osdc->map_sem);
976}
977
978/*
979 * Track open sessions with osds.
980 */
Alex Eldere10006f2012-05-26 23:26:43 -0500981static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
Sage Weilf24e9982009-10-06 11:31:10 -0700982{
983 struct ceph_osd *osd;
984
985 osd = kzalloc(sizeof(*osd), GFP_NOFS);
986 if (!osd)
987 return NULL;
988
989 atomic_set(&osd->o_ref, 1);
990 osd->o_osdc = osdc;
Alex Eldere10006f2012-05-26 23:26:43 -0500991 osd->o_osd = onum;
Alex Elderf4077312012-12-06 07:22:04 -0600992 RB_CLEAR_NODE(&osd->o_node);
Sage Weilf24e9982009-10-06 11:31:10 -0700993 INIT_LIST_HEAD(&osd->o_requests);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -0700994 INIT_LIST_HEAD(&osd->o_linger_requests);
Yehuda Sadehf5a20412010-02-03 11:00:26 -0800995 INIT_LIST_HEAD(&osd->o_osd_lru);
Sage Weilf24e9982009-10-06 11:31:10 -0700996 osd->o_incarnation = 1;
997
Sage Weilb7a9e5d2012-06-27 12:24:08 -0700998 ceph_con_init(&osd->o_con, osd, &osd_con_ops, &osdc->client->msgr);
Sage Weil4e7a5dc2009-11-18 16:19:57 -0800999
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001000 INIT_LIST_HEAD(&osd->o_keepalive_item);
Sage Weilf24e9982009-10-06 11:31:10 -07001001 return osd;
1002}
1003
1004static struct ceph_osd *get_osd(struct ceph_osd *osd)
1005{
1006 if (atomic_inc_not_zero(&osd->o_ref)) {
1007 dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1,
1008 atomic_read(&osd->o_ref));
1009 return osd;
1010 } else {
1011 dout("get_osd %p FAIL\n", osd);
1012 return NULL;
1013 }
1014}
1015
1016static void put_osd(struct ceph_osd *osd)
1017{
1018 dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref),
1019 atomic_read(&osd->o_ref) - 1);
Alex Eldera2556512012-05-16 15:16:39 -05001020 if (atomic_dec_and_test(&osd->o_ref) && osd->o_auth.authorizer) {
Sage Weil79494d12010-05-27 14:15:49 -07001021 struct ceph_auth_client *ac = osd->o_osdc->client->monc.auth;
1022
Sage Weil27859f92013-03-25 10:26:14 -07001023 ceph_auth_destroy_authorizer(ac, osd->o_auth.authorizer);
Sage Weilf24e9982009-10-06 11:31:10 -07001024 kfree(osd);
Sage Weil79494d12010-05-27 14:15:49 -07001025 }
Sage Weilf24e9982009-10-06 11:31:10 -07001026}
1027
1028/*
1029 * remove an osd from our map
1030 */
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001031static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
Sage Weilf24e9982009-10-06 11:31:10 -07001032{
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001033 dout("__remove_osd %p\n", osd);
Sage Weilf24e9982009-10-06 11:31:10 -07001034 BUG_ON(!list_empty(&osd->o_requests));
Ilya Dryomov7c6e6fc2014-06-18 13:02:12 +04001035 BUG_ON(!list_empty(&osd->o_linger_requests));
1036
Sage Weilf24e9982009-10-06 11:31:10 -07001037 rb_erase(&osd->o_node, &osdc->osds);
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001038 list_del_init(&osd->o_osd_lru);
Sage Weilf24e9982009-10-06 11:31:10 -07001039 ceph_con_close(&osd->o_con);
1040 put_osd(osd);
1041}
1042
Sage Weilaca420b2011-08-31 14:45:53 -07001043static void remove_all_osds(struct ceph_osd_client *osdc)
1044{
Jiaju Zhang048a9d22012-07-20 08:18:36 -05001045 dout("%s %p\n", __func__, osdc);
Sage Weilaca420b2011-08-31 14:45:53 -07001046 mutex_lock(&osdc->request_mutex);
1047 while (!RB_EMPTY_ROOT(&osdc->osds)) {
1048 struct ceph_osd *osd = rb_entry(rb_first(&osdc->osds),
1049 struct ceph_osd, o_node);
1050 __remove_osd(osdc, osd);
1051 }
1052 mutex_unlock(&osdc->request_mutex);
1053}
1054
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001055static void __move_osd_to_lru(struct ceph_osd_client *osdc,
1056 struct ceph_osd *osd)
1057{
Ilya Dryomovbbf37ec2014-06-20 14:14:41 +04001058 dout("%s %p\n", __func__, osd);
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001059 BUG_ON(!list_empty(&osd->o_osd_lru));
Ilya Dryomovbbf37ec2014-06-20 14:14:41 +04001060
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001061 list_add_tail(&osd->o_osd_lru, &osdc->osd_lru);
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001062 osd->lru_ttl = jiffies + osdc->client->options->osd_idle_ttl * HZ;
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001063}
1064
Ilya Dryomovbbf37ec2014-06-20 14:14:41 +04001065static void maybe_move_osd_to_lru(struct ceph_osd_client *osdc,
1066 struct ceph_osd *osd)
1067{
1068 dout("%s %p\n", __func__, osd);
1069
1070 if (list_empty(&osd->o_requests) &&
1071 list_empty(&osd->o_linger_requests))
1072 __move_osd_to_lru(osdc, osd);
1073}
1074
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001075static void __remove_osd_from_lru(struct ceph_osd *osd)
1076{
1077 dout("__remove_osd_from_lru %p\n", osd);
1078 if (!list_empty(&osd->o_osd_lru))
1079 list_del_init(&osd->o_osd_lru);
1080}
1081
Sage Weilaca420b2011-08-31 14:45:53 -07001082static void remove_old_osds(struct ceph_osd_client *osdc)
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001083{
1084 struct ceph_osd *osd, *nosd;
1085
1086 dout("__remove_old_osds %p\n", osdc);
1087 mutex_lock(&osdc->request_mutex);
1088 list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) {
Sage Weilaca420b2011-08-31 14:45:53 -07001089 if (time_before(jiffies, osd->lru_ttl))
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001090 break;
1091 __remove_osd(osdc, osd);
1092 }
1093 mutex_unlock(&osdc->request_mutex);
1094}
1095
Sage Weilf24e9982009-10-06 11:31:10 -07001096/*
1097 * reset osd connect
1098 */
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001099static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
Sage Weilf24e9982009-10-06 11:31:10 -07001100{
Alex Elderc3acb182012-12-07 09:57:58 -06001101 struct ceph_entity_addr *peer_addr;
Sage Weilf24e9982009-10-06 11:31:10 -07001102
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001103 dout("__reset_osd %p osd%d\n", osd, osd->o_osd);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001104 if (list_empty(&osd->o_requests) &&
1105 list_empty(&osd->o_linger_requests)) {
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001106 __remove_osd(osdc, osd);
Alex Elderc3acb182012-12-07 09:57:58 -06001107
1108 return -ENODEV;
1109 }
1110
1111 peer_addr = &osdc->osdmap->osd_addr[osd->o_osd];
1112 if (!memcmp(peer_addr, &osd->o_con.peer_addr, sizeof (*peer_addr)) &&
1113 !ceph_con_opened(&osd->o_con)) {
1114 struct ceph_osd_request *req;
1115
Ilya Dryomov0b4af2e2014-01-16 19:18:27 +02001116 dout("osd addr hasn't changed and connection never opened, "
1117 "letting msgr retry\n");
Sage Weil87b315a2010-03-22 14:51:18 -07001118 /* touch each r_stamp for handle_timeout()'s benfit */
1119 list_for_each_entry(req, &osd->o_requests, r_osd_item)
1120 req->r_stamp = jiffies;
Alex Elderc3acb182012-12-07 09:57:58 -06001121
1122 return -EAGAIN;
Sage Weilf24e9982009-10-06 11:31:10 -07001123 }
Alex Elderc3acb182012-12-07 09:57:58 -06001124
1125 ceph_con_close(&osd->o_con);
1126 ceph_con_open(&osd->o_con, CEPH_ENTITY_TYPE_OSD, osd->o_osd, peer_addr);
1127 osd->o_incarnation++;
1128
1129 return 0;
Sage Weilf24e9982009-10-06 11:31:10 -07001130}
1131
1132static void __insert_osd(struct ceph_osd_client *osdc, struct ceph_osd *new)
1133{
1134 struct rb_node **p = &osdc->osds.rb_node;
1135 struct rb_node *parent = NULL;
1136 struct ceph_osd *osd = NULL;
1137
Sage Weilaca420b2011-08-31 14:45:53 -07001138 dout("__insert_osd %p osd%d\n", new, new->o_osd);
Sage Weilf24e9982009-10-06 11:31:10 -07001139 while (*p) {
1140 parent = *p;
1141 osd = rb_entry(parent, struct ceph_osd, o_node);
1142 if (new->o_osd < osd->o_osd)
1143 p = &(*p)->rb_left;
1144 else if (new->o_osd > osd->o_osd)
1145 p = &(*p)->rb_right;
1146 else
1147 BUG();
1148 }
1149
1150 rb_link_node(&new->o_node, parent, p);
1151 rb_insert_color(&new->o_node, &osdc->osds);
1152}
1153
1154static struct ceph_osd *__lookup_osd(struct ceph_osd_client *osdc, int o)
1155{
1156 struct ceph_osd *osd;
1157 struct rb_node *n = osdc->osds.rb_node;
1158
1159 while (n) {
1160 osd = rb_entry(n, struct ceph_osd, o_node);
1161 if (o < osd->o_osd)
1162 n = n->rb_left;
1163 else if (o > osd->o_osd)
1164 n = n->rb_right;
1165 else
1166 return osd;
1167 }
1168 return NULL;
1169}
1170
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001171static void __schedule_osd_timeout(struct ceph_osd_client *osdc)
1172{
1173 schedule_delayed_work(&osdc->timeout_work,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001174 osdc->client->options->osd_keepalive_timeout * HZ);
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001175}
1176
1177static void __cancel_osd_timeout(struct ceph_osd_client *osdc)
1178{
1179 cancel_delayed_work(&osdc->timeout_work);
1180}
Sage Weilf24e9982009-10-06 11:31:10 -07001181
1182/*
1183 * Register request, assign tid. If this is the first request, set up
1184 * the timeout event.
1185 */
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001186static void __register_request(struct ceph_osd_client *osdc,
1187 struct ceph_osd_request *req)
Sage Weilf24e9982009-10-06 11:31:10 -07001188{
Sage Weilf24e9982009-10-06 11:31:10 -07001189 req->r_tid = ++osdc->last_tid;
Sage Weil6df058c2009-12-22 11:24:33 -08001190 req->r_request->hdr.tid = cpu_to_le64(req->r_tid);
Sage Weil77f38e02011-04-06 09:09:16 -07001191 dout("__register_request %p tid %lld\n", req, req->r_tid);
Sage Weilf24e9982009-10-06 11:31:10 -07001192 __insert_request(osdc, req);
1193 ceph_osdc_get_request(req);
1194 osdc->num_requests++;
Sage Weilf24e9982009-10-06 11:31:10 -07001195 if (osdc->num_requests == 1) {
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001196 dout(" first request, scheduling timeout\n");
1197 __schedule_osd_timeout(osdc);
Sage Weilf24e9982009-10-06 11:31:10 -07001198 }
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001199}
1200
Sage Weilf24e9982009-10-06 11:31:10 -07001201/*
1202 * called under osdc->request_mutex
1203 */
1204static void __unregister_request(struct ceph_osd_client *osdc,
1205 struct ceph_osd_request *req)
1206{
Sage Weil35f9f8a2012-05-16 15:16:38 -05001207 if (RB_EMPTY_NODE(&req->r_node)) {
1208 dout("__unregister_request %p tid %lld not registered\n",
1209 req, req->r_tid);
1210 return;
1211 }
1212
Sage Weilf24e9982009-10-06 11:31:10 -07001213 dout("__unregister_request %p tid %lld\n", req, req->r_tid);
1214 rb_erase(&req->r_node, &osdc->requests);
Ilya Dryomov6562d662014-06-20 14:14:42 +04001215 RB_CLEAR_NODE(&req->r_node);
Sage Weilf24e9982009-10-06 11:31:10 -07001216 osdc->num_requests--;
1217
Sage Weil0ba64782009-10-08 16:57:16 -07001218 if (req->r_osd) {
1219 /* make sure the original request isn't in flight. */
Alex Elder6740a842012-06-01 14:56:43 -05001220 ceph_msg_revoke(req->r_request);
Sage Weil0ba64782009-10-08 16:57:16 -07001221
1222 list_del_init(&req->r_osd_item);
Ilya Dryomovbbf37ec2014-06-20 14:14:41 +04001223 maybe_move_osd_to_lru(osdc, req->r_osd);
Ilya Dryomov4f234092014-06-20 18:29:20 +04001224 if (list_empty(&req->r_linger_osd_item))
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001225 req->r_osd = NULL;
Sage Weil0ba64782009-10-08 16:57:16 -07001226 }
Sage Weilf24e9982009-10-06 11:31:10 -07001227
Alex Elder7d5f2482012-11-29 08:37:03 -06001228 list_del_init(&req->r_req_lru_item);
Sage Weilf24e9982009-10-06 11:31:10 -07001229 ceph_osdc_put_request(req);
1230
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001231 if (osdc->num_requests == 0) {
1232 dout(" no requests, canceling timeout\n");
1233 __cancel_osd_timeout(osdc);
Sage Weilf24e9982009-10-06 11:31:10 -07001234 }
1235}
1236
1237/*
1238 * Cancel a previously queued request message
1239 */
1240static void __cancel_request(struct ceph_osd_request *req)
1241{
Sage Weil6bc18872010-09-27 10:18:52 -07001242 if (req->r_sent && req->r_osd) {
Alex Elder6740a842012-06-01 14:56:43 -05001243 ceph_msg_revoke(req->r_request);
Sage Weilf24e9982009-10-06 11:31:10 -07001244 req->r_sent = 0;
1245 }
1246}
1247
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001248static void __register_linger_request(struct ceph_osd_client *osdc,
1249 struct ceph_osd_request *req)
1250{
Ilya Dryomovaf593062014-06-20 18:29:20 +04001251 dout("%s %p tid %llu\n", __func__, req, req->r_tid);
1252 WARN_ON(!req->r_linger);
1253
Alex Elder96e4dac2013-05-22 20:54:25 -05001254 ceph_osdc_get_request(req);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001255 list_add_tail(&req->r_linger_item, &osdc->req_linger);
Sage Weil6194ea82012-07-30 16:19:28 -07001256 if (req->r_osd)
Ilya Dryomov1d0326b2014-06-20 14:14:41 +04001257 list_add_tail(&req->r_linger_osd_item,
Sage Weil6194ea82012-07-30 16:19:28 -07001258 &req->r_osd->o_linger_requests);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001259}
1260
1261static void __unregister_linger_request(struct ceph_osd_client *osdc,
1262 struct ceph_osd_request *req)
1263{
Ilya Dryomovaf593062014-06-20 18:29:20 +04001264 WARN_ON(!req->r_linger);
1265
1266 if (list_empty(&req->r_linger_item)) {
1267 dout("%s %p tid %llu not registered\n", __func__, req,
1268 req->r_tid);
1269 return;
1270 }
1271
1272 dout("%s %p tid %llu\n", __func__, req, req->r_tid);
Alex Elder61c74032012-12-06 09:37:23 -06001273 list_del_init(&req->r_linger_item);
Ilya Dryomovaf593062014-06-20 18:29:20 +04001274
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001275 if (req->r_osd) {
Ilya Dryomov1d0326b2014-06-20 14:14:41 +04001276 list_del_init(&req->r_linger_osd_item);
Ilya Dryomovbbf37ec2014-06-20 14:14:41 +04001277 maybe_move_osd_to_lru(osdc, req->r_osd);
Sage Weilfbdb9192011-03-29 12:11:06 -07001278 if (list_empty(&req->r_osd_item))
1279 req->r_osd = NULL;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001280 }
Alex Elder96e4dac2013-05-22 20:54:25 -05001281 ceph_osdc_put_request(req);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001282}
1283
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001284void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
1285 struct ceph_osd_request *req)
1286{
1287 if (!req->r_linger) {
1288 dout("set_request_linger %p\n", req);
1289 req->r_linger = 1;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001290 }
1291}
1292EXPORT_SYMBOL(ceph_osdc_set_request_linger);
1293
Sage Weilf24e9982009-10-06 11:31:10 -07001294/*
Josh Durgind29adb32013-12-02 19:11:48 -08001295 * Returns whether a request should be blocked from being sent
1296 * based on the current osdmap and osd_client settings.
1297 *
1298 * Caller should hold map_sem for read.
1299 */
1300static bool __req_should_be_paused(struct ceph_osd_client *osdc,
1301 struct ceph_osd_request *req)
1302{
1303 bool pauserd = ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSERD);
1304 bool pausewr = ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSEWR) ||
1305 ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL);
1306 return (req->r_flags & CEPH_OSD_FLAG_READ && pauserd) ||
1307 (req->r_flags & CEPH_OSD_FLAG_WRITE && pausewr);
1308}
1309
1310/*
Ilya Dryomov17a13e42014-01-27 17:40:19 +02001311 * Calculate mapping of a request to a PG. Takes tiering into account.
1312 */
1313static int __calc_request_pg(struct ceph_osdmap *osdmap,
1314 struct ceph_osd_request *req,
1315 struct ceph_pg *pg_out)
1316{
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001317 bool need_check_tiering;
1318
1319 need_check_tiering = false;
1320 if (req->r_target_oloc.pool == -1) {
1321 req->r_target_oloc = req->r_base_oloc; /* struct */
1322 need_check_tiering = true;
1323 }
1324 if (req->r_target_oid.name_len == 0) {
1325 ceph_oid_copy(&req->r_target_oid, &req->r_base_oid);
1326 need_check_tiering = true;
1327 }
1328
1329 if (need_check_tiering &&
1330 (req->r_flags & CEPH_OSD_FLAG_IGNORE_OVERLAY) == 0) {
Ilya Dryomov17a13e42014-01-27 17:40:19 +02001331 struct ceph_pg_pool_info *pi;
1332
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001333 pi = ceph_pg_pool_by_id(osdmap, req->r_target_oloc.pool);
Ilya Dryomov17a13e42014-01-27 17:40:19 +02001334 if (pi) {
1335 if ((req->r_flags & CEPH_OSD_FLAG_READ) &&
1336 pi->read_tier >= 0)
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001337 req->r_target_oloc.pool = pi->read_tier;
Ilya Dryomov17a13e42014-01-27 17:40:19 +02001338 if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
1339 pi->write_tier >= 0)
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001340 req->r_target_oloc.pool = pi->write_tier;
Ilya Dryomov17a13e42014-01-27 17:40:19 +02001341 }
1342 /* !pi is caught in ceph_oloc_oid_to_pg() */
1343 }
1344
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001345 return ceph_oloc_oid_to_pg(osdmap, &req->r_target_oloc,
1346 &req->r_target_oid, pg_out);
Ilya Dryomov17a13e42014-01-27 17:40:19 +02001347}
1348
Ilya Dryomovf671b582014-09-02 13:40:33 +04001349static void __enqueue_request(struct ceph_osd_request *req)
1350{
1351 struct ceph_osd_client *osdc = req->r_osdc;
1352
1353 dout("%s %p tid %llu to osd%d\n", __func__, req, req->r_tid,
1354 req->r_osd ? req->r_osd->o_osd : -1);
1355
1356 if (req->r_osd) {
1357 __remove_osd_from_lru(req->r_osd);
1358 list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
1359 list_move_tail(&req->r_req_lru_item, &osdc->req_unsent);
1360 } else {
1361 list_move_tail(&req->r_req_lru_item, &osdc->req_notarget);
1362 }
1363}
1364
Ilya Dryomov17a13e42014-01-27 17:40:19 +02001365/*
Sage Weilf24e9982009-10-06 11:31:10 -07001366 * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
1367 * (as needed), and set the request r_osd appropriately. If there is
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001368 * no up osd, set r_osd to NULL. Move the request to the appropriate list
Sage Weil6f6c7002011-01-17 20:34:08 -08001369 * (unsent, homeless) or leave on in-flight lru.
Sage Weilf24e9982009-10-06 11:31:10 -07001370 *
1371 * Return 0 if unchanged, 1 if changed, or negative on error.
1372 *
1373 * Caller should hold map_sem for read and request_mutex.
1374 */
Sage Weil6f6c7002011-01-17 20:34:08 -08001375static int __map_request(struct ceph_osd_client *osdc,
Sage Weil38d64532011-10-14 13:33:55 -07001376 struct ceph_osd_request *req, int force_resend)
Sage Weilf24e9982009-10-06 11:31:10 -07001377{
Sage Weil5b191d92013-02-23 10:38:16 -08001378 struct ceph_pg pgid;
Sage Weild85b7052010-05-10 10:24:48 -07001379 int acting[CEPH_PG_MAX_SIZE];
Ilya Dryomov8008ab12014-03-24 17:12:48 +02001380 int num, o;
Sage Weilf24e9982009-10-06 11:31:10 -07001381 int err;
Josh Durgind29adb32013-12-02 19:11:48 -08001382 bool was_paused;
Sage Weilf24e9982009-10-06 11:31:10 -07001383
Sage Weil6f6c7002011-01-17 20:34:08 -08001384 dout("map_request %p tid %lld\n", req, req->r_tid);
Ilya Dryomov17a13e42014-01-27 17:40:19 +02001385
1386 err = __calc_request_pg(osdc->osdmap, req, &pgid);
Sage Weil6f6c7002011-01-17 20:34:08 -08001387 if (err) {
1388 list_move(&req->r_req_lru_item, &osdc->req_notarget);
Sage Weilf24e9982009-10-06 11:31:10 -07001389 return err;
Sage Weil6f6c7002011-01-17 20:34:08 -08001390 }
Sage Weil7740a422010-01-08 15:58:25 -08001391 req->r_pgid = pgid;
1392
Ilya Dryomov8008ab12014-03-24 17:12:48 +02001393 num = ceph_calc_pg_acting(osdc->osdmap, pgid, acting, &o);
1394 if (num < 0)
1395 num = 0;
Sage Weilf24e9982009-10-06 11:31:10 -07001396
Josh Durgind29adb32013-12-02 19:11:48 -08001397 was_paused = req->r_paused;
1398 req->r_paused = __req_should_be_paused(osdc, req);
1399 if (was_paused && !req->r_paused)
1400 force_resend = 1;
1401
Sage Weil38d64532011-10-14 13:33:55 -07001402 if ((!force_resend &&
1403 req->r_osd && req->r_osd->o_osd == o &&
Sage Weild85b7052010-05-10 10:24:48 -07001404 req->r_sent >= req->r_osd->o_incarnation &&
1405 req->r_num_pg_osds == num &&
1406 memcmp(req->r_pg_osds, acting, sizeof(acting[0])*num) == 0) ||
Josh Durgind29adb32013-12-02 19:11:48 -08001407 (req->r_osd == NULL && o == -1) ||
1408 req->r_paused)
Sage Weilf24e9982009-10-06 11:31:10 -07001409 return 0; /* no change */
1410
Sage Weil5b191d92013-02-23 10:38:16 -08001411 dout("map_request tid %llu pgid %lld.%x osd%d (was osd%d)\n",
1412 req->r_tid, pgid.pool, pgid.seed, o,
Sage Weilf24e9982009-10-06 11:31:10 -07001413 req->r_osd ? req->r_osd->o_osd : -1);
1414
Sage Weild85b7052010-05-10 10:24:48 -07001415 /* record full pg acting set */
1416 memcpy(req->r_pg_osds, acting, sizeof(acting[0]) * num);
1417 req->r_num_pg_osds = num;
1418
Sage Weilf24e9982009-10-06 11:31:10 -07001419 if (req->r_osd) {
1420 __cancel_request(req);
1421 list_del_init(&req->r_osd_item);
Sage Weilf24e9982009-10-06 11:31:10 -07001422 req->r_osd = NULL;
1423 }
1424
1425 req->r_osd = __lookup_osd(osdc, o);
1426 if (!req->r_osd && o >= 0) {
Sage Weilc99eb1c2010-02-26 09:37:33 -08001427 err = -ENOMEM;
Alex Eldere10006f2012-05-26 23:26:43 -05001428 req->r_osd = create_osd(osdc, o);
Sage Weil6f6c7002011-01-17 20:34:08 -08001429 if (!req->r_osd) {
1430 list_move(&req->r_req_lru_item, &osdc->req_notarget);
Sage Weilc99eb1c2010-02-26 09:37:33 -08001431 goto out;
Sage Weil6f6c7002011-01-17 20:34:08 -08001432 }
Sage Weilf24e9982009-10-06 11:31:10 -07001433
Sage Weil6f6c7002011-01-17 20:34:08 -08001434 dout("map_request osd %p is osd%d\n", req->r_osd, o);
Sage Weilf24e9982009-10-06 11:31:10 -07001435 __insert_osd(osdc, req->r_osd);
1436
Sage Weilb7a9e5d2012-06-27 12:24:08 -07001437 ceph_con_open(&req->r_osd->o_con,
1438 CEPH_ENTITY_TYPE_OSD, o,
1439 &osdc->osdmap->osd_addr[o]);
Sage Weilf24e9982009-10-06 11:31:10 -07001440 }
1441
Ilya Dryomovf671b582014-09-02 13:40:33 +04001442 __enqueue_request(req);
Sage Weild85b7052010-05-10 10:24:48 -07001443 err = 1; /* osd or pg changed */
Sage Weilf24e9982009-10-06 11:31:10 -07001444
1445out:
Sage Weilf24e9982009-10-06 11:31:10 -07001446 return err;
1447}
1448
1449/*
1450 * caller should hold map_sem (for read) and request_mutex
1451 */
Sage Weil56e925b2012-01-03 12:34:34 -08001452static void __send_request(struct ceph_osd_client *osdc,
1453 struct ceph_osd_request *req)
Sage Weilf24e9982009-10-06 11:31:10 -07001454{
Sage Weil1b83bef2013-02-25 16:11:12 -08001455 void *p;
Sage Weilf24e9982009-10-06 11:31:10 -07001456
Sage Weil1b83bef2013-02-25 16:11:12 -08001457 dout("send_request %p tid %llu to osd%d flags %d pg %lld.%x\n",
1458 req, req->r_tid, req->r_osd->o_osd, req->r_flags,
1459 (unsigned long long)req->r_pgid.pool, req->r_pgid.seed);
Sage Weilf24e9982009-10-06 11:31:10 -07001460
Sage Weil1b83bef2013-02-25 16:11:12 -08001461 /* fill in message content that changes each time we send it */
1462 put_unaligned_le32(osdc->osdmap->epoch, req->r_request_osdmap_epoch);
1463 put_unaligned_le32(req->r_flags, req->r_request_flags);
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001464 put_unaligned_le64(req->r_target_oloc.pool, req->r_request_pool);
Sage Weil1b83bef2013-02-25 16:11:12 -08001465 p = req->r_request_pgid;
1466 ceph_encode_64(&p, req->r_pgid.pool);
1467 ceph_encode_32(&p, req->r_pgid.seed);
1468 put_unaligned_le64(1, req->r_request_attempts); /* FIXME */
1469 memcpy(req->r_request_reassert_version, &req->r_reassert_version,
1470 sizeof(req->r_reassert_version));
Sage Weil2169aea2013-02-25 16:13:08 -08001471
Sage Weil3dd72fc2010-03-22 14:42:30 -07001472 req->r_stamp = jiffies;
Henry C Chang07a27e22010-08-22 21:34:27 -07001473 list_move_tail(&req->r_req_lru_item, &osdc->req_lru);
Sage Weilf24e9982009-10-06 11:31:10 -07001474
1475 ceph_msg_get(req->r_request); /* send consumes a ref */
Alex Elder26be8802013-04-15 11:20:42 -05001476
Sage Weilf24e9982009-10-06 11:31:10 -07001477 req->r_sent = req->r_osd->o_incarnation;
Alex Elder26be8802013-04-15 11:20:42 -05001478
1479 ceph_con_send(&req->r_osd->o_con, req->r_request);
Sage Weilf24e9982009-10-06 11:31:10 -07001480}
1481
1482/*
Sage Weil6f6c7002011-01-17 20:34:08 -08001483 * Send any requests in the queue (req_unsent).
1484 */
Alex Elderf9d25192013-02-15 11:42:29 -06001485static void __send_queued(struct ceph_osd_client *osdc)
Sage Weil6f6c7002011-01-17 20:34:08 -08001486{
1487 struct ceph_osd_request *req, *tmp;
1488
Alex Elderf9d25192013-02-15 11:42:29 -06001489 dout("__send_queued\n");
1490 list_for_each_entry_safe(req, tmp, &osdc->req_unsent, r_req_lru_item)
Sage Weil6f6c7002011-01-17 20:34:08 -08001491 __send_request(osdc, req);
Sage Weil6f6c7002011-01-17 20:34:08 -08001492}
1493
1494/*
Ilya Dryomov0bbfdfe2014-01-31 19:33:39 +02001495 * Caller should hold map_sem for read and request_mutex.
1496 */
1497static int __ceph_osdc_start_request(struct ceph_osd_client *osdc,
1498 struct ceph_osd_request *req,
1499 bool nofail)
1500{
1501 int rc;
1502
1503 __register_request(osdc, req);
1504 req->r_sent = 0;
1505 req->r_got_reply = 0;
1506 rc = __map_request(osdc, req, 0);
1507 if (rc < 0) {
1508 if (nofail) {
1509 dout("osdc_start_request failed map, "
1510 " will retry %lld\n", req->r_tid);
1511 rc = 0;
1512 } else {
1513 __unregister_request(osdc, req);
1514 }
1515 return rc;
1516 }
1517
1518 if (req->r_osd == NULL) {
1519 dout("send_request %p no up osds in pg\n", req);
1520 ceph_monc_request_next_osdmap(&osdc->client->monc);
1521 } else {
1522 __send_queued(osdc);
1523 }
1524
1525 return 0;
1526}
1527
1528/*
Sage Weilf24e9982009-10-06 11:31:10 -07001529 * Timeout callback, called every N seconds when 1 or more osd
1530 * requests has been active for more than N seconds. When this
1531 * happens, we ping all OSDs with requests who have timed out to
1532 * ensure any communications channel reset is detected. Reset the
1533 * request timeouts another N seconds in the future as we go.
1534 * Reschedule the timeout event another N seconds in future (unless
1535 * there are no open requests).
1536 */
1537static void handle_timeout(struct work_struct *work)
1538{
1539 struct ceph_osd_client *osdc =
1540 container_of(work, struct ceph_osd_client, timeout_work.work);
Sage Weil83aff952012-11-28 12:28:24 -08001541 struct ceph_osd_request *req;
Sage Weilf24e9982009-10-06 11:31:10 -07001542 struct ceph_osd *osd;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001543 unsigned long keepalive =
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001544 osdc->client->options->osd_keepalive_timeout * HZ;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001545 struct list_head slow_osds;
Sage Weilf24e9982009-10-06 11:31:10 -07001546 dout("timeout\n");
1547 down_read(&osdc->map_sem);
1548
1549 ceph_monc_request_next_osdmap(&osdc->client->monc);
1550
1551 mutex_lock(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -07001552
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001553 /*
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001554 * ping osds that are a bit slow. this ensures that if there
1555 * is a break in the TCP connection we will notice, and reopen
1556 * a connection with that osd (from the fault callback).
1557 */
1558 INIT_LIST_HEAD(&slow_osds);
1559 list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) {
Sage Weil3dd72fc2010-03-22 14:42:30 -07001560 if (time_before(jiffies, req->r_stamp + keepalive))
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001561 break;
1562
1563 osd = req->r_osd;
1564 BUG_ON(!osd);
1565 dout(" tid %llu is slow, will send keepalive on osd%d\n",
Sage Weilf24e9982009-10-06 11:31:10 -07001566 req->r_tid, osd->o_osd);
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001567 list_move_tail(&osd->o_keepalive_item, &slow_osds);
1568 }
1569 while (!list_empty(&slow_osds)) {
1570 osd = list_entry(slow_osds.next, struct ceph_osd,
1571 o_keepalive_item);
1572 list_del_init(&osd->o_keepalive_item);
Sage Weilf24e9982009-10-06 11:31:10 -07001573 ceph_con_keepalive(&osd->o_con);
1574 }
1575
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001576 __schedule_osd_timeout(osdc);
Alex Elderf9d25192013-02-15 11:42:29 -06001577 __send_queued(osdc);
Sage Weilf24e9982009-10-06 11:31:10 -07001578 mutex_unlock(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -07001579 up_read(&osdc->map_sem);
1580}
1581
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001582static void handle_osds_timeout(struct work_struct *work)
1583{
1584 struct ceph_osd_client *osdc =
1585 container_of(work, struct ceph_osd_client,
1586 osds_timeout_work.work);
1587 unsigned long delay =
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07001588 osdc->client->options->osd_idle_ttl * HZ >> 2;
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001589
1590 dout("osds timeout\n");
1591 down_read(&osdc->map_sem);
Sage Weilaca420b2011-08-31 14:45:53 -07001592 remove_old_osds(osdc);
Yehuda Sadehf5a20412010-02-03 11:00:26 -08001593 up_read(&osdc->map_sem);
1594
1595 schedule_delayed_work(&osdc->osds_timeout_work,
1596 round_jiffies_relative(delay));
1597}
1598
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001599static int ceph_oloc_decode(void **p, void *end,
1600 struct ceph_object_locator *oloc)
1601{
1602 u8 struct_v, struct_cv;
1603 u32 len;
1604 void *struct_end;
1605 int ret = 0;
1606
1607 ceph_decode_need(p, end, 1 + 1 + 4, e_inval);
1608 struct_v = ceph_decode_8(p);
1609 struct_cv = ceph_decode_8(p);
1610 if (struct_v < 3) {
1611 pr_warn("got v %d < 3 cv %d of ceph_object_locator\n",
1612 struct_v, struct_cv);
1613 goto e_inval;
1614 }
1615 if (struct_cv > 6) {
1616 pr_warn("got v %d cv %d > 6 of ceph_object_locator\n",
1617 struct_v, struct_cv);
1618 goto e_inval;
1619 }
1620 len = ceph_decode_32(p);
1621 ceph_decode_need(p, end, len, e_inval);
1622 struct_end = *p + len;
1623
1624 oloc->pool = ceph_decode_64(p);
1625 *p += 4; /* skip preferred */
1626
1627 len = ceph_decode_32(p);
1628 if (len > 0) {
1629 pr_warn("ceph_object_locator::key is set\n");
1630 goto e_inval;
1631 }
1632
1633 if (struct_v >= 5) {
1634 len = ceph_decode_32(p);
1635 if (len > 0) {
1636 pr_warn("ceph_object_locator::nspace is set\n");
1637 goto e_inval;
1638 }
1639 }
1640
1641 if (struct_v >= 6) {
1642 s64 hash = ceph_decode_64(p);
1643 if (hash != -1) {
1644 pr_warn("ceph_object_locator::hash is set\n");
1645 goto e_inval;
1646 }
1647 }
1648
1649 /* skip the rest */
1650 *p = struct_end;
1651out:
1652 return ret;
1653
1654e_inval:
1655 ret = -EINVAL;
1656 goto out;
1657}
1658
1659static int ceph_redirect_decode(void **p, void *end,
1660 struct ceph_request_redirect *redir)
1661{
1662 u8 struct_v, struct_cv;
1663 u32 len;
1664 void *struct_end;
1665 int ret;
1666
1667 ceph_decode_need(p, end, 1 + 1 + 4, e_inval);
1668 struct_v = ceph_decode_8(p);
1669 struct_cv = ceph_decode_8(p);
1670 if (struct_cv > 1) {
1671 pr_warn("got v %d cv %d > 1 of ceph_request_redirect\n",
1672 struct_v, struct_cv);
1673 goto e_inval;
1674 }
1675 len = ceph_decode_32(p);
1676 ceph_decode_need(p, end, len, e_inval);
1677 struct_end = *p + len;
1678
1679 ret = ceph_oloc_decode(p, end, &redir->oloc);
1680 if (ret)
1681 goto out;
1682
1683 len = ceph_decode_32(p);
1684 if (len > 0) {
1685 pr_warn("ceph_request_redirect::object_name is set\n");
1686 goto e_inval;
1687 }
1688
1689 len = ceph_decode_32(p);
1690 *p += len; /* skip osd_instructions */
1691
1692 /* skip the rest */
1693 *p = struct_end;
1694out:
1695 return ret;
1696
1697e_inval:
1698 ret = -EINVAL;
1699 goto out;
1700}
1701
Sage Weil25845472011-06-03 09:37:09 -07001702static void complete_request(struct ceph_osd_request *req)
1703{
Sage Weil25845472011-06-03 09:37:09 -07001704 complete_all(&req->r_safe_completion); /* fsync waiter */
1705}
1706
Sage Weilf24e9982009-10-06 11:31:10 -07001707/*
1708 * handle osd op reply. either call the callback if it is specified,
1709 * or do the completion to wake up the waiting thread.
1710 */
Sage Weil350b1c32009-12-22 10:45:45 -08001711static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg,
1712 struct ceph_connection *con)
Sage Weilf24e9982009-10-06 11:31:10 -07001713{
Sage Weil1b83bef2013-02-25 16:11:12 -08001714 void *p, *end;
Sage Weilf24e9982009-10-06 11:31:10 -07001715 struct ceph_osd_request *req;
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001716 struct ceph_request_redirect redir;
Sage Weilf24e9982009-10-06 11:31:10 -07001717 u64 tid;
Sage Weil1b83bef2013-02-25 16:11:12 -08001718 int object_len;
Alex Elder79528732013-04-03 21:32:51 -05001719 unsigned int numops;
1720 int payload_len, flags;
Sage Weil0ceed5d2010-05-11 09:53:18 -07001721 s32 result;
Sage Weil1b83bef2013-02-25 16:11:12 -08001722 s32 retry_attempt;
1723 struct ceph_pg pg;
1724 int err;
1725 u32 reassert_epoch;
1726 u64 reassert_version;
1727 u32 osdmap_epoch;
Alex Elder0d5af162013-02-27 10:26:25 -06001728 int already_completed;
Alex Elder9fc6e062013-04-03 01:28:57 -05001729 u32 bytes;
Alex Elder79528732013-04-03 21:32:51 -05001730 unsigned int i;
Sage Weilf24e9982009-10-06 11:31:10 -07001731
Sage Weil6df058c2009-12-22 11:24:33 -08001732 tid = le64_to_cpu(msg->hdr.tid);
Sage Weil1b83bef2013-02-25 16:11:12 -08001733 dout("handle_reply %p tid %llu\n", msg, tid);
1734
1735 p = msg->front.iov_base;
1736 end = p + msg->front.iov_len;
1737
1738 ceph_decode_need(&p, end, 4, bad);
1739 object_len = ceph_decode_32(&p);
1740 ceph_decode_need(&p, end, object_len, bad);
1741 p += object_len;
1742
Alex Elderef4859d2013-04-01 18:58:26 -05001743 err = ceph_decode_pgid(&p, end, &pg);
Sage Weil1b83bef2013-02-25 16:11:12 -08001744 if (err)
Sage Weilf24e9982009-10-06 11:31:10 -07001745 goto bad;
Sage Weil1b83bef2013-02-25 16:11:12 -08001746
1747 ceph_decode_need(&p, end, 8 + 4 + 4 + 8 + 4, bad);
1748 flags = ceph_decode_64(&p);
1749 result = ceph_decode_32(&p);
1750 reassert_epoch = ceph_decode_32(&p);
1751 reassert_version = ceph_decode_64(&p);
1752 osdmap_epoch = ceph_decode_32(&p);
1753
Sage Weilf24e9982009-10-06 11:31:10 -07001754 /* lookup */
Ilya Dryomovff513ac2014-02-03 13:56:33 +02001755 down_read(&osdc->map_sem);
Sage Weilf24e9982009-10-06 11:31:10 -07001756 mutex_lock(&osdc->request_mutex);
1757 req = __lookup_request(osdc, tid);
1758 if (req == NULL) {
1759 dout("handle_reply tid %llu dne\n", tid);
Alex Elder8058fd42013-04-01 18:58:26 -05001760 goto bad_mutex;
Sage Weilf24e9982009-10-06 11:31:10 -07001761 }
1762 ceph_osdc_get_request(req);
Sage Weil1b83bef2013-02-25 16:11:12 -08001763
1764 dout("handle_reply %p tid %llu req %p result %d\n", msg, tid,
1765 req, result);
1766
Dan Carpenter18741192013-08-15 08:51:58 +03001767 ceph_decode_need(&p, end, 4, bad_put);
Sage Weil1b83bef2013-02-25 16:11:12 -08001768 numops = ceph_decode_32(&p);
1769 if (numops > CEPH_OSD_MAX_OP)
1770 goto bad_put;
1771 if (numops != req->r_num_ops)
1772 goto bad_put;
1773 payload_len = 0;
Dan Carpenter18741192013-08-15 08:51:58 +03001774 ceph_decode_need(&p, end, numops * sizeof(struct ceph_osd_op), bad_put);
Sage Weil1b83bef2013-02-25 16:11:12 -08001775 for (i = 0; i < numops; i++) {
1776 struct ceph_osd_op *op = p;
1777 int len;
1778
1779 len = le32_to_cpu(op->payload_len);
1780 req->r_reply_op_len[i] = len;
1781 dout(" op %d has %d bytes\n", i, len);
1782 payload_len += len;
1783 p += sizeof(*op);
1784 }
Alex Elder9fc6e062013-04-03 01:28:57 -05001785 bytes = le32_to_cpu(msg->hdr.data_len);
1786 if (payload_len != bytes) {
Sage Weil1b83bef2013-02-25 16:11:12 -08001787 pr_warning("sum of op payload lens %d != data_len %d",
Alex Elder9fc6e062013-04-03 01:28:57 -05001788 payload_len, bytes);
Sage Weil1b83bef2013-02-25 16:11:12 -08001789 goto bad_put;
1790 }
1791
Dan Carpenter18741192013-08-15 08:51:58 +03001792 ceph_decode_need(&p, end, 4 + numops * 4, bad_put);
Sage Weil1b83bef2013-02-25 16:11:12 -08001793 retry_attempt = ceph_decode_32(&p);
1794 for (i = 0; i < numops; i++)
1795 req->r_reply_op_result[i] = ceph_decode_32(&p);
Sage Weilf24e9982009-10-06 11:31:10 -07001796
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001797 if (le16_to_cpu(msg->hdr.version) >= 6) {
1798 p += 8 + 4; /* skip replay_version */
1799 p += 8; /* skip user_version */
1800
1801 err = ceph_redirect_decode(&p, end, &redir);
1802 if (err)
1803 goto bad_put;
1804 } else {
1805 redir.oloc.pool = -1;
1806 }
1807
1808 if (redir.oloc.pool != -1) {
1809 dout("redirect pool %lld\n", redir.oloc.pool);
1810
1811 __unregister_request(osdc, req);
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001812
1813 req->r_target_oloc = redir.oloc; /* struct */
1814
1815 /*
1816 * Start redirect requests with nofail=true. If
1817 * mapping fails, request will end up on the notarget
1818 * list, waiting for the new osdmap (which can take
1819 * a while), even though the original request mapped
1820 * successfully. In the future we might want to follow
1821 * original request's nofail setting here.
1822 */
Ilya Dryomovff513ac2014-02-03 13:56:33 +02001823 err = __ceph_osdc_start_request(osdc, req, true);
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001824 BUG_ON(err);
1825
Ilya Dryomovff513ac2014-02-03 13:56:33 +02001826 goto out_unlock;
Ilya Dryomov205ee1182014-01-27 17:40:20 +02001827 }
1828
Yan, Zhengeb845ff2013-05-31 15:54:44 +08001829 already_completed = req->r_got_reply;
Sage Weilf24e9982009-10-06 11:31:10 -07001830 if (!req->r_got_reply) {
Sage Weil1b83bef2013-02-25 16:11:12 -08001831 req->r_result = result;
Sage Weilf24e9982009-10-06 11:31:10 -07001832 dout("handle_reply result %d bytes %d\n", req->r_result,
1833 bytes);
1834 if (req->r_result == 0)
1835 req->r_result = bytes;
1836
1837 /* in case this is a write and we need to replay, */
Sage Weil1b83bef2013-02-25 16:11:12 -08001838 req->r_reassert_version.epoch = cpu_to_le32(reassert_epoch);
1839 req->r_reassert_version.version = cpu_to_le64(reassert_version);
Sage Weilf24e9982009-10-06 11:31:10 -07001840
1841 req->r_got_reply = 1;
1842 } else if ((flags & CEPH_OSD_FLAG_ONDISK) == 0) {
1843 dout("handle_reply tid %llu dup ack\n", tid);
Ilya Dryomovff513ac2014-02-03 13:56:33 +02001844 goto out_unlock;
Sage Weilf24e9982009-10-06 11:31:10 -07001845 }
1846
1847 dout("handle_reply tid %llu flags %d\n", tid, flags);
1848
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001849 if (req->r_linger && (flags & CEPH_OSD_FLAG_ONDISK))
1850 __register_linger_request(osdc, req);
1851
Sage Weilf24e9982009-10-06 11:31:10 -07001852 /* either this is a read, or we got the safe response */
Sage Weil0ceed5d2010-05-11 09:53:18 -07001853 if (result < 0 ||
1854 (flags & CEPH_OSD_FLAG_ONDISK) ||
Sage Weilf24e9982009-10-06 11:31:10 -07001855 ((flags & CEPH_OSD_FLAG_WRITE) == 0))
1856 __unregister_request(osdc, req);
1857
1858 mutex_unlock(&osdc->request_mutex);
Ilya Dryomovff513ac2014-02-03 13:56:33 +02001859 up_read(&osdc->map_sem);
Sage Weilf24e9982009-10-06 11:31:10 -07001860
Yan, Zhengeb845ff2013-05-31 15:54:44 +08001861 if (!already_completed) {
Yan, Zheng61c5d6b2013-06-24 14:41:27 +08001862 if (req->r_unsafe_callback &&
1863 result >= 0 && !(flags & CEPH_OSD_FLAG_ONDISK))
1864 req->r_unsafe_callback(req, true);
Yan, Zhengeb845ff2013-05-31 15:54:44 +08001865 if (req->r_callback)
1866 req->r_callback(req, msg);
1867 else
1868 complete_all(&req->r_completion);
1869 }
Sage Weilf24e9982009-10-06 11:31:10 -07001870
Yan, Zheng61c5d6b2013-06-24 14:41:27 +08001871 if (flags & CEPH_OSD_FLAG_ONDISK) {
1872 if (req->r_unsafe_callback && already_completed)
1873 req->r_unsafe_callback(req, false);
Sage Weil25845472011-06-03 09:37:09 -07001874 complete_request(req);
Yan, Zheng61c5d6b2013-06-24 14:41:27 +08001875 }
Sage Weilf24e9982009-10-06 11:31:10 -07001876
Ilya Dryomovff513ac2014-02-03 13:56:33 +02001877out:
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001878 dout("req=%p req->r_linger=%d\n", req, req->r_linger);
Sage Weilf24e9982009-10-06 11:31:10 -07001879 ceph_osdc_put_request(req);
1880 return;
Ilya Dryomovff513ac2014-02-03 13:56:33 +02001881out_unlock:
1882 mutex_unlock(&osdc->request_mutex);
1883 up_read(&osdc->map_sem);
1884 goto out;
Sage Weilf24e9982009-10-06 11:31:10 -07001885
Sage Weil1b83bef2013-02-25 16:11:12 -08001886bad_put:
Li Wang37c89bd2013-11-27 22:28:14 +08001887 req->r_result = -EIO;
1888 __unregister_request(osdc, req);
1889 if (req->r_callback)
1890 req->r_callback(req, msg);
1891 else
1892 complete_all(&req->r_completion);
1893 complete_request(req);
Sage Weil1b83bef2013-02-25 16:11:12 -08001894 ceph_osdc_put_request(req);
Alex Elder8058fd42013-04-01 18:58:26 -05001895bad_mutex:
1896 mutex_unlock(&osdc->request_mutex);
Ilya Dryomovff513ac2014-02-03 13:56:33 +02001897 up_read(&osdc->map_sem);
Sage Weilf24e9982009-10-06 11:31:10 -07001898bad:
Sage Weil1b83bef2013-02-25 16:11:12 -08001899 pr_err("corrupt osd_op_reply got %d %d\n",
1900 (int)msg->front.iov_len, le32_to_cpu(msg->hdr.front_len));
Sage Weil9ec7cab2009-12-14 15:13:47 -08001901 ceph_msg_dump(msg);
Sage Weilf24e9982009-10-06 11:31:10 -07001902}
1903
Sage Weil6f6c7002011-01-17 20:34:08 -08001904static void reset_changed_osds(struct ceph_osd_client *osdc)
Sage Weilf24e9982009-10-06 11:31:10 -07001905{
Sage Weilf24e9982009-10-06 11:31:10 -07001906 struct rb_node *p, *n;
Sage Weilf24e9982009-10-06 11:31:10 -07001907
Sage Weil6f6c7002011-01-17 20:34:08 -08001908 for (p = rb_first(&osdc->osds); p; p = n) {
1909 struct ceph_osd *osd = rb_entry(p, struct ceph_osd, o_node);
Sage Weilf24e9982009-10-06 11:31:10 -07001910
Sage Weil6f6c7002011-01-17 20:34:08 -08001911 n = rb_next(p);
1912 if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) ||
1913 memcmp(&osd->o_con.peer_addr,
1914 ceph_osd_addr(osdc->osdmap,
1915 osd->o_osd),
1916 sizeof(struct ceph_entity_addr)) != 0)
1917 __reset_osd(osdc, osd);
Sage Weilf24e9982009-10-06 11:31:10 -07001918 }
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001919}
1920
1921/*
Sage Weil6f6c7002011-01-17 20:34:08 -08001922 * Requeue requests whose mapping to an OSD has changed. If requests map to
1923 * no osd, request a new map.
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001924 *
Alex Eldere6d50f62012-12-26 14:31:40 -06001925 * Caller should hold map_sem for read.
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001926 */
Josh Durgin9a1ea2d2013-12-10 09:35:13 -08001927static void kick_requests(struct ceph_osd_client *osdc, bool force_resend,
1928 bool force_resend_writes)
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001929{
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001930 struct ceph_osd_request *req, *nreq;
Sage Weil6f6c7002011-01-17 20:34:08 -08001931 struct rb_node *p;
1932 int needmap = 0;
1933 int err;
Josh Durgin9a1ea2d2013-12-10 09:35:13 -08001934 bool force_resend_req;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001935
Josh Durgin9a1ea2d2013-12-10 09:35:13 -08001936 dout("kick_requests %s %s\n", force_resend ? " (force resend)" : "",
1937 force_resend_writes ? " (force resend writes)" : "");
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08001938 mutex_lock(&osdc->request_mutex);
Sage Weil6194ea82012-07-30 16:19:28 -07001939 for (p = rb_first(&osdc->requests); p; ) {
Sage Weil6f6c7002011-01-17 20:34:08 -08001940 req = rb_entry(p, struct ceph_osd_request, r_node);
Sage Weil6194ea82012-07-30 16:19:28 -07001941 p = rb_next(p);
Alex Elderab60b162012-12-19 15:52:36 -06001942
1943 /*
1944 * For linger requests that have not yet been
1945 * registered, move them to the linger list; they'll
1946 * be sent to the osd in the loop below. Unregister
1947 * the request before re-registering it as a linger
1948 * request to ensure the __map_request() below
1949 * will decide it needs to be sent.
1950 */
1951 if (req->r_linger && list_empty(&req->r_linger_item)) {
1952 dout("%p tid %llu restart on osd%d\n",
1953 req, req->r_tid,
1954 req->r_osd ? req->r_osd->o_osd : -1);
Alex Elder96e4dac2013-05-22 20:54:25 -05001955 ceph_osdc_get_request(req);
Alex Elderab60b162012-12-19 15:52:36 -06001956 __unregister_request(osdc, req);
1957 __register_linger_request(osdc, req);
Alex Elder96e4dac2013-05-22 20:54:25 -05001958 ceph_osdc_put_request(req);
Alex Elderab60b162012-12-19 15:52:36 -06001959 continue;
1960 }
1961
Josh Durgin9a1ea2d2013-12-10 09:35:13 -08001962 force_resend_req = force_resend ||
1963 (force_resend_writes &&
1964 req->r_flags & CEPH_OSD_FLAG_WRITE);
1965 err = __map_request(osdc, req, force_resend_req);
Sage Weil6f6c7002011-01-17 20:34:08 -08001966 if (err < 0)
1967 continue; /* error */
1968 if (req->r_osd == NULL) {
1969 dout("%p tid %llu maps to no osd\n", req, req->r_tid);
1970 needmap++; /* request a newer map */
1971 } else if (err > 0) {
Sage Weil6194ea82012-07-30 16:19:28 -07001972 if (!req->r_linger) {
1973 dout("%p tid %llu requeued on osd%d\n", req,
1974 req->r_tid,
1975 req->r_osd ? req->r_osd->o_osd : -1);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001976 req->r_flags |= CEPH_OSD_FLAG_RETRY;
Sage Weil6194ea82012-07-30 16:19:28 -07001977 }
1978 }
Sage Weil6f6c7002011-01-17 20:34:08 -08001979 }
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001980
1981 list_for_each_entry_safe(req, nreq, &osdc->req_linger,
1982 r_linger_item) {
1983 dout("linger req=%p req->r_osd=%p\n", req, req->r_osd);
1984
Josh Durgin9a1ea2d2013-12-10 09:35:13 -08001985 err = __map_request(osdc, req,
1986 force_resend || force_resend_writes);
Alex Elderab60b162012-12-19 15:52:36 -06001987 dout("__map_request returned %d\n", err);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07001988 if (err == 0)
1989 continue; /* no change and no osd was specified */
1990 if (err < 0)
1991 continue; /* hrm! */
1992 if (req->r_osd == NULL) {
1993 dout("tid %llu maps to no valid osd\n", req->r_tid);
1994 needmap++; /* request a newer map */
1995 continue;
1996 }
1997
1998 dout("kicking lingering %p tid %llu osd%d\n", req, req->r_tid,
1999 req->r_osd ? req->r_osd->o_osd : -1);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002000 __register_request(osdc, req);
Alex Elderc89ce052012-12-06 07:22:04 -06002001 __unregister_linger_request(osdc, req);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002002 }
Alex Elder14d2f382013-05-15 16:28:33 -05002003 reset_changed_osds(osdc);
Sage Weilf24e9982009-10-06 11:31:10 -07002004 mutex_unlock(&osdc->request_mutex);
2005
2006 if (needmap) {
2007 dout("%d requests for down osds, need new map\n", needmap);
2008 ceph_monc_request_next_osdmap(&osdc->client->monc);
2009 }
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08002010}
Sage Weil6f6c7002011-01-17 20:34:08 -08002011
2012
Sage Weilf24e9982009-10-06 11:31:10 -07002013/*
2014 * Process updated osd map.
2015 *
2016 * The message contains any number of incremental and full maps, normally
2017 * indicating some sort of topology change in the cluster. Kick requests
2018 * off to different OSDs as needed.
2019 */
2020void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
2021{
2022 void *p, *end, *next;
2023 u32 nr_maps, maplen;
2024 u32 epoch;
2025 struct ceph_osdmap *newmap = NULL, *oldmap;
2026 int err;
2027 struct ceph_fsid fsid;
Josh Durgin9a1ea2d2013-12-10 09:35:13 -08002028 bool was_full;
Sage Weilf24e9982009-10-06 11:31:10 -07002029
2030 dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0);
2031 p = msg->front.iov_base;
2032 end = p + msg->front.iov_len;
2033
2034 /* verify fsid */
2035 ceph_decode_need(&p, end, sizeof(fsid), bad);
2036 ceph_decode_copy(&p, &fsid, sizeof(fsid));
Sage Weil07433042009-11-18 16:50:41 -08002037 if (ceph_check_fsid(osdc->client, &fsid) < 0)
2038 return;
Sage Weilf24e9982009-10-06 11:31:10 -07002039
2040 down_write(&osdc->map_sem);
2041
Josh Durgin9a1ea2d2013-12-10 09:35:13 -08002042 was_full = ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL);
2043
Sage Weilf24e9982009-10-06 11:31:10 -07002044 /* incremental maps */
2045 ceph_decode_32_safe(&p, end, nr_maps, bad);
2046 dout(" %d inc maps\n", nr_maps);
2047 while (nr_maps > 0) {
2048 ceph_decode_need(&p, end, 2*sizeof(u32), bad);
Sage Weilc89136e2009-10-14 09:59:09 -07002049 epoch = ceph_decode_32(&p);
2050 maplen = ceph_decode_32(&p);
Sage Weilf24e9982009-10-06 11:31:10 -07002051 ceph_decode_need(&p, end, maplen, bad);
2052 next = p + maplen;
2053 if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) {
2054 dout("applying incremental map %u len %d\n",
2055 epoch, maplen);
2056 newmap = osdmap_apply_incremental(&p, next,
2057 osdc->osdmap,
Alex Elder15d98822012-05-26 23:26:43 -05002058 &osdc->client->msgr);
Sage Weilf24e9982009-10-06 11:31:10 -07002059 if (IS_ERR(newmap)) {
2060 err = PTR_ERR(newmap);
2061 goto bad;
2062 }
Sage Weil30dc6382009-12-21 14:49:37 -08002063 BUG_ON(!newmap);
Sage Weilf24e9982009-10-06 11:31:10 -07002064 if (newmap != osdc->osdmap) {
2065 ceph_osdmap_destroy(osdc->osdmap);
2066 osdc->osdmap = newmap;
2067 }
Josh Durgin9a1ea2d2013-12-10 09:35:13 -08002068 was_full = was_full ||
2069 ceph_osdmap_flag(osdc->osdmap,
2070 CEPH_OSDMAP_FULL);
2071 kick_requests(osdc, 0, was_full);
Sage Weilf24e9982009-10-06 11:31:10 -07002072 } else {
2073 dout("ignoring incremental map %u len %d\n",
2074 epoch, maplen);
2075 }
2076 p = next;
2077 nr_maps--;
2078 }
2079 if (newmap)
2080 goto done;
2081
2082 /* full maps */
2083 ceph_decode_32_safe(&p, end, nr_maps, bad);
2084 dout(" %d full maps\n", nr_maps);
2085 while (nr_maps) {
2086 ceph_decode_need(&p, end, 2*sizeof(u32), bad);
Sage Weilc89136e2009-10-14 09:59:09 -07002087 epoch = ceph_decode_32(&p);
2088 maplen = ceph_decode_32(&p);
Sage Weilf24e9982009-10-06 11:31:10 -07002089 ceph_decode_need(&p, end, maplen, bad);
2090 if (nr_maps > 1) {
2091 dout("skipping non-latest full map %u len %d\n",
2092 epoch, maplen);
2093 } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) {
2094 dout("skipping full map %u len %d, "
2095 "older than our %u\n", epoch, maplen,
2096 osdc->osdmap->epoch);
2097 } else {
Sage Weil38d64532011-10-14 13:33:55 -07002098 int skipped_map = 0;
2099
Sage Weilf24e9982009-10-06 11:31:10 -07002100 dout("taking full map %u len %d\n", epoch, maplen);
Ilya Dryomova2505d62014-03-13 16:36:13 +02002101 newmap = ceph_osdmap_decode(&p, p+maplen);
Sage Weilf24e9982009-10-06 11:31:10 -07002102 if (IS_ERR(newmap)) {
2103 err = PTR_ERR(newmap);
2104 goto bad;
2105 }
Sage Weil30dc6382009-12-21 14:49:37 -08002106 BUG_ON(!newmap);
Sage Weilf24e9982009-10-06 11:31:10 -07002107 oldmap = osdc->osdmap;
2108 osdc->osdmap = newmap;
Sage Weil38d64532011-10-14 13:33:55 -07002109 if (oldmap) {
2110 if (oldmap->epoch + 1 < newmap->epoch)
2111 skipped_map = 1;
Sage Weilf24e9982009-10-06 11:31:10 -07002112 ceph_osdmap_destroy(oldmap);
Sage Weil38d64532011-10-14 13:33:55 -07002113 }
Josh Durgin9a1ea2d2013-12-10 09:35:13 -08002114 was_full = was_full ||
2115 ceph_osdmap_flag(osdc->osdmap,
2116 CEPH_OSDMAP_FULL);
2117 kick_requests(osdc, skipped_map, was_full);
Sage Weilf24e9982009-10-06 11:31:10 -07002118 }
2119 p += maplen;
2120 nr_maps--;
2121 }
2122
Dan Carpenterb72e19b2013-08-15 08:52:48 +03002123 if (!osdc->osdmap)
2124 goto bad;
Sage Weilf24e9982009-10-06 11:31:10 -07002125done:
2126 downgrade_write(&osdc->map_sem);
2127 ceph_monc_got_osdmap(&osdc->client->monc, osdc->osdmap->epoch);
Sage Weilcd634fb2011-05-12 09:29:18 -07002128
2129 /*
2130 * subscribe to subsequent osdmap updates if full to ensure
2131 * we find out when we are no longer full and stop returning
2132 * ENOSPC.
2133 */
Josh Durgind29adb32013-12-02 19:11:48 -08002134 if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL) ||
2135 ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSERD) ||
2136 ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSEWR))
Sage Weilcd634fb2011-05-12 09:29:18 -07002137 ceph_monc_request_next_osdmap(&osdc->client->monc);
2138
Alex Elderf9d25192013-02-15 11:42:29 -06002139 mutex_lock(&osdc->request_mutex);
2140 __send_queued(osdc);
2141 mutex_unlock(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -07002142 up_read(&osdc->map_sem);
Yehuda Sadeh03066f22010-07-27 13:11:08 -07002143 wake_up_all(&osdc->client->auth_wq);
Sage Weilf24e9982009-10-06 11:31:10 -07002144 return;
2145
2146bad:
2147 pr_err("osdc handle_map corrupt msg\n");
Sage Weil9ec7cab2009-12-14 15:13:47 -08002148 ceph_msg_dump(msg);
Sage Weilf24e9982009-10-06 11:31:10 -07002149 up_write(&osdc->map_sem);
Sage Weilf24e9982009-10-06 11:31:10 -07002150}
2151
Sage Weilf24e9982009-10-06 11:31:10 -07002152/*
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002153 * watch/notify callback event infrastructure
2154 *
2155 * These callbacks are used both for watch and notify operations.
2156 */
2157static void __release_event(struct kref *kref)
2158{
2159 struct ceph_osd_event *event =
2160 container_of(kref, struct ceph_osd_event, kref);
2161
2162 dout("__release_event %p\n", event);
2163 kfree(event);
2164}
2165
2166static void get_event(struct ceph_osd_event *event)
2167{
2168 kref_get(&event->kref);
2169}
2170
2171void ceph_osdc_put_event(struct ceph_osd_event *event)
2172{
2173 kref_put(&event->kref, __release_event);
2174}
2175EXPORT_SYMBOL(ceph_osdc_put_event);
2176
2177static void __insert_event(struct ceph_osd_client *osdc,
2178 struct ceph_osd_event *new)
2179{
2180 struct rb_node **p = &osdc->event_tree.rb_node;
2181 struct rb_node *parent = NULL;
2182 struct ceph_osd_event *event = NULL;
2183
2184 while (*p) {
2185 parent = *p;
2186 event = rb_entry(parent, struct ceph_osd_event, node);
2187 if (new->cookie < event->cookie)
2188 p = &(*p)->rb_left;
2189 else if (new->cookie > event->cookie)
2190 p = &(*p)->rb_right;
2191 else
2192 BUG();
2193 }
2194
2195 rb_link_node(&new->node, parent, p);
2196 rb_insert_color(&new->node, &osdc->event_tree);
2197}
2198
2199static struct ceph_osd_event *__find_event(struct ceph_osd_client *osdc,
2200 u64 cookie)
2201{
2202 struct rb_node **p = &osdc->event_tree.rb_node;
2203 struct rb_node *parent = NULL;
2204 struct ceph_osd_event *event = NULL;
2205
2206 while (*p) {
2207 parent = *p;
2208 event = rb_entry(parent, struct ceph_osd_event, node);
2209 if (cookie < event->cookie)
2210 p = &(*p)->rb_left;
2211 else if (cookie > event->cookie)
2212 p = &(*p)->rb_right;
2213 else
2214 return event;
2215 }
2216 return NULL;
2217}
2218
2219static void __remove_event(struct ceph_osd_event *event)
2220{
2221 struct ceph_osd_client *osdc = event->osdc;
2222
2223 if (!RB_EMPTY_NODE(&event->node)) {
2224 dout("__remove_event removed %p\n", event);
2225 rb_erase(&event->node, &osdc->event_tree);
2226 ceph_osdc_put_event(event);
2227 } else {
2228 dout("__remove_event didn't remove %p\n", event);
2229 }
2230}
2231
2232int ceph_osdc_create_event(struct ceph_osd_client *osdc,
2233 void (*event_cb)(u64, u64, u8, void *),
Alex Elder3c663bb2013-02-15 11:42:30 -06002234 void *data, struct ceph_osd_event **pevent)
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002235{
2236 struct ceph_osd_event *event;
2237
2238 event = kmalloc(sizeof(*event), GFP_NOIO);
2239 if (!event)
2240 return -ENOMEM;
2241
2242 dout("create_event %p\n", event);
2243 event->cb = event_cb;
Alex Elder3c663bb2013-02-15 11:42:30 -06002244 event->one_shot = 0;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002245 event->data = data;
2246 event->osdc = osdc;
2247 INIT_LIST_HEAD(&event->osd_node);
Alex Elder3ee52342012-12-17 12:23:48 -06002248 RB_CLEAR_NODE(&event->node);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002249 kref_init(&event->kref); /* one ref for us */
2250 kref_get(&event->kref); /* one ref for the caller */
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002251
2252 spin_lock(&osdc->event_lock);
2253 event->cookie = ++osdc->event_count;
2254 __insert_event(osdc, event);
2255 spin_unlock(&osdc->event_lock);
2256
2257 *pevent = event;
2258 return 0;
2259}
2260EXPORT_SYMBOL(ceph_osdc_create_event);
2261
2262void ceph_osdc_cancel_event(struct ceph_osd_event *event)
2263{
2264 struct ceph_osd_client *osdc = event->osdc;
2265
2266 dout("cancel_event %p\n", event);
2267 spin_lock(&osdc->event_lock);
2268 __remove_event(event);
2269 spin_unlock(&osdc->event_lock);
2270 ceph_osdc_put_event(event); /* caller's */
2271}
2272EXPORT_SYMBOL(ceph_osdc_cancel_event);
2273
2274
2275static void do_event_work(struct work_struct *work)
2276{
2277 struct ceph_osd_event_work *event_work =
2278 container_of(work, struct ceph_osd_event_work, work);
2279 struct ceph_osd_event *event = event_work->event;
2280 u64 ver = event_work->ver;
2281 u64 notify_id = event_work->notify_id;
2282 u8 opcode = event_work->opcode;
2283
2284 dout("do_event_work completing %p\n", event);
2285 event->cb(ver, notify_id, opcode, event->data);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002286 dout("do_event_work completed %p\n", event);
2287 ceph_osdc_put_event(event);
2288 kfree(event_work);
2289}
2290
2291
2292/*
2293 * Process osd watch notifications
2294 */
Alex Elder3c663bb2013-02-15 11:42:30 -06002295static void handle_watch_notify(struct ceph_osd_client *osdc,
2296 struct ceph_msg *msg)
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002297{
2298 void *p, *end;
2299 u8 proto_ver;
2300 u64 cookie, ver, notify_id;
2301 u8 opcode;
2302 struct ceph_osd_event *event;
2303 struct ceph_osd_event_work *event_work;
2304
2305 p = msg->front.iov_base;
2306 end = p + msg->front.iov_len;
2307
2308 ceph_decode_8_safe(&p, end, proto_ver, bad);
2309 ceph_decode_8_safe(&p, end, opcode, bad);
2310 ceph_decode_64_safe(&p, end, cookie, bad);
2311 ceph_decode_64_safe(&p, end, ver, bad);
2312 ceph_decode_64_safe(&p, end, notify_id, bad);
2313
2314 spin_lock(&osdc->event_lock);
2315 event = __find_event(osdc, cookie);
2316 if (event) {
Alex Elder3c663bb2013-02-15 11:42:30 -06002317 BUG_ON(event->one_shot);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002318 get_event(event);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002319 }
2320 spin_unlock(&osdc->event_lock);
2321 dout("handle_watch_notify cookie %lld ver %lld event %p\n",
2322 cookie, ver, event);
2323 if (event) {
2324 event_work = kmalloc(sizeof(*event_work), GFP_NOIO);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002325 if (!event_work) {
2326 dout("ERROR: could not allocate event_work\n");
2327 goto done_err;
2328 }
Mariusz Kozlowski6b0ae402011-03-26 19:29:34 +01002329 INIT_WORK(&event_work->work, do_event_work);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002330 event_work->event = event;
2331 event_work->ver = ver;
2332 event_work->notify_id = notify_id;
2333 event_work->opcode = opcode;
2334 if (!queue_work(osdc->notify_wq, &event_work->work)) {
2335 dout("WARNING: failed to queue notify event work\n");
2336 goto done_err;
2337 }
2338 }
2339
2340 return;
2341
2342done_err:
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002343 ceph_osdc_put_event(event);
2344 return;
2345
2346bad:
2347 pr_err("osdc handle_watch_notify corrupt msg\n");
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002348}
2349
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002350/*
Alex Eldere65550f2013-04-05 01:27:12 -05002351 * build new request AND message
2352 *
2353 */
2354void ceph_osdc_build_request(struct ceph_osd_request *req, u64 off,
2355 struct ceph_snap_context *snapc, u64 snap_id,
2356 struct timespec *mtime)
2357{
2358 struct ceph_msg *msg = req->r_request;
2359 void *p;
2360 size_t msg_size;
2361 int flags = req->r_flags;
2362 u64 data_len;
2363 unsigned int i;
2364
2365 req->r_snapid = snap_id;
2366 req->r_snapc = ceph_get_snap_context(snapc);
2367
2368 /* encode request */
2369 msg->hdr.version = cpu_to_le16(4);
2370
2371 p = msg->front.iov_base;
2372 ceph_encode_32(&p, 1); /* client_inc is always 1 */
2373 req->r_request_osdmap_epoch = p;
2374 p += 4;
2375 req->r_request_flags = p;
2376 p += 4;
2377 if (req->r_flags & CEPH_OSD_FLAG_WRITE)
2378 ceph_encode_timespec(p, mtime);
2379 p += sizeof(struct ceph_timespec);
2380 req->r_request_reassert_version = p;
2381 p += sizeof(struct ceph_eversion); /* will get filled in */
2382
2383 /* oloc */
2384 ceph_encode_8(&p, 4);
2385 ceph_encode_8(&p, 4);
2386 ceph_encode_32(&p, 8 + 4 + 4);
2387 req->r_request_pool = p;
2388 p += 8;
2389 ceph_encode_32(&p, -1); /* preferred */
2390 ceph_encode_32(&p, 0); /* key len */
2391
2392 ceph_encode_8(&p, 1);
2393 req->r_request_pgid = p;
2394 p += 8 + 4;
2395 ceph_encode_32(&p, -1); /* preferred */
2396
2397 /* oid */
Ilya Dryomov3c972c92014-01-27 17:40:20 +02002398 ceph_encode_32(&p, req->r_base_oid.name_len);
2399 memcpy(p, req->r_base_oid.name, req->r_base_oid.name_len);
2400 dout("oid '%.*s' len %d\n", req->r_base_oid.name_len,
2401 req->r_base_oid.name, req->r_base_oid.name_len);
2402 p += req->r_base_oid.name_len;
Alex Eldere65550f2013-04-05 01:27:12 -05002403
2404 /* ops--can imply data */
2405 ceph_encode_16(&p, (u16)req->r_num_ops);
2406 data_len = 0;
2407 for (i = 0; i < req->r_num_ops; i++) {
2408 data_len += osd_req_encode_op(req, p, i);
2409 p += sizeof(struct ceph_osd_op);
2410 }
2411
2412 /* snaps */
2413 ceph_encode_64(&p, req->r_snapid);
2414 ceph_encode_64(&p, req->r_snapc ? req->r_snapc->seq : 0);
2415 ceph_encode_32(&p, req->r_snapc ? req->r_snapc->num_snaps : 0);
2416 if (req->r_snapc) {
2417 for (i = 0; i < snapc->num_snaps; i++) {
2418 ceph_encode_64(&p, req->r_snapc->snaps[i]);
2419 }
2420 }
2421
2422 req->r_request_attempts = p;
2423 p += 4;
2424
2425 /* data */
2426 if (flags & CEPH_OSD_FLAG_WRITE) {
2427 u16 data_off;
2428
2429 /*
2430 * The header "data_off" is a hint to the receiver
2431 * allowing it to align received data into its
2432 * buffers such that there's no need to re-copy
2433 * it before writing it to disk (direct I/O).
2434 */
2435 data_off = (u16) (off & 0xffff);
2436 req->r_request->hdr.data_off = cpu_to_le16(data_off);
2437 }
2438 req->r_request->hdr.data_len = cpu_to_le32(data_len);
2439
2440 BUG_ON(p > msg->front.iov_base + msg->front.iov_len);
2441 msg_size = p - msg->front.iov_base;
2442 msg->front.iov_len = msg_size;
2443 msg->hdr.front_len = cpu_to_le32(msg_size);
2444
2445 dout("build_request msg_size was %d\n", (int)msg_size);
2446}
2447EXPORT_SYMBOL(ceph_osdc_build_request);
2448
2449/*
Sage Weilf24e9982009-10-06 11:31:10 -07002450 * Register request, send initial attempt.
2451 */
2452int ceph_osdc_start_request(struct ceph_osd_client *osdc,
2453 struct ceph_osd_request *req,
2454 bool nofail)
2455{
Ilya Dryomov0bbfdfe2014-01-31 19:33:39 +02002456 int rc;
Sage Weilf24e9982009-10-06 11:31:10 -07002457
Sage Weilf24e9982009-10-06 11:31:10 -07002458 down_read(&osdc->map_sem);
2459 mutex_lock(&osdc->request_mutex);
Ilya Dryomov0bbfdfe2014-01-31 19:33:39 +02002460
2461 rc = __ceph_osdc_start_request(osdc, req, nofail);
2462
Sage Weilf24e9982009-10-06 11:31:10 -07002463 mutex_unlock(&osdc->request_mutex);
2464 up_read(&osdc->map_sem);
Ilya Dryomov0bbfdfe2014-01-31 19:33:39 +02002465
Sage Weilf24e9982009-10-06 11:31:10 -07002466 return rc;
2467}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002468EXPORT_SYMBOL(ceph_osdc_start_request);
Sage Weilf24e9982009-10-06 11:31:10 -07002469
2470/*
Ilya Dryomovc9f9b93d2014-06-19 11:38:13 +04002471 * Unregister a registered request. The request is not completed (i.e.
2472 * no callbacks or wakeups) - higher layers are supposed to know what
2473 * they are canceling.
2474 */
2475void ceph_osdc_cancel_request(struct ceph_osd_request *req)
2476{
2477 struct ceph_osd_client *osdc = req->r_osdc;
2478
2479 mutex_lock(&osdc->request_mutex);
2480 if (req->r_linger)
2481 __unregister_linger_request(osdc, req);
2482 __unregister_request(osdc, req);
2483 mutex_unlock(&osdc->request_mutex);
2484
2485 dout("%s %p tid %llu canceled\n", __func__, req, req->r_tid);
2486}
2487EXPORT_SYMBOL(ceph_osdc_cancel_request);
2488
2489/*
Sage Weilf24e9982009-10-06 11:31:10 -07002490 * wait for a request to complete
2491 */
2492int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
2493 struct ceph_osd_request *req)
2494{
2495 int rc;
2496
Ilya Dryomovc9f9b93d2014-06-19 11:38:13 +04002497 dout("%s %p tid %llu\n", __func__, req, req->r_tid);
2498
Sage Weilf24e9982009-10-06 11:31:10 -07002499 rc = wait_for_completion_interruptible(&req->r_completion);
2500 if (rc < 0) {
Ilya Dryomovc9f9b93d2014-06-19 11:38:13 +04002501 dout("%s %p tid %llu interrupted\n", __func__, req, req->r_tid);
2502 ceph_osdc_cancel_request(req);
Sage Weil25845472011-06-03 09:37:09 -07002503 complete_request(req);
Sage Weilf24e9982009-10-06 11:31:10 -07002504 return rc;
2505 }
2506
Ilya Dryomovc9f9b93d2014-06-19 11:38:13 +04002507 dout("%s %p tid %llu result %d\n", __func__, req, req->r_tid,
2508 req->r_result);
Sage Weilf24e9982009-10-06 11:31:10 -07002509 return req->r_result;
2510}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002511EXPORT_SYMBOL(ceph_osdc_wait_request);
Sage Weilf24e9982009-10-06 11:31:10 -07002512
2513/*
2514 * sync - wait for all in-flight requests to flush. avoid starvation.
2515 */
2516void ceph_osdc_sync(struct ceph_osd_client *osdc)
2517{
2518 struct ceph_osd_request *req;
2519 u64 last_tid, next_tid = 0;
2520
2521 mutex_lock(&osdc->request_mutex);
2522 last_tid = osdc->last_tid;
2523 while (1) {
2524 req = __lookup_request_ge(osdc, next_tid);
2525 if (!req)
2526 break;
2527 if (req->r_tid > last_tid)
2528 break;
2529
2530 next_tid = req->r_tid + 1;
2531 if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0)
2532 continue;
2533
2534 ceph_osdc_get_request(req);
2535 mutex_unlock(&osdc->request_mutex);
2536 dout("sync waiting on tid %llu (last is %llu)\n",
2537 req->r_tid, last_tid);
2538 wait_for_completion(&req->r_safe_completion);
2539 mutex_lock(&osdc->request_mutex);
2540 ceph_osdc_put_request(req);
2541 }
2542 mutex_unlock(&osdc->request_mutex);
2543 dout("sync done (thru tid %llu)\n", last_tid);
2544}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002545EXPORT_SYMBOL(ceph_osdc_sync);
Sage Weilf24e9982009-10-06 11:31:10 -07002546
2547/*
Josh Durgindd935f42013-08-28 21:43:09 -07002548 * Call all pending notify callbacks - for use after a watch is
2549 * unregistered, to make sure no more callbacks for it will be invoked
2550 */
stephen hemmingerf64794492014-06-10 20:30:13 -07002551void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc)
Josh Durgindd935f42013-08-28 21:43:09 -07002552{
2553 flush_workqueue(osdc->notify_wq);
2554}
2555EXPORT_SYMBOL(ceph_osdc_flush_notifies);
2556
2557
2558/*
Sage Weilf24e9982009-10-06 11:31:10 -07002559 * init, shutdown
2560 */
2561int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
2562{
2563 int err;
2564
2565 dout("init\n");
2566 osdc->client = client;
2567 osdc->osdmap = NULL;
2568 init_rwsem(&osdc->map_sem);
2569 init_completion(&osdc->map_waiters);
2570 osdc->last_requested_map = 0;
2571 mutex_init(&osdc->request_mutex);
Sage Weilf24e9982009-10-06 11:31:10 -07002572 osdc->last_tid = 0;
2573 osdc->osds = RB_ROOT;
Yehuda Sadehf5a20412010-02-03 11:00:26 -08002574 INIT_LIST_HEAD(&osdc->osd_lru);
Sage Weilf24e9982009-10-06 11:31:10 -07002575 osdc->requests = RB_ROOT;
Yehuda Sadeh422d2cb2010-02-26 15:32:31 -08002576 INIT_LIST_HEAD(&osdc->req_lru);
Sage Weil6f6c7002011-01-17 20:34:08 -08002577 INIT_LIST_HEAD(&osdc->req_unsent);
2578 INIT_LIST_HEAD(&osdc->req_notarget);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002579 INIT_LIST_HEAD(&osdc->req_linger);
Sage Weilf24e9982009-10-06 11:31:10 -07002580 osdc->num_requests = 0;
2581 INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout);
Yehuda Sadehf5a20412010-02-03 11:00:26 -08002582 INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout);
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002583 spin_lock_init(&osdc->event_lock);
2584 osdc->event_tree = RB_ROOT;
2585 osdc->event_count = 0;
Yehuda Sadehf5a20412010-02-03 11:00:26 -08002586
2587 schedule_delayed_work(&osdc->osds_timeout_work,
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002588 round_jiffies_relative(osdc->client->options->osd_idle_ttl * HZ));
Sage Weilf24e9982009-10-06 11:31:10 -07002589
Sage Weil5f44f142009-11-18 14:52:18 -08002590 err = -ENOMEM;
Sage Weilf24e9982009-10-06 11:31:10 -07002591 osdc->req_mempool = mempool_create_kmalloc_pool(10,
2592 sizeof(struct ceph_osd_request));
2593 if (!osdc->req_mempool)
Sage Weil5f44f142009-11-18 14:52:18 -08002594 goto out;
Sage Weilf24e9982009-10-06 11:31:10 -07002595
Sage Weild50b4092012-07-09 14:22:34 -07002596 err = ceph_msgpool_init(&osdc->msgpool_op, CEPH_MSG_OSD_OP,
2597 OSD_OP_FRONT_LEN, 10, true,
Sage Weil4f482802010-04-24 09:56:35 -07002598 "osd_op");
Sage Weilf24e9982009-10-06 11:31:10 -07002599 if (err < 0)
Sage Weil5f44f142009-11-18 14:52:18 -08002600 goto out_mempool;
Sage Weild50b4092012-07-09 14:22:34 -07002601 err = ceph_msgpool_init(&osdc->msgpool_op_reply, CEPH_MSG_OSD_OPREPLY,
Sage Weil4f482802010-04-24 09:56:35 -07002602 OSD_OPREPLY_FRONT_LEN, 10, true,
2603 "osd_op_reply");
Sage Weilc16e7862010-03-01 13:02:00 -08002604 if (err < 0)
2605 goto out_msgpool;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002606
Dan Carpenterdbcae082013-08-15 08:58:59 +03002607 err = -ENOMEM;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002608 osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify");
Dan Carpenterdbcae082013-08-15 08:58:59 +03002609 if (!osdc->notify_wq)
Ilya Dryomovc172ec52014-01-31 17:49:22 +02002610 goto out_msgpool_reply;
2611
Sage Weilf24e9982009-10-06 11:31:10 -07002612 return 0;
Sage Weil5f44f142009-11-18 14:52:18 -08002613
Ilya Dryomovc172ec52014-01-31 17:49:22 +02002614out_msgpool_reply:
2615 ceph_msgpool_destroy(&osdc->msgpool_op_reply);
Sage Weilc16e7862010-03-01 13:02:00 -08002616out_msgpool:
2617 ceph_msgpool_destroy(&osdc->msgpool_op);
Sage Weil5f44f142009-11-18 14:52:18 -08002618out_mempool:
2619 mempool_destroy(osdc->req_mempool);
2620out:
2621 return err;
Sage Weilf24e9982009-10-06 11:31:10 -07002622}
2623
2624void ceph_osdc_stop(struct ceph_osd_client *osdc)
2625{
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002626 flush_workqueue(osdc->notify_wq);
2627 destroy_workqueue(osdc->notify_wq);
Sage Weilf24e9982009-10-06 11:31:10 -07002628 cancel_delayed_work_sync(&osdc->timeout_work);
Yehuda Sadehf5a20412010-02-03 11:00:26 -08002629 cancel_delayed_work_sync(&osdc->osds_timeout_work);
Sage Weilf24e9982009-10-06 11:31:10 -07002630 if (osdc->osdmap) {
2631 ceph_osdmap_destroy(osdc->osdmap);
2632 osdc->osdmap = NULL;
2633 }
Sage Weilaca420b2011-08-31 14:45:53 -07002634 remove_all_osds(osdc);
Sage Weilf24e9982009-10-06 11:31:10 -07002635 mempool_destroy(osdc->req_mempool);
2636 ceph_msgpool_destroy(&osdc->msgpool_op);
Sage Weilc16e7862010-03-01 13:02:00 -08002637 ceph_msgpool_destroy(&osdc->msgpool_op_reply);
Sage Weilf24e9982009-10-06 11:31:10 -07002638}
2639
2640/*
2641 * Read some contiguous pages. If we cross a stripe boundary, shorten
2642 * *plen. Return number of bytes read, or error.
2643 */
2644int ceph_osdc_readpages(struct ceph_osd_client *osdc,
2645 struct ceph_vino vino, struct ceph_file_layout *layout,
2646 u64 off, u64 *plen,
2647 u32 truncate_seq, u64 truncate_size,
Sage Weilb7495fc2010-11-09 12:43:12 -08002648 struct page **pages, int num_pages, int page_align)
Sage Weilf24e9982009-10-06 11:31:10 -07002649{
2650 struct ceph_osd_request *req;
2651 int rc = 0;
2652
2653 dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
2654 vino.snap, off, *plen);
Alex Elder79528732013-04-03 21:32:51 -05002655 req = ceph_osdc_new_request(osdc, layout, vino, off, plen, 1,
Sage Weilf24e9982009-10-06 11:31:10 -07002656 CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
Alex Elderacead002013-03-14 14:09:05 -05002657 NULL, truncate_seq, truncate_size,
Alex Elder153e5162013-03-01 18:00:15 -06002658 false);
Sage Weil68162822012-09-24 21:01:02 -07002659 if (IS_ERR(req))
2660 return PTR_ERR(req);
Sage Weilf24e9982009-10-06 11:31:10 -07002661
2662 /* it may be a short read due to an object boundary */
Alex Elder0fff87e2013-02-14 12:16:43 -06002663
Alex Elder406e2c92013-04-15 14:50:36 -05002664 osd_req_op_extent_osd_data_pages(req, 0,
Alex Eldera4ce40a2013-04-05 01:27:12 -05002665 pages, *plen, page_align, false, false);
Sage Weilf24e9982009-10-06 11:31:10 -07002666
Alex Eldere0c59482013-03-07 15:38:25 -06002667 dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n",
Alex Elder43bfe5d2013-04-03 01:28:57 -05002668 off, *plen, *plen, page_align);
Sage Weilf24e9982009-10-06 11:31:10 -07002669
Alex Elder79528732013-04-03 21:32:51 -05002670 ceph_osdc_build_request(req, off, NULL, vino.snap, NULL);
Alex Elder02ee07d2013-03-14 14:09:06 -05002671
Sage Weilf24e9982009-10-06 11:31:10 -07002672 rc = ceph_osdc_start_request(osdc, req, false);
2673 if (!rc)
2674 rc = ceph_osdc_wait_request(osdc, req);
2675
2676 ceph_osdc_put_request(req);
2677 dout("readpages result %d\n", rc);
2678 return rc;
2679}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002680EXPORT_SYMBOL(ceph_osdc_readpages);
Sage Weilf24e9982009-10-06 11:31:10 -07002681
2682/*
2683 * do a synchronous write on N pages
2684 */
2685int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
2686 struct ceph_file_layout *layout,
2687 struct ceph_snap_context *snapc,
2688 u64 off, u64 len,
2689 u32 truncate_seq, u64 truncate_size,
2690 struct timespec *mtime,
Alex Elder24808822013-02-15 11:42:29 -06002691 struct page **pages, int num_pages)
Sage Weilf24e9982009-10-06 11:31:10 -07002692{
2693 struct ceph_osd_request *req;
2694 int rc = 0;
Sage Weilb7495fc2010-11-09 12:43:12 -08002695 int page_align = off & ~PAGE_MASK;
Sage Weilf24e9982009-10-06 11:31:10 -07002696
Alex Elderacead002013-03-14 14:09:05 -05002697 BUG_ON(vino.snap != CEPH_NOSNAP); /* snapshots aren't writeable */
Alex Elder79528732013-04-03 21:32:51 -05002698 req = ceph_osdc_new_request(osdc, layout, vino, off, &len, 1,
Sage Weilf24e9982009-10-06 11:31:10 -07002699 CEPH_OSD_OP_WRITE,
Alex Elder24808822013-02-15 11:42:29 -06002700 CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
Alex Elderacead002013-03-14 14:09:05 -05002701 snapc, truncate_seq, truncate_size,
Alex Elder153e5162013-03-01 18:00:15 -06002702 true);
Sage Weil68162822012-09-24 21:01:02 -07002703 if (IS_ERR(req))
2704 return PTR_ERR(req);
Sage Weilf24e9982009-10-06 11:31:10 -07002705
2706 /* it may be a short write due to an object boundary */
Alex Elder406e2c92013-04-15 14:50:36 -05002707 osd_req_op_extent_osd_data_pages(req, 0, pages, len, page_align,
Alex Elder43bfe5d2013-04-03 01:28:57 -05002708 false, false);
2709 dout("writepages %llu~%llu (%llu bytes)\n", off, len, len);
Sage Weilf24e9982009-10-06 11:31:10 -07002710
Alex Elder79528732013-04-03 21:32:51 -05002711 ceph_osdc_build_request(req, off, snapc, CEPH_NOSNAP, mtime);
Alex Elder02ee07d2013-03-14 14:09:06 -05002712
Alex Elder87f979d2013-02-15 11:42:29 -06002713 rc = ceph_osdc_start_request(osdc, req, true);
Sage Weilf24e9982009-10-06 11:31:10 -07002714 if (!rc)
2715 rc = ceph_osdc_wait_request(osdc, req);
2716
2717 ceph_osdc_put_request(req);
2718 if (rc == 0)
2719 rc = len;
2720 dout("writepages result %d\n", rc);
2721 return rc;
2722}
Yehuda Sadeh3d14c5d2010-04-06 15:14:15 -07002723EXPORT_SYMBOL(ceph_osdc_writepages);
Sage Weilf24e9982009-10-06 11:31:10 -07002724
Alex Elder5522ae02013-05-01 12:43:04 -05002725int ceph_osdc_setup(void)
2726{
2727 BUG_ON(ceph_osd_request_cache);
2728 ceph_osd_request_cache = kmem_cache_create("ceph_osd_request",
2729 sizeof (struct ceph_osd_request),
2730 __alignof__(struct ceph_osd_request),
2731 0, NULL);
2732
2733 return ceph_osd_request_cache ? 0 : -ENOMEM;
2734}
2735EXPORT_SYMBOL(ceph_osdc_setup);
2736
2737void ceph_osdc_cleanup(void)
2738{
2739 BUG_ON(!ceph_osd_request_cache);
2740 kmem_cache_destroy(ceph_osd_request_cache);
2741 ceph_osd_request_cache = NULL;
2742}
2743EXPORT_SYMBOL(ceph_osdc_cleanup);
2744
Sage Weilf24e9982009-10-06 11:31:10 -07002745/*
2746 * handle incoming message
2747 */
2748static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
2749{
2750 struct ceph_osd *osd = con->private;
Julia Lawall32c895e2009-11-21 16:53:16 +01002751 struct ceph_osd_client *osdc;
Sage Weilf24e9982009-10-06 11:31:10 -07002752 int type = le16_to_cpu(msg->hdr.type);
2753
2754 if (!osd)
Sage Weil4a32f932010-06-13 10:27:53 -07002755 goto out;
Julia Lawall32c895e2009-11-21 16:53:16 +01002756 osdc = osd->o_osdc;
Sage Weilf24e9982009-10-06 11:31:10 -07002757
2758 switch (type) {
2759 case CEPH_MSG_OSD_MAP:
2760 ceph_osdc_handle_map(osdc, msg);
2761 break;
2762 case CEPH_MSG_OSD_OPREPLY:
Sage Weil350b1c32009-12-22 10:45:45 -08002763 handle_reply(osdc, msg, con);
Sage Weilf24e9982009-10-06 11:31:10 -07002764 break;
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002765 case CEPH_MSG_WATCH_NOTIFY:
2766 handle_watch_notify(osdc, msg);
2767 break;
Sage Weilf24e9982009-10-06 11:31:10 -07002768
2769 default:
2770 pr_err("received unknown message type %d %s\n", type,
2771 ceph_msg_type_name(type));
2772 }
Sage Weil4a32f932010-06-13 10:27:53 -07002773out:
Sage Weilf24e9982009-10-06 11:31:10 -07002774 ceph_msg_put(msg);
2775}
2776
Sage Weil5b3a4db2010-02-19 21:43:23 -08002777/*
Sage Weil21b667f2010-03-04 10:22:59 -08002778 * lookup and return message for incoming reply. set up reply message
2779 * pages.
Sage Weil5b3a4db2010-02-19 21:43:23 -08002780 */
2781static struct ceph_msg *get_reply(struct ceph_connection *con,
Yehuda Sadeh24504182010-01-08 13:58:34 -08002782 struct ceph_msg_header *hdr,
2783 int *skip)
Sage Weilf24e9982009-10-06 11:31:10 -07002784{
2785 struct ceph_osd *osd = con->private;
2786 struct ceph_osd_client *osdc = osd->o_osdc;
Yehuda Sadeh24504182010-01-08 13:58:34 -08002787 struct ceph_msg *m;
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002788 struct ceph_osd_request *req;
Ilya Dryomov3f0a4ac2014-01-09 20:08:21 +02002789 int front_len = le32_to_cpu(hdr->front_len);
Sage Weil5b3a4db2010-02-19 21:43:23 -08002790 int data_len = le32_to_cpu(hdr->data_len);
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002791 u64 tid;
Sage Weilf24e9982009-10-06 11:31:10 -07002792
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002793 tid = le64_to_cpu(hdr->tid);
2794 mutex_lock(&osdc->request_mutex);
2795 req = __lookup_request(osdc, tid);
2796 if (!req) {
2797 *skip = 1;
2798 m = NULL;
Sage Weil756a16a2012-07-30 16:26:13 -07002799 dout("get_reply unknown tid %llu from osd%d\n", tid,
2800 osd->o_osd);
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002801 goto out;
2802 }
Sage Weilc16e7862010-03-01 13:02:00 -08002803
Alex Elderace6d3a2013-04-01 16:12:14 -05002804 if (req->r_reply->con)
Alex Elder8921d112012-06-01 14:56:43 -05002805 dout("%s revoking msg %p from old con %p\n", __func__,
Alex Elderace6d3a2013-04-01 16:12:14 -05002806 req->r_reply, req->r_reply->con);
2807 ceph_msg_revoke_incoming(req->r_reply);
Yehuda Sadeh24504182010-01-08 13:58:34 -08002808
Ilya Dryomovf2be82b2014-01-09 20:08:21 +02002809 if (front_len > req->r_reply->front_alloc_len) {
Alex Elder49743412013-05-29 11:19:00 -05002810 pr_warning("get_reply front %d > preallocated %d (%u#%llu)\n",
Ilya Dryomovf2be82b2014-01-09 20:08:21 +02002811 front_len, req->r_reply->front_alloc_len,
Alex Elder49743412013-05-29 11:19:00 -05002812 (unsigned int)con->peer_name.type,
2813 le64_to_cpu(con->peer_name.num));
Ilya Dryomov3f0a4ac2014-01-09 20:08:21 +02002814 m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front_len, GFP_NOFS,
2815 false);
Sage Weila79832f2010-04-01 16:06:19 -07002816 if (!m)
Sage Weilc16e7862010-03-01 13:02:00 -08002817 goto out;
2818 ceph_msg_put(req->r_reply);
2819 req->r_reply = m;
2820 }
2821 m = ceph_msg_get(req->r_reply);
2822
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002823 if (data_len > 0) {
Alex Eldera4ce40a2013-04-05 01:27:12 -05002824 struct ceph_osd_data *osd_data;
Alex Elder0fff87e2013-02-14 12:16:43 -06002825
Alex Eldera4ce40a2013-04-05 01:27:12 -05002826 /*
2827 * XXX This is assuming there is only one op containing
2828 * XXX page data. Probably OK for reads, but this
2829 * XXX ought to be done more generally.
2830 */
Alex Elder406e2c92013-04-15 14:50:36 -05002831 osd_data = osd_req_op_extent_osd_data(req, 0);
Alex Elder0fff87e2013-02-14 12:16:43 -06002832 if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
Alex Elder0fff87e2013-02-14 12:16:43 -06002833 if (osd_data->pages &&
Alex Eldere0c59482013-03-07 15:38:25 -06002834 unlikely(osd_data->length < data_len)) {
Alex Elder2ac2b7a62013-02-14 12:16:43 -06002835
Alex Eldere0c59482013-03-07 15:38:25 -06002836 pr_warning("tid %lld reply has %d bytes "
2837 "we had only %llu bytes ready\n",
2838 tid, data_len, osd_data->length);
Alex Elder2ac2b7a62013-02-14 12:16:43 -06002839 *skip = 1;
2840 ceph_msg_put(m);
2841 m = NULL;
2842 goto out;
2843 }
Alex Elder2ac2b7a62013-02-14 12:16:43 -06002844 }
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002845 }
Sage Weil5b3a4db2010-02-19 21:43:23 -08002846 *skip = 0;
Sage Weilc16e7862010-03-01 13:02:00 -08002847 dout("get_reply tid %lld %p\n", tid, m);
Yehuda Sadeh0547a9b2010-01-11 14:47:13 -08002848
2849out:
2850 mutex_unlock(&osdc->request_mutex);
Yehuda Sadeh24504182010-01-08 13:58:34 -08002851 return m;
Sage Weil5b3a4db2010-02-19 21:43:23 -08002852
2853}
2854
2855static struct ceph_msg *alloc_msg(struct ceph_connection *con,
2856 struct ceph_msg_header *hdr,
2857 int *skip)
2858{
2859 struct ceph_osd *osd = con->private;
2860 int type = le16_to_cpu(hdr->type);
2861 int front = le32_to_cpu(hdr->front_len);
2862
Alex Elder1c20f2d2012-06-04 14:43:32 -05002863 *skip = 0;
Sage Weil5b3a4db2010-02-19 21:43:23 -08002864 switch (type) {
2865 case CEPH_MSG_OSD_MAP:
Yehuda Sadeha40c4f12011-03-21 15:07:16 -07002866 case CEPH_MSG_WATCH_NOTIFY:
Sage Weilb61c2762011-08-09 15:03:46 -07002867 return ceph_msg_new(type, front, GFP_NOFS, false);
Sage Weil5b3a4db2010-02-19 21:43:23 -08002868 case CEPH_MSG_OSD_OPREPLY:
2869 return get_reply(con, hdr, skip);
2870 default:
2871 pr_info("alloc_msg unexpected msg type %d from osd%d\n", type,
2872 osd->o_osd);
2873 *skip = 1;
2874 return NULL;
2875 }
Sage Weilf24e9982009-10-06 11:31:10 -07002876}
2877
2878/*
2879 * Wrappers to refcount containing ceph_osd struct
2880 */
2881static struct ceph_connection *get_osd_con(struct ceph_connection *con)
2882{
2883 struct ceph_osd *osd = con->private;
2884 if (get_osd(osd))
2885 return con;
2886 return NULL;
2887}
2888
2889static void put_osd_con(struct ceph_connection *con)
2890{
2891 struct ceph_osd *osd = con->private;
2892 put_osd(osd);
2893}
2894
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002895/*
2896 * authentication
2897 */
Alex Eldera3530df2012-05-16 15:16:39 -05002898/*
2899 * Note: returned pointer is the address of a structure that's
2900 * managed separately. Caller must *not* attempt to free it.
2901 */
2902static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
Alex Elder8f43fb52012-05-16 15:16:39 -05002903 int *proto, int force_new)
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002904{
2905 struct ceph_osd *o = con->private;
2906 struct ceph_osd_client *osdc = o->o_osdc;
2907 struct ceph_auth_client *ac = osdc->client->monc.auth;
Alex Elder74f18692012-05-16 15:16:39 -05002908 struct ceph_auth_handshake *auth = &o->o_auth;
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002909
Alex Elder74f18692012-05-16 15:16:39 -05002910 if (force_new && auth->authorizer) {
Sage Weil27859f92013-03-25 10:26:14 -07002911 ceph_auth_destroy_authorizer(ac, auth->authorizer);
Alex Elder74f18692012-05-16 15:16:39 -05002912 auth->authorizer = NULL;
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002913 }
Sage Weil27859f92013-03-25 10:26:14 -07002914 if (!auth->authorizer) {
2915 int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
2916 auth);
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002917 if (ret)
Alex Eldera3530df2012-05-16 15:16:39 -05002918 return ERR_PTR(ret);
Sage Weil27859f92013-03-25 10:26:14 -07002919 } else {
2920 int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
Sage Weil0bed9b52013-03-25 10:26:01 -07002921 auth);
2922 if (ret)
2923 return ERR_PTR(ret);
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002924 }
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002925 *proto = ac->protocol;
Alex Elder74f18692012-05-16 15:16:39 -05002926
Alex Eldera3530df2012-05-16 15:16:39 -05002927 return auth;
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002928}
2929
2930
2931static int verify_authorizer_reply(struct ceph_connection *con, int len)
2932{
2933 struct ceph_osd *o = con->private;
2934 struct ceph_osd_client *osdc = o->o_osdc;
2935 struct ceph_auth_client *ac = osdc->client->monc.auth;
2936
Sage Weil27859f92013-03-25 10:26:14 -07002937 return ceph_auth_verify_authorizer_reply(ac, o->o_auth.authorizer, len);
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002938}
2939
Sage Weil9bd2e6f2010-02-02 16:21:06 -08002940static int invalidate_authorizer(struct ceph_connection *con)
2941{
2942 struct ceph_osd *o = con->private;
2943 struct ceph_osd_client *osdc = o->o_osdc;
2944 struct ceph_auth_client *ac = osdc->client->monc.auth;
2945
Sage Weil27859f92013-03-25 10:26:14 -07002946 ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
Sage Weil9bd2e6f2010-02-02 16:21:06 -08002947 return ceph_monc_validate_auth(&osdc->client->monc);
2948}
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002949
Tobias Klauser9e327892010-05-20 10:40:19 +02002950static const struct ceph_connection_operations osd_con_ops = {
Sage Weilf24e9982009-10-06 11:31:10 -07002951 .get = get_osd_con,
2952 .put = put_osd_con,
2953 .dispatch = dispatch,
Sage Weil4e7a5dc2009-11-18 16:19:57 -08002954 .get_authorizer = get_authorizer,
2955 .verify_authorizer_reply = verify_authorizer_reply,
Sage Weil9bd2e6f2010-02-02 16:21:06 -08002956 .invalidate_authorizer = invalidate_authorizer,
Sage Weilf24e9982009-10-06 11:31:10 -07002957 .alloc_msg = alloc_msg,
Sage Weil81b024e2009-10-09 10:29:18 -07002958 .fault = osd_reset,
Sage Weilf24e9982009-10-06 11:31:10 -07002959};