2 #include <linux/ceph/ceph_debug.h>
4 #include <linux/module.h>
6 #include <linux/highmem.h>
8 #include <linux/pagemap.h>
9 #include <linux/slab.h>
10 #include <linux/uaccess.h>
12 #include <linux/bio.h>
15 #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>
22 #define OSD_OPREPLY_FRONT_LEN 512
24 static struct kmem_cache *ceph_osd_request_cache;
26 static const struct ceph_connection_operations osd_con_ops;
28 static void __send_queued(struct ceph_osd_client *osdc);
29 static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd);
30 static void __register_request(struct ceph_osd_client *osdc,
31 struct ceph_osd_request *req);
32 static void __unregister_request(struct ceph_osd_client *osdc,
33 struct ceph_osd_request *req);
34 static void __unregister_linger_request(struct ceph_osd_client *osdc,
35 struct ceph_osd_request *req);
36 static void __enqueue_request(struct ceph_osd_request *req);
39 * Implement client access to distributed object storage cluster.
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
47 * Cluster membership and the mapping of data objects onto storage devices
48 * are described by the osd map.
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.
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
61 * fill osd op in request message.
63 static int calc_layout(struct ceph_file_layout *layout, u64 off, u64 *plen,
64 u64 *objnum, u64 *objoff, u64 *objlen)
70 r = ceph_calc_file_object_mapping(layout, off, orig_len, objnum,
74 if (*objlen < orig_len) {
76 dout(" skipping last %llu, final file extent %llu~%llu\n",
77 orig_len - *plen, off, *plen);
80 dout("calc_layout objnum=%llx %llu~%llu\n", *objnum, *objoff, *objlen);
85 static void ceph_osd_data_init(struct ceph_osd_data *osd_data)
87 memset(osd_data, 0, sizeof (*osd_data));
88 osd_data->type = CEPH_OSD_DATA_TYPE_NONE;
91 static void ceph_osd_data_pages_init(struct ceph_osd_data *osd_data,
92 struct page **pages, u64 length, u32 alignment,
93 bool pages_from_pool, bool own_pages)
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;
103 static void ceph_osd_data_pagelist_init(struct ceph_osd_data *osd_data,
104 struct ceph_pagelist *pagelist)
106 osd_data->type = CEPH_OSD_DATA_TYPE_PAGELIST;
107 osd_data->pagelist = pagelist;
111 static void ceph_osd_data_bio_init(struct ceph_osd_data *osd_data,
112 struct bio *bio, size_t bio_length)
114 osd_data->type = CEPH_OSD_DATA_TYPE_BIO;
116 osd_data->bio_length = bio_length;
118 #endif /* CONFIG_BLOCK */
120 #define osd_req_op_data(oreq, whch, typ, fld) \
122 struct ceph_osd_request *__oreq = (oreq); \
123 unsigned int __whch = (whch); \
124 BUG_ON(__whch >= __oreq->r_num_ops); \
125 &__oreq->r_ops[__whch].typ.fld; \
128 static struct ceph_osd_data *
129 osd_req_op_raw_data_in(struct ceph_osd_request *osd_req, unsigned int which)
131 BUG_ON(which >= osd_req->r_num_ops);
133 return &osd_req->r_ops[which].raw_data_in;
136 struct ceph_osd_data *
137 osd_req_op_extent_osd_data(struct ceph_osd_request *osd_req,
140 return osd_req_op_data(osd_req, which, extent, osd_data);
142 EXPORT_SYMBOL(osd_req_op_extent_osd_data);
144 void osd_req_op_raw_data_in_pages(struct ceph_osd_request *osd_req,
145 unsigned int which, struct page **pages,
146 u64 length, u32 alignment,
147 bool pages_from_pool, bool own_pages)
149 struct ceph_osd_data *osd_data;
151 osd_data = osd_req_op_raw_data_in(osd_req, which);
152 ceph_osd_data_pages_init(osd_data, pages, length, alignment,
153 pages_from_pool, own_pages);
155 EXPORT_SYMBOL(osd_req_op_raw_data_in_pages);
157 void osd_req_op_extent_osd_data_pages(struct ceph_osd_request *osd_req,
158 unsigned int which, struct page **pages,
159 u64 length, u32 alignment,
160 bool pages_from_pool, bool own_pages)
162 struct ceph_osd_data *osd_data;
164 osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
165 ceph_osd_data_pages_init(osd_data, pages, length, alignment,
166 pages_from_pool, own_pages);
168 EXPORT_SYMBOL(osd_req_op_extent_osd_data_pages);
170 void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request *osd_req,
171 unsigned int which, struct ceph_pagelist *pagelist)
173 struct ceph_osd_data *osd_data;
175 osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
176 ceph_osd_data_pagelist_init(osd_data, pagelist);
178 EXPORT_SYMBOL(osd_req_op_extent_osd_data_pagelist);
181 void osd_req_op_extent_osd_data_bio(struct ceph_osd_request *osd_req,
182 unsigned int which, struct bio *bio, size_t bio_length)
184 struct ceph_osd_data *osd_data;
186 osd_data = osd_req_op_data(osd_req, which, extent, osd_data);
187 ceph_osd_data_bio_init(osd_data, bio, bio_length);
189 EXPORT_SYMBOL(osd_req_op_extent_osd_data_bio);
190 #endif /* CONFIG_BLOCK */
192 static void osd_req_op_cls_request_info_pagelist(
193 struct ceph_osd_request *osd_req,
194 unsigned int which, struct ceph_pagelist *pagelist)
196 struct ceph_osd_data *osd_data;
198 osd_data = osd_req_op_data(osd_req, which, cls, request_info);
199 ceph_osd_data_pagelist_init(osd_data, pagelist);
202 void osd_req_op_cls_request_data_pagelist(
203 struct ceph_osd_request *osd_req,
204 unsigned int which, struct ceph_pagelist *pagelist)
206 struct ceph_osd_data *osd_data;
208 osd_data = osd_req_op_data(osd_req, which, cls, request_data);
209 ceph_osd_data_pagelist_init(osd_data, pagelist);
210 osd_req->r_ops[which].cls.indata_len += pagelist->length;
211 osd_req->r_ops[which].indata_len += pagelist->length;
213 EXPORT_SYMBOL(osd_req_op_cls_request_data_pagelist);
215 void osd_req_op_cls_request_data_pages(struct ceph_osd_request *osd_req,
216 unsigned int which, struct page **pages, u64 length,
217 u32 alignment, bool pages_from_pool, bool own_pages)
219 struct ceph_osd_data *osd_data;
221 osd_data = osd_req_op_data(osd_req, which, cls, request_data);
222 ceph_osd_data_pages_init(osd_data, pages, length, alignment,
223 pages_from_pool, own_pages);
224 osd_req->r_ops[which].cls.indata_len += length;
225 osd_req->r_ops[which].indata_len += length;
227 EXPORT_SYMBOL(osd_req_op_cls_request_data_pages);
229 void osd_req_op_cls_response_data_pages(struct ceph_osd_request *osd_req,
230 unsigned int which, struct page **pages, u64 length,
231 u32 alignment, bool pages_from_pool, bool own_pages)
233 struct ceph_osd_data *osd_data;
235 osd_data = osd_req_op_data(osd_req, which, cls, response_data);
236 ceph_osd_data_pages_init(osd_data, pages, length, alignment,
237 pages_from_pool, own_pages);
239 EXPORT_SYMBOL(osd_req_op_cls_response_data_pages);
241 static u64 ceph_osd_data_length(struct ceph_osd_data *osd_data)
243 switch (osd_data->type) {
244 case CEPH_OSD_DATA_TYPE_NONE:
246 case CEPH_OSD_DATA_TYPE_PAGES:
247 return osd_data->length;
248 case CEPH_OSD_DATA_TYPE_PAGELIST:
249 return (u64)osd_data->pagelist->length;
251 case CEPH_OSD_DATA_TYPE_BIO:
252 return (u64)osd_data->bio_length;
253 #endif /* CONFIG_BLOCK */
255 WARN(true, "unrecognized data type %d\n", (int)osd_data->type);
260 static void ceph_osd_data_release(struct ceph_osd_data *osd_data)
262 if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES && osd_data->own_pages) {
265 num_pages = calc_pages_for((u64)osd_data->alignment,
266 (u64)osd_data->length);
267 ceph_release_page_vector(osd_data->pages, num_pages);
269 ceph_osd_data_init(osd_data);
272 static void osd_req_op_data_release(struct ceph_osd_request *osd_req,
275 struct ceph_osd_req_op *op;
277 BUG_ON(which >= osd_req->r_num_ops);
278 op = &osd_req->r_ops[which];
281 case CEPH_OSD_OP_READ:
282 case CEPH_OSD_OP_WRITE:
283 case CEPH_OSD_OP_WRITEFULL:
284 ceph_osd_data_release(&op->extent.osd_data);
286 case CEPH_OSD_OP_CALL:
287 ceph_osd_data_release(&op->cls.request_info);
288 ceph_osd_data_release(&op->cls.request_data);
289 ceph_osd_data_release(&op->cls.response_data);
291 case CEPH_OSD_OP_SETXATTR:
292 case CEPH_OSD_OP_CMPXATTR:
293 ceph_osd_data_release(&op->xattr.osd_data);
295 case CEPH_OSD_OP_STAT:
296 ceph_osd_data_release(&op->raw_data_in);
304 * Assumes @t is zero-initialized.
306 static void target_init(struct ceph_osd_request_target *t)
308 ceph_oid_init(&t->base_oid);
309 ceph_oloc_init(&t->base_oloc);
310 ceph_oid_init(&t->target_oid);
311 ceph_oloc_init(&t->target_oloc);
313 ceph_osds_init(&t->acting);
314 ceph_osds_init(&t->up);
318 t->osd = CEPH_HOMELESS_OSD;
321 static void target_destroy(struct ceph_osd_request_target *t)
323 ceph_oid_destroy(&t->base_oid);
324 ceph_oid_destroy(&t->target_oid);
330 static void ceph_osdc_release_request(struct kref *kref)
332 struct ceph_osd_request *req = container_of(kref,
333 struct ceph_osd_request, r_kref);
336 dout("%s %p (r_request %p r_reply %p)\n", __func__, req,
337 req->r_request, req->r_reply);
338 WARN_ON(!RB_EMPTY_NODE(&req->r_node));
339 WARN_ON(!list_empty(&req->r_req_lru_item));
340 WARN_ON(!list_empty(&req->r_osd_item));
341 WARN_ON(!list_empty(&req->r_linger_item));
342 WARN_ON(!list_empty(&req->r_linger_osd_item));
346 ceph_msg_put(req->r_request);
348 ceph_msg_revoke_incoming(req->r_reply);
349 ceph_msg_put(req->r_reply);
352 for (which = 0; which < req->r_num_ops; which++)
353 osd_req_op_data_release(req, which);
355 target_destroy(&req->r_t);
356 ceph_put_snap_context(req->r_snapc);
359 mempool_free(req, req->r_osdc->req_mempool);
360 else if (req->r_num_ops <= CEPH_OSD_SLAB_OPS)
361 kmem_cache_free(ceph_osd_request_cache, req);
366 void ceph_osdc_get_request(struct ceph_osd_request *req)
368 dout("%s %p (was %d)\n", __func__, req,
369 atomic_read(&req->r_kref.refcount));
370 kref_get(&req->r_kref);
372 EXPORT_SYMBOL(ceph_osdc_get_request);
374 void ceph_osdc_put_request(struct ceph_osd_request *req)
377 dout("%s %p (was %d)\n", __func__, req,
378 atomic_read(&req->r_kref.refcount));
379 kref_put(&req->r_kref, ceph_osdc_release_request);
382 EXPORT_SYMBOL(ceph_osdc_put_request);
384 struct ceph_osd_request *ceph_osdc_alloc_request(struct ceph_osd_client *osdc,
385 struct ceph_snap_context *snapc,
386 unsigned int num_ops,
390 struct ceph_osd_request *req;
393 BUG_ON(num_ops > CEPH_OSD_SLAB_OPS);
394 req = mempool_alloc(osdc->req_mempool, gfp_flags);
395 } else if (num_ops <= CEPH_OSD_SLAB_OPS) {
396 req = kmem_cache_alloc(ceph_osd_request_cache, gfp_flags);
398 BUG_ON(num_ops > CEPH_OSD_MAX_OPS);
399 req = kmalloc(sizeof(*req) + num_ops * sizeof(req->r_ops[0]),
405 /* req only, each op is zeroed in _osd_req_op_init() */
406 memset(req, 0, sizeof(*req));
409 req->r_mempool = use_mempool;
410 req->r_num_ops = num_ops;
411 req->r_snapid = CEPH_NOSNAP;
412 req->r_snapc = ceph_get_snap_context(snapc);
414 kref_init(&req->r_kref);
415 init_completion(&req->r_completion);
416 init_completion(&req->r_safe_completion);
417 RB_CLEAR_NODE(&req->r_node);
418 INIT_LIST_HEAD(&req->r_unsafe_item);
419 INIT_LIST_HEAD(&req->r_linger_item);
420 INIT_LIST_HEAD(&req->r_linger_osd_item);
421 INIT_LIST_HEAD(&req->r_req_lru_item);
422 INIT_LIST_HEAD(&req->r_osd_item);
424 target_init(&req->r_t);
426 dout("%s req %p\n", __func__, req);
429 EXPORT_SYMBOL(ceph_osdc_alloc_request);
431 int ceph_osdc_alloc_messages(struct ceph_osd_request *req, gfp_t gfp)
433 struct ceph_osd_client *osdc = req->r_osdc;
434 struct ceph_msg *msg;
437 WARN_ON(ceph_oid_empty(&req->r_base_oid));
439 /* create request message */
440 msg_size = 4 + 4 + 4; /* client_inc, osdmap_epoch, flags */
441 msg_size += 4 + 4 + 4 + 8; /* mtime, reassert_version */
442 msg_size += 2 + 4 + 8 + 4 + 4; /* oloc */
443 msg_size += 1 + 8 + 4 + 4; /* pgid */
444 msg_size += 4 + req->r_base_oid.name_len; /* oid */
445 msg_size += 2 + req->r_num_ops * sizeof(struct ceph_osd_op);
446 msg_size += 8; /* snapid */
447 msg_size += 8; /* snap_seq */
448 msg_size += 4 + 8 * (req->r_snapc ? req->r_snapc->num_snaps : 0);
449 msg_size += 4; /* retry_attempt */
452 msg = ceph_msgpool_get(&osdc->msgpool_op, 0);
454 msg = ceph_msg_new(CEPH_MSG_OSD_OP, msg_size, gfp, true);
458 memset(msg->front.iov_base, 0, msg->front.iov_len);
459 req->r_request = msg;
461 /* create reply message */
462 msg_size = OSD_OPREPLY_FRONT_LEN;
463 msg_size += req->r_base_oid.name_len;
464 msg_size += req->r_num_ops * sizeof(struct ceph_osd_op);
467 msg = ceph_msgpool_get(&osdc->msgpool_op_reply, 0);
469 msg = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, msg_size, gfp, true);
477 EXPORT_SYMBOL(ceph_osdc_alloc_messages);
479 static bool osd_req_opcode_valid(u16 opcode)
482 #define GENERATE_CASE(op, opcode, str) case CEPH_OSD_OP_##op: return true;
483 __CEPH_FORALL_OSD_OPS(GENERATE_CASE)
491 * This is an osd op init function for opcodes that have no data or
492 * other information associated with them. It also serves as a
493 * common init routine for all the other init functions, below.
495 static struct ceph_osd_req_op *
496 _osd_req_op_init(struct ceph_osd_request *osd_req, unsigned int which,
497 u16 opcode, u32 flags)
499 struct ceph_osd_req_op *op;
501 BUG_ON(which >= osd_req->r_num_ops);
502 BUG_ON(!osd_req_opcode_valid(opcode));
504 op = &osd_req->r_ops[which];
505 memset(op, 0, sizeof (*op));
512 void osd_req_op_init(struct ceph_osd_request *osd_req,
513 unsigned int which, u16 opcode, u32 flags)
515 (void)_osd_req_op_init(osd_req, which, opcode, flags);
517 EXPORT_SYMBOL(osd_req_op_init);
519 void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
520 unsigned int which, u16 opcode,
521 u64 offset, u64 length,
522 u64 truncate_size, u32 truncate_seq)
524 struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which,
526 size_t payload_len = 0;
528 BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE &&
529 opcode != CEPH_OSD_OP_WRITEFULL && opcode != CEPH_OSD_OP_ZERO &&
530 opcode != CEPH_OSD_OP_TRUNCATE);
532 op->extent.offset = offset;
533 op->extent.length = length;
534 op->extent.truncate_size = truncate_size;
535 op->extent.truncate_seq = truncate_seq;
536 if (opcode == CEPH_OSD_OP_WRITE || opcode == CEPH_OSD_OP_WRITEFULL)
537 payload_len += length;
539 op->indata_len = payload_len;
541 EXPORT_SYMBOL(osd_req_op_extent_init);
543 void osd_req_op_extent_update(struct ceph_osd_request *osd_req,
544 unsigned int which, u64 length)
546 struct ceph_osd_req_op *op;
549 BUG_ON(which >= osd_req->r_num_ops);
550 op = &osd_req->r_ops[which];
551 previous = op->extent.length;
553 if (length == previous)
554 return; /* Nothing to do */
555 BUG_ON(length > previous);
557 op->extent.length = length;
558 op->indata_len -= previous - length;
560 EXPORT_SYMBOL(osd_req_op_extent_update);
562 void osd_req_op_extent_dup_last(struct ceph_osd_request *osd_req,
563 unsigned int which, u64 offset_inc)
565 struct ceph_osd_req_op *op, *prev_op;
567 BUG_ON(which + 1 >= osd_req->r_num_ops);
569 prev_op = &osd_req->r_ops[which];
570 op = _osd_req_op_init(osd_req, which + 1, prev_op->op, prev_op->flags);
571 /* dup previous one */
572 op->indata_len = prev_op->indata_len;
573 op->outdata_len = prev_op->outdata_len;
574 op->extent = prev_op->extent;
576 op->extent.offset += offset_inc;
577 op->extent.length -= offset_inc;
579 if (op->op == CEPH_OSD_OP_WRITE || op->op == CEPH_OSD_OP_WRITEFULL)
580 op->indata_len -= offset_inc;
582 EXPORT_SYMBOL(osd_req_op_extent_dup_last);
584 void osd_req_op_cls_init(struct ceph_osd_request *osd_req, unsigned int which,
585 u16 opcode, const char *class, const char *method)
587 struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which,
589 struct ceph_pagelist *pagelist;
590 size_t payload_len = 0;
593 BUG_ON(opcode != CEPH_OSD_OP_CALL);
595 pagelist = kmalloc(sizeof (*pagelist), GFP_NOFS);
597 ceph_pagelist_init(pagelist);
599 op->cls.class_name = class;
600 size = strlen(class);
601 BUG_ON(size > (size_t) U8_MAX);
602 op->cls.class_len = size;
603 ceph_pagelist_append(pagelist, class, size);
606 op->cls.method_name = method;
607 size = strlen(method);
608 BUG_ON(size > (size_t) U8_MAX);
609 op->cls.method_len = size;
610 ceph_pagelist_append(pagelist, method, size);
613 osd_req_op_cls_request_info_pagelist(osd_req, which, pagelist);
615 op->indata_len = payload_len;
617 EXPORT_SYMBOL(osd_req_op_cls_init);
619 int osd_req_op_xattr_init(struct ceph_osd_request *osd_req, unsigned int which,
620 u16 opcode, const char *name, const void *value,
621 size_t size, u8 cmp_op, u8 cmp_mode)
623 struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which,
625 struct ceph_pagelist *pagelist;
628 BUG_ON(opcode != CEPH_OSD_OP_SETXATTR && opcode != CEPH_OSD_OP_CMPXATTR);
630 pagelist = kmalloc(sizeof(*pagelist), GFP_NOFS);
634 ceph_pagelist_init(pagelist);
636 payload_len = strlen(name);
637 op->xattr.name_len = payload_len;
638 ceph_pagelist_append(pagelist, name, payload_len);
640 op->xattr.value_len = size;
641 ceph_pagelist_append(pagelist, value, size);
644 op->xattr.cmp_op = cmp_op;
645 op->xattr.cmp_mode = cmp_mode;
647 ceph_osd_data_pagelist_init(&op->xattr.osd_data, pagelist);
648 op->indata_len = payload_len;
651 EXPORT_SYMBOL(osd_req_op_xattr_init);
653 void osd_req_op_watch_init(struct ceph_osd_request *osd_req,
654 unsigned int which, u16 opcode,
655 u64 cookie, u64 version, int flag)
657 struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which,
660 BUG_ON(opcode != CEPH_OSD_OP_NOTIFY_ACK && opcode != CEPH_OSD_OP_WATCH);
662 op->watch.cookie = cookie;
663 op->watch.ver = version;
664 if (opcode == CEPH_OSD_OP_WATCH && flag)
665 op->watch.flag = (u8)1;
667 EXPORT_SYMBOL(osd_req_op_watch_init);
669 void osd_req_op_alloc_hint_init(struct ceph_osd_request *osd_req,
671 u64 expected_object_size,
672 u64 expected_write_size)
674 struct ceph_osd_req_op *op = _osd_req_op_init(osd_req, which,
675 CEPH_OSD_OP_SETALLOCHINT,
678 op->alloc_hint.expected_object_size = expected_object_size;
679 op->alloc_hint.expected_write_size = expected_write_size;
682 * CEPH_OSD_OP_SETALLOCHINT op is advisory and therefore deemed
683 * not worth a feature bit. Set FAILOK per-op flag to make
684 * sure older osds don't trip over an unsupported opcode.
686 op->flags |= CEPH_OSD_OP_FLAG_FAILOK;
688 EXPORT_SYMBOL(osd_req_op_alloc_hint_init);
690 static void ceph_osdc_msg_data_add(struct ceph_msg *msg,
691 struct ceph_osd_data *osd_data)
693 u64 length = ceph_osd_data_length(osd_data);
695 if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGES) {
696 BUG_ON(length > (u64) SIZE_MAX);
698 ceph_msg_data_add_pages(msg, osd_data->pages,
699 length, osd_data->alignment);
700 } else if (osd_data->type == CEPH_OSD_DATA_TYPE_PAGELIST) {
702 ceph_msg_data_add_pagelist(msg, osd_data->pagelist);
704 } else if (osd_data->type == CEPH_OSD_DATA_TYPE_BIO) {
705 ceph_msg_data_add_bio(msg, osd_data->bio, length);
708 BUG_ON(osd_data->type != CEPH_OSD_DATA_TYPE_NONE);
712 static u32 osd_req_encode_op(struct ceph_osd_op *dst,
713 const struct ceph_osd_req_op *src)
715 if (WARN_ON(!osd_req_opcode_valid(src->op))) {
716 pr_err("unrecognized osd opcode %d\n", src->op);
722 case CEPH_OSD_OP_STAT:
724 case CEPH_OSD_OP_READ:
725 case CEPH_OSD_OP_WRITE:
726 case CEPH_OSD_OP_WRITEFULL:
727 case CEPH_OSD_OP_ZERO:
728 case CEPH_OSD_OP_TRUNCATE:
729 dst->extent.offset = cpu_to_le64(src->extent.offset);
730 dst->extent.length = cpu_to_le64(src->extent.length);
731 dst->extent.truncate_size =
732 cpu_to_le64(src->extent.truncate_size);
733 dst->extent.truncate_seq =
734 cpu_to_le32(src->extent.truncate_seq);
736 case CEPH_OSD_OP_CALL:
737 dst->cls.class_len = src->cls.class_len;
738 dst->cls.method_len = src->cls.method_len;
739 dst->cls.indata_len = cpu_to_le32(src->cls.indata_len);
741 case CEPH_OSD_OP_STARTSYNC:
743 case CEPH_OSD_OP_NOTIFY_ACK:
744 case CEPH_OSD_OP_WATCH:
745 dst->watch.cookie = cpu_to_le64(src->watch.cookie);
746 dst->watch.ver = cpu_to_le64(src->watch.ver);
747 dst->watch.flag = src->watch.flag;
749 case CEPH_OSD_OP_SETALLOCHINT:
750 dst->alloc_hint.expected_object_size =
751 cpu_to_le64(src->alloc_hint.expected_object_size);
752 dst->alloc_hint.expected_write_size =
753 cpu_to_le64(src->alloc_hint.expected_write_size);
755 case CEPH_OSD_OP_SETXATTR:
756 case CEPH_OSD_OP_CMPXATTR:
757 dst->xattr.name_len = cpu_to_le32(src->xattr.name_len);
758 dst->xattr.value_len = cpu_to_le32(src->xattr.value_len);
759 dst->xattr.cmp_op = src->xattr.cmp_op;
760 dst->xattr.cmp_mode = src->xattr.cmp_mode;
762 case CEPH_OSD_OP_CREATE:
763 case CEPH_OSD_OP_DELETE:
766 pr_err("unsupported osd opcode %s\n",
767 ceph_osd_op_name(src->op));
773 dst->op = cpu_to_le16(src->op);
774 dst->flags = cpu_to_le32(src->flags);
775 dst->payload_len = cpu_to_le32(src->indata_len);
777 return src->indata_len;
781 * build new request AND message, calculate layout, and adjust file
784 * if the file was recently truncated, we include information about its
785 * old and new size so that the object can be updated appropriately. (we
786 * avoid synchronously deleting truncated objects because it's slow.)
788 * if @do_sync, include a 'startsync' command so that the osd will flush
791 struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
792 struct ceph_file_layout *layout,
793 struct ceph_vino vino,
795 unsigned int which, int num_ops,
796 int opcode, int flags,
797 struct ceph_snap_context *snapc,
802 struct ceph_osd_request *req;
808 BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE &&
809 opcode != CEPH_OSD_OP_ZERO && opcode != CEPH_OSD_OP_TRUNCATE &&
810 opcode != CEPH_OSD_OP_CREATE && opcode != CEPH_OSD_OP_DELETE);
812 req = ceph_osdc_alloc_request(osdc, snapc, num_ops, use_mempool,
819 /* calculate max write size */
820 r = calc_layout(layout, off, plen, &objnum, &objoff, &objlen);
824 if (opcode == CEPH_OSD_OP_CREATE || opcode == CEPH_OSD_OP_DELETE) {
825 osd_req_op_init(req, which, opcode, 0);
827 u32 object_size = le32_to_cpu(layout->fl_object_size);
828 u32 object_base = off - objoff;
829 if (!(truncate_seq == 1 && truncate_size == -1ULL)) {
830 if (truncate_size <= object_base) {
833 truncate_size -= object_base;
834 if (truncate_size > object_size)
835 truncate_size = object_size;
838 osd_req_op_extent_init(req, which, opcode, objoff, objlen,
839 truncate_size, truncate_seq);
842 req->r_flags = flags;
843 req->r_base_oloc.pool = ceph_file_layout_pg_pool(*layout);
844 ceph_oid_printf(&req->r_base_oid, "%llx.%08llx", vino.ino, objnum);
846 req->r_snapid = vino.snap;
847 if (flags & CEPH_OSD_FLAG_WRITE)
848 req->r_data_offset = off;
850 r = ceph_osdc_alloc_messages(req, GFP_NOFS);
857 ceph_osdc_put_request(req);
860 EXPORT_SYMBOL(ceph_osdc_new_request);
863 * We keep osd requests in an rbtree, sorted by ->r_tid.
865 DEFINE_RB_FUNCS(request, struct ceph_osd_request, r_tid, r_node)
867 static struct ceph_osd_request *
868 __lookup_request_ge(struct ceph_osd_client *osdc,
871 struct ceph_osd_request *req;
872 struct rb_node *n = osdc->requests.rb_node;
875 req = rb_entry(n, struct ceph_osd_request, r_node);
876 if (tid < req->r_tid) {
880 } else if (tid > req->r_tid) {
889 static void __kick_linger_request(struct ceph_osd_request *req)
891 struct ceph_osd_client *osdc = req->r_osdc;
892 struct ceph_osd *osd = req->r_osd;
895 * Linger requests need to be resent with a new tid to avoid
896 * the dup op detection logic on the OSDs. Achieve this with
897 * a re-register dance instead of open-coding.
899 ceph_osdc_get_request(req);
900 if (!list_empty(&req->r_linger_item))
901 __unregister_linger_request(osdc, req);
903 __unregister_request(osdc, req);
904 __register_request(osdc, req);
905 ceph_osdc_put_request(req);
908 * Unless request has been registered as both normal and
909 * lingering, __unregister{,_linger}_request clears r_osd.
910 * However, here we need to preserve r_osd to make sure we
911 * requeue on the same OSD.
913 WARN_ON(req->r_osd || !osd);
916 dout("%s requeueing %p tid %llu\n", __func__, req, req->r_tid);
917 __enqueue_request(req);
921 * Resubmit requests pending on the given osd.
923 static void __kick_osd_requests(struct ceph_osd_client *osdc,
924 struct ceph_osd *osd)
926 struct ceph_osd_request *req, *nreq;
928 LIST_HEAD(resend_linger);
931 dout("%s osd%d\n", __func__, osd->o_osd);
932 err = __reset_osd(osdc, osd);
937 * Build up a list of requests to resend by traversing the
938 * osd's list of requests. Requests for a given object are
939 * sent in tid order, and that is also the order they're
940 * kept on this list. Therefore all requests that are in
941 * flight will be found first, followed by all requests that
942 * have not yet been sent. And to resend requests while
943 * preserving this order we will want to put any sent
944 * requests back on the front of the osd client's unsent
947 * So we build a separate ordered list of already-sent
948 * requests for the affected osd and splice it onto the
949 * front of the osd client's unsent list. Once we've seen a
950 * request that has not yet been sent we're done. Those
951 * requests are already sitting right where they belong.
953 list_for_each_entry(req, &osd->o_requests, r_osd_item) {
957 if (!req->r_linger) {
958 dout("%s requeueing %p tid %llu\n", __func__, req,
960 list_move_tail(&req->r_req_lru_item, &resend);
961 req->r_flags |= CEPH_OSD_FLAG_RETRY;
963 list_move_tail(&req->r_req_lru_item, &resend_linger);
966 list_splice(&resend, &osdc->req_unsent);
969 * Both registered and not yet registered linger requests are
970 * enqueued with a new tid on the same OSD. We add/move them
971 * to req_unsent/o_requests at the end to keep things in tid
974 list_for_each_entry_safe(req, nreq, &osd->o_linger_requests,
976 WARN_ON(!list_empty(&req->r_req_lru_item));
977 __kick_linger_request(req);
980 list_for_each_entry_safe(req, nreq, &resend_linger, r_req_lru_item)
981 __kick_linger_request(req);
985 * If the osd connection drops, we need to resubmit all requests.
987 static void osd_reset(struct ceph_connection *con)
989 struct ceph_osd *osd = con->private;
990 struct ceph_osd_client *osdc;
994 dout("osd_reset osd%d\n", osd->o_osd);
996 down_read(&osdc->map_sem);
997 mutex_lock(&osdc->request_mutex);
998 __kick_osd_requests(osdc, osd);
1000 mutex_unlock(&osdc->request_mutex);
1001 up_read(&osdc->map_sem);
1005 * Track open sessions with osds.
1007 static struct ceph_osd *create_osd(struct ceph_osd_client *osdc, int onum)
1009 struct ceph_osd *osd;
1011 osd = kzalloc(sizeof(*osd), GFP_NOFS);
1015 atomic_set(&osd->o_ref, 1);
1018 RB_CLEAR_NODE(&osd->o_node);
1019 INIT_LIST_HEAD(&osd->o_requests);
1020 INIT_LIST_HEAD(&osd->o_linger_requests);
1021 INIT_LIST_HEAD(&osd->o_osd_lru);
1022 osd->o_incarnation = 1;
1024 ceph_con_init(&osd->o_con, osd, &osd_con_ops, &osdc->client->msgr);
1026 INIT_LIST_HEAD(&osd->o_keepalive_item);
1030 static struct ceph_osd *get_osd(struct ceph_osd *osd)
1032 if (atomic_inc_not_zero(&osd->o_ref)) {
1033 dout("get_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref)-1,
1034 atomic_read(&osd->o_ref));
1037 dout("get_osd %p FAIL\n", osd);
1042 static void put_osd(struct ceph_osd *osd)
1044 dout("put_osd %p %d -> %d\n", osd, atomic_read(&osd->o_ref),
1045 atomic_read(&osd->o_ref) - 1);
1046 if (atomic_dec_and_test(&osd->o_ref)) {
1047 if (osd->o_auth.authorizer)
1048 ceph_auth_destroy_authorizer(osd->o_auth.authorizer);
1053 DEFINE_RB_FUNCS(osd, struct ceph_osd, o_osd, o_node)
1056 * remove an osd from our map
1058 static void __remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
1060 dout("%s %p osd%d\n", __func__, osd, osd->o_osd);
1061 WARN_ON(!list_empty(&osd->o_requests));
1062 WARN_ON(!list_empty(&osd->o_linger_requests));
1064 list_del_init(&osd->o_osd_lru);
1065 erase_osd(&osdc->osds, osd);
1068 static void remove_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
1070 dout("%s %p osd%d\n", __func__, osd, osd->o_osd);
1072 if (!RB_EMPTY_NODE(&osd->o_node)) {
1073 ceph_con_close(&osd->o_con);
1074 __remove_osd(osdc, osd);
1079 static void __move_osd_to_lru(struct ceph_osd_client *osdc,
1080 struct ceph_osd *osd)
1082 dout("%s %p\n", __func__, osd);
1083 BUG_ON(!list_empty(&osd->o_osd_lru));
1085 list_add_tail(&osd->o_osd_lru, &osdc->osd_lru);
1086 osd->lru_ttl = jiffies + osdc->client->options->osd_idle_ttl;
1089 static void maybe_move_osd_to_lru(struct ceph_osd_client *osdc,
1090 struct ceph_osd *osd)
1092 dout("%s %p\n", __func__, osd);
1094 if (list_empty(&osd->o_requests) &&
1095 list_empty(&osd->o_linger_requests))
1096 __move_osd_to_lru(osdc, osd);
1099 static void __remove_osd_from_lru(struct ceph_osd *osd)
1101 dout("__remove_osd_from_lru %p\n", osd);
1102 if (!list_empty(&osd->o_osd_lru))
1103 list_del_init(&osd->o_osd_lru);
1109 static int __reset_osd(struct ceph_osd_client *osdc, struct ceph_osd *osd)
1111 struct ceph_entity_addr *peer_addr;
1113 dout("__reset_osd %p osd%d\n", osd, osd->o_osd);
1114 if (list_empty(&osd->o_requests) &&
1115 list_empty(&osd->o_linger_requests)) {
1116 remove_osd(osdc, osd);
1120 peer_addr = &osdc->osdmap->osd_addr[osd->o_osd];
1121 if (!memcmp(peer_addr, &osd->o_con.peer_addr, sizeof (*peer_addr)) &&
1122 !ceph_con_opened(&osd->o_con)) {
1123 struct ceph_osd_request *req;
1125 dout("osd addr hasn't changed and connection never opened, "
1126 "letting msgr retry\n");
1127 /* touch each r_stamp for handle_timeout()'s benfit */
1128 list_for_each_entry(req, &osd->o_requests, r_osd_item)
1129 req->r_stamp = jiffies;
1134 ceph_con_close(&osd->o_con);
1135 ceph_con_open(&osd->o_con, CEPH_ENTITY_TYPE_OSD, osd->o_osd, peer_addr);
1136 osd->o_incarnation++;
1141 static void __schedule_osd_timeout(struct ceph_osd_client *osdc)
1143 schedule_delayed_work(&osdc->timeout_work,
1144 osdc->client->options->osd_keepalive_timeout);
1147 static void __cancel_osd_timeout(struct ceph_osd_client *osdc)
1149 cancel_delayed_work(&osdc->timeout_work);
1153 * Register request, assign tid. If this is the first request, set up
1154 * the timeout event.
1156 static void __register_request(struct ceph_osd_client *osdc,
1157 struct ceph_osd_request *req)
1159 req->r_tid = ++osdc->last_tid;
1160 req->r_request->hdr.tid = cpu_to_le64(req->r_tid);
1161 dout("__register_request %p tid %lld\n", req, req->r_tid);
1162 insert_request(&osdc->requests, req);
1163 ceph_osdc_get_request(req);
1164 osdc->num_requests++;
1165 if (osdc->num_requests == 1) {
1166 dout(" first request, scheduling timeout\n");
1167 __schedule_osd_timeout(osdc);
1172 * called under osdc->request_mutex
1174 static void __unregister_request(struct ceph_osd_client *osdc,
1175 struct ceph_osd_request *req)
1177 if (RB_EMPTY_NODE(&req->r_node)) {
1178 dout("__unregister_request %p tid %lld not registered\n",
1183 dout("__unregister_request %p tid %lld\n", req, req->r_tid);
1184 erase_request(&osdc->requests, req);
1185 osdc->num_requests--;
1188 /* make sure the original request isn't in flight. */
1189 ceph_msg_revoke(req->r_request);
1191 list_del_init(&req->r_osd_item);
1192 maybe_move_osd_to_lru(osdc, req->r_osd);
1193 if (list_empty(&req->r_linger_osd_item))
1197 list_del_init(&req->r_req_lru_item);
1198 ceph_osdc_put_request(req);
1200 if (osdc->num_requests == 0) {
1201 dout(" no requests, canceling timeout\n");
1202 __cancel_osd_timeout(osdc);
1207 * Cancel a previously queued request message
1209 static void __cancel_request(struct ceph_osd_request *req)
1211 if (req->r_sent && req->r_osd) {
1212 ceph_msg_revoke(req->r_request);
1217 static void __register_linger_request(struct ceph_osd_client *osdc,
1218 struct ceph_osd_request *req)
1220 dout("%s %p tid %llu\n", __func__, req, req->r_tid);
1221 WARN_ON(!req->r_linger);
1223 ceph_osdc_get_request(req);
1224 list_add_tail(&req->r_linger_item, &osdc->req_linger);
1226 list_add_tail(&req->r_linger_osd_item,
1227 &req->r_osd->o_linger_requests);
1230 static void __unregister_linger_request(struct ceph_osd_client *osdc,
1231 struct ceph_osd_request *req)
1233 WARN_ON(!req->r_linger);
1235 if (list_empty(&req->r_linger_item)) {
1236 dout("%s %p tid %llu not registered\n", __func__, req,
1241 dout("%s %p tid %llu\n", __func__, req, req->r_tid);
1242 list_del_init(&req->r_linger_item);
1245 list_del_init(&req->r_linger_osd_item);
1246 maybe_move_osd_to_lru(osdc, req->r_osd);
1247 if (list_empty(&req->r_osd_item))
1250 ceph_osdc_put_request(req);
1253 void ceph_osdc_set_request_linger(struct ceph_osd_client *osdc,
1254 struct ceph_osd_request *req)
1256 if (!req->r_linger) {
1257 dout("set_request_linger %p\n", req);
1261 EXPORT_SYMBOL(ceph_osdc_set_request_linger);
1263 static bool __pool_full(struct ceph_pg_pool_info *pi)
1265 return pi->flags & CEPH_POOL_FLAG_FULL;
1269 * Returns whether a request should be blocked from being sent
1270 * based on the current osdmap and osd_client settings.
1272 * Caller should hold map_sem for read.
1274 static bool target_should_be_paused(struct ceph_osd_client *osdc,
1275 const struct ceph_osd_request_target *t,
1276 struct ceph_pg_pool_info *pi)
1278 bool pauserd = ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSERD);
1279 bool pausewr = ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSEWR) ||
1280 ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL) ||
1283 WARN_ON(pi->id != t->base_oloc.pool);
1284 return (t->flags & CEPH_OSD_FLAG_READ && pauserd) ||
1285 (t->flags & CEPH_OSD_FLAG_WRITE && pausewr);
1288 enum calc_target_result {
1289 CALC_TARGET_NO_ACTION = 0,
1290 CALC_TARGET_NEED_RESEND,
1291 CALC_TARGET_POOL_DNE,
1294 static enum calc_target_result calc_target(struct ceph_osd_client *osdc,
1295 struct ceph_osd_request_target *t,
1296 u32 *last_force_resend,
1299 struct ceph_pg_pool_info *pi;
1300 struct ceph_pg pgid, last_pgid;
1301 struct ceph_osds up, acting;
1302 bool force_resend = false;
1303 bool need_check_tiering = false;
1304 bool need_resend = false;
1305 bool sort_bitwise = ceph_osdmap_flag(osdc->osdmap,
1306 CEPH_OSDMAP_SORTBITWISE);
1307 enum calc_target_result ct_res;
1310 pi = ceph_pg_pool_by_id(osdc->osdmap, t->base_oloc.pool);
1312 t->osd = CEPH_HOMELESS_OSD;
1313 ct_res = CALC_TARGET_POOL_DNE;
1317 if (osdc->osdmap->epoch == pi->last_force_request_resend) {
1318 if (last_force_resend &&
1319 *last_force_resend < pi->last_force_request_resend) {
1320 *last_force_resend = pi->last_force_request_resend;
1321 force_resend = true;
1322 } else if (!last_force_resend) {
1323 force_resend = true;
1326 if (ceph_oid_empty(&t->target_oid) || force_resend) {
1327 ceph_oid_copy(&t->target_oid, &t->base_oid);
1328 need_check_tiering = true;
1330 if (ceph_oloc_empty(&t->target_oloc) || force_resend) {
1331 ceph_oloc_copy(&t->target_oloc, &t->base_oloc);
1332 need_check_tiering = true;
1335 if (need_check_tiering &&
1336 (t->flags & CEPH_OSD_FLAG_IGNORE_OVERLAY) == 0) {
1337 if (t->flags & CEPH_OSD_FLAG_READ && pi->read_tier >= 0)
1338 t->target_oloc.pool = pi->read_tier;
1339 if (t->flags & CEPH_OSD_FLAG_WRITE && pi->write_tier >= 0)
1340 t->target_oloc.pool = pi->write_tier;
1343 ret = ceph_object_locator_to_pg(osdc->osdmap, &t->target_oid,
1344 &t->target_oloc, &pgid);
1346 WARN_ON(ret != -ENOENT);
1347 t->osd = CEPH_HOMELESS_OSD;
1348 ct_res = CALC_TARGET_POOL_DNE;
1351 last_pgid.pool = pgid.pool;
1352 last_pgid.seed = ceph_stable_mod(pgid.seed, t->pg_num, t->pg_num_mask);
1354 ceph_pg_to_up_acting_osds(osdc->osdmap, &pgid, &up, &acting);
1356 ceph_is_new_interval(&t->acting,
1369 force_resend = true;
1371 if (t->paused && !target_should_be_paused(osdc, t, pi)) {
1376 if (ceph_pg_compare(&t->pgid, &pgid) ||
1377 ceph_osds_changed(&t->acting, &acting, any_change) ||
1379 t->pgid = pgid; /* struct */
1380 ceph_osds_copy(&t->acting, &acting);
1381 ceph_osds_copy(&t->up, &up);
1383 t->min_size = pi->min_size;
1384 t->pg_num = pi->pg_num;
1385 t->pg_num_mask = pi->pg_num_mask;
1386 t->sort_bitwise = sort_bitwise;
1388 t->osd = acting.primary;
1392 ct_res = need_resend ? CALC_TARGET_NEED_RESEND : CALC_TARGET_NO_ACTION;
1394 dout("%s t %p -> ct_res %d osd %d\n", __func__, t, ct_res, t->osd);
1398 static void __enqueue_request(struct ceph_osd_request *req)
1400 struct ceph_osd_client *osdc = req->r_osdc;
1402 dout("%s %p tid %llu to osd%d\n", __func__, req, req->r_tid,
1403 req->r_osd ? req->r_osd->o_osd : -1);
1406 __remove_osd_from_lru(req->r_osd);
1407 list_add_tail(&req->r_osd_item, &req->r_osd->o_requests);
1408 list_move_tail(&req->r_req_lru_item, &osdc->req_unsent);
1410 list_move_tail(&req->r_req_lru_item, &osdc->req_notarget);
1415 * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
1416 * (as needed), and set the request r_osd appropriately. If there is
1417 * no up osd, set r_osd to NULL. Move the request to the appropriate list
1418 * (unsent, homeless) or leave on in-flight lru.
1420 * Return 0 if unchanged, 1 if changed, or negative on error.
1422 * Caller should hold map_sem for read and request_mutex.
1424 static int __map_request(struct ceph_osd_client *osdc,
1425 struct ceph_osd_request *req, int force_resend)
1427 enum calc_target_result ct_res;
1430 dout("map_request %p tid %lld\n", req, req->r_tid);
1432 ct_res = calc_target(osdc, &req->r_t, NULL, force_resend);
1434 case CALC_TARGET_POOL_DNE:
1435 list_move(&req->r_req_lru_item, &osdc->req_notarget);
1437 case CALC_TARGET_NO_ACTION:
1438 return 0; /* no change */
1440 BUG_ON(ct_res != CALC_TARGET_NEED_RESEND);
1443 dout("map_request tid %llu pgid %lld.%x osd%d (was osd%d)\n",
1444 req->r_tid, req->r_t.pgid.pool, req->r_t.pgid.seed, req->r_t.osd,
1445 req->r_osd ? req->r_osd->o_osd : -1);
1448 __cancel_request(req);
1449 list_del_init(&req->r_osd_item);
1450 list_del_init(&req->r_linger_osd_item);
1454 req->r_osd = lookup_osd(&osdc->osds, req->r_t.osd);
1455 if (!req->r_osd && req->r_t.osd >= 0) {
1457 req->r_osd = create_osd(osdc, req->r_t.osd);
1459 list_move(&req->r_req_lru_item, &osdc->req_notarget);
1463 dout("map_request osd %p is osd%d\n", req->r_osd,
1465 insert_osd(&osdc->osds, req->r_osd);
1467 ceph_con_open(&req->r_osd->o_con,
1468 CEPH_ENTITY_TYPE_OSD, req->r_osd->o_osd,
1469 &osdc->osdmap->osd_addr[req->r_osd->o_osd]);
1472 __enqueue_request(req);
1473 err = 1; /* osd or pg changed */
1479 static void setup_request_data(struct ceph_osd_request *req,
1480 struct ceph_msg *msg)
1485 if (!list_empty(&msg->data))
1488 WARN_ON(msg->data_length);
1489 for (i = 0; i < req->r_num_ops; i++) {
1490 struct ceph_osd_req_op *op = &req->r_ops[i];
1494 case CEPH_OSD_OP_WRITE:
1495 case CEPH_OSD_OP_WRITEFULL:
1496 WARN_ON(op->indata_len != op->extent.length);
1497 ceph_osdc_msg_data_add(msg, &op->extent.osd_data);
1499 case CEPH_OSD_OP_SETXATTR:
1500 case CEPH_OSD_OP_CMPXATTR:
1501 WARN_ON(op->indata_len != op->xattr.name_len +
1502 op->xattr.value_len);
1503 ceph_osdc_msg_data_add(msg, &op->xattr.osd_data);
1507 case CEPH_OSD_OP_STAT:
1508 ceph_osdc_msg_data_add(req->r_reply,
1511 case CEPH_OSD_OP_READ:
1512 ceph_osdc_msg_data_add(req->r_reply,
1513 &op->extent.osd_data);
1517 case CEPH_OSD_OP_CALL:
1518 WARN_ON(op->indata_len != op->cls.class_len +
1519 op->cls.method_len +
1520 op->cls.indata_len);
1521 ceph_osdc_msg_data_add(msg, &op->cls.request_info);
1522 /* optional, can be NONE */
1523 ceph_osdc_msg_data_add(msg, &op->cls.request_data);
1524 /* optional, can be NONE */
1525 ceph_osdc_msg_data_add(req->r_reply,
1526 &op->cls.response_data);
1530 data_len += op->indata_len;
1533 WARN_ON(data_len != msg->data_length);
1536 static void encode_request(struct ceph_osd_request *req, struct ceph_msg *msg)
1538 void *p = msg->front.iov_base;
1539 void *const end = p + msg->front_alloc_len;
1543 if (req->r_flags & CEPH_OSD_FLAG_WRITE) {
1544 /* snapshots aren't writeable */
1545 WARN_ON(req->r_snapid != CEPH_NOSNAP);
1547 WARN_ON(req->r_mtime.tv_sec || req->r_mtime.tv_nsec ||
1548 req->r_data_offset || req->r_snapc);
1551 setup_request_data(req, msg);
1553 ceph_encode_32(&p, 1); /* client_inc, always 1 */
1554 ceph_encode_32(&p, req->r_osdc->osdmap->epoch);
1555 ceph_encode_32(&p, req->r_flags);
1556 ceph_encode_timespec(p, &req->r_mtime);
1557 p += sizeof(struct ceph_timespec);
1558 /* aka reassert_version */
1559 memcpy(p, &req->r_replay_version, sizeof(req->r_replay_version));
1560 p += sizeof(req->r_replay_version);
1563 ceph_encode_8(&p, 4);
1564 ceph_encode_8(&p, 4);
1565 ceph_encode_32(&p, 8 + 4 + 4);
1566 ceph_encode_64(&p, req->r_t.target_oloc.pool);
1567 ceph_encode_32(&p, -1); /* preferred */
1568 ceph_encode_32(&p, 0); /* key len */
1571 ceph_encode_8(&p, 1);
1572 ceph_encode_64(&p, req->r_t.pgid.pool);
1573 ceph_encode_32(&p, req->r_t.pgid.seed);
1574 ceph_encode_32(&p, -1); /* preferred */
1577 ceph_encode_32(&p, req->r_t.target_oid.name_len);
1578 memcpy(p, req->r_t.target_oid.name, req->r_t.target_oid.name_len);
1579 p += req->r_t.target_oid.name_len;
1581 /* ops, can imply data */
1582 ceph_encode_16(&p, req->r_num_ops);
1583 for (i = 0; i < req->r_num_ops; i++) {
1584 data_len += osd_req_encode_op(p, &req->r_ops[i]);
1585 p += sizeof(struct ceph_osd_op);
1588 ceph_encode_64(&p, req->r_snapid); /* snapid */
1590 ceph_encode_64(&p, req->r_snapc->seq);
1591 ceph_encode_32(&p, req->r_snapc->num_snaps);
1592 for (i = 0; i < req->r_snapc->num_snaps; i++)
1593 ceph_encode_64(&p, req->r_snapc->snaps[i]);
1595 ceph_encode_64(&p, 0); /* snap_seq */
1596 ceph_encode_32(&p, 0); /* snaps len */
1599 ceph_encode_32(&p, req->r_attempts); /* retry_attempt */
1602 msg->front.iov_len = p - msg->front.iov_base;
1603 msg->hdr.version = cpu_to_le16(4); /* MOSDOp v4 */
1604 msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
1605 msg->hdr.data_len = cpu_to_le32(data_len);
1607 * The header "data_off" is a hint to the receiver allowing it
1608 * to align received data into its buffers such that there's no
1609 * need to re-copy it before writing it to disk (direct I/O).
1611 msg->hdr.data_off = cpu_to_le16(req->r_data_offset);
1613 dout("%s req %p oid %*pE oid_len %d front %zu data %u\n", __func__,
1614 req, req->r_t.target_oid.name_len, req->r_t.target_oid.name,
1615 req->r_t.target_oid.name_len, msg->front.iov_len, data_len);
1619 * @req has to be assigned a tid and registered.
1621 static void send_request(struct ceph_osd_request *req)
1623 struct ceph_osd *osd = req->r_osd;
1625 WARN_ON(osd->o_osd != req->r_t.osd);
1627 req->r_flags |= CEPH_OSD_FLAG_KNOWN_REDIR;
1628 if (req->r_attempts)
1629 req->r_flags |= CEPH_OSD_FLAG_RETRY;
1631 WARN_ON(req->r_flags & CEPH_OSD_FLAG_RETRY);
1633 encode_request(req, req->r_request);
1635 dout("%s req %p tid %llu to pg %llu.%x osd%d flags 0x%x attempt %d\n",
1636 __func__, req, req->r_tid, req->r_t.pgid.pool, req->r_t.pgid.seed,
1637 req->r_t.osd, req->r_flags, req->r_attempts);
1639 req->r_t.paused = false;
1640 req->r_stamp = jiffies;
1643 req->r_sent = osd->o_incarnation;
1644 req->r_request->hdr.tid = cpu_to_le64(req->r_tid);
1645 ceph_con_send(&osd->o_con, ceph_msg_get(req->r_request));
1649 * Send any requests in the queue (req_unsent).
1651 static void __send_queued(struct ceph_osd_client *osdc)
1653 struct ceph_osd_request *req, *tmp;
1655 dout("__send_queued\n");
1656 list_for_each_entry_safe(req, tmp, &osdc->req_unsent, r_req_lru_item) {
1657 list_move_tail(&req->r_req_lru_item, &osdc->req_lru);
1663 * Caller should hold map_sem for read and request_mutex.
1665 static int __ceph_osdc_start_request(struct ceph_osd_client *osdc,
1666 struct ceph_osd_request *req,
1671 __register_request(osdc, req);
1673 req->r_got_reply = 0;
1674 rc = __map_request(osdc, req, 0);
1677 dout("osdc_start_request failed map, "
1678 " will retry %lld\n", req->r_tid);
1681 __unregister_request(osdc, req);
1686 if (req->r_osd == NULL) {
1687 dout("send_request %p no up osds in pg\n", req);
1688 ceph_monc_request_next_osdmap(&osdc->client->monc);
1690 __send_queued(osdc);
1696 static void __complete_request(struct ceph_osd_request *req)
1698 if (req->r_callback)
1699 req->r_callback(req);
1701 complete_all(&req->r_completion);
1705 * Timeout callback, called every N seconds when 1 or more osd
1706 * requests has been active for more than N seconds. When this
1707 * happens, we ping all OSDs with requests who have timed out to
1708 * ensure any communications channel reset is detected. Reset the
1709 * request timeouts another N seconds in the future as we go.
1710 * Reschedule the timeout event another N seconds in future (unless
1711 * there are no open requests).
1713 static void handle_timeout(struct work_struct *work)
1715 struct ceph_osd_client *osdc =
1716 container_of(work, struct ceph_osd_client, timeout_work.work);
1717 struct ceph_options *opts = osdc->client->options;
1718 struct ceph_osd_request *req;
1719 struct ceph_osd *osd;
1720 struct list_head slow_osds;
1722 down_read(&osdc->map_sem);
1724 ceph_monc_request_next_osdmap(&osdc->client->monc);
1726 mutex_lock(&osdc->request_mutex);
1729 * ping osds that are a bit slow. this ensures that if there
1730 * is a break in the TCP connection we will notice, and reopen
1731 * a connection with that osd (from the fault callback).
1733 INIT_LIST_HEAD(&slow_osds);
1734 list_for_each_entry(req, &osdc->req_lru, r_req_lru_item) {
1735 if (time_before(jiffies,
1736 req->r_stamp + opts->osd_keepalive_timeout))
1741 dout(" tid %llu is slow, will send keepalive on osd%d\n",
1742 req->r_tid, osd->o_osd);
1743 list_move_tail(&osd->o_keepalive_item, &slow_osds);
1745 while (!list_empty(&slow_osds)) {
1746 osd = list_entry(slow_osds.next, struct ceph_osd,
1748 list_del_init(&osd->o_keepalive_item);
1749 ceph_con_keepalive(&osd->o_con);
1752 __schedule_osd_timeout(osdc);
1753 __send_queued(osdc);
1754 mutex_unlock(&osdc->request_mutex);
1755 up_read(&osdc->map_sem);
1758 static void handle_osds_timeout(struct work_struct *work)
1760 struct ceph_osd_client *osdc =
1761 container_of(work, struct ceph_osd_client,
1762 osds_timeout_work.work);
1763 unsigned long delay = osdc->client->options->osd_idle_ttl / 4;
1764 struct ceph_osd *osd, *nosd;
1766 dout("%s osdc %p\n", __func__, osdc);
1767 down_read(&osdc->map_sem);
1768 mutex_lock(&osdc->request_mutex);
1770 list_for_each_entry_safe(osd, nosd, &osdc->osd_lru, o_osd_lru) {
1771 if (time_before(jiffies, osd->lru_ttl))
1774 remove_osd(osdc, osd);
1777 mutex_unlock(&osdc->request_mutex);
1778 up_read(&osdc->map_sem);
1779 schedule_delayed_work(&osdc->osds_timeout_work,
1780 round_jiffies_relative(delay));
1783 static int ceph_oloc_decode(void **p, void *end,
1784 struct ceph_object_locator *oloc)
1786 u8 struct_v, struct_cv;
1791 ceph_decode_need(p, end, 1 + 1 + 4, e_inval);
1792 struct_v = ceph_decode_8(p);
1793 struct_cv = ceph_decode_8(p);
1795 pr_warn("got v %d < 3 cv %d of ceph_object_locator\n",
1796 struct_v, struct_cv);
1799 if (struct_cv > 6) {
1800 pr_warn("got v %d cv %d > 6 of ceph_object_locator\n",
1801 struct_v, struct_cv);
1804 len = ceph_decode_32(p);
1805 ceph_decode_need(p, end, len, e_inval);
1806 struct_end = *p + len;
1808 oloc->pool = ceph_decode_64(p);
1809 *p += 4; /* skip preferred */
1811 len = ceph_decode_32(p);
1813 pr_warn("ceph_object_locator::key is set\n");
1817 if (struct_v >= 5) {
1818 len = ceph_decode_32(p);
1820 pr_warn("ceph_object_locator::nspace is set\n");
1825 if (struct_v >= 6) {
1826 s64 hash = ceph_decode_64(p);
1828 pr_warn("ceph_object_locator::hash is set\n");
1843 static int ceph_redirect_decode(void **p, void *end,
1844 struct ceph_request_redirect *redir)
1846 u8 struct_v, struct_cv;
1851 ceph_decode_need(p, end, 1 + 1 + 4, e_inval);
1852 struct_v = ceph_decode_8(p);
1853 struct_cv = ceph_decode_8(p);
1854 if (struct_cv > 1) {
1855 pr_warn("got v %d cv %d > 1 of ceph_request_redirect\n",
1856 struct_v, struct_cv);
1859 len = ceph_decode_32(p);
1860 ceph_decode_need(p, end, len, e_inval);
1861 struct_end = *p + len;
1863 ret = ceph_oloc_decode(p, end, &redir->oloc);
1867 len = ceph_decode_32(p);
1869 pr_warn("ceph_request_redirect::object_name is set\n");
1873 len = ceph_decode_32(p);
1874 *p += len; /* skip osd_instructions */
1886 struct MOSDOpReply {
1887 struct ceph_pg pgid;
1892 u32 outdata_len[CEPH_OSD_MAX_OPS];
1893 s32 rval[CEPH_OSD_MAX_OPS];
1895 struct ceph_eversion replay_version;
1897 struct ceph_request_redirect redirect;
1900 static int decode_MOSDOpReply(const struct ceph_msg *msg, struct MOSDOpReply *m)
1902 void *p = msg->front.iov_base;
1903 void *const end = p + msg->front.iov_len;
1904 u16 version = le16_to_cpu(msg->hdr.version);
1905 struct ceph_eversion bad_replay_version;
1911 ceph_decode_32_safe(&p, end, len, e_inval);
1912 ceph_decode_need(&p, end, len, e_inval);
1913 p += len; /* skip oid */
1915 ret = ceph_decode_pgid(&p, end, &m->pgid);
1919 ceph_decode_64_safe(&p, end, m->flags, e_inval);
1920 ceph_decode_32_safe(&p, end, m->result, e_inval);
1921 ceph_decode_need(&p, end, sizeof(bad_replay_version), e_inval);
1922 memcpy(&bad_replay_version, p, sizeof(bad_replay_version));
1923 p += sizeof(bad_replay_version);
1924 ceph_decode_32_safe(&p, end, m->epoch, e_inval);
1926 ceph_decode_32_safe(&p, end, m->num_ops, e_inval);
1927 if (m->num_ops > ARRAY_SIZE(m->outdata_len))
1930 ceph_decode_need(&p, end, m->num_ops * sizeof(struct ceph_osd_op),
1932 for (i = 0; i < m->num_ops; i++) {
1933 struct ceph_osd_op *op = p;
1935 m->outdata_len[i] = le32_to_cpu(op->payload_len);
1939 ceph_decode_32_safe(&p, end, m->retry_attempt, e_inval);
1940 for (i = 0; i < m->num_ops; i++)
1941 ceph_decode_32_safe(&p, end, m->rval[i], e_inval);
1944 ceph_decode_need(&p, end, sizeof(m->replay_version), e_inval);
1945 memcpy(&m->replay_version, p, sizeof(m->replay_version));
1946 p += sizeof(m->replay_version);
1947 ceph_decode_64_safe(&p, end, m->user_version, e_inval);
1949 m->replay_version = bad_replay_version; /* struct */
1950 m->user_version = le64_to_cpu(m->replay_version.version);
1955 ceph_decode_8_safe(&p, end, decode_redir, e_inval);
1963 ret = ceph_redirect_decode(&p, end, &m->redirect);
1967 ceph_oloc_init(&m->redirect.oloc);
1977 * We are done with @req if
1978 * - @m is a safe reply, or
1979 * - @m is an unsafe reply and we didn't want a safe one
1981 static bool done_request(const struct ceph_osd_request *req,
1982 const struct MOSDOpReply *m)
1984 return (m->result < 0 ||
1985 (m->flags & CEPH_OSD_FLAG_ONDISK) ||
1986 !(req->r_flags & CEPH_OSD_FLAG_ONDISK));
1990 * handle osd op reply. either call the callback if it is specified,
1991 * or do the completion to wake up the waiting thread.
1993 * ->r_unsafe_callback is set? yes no
1995 * first reply is OK (needed r_cb/r_completion, r_cb/r_completion,
1996 * any or needed/got safe) r_safe_completion r_safe_completion
1998 * first reply is unsafe r_unsafe_cb(true) (nothing)
2000 * when we get the safe reply r_unsafe_cb(false), r_cb/r_completion,
2001 * r_safe_completion r_safe_completion
2003 static void handle_reply(struct ceph_osd_client *osdc, struct ceph_msg *msg)
2005 struct ceph_osd_request *req;
2006 struct MOSDOpReply m;
2007 u64 tid = le64_to_cpu(msg->hdr.tid);
2013 dout("%s msg %p tid %llu\n", __func__, msg, tid);
2015 down_read(&osdc->map_sem);
2016 mutex_lock(&osdc->request_mutex);
2017 req = lookup_request(&osdc->requests, tid);
2019 dout("%s no tid %llu\n", __func__, tid);
2022 ceph_osdc_get_request(req);
2024 ret = decode_MOSDOpReply(msg, &m);
2026 pr_err("failed to decode MOSDOpReply for tid %llu: %d\n",
2031 dout("%s req %p tid %llu flags 0x%llx pgid %llu.%x epoch %u attempt %d v %u'%llu uv %llu\n",
2032 __func__, req, req->r_tid, m.flags, m.pgid.pool, m.pgid.seed,
2033 m.epoch, m.retry_attempt, le32_to_cpu(m.replay_version.epoch),
2034 le64_to_cpu(m.replay_version.version), m.user_version);
2036 if (m.retry_attempt >= 0) {
2037 if (m.retry_attempt != req->r_attempts - 1) {
2038 dout("req %p tid %llu retry_attempt %d != %d, ignoring\n",
2039 req, req->r_tid, m.retry_attempt,
2040 req->r_attempts - 1);
2044 WARN_ON(1); /* MOSDOpReply v4 is assumed */
2047 if (!ceph_oloc_empty(&m.redirect.oloc)) {
2048 dout("req %p tid %llu redirect pool %lld\n", req, req->r_tid,
2049 m.redirect.oloc.pool);
2050 __unregister_request(osdc, req);
2052 ceph_oloc_copy(&req->r_t.target_oloc, &m.redirect.oloc);
2055 * Start redirect requests with nofail=true. If
2056 * mapping fails, request will end up on the notarget
2057 * list, waiting for the new osdmap (which can take
2058 * a while), even though the original request mapped
2059 * successfully. In the future we might want to follow
2060 * original request's nofail setting here.
2062 ret = __ceph_osdc_start_request(osdc, req, true);
2068 if (m.num_ops != req->r_num_ops) {
2069 pr_err("num_ops %d != %d for tid %llu\n", m.num_ops,
2070 req->r_num_ops, req->r_tid);
2073 for (i = 0; i < req->r_num_ops; i++) {
2074 dout(" req %p tid %llu op %d rval %d len %u\n", req,
2075 req->r_tid, i, m.rval[i], m.outdata_len[i]);
2076 req->r_ops[i].rval = m.rval[i];
2077 req->r_ops[i].outdata_len = m.outdata_len[i];
2078 data_len += m.outdata_len[i];
2080 if (data_len != le32_to_cpu(msg->hdr.data_len)) {
2081 pr_err("sum of lens %u != %u for tid %llu\n", data_len,
2082 le32_to_cpu(msg->hdr.data_len), req->r_tid);
2085 dout("%s req %p tid %llu acked %d result %d data_len %u\n", __func__,
2086 req, req->r_tid, req->r_got_reply, m.result, data_len);
2088 already_acked = req->r_got_reply;
2089 if (!already_acked) {
2090 req->r_result = m.result ?: data_len;
2091 req->r_replay_version = m.replay_version; /* struct */
2092 req->r_got_reply = true;
2093 } else if (!(m.flags & CEPH_OSD_FLAG_ONDISK)) {
2094 dout("req %p tid %llu dup ack\n", req, req->r_tid);
2098 if (done_request(req, &m)) {
2099 __unregister_request(osdc, req);
2100 if (req->r_linger) {
2101 WARN_ON(req->r_unsafe_callback);
2102 __register_linger_request(osdc, req);
2106 mutex_unlock(&osdc->request_mutex);
2107 up_read(&osdc->map_sem);
2109 if (done_request(req, &m)) {
2110 if (already_acked && req->r_unsafe_callback) {
2111 dout("req %p tid %llu safe-cb\n", req, req->r_tid);
2112 req->r_unsafe_callback(req, false);
2114 dout("req %p tid %llu cb\n", req, req->r_tid);
2115 __complete_request(req);
2118 if (req->r_unsafe_callback) {
2119 dout("req %p tid %llu unsafe-cb\n", req, req->r_tid);
2120 req->r_unsafe_callback(req, true);
2125 if (m.flags & CEPH_OSD_FLAG_ONDISK)
2126 complete_all(&req->r_safe_completion);
2128 ceph_osdc_put_request(req);
2132 req->r_result = -EIO;
2133 __unregister_request(osdc, req);
2134 __complete_request(req);
2135 complete_all(&req->r_safe_completion);
2137 ceph_osdc_put_request(req);
2139 mutex_unlock(&osdc->request_mutex);
2140 up_read(&osdc->map_sem);
2143 static void reset_changed_osds(struct ceph_osd_client *osdc)
2145 struct rb_node *p, *n;
2147 dout("%s %p\n", __func__, osdc);
2148 for (p = rb_first(&osdc->osds); p; p = n) {
2149 struct ceph_osd *osd = rb_entry(p, struct ceph_osd, o_node);
2152 if (!ceph_osd_is_up(osdc->osdmap, osd->o_osd) ||
2153 memcmp(&osd->o_con.peer_addr,
2154 ceph_osd_addr(osdc->osdmap,
2156 sizeof(struct ceph_entity_addr)) != 0)
2157 __reset_osd(osdc, osd);
2162 * Requeue requests whose mapping to an OSD has changed. If requests map to
2163 * no osd, request a new map.
2165 * Caller should hold map_sem for read.
2167 static void kick_requests(struct ceph_osd_client *osdc, bool force_resend,
2168 bool force_resend_writes)
2170 struct ceph_osd_request *req, *nreq;
2174 bool force_resend_req;
2176 dout("kick_requests %s %s\n", force_resend ? " (force resend)" : "",
2177 force_resend_writes ? " (force resend writes)" : "");
2178 mutex_lock(&osdc->request_mutex);
2179 for (p = rb_first(&osdc->requests); p; ) {
2180 req = rb_entry(p, struct ceph_osd_request, r_node);
2184 * For linger requests that have not yet been
2185 * registered, move them to the linger list; they'll
2186 * be sent to the osd in the loop below. Unregister
2187 * the request before re-registering it as a linger
2188 * request to ensure the __map_request() below
2189 * will decide it needs to be sent.
2191 if (req->r_linger && list_empty(&req->r_linger_item)) {
2192 dout("%p tid %llu restart on osd%d\n",
2194 req->r_osd ? req->r_osd->o_osd : -1);
2195 ceph_osdc_get_request(req);
2196 __unregister_request(osdc, req);
2197 __register_linger_request(osdc, req);
2198 ceph_osdc_put_request(req);
2202 force_resend_req = force_resend ||
2203 (force_resend_writes &&
2204 req->r_flags & CEPH_OSD_FLAG_WRITE);
2205 err = __map_request(osdc, req, force_resend_req);
2207 continue; /* error */
2208 if (req->r_osd == NULL) {
2209 dout("%p tid %llu maps to no osd\n", req, req->r_tid);
2210 needmap++; /* request a newer map */
2211 } else if (err > 0) {
2212 if (!req->r_linger) {
2213 dout("%p tid %llu requeued on osd%d\n", req,
2215 req->r_osd ? req->r_osd->o_osd : -1);
2216 req->r_flags |= CEPH_OSD_FLAG_RETRY;
2221 list_for_each_entry_safe(req, nreq, &osdc->req_linger,
2223 dout("linger req=%p req->r_osd=%p\n", req, req->r_osd);
2225 err = __map_request(osdc, req,
2226 force_resend || force_resend_writes);
2227 dout("__map_request returned %d\n", err);
2229 continue; /* hrm! */
2230 if (req->r_osd == NULL || err > 0) {
2231 if (req->r_osd == NULL) {
2232 dout("lingering %p tid %llu maps to no osd\n",
2235 * A homeless lingering request makes
2236 * no sense, as it's job is to keep
2237 * a particular OSD connection open.
2238 * Request a newer map and kick the
2239 * request, knowing that it won't be
2240 * resent until we actually get a map
2241 * that can tell us where to send it.
2246 dout("kicking lingering %p tid %llu osd%d\n", req,
2247 req->r_tid, req->r_osd ? req->r_osd->o_osd : -1);
2248 __register_request(osdc, req);
2249 __unregister_linger_request(osdc, req);
2252 reset_changed_osds(osdc);
2253 mutex_unlock(&osdc->request_mutex);
2256 dout("%d requests for down osds, need new map\n", needmap);
2257 ceph_monc_request_next_osdmap(&osdc->client->monc);
2263 * Process updated osd map.
2265 * The message contains any number of incremental and full maps, normally
2266 * indicating some sort of topology change in the cluster. Kick requests
2267 * off to different OSDs as needed.
2269 void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
2271 void *p, *end, *next;
2272 u32 nr_maps, maplen;
2274 struct ceph_osdmap *newmap = NULL, *oldmap;
2276 struct ceph_fsid fsid;
2279 dout("handle_map have %u\n", osdc->osdmap ? osdc->osdmap->epoch : 0);
2280 p = msg->front.iov_base;
2281 end = p + msg->front.iov_len;
2284 ceph_decode_need(&p, end, sizeof(fsid), bad);
2285 ceph_decode_copy(&p, &fsid, sizeof(fsid));
2286 if (ceph_check_fsid(osdc->client, &fsid) < 0)
2289 down_write(&osdc->map_sem);
2291 was_full = ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL);
2293 /* incremental maps */
2294 ceph_decode_32_safe(&p, end, nr_maps, bad);
2295 dout(" %d inc maps\n", nr_maps);
2296 while (nr_maps > 0) {
2297 ceph_decode_need(&p, end, 2*sizeof(u32), bad);
2298 epoch = ceph_decode_32(&p);
2299 maplen = ceph_decode_32(&p);
2300 ceph_decode_need(&p, end, maplen, bad);
2302 if (osdc->osdmap && osdc->osdmap->epoch+1 == epoch) {
2303 dout("applying incremental map %u len %d\n",
2305 newmap = osdmap_apply_incremental(&p, next,
2307 if (IS_ERR(newmap)) {
2308 err = PTR_ERR(newmap);
2312 if (newmap != osdc->osdmap) {
2313 ceph_osdmap_destroy(osdc->osdmap);
2314 osdc->osdmap = newmap;
2316 was_full = was_full ||
2317 ceph_osdmap_flag(osdc->osdmap,
2319 kick_requests(osdc, 0, was_full);
2321 dout("ignoring incremental map %u len %d\n",
2331 ceph_decode_32_safe(&p, end, nr_maps, bad);
2332 dout(" %d full maps\n", nr_maps);
2334 ceph_decode_need(&p, end, 2*sizeof(u32), bad);
2335 epoch = ceph_decode_32(&p);
2336 maplen = ceph_decode_32(&p);
2337 ceph_decode_need(&p, end, maplen, bad);
2339 dout("skipping non-latest full map %u len %d\n",
2341 } else if (osdc->osdmap && osdc->osdmap->epoch >= epoch) {
2342 dout("skipping full map %u len %d, "
2343 "older than our %u\n", epoch, maplen,
2344 osdc->osdmap->epoch);
2346 int skipped_map = 0;
2348 dout("taking full map %u len %d\n", epoch, maplen);
2349 newmap = ceph_osdmap_decode(&p, p+maplen);
2350 if (IS_ERR(newmap)) {
2351 err = PTR_ERR(newmap);
2355 oldmap = osdc->osdmap;
2356 osdc->osdmap = newmap;
2358 if (oldmap->epoch + 1 < newmap->epoch)
2360 ceph_osdmap_destroy(oldmap);
2362 was_full = was_full ||
2363 ceph_osdmap_flag(osdc->osdmap,
2365 kick_requests(osdc, skipped_map, was_full);
2374 downgrade_write(&osdc->map_sem);
2375 ceph_monc_got_map(&osdc->client->monc, CEPH_SUB_OSDMAP,
2376 osdc->osdmap->epoch);
2379 * subscribe to subsequent osdmap updates if full to ensure
2380 * we find out when we are no longer full and stop returning
2383 if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL) ||
2384 ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSERD) ||
2385 ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_PAUSEWR))
2386 ceph_monc_request_next_osdmap(&osdc->client->monc);
2388 mutex_lock(&osdc->request_mutex);
2389 __send_queued(osdc);
2390 mutex_unlock(&osdc->request_mutex);
2391 up_read(&osdc->map_sem);
2392 wake_up_all(&osdc->client->auth_wq);
2396 pr_err("osdc handle_map corrupt msg\n");
2398 up_write(&osdc->map_sem);
2402 * watch/notify callback event infrastructure
2404 * These callbacks are used both for watch and notify operations.
2406 static void __release_event(struct kref *kref)
2408 struct ceph_osd_event *event =
2409 container_of(kref, struct ceph_osd_event, kref);
2411 dout("__release_event %p\n", event);
2415 static void get_event(struct ceph_osd_event *event)
2417 kref_get(&event->kref);
2420 void ceph_osdc_put_event(struct ceph_osd_event *event)
2422 kref_put(&event->kref, __release_event);
2424 EXPORT_SYMBOL(ceph_osdc_put_event);
2426 static void __insert_event(struct ceph_osd_client *osdc,
2427 struct ceph_osd_event *new)
2429 struct rb_node **p = &osdc->event_tree.rb_node;
2430 struct rb_node *parent = NULL;
2431 struct ceph_osd_event *event = NULL;
2435 event = rb_entry(parent, struct ceph_osd_event, node);
2436 if (new->cookie < event->cookie)
2438 else if (new->cookie > event->cookie)
2439 p = &(*p)->rb_right;
2444 rb_link_node(&new->node, parent, p);
2445 rb_insert_color(&new->node, &osdc->event_tree);
2448 static struct ceph_osd_event *__find_event(struct ceph_osd_client *osdc,
2451 struct rb_node **p = &osdc->event_tree.rb_node;
2452 struct rb_node *parent = NULL;
2453 struct ceph_osd_event *event = NULL;
2457 event = rb_entry(parent, struct ceph_osd_event, node);
2458 if (cookie < event->cookie)
2460 else if (cookie > event->cookie)
2461 p = &(*p)->rb_right;
2468 static void __remove_event(struct ceph_osd_event *event)
2470 struct ceph_osd_client *osdc = event->osdc;
2472 if (!RB_EMPTY_NODE(&event->node)) {
2473 dout("__remove_event removed %p\n", event);
2474 rb_erase(&event->node, &osdc->event_tree);
2475 ceph_osdc_put_event(event);
2477 dout("__remove_event didn't remove %p\n", event);
2481 int ceph_osdc_create_event(struct ceph_osd_client *osdc,
2482 void (*event_cb)(u64, u64, u8, void *),
2483 void *data, struct ceph_osd_event **pevent)
2485 struct ceph_osd_event *event;
2487 event = kmalloc(sizeof(*event), GFP_NOIO);
2491 dout("create_event %p\n", event);
2492 event->cb = event_cb;
2493 event->one_shot = 0;
2496 INIT_LIST_HEAD(&event->osd_node);
2497 RB_CLEAR_NODE(&event->node);
2498 kref_init(&event->kref); /* one ref for us */
2499 kref_get(&event->kref); /* one ref for the caller */
2501 spin_lock(&osdc->event_lock);
2502 event->cookie = ++osdc->event_count;
2503 __insert_event(osdc, event);
2504 spin_unlock(&osdc->event_lock);
2509 EXPORT_SYMBOL(ceph_osdc_create_event);
2511 void ceph_osdc_cancel_event(struct ceph_osd_event *event)
2513 struct ceph_osd_client *osdc = event->osdc;
2515 dout("cancel_event %p\n", event);
2516 spin_lock(&osdc->event_lock);
2517 __remove_event(event);
2518 spin_unlock(&osdc->event_lock);
2519 ceph_osdc_put_event(event); /* caller's */
2521 EXPORT_SYMBOL(ceph_osdc_cancel_event);
2524 static void do_event_work(struct work_struct *work)
2526 struct ceph_osd_event_work *event_work =
2527 container_of(work, struct ceph_osd_event_work, work);
2528 struct ceph_osd_event *event = event_work->event;
2529 u64 ver = event_work->ver;
2530 u64 notify_id = event_work->notify_id;
2531 u8 opcode = event_work->opcode;
2533 dout("do_event_work completing %p\n", event);
2534 event->cb(ver, notify_id, opcode, event->data);
2535 dout("do_event_work completed %p\n", event);
2536 ceph_osdc_put_event(event);
2542 * Process osd watch notifications
2544 static void handle_watch_notify(struct ceph_osd_client *osdc,
2545 struct ceph_msg *msg)
2549 u64 cookie, ver, notify_id;
2551 struct ceph_osd_event *event;
2552 struct ceph_osd_event_work *event_work;
2554 p = msg->front.iov_base;
2555 end = p + msg->front.iov_len;
2557 ceph_decode_8_safe(&p, end, proto_ver, bad);
2558 ceph_decode_8_safe(&p, end, opcode, bad);
2559 ceph_decode_64_safe(&p, end, cookie, bad);
2560 ceph_decode_64_safe(&p, end, ver, bad);
2561 ceph_decode_64_safe(&p, end, notify_id, bad);
2563 spin_lock(&osdc->event_lock);
2564 event = __find_event(osdc, cookie);
2566 BUG_ON(event->one_shot);
2569 spin_unlock(&osdc->event_lock);
2570 dout("handle_watch_notify cookie %lld ver %lld event %p\n",
2571 cookie, ver, event);
2573 event_work = kmalloc(sizeof(*event_work), GFP_NOIO);
2575 pr_err("couldn't allocate event_work\n");
2576 ceph_osdc_put_event(event);
2579 INIT_WORK(&event_work->work, do_event_work);
2580 event_work->event = event;
2581 event_work->ver = ver;
2582 event_work->notify_id = notify_id;
2583 event_work->opcode = opcode;
2585 queue_work(osdc->notify_wq, &event_work->work);
2591 pr_err("osdc handle_watch_notify corrupt msg\n");
2595 * Register request, send initial attempt.
2597 int ceph_osdc_start_request(struct ceph_osd_client *osdc,
2598 struct ceph_osd_request *req,
2603 down_read(&osdc->map_sem);
2604 mutex_lock(&osdc->request_mutex);
2606 rc = __ceph_osdc_start_request(osdc, req, nofail);
2608 mutex_unlock(&osdc->request_mutex);
2609 up_read(&osdc->map_sem);
2613 EXPORT_SYMBOL(ceph_osdc_start_request);
2616 * Unregister a registered request. The request is not completed (i.e.
2617 * no callbacks or wakeups) - higher layers are supposed to know what
2618 * they are canceling.
2620 void ceph_osdc_cancel_request(struct ceph_osd_request *req)
2622 struct ceph_osd_client *osdc = req->r_osdc;
2624 mutex_lock(&osdc->request_mutex);
2626 __unregister_linger_request(osdc, req);
2627 __unregister_request(osdc, req);
2628 mutex_unlock(&osdc->request_mutex);
2630 dout("%s %p tid %llu canceled\n", __func__, req, req->r_tid);
2632 EXPORT_SYMBOL(ceph_osdc_cancel_request);
2635 * wait for a request to complete
2637 int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
2638 struct ceph_osd_request *req)
2642 dout("%s %p tid %llu\n", __func__, req, req->r_tid);
2644 rc = wait_for_completion_interruptible(&req->r_completion);
2646 dout("%s %p tid %llu interrupted\n", __func__, req, req->r_tid);
2647 ceph_osdc_cancel_request(req);
2649 /* kludge - need to to wake ceph_osdc_sync() */
2650 complete_all(&req->r_safe_completion);
2654 dout("%s %p tid %llu result %d\n", __func__, req, req->r_tid,
2656 return req->r_result;
2658 EXPORT_SYMBOL(ceph_osdc_wait_request);
2661 * sync - wait for all in-flight requests to flush. avoid starvation.
2663 void ceph_osdc_sync(struct ceph_osd_client *osdc)
2665 struct ceph_osd_request *req;
2666 u64 last_tid, next_tid = 0;
2668 mutex_lock(&osdc->request_mutex);
2669 last_tid = osdc->last_tid;
2671 req = __lookup_request_ge(osdc, next_tid);
2674 if (req->r_tid > last_tid)
2677 next_tid = req->r_tid + 1;
2678 if ((req->r_flags & CEPH_OSD_FLAG_WRITE) == 0)
2681 ceph_osdc_get_request(req);
2682 mutex_unlock(&osdc->request_mutex);
2683 dout("sync waiting on tid %llu (last is %llu)\n",
2684 req->r_tid, last_tid);
2685 wait_for_completion(&req->r_safe_completion);
2686 mutex_lock(&osdc->request_mutex);
2687 ceph_osdc_put_request(req);
2689 mutex_unlock(&osdc->request_mutex);
2690 dout("sync done (thru tid %llu)\n", last_tid);
2692 EXPORT_SYMBOL(ceph_osdc_sync);
2695 * Call all pending notify callbacks - for use after a watch is
2696 * unregistered, to make sure no more callbacks for it will be invoked
2698 void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc)
2700 flush_workqueue(osdc->notify_wq);
2702 EXPORT_SYMBOL(ceph_osdc_flush_notifies);
2708 int ceph_osdc_init(struct ceph_osd_client *osdc, struct ceph_client *client)
2713 osdc->client = client;
2714 osdc->osdmap = NULL;
2715 init_rwsem(&osdc->map_sem);
2716 mutex_init(&osdc->request_mutex);
2718 osdc->osds = RB_ROOT;
2719 INIT_LIST_HEAD(&osdc->osd_lru);
2720 osdc->requests = RB_ROOT;
2721 INIT_LIST_HEAD(&osdc->req_lru);
2722 INIT_LIST_HEAD(&osdc->req_unsent);
2723 INIT_LIST_HEAD(&osdc->req_notarget);
2724 INIT_LIST_HEAD(&osdc->req_linger);
2725 osdc->num_requests = 0;
2726 INIT_DELAYED_WORK(&osdc->timeout_work, handle_timeout);
2727 INIT_DELAYED_WORK(&osdc->osds_timeout_work, handle_osds_timeout);
2728 spin_lock_init(&osdc->event_lock);
2729 osdc->event_tree = RB_ROOT;
2730 osdc->event_count = 0;
2732 schedule_delayed_work(&osdc->osds_timeout_work,
2733 round_jiffies_relative(osdc->client->options->osd_idle_ttl));
2736 osdc->req_mempool = mempool_create_slab_pool(10,
2737 ceph_osd_request_cache);
2738 if (!osdc->req_mempool)
2741 err = ceph_msgpool_init(&osdc->msgpool_op, CEPH_MSG_OSD_OP,
2742 PAGE_SIZE, 10, true, "osd_op");
2745 err = ceph_msgpool_init(&osdc->msgpool_op_reply, CEPH_MSG_OSD_OPREPLY,
2746 PAGE_SIZE, 10, true, "osd_op_reply");
2751 osdc->notify_wq = create_singlethread_workqueue("ceph-watch-notify");
2752 if (!osdc->notify_wq)
2753 goto out_msgpool_reply;
2758 ceph_msgpool_destroy(&osdc->msgpool_op_reply);
2760 ceph_msgpool_destroy(&osdc->msgpool_op);
2762 mempool_destroy(osdc->req_mempool);
2767 void ceph_osdc_stop(struct ceph_osd_client *osdc)
2769 flush_workqueue(osdc->notify_wq);
2770 destroy_workqueue(osdc->notify_wq);
2771 cancel_delayed_work_sync(&osdc->timeout_work);
2772 cancel_delayed_work_sync(&osdc->osds_timeout_work);
2774 mutex_lock(&osdc->request_mutex);
2775 while (!RB_EMPTY_ROOT(&osdc->osds)) {
2776 struct ceph_osd *osd = rb_entry(rb_first(&osdc->osds),
2777 struct ceph_osd, o_node);
2778 remove_osd(osdc, osd);
2780 mutex_unlock(&osdc->request_mutex);
2783 ceph_osdmap_destroy(osdc->osdmap);
2784 osdc->osdmap = NULL;
2786 mempool_destroy(osdc->req_mempool);
2787 ceph_msgpool_destroy(&osdc->msgpool_op);
2788 ceph_msgpool_destroy(&osdc->msgpool_op_reply);
2792 * Read some contiguous pages. If we cross a stripe boundary, shorten
2793 * *plen. Return number of bytes read, or error.
2795 int ceph_osdc_readpages(struct ceph_osd_client *osdc,
2796 struct ceph_vino vino, struct ceph_file_layout *layout,
2798 u32 truncate_seq, u64 truncate_size,
2799 struct page **pages, int num_pages, int page_align)
2801 struct ceph_osd_request *req;
2804 dout("readpages on ino %llx.%llx on %llu~%llu\n", vino.ino,
2805 vino.snap, off, *plen);
2806 req = ceph_osdc_new_request(osdc, layout, vino, off, plen, 0, 1,
2807 CEPH_OSD_OP_READ, CEPH_OSD_FLAG_READ,
2808 NULL, truncate_seq, truncate_size,
2811 return PTR_ERR(req);
2813 /* it may be a short read due to an object boundary */
2814 osd_req_op_extent_osd_data_pages(req, 0,
2815 pages, *plen, page_align, false, false);
2817 dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n",
2818 off, *plen, *plen, page_align);
2820 rc = ceph_osdc_start_request(osdc, req, false);
2822 rc = ceph_osdc_wait_request(osdc, req);
2824 ceph_osdc_put_request(req);
2825 dout("readpages result %d\n", rc);
2828 EXPORT_SYMBOL(ceph_osdc_readpages);
2831 * do a synchronous write on N pages
2833 int ceph_osdc_writepages(struct ceph_osd_client *osdc, struct ceph_vino vino,
2834 struct ceph_file_layout *layout,
2835 struct ceph_snap_context *snapc,
2837 u32 truncate_seq, u64 truncate_size,
2838 struct timespec *mtime,
2839 struct page **pages, int num_pages)
2841 struct ceph_osd_request *req;
2843 int page_align = off & ~PAGE_MASK;
2845 req = ceph_osdc_new_request(osdc, layout, vino, off, &len, 0, 1,
2847 CEPH_OSD_FLAG_ONDISK | CEPH_OSD_FLAG_WRITE,
2848 snapc, truncate_seq, truncate_size,
2851 return PTR_ERR(req);
2853 /* it may be a short write due to an object boundary */
2854 osd_req_op_extent_osd_data_pages(req, 0, pages, len, page_align,
2856 dout("writepages %llu~%llu (%llu bytes)\n", off, len, len);
2858 req->r_mtime = *mtime;
2859 rc = ceph_osdc_start_request(osdc, req, true);
2861 rc = ceph_osdc_wait_request(osdc, req);
2863 ceph_osdc_put_request(req);
2866 dout("writepages result %d\n", rc);
2869 EXPORT_SYMBOL(ceph_osdc_writepages);
2871 int ceph_osdc_setup(void)
2873 size_t size = sizeof(struct ceph_osd_request) +
2874 CEPH_OSD_SLAB_OPS * sizeof(struct ceph_osd_req_op);
2876 BUG_ON(ceph_osd_request_cache);
2877 ceph_osd_request_cache = kmem_cache_create("ceph_osd_request", size,
2880 return ceph_osd_request_cache ? 0 : -ENOMEM;
2882 EXPORT_SYMBOL(ceph_osdc_setup);
2884 void ceph_osdc_cleanup(void)
2886 BUG_ON(!ceph_osd_request_cache);
2887 kmem_cache_destroy(ceph_osd_request_cache);
2888 ceph_osd_request_cache = NULL;
2890 EXPORT_SYMBOL(ceph_osdc_cleanup);
2893 * handle incoming message
2895 static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
2897 struct ceph_osd *osd = con->private;
2898 struct ceph_osd_client *osdc;
2899 int type = le16_to_cpu(msg->hdr.type);
2906 case CEPH_MSG_OSD_MAP:
2907 ceph_osdc_handle_map(osdc, msg);
2909 case CEPH_MSG_OSD_OPREPLY:
2910 handle_reply(osdc, msg);
2912 case CEPH_MSG_WATCH_NOTIFY:
2913 handle_watch_notify(osdc, msg);
2917 pr_err("received unknown message type %d %s\n", type,
2918 ceph_msg_type_name(type));
2925 * Lookup and return message for incoming reply. Don't try to do
2926 * anything about a larger than preallocated data portion of the
2927 * message at the moment - for now, just skip the message.
2929 static struct ceph_msg *get_reply(struct ceph_connection *con,
2930 struct ceph_msg_header *hdr,
2933 struct ceph_osd *osd = con->private;
2934 struct ceph_osd_client *osdc = osd->o_osdc;
2936 struct ceph_osd_request *req;
2937 int front_len = le32_to_cpu(hdr->front_len);
2938 int data_len = le32_to_cpu(hdr->data_len);
2941 tid = le64_to_cpu(hdr->tid);
2942 mutex_lock(&osdc->request_mutex);
2943 req = lookup_request(&osdc->requests, tid);
2945 dout("%s osd%d tid %llu unknown, skipping\n", __func__,
2952 ceph_msg_revoke_incoming(req->r_reply);
2954 if (front_len > req->r_reply->front_alloc_len) {
2955 pr_warn("%s osd%d tid %llu front %d > preallocated %d\n",
2956 __func__, osd->o_osd, req->r_tid, front_len,
2957 req->r_reply->front_alloc_len);
2958 m = ceph_msg_new(CEPH_MSG_OSD_OPREPLY, front_len, GFP_NOFS,
2962 ceph_msg_put(req->r_reply);
2966 if (data_len > req->r_reply->data_length) {
2967 pr_warn("%s osd%d tid %llu data %d > preallocated %zu, skipping\n",
2968 __func__, osd->o_osd, req->r_tid, data_len,
2969 req->r_reply->data_length);
2975 m = ceph_msg_get(req->r_reply);
2976 dout("get_reply tid %lld %p\n", tid, m);
2979 mutex_unlock(&osdc->request_mutex);
2983 static struct ceph_msg *alloc_msg(struct ceph_connection *con,
2984 struct ceph_msg_header *hdr,
2987 struct ceph_osd *osd = con->private;
2988 int type = le16_to_cpu(hdr->type);
2989 int front = le32_to_cpu(hdr->front_len);
2993 case CEPH_MSG_OSD_MAP:
2994 case CEPH_MSG_WATCH_NOTIFY:
2995 return ceph_msg_new(type, front, GFP_NOFS, false);
2996 case CEPH_MSG_OSD_OPREPLY:
2997 return get_reply(con, hdr, skip);
2999 pr_info("alloc_msg unexpected msg type %d from osd%d\n", type,
3007 * Wrappers to refcount containing ceph_osd struct
3009 static struct ceph_connection *get_osd_con(struct ceph_connection *con)
3011 struct ceph_osd *osd = con->private;
3017 static void put_osd_con(struct ceph_connection *con)
3019 struct ceph_osd *osd = con->private;
3027 * Note: returned pointer is the address of a structure that's
3028 * managed separately. Caller must *not* attempt to free it.
3030 static struct ceph_auth_handshake *get_authorizer(struct ceph_connection *con,
3031 int *proto, int force_new)
3033 struct ceph_osd *o = con->private;
3034 struct ceph_osd_client *osdc = o->o_osdc;
3035 struct ceph_auth_client *ac = osdc->client->monc.auth;
3036 struct ceph_auth_handshake *auth = &o->o_auth;
3038 if (force_new && auth->authorizer) {
3039 ceph_auth_destroy_authorizer(auth->authorizer);
3040 auth->authorizer = NULL;
3042 if (!auth->authorizer) {
3043 int ret = ceph_auth_create_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
3046 return ERR_PTR(ret);
3048 int ret = ceph_auth_update_authorizer(ac, CEPH_ENTITY_TYPE_OSD,
3051 return ERR_PTR(ret);
3053 *proto = ac->protocol;
3059 static int verify_authorizer_reply(struct ceph_connection *con, int len)
3061 struct ceph_osd *o = con->private;
3062 struct ceph_osd_client *osdc = o->o_osdc;
3063 struct ceph_auth_client *ac = osdc->client->monc.auth;
3065 return ceph_auth_verify_authorizer_reply(ac, o->o_auth.authorizer, len);
3068 static int invalidate_authorizer(struct ceph_connection *con)
3070 struct ceph_osd *o = con->private;
3071 struct ceph_osd_client *osdc = o->o_osdc;
3072 struct ceph_auth_client *ac = osdc->client->monc.auth;
3074 ceph_auth_invalidate_authorizer(ac, CEPH_ENTITY_TYPE_OSD);
3075 return ceph_monc_validate_auth(&osdc->client->monc);
3078 static int osd_sign_message(struct ceph_msg *msg)
3080 struct ceph_osd *o = msg->con->private;
3081 struct ceph_auth_handshake *auth = &o->o_auth;
3083 return ceph_auth_sign_message(auth, msg);
3086 static int osd_check_message_signature(struct ceph_msg *msg)
3088 struct ceph_osd *o = msg->con->private;
3089 struct ceph_auth_handshake *auth = &o->o_auth;
3091 return ceph_auth_check_message_signature(auth, msg);
3094 static const struct ceph_connection_operations osd_con_ops = {
3097 .dispatch = dispatch,
3098 .get_authorizer = get_authorizer,
3099 .verify_authorizer_reply = verify_authorizer_reply,
3100 .invalidate_authorizer = invalidate_authorizer,
3101 .alloc_msg = alloc_msg,
3102 .sign_message = osd_sign_message,
3103 .check_message_signature = osd_check_message_signature,