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_OP_FRONT_LEN 4096
23 #define OSD_OPREPLY_FRONT_LEN 512
25 static struct kmem_cache
*ceph_osd_request_cache
;
27 static const struct ceph_connection_operations osd_con_ops
;
29 static void __send_queued(struct ceph_osd_client
*osdc
);
30 static int __reset_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*osd
);
31 static void __register_request(struct ceph_osd_client
*osdc
,
32 struct ceph_osd_request
*req
);
33 static void __unregister_request(struct ceph_osd_client
*osdc
,
34 struct ceph_osd_request
*req
);
35 static void __unregister_linger_request(struct ceph_osd_client
*osdc
,
36 struct ceph_osd_request
*req
);
37 static void __enqueue_request(struct ceph_osd_request
*req
);
38 static void __send_request(struct ceph_osd_client
*osdc
,
39 struct ceph_osd_request
*req
);
42 * Implement client access to distributed object storage cluster.
44 * All data objects are stored within a cluster/cloud of OSDs, or
45 * "object storage devices." (Note that Ceph OSDs have _nothing_ to
46 * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply
47 * remote daemons serving up and coordinating consistent and safe
50 * Cluster membership and the mapping of data objects onto storage devices
51 * are described by the osd map.
53 * We keep track of pending OSD requests (read, write), resubmit
54 * requests to different OSDs when the cluster topology/data layout
55 * change, or retry the affected requests when the communications
56 * channel with an OSD is reset.
60 * calculate the mapping of a file extent onto an object, and fill out the
61 * request accordingly. shorten extent as necessary if it crosses an
64 * fill osd op in request message.
66 static int calc_layout(struct ceph_file_layout
*layout
, u64 off
, u64
*plen
,
67 u64
*objnum
, u64
*objoff
, u64
*objlen
)
73 r
= ceph_calc_file_object_mapping(layout
, off
, orig_len
, objnum
,
77 if (*objlen
< orig_len
) {
79 dout(" skipping last %llu, final file extent %llu~%llu\n",
80 orig_len
- *plen
, off
, *plen
);
83 dout("calc_layout objnum=%llx %llu~%llu\n", *objnum
, *objoff
, *objlen
);
88 static void ceph_osd_data_init(struct ceph_osd_data
*osd_data
)
90 memset(osd_data
, 0, sizeof (*osd_data
));
91 osd_data
->type
= CEPH_OSD_DATA_TYPE_NONE
;
94 static void ceph_osd_data_pages_init(struct ceph_osd_data
*osd_data
,
95 struct page
**pages
, u64 length
, u32 alignment
,
96 bool pages_from_pool
, bool own_pages
)
98 osd_data
->type
= CEPH_OSD_DATA_TYPE_PAGES
;
99 osd_data
->pages
= pages
;
100 osd_data
->length
= length
;
101 osd_data
->alignment
= alignment
;
102 osd_data
->pages_from_pool
= pages_from_pool
;
103 osd_data
->own_pages
= own_pages
;
106 static void ceph_osd_data_pagelist_init(struct ceph_osd_data
*osd_data
,
107 struct ceph_pagelist
*pagelist
)
109 osd_data
->type
= CEPH_OSD_DATA_TYPE_PAGELIST
;
110 osd_data
->pagelist
= pagelist
;
114 static void ceph_osd_data_bio_init(struct ceph_osd_data
*osd_data
,
115 struct bio
*bio
, size_t bio_length
)
117 osd_data
->type
= CEPH_OSD_DATA_TYPE_BIO
;
119 osd_data
->bio_length
= bio_length
;
121 #endif /* CONFIG_BLOCK */
123 #define osd_req_op_data(oreq, whch, typ, fld) \
125 BUG_ON(whch >= (oreq)->r_num_ops); \
126 &(oreq)->r_ops[whch].typ.fld; \
129 static struct ceph_osd_data
*
130 osd_req_op_raw_data_in(struct ceph_osd_request
*osd_req
, unsigned int which
)
132 BUG_ON(which
>= osd_req
->r_num_ops
);
134 return &osd_req
->r_ops
[which
].raw_data_in
;
137 struct ceph_osd_data
*
138 osd_req_op_extent_osd_data(struct ceph_osd_request
*osd_req
,
141 return osd_req_op_data(osd_req
, which
, extent
, osd_data
);
143 EXPORT_SYMBOL(osd_req_op_extent_osd_data
);
145 struct ceph_osd_data
*
146 osd_req_op_cls_response_data(struct ceph_osd_request
*osd_req
,
149 return osd_req_op_data(osd_req
, which
, cls
, response_data
);
151 EXPORT_SYMBOL(osd_req_op_cls_response_data
); /* ??? */
153 void osd_req_op_raw_data_in_pages(struct ceph_osd_request
*osd_req
,
154 unsigned int which
, struct page
**pages
,
155 u64 length
, u32 alignment
,
156 bool pages_from_pool
, bool own_pages
)
158 struct ceph_osd_data
*osd_data
;
160 osd_data
= osd_req_op_raw_data_in(osd_req
, which
);
161 ceph_osd_data_pages_init(osd_data
, pages
, length
, alignment
,
162 pages_from_pool
, own_pages
);
164 EXPORT_SYMBOL(osd_req_op_raw_data_in_pages
);
166 void osd_req_op_extent_osd_data_pages(struct ceph_osd_request
*osd_req
,
167 unsigned int which
, struct page
**pages
,
168 u64 length
, u32 alignment
,
169 bool pages_from_pool
, bool own_pages
)
171 struct ceph_osd_data
*osd_data
;
173 osd_data
= osd_req_op_data(osd_req
, which
, extent
, osd_data
);
174 ceph_osd_data_pages_init(osd_data
, pages
, length
, alignment
,
175 pages_from_pool
, own_pages
);
177 EXPORT_SYMBOL(osd_req_op_extent_osd_data_pages
);
179 void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request
*osd_req
,
180 unsigned int which
, struct ceph_pagelist
*pagelist
)
182 struct ceph_osd_data
*osd_data
;
184 osd_data
= osd_req_op_data(osd_req
, which
, extent
, osd_data
);
185 ceph_osd_data_pagelist_init(osd_data
, pagelist
);
187 EXPORT_SYMBOL(osd_req_op_extent_osd_data_pagelist
);
190 void osd_req_op_extent_osd_data_bio(struct ceph_osd_request
*osd_req
,
191 unsigned int which
, struct bio
*bio
, size_t bio_length
)
193 struct ceph_osd_data
*osd_data
;
195 osd_data
= osd_req_op_data(osd_req
, which
, extent
, osd_data
);
196 ceph_osd_data_bio_init(osd_data
, bio
, bio_length
);
198 EXPORT_SYMBOL(osd_req_op_extent_osd_data_bio
);
199 #endif /* CONFIG_BLOCK */
201 static void osd_req_op_cls_request_info_pagelist(
202 struct ceph_osd_request
*osd_req
,
203 unsigned int which
, struct ceph_pagelist
*pagelist
)
205 struct ceph_osd_data
*osd_data
;
207 osd_data
= osd_req_op_data(osd_req
, which
, cls
, request_info
);
208 ceph_osd_data_pagelist_init(osd_data
, pagelist
);
211 void osd_req_op_cls_request_data_pagelist(
212 struct ceph_osd_request
*osd_req
,
213 unsigned int which
, struct ceph_pagelist
*pagelist
)
215 struct ceph_osd_data
*osd_data
;
217 osd_data
= osd_req_op_data(osd_req
, which
, cls
, request_data
);
218 ceph_osd_data_pagelist_init(osd_data
, pagelist
);
220 EXPORT_SYMBOL(osd_req_op_cls_request_data_pagelist
);
222 void osd_req_op_cls_request_data_pages(struct ceph_osd_request
*osd_req
,
223 unsigned int which
, struct page
**pages
, u64 length
,
224 u32 alignment
, bool pages_from_pool
, bool own_pages
)
226 struct ceph_osd_data
*osd_data
;
228 osd_data
= osd_req_op_data(osd_req
, which
, cls
, request_data
);
229 ceph_osd_data_pages_init(osd_data
, pages
, length
, alignment
,
230 pages_from_pool
, own_pages
);
232 EXPORT_SYMBOL(osd_req_op_cls_request_data_pages
);
234 void osd_req_op_cls_response_data_pages(struct ceph_osd_request
*osd_req
,
235 unsigned int which
, struct page
**pages
, u64 length
,
236 u32 alignment
, bool pages_from_pool
, bool own_pages
)
238 struct ceph_osd_data
*osd_data
;
240 osd_data
= osd_req_op_data(osd_req
, which
, cls
, response_data
);
241 ceph_osd_data_pages_init(osd_data
, pages
, length
, alignment
,
242 pages_from_pool
, own_pages
);
244 EXPORT_SYMBOL(osd_req_op_cls_response_data_pages
);
246 static u64
ceph_osd_data_length(struct ceph_osd_data
*osd_data
)
248 switch (osd_data
->type
) {
249 case CEPH_OSD_DATA_TYPE_NONE
:
251 case CEPH_OSD_DATA_TYPE_PAGES
:
252 return osd_data
->length
;
253 case CEPH_OSD_DATA_TYPE_PAGELIST
:
254 return (u64
)osd_data
->pagelist
->length
;
256 case CEPH_OSD_DATA_TYPE_BIO
:
257 return (u64
)osd_data
->bio_length
;
258 #endif /* CONFIG_BLOCK */
260 WARN(true, "unrecognized data type %d\n", (int)osd_data
->type
);
265 static void ceph_osd_data_release(struct ceph_osd_data
*osd_data
)
267 if (osd_data
->type
== CEPH_OSD_DATA_TYPE_PAGES
&& osd_data
->own_pages
) {
270 num_pages
= calc_pages_for((u64
)osd_data
->alignment
,
271 (u64
)osd_data
->length
);
272 ceph_release_page_vector(osd_data
->pages
, num_pages
);
274 ceph_osd_data_init(osd_data
);
277 static void osd_req_op_data_release(struct ceph_osd_request
*osd_req
,
280 struct ceph_osd_req_op
*op
;
282 BUG_ON(which
>= osd_req
->r_num_ops
);
283 op
= &osd_req
->r_ops
[which
];
286 case CEPH_OSD_OP_READ
:
287 case CEPH_OSD_OP_WRITE
:
288 ceph_osd_data_release(&op
->extent
.osd_data
);
290 case CEPH_OSD_OP_CALL
:
291 ceph_osd_data_release(&op
->cls
.request_info
);
292 ceph_osd_data_release(&op
->cls
.request_data
);
293 ceph_osd_data_release(&op
->cls
.response_data
);
295 case CEPH_OSD_OP_SETXATTR
:
296 case CEPH_OSD_OP_CMPXATTR
:
297 ceph_osd_data_release(&op
->xattr
.osd_data
);
307 static void ceph_osdc_release_request(struct kref
*kref
)
309 struct ceph_osd_request
*req
= container_of(kref
,
310 struct ceph_osd_request
, r_kref
);
313 dout("%s %p (r_request %p r_reply %p)\n", __func__
, req
,
314 req
->r_request
, req
->r_reply
);
315 WARN_ON(!RB_EMPTY_NODE(&req
->r_node
));
316 WARN_ON(!list_empty(&req
->r_req_lru_item
));
317 WARN_ON(!list_empty(&req
->r_osd_item
));
318 WARN_ON(!list_empty(&req
->r_linger_item
));
319 WARN_ON(!list_empty(&req
->r_linger_osd_item
));
323 ceph_msg_put(req
->r_request
);
325 ceph_msg_revoke_incoming(req
->r_reply
);
326 ceph_msg_put(req
->r_reply
);
329 for (which
= 0; which
< req
->r_num_ops
; which
++)
330 osd_req_op_data_release(req
, which
);
332 ceph_put_snap_context(req
->r_snapc
);
334 mempool_free(req
, req
->r_osdc
->req_mempool
);
336 kmem_cache_free(ceph_osd_request_cache
, req
);
340 void ceph_osdc_get_request(struct ceph_osd_request
*req
)
342 dout("%s %p (was %d)\n", __func__
, req
,
343 atomic_read(&req
->r_kref
.refcount
));
344 kref_get(&req
->r_kref
);
346 EXPORT_SYMBOL(ceph_osdc_get_request
);
348 void ceph_osdc_put_request(struct ceph_osd_request
*req
)
350 dout("%s %p (was %d)\n", __func__
, req
,
351 atomic_read(&req
->r_kref
.refcount
));
352 kref_put(&req
->r_kref
, ceph_osdc_release_request
);
354 EXPORT_SYMBOL(ceph_osdc_put_request
);
356 struct ceph_osd_request
*ceph_osdc_alloc_request(struct ceph_osd_client
*osdc
,
357 struct ceph_snap_context
*snapc
,
358 unsigned int num_ops
,
362 struct ceph_osd_request
*req
;
363 struct ceph_msg
*msg
;
366 BUILD_BUG_ON(CEPH_OSD_MAX_OP
> U16_MAX
);
367 BUG_ON(num_ops
> CEPH_OSD_MAX_OP
);
369 msg_size
= 4 + 4 + 8 + 8 + 4+8;
370 msg_size
+= 2 + 4 + 8 + 4 + 4; /* oloc */
371 msg_size
+= 1 + 8 + 4 + 4; /* pg_t */
372 msg_size
+= 4 + CEPH_MAX_OID_NAME_LEN
; /* oid */
373 msg_size
+= 2 + num_ops
*sizeof(struct ceph_osd_op
);
374 msg_size
+= 8; /* snapid */
375 msg_size
+= 8; /* snap_seq */
376 msg_size
+= 8 * (snapc
? snapc
->num_snaps
: 0); /* snaps */
380 req
= mempool_alloc(osdc
->req_mempool
, gfp_flags
);
381 memset(req
, 0, sizeof(*req
));
383 req
= kmem_cache_zalloc(ceph_osd_request_cache
, gfp_flags
);
389 req
->r_mempool
= use_mempool
;
390 req
->r_num_ops
= num_ops
;
392 kref_init(&req
->r_kref
);
393 init_completion(&req
->r_completion
);
394 init_completion(&req
->r_safe_completion
);
395 RB_CLEAR_NODE(&req
->r_node
);
396 INIT_LIST_HEAD(&req
->r_unsafe_item
);
397 INIT_LIST_HEAD(&req
->r_linger_item
);
398 INIT_LIST_HEAD(&req
->r_linger_osd_item
);
399 INIT_LIST_HEAD(&req
->r_req_lru_item
);
400 INIT_LIST_HEAD(&req
->r_osd_item
);
402 req
->r_base_oloc
.pool
= -1;
403 req
->r_target_oloc
.pool
= -1;
405 /* create reply message */
407 msg
= ceph_msgpool_get(&osdc
->msgpool_op_reply
, 0);
409 msg
= ceph_msg_new(CEPH_MSG_OSD_OPREPLY
,
410 OSD_OPREPLY_FRONT_LEN
, gfp_flags
, true);
412 ceph_osdc_put_request(req
);
417 /* create request message; allow space for oid */
419 msg
= ceph_msgpool_get(&osdc
->msgpool_op
, 0);
421 msg
= ceph_msg_new(CEPH_MSG_OSD_OP
, msg_size
, gfp_flags
, true);
423 ceph_osdc_put_request(req
);
427 memset(msg
->front
.iov_base
, 0, msg
->front
.iov_len
);
429 req
->r_request
= msg
;
433 EXPORT_SYMBOL(ceph_osdc_alloc_request
);
435 static bool osd_req_opcode_valid(u16 opcode
)
438 #define GENERATE_CASE(op, opcode, str) case CEPH_OSD_OP_##op: return true;
439 __CEPH_FORALL_OSD_OPS(GENERATE_CASE
)
447 * This is an osd op init function for opcodes that have no data or
448 * other information associated with them. It also serves as a
449 * common init routine for all the other init functions, below.
451 static struct ceph_osd_req_op
*
452 _osd_req_op_init(struct ceph_osd_request
*osd_req
, unsigned int which
,
455 struct ceph_osd_req_op
*op
;
457 BUG_ON(which
>= osd_req
->r_num_ops
);
458 BUG_ON(!osd_req_opcode_valid(opcode
));
460 op
= &osd_req
->r_ops
[which
];
461 memset(op
, 0, sizeof (*op
));
467 void osd_req_op_init(struct ceph_osd_request
*osd_req
,
468 unsigned int which
, u16 opcode
)
470 (void)_osd_req_op_init(osd_req
, which
, opcode
);
472 EXPORT_SYMBOL(osd_req_op_init
);
474 void osd_req_op_extent_init(struct ceph_osd_request
*osd_req
,
475 unsigned int which
, u16 opcode
,
476 u64 offset
, u64 length
,
477 u64 truncate_size
, u32 truncate_seq
)
479 struct ceph_osd_req_op
*op
= _osd_req_op_init(osd_req
, which
, opcode
);
480 size_t payload_len
= 0;
482 BUG_ON(opcode
!= CEPH_OSD_OP_READ
&& opcode
!= CEPH_OSD_OP_WRITE
&&
483 opcode
!= CEPH_OSD_OP_DELETE
&& opcode
!= CEPH_OSD_OP_ZERO
&&
484 opcode
!= CEPH_OSD_OP_TRUNCATE
);
486 op
->extent
.offset
= offset
;
487 op
->extent
.length
= length
;
488 op
->extent
.truncate_size
= truncate_size
;
489 op
->extent
.truncate_seq
= truncate_seq
;
490 if (opcode
== CEPH_OSD_OP_WRITE
)
491 payload_len
+= length
;
493 op
->payload_len
= payload_len
;
495 EXPORT_SYMBOL(osd_req_op_extent_init
);
497 void osd_req_op_extent_update(struct ceph_osd_request
*osd_req
,
498 unsigned int which
, u64 length
)
500 struct ceph_osd_req_op
*op
;
503 BUG_ON(which
>= osd_req
->r_num_ops
);
504 op
= &osd_req
->r_ops
[which
];
505 previous
= op
->extent
.length
;
507 if (length
== previous
)
508 return; /* Nothing to do */
509 BUG_ON(length
> previous
);
511 op
->extent
.length
= length
;
512 op
->payload_len
-= previous
- length
;
514 EXPORT_SYMBOL(osd_req_op_extent_update
);
516 void osd_req_op_cls_init(struct ceph_osd_request
*osd_req
, unsigned int which
,
517 u16 opcode
, const char *class, const char *method
)
519 struct ceph_osd_req_op
*op
= _osd_req_op_init(osd_req
, which
, opcode
);
520 struct ceph_pagelist
*pagelist
;
521 size_t payload_len
= 0;
524 BUG_ON(opcode
!= CEPH_OSD_OP_CALL
);
526 pagelist
= kmalloc(sizeof (*pagelist
), GFP_NOFS
);
528 ceph_pagelist_init(pagelist
);
530 op
->cls
.class_name
= class;
531 size
= strlen(class);
532 BUG_ON(size
> (size_t) U8_MAX
);
533 op
->cls
.class_len
= size
;
534 ceph_pagelist_append(pagelist
, class, size
);
537 op
->cls
.method_name
= method
;
538 size
= strlen(method
);
539 BUG_ON(size
> (size_t) U8_MAX
);
540 op
->cls
.method_len
= size
;
541 ceph_pagelist_append(pagelist
, method
, size
);
544 osd_req_op_cls_request_info_pagelist(osd_req
, which
, pagelist
);
546 op
->cls
.argc
= 0; /* currently unused */
548 op
->payload_len
= payload_len
;
550 EXPORT_SYMBOL(osd_req_op_cls_init
);
552 int osd_req_op_xattr_init(struct ceph_osd_request
*osd_req
, unsigned int which
,
553 u16 opcode
, const char *name
, const void *value
,
554 size_t size
, u8 cmp_op
, u8 cmp_mode
)
556 struct ceph_osd_req_op
*op
= _osd_req_op_init(osd_req
, which
, opcode
);
557 struct ceph_pagelist
*pagelist
;
560 BUG_ON(opcode
!= CEPH_OSD_OP_SETXATTR
&& opcode
!= CEPH_OSD_OP_CMPXATTR
);
562 pagelist
= kmalloc(sizeof(*pagelist
), GFP_NOFS
);
566 ceph_pagelist_init(pagelist
);
568 payload_len
= strlen(name
);
569 op
->xattr
.name_len
= payload_len
;
570 ceph_pagelist_append(pagelist
, name
, payload_len
);
572 op
->xattr
.value_len
= size
;
573 ceph_pagelist_append(pagelist
, value
, size
);
576 op
->xattr
.cmp_op
= cmp_op
;
577 op
->xattr
.cmp_mode
= cmp_mode
;
579 ceph_osd_data_pagelist_init(&op
->xattr
.osd_data
, pagelist
);
580 op
->payload_len
= payload_len
;
583 EXPORT_SYMBOL(osd_req_op_xattr_init
);
585 void osd_req_op_watch_init(struct ceph_osd_request
*osd_req
,
586 unsigned int which
, u16 opcode
,
587 u64 cookie
, u64 version
, int flag
)
589 struct ceph_osd_req_op
*op
= _osd_req_op_init(osd_req
, which
, opcode
);
591 BUG_ON(opcode
!= CEPH_OSD_OP_NOTIFY_ACK
&& opcode
!= CEPH_OSD_OP_WATCH
);
593 op
->watch
.cookie
= cookie
;
594 op
->watch
.ver
= version
;
595 if (opcode
== CEPH_OSD_OP_WATCH
&& flag
)
596 op
->watch
.flag
= (u8
)1;
598 EXPORT_SYMBOL(osd_req_op_watch_init
);
600 void osd_req_op_alloc_hint_init(struct ceph_osd_request
*osd_req
,
602 u64 expected_object_size
,
603 u64 expected_write_size
)
605 struct ceph_osd_req_op
*op
= _osd_req_op_init(osd_req
, which
,
606 CEPH_OSD_OP_SETALLOCHINT
);
608 op
->alloc_hint
.expected_object_size
= expected_object_size
;
609 op
->alloc_hint
.expected_write_size
= expected_write_size
;
612 * CEPH_OSD_OP_SETALLOCHINT op is advisory and therefore deemed
613 * not worth a feature bit. Set FAILOK per-op flag to make
614 * sure older osds don't trip over an unsupported opcode.
616 op
->flags
|= CEPH_OSD_OP_FLAG_FAILOK
;
618 EXPORT_SYMBOL(osd_req_op_alloc_hint_init
);
620 static void ceph_osdc_msg_data_add(struct ceph_msg
*msg
,
621 struct ceph_osd_data
*osd_data
)
623 u64 length
= ceph_osd_data_length(osd_data
);
625 if (osd_data
->type
== CEPH_OSD_DATA_TYPE_PAGES
) {
626 BUG_ON(length
> (u64
) SIZE_MAX
);
628 ceph_msg_data_add_pages(msg
, osd_data
->pages
,
629 length
, osd_data
->alignment
);
630 } else if (osd_data
->type
== CEPH_OSD_DATA_TYPE_PAGELIST
) {
632 ceph_msg_data_add_pagelist(msg
, osd_data
->pagelist
);
634 } else if (osd_data
->type
== CEPH_OSD_DATA_TYPE_BIO
) {
635 ceph_msg_data_add_bio(msg
, osd_data
->bio
, length
);
638 BUG_ON(osd_data
->type
!= CEPH_OSD_DATA_TYPE_NONE
);
642 static u64
osd_req_encode_op(struct ceph_osd_request
*req
,
643 struct ceph_osd_op
*dst
, unsigned int which
)
645 struct ceph_osd_req_op
*src
;
646 struct ceph_osd_data
*osd_data
;
647 u64 request_data_len
= 0;
650 BUG_ON(which
>= req
->r_num_ops
);
651 src
= &req
->r_ops
[which
];
652 if (WARN_ON(!osd_req_opcode_valid(src
->op
))) {
653 pr_err("unrecognized osd opcode %d\n", src
->op
);
659 case CEPH_OSD_OP_STAT
:
660 osd_data
= &src
->raw_data_in
;
661 ceph_osdc_msg_data_add(req
->r_reply
, osd_data
);
663 case CEPH_OSD_OP_READ
:
664 case CEPH_OSD_OP_WRITE
:
665 case CEPH_OSD_OP_ZERO
:
666 case CEPH_OSD_OP_DELETE
:
667 case CEPH_OSD_OP_TRUNCATE
:
668 if (src
->op
== CEPH_OSD_OP_WRITE
)
669 request_data_len
= src
->extent
.length
;
670 dst
->extent
.offset
= cpu_to_le64(src
->extent
.offset
);
671 dst
->extent
.length
= cpu_to_le64(src
->extent
.length
);
672 dst
->extent
.truncate_size
=
673 cpu_to_le64(src
->extent
.truncate_size
);
674 dst
->extent
.truncate_seq
=
675 cpu_to_le32(src
->extent
.truncate_seq
);
676 osd_data
= &src
->extent
.osd_data
;
677 if (src
->op
== CEPH_OSD_OP_WRITE
)
678 ceph_osdc_msg_data_add(req
->r_request
, osd_data
);
680 ceph_osdc_msg_data_add(req
->r_reply
, osd_data
);
682 case CEPH_OSD_OP_CALL
:
683 dst
->cls
.class_len
= src
->cls
.class_len
;
684 dst
->cls
.method_len
= src
->cls
.method_len
;
685 osd_data
= &src
->cls
.request_info
;
686 ceph_osdc_msg_data_add(req
->r_request
, osd_data
);
687 BUG_ON(osd_data
->type
!= CEPH_OSD_DATA_TYPE_PAGELIST
);
688 request_data_len
= osd_data
->pagelist
->length
;
690 osd_data
= &src
->cls
.request_data
;
691 data_length
= ceph_osd_data_length(osd_data
);
693 BUG_ON(osd_data
->type
== CEPH_OSD_DATA_TYPE_NONE
);
694 dst
->cls
.indata_len
= cpu_to_le32(data_length
);
695 ceph_osdc_msg_data_add(req
->r_request
, osd_data
);
696 src
->payload_len
+= data_length
;
697 request_data_len
+= data_length
;
699 osd_data
= &src
->cls
.response_data
;
700 ceph_osdc_msg_data_add(req
->r_reply
, osd_data
);
702 case CEPH_OSD_OP_STARTSYNC
:
704 case CEPH_OSD_OP_NOTIFY_ACK
:
705 case CEPH_OSD_OP_WATCH
:
706 dst
->watch
.cookie
= cpu_to_le64(src
->watch
.cookie
);
707 dst
->watch
.ver
= cpu_to_le64(src
->watch
.ver
);
708 dst
->watch
.flag
= src
->watch
.flag
;
710 case CEPH_OSD_OP_SETALLOCHINT
:
711 dst
->alloc_hint
.expected_object_size
=
712 cpu_to_le64(src
->alloc_hint
.expected_object_size
);
713 dst
->alloc_hint
.expected_write_size
=
714 cpu_to_le64(src
->alloc_hint
.expected_write_size
);
716 case CEPH_OSD_OP_SETXATTR
:
717 case CEPH_OSD_OP_CMPXATTR
:
718 dst
->xattr
.name_len
= cpu_to_le32(src
->xattr
.name_len
);
719 dst
->xattr
.value_len
= cpu_to_le32(src
->xattr
.value_len
);
720 dst
->xattr
.cmp_op
= src
->xattr
.cmp_op
;
721 dst
->xattr
.cmp_mode
= src
->xattr
.cmp_mode
;
722 osd_data
= &src
->xattr
.osd_data
;
723 ceph_osdc_msg_data_add(req
->r_request
, osd_data
);
724 request_data_len
= osd_data
->pagelist
->length
;
727 pr_err("unsupported osd opcode %s\n",
728 ceph_osd_op_name(src
->op
));
734 dst
->op
= cpu_to_le16(src
->op
);
735 dst
->flags
= cpu_to_le32(src
->flags
);
736 dst
->payload_len
= cpu_to_le32(src
->payload_len
);
738 return request_data_len
;
742 * build new request AND message, calculate layout, and adjust file
745 * if the file was recently truncated, we include information about its
746 * old and new size so that the object can be updated appropriately. (we
747 * avoid synchronously deleting truncated objects because it's slow.)
749 * if @do_sync, include a 'startsync' command so that the osd will flush
752 struct ceph_osd_request
*ceph_osdc_new_request(struct ceph_osd_client
*osdc
,
753 struct ceph_file_layout
*layout
,
754 struct ceph_vino vino
,
755 u64 off
, u64
*plen
, int num_ops
,
756 int opcode
, int flags
,
757 struct ceph_snap_context
*snapc
,
762 struct ceph_osd_request
*req
;
770 BUG_ON(opcode
!= CEPH_OSD_OP_READ
&& opcode
!= CEPH_OSD_OP_WRITE
&&
771 opcode
!= CEPH_OSD_OP_DELETE
&& opcode
!= CEPH_OSD_OP_ZERO
&&
772 opcode
!= CEPH_OSD_OP_TRUNCATE
);
774 req
= ceph_osdc_alloc_request(osdc
, snapc
, num_ops
, use_mempool
,
777 return ERR_PTR(-ENOMEM
);
779 req
->r_flags
= flags
;
781 /* calculate max write size */
782 r
= calc_layout(layout
, off
, plen
, &objnum
, &objoff
, &objlen
);
784 ceph_osdc_put_request(req
);
788 object_size
= le32_to_cpu(layout
->fl_object_size
);
789 object_base
= off
- objoff
;
790 if (!(truncate_seq
== 1 && truncate_size
== -1ULL)) {
791 if (truncate_size
<= object_base
) {
794 truncate_size
-= object_base
;
795 if (truncate_size
> object_size
)
796 truncate_size
= object_size
;
800 osd_req_op_extent_init(req
, 0, opcode
, objoff
, objlen
,
801 truncate_size
, truncate_seq
);
804 * A second op in the ops array means the caller wants to
805 * also issue a include a 'startsync' command so that the
806 * osd will flush data quickly.
809 osd_req_op_init(req
, 1, CEPH_OSD_OP_STARTSYNC
);
811 req
->r_base_oloc
.pool
= ceph_file_layout_pg_pool(*layout
);
813 snprintf(req
->r_base_oid
.name
, sizeof(req
->r_base_oid
.name
),
814 "%llx.%08llx", vino
.ino
, objnum
);
815 req
->r_base_oid
.name_len
= strlen(req
->r_base_oid
.name
);
819 EXPORT_SYMBOL(ceph_osdc_new_request
);
822 * We keep osd requests in an rbtree, sorted by ->r_tid.
824 static void __insert_request(struct ceph_osd_client
*osdc
,
825 struct ceph_osd_request
*new)
827 struct rb_node
**p
= &osdc
->requests
.rb_node
;
828 struct rb_node
*parent
= NULL
;
829 struct ceph_osd_request
*req
= NULL
;
833 req
= rb_entry(parent
, struct ceph_osd_request
, r_node
);
834 if (new->r_tid
< req
->r_tid
)
836 else if (new->r_tid
> req
->r_tid
)
842 rb_link_node(&new->r_node
, parent
, p
);
843 rb_insert_color(&new->r_node
, &osdc
->requests
);
846 static struct ceph_osd_request
*__lookup_request(struct ceph_osd_client
*osdc
,
849 struct ceph_osd_request
*req
;
850 struct rb_node
*n
= osdc
->requests
.rb_node
;
853 req
= rb_entry(n
, struct ceph_osd_request
, r_node
);
854 if (tid
< req
->r_tid
)
856 else if (tid
> req
->r_tid
)
864 static struct ceph_osd_request
*
865 __lookup_request_ge(struct ceph_osd_client
*osdc
,
868 struct ceph_osd_request
*req
;
869 struct rb_node
*n
= osdc
->requests
.rb_node
;
872 req
= rb_entry(n
, struct ceph_osd_request
, r_node
);
873 if (tid
< req
->r_tid
) {
877 } else if (tid
> req
->r_tid
) {
886 static void __kick_linger_request(struct ceph_osd_request
*req
)
888 struct ceph_osd_client
*osdc
= req
->r_osdc
;
889 struct ceph_osd
*osd
= req
->r_osd
;
892 * Linger requests need to be resent with a new tid to avoid
893 * the dup op detection logic on the OSDs. Achieve this with
894 * a re-register dance instead of open-coding.
896 ceph_osdc_get_request(req
);
897 if (!list_empty(&req
->r_linger_item
))
898 __unregister_linger_request(osdc
, req
);
900 __unregister_request(osdc
, req
);
901 __register_request(osdc
, req
);
902 ceph_osdc_put_request(req
);
905 * Unless request has been registered as both normal and
906 * lingering, __unregister{,_linger}_request clears r_osd.
907 * However, here we need to preserve r_osd to make sure we
908 * requeue on the same OSD.
910 WARN_ON(req
->r_osd
|| !osd
);
913 dout("%s requeueing %p tid %llu\n", __func__
, req
, req
->r_tid
);
914 __enqueue_request(req
);
918 * Resubmit requests pending on the given osd.
920 static void __kick_osd_requests(struct ceph_osd_client
*osdc
,
921 struct ceph_osd
*osd
)
923 struct ceph_osd_request
*req
, *nreq
;
925 LIST_HEAD(resend_linger
);
928 dout("%s osd%d\n", __func__
, osd
->o_osd
);
929 err
= __reset_osd(osdc
, osd
);
934 * Build up a list of requests to resend by traversing the
935 * osd's list of requests. Requests for a given object are
936 * sent in tid order, and that is also the order they're
937 * kept on this list. Therefore all requests that are in
938 * flight will be found first, followed by all requests that
939 * have not yet been sent. And to resend requests while
940 * preserving this order we will want to put any sent
941 * requests back on the front of the osd client's unsent
944 * So we build a separate ordered list of already-sent
945 * requests for the affected osd and splice it onto the
946 * front of the osd client's unsent list. Once we've seen a
947 * request that has not yet been sent we're done. Those
948 * requests are already sitting right where they belong.
950 list_for_each_entry(req
, &osd
->o_requests
, r_osd_item
) {
954 if (!req
->r_linger
) {
955 dout("%s requeueing %p tid %llu\n", __func__
, req
,
957 list_move_tail(&req
->r_req_lru_item
, &resend
);
958 req
->r_flags
|= CEPH_OSD_FLAG_RETRY
;
960 list_move_tail(&req
->r_req_lru_item
, &resend_linger
);
963 list_splice(&resend
, &osdc
->req_unsent
);
966 * Both registered and not yet registered linger requests are
967 * enqueued with a new tid on the same OSD. We add/move them
968 * to req_unsent/o_requests at the end to keep things in tid
971 list_for_each_entry_safe(req
, nreq
, &osd
->o_linger_requests
,
973 WARN_ON(!list_empty(&req
->r_req_lru_item
));
974 __kick_linger_request(req
);
977 list_for_each_entry_safe(req
, nreq
, &resend_linger
, r_req_lru_item
)
978 __kick_linger_request(req
);
982 * If the osd connection drops, we need to resubmit all requests.
984 static void osd_reset(struct ceph_connection
*con
)
986 struct ceph_osd
*osd
= con
->private;
987 struct ceph_osd_client
*osdc
;
991 dout("osd_reset osd%d\n", osd
->o_osd
);
993 down_read(&osdc
->map_sem
);
994 mutex_lock(&osdc
->request_mutex
);
995 __kick_osd_requests(osdc
, osd
);
997 mutex_unlock(&osdc
->request_mutex
);
998 up_read(&osdc
->map_sem
);
1002 * Track open sessions with osds.
1004 static struct ceph_osd
*create_osd(struct ceph_osd_client
*osdc
, int onum
)
1006 struct ceph_osd
*osd
;
1008 osd
= kzalloc(sizeof(*osd
), GFP_NOFS
);
1012 atomic_set(&osd
->o_ref
, 1);
1015 RB_CLEAR_NODE(&osd
->o_node
);
1016 INIT_LIST_HEAD(&osd
->o_requests
);
1017 INIT_LIST_HEAD(&osd
->o_linger_requests
);
1018 INIT_LIST_HEAD(&osd
->o_osd_lru
);
1019 osd
->o_incarnation
= 1;
1021 ceph_con_init(&osd
->o_con
, osd
, &osd_con_ops
, &osdc
->client
->msgr
);
1023 INIT_LIST_HEAD(&osd
->o_keepalive_item
);
1027 static struct ceph_osd
*get_osd(struct ceph_osd
*osd
)
1029 if (atomic_inc_not_zero(&osd
->o_ref
)) {
1030 dout("get_osd %p %d -> %d\n", osd
, atomic_read(&osd
->o_ref
)-1,
1031 atomic_read(&osd
->o_ref
));
1034 dout("get_osd %p FAIL\n", osd
);
1039 static void put_osd(struct ceph_osd
*osd
)
1041 dout("put_osd %p %d -> %d\n", osd
, atomic_read(&osd
->o_ref
),
1042 atomic_read(&osd
->o_ref
) - 1);
1043 if (atomic_dec_and_test(&osd
->o_ref
) && osd
->o_auth
.authorizer
) {
1044 struct ceph_auth_client
*ac
= osd
->o_osdc
->client
->monc
.auth
;
1046 ceph_auth_destroy_authorizer(ac
, osd
->o_auth
.authorizer
);
1052 * remove an osd from our map
1054 static void __remove_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*osd
)
1056 dout("__remove_osd %p\n", osd
);
1057 WARN_ON(!list_empty(&osd
->o_requests
));
1058 WARN_ON(!list_empty(&osd
->o_linger_requests
));
1060 rb_erase(&osd
->o_node
, &osdc
->osds
);
1061 list_del_init(&osd
->o_osd_lru
);
1062 ceph_con_close(&osd
->o_con
);
1066 static void remove_all_osds(struct ceph_osd_client
*osdc
)
1068 dout("%s %p\n", __func__
, osdc
);
1069 mutex_lock(&osdc
->request_mutex
);
1070 while (!RB_EMPTY_ROOT(&osdc
->osds
)) {
1071 struct ceph_osd
*osd
= rb_entry(rb_first(&osdc
->osds
),
1072 struct ceph_osd
, o_node
);
1073 __remove_osd(osdc
, osd
);
1075 mutex_unlock(&osdc
->request_mutex
);
1078 static void __move_osd_to_lru(struct ceph_osd_client
*osdc
,
1079 struct ceph_osd
*osd
)
1081 dout("%s %p\n", __func__
, osd
);
1082 BUG_ON(!list_empty(&osd
->o_osd_lru
));
1084 list_add_tail(&osd
->o_osd_lru
, &osdc
->osd_lru
);
1085 osd
->lru_ttl
= jiffies
+ osdc
->client
->options
->osd_idle_ttl
* HZ
;
1088 static void maybe_move_osd_to_lru(struct ceph_osd_client
*osdc
,
1089 struct ceph_osd
*osd
)
1091 dout("%s %p\n", __func__
, osd
);
1093 if (list_empty(&osd
->o_requests
) &&
1094 list_empty(&osd
->o_linger_requests
))
1095 __move_osd_to_lru(osdc
, osd
);
1098 static void __remove_osd_from_lru(struct ceph_osd
*osd
)
1100 dout("__remove_osd_from_lru %p\n", osd
);
1101 if (!list_empty(&osd
->o_osd_lru
))
1102 list_del_init(&osd
->o_osd_lru
);
1105 static void remove_old_osds(struct ceph_osd_client
*osdc
)
1107 struct ceph_osd
*osd
, *nosd
;
1109 dout("__remove_old_osds %p\n", osdc
);
1110 mutex_lock(&osdc
->request_mutex
);
1111 list_for_each_entry_safe(osd
, nosd
, &osdc
->osd_lru
, o_osd_lru
) {
1112 if (time_before(jiffies
, osd
->lru_ttl
))
1114 __remove_osd(osdc
, osd
);
1116 mutex_unlock(&osdc
->request_mutex
);
1122 static int __reset_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*osd
)
1124 struct ceph_entity_addr
*peer_addr
;
1126 dout("__reset_osd %p osd%d\n", osd
, osd
->o_osd
);
1127 if (list_empty(&osd
->o_requests
) &&
1128 list_empty(&osd
->o_linger_requests
)) {
1129 __remove_osd(osdc
, osd
);
1134 peer_addr
= &osdc
->osdmap
->osd_addr
[osd
->o_osd
];
1135 if (!memcmp(peer_addr
, &osd
->o_con
.peer_addr
, sizeof (*peer_addr
)) &&
1136 !ceph_con_opened(&osd
->o_con
)) {
1137 struct ceph_osd_request
*req
;
1139 dout("osd addr hasn't changed and connection never opened, "
1140 "letting msgr retry\n");
1141 /* touch each r_stamp for handle_timeout()'s benfit */
1142 list_for_each_entry(req
, &osd
->o_requests
, r_osd_item
)
1143 req
->r_stamp
= jiffies
;
1148 ceph_con_close(&osd
->o_con
);
1149 ceph_con_open(&osd
->o_con
, CEPH_ENTITY_TYPE_OSD
, osd
->o_osd
, peer_addr
);
1150 osd
->o_incarnation
++;
1155 static void __insert_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*new)
1157 struct rb_node
**p
= &osdc
->osds
.rb_node
;
1158 struct rb_node
*parent
= NULL
;
1159 struct ceph_osd
*osd
= NULL
;
1161 dout("__insert_osd %p osd%d\n", new, new->o_osd
);
1164 osd
= rb_entry(parent
, struct ceph_osd
, o_node
);
1165 if (new->o_osd
< osd
->o_osd
)
1167 else if (new->o_osd
> osd
->o_osd
)
1168 p
= &(*p
)->rb_right
;
1173 rb_link_node(&new->o_node
, parent
, p
);
1174 rb_insert_color(&new->o_node
, &osdc
->osds
);
1177 static struct ceph_osd
*__lookup_osd(struct ceph_osd_client
*osdc
, int o
)
1179 struct ceph_osd
*osd
;
1180 struct rb_node
*n
= osdc
->osds
.rb_node
;
1183 osd
= rb_entry(n
, struct ceph_osd
, o_node
);
1186 else if (o
> osd
->o_osd
)
1194 static void __schedule_osd_timeout(struct ceph_osd_client
*osdc
)
1196 schedule_delayed_work(&osdc
->timeout_work
,
1197 osdc
->client
->options
->osd_keepalive_timeout
* HZ
);
1200 static void __cancel_osd_timeout(struct ceph_osd_client
*osdc
)
1202 cancel_delayed_work(&osdc
->timeout_work
);
1206 * Register request, assign tid. If this is the first request, set up
1207 * the timeout event.
1209 static void __register_request(struct ceph_osd_client
*osdc
,
1210 struct ceph_osd_request
*req
)
1212 req
->r_tid
= ++osdc
->last_tid
;
1213 req
->r_request
->hdr
.tid
= cpu_to_le64(req
->r_tid
);
1214 dout("__register_request %p tid %lld\n", req
, req
->r_tid
);
1215 __insert_request(osdc
, req
);
1216 ceph_osdc_get_request(req
);
1217 osdc
->num_requests
++;
1218 if (osdc
->num_requests
== 1) {
1219 dout(" first request, scheduling timeout\n");
1220 __schedule_osd_timeout(osdc
);
1225 * called under osdc->request_mutex
1227 static void __unregister_request(struct ceph_osd_client
*osdc
,
1228 struct ceph_osd_request
*req
)
1230 if (RB_EMPTY_NODE(&req
->r_node
)) {
1231 dout("__unregister_request %p tid %lld not registered\n",
1236 dout("__unregister_request %p tid %lld\n", req
, req
->r_tid
);
1237 rb_erase(&req
->r_node
, &osdc
->requests
);
1238 RB_CLEAR_NODE(&req
->r_node
);
1239 osdc
->num_requests
--;
1242 /* make sure the original request isn't in flight. */
1243 ceph_msg_revoke(req
->r_request
);
1245 list_del_init(&req
->r_osd_item
);
1246 maybe_move_osd_to_lru(osdc
, req
->r_osd
);
1247 if (list_empty(&req
->r_linger_osd_item
))
1251 list_del_init(&req
->r_req_lru_item
);
1252 ceph_osdc_put_request(req
);
1254 if (osdc
->num_requests
== 0) {
1255 dout(" no requests, canceling timeout\n");
1256 __cancel_osd_timeout(osdc
);
1261 * Cancel a previously queued request message
1263 static void __cancel_request(struct ceph_osd_request
*req
)
1265 if (req
->r_sent
&& req
->r_osd
) {
1266 ceph_msg_revoke(req
->r_request
);
1271 static void __register_linger_request(struct ceph_osd_client
*osdc
,
1272 struct ceph_osd_request
*req
)
1274 dout("%s %p tid %llu\n", __func__
, req
, req
->r_tid
);
1275 WARN_ON(!req
->r_linger
);
1277 ceph_osdc_get_request(req
);
1278 list_add_tail(&req
->r_linger_item
, &osdc
->req_linger
);
1280 list_add_tail(&req
->r_linger_osd_item
,
1281 &req
->r_osd
->o_linger_requests
);
1284 static void __unregister_linger_request(struct ceph_osd_client
*osdc
,
1285 struct ceph_osd_request
*req
)
1287 WARN_ON(!req
->r_linger
);
1289 if (list_empty(&req
->r_linger_item
)) {
1290 dout("%s %p tid %llu not registered\n", __func__
, req
,
1295 dout("%s %p tid %llu\n", __func__
, req
, req
->r_tid
);
1296 list_del_init(&req
->r_linger_item
);
1299 list_del_init(&req
->r_linger_osd_item
);
1300 maybe_move_osd_to_lru(osdc
, req
->r_osd
);
1301 if (list_empty(&req
->r_osd_item
))
1305 list_del_init(&req
->r_req_lru_item
); /* can be on notarget */
1306 ceph_osdc_put_request(req
);
1309 void ceph_osdc_set_request_linger(struct ceph_osd_client
*osdc
,
1310 struct ceph_osd_request
*req
)
1312 if (!req
->r_linger
) {
1313 dout("set_request_linger %p\n", req
);
1317 EXPORT_SYMBOL(ceph_osdc_set_request_linger
);
1320 * Returns whether a request should be blocked from being sent
1321 * based on the current osdmap and osd_client settings.
1323 * Caller should hold map_sem for read.
1325 static bool __req_should_be_paused(struct ceph_osd_client
*osdc
,
1326 struct ceph_osd_request
*req
)
1328 bool pauserd
= ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_PAUSERD
);
1329 bool pausewr
= ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_PAUSEWR
) ||
1330 ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_FULL
);
1331 return (req
->r_flags
& CEPH_OSD_FLAG_READ
&& pauserd
) ||
1332 (req
->r_flags
& CEPH_OSD_FLAG_WRITE
&& pausewr
);
1336 * Calculate mapping of a request to a PG. Takes tiering into account.
1338 static int __calc_request_pg(struct ceph_osdmap
*osdmap
,
1339 struct ceph_osd_request
*req
,
1340 struct ceph_pg
*pg_out
)
1342 bool need_check_tiering
;
1344 need_check_tiering
= false;
1345 if (req
->r_target_oloc
.pool
== -1) {
1346 req
->r_target_oloc
= req
->r_base_oloc
; /* struct */
1347 need_check_tiering
= true;
1349 if (req
->r_target_oid
.name_len
== 0) {
1350 ceph_oid_copy(&req
->r_target_oid
, &req
->r_base_oid
);
1351 need_check_tiering
= true;
1354 if (need_check_tiering
&&
1355 (req
->r_flags
& CEPH_OSD_FLAG_IGNORE_OVERLAY
) == 0) {
1356 struct ceph_pg_pool_info
*pi
;
1358 pi
= ceph_pg_pool_by_id(osdmap
, req
->r_target_oloc
.pool
);
1360 if ((req
->r_flags
& CEPH_OSD_FLAG_READ
) &&
1362 req
->r_target_oloc
.pool
= pi
->read_tier
;
1363 if ((req
->r_flags
& CEPH_OSD_FLAG_WRITE
) &&
1364 pi
->write_tier
>= 0)
1365 req
->r_target_oloc
.pool
= pi
->write_tier
;
1367 /* !pi is caught in ceph_oloc_oid_to_pg() */
1370 return ceph_oloc_oid_to_pg(osdmap
, &req
->r_target_oloc
,
1371 &req
->r_target_oid
, pg_out
);
1374 static void __enqueue_request(struct ceph_osd_request
*req
)
1376 struct ceph_osd_client
*osdc
= req
->r_osdc
;
1378 dout("%s %p tid %llu to osd%d\n", __func__
, req
, req
->r_tid
,
1379 req
->r_osd
? req
->r_osd
->o_osd
: -1);
1382 __remove_osd_from_lru(req
->r_osd
);
1383 list_add_tail(&req
->r_osd_item
, &req
->r_osd
->o_requests
);
1384 list_move_tail(&req
->r_req_lru_item
, &osdc
->req_unsent
);
1386 list_move_tail(&req
->r_req_lru_item
, &osdc
->req_notarget
);
1391 * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
1392 * (as needed), and set the request r_osd appropriately. If there is
1393 * no up osd, set r_osd to NULL. Move the request to the appropriate list
1394 * (unsent, homeless) or leave on in-flight lru.
1396 * Return 0 if unchanged, 1 if changed, or negative on error.
1398 * Caller should hold map_sem for read and request_mutex.
1400 static int __map_request(struct ceph_osd_client
*osdc
,
1401 struct ceph_osd_request
*req
, int force_resend
)
1403 struct ceph_pg pgid
;
1404 int acting
[CEPH_PG_MAX_SIZE
];
1409 dout("map_request %p tid %lld\n", req
, req
->r_tid
);
1411 err
= __calc_request_pg(osdc
->osdmap
, req
, &pgid
);
1413 list_move(&req
->r_req_lru_item
, &osdc
->req_notarget
);
1418 num
= ceph_calc_pg_acting(osdc
->osdmap
, pgid
, acting
, &o
);
1422 was_paused
= req
->r_paused
;
1423 req
->r_paused
= __req_should_be_paused(osdc
, req
);
1424 if (was_paused
&& !req
->r_paused
)
1427 if ((!force_resend
&&
1428 req
->r_osd
&& req
->r_osd
->o_osd
== o
&&
1429 req
->r_sent
>= req
->r_osd
->o_incarnation
&&
1430 req
->r_num_pg_osds
== num
&&
1431 memcmp(req
->r_pg_osds
, acting
, sizeof(acting
[0])*num
) == 0) ||
1432 (req
->r_osd
== NULL
&& o
== -1) ||
1434 return 0; /* no change */
1436 dout("map_request tid %llu pgid %lld.%x osd%d (was osd%d)\n",
1437 req
->r_tid
, pgid
.pool
, pgid
.seed
, o
,
1438 req
->r_osd
? req
->r_osd
->o_osd
: -1);
1440 /* record full pg acting set */
1441 memcpy(req
->r_pg_osds
, acting
, sizeof(acting
[0]) * num
);
1442 req
->r_num_pg_osds
= num
;
1445 __cancel_request(req
);
1446 list_del_init(&req
->r_osd_item
);
1447 list_del_init(&req
->r_linger_osd_item
);
1451 req
->r_osd
= __lookup_osd(osdc
, o
);
1452 if (!req
->r_osd
&& o
>= 0) {
1454 req
->r_osd
= create_osd(osdc
, o
);
1456 list_move(&req
->r_req_lru_item
, &osdc
->req_notarget
);
1460 dout("map_request osd %p is osd%d\n", req
->r_osd
, o
);
1461 __insert_osd(osdc
, req
->r_osd
);
1463 ceph_con_open(&req
->r_osd
->o_con
,
1464 CEPH_ENTITY_TYPE_OSD
, o
,
1465 &osdc
->osdmap
->osd_addr
[o
]);
1468 __enqueue_request(req
);
1469 err
= 1; /* osd or pg changed */
1476 * caller should hold map_sem (for read) and request_mutex
1478 static void __send_request(struct ceph_osd_client
*osdc
,
1479 struct ceph_osd_request
*req
)
1483 dout("send_request %p tid %llu to osd%d flags %d pg %lld.%x\n",
1484 req
, req
->r_tid
, req
->r_osd
->o_osd
, req
->r_flags
,
1485 (unsigned long long)req
->r_pgid
.pool
, req
->r_pgid
.seed
);
1487 /* fill in message content that changes each time we send it */
1488 put_unaligned_le32(osdc
->osdmap
->epoch
, req
->r_request_osdmap_epoch
);
1489 put_unaligned_le32(req
->r_flags
, req
->r_request_flags
);
1490 put_unaligned_le64(req
->r_target_oloc
.pool
, req
->r_request_pool
);
1491 p
= req
->r_request_pgid
;
1492 ceph_encode_64(&p
, req
->r_pgid
.pool
);
1493 ceph_encode_32(&p
, req
->r_pgid
.seed
);
1494 put_unaligned_le64(1, req
->r_request_attempts
); /* FIXME */
1495 memcpy(req
->r_request_reassert_version
, &req
->r_reassert_version
,
1496 sizeof(req
->r_reassert_version
));
1498 req
->r_stamp
= jiffies
;
1499 list_move_tail(&req
->r_req_lru_item
, &osdc
->req_lru
);
1501 ceph_msg_get(req
->r_request
); /* send consumes a ref */
1503 req
->r_sent
= req
->r_osd
->o_incarnation
;
1505 ceph_con_send(&req
->r_osd
->o_con
, req
->r_request
);
1509 * Send any requests in the queue (req_unsent).
1511 static void __send_queued(struct ceph_osd_client
*osdc
)
1513 struct ceph_osd_request
*req
, *tmp
;
1515 dout("__send_queued\n");
1516 list_for_each_entry_safe(req
, tmp
, &osdc
->req_unsent
, r_req_lru_item
)
1517 __send_request(osdc
, req
);
1521 * Caller should hold map_sem for read and request_mutex.
1523 static int __ceph_osdc_start_request(struct ceph_osd_client
*osdc
,
1524 struct ceph_osd_request
*req
,
1529 __register_request(osdc
, req
);
1531 req
->r_got_reply
= 0;
1532 rc
= __map_request(osdc
, req
, 0);
1535 dout("osdc_start_request failed map, "
1536 " will retry %lld\n", req
->r_tid
);
1539 __unregister_request(osdc
, req
);
1544 if (req
->r_osd
== NULL
) {
1545 dout("send_request %p no up osds in pg\n", req
);
1546 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
1548 __send_queued(osdc
);
1555 * Timeout callback, called every N seconds when 1 or more osd
1556 * requests has been active for more than N seconds. When this
1557 * happens, we ping all OSDs with requests who have timed out to
1558 * ensure any communications channel reset is detected. Reset the
1559 * request timeouts another N seconds in the future as we go.
1560 * Reschedule the timeout event another N seconds in future (unless
1561 * there are no open requests).
1563 static void handle_timeout(struct work_struct
*work
)
1565 struct ceph_osd_client
*osdc
=
1566 container_of(work
, struct ceph_osd_client
, timeout_work
.work
);
1567 struct ceph_osd_request
*req
;
1568 struct ceph_osd
*osd
;
1569 unsigned long keepalive
=
1570 osdc
->client
->options
->osd_keepalive_timeout
* HZ
;
1571 struct list_head slow_osds
;
1573 down_read(&osdc
->map_sem
);
1575 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
1577 mutex_lock(&osdc
->request_mutex
);
1580 * ping osds that are a bit slow. this ensures that if there
1581 * is a break in the TCP connection we will notice, and reopen
1582 * a connection with that osd (from the fault callback).
1584 INIT_LIST_HEAD(&slow_osds
);
1585 list_for_each_entry(req
, &osdc
->req_lru
, r_req_lru_item
) {
1586 if (time_before(jiffies
, req
->r_stamp
+ keepalive
))
1591 dout(" tid %llu is slow, will send keepalive on osd%d\n",
1592 req
->r_tid
, osd
->o_osd
);
1593 list_move_tail(&osd
->o_keepalive_item
, &slow_osds
);
1595 while (!list_empty(&slow_osds
)) {
1596 osd
= list_entry(slow_osds
.next
, struct ceph_osd
,
1598 list_del_init(&osd
->o_keepalive_item
);
1599 ceph_con_keepalive(&osd
->o_con
);
1602 __schedule_osd_timeout(osdc
);
1603 __send_queued(osdc
);
1604 mutex_unlock(&osdc
->request_mutex
);
1605 up_read(&osdc
->map_sem
);
1608 static void handle_osds_timeout(struct work_struct
*work
)
1610 struct ceph_osd_client
*osdc
=
1611 container_of(work
, struct ceph_osd_client
,
1612 osds_timeout_work
.work
);
1613 unsigned long delay
=
1614 osdc
->client
->options
->osd_idle_ttl
* HZ
>> 2;
1616 dout("osds timeout\n");
1617 down_read(&osdc
->map_sem
);
1618 remove_old_osds(osdc
);
1619 up_read(&osdc
->map_sem
);
1621 schedule_delayed_work(&osdc
->osds_timeout_work
,
1622 round_jiffies_relative(delay
));
1625 static int ceph_oloc_decode(void **p
, void *end
,
1626 struct ceph_object_locator
*oloc
)
1628 u8 struct_v
, struct_cv
;
1633 ceph_decode_need(p
, end
, 1 + 1 + 4, e_inval
);
1634 struct_v
= ceph_decode_8(p
);
1635 struct_cv
= ceph_decode_8(p
);
1637 pr_warn("got v %d < 3 cv %d of ceph_object_locator\n",
1638 struct_v
, struct_cv
);
1641 if (struct_cv
> 6) {
1642 pr_warn("got v %d cv %d > 6 of ceph_object_locator\n",
1643 struct_v
, struct_cv
);
1646 len
= ceph_decode_32(p
);
1647 ceph_decode_need(p
, end
, len
, e_inval
);
1648 struct_end
= *p
+ len
;
1650 oloc
->pool
= ceph_decode_64(p
);
1651 *p
+= 4; /* skip preferred */
1653 len
= ceph_decode_32(p
);
1655 pr_warn("ceph_object_locator::key is set\n");
1659 if (struct_v
>= 5) {
1660 len
= ceph_decode_32(p
);
1662 pr_warn("ceph_object_locator::nspace is set\n");
1667 if (struct_v
>= 6) {
1668 s64 hash
= ceph_decode_64(p
);
1670 pr_warn("ceph_object_locator::hash is set\n");
1685 static int ceph_redirect_decode(void **p
, void *end
,
1686 struct ceph_request_redirect
*redir
)
1688 u8 struct_v
, struct_cv
;
1693 ceph_decode_need(p
, end
, 1 + 1 + 4, e_inval
);
1694 struct_v
= ceph_decode_8(p
);
1695 struct_cv
= ceph_decode_8(p
);
1696 if (struct_cv
> 1) {
1697 pr_warn("got v %d cv %d > 1 of ceph_request_redirect\n",
1698 struct_v
, struct_cv
);
1701 len
= ceph_decode_32(p
);
1702 ceph_decode_need(p
, end
, len
, e_inval
);
1703 struct_end
= *p
+ len
;
1705 ret
= ceph_oloc_decode(p
, end
, &redir
->oloc
);
1709 len
= ceph_decode_32(p
);
1711 pr_warn("ceph_request_redirect::object_name is set\n");
1715 len
= ceph_decode_32(p
);
1716 *p
+= len
; /* skip osd_instructions */
1728 static void complete_request(struct ceph_osd_request
*req
)
1730 complete_all(&req
->r_safe_completion
); /* fsync waiter */
1734 * handle osd op reply. either call the callback if it is specified,
1735 * or do the completion to wake up the waiting thread.
1737 static void handle_reply(struct ceph_osd_client
*osdc
, struct ceph_msg
*msg
,
1738 struct ceph_connection
*con
)
1741 struct ceph_osd_request
*req
;
1742 struct ceph_request_redirect redir
;
1745 unsigned int numops
;
1746 int payload_len
, flags
;
1752 u64 reassert_version
;
1754 int already_completed
;
1758 tid
= le64_to_cpu(msg
->hdr
.tid
);
1759 dout("handle_reply %p tid %llu\n", msg
, tid
);
1761 p
= msg
->front
.iov_base
;
1762 end
= p
+ msg
->front
.iov_len
;
1764 ceph_decode_need(&p
, end
, 4, bad
);
1765 object_len
= ceph_decode_32(&p
);
1766 ceph_decode_need(&p
, end
, object_len
, bad
);
1769 err
= ceph_decode_pgid(&p
, end
, &pg
);
1773 ceph_decode_need(&p
, end
, 8 + 4 + 4 + 8 + 4, bad
);
1774 flags
= ceph_decode_64(&p
);
1775 result
= ceph_decode_32(&p
);
1776 reassert_epoch
= ceph_decode_32(&p
);
1777 reassert_version
= ceph_decode_64(&p
);
1778 osdmap_epoch
= ceph_decode_32(&p
);
1781 down_read(&osdc
->map_sem
);
1782 mutex_lock(&osdc
->request_mutex
);
1783 req
= __lookup_request(osdc
, tid
);
1785 dout("handle_reply tid %llu dne\n", tid
);
1788 ceph_osdc_get_request(req
);
1790 dout("handle_reply %p tid %llu req %p result %d\n", msg
, tid
,
1793 ceph_decode_need(&p
, end
, 4, bad_put
);
1794 numops
= ceph_decode_32(&p
);
1795 if (numops
> CEPH_OSD_MAX_OP
)
1797 if (numops
!= req
->r_num_ops
)
1800 ceph_decode_need(&p
, end
, numops
* sizeof(struct ceph_osd_op
), bad_put
);
1801 for (i
= 0; i
< numops
; i
++) {
1802 struct ceph_osd_op
*op
= p
;
1805 len
= le32_to_cpu(op
->payload_len
);
1806 req
->r_reply_op_len
[i
] = len
;
1807 dout(" op %d has %d bytes\n", i
, len
);
1811 bytes
= le32_to_cpu(msg
->hdr
.data_len
);
1812 if (payload_len
!= bytes
) {
1813 pr_warn("sum of op payload lens %d != data_len %d\n",
1814 payload_len
, bytes
);
1818 ceph_decode_need(&p
, end
, 4 + numops
* 4, bad_put
);
1819 retry_attempt
= ceph_decode_32(&p
);
1820 for (i
= 0; i
< numops
; i
++)
1821 req
->r_reply_op_result
[i
] = ceph_decode_32(&p
);
1823 if (le16_to_cpu(msg
->hdr
.version
) >= 6) {
1824 p
+= 8 + 4; /* skip replay_version */
1825 p
+= 8; /* skip user_version */
1827 err
= ceph_redirect_decode(&p
, end
, &redir
);
1831 redir
.oloc
.pool
= -1;
1834 if (redir
.oloc
.pool
!= -1) {
1835 dout("redirect pool %lld\n", redir
.oloc
.pool
);
1837 __unregister_request(osdc
, req
);
1839 req
->r_target_oloc
= redir
.oloc
; /* struct */
1842 * Start redirect requests with nofail=true. If
1843 * mapping fails, request will end up on the notarget
1844 * list, waiting for the new osdmap (which can take
1845 * a while), even though the original request mapped
1846 * successfully. In the future we might want to follow
1847 * original request's nofail setting here.
1849 err
= __ceph_osdc_start_request(osdc
, req
, true);
1855 already_completed
= req
->r_got_reply
;
1856 if (!req
->r_got_reply
) {
1857 req
->r_result
= result
;
1858 dout("handle_reply result %d bytes %d\n", req
->r_result
,
1860 if (req
->r_result
== 0)
1861 req
->r_result
= bytes
;
1863 /* in case this is a write and we need to replay, */
1864 req
->r_reassert_version
.epoch
= cpu_to_le32(reassert_epoch
);
1865 req
->r_reassert_version
.version
= cpu_to_le64(reassert_version
);
1867 req
->r_got_reply
= 1;
1868 } else if ((flags
& CEPH_OSD_FLAG_ONDISK
) == 0) {
1869 dout("handle_reply tid %llu dup ack\n", tid
);
1873 dout("handle_reply tid %llu flags %d\n", tid
, flags
);
1875 if (req
->r_linger
&& (flags
& CEPH_OSD_FLAG_ONDISK
))
1876 __register_linger_request(osdc
, req
);
1878 /* either this is a read, or we got the safe response */
1880 (flags
& CEPH_OSD_FLAG_ONDISK
) ||
1881 ((flags
& CEPH_OSD_FLAG_WRITE
) == 0))
1882 __unregister_request(osdc
, req
);
1884 mutex_unlock(&osdc
->request_mutex
);
1885 up_read(&osdc
->map_sem
);
1887 if (!already_completed
) {
1888 if (req
->r_unsafe_callback
&&
1889 result
>= 0 && !(flags
& CEPH_OSD_FLAG_ONDISK
))
1890 req
->r_unsafe_callback(req
, true);
1891 if (req
->r_callback
)
1892 req
->r_callback(req
, msg
);
1894 complete_all(&req
->r_completion
);
1897 if (flags
& CEPH_OSD_FLAG_ONDISK
) {
1898 if (req
->r_unsafe_callback
&& already_completed
)
1899 req
->r_unsafe_callback(req
, false);
1900 complete_request(req
);
1904 dout("req=%p req->r_linger=%d\n", req
, req
->r_linger
);
1905 ceph_osdc_put_request(req
);
1908 mutex_unlock(&osdc
->request_mutex
);
1909 up_read(&osdc
->map_sem
);
1913 req
->r_result
= -EIO
;
1914 __unregister_request(osdc
, req
);
1915 if (req
->r_callback
)
1916 req
->r_callback(req
, msg
);
1918 complete_all(&req
->r_completion
);
1919 complete_request(req
);
1920 ceph_osdc_put_request(req
);
1922 mutex_unlock(&osdc
->request_mutex
);
1923 up_read(&osdc
->map_sem
);
1925 pr_err("corrupt osd_op_reply got %d %d\n",
1926 (int)msg
->front
.iov_len
, le32_to_cpu(msg
->hdr
.front_len
));
1930 static void reset_changed_osds(struct ceph_osd_client
*osdc
)
1932 struct rb_node
*p
, *n
;
1934 for (p
= rb_first(&osdc
->osds
); p
; p
= n
) {
1935 struct ceph_osd
*osd
= rb_entry(p
, struct ceph_osd
, o_node
);
1938 if (!ceph_osd_is_up(osdc
->osdmap
, osd
->o_osd
) ||
1939 memcmp(&osd
->o_con
.peer_addr
,
1940 ceph_osd_addr(osdc
->osdmap
,
1942 sizeof(struct ceph_entity_addr
)) != 0)
1943 __reset_osd(osdc
, osd
);
1948 * Requeue requests whose mapping to an OSD has changed. If requests map to
1949 * no osd, request a new map.
1951 * Caller should hold map_sem for read.
1953 static void kick_requests(struct ceph_osd_client
*osdc
, bool force_resend
,
1954 bool force_resend_writes
)
1956 struct ceph_osd_request
*req
, *nreq
;
1960 bool force_resend_req
;
1962 dout("kick_requests %s %s\n", force_resend
? " (force resend)" : "",
1963 force_resend_writes
? " (force resend writes)" : "");
1964 mutex_lock(&osdc
->request_mutex
);
1965 for (p
= rb_first(&osdc
->requests
); p
; ) {
1966 req
= rb_entry(p
, struct ceph_osd_request
, r_node
);
1970 * For linger requests that have not yet been
1971 * registered, move them to the linger list; they'll
1972 * be sent to the osd in the loop below. Unregister
1973 * the request before re-registering it as a linger
1974 * request to ensure the __map_request() below
1975 * will decide it needs to be sent.
1977 if (req
->r_linger
&& list_empty(&req
->r_linger_item
)) {
1978 dout("%p tid %llu restart on osd%d\n",
1980 req
->r_osd
? req
->r_osd
->o_osd
: -1);
1981 ceph_osdc_get_request(req
);
1982 __unregister_request(osdc
, req
);
1983 __register_linger_request(osdc
, req
);
1984 ceph_osdc_put_request(req
);
1988 force_resend_req
= force_resend
||
1989 (force_resend_writes
&&
1990 req
->r_flags
& CEPH_OSD_FLAG_WRITE
);
1991 err
= __map_request(osdc
, req
, force_resend_req
);
1993 continue; /* error */
1994 if (req
->r_osd
== NULL
) {
1995 dout("%p tid %llu maps to no osd\n", req
, req
->r_tid
);
1996 needmap
++; /* request a newer map */
1997 } else if (err
> 0) {
1998 if (!req
->r_linger
) {
1999 dout("%p tid %llu requeued on osd%d\n", req
,
2001 req
->r_osd
? req
->r_osd
->o_osd
: -1);
2002 req
->r_flags
|= CEPH_OSD_FLAG_RETRY
;
2007 list_for_each_entry_safe(req
, nreq
, &osdc
->req_linger
,
2009 dout("linger req=%p req->r_osd=%p\n", req
, req
->r_osd
);
2011 err
= __map_request(osdc
, req
,
2012 force_resend
|| force_resend_writes
);
2013 dout("__map_request returned %d\n", err
);
2015 continue; /* no change and no osd was specified */
2017 continue; /* hrm! */
2018 if (req
->r_osd
== NULL
) {
2019 dout("tid %llu maps to no valid osd\n", req
->r_tid
);
2020 needmap
++; /* request a newer map */
2024 dout("kicking lingering %p tid %llu osd%d\n", req
, req
->r_tid
,
2025 req
->r_osd
? req
->r_osd
->o_osd
: -1);
2026 __register_request(osdc
, req
);
2027 __unregister_linger_request(osdc
, req
);
2029 reset_changed_osds(osdc
);
2030 mutex_unlock(&osdc
->request_mutex
);
2033 dout("%d requests for down osds, need new map\n", needmap
);
2034 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
2040 * Process updated osd map.
2042 * The message contains any number of incremental and full maps, normally
2043 * indicating some sort of topology change in the cluster. Kick requests
2044 * off to different OSDs as needed.
2046 void ceph_osdc_handle_map(struct ceph_osd_client
*osdc
, struct ceph_msg
*msg
)
2048 void *p
, *end
, *next
;
2049 u32 nr_maps
, maplen
;
2051 struct ceph_osdmap
*newmap
= NULL
, *oldmap
;
2053 struct ceph_fsid fsid
;
2056 dout("handle_map have %u\n", osdc
->osdmap
? osdc
->osdmap
->epoch
: 0);
2057 p
= msg
->front
.iov_base
;
2058 end
= p
+ msg
->front
.iov_len
;
2061 ceph_decode_need(&p
, end
, sizeof(fsid
), bad
);
2062 ceph_decode_copy(&p
, &fsid
, sizeof(fsid
));
2063 if (ceph_check_fsid(osdc
->client
, &fsid
) < 0)
2066 down_write(&osdc
->map_sem
);
2068 was_full
= ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_FULL
);
2070 /* incremental maps */
2071 ceph_decode_32_safe(&p
, end
, nr_maps
, bad
);
2072 dout(" %d inc maps\n", nr_maps
);
2073 while (nr_maps
> 0) {
2074 ceph_decode_need(&p
, end
, 2*sizeof(u32
), bad
);
2075 epoch
= ceph_decode_32(&p
);
2076 maplen
= ceph_decode_32(&p
);
2077 ceph_decode_need(&p
, end
, maplen
, bad
);
2079 if (osdc
->osdmap
&& osdc
->osdmap
->epoch
+1 == epoch
) {
2080 dout("applying incremental map %u len %d\n",
2082 newmap
= osdmap_apply_incremental(&p
, next
,
2084 &osdc
->client
->msgr
);
2085 if (IS_ERR(newmap
)) {
2086 err
= PTR_ERR(newmap
);
2090 if (newmap
!= osdc
->osdmap
) {
2091 ceph_osdmap_destroy(osdc
->osdmap
);
2092 osdc
->osdmap
= newmap
;
2094 was_full
= was_full
||
2095 ceph_osdmap_flag(osdc
->osdmap
,
2097 kick_requests(osdc
, 0, was_full
);
2099 dout("ignoring incremental map %u len %d\n",
2109 ceph_decode_32_safe(&p
, end
, nr_maps
, bad
);
2110 dout(" %d full maps\n", nr_maps
);
2112 ceph_decode_need(&p
, end
, 2*sizeof(u32
), bad
);
2113 epoch
= ceph_decode_32(&p
);
2114 maplen
= ceph_decode_32(&p
);
2115 ceph_decode_need(&p
, end
, maplen
, bad
);
2117 dout("skipping non-latest full map %u len %d\n",
2119 } else if (osdc
->osdmap
&& osdc
->osdmap
->epoch
>= epoch
) {
2120 dout("skipping full map %u len %d, "
2121 "older than our %u\n", epoch
, maplen
,
2122 osdc
->osdmap
->epoch
);
2124 int skipped_map
= 0;
2126 dout("taking full map %u len %d\n", epoch
, maplen
);
2127 newmap
= ceph_osdmap_decode(&p
, p
+maplen
);
2128 if (IS_ERR(newmap
)) {
2129 err
= PTR_ERR(newmap
);
2133 oldmap
= osdc
->osdmap
;
2134 osdc
->osdmap
= newmap
;
2136 if (oldmap
->epoch
+ 1 < newmap
->epoch
)
2138 ceph_osdmap_destroy(oldmap
);
2140 was_full
= was_full
||
2141 ceph_osdmap_flag(osdc
->osdmap
,
2143 kick_requests(osdc
, skipped_map
, was_full
);
2152 downgrade_write(&osdc
->map_sem
);
2153 ceph_monc_got_osdmap(&osdc
->client
->monc
, osdc
->osdmap
->epoch
);
2156 * subscribe to subsequent osdmap updates if full to ensure
2157 * we find out when we are no longer full and stop returning
2160 if (ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_FULL
) ||
2161 ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_PAUSERD
) ||
2162 ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_PAUSEWR
))
2163 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
2165 mutex_lock(&osdc
->request_mutex
);
2166 __send_queued(osdc
);
2167 mutex_unlock(&osdc
->request_mutex
);
2168 up_read(&osdc
->map_sem
);
2169 wake_up_all(&osdc
->client
->auth_wq
);
2173 pr_err("osdc handle_map corrupt msg\n");
2175 up_write(&osdc
->map_sem
);
2179 * watch/notify callback event infrastructure
2181 * These callbacks are used both for watch and notify operations.
2183 static void __release_event(struct kref
*kref
)
2185 struct ceph_osd_event
*event
=
2186 container_of(kref
, struct ceph_osd_event
, kref
);
2188 dout("__release_event %p\n", event
);
2192 static void get_event(struct ceph_osd_event
*event
)
2194 kref_get(&event
->kref
);
2197 void ceph_osdc_put_event(struct ceph_osd_event
*event
)
2199 kref_put(&event
->kref
, __release_event
);
2201 EXPORT_SYMBOL(ceph_osdc_put_event
);
2203 static void __insert_event(struct ceph_osd_client
*osdc
,
2204 struct ceph_osd_event
*new)
2206 struct rb_node
**p
= &osdc
->event_tree
.rb_node
;
2207 struct rb_node
*parent
= NULL
;
2208 struct ceph_osd_event
*event
= NULL
;
2212 event
= rb_entry(parent
, struct ceph_osd_event
, node
);
2213 if (new->cookie
< event
->cookie
)
2215 else if (new->cookie
> event
->cookie
)
2216 p
= &(*p
)->rb_right
;
2221 rb_link_node(&new->node
, parent
, p
);
2222 rb_insert_color(&new->node
, &osdc
->event_tree
);
2225 static struct ceph_osd_event
*__find_event(struct ceph_osd_client
*osdc
,
2228 struct rb_node
**p
= &osdc
->event_tree
.rb_node
;
2229 struct rb_node
*parent
= NULL
;
2230 struct ceph_osd_event
*event
= NULL
;
2234 event
= rb_entry(parent
, struct ceph_osd_event
, node
);
2235 if (cookie
< event
->cookie
)
2237 else if (cookie
> event
->cookie
)
2238 p
= &(*p
)->rb_right
;
2245 static void __remove_event(struct ceph_osd_event
*event
)
2247 struct ceph_osd_client
*osdc
= event
->osdc
;
2249 if (!RB_EMPTY_NODE(&event
->node
)) {
2250 dout("__remove_event removed %p\n", event
);
2251 rb_erase(&event
->node
, &osdc
->event_tree
);
2252 ceph_osdc_put_event(event
);
2254 dout("__remove_event didn't remove %p\n", event
);
2258 int ceph_osdc_create_event(struct ceph_osd_client
*osdc
,
2259 void (*event_cb
)(u64
, u64
, u8
, void *),
2260 void *data
, struct ceph_osd_event
**pevent
)
2262 struct ceph_osd_event
*event
;
2264 event
= kmalloc(sizeof(*event
), GFP_NOIO
);
2268 dout("create_event %p\n", event
);
2269 event
->cb
= event_cb
;
2270 event
->one_shot
= 0;
2273 INIT_LIST_HEAD(&event
->osd_node
);
2274 RB_CLEAR_NODE(&event
->node
);
2275 kref_init(&event
->kref
); /* one ref for us */
2276 kref_get(&event
->kref
); /* one ref for the caller */
2278 spin_lock(&osdc
->event_lock
);
2279 event
->cookie
= ++osdc
->event_count
;
2280 __insert_event(osdc
, event
);
2281 spin_unlock(&osdc
->event_lock
);
2286 EXPORT_SYMBOL(ceph_osdc_create_event
);
2288 void ceph_osdc_cancel_event(struct ceph_osd_event
*event
)
2290 struct ceph_osd_client
*osdc
= event
->osdc
;
2292 dout("cancel_event %p\n", event
);
2293 spin_lock(&osdc
->event_lock
);
2294 __remove_event(event
);
2295 spin_unlock(&osdc
->event_lock
);
2296 ceph_osdc_put_event(event
); /* caller's */
2298 EXPORT_SYMBOL(ceph_osdc_cancel_event
);
2301 static void do_event_work(struct work_struct
*work
)
2303 struct ceph_osd_event_work
*event_work
=
2304 container_of(work
, struct ceph_osd_event_work
, work
);
2305 struct ceph_osd_event
*event
= event_work
->event
;
2306 u64 ver
= event_work
->ver
;
2307 u64 notify_id
= event_work
->notify_id
;
2308 u8 opcode
= event_work
->opcode
;
2310 dout("do_event_work completing %p\n", event
);
2311 event
->cb(ver
, notify_id
, opcode
, event
->data
);
2312 dout("do_event_work completed %p\n", event
);
2313 ceph_osdc_put_event(event
);
2319 * Process osd watch notifications
2321 static void handle_watch_notify(struct ceph_osd_client
*osdc
,
2322 struct ceph_msg
*msg
)
2326 u64 cookie
, ver
, notify_id
;
2328 struct ceph_osd_event
*event
;
2329 struct ceph_osd_event_work
*event_work
;
2331 p
= msg
->front
.iov_base
;
2332 end
= p
+ msg
->front
.iov_len
;
2334 ceph_decode_8_safe(&p
, end
, proto_ver
, bad
);
2335 ceph_decode_8_safe(&p
, end
, opcode
, bad
);
2336 ceph_decode_64_safe(&p
, end
, cookie
, bad
);
2337 ceph_decode_64_safe(&p
, end
, ver
, bad
);
2338 ceph_decode_64_safe(&p
, end
, notify_id
, bad
);
2340 spin_lock(&osdc
->event_lock
);
2341 event
= __find_event(osdc
, cookie
);
2343 BUG_ON(event
->one_shot
);
2346 spin_unlock(&osdc
->event_lock
);
2347 dout("handle_watch_notify cookie %lld ver %lld event %p\n",
2348 cookie
, ver
, event
);
2350 event_work
= kmalloc(sizeof(*event_work
), GFP_NOIO
);
2352 pr_err("couldn't allocate event_work\n");
2353 ceph_osdc_put_event(event
);
2356 INIT_WORK(&event_work
->work
, do_event_work
);
2357 event_work
->event
= event
;
2358 event_work
->ver
= ver
;
2359 event_work
->notify_id
= notify_id
;
2360 event_work
->opcode
= opcode
;
2362 queue_work(osdc
->notify_wq
, &event_work
->work
);
2368 pr_err("osdc handle_watch_notify corrupt msg\n");
2372 * build new request AND message
2375 void ceph_osdc_build_request(struct ceph_osd_request
*req
, u64 off
,
2376 struct ceph_snap_context
*snapc
, u64 snap_id
,
2377 struct timespec
*mtime
)
2379 struct ceph_msg
*msg
= req
->r_request
;
2382 int flags
= req
->r_flags
;
2386 req
->r_snapid
= snap_id
;
2387 req
->r_snapc
= ceph_get_snap_context(snapc
);
2389 /* encode request */
2390 msg
->hdr
.version
= cpu_to_le16(4);
2392 p
= msg
->front
.iov_base
;
2393 ceph_encode_32(&p
, 1); /* client_inc is always 1 */
2394 req
->r_request_osdmap_epoch
= p
;
2396 req
->r_request_flags
= p
;
2398 if (req
->r_flags
& CEPH_OSD_FLAG_WRITE
)
2399 ceph_encode_timespec(p
, mtime
);
2400 p
+= sizeof(struct ceph_timespec
);
2401 req
->r_request_reassert_version
= p
;
2402 p
+= sizeof(struct ceph_eversion
); /* will get filled in */
2405 ceph_encode_8(&p
, 4);
2406 ceph_encode_8(&p
, 4);
2407 ceph_encode_32(&p
, 8 + 4 + 4);
2408 req
->r_request_pool
= p
;
2410 ceph_encode_32(&p
, -1); /* preferred */
2411 ceph_encode_32(&p
, 0); /* key len */
2413 ceph_encode_8(&p
, 1);
2414 req
->r_request_pgid
= p
;
2416 ceph_encode_32(&p
, -1); /* preferred */
2419 ceph_encode_32(&p
, req
->r_base_oid
.name_len
);
2420 memcpy(p
, req
->r_base_oid
.name
, req
->r_base_oid
.name_len
);
2421 dout("oid '%.*s' len %d\n", req
->r_base_oid
.name_len
,
2422 req
->r_base_oid
.name
, req
->r_base_oid
.name_len
);
2423 p
+= req
->r_base_oid
.name_len
;
2425 /* ops--can imply data */
2426 ceph_encode_16(&p
, (u16
)req
->r_num_ops
);
2428 for (i
= 0; i
< req
->r_num_ops
; i
++) {
2429 data_len
+= osd_req_encode_op(req
, p
, i
);
2430 p
+= sizeof(struct ceph_osd_op
);
2434 ceph_encode_64(&p
, req
->r_snapid
);
2435 ceph_encode_64(&p
, req
->r_snapc
? req
->r_snapc
->seq
: 0);
2436 ceph_encode_32(&p
, req
->r_snapc
? req
->r_snapc
->num_snaps
: 0);
2438 for (i
= 0; i
< snapc
->num_snaps
; i
++) {
2439 ceph_encode_64(&p
, req
->r_snapc
->snaps
[i
]);
2443 req
->r_request_attempts
= p
;
2447 if (flags
& CEPH_OSD_FLAG_WRITE
) {
2451 * The header "data_off" is a hint to the receiver
2452 * allowing it to align received data into its
2453 * buffers such that there's no need to re-copy
2454 * it before writing it to disk (direct I/O).
2456 data_off
= (u16
) (off
& 0xffff);
2457 req
->r_request
->hdr
.data_off
= cpu_to_le16(data_off
);
2459 req
->r_request
->hdr
.data_len
= cpu_to_le32(data_len
);
2461 BUG_ON(p
> msg
->front
.iov_base
+ msg
->front
.iov_len
);
2462 msg_size
= p
- msg
->front
.iov_base
;
2463 msg
->front
.iov_len
= msg_size
;
2464 msg
->hdr
.front_len
= cpu_to_le32(msg_size
);
2466 dout("build_request msg_size was %d\n", (int)msg_size
);
2468 EXPORT_SYMBOL(ceph_osdc_build_request
);
2471 * Register request, send initial attempt.
2473 int ceph_osdc_start_request(struct ceph_osd_client
*osdc
,
2474 struct ceph_osd_request
*req
,
2479 down_read(&osdc
->map_sem
);
2480 mutex_lock(&osdc
->request_mutex
);
2482 rc
= __ceph_osdc_start_request(osdc
, req
, nofail
);
2484 mutex_unlock(&osdc
->request_mutex
);
2485 up_read(&osdc
->map_sem
);
2489 EXPORT_SYMBOL(ceph_osdc_start_request
);
2492 * Unregister a registered request. The request is not completed (i.e.
2493 * no callbacks or wakeups) - higher layers are supposed to know what
2494 * they are canceling.
2496 void ceph_osdc_cancel_request(struct ceph_osd_request
*req
)
2498 struct ceph_osd_client
*osdc
= req
->r_osdc
;
2500 mutex_lock(&osdc
->request_mutex
);
2502 __unregister_linger_request(osdc
, req
);
2503 __unregister_request(osdc
, req
);
2504 mutex_unlock(&osdc
->request_mutex
);
2506 dout("%s %p tid %llu canceled\n", __func__
, req
, req
->r_tid
);
2508 EXPORT_SYMBOL(ceph_osdc_cancel_request
);
2511 * wait for a request to complete
2513 int ceph_osdc_wait_request(struct ceph_osd_client
*osdc
,
2514 struct ceph_osd_request
*req
)
2518 dout("%s %p tid %llu\n", __func__
, req
, req
->r_tid
);
2520 rc
= wait_for_completion_interruptible(&req
->r_completion
);
2522 dout("%s %p tid %llu interrupted\n", __func__
, req
, req
->r_tid
);
2523 ceph_osdc_cancel_request(req
);
2524 complete_request(req
);
2528 dout("%s %p tid %llu result %d\n", __func__
, req
, req
->r_tid
,
2530 return req
->r_result
;
2532 EXPORT_SYMBOL(ceph_osdc_wait_request
);
2535 * sync - wait for all in-flight requests to flush. avoid starvation.
2537 void ceph_osdc_sync(struct ceph_osd_client
*osdc
)
2539 struct ceph_osd_request
*req
;
2540 u64 last_tid
, next_tid
= 0;
2542 mutex_lock(&osdc
->request_mutex
);
2543 last_tid
= osdc
->last_tid
;
2545 req
= __lookup_request_ge(osdc
, next_tid
);
2548 if (req
->r_tid
> last_tid
)
2551 next_tid
= req
->r_tid
+ 1;
2552 if ((req
->r_flags
& CEPH_OSD_FLAG_WRITE
) == 0)
2555 ceph_osdc_get_request(req
);
2556 mutex_unlock(&osdc
->request_mutex
);
2557 dout("sync waiting on tid %llu (last is %llu)\n",
2558 req
->r_tid
, last_tid
);
2559 wait_for_completion(&req
->r_safe_completion
);
2560 mutex_lock(&osdc
->request_mutex
);
2561 ceph_osdc_put_request(req
);
2563 mutex_unlock(&osdc
->request_mutex
);
2564 dout("sync done (thru tid %llu)\n", last_tid
);
2566 EXPORT_SYMBOL(ceph_osdc_sync
);
2569 * Call all pending notify callbacks - for use after a watch is
2570 * unregistered, to make sure no more callbacks for it will be invoked
2572 void ceph_osdc_flush_notifies(struct ceph_osd_client
*osdc
)
2574 flush_workqueue(osdc
->notify_wq
);
2576 EXPORT_SYMBOL(ceph_osdc_flush_notifies
);
2582 int ceph_osdc_init(struct ceph_osd_client
*osdc
, struct ceph_client
*client
)
2587 osdc
->client
= client
;
2588 osdc
->osdmap
= NULL
;
2589 init_rwsem(&osdc
->map_sem
);
2590 init_completion(&osdc
->map_waiters
);
2591 osdc
->last_requested_map
= 0;
2592 mutex_init(&osdc
->request_mutex
);
2594 osdc
->osds
= RB_ROOT
;
2595 INIT_LIST_HEAD(&osdc
->osd_lru
);
2596 osdc
->requests
= RB_ROOT
;
2597 INIT_LIST_HEAD(&osdc
->req_lru
);
2598 INIT_LIST_HEAD(&osdc
->req_unsent
);
2599 INIT_LIST_HEAD(&osdc
->req_notarget
);
2600 INIT_LIST_HEAD(&osdc
->req_linger
);
2601 osdc
->num_requests
= 0;
2602 INIT_DELAYED_WORK(&osdc
->timeout_work
, handle_timeout
);
2603 INIT_DELAYED_WORK(&osdc
->osds_timeout_work
, handle_osds_timeout
);
2604 spin_lock_init(&osdc
->event_lock
);
2605 osdc
->event_tree
= RB_ROOT
;
2606 osdc
->event_count
= 0;
2608 schedule_delayed_work(&osdc
->osds_timeout_work
,
2609 round_jiffies_relative(osdc
->client
->options
->osd_idle_ttl
* HZ
));
2612 osdc
->req_mempool
= mempool_create_kmalloc_pool(10,
2613 sizeof(struct ceph_osd_request
));
2614 if (!osdc
->req_mempool
)
2617 err
= ceph_msgpool_init(&osdc
->msgpool_op
, CEPH_MSG_OSD_OP
,
2618 OSD_OP_FRONT_LEN
, 10, true,
2622 err
= ceph_msgpool_init(&osdc
->msgpool_op_reply
, CEPH_MSG_OSD_OPREPLY
,
2623 OSD_OPREPLY_FRONT_LEN
, 10, true,
2629 osdc
->notify_wq
= create_singlethread_workqueue("ceph-watch-notify");
2630 if (!osdc
->notify_wq
)
2631 goto out_msgpool_reply
;
2636 ceph_msgpool_destroy(&osdc
->msgpool_op_reply
);
2638 ceph_msgpool_destroy(&osdc
->msgpool_op
);
2640 mempool_destroy(osdc
->req_mempool
);
2645 void ceph_osdc_stop(struct ceph_osd_client
*osdc
)
2647 flush_workqueue(osdc
->notify_wq
);
2648 destroy_workqueue(osdc
->notify_wq
);
2649 cancel_delayed_work_sync(&osdc
->timeout_work
);
2650 cancel_delayed_work_sync(&osdc
->osds_timeout_work
);
2652 ceph_osdmap_destroy(osdc
->osdmap
);
2653 osdc
->osdmap
= NULL
;
2655 remove_all_osds(osdc
);
2656 mempool_destroy(osdc
->req_mempool
);
2657 ceph_msgpool_destroy(&osdc
->msgpool_op
);
2658 ceph_msgpool_destroy(&osdc
->msgpool_op_reply
);
2662 * Read some contiguous pages. If we cross a stripe boundary, shorten
2663 * *plen. Return number of bytes read, or error.
2665 int ceph_osdc_readpages(struct ceph_osd_client
*osdc
,
2666 struct ceph_vino vino
, struct ceph_file_layout
*layout
,
2668 u32 truncate_seq
, u64 truncate_size
,
2669 struct page
**pages
, int num_pages
, int page_align
)
2671 struct ceph_osd_request
*req
;
2674 dout("readpages on ino %llx.%llx on %llu~%llu\n", vino
.ino
,
2675 vino
.snap
, off
, *plen
);
2676 req
= ceph_osdc_new_request(osdc
, layout
, vino
, off
, plen
, 1,
2677 CEPH_OSD_OP_READ
, CEPH_OSD_FLAG_READ
,
2678 NULL
, truncate_seq
, truncate_size
,
2681 return PTR_ERR(req
);
2683 /* it may be a short read due to an object boundary */
2685 osd_req_op_extent_osd_data_pages(req
, 0,
2686 pages
, *plen
, page_align
, false, false);
2688 dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n",
2689 off
, *plen
, *plen
, page_align
);
2691 ceph_osdc_build_request(req
, off
, NULL
, vino
.snap
, NULL
);
2693 rc
= ceph_osdc_start_request(osdc
, req
, false);
2695 rc
= ceph_osdc_wait_request(osdc
, req
);
2697 ceph_osdc_put_request(req
);
2698 dout("readpages result %d\n", rc
);
2701 EXPORT_SYMBOL(ceph_osdc_readpages
);
2704 * do a synchronous write on N pages
2706 int ceph_osdc_writepages(struct ceph_osd_client
*osdc
, struct ceph_vino vino
,
2707 struct ceph_file_layout
*layout
,
2708 struct ceph_snap_context
*snapc
,
2710 u32 truncate_seq
, u64 truncate_size
,
2711 struct timespec
*mtime
,
2712 struct page
**pages
, int num_pages
)
2714 struct ceph_osd_request
*req
;
2716 int page_align
= off
& ~PAGE_MASK
;
2718 BUG_ON(vino
.snap
!= CEPH_NOSNAP
); /* snapshots aren't writeable */
2719 req
= ceph_osdc_new_request(osdc
, layout
, vino
, off
, &len
, 1,
2721 CEPH_OSD_FLAG_ONDISK
| CEPH_OSD_FLAG_WRITE
,
2722 snapc
, truncate_seq
, truncate_size
,
2725 return PTR_ERR(req
);
2727 /* it may be a short write due to an object boundary */
2728 osd_req_op_extent_osd_data_pages(req
, 0, pages
, len
, page_align
,
2730 dout("writepages %llu~%llu (%llu bytes)\n", off
, len
, len
);
2732 ceph_osdc_build_request(req
, off
, snapc
, CEPH_NOSNAP
, mtime
);
2734 rc
= ceph_osdc_start_request(osdc
, req
, true);
2736 rc
= ceph_osdc_wait_request(osdc
, req
);
2738 ceph_osdc_put_request(req
);
2741 dout("writepages result %d\n", rc
);
2744 EXPORT_SYMBOL(ceph_osdc_writepages
);
2746 int ceph_osdc_setup(void)
2748 BUG_ON(ceph_osd_request_cache
);
2749 ceph_osd_request_cache
= kmem_cache_create("ceph_osd_request",
2750 sizeof (struct ceph_osd_request
),
2751 __alignof__(struct ceph_osd_request
),
2754 return ceph_osd_request_cache
? 0 : -ENOMEM
;
2756 EXPORT_SYMBOL(ceph_osdc_setup
);
2758 void ceph_osdc_cleanup(void)
2760 BUG_ON(!ceph_osd_request_cache
);
2761 kmem_cache_destroy(ceph_osd_request_cache
);
2762 ceph_osd_request_cache
= NULL
;
2764 EXPORT_SYMBOL(ceph_osdc_cleanup
);
2767 * handle incoming message
2769 static void dispatch(struct ceph_connection
*con
, struct ceph_msg
*msg
)
2771 struct ceph_osd
*osd
= con
->private;
2772 struct ceph_osd_client
*osdc
;
2773 int type
= le16_to_cpu(msg
->hdr
.type
);
2780 case CEPH_MSG_OSD_MAP
:
2781 ceph_osdc_handle_map(osdc
, msg
);
2783 case CEPH_MSG_OSD_OPREPLY
:
2784 handle_reply(osdc
, msg
, con
);
2786 case CEPH_MSG_WATCH_NOTIFY
:
2787 handle_watch_notify(osdc
, msg
);
2791 pr_err("received unknown message type %d %s\n", type
,
2792 ceph_msg_type_name(type
));
2799 * lookup and return message for incoming reply. set up reply message
2802 static struct ceph_msg
*get_reply(struct ceph_connection
*con
,
2803 struct ceph_msg_header
*hdr
,
2806 struct ceph_osd
*osd
= con
->private;
2807 struct ceph_osd_client
*osdc
= osd
->o_osdc
;
2809 struct ceph_osd_request
*req
;
2810 int front_len
= le32_to_cpu(hdr
->front_len
);
2811 int data_len
= le32_to_cpu(hdr
->data_len
);
2814 tid
= le64_to_cpu(hdr
->tid
);
2815 mutex_lock(&osdc
->request_mutex
);
2816 req
= __lookup_request(osdc
, tid
);
2820 dout("get_reply unknown tid %llu from osd%d\n", tid
,
2825 if (req
->r_reply
->con
)
2826 dout("%s revoking msg %p from old con %p\n", __func__
,
2827 req
->r_reply
, req
->r_reply
->con
);
2828 ceph_msg_revoke_incoming(req
->r_reply
);
2830 if (front_len
> req
->r_reply
->front_alloc_len
) {
2831 pr_warn("get_reply front %d > preallocated %d (%u#%llu)\n",
2832 front_len
, req
->r_reply
->front_alloc_len
,
2833 (unsigned int)con
->peer_name
.type
,
2834 le64_to_cpu(con
->peer_name
.num
));
2835 m
= ceph_msg_new(CEPH_MSG_OSD_OPREPLY
, front_len
, GFP_NOFS
,
2839 ceph_msg_put(req
->r_reply
);
2842 m
= ceph_msg_get(req
->r_reply
);
2845 struct ceph_osd_data
*osd_data
;
2848 * XXX This is assuming there is only one op containing
2849 * XXX page data. Probably OK for reads, but this
2850 * XXX ought to be done more generally.
2852 osd_data
= osd_req_op_extent_osd_data(req
, 0);
2853 if (osd_data
->type
== CEPH_OSD_DATA_TYPE_PAGES
) {
2854 if (osd_data
->pages
&&
2855 unlikely(osd_data
->length
< data_len
)) {
2857 pr_warn("tid %lld reply has %d bytes we had only %llu bytes ready\n",
2858 tid
, data_len
, osd_data
->length
);
2867 dout("get_reply tid %lld %p\n", tid
, m
);
2870 mutex_unlock(&osdc
->request_mutex
);
2875 static struct ceph_msg
*alloc_msg(struct ceph_connection
*con
,
2876 struct ceph_msg_header
*hdr
,
2879 struct ceph_osd
*osd
= con
->private;
2880 int type
= le16_to_cpu(hdr
->type
);
2881 int front
= le32_to_cpu(hdr
->front_len
);
2885 case CEPH_MSG_OSD_MAP
:
2886 case CEPH_MSG_WATCH_NOTIFY
:
2887 return ceph_msg_new(type
, front
, GFP_NOFS
, false);
2888 case CEPH_MSG_OSD_OPREPLY
:
2889 return get_reply(con
, hdr
, skip
);
2891 pr_info("alloc_msg unexpected msg type %d from osd%d\n", type
,
2899 * Wrappers to refcount containing ceph_osd struct
2901 static struct ceph_connection
*get_osd_con(struct ceph_connection
*con
)
2903 struct ceph_osd
*osd
= con
->private;
2909 static void put_osd_con(struct ceph_connection
*con
)
2911 struct ceph_osd
*osd
= con
->private;
2919 * Note: returned pointer is the address of a structure that's
2920 * managed separately. Caller must *not* attempt to free it.
2922 static struct ceph_auth_handshake
*get_authorizer(struct ceph_connection
*con
,
2923 int *proto
, int force_new
)
2925 struct ceph_osd
*o
= con
->private;
2926 struct ceph_osd_client
*osdc
= o
->o_osdc
;
2927 struct ceph_auth_client
*ac
= osdc
->client
->monc
.auth
;
2928 struct ceph_auth_handshake
*auth
= &o
->o_auth
;
2930 if (force_new
&& auth
->authorizer
) {
2931 ceph_auth_destroy_authorizer(ac
, auth
->authorizer
);
2932 auth
->authorizer
= NULL
;
2934 if (!auth
->authorizer
) {
2935 int ret
= ceph_auth_create_authorizer(ac
, CEPH_ENTITY_TYPE_OSD
,
2938 return ERR_PTR(ret
);
2940 int ret
= ceph_auth_update_authorizer(ac
, CEPH_ENTITY_TYPE_OSD
,
2943 return ERR_PTR(ret
);
2945 *proto
= ac
->protocol
;
2951 static int verify_authorizer_reply(struct ceph_connection
*con
, int len
)
2953 struct ceph_osd
*o
= con
->private;
2954 struct ceph_osd_client
*osdc
= o
->o_osdc
;
2955 struct ceph_auth_client
*ac
= osdc
->client
->monc
.auth
;
2957 return ceph_auth_verify_authorizer_reply(ac
, o
->o_auth
.authorizer
, len
);
2960 static int invalidate_authorizer(struct ceph_connection
*con
)
2962 struct ceph_osd
*o
= con
->private;
2963 struct ceph_osd_client
*osdc
= o
->o_osdc
;
2964 struct ceph_auth_client
*ac
= osdc
->client
->monc
.auth
;
2966 ceph_auth_invalidate_authorizer(ac
, CEPH_ENTITY_TYPE_OSD
);
2967 return ceph_monc_validate_auth(&osdc
->client
->monc
);
2970 static int sign_message(struct ceph_connection
*con
, struct ceph_msg
*msg
)
2972 struct ceph_osd
*o
= con
->private;
2973 struct ceph_auth_handshake
*auth
= &o
->o_auth
;
2974 return ceph_auth_sign_message(auth
, msg
);
2977 static int check_message_signature(struct ceph_connection
*con
, struct ceph_msg
*msg
)
2979 struct ceph_osd
*o
= con
->private;
2980 struct ceph_auth_handshake
*auth
= &o
->o_auth
;
2981 return ceph_auth_check_message_signature(auth
, msg
);
2984 static const struct ceph_connection_operations osd_con_ops
= {
2987 .dispatch
= dispatch
,
2988 .get_authorizer
= get_authorizer
,
2989 .verify_authorizer_reply
= verify_authorizer_reply
,
2990 .invalidate_authorizer
= invalidate_authorizer
,
2991 .alloc_msg
= alloc_msg
,
2992 .sign_message
= sign_message
,
2993 .check_message_signature
= check_message_signature
,