1 #include "ceph_debug.h"
4 #include <linux/highmem.h>
6 #include <linux/pagemap.h>
7 #include <linux/slab.h>
8 #include <linux/uaccess.h>
10 #include <linux/bio.h>
14 #include "osd_client.h"
15 #include "messenger.h"
20 #define OSD_OP_FRONT_LEN 4096
21 #define OSD_OPREPLY_FRONT_LEN 512
23 static const struct ceph_connection_operations osd_con_ops
;
24 static int __kick_requests(struct ceph_osd_client
*osdc
,
25 struct ceph_osd
*kickosd
);
27 static void kick_requests(struct ceph_osd_client
*osdc
, struct ceph_osd
*osd
);
29 static int op_needs_trail(int op
)
32 case CEPH_OSD_OP_GETXATTR
:
33 case CEPH_OSD_OP_SETXATTR
:
34 case CEPH_OSD_OP_CMPXATTR
:
35 case CEPH_OSD_OP_CALL
:
42 static int op_has_extent(int op
)
44 return (op
== CEPH_OSD_OP_READ
||
45 op
== CEPH_OSD_OP_WRITE
);
48 void ceph_calc_raw_layout(struct ceph_osd_client
*osdc
,
49 struct ceph_file_layout
*layout
,
51 u64 off
, u64
*plen
, u64
*bno
,
52 struct ceph_osd_request
*req
,
53 struct ceph_osd_req_op
*op
)
55 struct ceph_osd_request_head
*reqhead
= req
->r_request
->front
.iov_base
;
57 u64 objoff
, objlen
; /* extent in object */
59 reqhead
->snapid
= cpu_to_le64(snapid
);
62 ceph_calc_file_object_mapping(layout
, off
, plen
, bno
,
65 dout(" skipping last %llu, final file extent %llu~%llu\n",
66 orig_len
- *plen
, off
, *plen
);
68 if (op_has_extent(op
->op
)) {
69 op
->extent
.offset
= objoff
;
70 op
->extent
.length
= objlen
;
72 req
->r_num_pages
= calc_pages_for(off
, *plen
);
74 dout("calc_layout bno=%llx %llu~%llu (%d pages)\n",
75 *bno
, objoff
, objlen
, req
->r_num_pages
);
80 * Implement client access to distributed object storage cluster.
82 * All data objects are stored within a cluster/cloud of OSDs, or
83 * "object storage devices." (Note that Ceph OSDs have _nothing_ to
84 * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply
85 * remote daemons serving up and coordinating consistent and safe
88 * Cluster membership and the mapping of data objects onto storage devices
89 * are described by the osd map.
91 * We keep track of pending OSD requests (read, write), resubmit
92 * requests to different OSDs when the cluster topology/data layout
93 * change, or retry the affected requests when the communications
94 * channel with an OSD is reset.
98 * calculate the mapping of a file extent onto an object, and fill out the
99 * request accordingly. shorten extent as necessary if it crosses an
102 * fill osd op in request message.
104 static void calc_layout(struct ceph_osd_client
*osdc
,
105 struct ceph_vino vino
,
106 struct ceph_file_layout
*layout
,
108 struct ceph_osd_request
*req
,
109 struct ceph_osd_req_op
*op
)
113 ceph_calc_raw_layout(osdc
, layout
, vino
.snap
, off
,
114 plen
, &bno
, req
, op
);
116 sprintf(req
->r_oid
, "%llx.%08llx", vino
.ino
, bno
);
117 req
->r_oid_len
= strlen(req
->r_oid
);
123 void ceph_osdc_release_request(struct kref
*kref
)
125 struct ceph_osd_request
*req
= container_of(kref
,
126 struct ceph_osd_request
,
130 ceph_msg_put(req
->r_request
);
132 ceph_msg_put(req
->r_reply
);
133 if (req
->r_con_filling_msg
) {
134 dout("release_request revoking pages %p from con %p\n",
135 req
->r_pages
, req
->r_con_filling_msg
);
136 ceph_con_revoke_message(req
->r_con_filling_msg
,
138 ceph_con_put(req
->r_con_filling_msg
);
140 if (req
->r_own_pages
)
141 ceph_release_page_vector(req
->r_pages
,
147 ceph_put_snap_context(req
->r_snapc
);
149 ceph_pagelist_release(req
->r_trail
);
153 mempool_free(req
, req
->r_osdc
->req_mempool
);
158 static int op_needs_trail(int op
)
161 case CEPH_OSD_OP_GETXATTR
:
162 case CEPH_OSD_OP_SETXATTR
:
163 case CEPH_OSD_OP_CMPXATTR
:
164 case CEPH_OSD_OP_CALL
:
171 static int get_num_ops(struct ceph_osd_req_op
*ops
, int *needs_trail
)
178 if (needs_trail
&& op_needs_trail(ops
[i
].op
))
186 struct ceph_osd_request
*ceph_osdc_alloc_request(struct ceph_osd_client
*osdc
,
188 struct ceph_snap_context
*snapc
,
189 struct ceph_osd_req_op
*ops
,
195 struct ceph_osd_request
*req
;
196 struct ceph_msg
*msg
;
198 int num_op
= get_num_ops(ops
, &needs_trail
);
199 size_t msg_size
= sizeof(struct ceph_osd_request_head
);
201 msg_size
+= num_op
*sizeof(struct ceph_osd_op
);
204 req
= mempool_alloc(osdc
->req_mempool
, gfp_flags
);
205 memset(req
, 0, sizeof(*req
));
207 req
= kzalloc(sizeof(*req
), gfp_flags
);
213 req
->r_mempool
= use_mempool
;
215 kref_init(&req
->r_kref
);
216 init_completion(&req
->r_completion
);
217 init_completion(&req
->r_safe_completion
);
218 INIT_LIST_HEAD(&req
->r_unsafe_item
);
219 req
->r_flags
= flags
;
221 WARN_ON((flags
& (CEPH_OSD_FLAG_READ
|CEPH_OSD_FLAG_WRITE
)) == 0);
223 /* create reply message */
225 msg
= ceph_msgpool_get(&osdc
->msgpool_op_reply
, 0);
227 msg
= ceph_msg_new(CEPH_MSG_OSD_OPREPLY
,
228 OSD_OPREPLY_FRONT_LEN
, gfp_flags
);
230 ceph_osdc_put_request(req
);
235 /* allocate space for the trailing data */
237 req
->r_trail
= kmalloc(sizeof(struct ceph_pagelist
), gfp_flags
);
239 ceph_osdc_put_request(req
);
242 ceph_pagelist_init(req
->r_trail
);
244 /* create request message; allow space for oid */
247 msg_size
+= sizeof(u64
) * snapc
->num_snaps
;
249 msg
= ceph_msgpool_get(&osdc
->msgpool_op
, 0);
251 msg
= ceph_msg_new(CEPH_MSG_OSD_OP
, msg_size
, gfp_flags
);
253 ceph_osdc_put_request(req
);
257 msg
->hdr
.type
= cpu_to_le16(CEPH_MSG_OSD_OP
);
258 memset(msg
->front
.iov_base
, 0, msg
->front
.iov_len
);
260 req
->r_request
= msg
;
261 req
->r_pages
= pages
;
272 static void osd_req_encode_op(struct ceph_osd_request
*req
,
273 struct ceph_osd_op
*dst
,
274 struct ceph_osd_req_op
*src
)
276 dst
->op
= cpu_to_le16(src
->op
);
279 case CEPH_OSD_OP_READ
:
280 case CEPH_OSD_OP_WRITE
:
282 cpu_to_le64(src
->extent
.offset
);
284 cpu_to_le64(src
->extent
.length
);
285 dst
->extent
.truncate_size
=
286 cpu_to_le64(src
->extent
.truncate_size
);
287 dst
->extent
.truncate_seq
=
288 cpu_to_le32(src
->extent
.truncate_seq
);
291 case CEPH_OSD_OP_GETXATTR
:
292 case CEPH_OSD_OP_SETXATTR
:
293 case CEPH_OSD_OP_CMPXATTR
:
294 BUG_ON(!req
->r_trail
);
296 dst
->xattr
.name_len
= cpu_to_le32(src
->xattr
.name_len
);
297 dst
->xattr
.value_len
= cpu_to_le32(src
->xattr
.value_len
);
298 dst
->xattr
.cmp_op
= src
->xattr
.cmp_op
;
299 dst
->xattr
.cmp_mode
= src
->xattr
.cmp_mode
;
300 ceph_pagelist_append(req
->r_trail
, src
->xattr
.name
,
301 src
->xattr
.name_len
);
302 ceph_pagelist_append(req
->r_trail
, src
->xattr
.val
,
303 src
->xattr
.value_len
);
305 case CEPH_OSD_OP_CALL
:
306 BUG_ON(!req
->r_trail
);
308 dst
->cls
.class_len
= src
->cls
.class_len
;
309 dst
->cls
.method_len
= src
->cls
.method_len
;
310 dst
->cls
.indata_len
= cpu_to_le32(src
->cls
.indata_len
);
312 ceph_pagelist_append(req
->r_trail
, src
->cls
.class_name
,
314 ceph_pagelist_append(req
->r_trail
, src
->cls
.method_name
,
315 src
->cls
.method_len
);
316 ceph_pagelist_append(req
->r_trail
, src
->cls
.indata
,
317 src
->cls
.indata_len
);
319 case CEPH_OSD_OP_ROLLBACK
:
320 dst
->snap
.snapid
= cpu_to_le64(src
->snap
.snapid
);
322 case CEPH_OSD_OP_STARTSYNC
:
325 pr_err("unrecognized osd opcode %d\n", dst
->op
);
329 dst
->payload_len
= cpu_to_le32(src
->payload_len
);
333 * build new request AND message
336 void ceph_osdc_build_request(struct ceph_osd_request
*req
,
338 struct ceph_osd_req_op
*src_ops
,
339 struct ceph_snap_context
*snapc
,
340 struct timespec
*mtime
,
344 struct ceph_msg
*msg
= req
->r_request
;
345 struct ceph_osd_request_head
*head
;
346 struct ceph_osd_req_op
*src_op
;
347 struct ceph_osd_op
*op
;
349 int num_op
= get_num_ops(src_ops
, NULL
);
350 size_t msg_size
= sizeof(*head
) + num_op
*sizeof(*op
);
351 int flags
= req
->r_flags
;
355 head
= msg
->front
.iov_base
;
356 op
= (void *)(head
+ 1);
357 p
= (void *)(op
+ num_op
);
359 req
->r_snapc
= ceph_get_snap_context(snapc
);
361 head
->client_inc
= cpu_to_le32(1); /* always, for now. */
362 head
->flags
= cpu_to_le32(flags
);
363 if (flags
& CEPH_OSD_FLAG_WRITE
)
364 ceph_encode_timespec(&head
->mtime
, mtime
);
365 head
->num_ops
= cpu_to_le16(num_op
);
369 head
->object_len
= cpu_to_le32(oid_len
);
370 memcpy(p
, oid
, oid_len
);
375 osd_req_encode_op(req
, op
, src_op
);
381 data_len
+= req
->r_trail
->length
;
384 head
->snap_seq
= cpu_to_le64(snapc
->seq
);
385 head
->num_snaps
= cpu_to_le32(snapc
->num_snaps
);
386 for (i
= 0; i
< snapc
->num_snaps
; i
++) {
387 put_unaligned_le64(snapc
->snaps
[i
], p
);
392 if (flags
& CEPH_OSD_FLAG_WRITE
) {
393 req
->r_request
->hdr
.data_off
= cpu_to_le16(off
);
394 req
->r_request
->hdr
.data_len
= cpu_to_le32(*plen
+ data_len
);
395 } else if (data_len
) {
396 req
->r_request
->hdr
.data_off
= 0;
397 req
->r_request
->hdr
.data_len
= cpu_to_le32(data_len
);
400 BUG_ON(p
> msg
->front
.iov_base
+ msg
->front
.iov_len
);
401 msg_size
= p
- msg
->front
.iov_base
;
402 msg
->front
.iov_len
= msg_size
;
403 msg
->hdr
.front_len
= cpu_to_le32(msg_size
);
408 * build new request AND message, calculate layout, and adjust file
411 * if the file was recently truncated, we include information about its
412 * old and new size so that the object can be updated appropriately. (we
413 * avoid synchronously deleting truncated objects because it's slow.)
415 * if @do_sync, include a 'startsync' command so that the osd will flush
418 struct ceph_osd_request
*ceph_osdc_new_request(struct ceph_osd_client
*osdc
,
419 struct ceph_file_layout
*layout
,
420 struct ceph_vino vino
,
422 int opcode
, int flags
,
423 struct ceph_snap_context
*snapc
,
427 struct timespec
*mtime
,
428 bool use_mempool
, int num_reply
)
430 struct ceph_osd_req_op ops
[3];
431 struct ceph_osd_request
*req
;
434 ops
[0].extent
.truncate_seq
= truncate_seq
;
435 ops
[0].extent
.truncate_size
= truncate_size
;
436 ops
[0].payload_len
= 0;
439 ops
[1].op
= CEPH_OSD_OP_STARTSYNC
;
440 ops
[1].payload_len
= 0;
445 req
= ceph_osdc_alloc_request(osdc
, flags
,
448 GFP_NOFS
, NULL
, NULL
);
452 /* calculate max write size */
453 calc_layout(osdc
, vino
, layout
, off
, plen
, req
, ops
);
454 req
->r_file_layout
= *layout
; /* keep a copy */
456 ceph_osdc_build_request(req
, off
, plen
, ops
,
459 req
->r_oid
, req
->r_oid_len
);
465 * We keep osd requests in an rbtree, sorted by ->r_tid.
467 static void __insert_request(struct ceph_osd_client
*osdc
,
468 struct ceph_osd_request
*new)
470 struct rb_node
**p
= &osdc
->requests
.rb_node
;
471 struct rb_node
*parent
= NULL
;
472 struct ceph_osd_request
*req
= NULL
;
476 req
= rb_entry(parent
, struct ceph_osd_request
, r_node
);
477 if (new->r_tid
< req
->r_tid
)
479 else if (new->r_tid
> req
->r_tid
)
485 rb_link_node(&new->r_node
, parent
, p
);
486 rb_insert_color(&new->r_node
, &osdc
->requests
);
489 static struct ceph_osd_request
*__lookup_request(struct ceph_osd_client
*osdc
,
492 struct ceph_osd_request
*req
;
493 struct rb_node
*n
= osdc
->requests
.rb_node
;
496 req
= rb_entry(n
, struct ceph_osd_request
, r_node
);
497 if (tid
< req
->r_tid
)
499 else if (tid
> req
->r_tid
)
507 static struct ceph_osd_request
*
508 __lookup_request_ge(struct ceph_osd_client
*osdc
,
511 struct ceph_osd_request
*req
;
512 struct rb_node
*n
= osdc
->requests
.rb_node
;
515 req
= rb_entry(n
, struct ceph_osd_request
, r_node
);
516 if (tid
< req
->r_tid
) {
520 } else if (tid
> req
->r_tid
) {
531 * If the osd connection drops, we need to resubmit all requests.
533 static void osd_reset(struct ceph_connection
*con
)
535 struct ceph_osd
*osd
= con
->private;
536 struct ceph_osd_client
*osdc
;
540 dout("osd_reset osd%d\n", osd
->o_osd
);
542 down_read(&osdc
->map_sem
);
543 kick_requests(osdc
, osd
);
544 up_read(&osdc
->map_sem
);
548 * Track open sessions with osds.
550 static struct ceph_osd
*create_osd(struct ceph_osd_client
*osdc
)
552 struct ceph_osd
*osd
;
554 osd
= kzalloc(sizeof(*osd
), GFP_NOFS
);
558 atomic_set(&osd
->o_ref
, 1);
560 INIT_LIST_HEAD(&osd
->o_requests
);
561 INIT_LIST_HEAD(&osd
->o_osd_lru
);
562 osd
->o_incarnation
= 1;
564 ceph_con_init(osdc
->client
->msgr
, &osd
->o_con
);
565 osd
->o_con
.private = osd
;
566 osd
->o_con
.ops
= &osd_con_ops
;
567 osd
->o_con
.peer_name
.type
= CEPH_ENTITY_TYPE_OSD
;
569 INIT_LIST_HEAD(&osd
->o_keepalive_item
);
573 static struct ceph_osd
*get_osd(struct ceph_osd
*osd
)
575 if (atomic_inc_not_zero(&osd
->o_ref
)) {
576 dout("get_osd %p %d -> %d\n", osd
, atomic_read(&osd
->o_ref
)-1,
577 atomic_read(&osd
->o_ref
));
580 dout("get_osd %p FAIL\n", osd
);
585 static void put_osd(struct ceph_osd
*osd
)
587 dout("put_osd %p %d -> %d\n", osd
, atomic_read(&osd
->o_ref
),
588 atomic_read(&osd
->o_ref
) - 1);
589 if (atomic_dec_and_test(&osd
->o_ref
)) {
590 struct ceph_auth_client
*ac
= osd
->o_osdc
->client
->monc
.auth
;
592 if (osd
->o_authorizer
)
593 ac
->ops
->destroy_authorizer(ac
, osd
->o_authorizer
);
599 * remove an osd from our map
601 static void __remove_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*osd
)
603 dout("__remove_osd %p\n", osd
);
604 BUG_ON(!list_empty(&osd
->o_requests
));
605 rb_erase(&osd
->o_node
, &osdc
->osds
);
606 list_del_init(&osd
->o_osd_lru
);
607 ceph_con_close(&osd
->o_con
);
611 static void __move_osd_to_lru(struct ceph_osd_client
*osdc
,
612 struct ceph_osd
*osd
)
614 dout("__move_osd_to_lru %p\n", osd
);
615 BUG_ON(!list_empty(&osd
->o_osd_lru
));
616 list_add_tail(&osd
->o_osd_lru
, &osdc
->osd_lru
);
617 osd
->lru_ttl
= jiffies
+ osdc
->client
->mount_args
->osd_idle_ttl
* HZ
;
620 static void __remove_osd_from_lru(struct ceph_osd
*osd
)
622 dout("__remove_osd_from_lru %p\n", osd
);
623 if (!list_empty(&osd
->o_osd_lru
))
624 list_del_init(&osd
->o_osd_lru
);
627 static void remove_old_osds(struct ceph_osd_client
*osdc
, int remove_all
)
629 struct ceph_osd
*osd
, *nosd
;
631 dout("__remove_old_osds %p\n", osdc
);
632 mutex_lock(&osdc
->request_mutex
);
633 list_for_each_entry_safe(osd
, nosd
, &osdc
->osd_lru
, o_osd_lru
) {
634 if (!remove_all
&& time_before(jiffies
, osd
->lru_ttl
))
636 __remove_osd(osdc
, osd
);
638 mutex_unlock(&osdc
->request_mutex
);
644 static int __reset_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*osd
)
646 struct ceph_osd_request
*req
;
649 dout("__reset_osd %p osd%d\n", osd
, osd
->o_osd
);
650 if (list_empty(&osd
->o_requests
)) {
651 __remove_osd(osdc
, osd
);
652 } else if (memcmp(&osdc
->osdmap
->osd_addr
[osd
->o_osd
],
653 &osd
->o_con
.peer_addr
,
654 sizeof(osd
->o_con
.peer_addr
)) == 0 &&
655 !ceph_con_opened(&osd
->o_con
)) {
656 dout(" osd addr hasn't changed and connection never opened,"
657 " letting msgr retry");
658 /* touch each r_stamp for handle_timeout()'s benfit */
659 list_for_each_entry(req
, &osd
->o_requests
, r_osd_item
)
660 req
->r_stamp
= jiffies
;
663 ceph_con_close(&osd
->o_con
);
664 ceph_con_open(&osd
->o_con
, &osdc
->osdmap
->osd_addr
[osd
->o_osd
]);
665 osd
->o_incarnation
++;
670 static void __insert_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*new)
672 struct rb_node
**p
= &osdc
->osds
.rb_node
;
673 struct rb_node
*parent
= NULL
;
674 struct ceph_osd
*osd
= NULL
;
678 osd
= rb_entry(parent
, struct ceph_osd
, o_node
);
679 if (new->o_osd
< osd
->o_osd
)
681 else if (new->o_osd
> osd
->o_osd
)
687 rb_link_node(&new->o_node
, parent
, p
);
688 rb_insert_color(&new->o_node
, &osdc
->osds
);
691 static struct ceph_osd
*__lookup_osd(struct ceph_osd_client
*osdc
, int o
)
693 struct ceph_osd
*osd
;
694 struct rb_node
*n
= osdc
->osds
.rb_node
;
697 osd
= rb_entry(n
, struct ceph_osd
, o_node
);
700 else if (o
> osd
->o_osd
)
708 static void __schedule_osd_timeout(struct ceph_osd_client
*osdc
)
710 schedule_delayed_work(&osdc
->timeout_work
,
711 osdc
->client
->mount_args
->osd_keepalive_timeout
* HZ
);
714 static void __cancel_osd_timeout(struct ceph_osd_client
*osdc
)
716 cancel_delayed_work(&osdc
->timeout_work
);
720 * Register request, assign tid. If this is the first request, set up
723 static void register_request(struct ceph_osd_client
*osdc
,
724 struct ceph_osd_request
*req
)
726 mutex_lock(&osdc
->request_mutex
);
727 req
->r_tid
= ++osdc
->last_tid
;
728 req
->r_request
->hdr
.tid
= cpu_to_le64(req
->r_tid
);
729 INIT_LIST_HEAD(&req
->r_req_lru_item
);
731 dout("register_request %p tid %lld\n", req
, req
->r_tid
);
732 __insert_request(osdc
, req
);
733 ceph_osdc_get_request(req
);
734 osdc
->num_requests
++;
736 if (osdc
->num_requests
== 1) {
737 dout(" first request, scheduling timeout\n");
738 __schedule_osd_timeout(osdc
);
740 mutex_unlock(&osdc
->request_mutex
);
744 * called under osdc->request_mutex
746 static void __unregister_request(struct ceph_osd_client
*osdc
,
747 struct ceph_osd_request
*req
)
749 dout("__unregister_request %p tid %lld\n", req
, req
->r_tid
);
750 rb_erase(&req
->r_node
, &osdc
->requests
);
751 osdc
->num_requests
--;
754 /* make sure the original request isn't in flight. */
755 ceph_con_revoke(&req
->r_osd
->o_con
, req
->r_request
);
757 list_del_init(&req
->r_osd_item
);
758 if (list_empty(&req
->r_osd
->o_requests
))
759 __move_osd_to_lru(osdc
, req
->r_osd
);
763 ceph_osdc_put_request(req
);
765 list_del_init(&req
->r_req_lru_item
);
766 if (osdc
->num_requests
== 0) {
767 dout(" no requests, canceling timeout\n");
768 __cancel_osd_timeout(osdc
);
773 * Cancel a previously queued request message
775 static void __cancel_request(struct ceph_osd_request
*req
)
777 if (req
->r_sent
&& req
->r_osd
) {
778 ceph_con_revoke(&req
->r_osd
->o_con
, req
->r_request
);
781 list_del_init(&req
->r_req_lru_item
);
785 * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
786 * (as needed), and set the request r_osd appropriately. If there is
787 * no up osd, set r_osd to NULL.
789 * Return 0 if unchanged, 1 if changed, or negative on error.
791 * Caller should hold map_sem for read and request_mutex.
793 static int __map_osds(struct ceph_osd_client
*osdc
,
794 struct ceph_osd_request
*req
)
796 struct ceph_osd_request_head
*reqhead
= req
->r_request
->front
.iov_base
;
798 int acting
[CEPH_PG_MAX_SIZE
];
802 dout("map_osds %p tid %lld\n", req
, req
->r_tid
);
803 err
= ceph_calc_object_layout(&reqhead
->layout
, req
->r_oid
,
804 &req
->r_file_layout
, osdc
->osdmap
);
807 pgid
= reqhead
->layout
.ol_pgid
;
810 err
= ceph_calc_pg_acting(osdc
->osdmap
, pgid
, acting
);
816 if ((req
->r_osd
&& req
->r_osd
->o_osd
== o
&&
817 req
->r_sent
>= req
->r_osd
->o_incarnation
&&
818 req
->r_num_pg_osds
== num
&&
819 memcmp(req
->r_pg_osds
, acting
, sizeof(acting
[0])*num
) == 0) ||
820 (req
->r_osd
== NULL
&& o
== -1))
821 return 0; /* no change */
823 dout("map_osds tid %llu pgid %d.%x osd%d (was osd%d)\n",
824 req
->r_tid
, le32_to_cpu(pgid
.pool
), le16_to_cpu(pgid
.ps
), o
,
825 req
->r_osd
? req
->r_osd
->o_osd
: -1);
827 /* record full pg acting set */
828 memcpy(req
->r_pg_osds
, acting
, sizeof(acting
[0]) * num
);
829 req
->r_num_pg_osds
= num
;
832 __cancel_request(req
);
833 list_del_init(&req
->r_osd_item
);
837 req
->r_osd
= __lookup_osd(osdc
, o
);
838 if (!req
->r_osd
&& o
>= 0) {
840 req
->r_osd
= create_osd(osdc
);
844 dout("map_osds osd %p is osd%d\n", req
->r_osd
, o
);
845 req
->r_osd
->o_osd
= o
;
846 req
->r_osd
->o_con
.peer_name
.num
= cpu_to_le64(o
);
847 __insert_osd(osdc
, req
->r_osd
);
849 ceph_con_open(&req
->r_osd
->o_con
, &osdc
->osdmap
->osd_addr
[o
]);
853 __remove_osd_from_lru(req
->r_osd
);
854 list_add(&req
->r_osd_item
, &req
->r_osd
->o_requests
);
856 err
= 1; /* osd or pg changed */
863 * caller should hold map_sem (for read) and request_mutex
865 static int __send_request(struct ceph_osd_client
*osdc
,
866 struct ceph_osd_request
*req
)
868 struct ceph_osd_request_head
*reqhead
;
871 err
= __map_osds(osdc
, req
);
874 if (req
->r_osd
== NULL
) {
875 dout("send_request %p no up osds in pg\n", req
);
876 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
880 dout("send_request %p tid %llu to osd%d flags %d\n",
881 req
, req
->r_tid
, req
->r_osd
->o_osd
, req
->r_flags
);
883 reqhead
= req
->r_request
->front
.iov_base
;
884 reqhead
->osdmap_epoch
= cpu_to_le32(osdc
->osdmap
->epoch
);
885 reqhead
->flags
|= cpu_to_le32(req
->r_flags
); /* e.g., RETRY */
886 reqhead
->reassert_version
= req
->r_reassert_version
;
888 req
->r_stamp
= jiffies
;
889 list_move_tail(&req
->r_req_lru_item
, &osdc
->req_lru
);
891 ceph_msg_get(req
->r_request
); /* send consumes a ref */
892 ceph_con_send(&req
->r_osd
->o_con
, req
->r_request
);
893 req
->r_sent
= req
->r_osd
->o_incarnation
;
898 * Timeout callback, called every N seconds when 1 or more osd
899 * requests has been active for more than N seconds. When this
900 * happens, we ping all OSDs with requests who have timed out to
901 * ensure any communications channel reset is detected. Reset the
902 * request timeouts another N seconds in the future as we go.
903 * Reschedule the timeout event another N seconds in future (unless
904 * there are no open requests).
906 static void handle_timeout(struct work_struct
*work
)
908 struct ceph_osd_client
*osdc
=
909 container_of(work
, struct ceph_osd_client
, timeout_work
.work
);
910 struct ceph_osd_request
*req
, *last_req
= NULL
;
911 struct ceph_osd
*osd
;
912 unsigned long timeout
= osdc
->client
->mount_args
->osd_timeout
* HZ
;
913 unsigned long keepalive
=
914 osdc
->client
->mount_args
->osd_keepalive_timeout
* HZ
;
915 unsigned long last_stamp
= 0;
917 struct list_head slow_osds
;
920 down_read(&osdc
->map_sem
);
922 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
924 mutex_lock(&osdc
->request_mutex
);
925 for (p
= rb_first(&osdc
->requests
); p
; p
= rb_next(p
)) {
926 req
= rb_entry(p
, struct ceph_osd_request
, r_node
);
931 dout("osdc resending prev failed %lld\n", req
->r_tid
);
932 err
= __send_request(osdc
, req
);
934 dout("osdc failed again on %lld\n", req
->r_tid
);
936 req
->r_resend
= false;
942 * reset osds that appear to be _really_ unresponsive. this
943 * is a failsafe measure.. we really shouldn't be getting to
944 * this point if the system is working properly. the monitors
945 * should mark the osd as failed and we should find out about
946 * it from an updated osd map.
948 while (timeout
&& !list_empty(&osdc
->req_lru
)) {
949 req
= list_entry(osdc
->req_lru
.next
, struct ceph_osd_request
,
952 if (time_before(jiffies
, req
->r_stamp
+ timeout
))
955 BUG_ON(req
== last_req
&& req
->r_stamp
== last_stamp
);
957 last_stamp
= req
->r_stamp
;
961 pr_warning(" tid %llu timed out on osd%d, will reset osd\n",
962 req
->r_tid
, osd
->o_osd
);
963 __kick_requests(osdc
, osd
);
967 * ping osds that are a bit slow. this ensures that if there
968 * is a break in the TCP connection we will notice, and reopen
969 * a connection with that osd (from the fault callback).
971 INIT_LIST_HEAD(&slow_osds
);
972 list_for_each_entry(req
, &osdc
->req_lru
, r_req_lru_item
) {
973 if (time_before(jiffies
, req
->r_stamp
+ keepalive
))
978 dout(" tid %llu is slow, will send keepalive on osd%d\n",
979 req
->r_tid
, osd
->o_osd
);
980 list_move_tail(&osd
->o_keepalive_item
, &slow_osds
);
982 while (!list_empty(&slow_osds
)) {
983 osd
= list_entry(slow_osds
.next
, struct ceph_osd
,
985 list_del_init(&osd
->o_keepalive_item
);
986 ceph_con_keepalive(&osd
->o_con
);
989 __schedule_osd_timeout(osdc
);
990 mutex_unlock(&osdc
->request_mutex
);
992 up_read(&osdc
->map_sem
);
995 static void handle_osds_timeout(struct work_struct
*work
)
997 struct ceph_osd_client
*osdc
=
998 container_of(work
, struct ceph_osd_client
,
999 osds_timeout_work
.work
);
1000 unsigned long delay
=
1001 osdc
->client
->mount_args
->osd_idle_ttl
* HZ
>> 2;
1003 dout("osds timeout\n");
1004 down_read(&osdc
->map_sem
);
1005 remove_old_osds(osdc
, 0);
1006 up_read(&osdc
->map_sem
);
1008 schedule_delayed_work(&osdc
->osds_timeout_work
,
1009 round_jiffies_relative(delay
));
1013 * handle osd op reply. either call the callback if it is specified,
1014 * or do the completion to wake up the waiting thread.
1016 static void handle_reply(struct ceph_osd_client
*osdc
, struct ceph_msg
*msg
,
1017 struct ceph_connection
*con
)
1019 struct ceph_osd_reply_head
*rhead
= msg
->front
.iov_base
;
1020 struct ceph_osd_request
*req
;
1022 int numops
, object_len
, flags
;
1025 tid
= le64_to_cpu(msg
->hdr
.tid
);
1026 if (msg
->front
.iov_len
< sizeof(*rhead
))
1028 numops
= le32_to_cpu(rhead
->num_ops
);
1029 object_len
= le32_to_cpu(rhead
->object_len
);
1030 result
= le32_to_cpu(rhead
->result
);
1031 if (msg
->front
.iov_len
!= sizeof(*rhead
) + object_len
+
1032 numops
* sizeof(struct ceph_osd_op
))
1034 dout("handle_reply %p tid %llu result %d\n", msg
, tid
, (int)result
);
1037 mutex_lock(&osdc
->request_mutex
);
1038 req
= __lookup_request(osdc
, tid
);
1040 dout("handle_reply tid %llu dne\n", tid
);
1041 mutex_unlock(&osdc
->request_mutex
);
1044 ceph_osdc_get_request(req
);
1045 flags
= le32_to_cpu(rhead
->flags
);
1048 * if this connection filled our message, drop our reference now, to
1049 * avoid a (safe but slower) revoke later.
1051 if (req
->r_con_filling_msg
== con
&& req
->r_reply
== msg
) {
1052 dout(" dropping con_filling_msg ref %p\n", con
);
1053 req
->r_con_filling_msg
= NULL
;
1057 if (!req
->r_got_reply
) {
1060 req
->r_result
= le32_to_cpu(rhead
->result
);
1061 bytes
= le32_to_cpu(msg
->hdr
.data_len
);
1062 dout("handle_reply result %d bytes %d\n", req
->r_result
,
1064 if (req
->r_result
== 0)
1065 req
->r_result
= bytes
;
1067 /* in case this is a write and we need to replay, */
1068 req
->r_reassert_version
= rhead
->reassert_version
;
1070 req
->r_got_reply
= 1;
1071 } else if ((flags
& CEPH_OSD_FLAG_ONDISK
) == 0) {
1072 dout("handle_reply tid %llu dup ack\n", tid
);
1073 mutex_unlock(&osdc
->request_mutex
);
1077 dout("handle_reply tid %llu flags %d\n", tid
, flags
);
1079 /* either this is a read, or we got the safe response */
1081 (flags
& CEPH_OSD_FLAG_ONDISK
) ||
1082 ((flags
& CEPH_OSD_FLAG_WRITE
) == 0))
1083 __unregister_request(osdc
, req
);
1085 mutex_unlock(&osdc
->request_mutex
);
1087 if (req
->r_callback
)
1088 req
->r_callback(req
, msg
);
1090 complete_all(&req
->r_completion
);
1092 if (flags
& CEPH_OSD_FLAG_ONDISK
) {
1093 if (req
->r_safe_callback
)
1094 req
->r_safe_callback(req
, msg
);
1095 complete_all(&req
->r_safe_completion
); /* fsync waiter */
1099 ceph_osdc_put_request(req
);
1103 pr_err("corrupt osd_op_reply got %d %d expected %d\n",
1104 (int)msg
->front
.iov_len
, le32_to_cpu(msg
->hdr
.front_len
),
1105 (int)sizeof(*rhead
));
1110 static int __kick_requests(struct ceph_osd_client
*osdc
,
1111 struct ceph_osd
*kickosd
)
1113 struct ceph_osd_request
*req
;
1114 struct rb_node
*p
, *n
;
1118 dout("kick_requests osd%d\n", kickosd
? kickosd
->o_osd
: -1);
1120 err
= __reset_osd(osdc
, kickosd
);
1124 for (p
= rb_first(&osdc
->osds
); p
; p
= n
) {
1125 struct ceph_osd
*osd
=
1126 rb_entry(p
, struct ceph_osd
, o_node
);
1129 if (!ceph_osd_is_up(osdc
->osdmap
, osd
->o_osd
) ||
1130 memcmp(&osd
->o_con
.peer_addr
,
1131 ceph_osd_addr(osdc
->osdmap
,
1133 sizeof(struct ceph_entity_addr
)) != 0)
1134 __reset_osd(osdc
, osd
);
1138 for (p
= rb_first(&osdc
->requests
); p
; p
= rb_next(p
)) {
1139 req
= rb_entry(p
, struct ceph_osd_request
, r_node
);
1141 if (req
->r_resend
) {
1142 dout(" r_resend set on tid %llu\n", req
->r_tid
);
1143 __cancel_request(req
);
1146 if (req
->r_osd
&& kickosd
== req
->r_osd
) {
1147 __cancel_request(req
);
1151 err
= __map_osds(osdc
, req
);
1153 continue; /* no change */
1156 * FIXME: really, we should set the request
1157 * error and fail if this isn't a 'nofail'
1158 * request, but that's a fair bit more
1159 * complicated to do. So retry!
1161 dout(" setting r_resend on %llu\n", req
->r_tid
);
1162 req
->r_resend
= true;
1165 if (req
->r_osd
== NULL
) {
1166 dout("tid %llu maps to no valid osd\n", req
->r_tid
);
1167 needmap
++; /* request a newer map */
1172 dout("kicking %p tid %llu osd%d\n", req
, req
->r_tid
,
1173 req
->r_osd
? req
->r_osd
->o_osd
: -1);
1174 req
->r_flags
|= CEPH_OSD_FLAG_RETRY
;
1175 err
= __send_request(osdc
, req
);
1177 dout(" setting r_resend on %llu\n", req
->r_tid
);
1178 req
->r_resend
= true;
1186 * Resubmit osd requests whose osd or osd address has changed. Request
1187 * a new osd map if osds are down, or we are otherwise unable to determine
1188 * how to direct a request.
1190 * Close connections to down osds.
1192 * If @who is specified, resubmit requests for that specific osd.
1194 * Caller should hold map_sem for read and request_mutex.
1196 static void kick_requests(struct ceph_osd_client
*osdc
,
1197 struct ceph_osd
*kickosd
)
1201 mutex_lock(&osdc
->request_mutex
);
1202 needmap
= __kick_requests(osdc
, kickosd
);
1203 mutex_unlock(&osdc
->request_mutex
);
1206 dout("%d requests for down osds, need new map\n", needmap
);
1207 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
1212 * Process updated osd map.
1214 * The message contains any number of incremental and full maps, normally
1215 * indicating some sort of topology change in the cluster. Kick requests
1216 * off to different OSDs as needed.
1218 void ceph_osdc_handle_map(struct ceph_osd_client
*osdc
, struct ceph_msg
*msg
)
1220 void *p
, *end
, *next
;
1221 u32 nr_maps
, maplen
;
1223 struct ceph_osdmap
*newmap
= NULL
, *oldmap
;
1225 struct ceph_fsid fsid
;
1227 dout("handle_map have %u\n", osdc
->osdmap
? osdc
->osdmap
->epoch
: 0);
1228 p
= msg
->front
.iov_base
;
1229 end
= p
+ msg
->front
.iov_len
;
1232 ceph_decode_need(&p
, end
, sizeof(fsid
), bad
);
1233 ceph_decode_copy(&p
, &fsid
, sizeof(fsid
));
1234 if (ceph_check_fsid(osdc
->client
, &fsid
) < 0)
1237 down_write(&osdc
->map_sem
);
1239 /* incremental maps */
1240 ceph_decode_32_safe(&p
, end
, nr_maps
, bad
);
1241 dout(" %d inc maps\n", nr_maps
);
1242 while (nr_maps
> 0) {
1243 ceph_decode_need(&p
, end
, 2*sizeof(u32
), bad
);
1244 epoch
= ceph_decode_32(&p
);
1245 maplen
= ceph_decode_32(&p
);
1246 ceph_decode_need(&p
, end
, maplen
, bad
);
1248 if (osdc
->osdmap
&& osdc
->osdmap
->epoch
+1 == epoch
) {
1249 dout("applying incremental map %u len %d\n",
1251 newmap
= osdmap_apply_incremental(&p
, next
,
1253 osdc
->client
->msgr
);
1254 if (IS_ERR(newmap
)) {
1255 err
= PTR_ERR(newmap
);
1259 if (newmap
!= osdc
->osdmap
) {
1260 ceph_osdmap_destroy(osdc
->osdmap
);
1261 osdc
->osdmap
= newmap
;
1264 dout("ignoring incremental map %u len %d\n",
1274 ceph_decode_32_safe(&p
, end
, nr_maps
, bad
);
1275 dout(" %d full maps\n", nr_maps
);
1277 ceph_decode_need(&p
, end
, 2*sizeof(u32
), bad
);
1278 epoch
= ceph_decode_32(&p
);
1279 maplen
= ceph_decode_32(&p
);
1280 ceph_decode_need(&p
, end
, maplen
, bad
);
1282 dout("skipping non-latest full map %u len %d\n",
1284 } else if (osdc
->osdmap
&& osdc
->osdmap
->epoch
>= epoch
) {
1285 dout("skipping full map %u len %d, "
1286 "older than our %u\n", epoch
, maplen
,
1287 osdc
->osdmap
->epoch
);
1289 dout("taking full map %u len %d\n", epoch
, maplen
);
1290 newmap
= osdmap_decode(&p
, p
+maplen
);
1291 if (IS_ERR(newmap
)) {
1292 err
= PTR_ERR(newmap
);
1296 oldmap
= osdc
->osdmap
;
1297 osdc
->osdmap
= newmap
;
1299 ceph_osdmap_destroy(oldmap
);
1306 downgrade_write(&osdc
->map_sem
);
1307 ceph_monc_got_osdmap(&osdc
->client
->monc
, osdc
->osdmap
->epoch
);
1309 kick_requests(osdc
, NULL
);
1310 up_read(&osdc
->map_sem
);
1311 wake_up_all(&osdc
->client
->auth_wq
);
1315 pr_err("osdc handle_map corrupt msg\n");
1317 up_write(&osdc
->map_sem
);
1322 * Register request, send initial attempt.
1324 int ceph_osdc_start_request(struct ceph_osd_client
*osdc
,
1325 struct ceph_osd_request
*req
,
1330 req
->r_request
->pages
= req
->r_pages
;
1331 req
->r_request
->nr_pages
= req
->r_num_pages
;
1333 req
->r_request
->bio
= req
->r_bio
;
1335 req
->r_request
->trail
= req
->r_trail
;
1337 register_request(osdc
, req
);
1339 down_read(&osdc
->map_sem
);
1340 mutex_lock(&osdc
->request_mutex
);
1342 * a racing kick_requests() may have sent the message for us
1343 * while we dropped request_mutex above, so only send now if
1344 * the request still han't been touched yet.
1346 if (req
->r_sent
== 0) {
1347 rc
= __send_request(osdc
, req
);
1350 dout("osdc_start_request failed send, "
1351 " marking %lld\n", req
->r_tid
);
1352 req
->r_resend
= true;
1355 __unregister_request(osdc
, req
);
1359 mutex_unlock(&osdc
->request_mutex
);
1360 up_read(&osdc
->map_sem
);
1365 * wait for a request to complete
1367 int ceph_osdc_wait_request(struct ceph_osd_client
*osdc
,
1368 struct ceph_osd_request
*req
)
1372 rc
= wait_for_completion_interruptible(&req
->r_completion
);
1374 mutex_lock(&osdc
->request_mutex
);
1375 __cancel_request(req
);
1376 __unregister_request(osdc
, req
);
1377 mutex_unlock(&osdc
->request_mutex
);
1378 dout("wait_request tid %llu canceled/timed out\n", req
->r_tid
);
1382 dout("wait_request tid %llu result %d\n", req
->r_tid
, req
->r_result
);
1383 return req
->r_result
;
1387 * sync - wait for all in-flight requests to flush. avoid starvation.
1389 void ceph_osdc_sync(struct ceph_osd_client
*osdc
)
1391 struct ceph_osd_request
*req
;
1392 u64 last_tid
, next_tid
= 0;
1394 mutex_lock(&osdc
->request_mutex
);
1395 last_tid
= osdc
->last_tid
;
1397 req
= __lookup_request_ge(osdc
, next_tid
);
1400 if (req
->r_tid
> last_tid
)
1403 next_tid
= req
->r_tid
+ 1;
1404 if ((req
->r_flags
& CEPH_OSD_FLAG_WRITE
) == 0)
1407 ceph_osdc_get_request(req
);
1408 mutex_unlock(&osdc
->request_mutex
);
1409 dout("sync waiting on tid %llu (last is %llu)\n",
1410 req
->r_tid
, last_tid
);
1411 wait_for_completion(&req
->r_safe_completion
);
1412 mutex_lock(&osdc
->request_mutex
);
1413 ceph_osdc_put_request(req
);
1415 mutex_unlock(&osdc
->request_mutex
);
1416 dout("sync done (thru tid %llu)\n", last_tid
);
1422 int ceph_osdc_init(struct ceph_osd_client
*osdc
, struct ceph_client
*client
)
1427 osdc
->client
= client
;
1428 osdc
->osdmap
= NULL
;
1429 init_rwsem(&osdc
->map_sem
);
1430 init_completion(&osdc
->map_waiters
);
1431 osdc
->last_requested_map
= 0;
1432 mutex_init(&osdc
->request_mutex
);
1434 osdc
->osds
= RB_ROOT
;
1435 INIT_LIST_HEAD(&osdc
->osd_lru
);
1436 osdc
->requests
= RB_ROOT
;
1437 INIT_LIST_HEAD(&osdc
->req_lru
);
1438 osdc
->num_requests
= 0;
1439 INIT_DELAYED_WORK(&osdc
->timeout_work
, handle_timeout
);
1440 INIT_DELAYED_WORK(&osdc
->osds_timeout_work
, handle_osds_timeout
);
1442 schedule_delayed_work(&osdc
->osds_timeout_work
,
1443 round_jiffies_relative(osdc
->client
->mount_args
->osd_idle_ttl
* HZ
));
1446 osdc
->req_mempool
= mempool_create_kmalloc_pool(10,
1447 sizeof(struct ceph_osd_request
));
1448 if (!osdc
->req_mempool
)
1451 err
= ceph_msgpool_init(&osdc
->msgpool_op
, OSD_OP_FRONT_LEN
, 10, true,
1455 err
= ceph_msgpool_init(&osdc
->msgpool_op_reply
,
1456 OSD_OPREPLY_FRONT_LEN
, 10, true,
1463 ceph_msgpool_destroy(&osdc
->msgpool_op
);
1465 mempool_destroy(osdc
->req_mempool
);
1470 void ceph_osdc_stop(struct ceph_osd_client
*osdc
)
1472 cancel_delayed_work_sync(&osdc
->timeout_work
);
1473 cancel_delayed_work_sync(&osdc
->osds_timeout_work
);
1475 ceph_osdmap_destroy(osdc
->osdmap
);
1476 osdc
->osdmap
= NULL
;
1478 remove_old_osds(osdc
, 1);
1479 mempool_destroy(osdc
->req_mempool
);
1480 ceph_msgpool_destroy(&osdc
->msgpool_op
);
1481 ceph_msgpool_destroy(&osdc
->msgpool_op_reply
);
1485 * Read some contiguous pages. If we cross a stripe boundary, shorten
1486 * *plen. Return number of bytes read, or error.
1488 int ceph_osdc_readpages(struct ceph_osd_client
*osdc
,
1489 struct ceph_vino vino
, struct ceph_file_layout
*layout
,
1491 u32 truncate_seq
, u64 truncate_size
,
1492 struct page
**pages
, int num_pages
)
1494 struct ceph_osd_request
*req
;
1497 dout("readpages on ino %llx.%llx on %llu~%llu\n", vino
.ino
,
1498 vino
.snap
, off
, *plen
);
1499 req
= ceph_osdc_new_request(osdc
, layout
, vino
, off
, plen
,
1500 CEPH_OSD_OP_READ
, CEPH_OSD_FLAG_READ
,
1501 NULL
, 0, truncate_seq
, truncate_size
, NULL
,
1506 /* it may be a short read due to an object boundary */
1507 req
->r_pages
= pages
;
1509 dout("readpages final extent is %llu~%llu (%d pages)\n",
1510 off
, *plen
, req
->r_num_pages
);
1512 rc
= ceph_osdc_start_request(osdc
, req
, false);
1514 rc
= ceph_osdc_wait_request(osdc
, req
);
1516 ceph_osdc_put_request(req
);
1517 dout("readpages result %d\n", rc
);
1522 * do a synchronous write on N pages
1524 int ceph_osdc_writepages(struct ceph_osd_client
*osdc
, struct ceph_vino vino
,
1525 struct ceph_file_layout
*layout
,
1526 struct ceph_snap_context
*snapc
,
1528 u32 truncate_seq
, u64 truncate_size
,
1529 struct timespec
*mtime
,
1530 struct page
**pages
, int num_pages
,
1531 int flags
, int do_sync
, bool nofail
)
1533 struct ceph_osd_request
*req
;
1536 BUG_ON(vino
.snap
!= CEPH_NOSNAP
);
1537 req
= ceph_osdc_new_request(osdc
, layout
, vino
, off
, &len
,
1539 flags
| CEPH_OSD_FLAG_ONDISK
|
1540 CEPH_OSD_FLAG_WRITE
,
1542 truncate_seq
, truncate_size
, mtime
,
1547 /* it may be a short write due to an object boundary */
1548 req
->r_pages
= pages
;
1549 dout("writepages %llu~%llu (%d pages)\n", off
, len
,
1552 rc
= ceph_osdc_start_request(osdc
, req
, nofail
);
1554 rc
= ceph_osdc_wait_request(osdc
, req
);
1556 ceph_osdc_put_request(req
);
1559 dout("writepages result %d\n", rc
);
1564 * handle incoming message
1566 static void dispatch(struct ceph_connection
*con
, struct ceph_msg
*msg
)
1568 struct ceph_osd
*osd
= con
->private;
1569 struct ceph_osd_client
*osdc
;
1570 int type
= le16_to_cpu(msg
->hdr
.type
);
1577 case CEPH_MSG_OSD_MAP
:
1578 ceph_osdc_handle_map(osdc
, msg
);
1580 case CEPH_MSG_OSD_OPREPLY
:
1581 handle_reply(osdc
, msg
, con
);
1585 pr_err("received unknown message type %d %s\n", type
,
1586 ceph_msg_type_name(type
));
1593 * lookup and return message for incoming reply. set up reply message
1596 static struct ceph_msg
*get_reply(struct ceph_connection
*con
,
1597 struct ceph_msg_header
*hdr
,
1600 struct ceph_osd
*osd
= con
->private;
1601 struct ceph_osd_client
*osdc
= osd
->o_osdc
;
1603 struct ceph_osd_request
*req
;
1604 int front
= le32_to_cpu(hdr
->front_len
);
1605 int data_len
= le32_to_cpu(hdr
->data_len
);
1608 tid
= le64_to_cpu(hdr
->tid
);
1609 mutex_lock(&osdc
->request_mutex
);
1610 req
= __lookup_request(osdc
, tid
);
1614 pr_info("get_reply unknown tid %llu from osd%d\n", tid
,
1619 if (req
->r_con_filling_msg
) {
1620 dout("get_reply revoking msg %p from old con %p\n",
1621 req
->r_reply
, req
->r_con_filling_msg
);
1622 ceph_con_revoke_message(req
->r_con_filling_msg
, req
->r_reply
);
1623 ceph_con_put(req
->r_con_filling_msg
);
1624 req
->r_con_filling_msg
= NULL
;
1627 if (front
> req
->r_reply
->front
.iov_len
) {
1628 pr_warning("get_reply front %d > preallocated %d\n",
1629 front
, (int)req
->r_reply
->front
.iov_len
);
1630 m
= ceph_msg_new(CEPH_MSG_OSD_OPREPLY
, front
, GFP_NOFS
);
1633 ceph_msg_put(req
->r_reply
);
1636 m
= ceph_msg_get(req
->r_reply
);
1639 unsigned data_off
= le16_to_cpu(hdr
->data_off
);
1640 int want
= calc_pages_for(data_off
& ~PAGE_MASK
, data_len
);
1642 if (unlikely(req
->r_num_pages
< want
)) {
1643 pr_warning("tid %lld reply %d > expected %d pages\n",
1644 tid
, want
, m
->nr_pages
);
1650 m
->pages
= req
->r_pages
;
1651 m
->nr_pages
= req
->r_num_pages
;
1653 m
->bio
= req
->r_bio
;
1657 req
->r_con_filling_msg
= ceph_con_get(con
);
1658 dout("get_reply tid %lld %p\n", tid
, m
);
1661 mutex_unlock(&osdc
->request_mutex
);
1666 static struct ceph_msg
*alloc_msg(struct ceph_connection
*con
,
1667 struct ceph_msg_header
*hdr
,
1670 struct ceph_osd
*osd
= con
->private;
1671 int type
= le16_to_cpu(hdr
->type
);
1672 int front
= le32_to_cpu(hdr
->front_len
);
1675 case CEPH_MSG_OSD_MAP
:
1676 return ceph_msg_new(type
, front
, GFP_NOFS
);
1677 case CEPH_MSG_OSD_OPREPLY
:
1678 return get_reply(con
, hdr
, skip
);
1680 pr_info("alloc_msg unexpected msg type %d from osd%d\n", type
,
1688 * Wrappers to refcount containing ceph_osd struct
1690 static struct ceph_connection
*get_osd_con(struct ceph_connection
*con
)
1692 struct ceph_osd
*osd
= con
->private;
1698 static void put_osd_con(struct ceph_connection
*con
)
1700 struct ceph_osd
*osd
= con
->private;
1707 static int get_authorizer(struct ceph_connection
*con
,
1708 void **buf
, int *len
, int *proto
,
1709 void **reply_buf
, int *reply_len
, int force_new
)
1711 struct ceph_osd
*o
= con
->private;
1712 struct ceph_osd_client
*osdc
= o
->o_osdc
;
1713 struct ceph_auth_client
*ac
= osdc
->client
->monc
.auth
;
1716 if (force_new
&& o
->o_authorizer
) {
1717 ac
->ops
->destroy_authorizer(ac
, o
->o_authorizer
);
1718 o
->o_authorizer
= NULL
;
1720 if (o
->o_authorizer
== NULL
) {
1721 ret
= ac
->ops
->create_authorizer(
1722 ac
, CEPH_ENTITY_TYPE_OSD
,
1724 &o
->o_authorizer_buf
,
1725 &o
->o_authorizer_buf_len
,
1726 &o
->o_authorizer_reply_buf
,
1727 &o
->o_authorizer_reply_buf_len
);
1732 *proto
= ac
->protocol
;
1733 *buf
= o
->o_authorizer_buf
;
1734 *len
= o
->o_authorizer_buf_len
;
1735 *reply_buf
= o
->o_authorizer_reply_buf
;
1736 *reply_len
= o
->o_authorizer_reply_buf_len
;
1741 static int verify_authorizer_reply(struct ceph_connection
*con
, int len
)
1743 struct ceph_osd
*o
= con
->private;
1744 struct ceph_osd_client
*osdc
= o
->o_osdc
;
1745 struct ceph_auth_client
*ac
= osdc
->client
->monc
.auth
;
1747 return ac
->ops
->verify_authorizer_reply(ac
, o
->o_authorizer
, len
);
1750 static int invalidate_authorizer(struct ceph_connection
*con
)
1752 struct ceph_osd
*o
= con
->private;
1753 struct ceph_osd_client
*osdc
= o
->o_osdc
;
1754 struct ceph_auth_client
*ac
= osdc
->client
->monc
.auth
;
1756 if (ac
->ops
->invalidate_authorizer
)
1757 ac
->ops
->invalidate_authorizer(ac
, CEPH_ENTITY_TYPE_OSD
);
1759 return ceph_monc_validate_auth(&osdc
->client
->monc
);
1762 static const struct ceph_connection_operations osd_con_ops
= {
1765 .dispatch
= dispatch
,
1766 .get_authorizer
= get_authorizer
,
1767 .verify_authorizer_reply
= verify_authorizer_reply
,
1768 .invalidate_authorizer
= invalidate_authorizer
,
1769 .alloc_msg
= alloc_msg
,