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_linger_request(struct ceph_osd_client
*osdc
,
34 struct ceph_osd_request
*req
);
35 static void __send_request(struct ceph_osd_client
*osdc
,
36 struct ceph_osd_request
*req
);
39 * Implement client access to distributed object storage cluster.
41 * All data objects are stored within a cluster/cloud of OSDs, or
42 * "object storage devices." (Note that Ceph OSDs have _nothing_ to
43 * do with the T10 OSD extensions to SCSI.) Ceph OSDs are simply
44 * remote daemons serving up and coordinating consistent and safe
47 * Cluster membership and the mapping of data objects onto storage devices
48 * are described by the osd map.
50 * We keep track of pending OSD requests (read, write), resubmit
51 * requests to different OSDs when the cluster topology/data layout
52 * change, or retry the affected requests when the communications
53 * channel with an OSD is reset.
57 * calculate the mapping of a file extent onto an object, and fill out the
58 * request accordingly. shorten extent as necessary if it crosses an
61 * fill osd op in request message.
63 static int calc_layout(struct ceph_file_layout
*layout
, u64 off
, u64
*plen
,
64 u64
*objnum
, u64
*objoff
, u64
*objlen
)
70 r
= ceph_calc_file_object_mapping(layout
, off
, orig_len
, objnum
,
74 if (*objlen
< orig_len
) {
76 dout(" skipping last %llu, final file extent %llu~%llu\n",
77 orig_len
- *plen
, off
, *plen
);
80 dout("calc_layout objnum=%llx %llu~%llu\n", *objnum
, *objoff
, *objlen
);
85 static void ceph_osd_data_init(struct ceph_osd_data
*osd_data
)
87 memset(osd_data
, 0, sizeof (*osd_data
));
88 osd_data
->type
= CEPH_OSD_DATA_TYPE_NONE
;
91 static void ceph_osd_data_pages_init(struct ceph_osd_data
*osd_data
,
92 struct page
**pages
, u64 length
, u32 alignment
,
93 bool pages_from_pool
, bool own_pages
)
95 osd_data
->type
= CEPH_OSD_DATA_TYPE_PAGES
;
96 osd_data
->pages
= pages
;
97 osd_data
->length
= length
;
98 osd_data
->alignment
= alignment
;
99 osd_data
->pages_from_pool
= pages_from_pool
;
100 osd_data
->own_pages
= own_pages
;
103 static void ceph_osd_data_pagelist_init(struct ceph_osd_data
*osd_data
,
104 struct ceph_pagelist
*pagelist
)
106 osd_data
->type
= CEPH_OSD_DATA_TYPE_PAGELIST
;
107 osd_data
->pagelist
= pagelist
;
111 static void ceph_osd_data_bio_init(struct ceph_osd_data
*osd_data
,
112 struct bio
*bio
, size_t bio_length
)
114 osd_data
->type
= CEPH_OSD_DATA_TYPE_BIO
;
116 osd_data
->bio_length
= bio_length
;
118 #endif /* CONFIG_BLOCK */
120 #define osd_req_op_data(oreq, whch, typ, fld) \
122 BUG_ON(whch >= (oreq)->r_num_ops); \
123 &(oreq)->r_ops[whch].typ.fld; \
126 static struct ceph_osd_data
*
127 osd_req_op_raw_data_in(struct ceph_osd_request
*osd_req
, unsigned int which
)
129 BUG_ON(which
>= osd_req
->r_num_ops
);
131 return &osd_req
->r_ops
[which
].raw_data_in
;
134 struct ceph_osd_data
*
135 osd_req_op_extent_osd_data(struct ceph_osd_request
*osd_req
,
138 return osd_req_op_data(osd_req
, which
, extent
, osd_data
);
140 EXPORT_SYMBOL(osd_req_op_extent_osd_data
);
142 struct ceph_osd_data
*
143 osd_req_op_cls_response_data(struct ceph_osd_request
*osd_req
,
146 return osd_req_op_data(osd_req
, which
, cls
, response_data
);
148 EXPORT_SYMBOL(osd_req_op_cls_response_data
); /* ??? */
150 void osd_req_op_raw_data_in_pages(struct ceph_osd_request
*osd_req
,
151 unsigned int which
, struct page
**pages
,
152 u64 length
, u32 alignment
,
153 bool pages_from_pool
, bool own_pages
)
155 struct ceph_osd_data
*osd_data
;
157 osd_data
= osd_req_op_raw_data_in(osd_req
, which
);
158 ceph_osd_data_pages_init(osd_data
, pages
, length
, alignment
,
159 pages_from_pool
, own_pages
);
161 EXPORT_SYMBOL(osd_req_op_raw_data_in_pages
);
163 void osd_req_op_extent_osd_data_pages(struct ceph_osd_request
*osd_req
,
164 unsigned int which
, struct page
**pages
,
165 u64 length
, u32 alignment
,
166 bool pages_from_pool
, bool own_pages
)
168 struct ceph_osd_data
*osd_data
;
170 osd_data
= osd_req_op_data(osd_req
, which
, extent
, osd_data
);
171 ceph_osd_data_pages_init(osd_data
, pages
, length
, alignment
,
172 pages_from_pool
, own_pages
);
174 EXPORT_SYMBOL(osd_req_op_extent_osd_data_pages
);
176 void osd_req_op_extent_osd_data_pagelist(struct ceph_osd_request
*osd_req
,
177 unsigned int which
, struct ceph_pagelist
*pagelist
)
179 struct ceph_osd_data
*osd_data
;
181 osd_data
= osd_req_op_data(osd_req
, which
, extent
, osd_data
);
182 ceph_osd_data_pagelist_init(osd_data
, pagelist
);
184 EXPORT_SYMBOL(osd_req_op_extent_osd_data_pagelist
);
187 void osd_req_op_extent_osd_data_bio(struct ceph_osd_request
*osd_req
,
188 unsigned int which
, struct bio
*bio
, size_t bio_length
)
190 struct ceph_osd_data
*osd_data
;
192 osd_data
= osd_req_op_data(osd_req
, which
, extent
, osd_data
);
193 ceph_osd_data_bio_init(osd_data
, bio
, bio_length
);
195 EXPORT_SYMBOL(osd_req_op_extent_osd_data_bio
);
196 #endif /* CONFIG_BLOCK */
198 static void osd_req_op_cls_request_info_pagelist(
199 struct ceph_osd_request
*osd_req
,
200 unsigned int which
, struct ceph_pagelist
*pagelist
)
202 struct ceph_osd_data
*osd_data
;
204 osd_data
= osd_req_op_data(osd_req
, which
, cls
, request_info
);
205 ceph_osd_data_pagelist_init(osd_data
, pagelist
);
208 void osd_req_op_cls_request_data_pagelist(
209 struct ceph_osd_request
*osd_req
,
210 unsigned int which
, struct ceph_pagelist
*pagelist
)
212 struct ceph_osd_data
*osd_data
;
214 osd_data
= osd_req_op_data(osd_req
, which
, cls
, request_data
);
215 ceph_osd_data_pagelist_init(osd_data
, pagelist
);
217 EXPORT_SYMBOL(osd_req_op_cls_request_data_pagelist
);
219 void osd_req_op_cls_request_data_pages(struct ceph_osd_request
*osd_req
,
220 unsigned int which
, struct page
**pages
, u64 length
,
221 u32 alignment
, bool pages_from_pool
, bool own_pages
)
223 struct ceph_osd_data
*osd_data
;
225 osd_data
= osd_req_op_data(osd_req
, which
, cls
, request_data
);
226 ceph_osd_data_pages_init(osd_data
, pages
, length
, alignment
,
227 pages_from_pool
, own_pages
);
229 EXPORT_SYMBOL(osd_req_op_cls_request_data_pages
);
231 void osd_req_op_cls_response_data_pages(struct ceph_osd_request
*osd_req
,
232 unsigned int which
, struct page
**pages
, u64 length
,
233 u32 alignment
, bool pages_from_pool
, bool own_pages
)
235 struct ceph_osd_data
*osd_data
;
237 osd_data
= osd_req_op_data(osd_req
, which
, cls
, response_data
);
238 ceph_osd_data_pages_init(osd_data
, pages
, length
, alignment
,
239 pages_from_pool
, own_pages
);
241 EXPORT_SYMBOL(osd_req_op_cls_response_data_pages
);
243 static u64
ceph_osd_data_length(struct ceph_osd_data
*osd_data
)
245 switch (osd_data
->type
) {
246 case CEPH_OSD_DATA_TYPE_NONE
:
248 case CEPH_OSD_DATA_TYPE_PAGES
:
249 return osd_data
->length
;
250 case CEPH_OSD_DATA_TYPE_PAGELIST
:
251 return (u64
)osd_data
->pagelist
->length
;
253 case CEPH_OSD_DATA_TYPE_BIO
:
254 return (u64
)osd_data
->bio_length
;
255 #endif /* CONFIG_BLOCK */
257 WARN(true, "unrecognized data type %d\n", (int)osd_data
->type
);
262 static void ceph_osd_data_release(struct ceph_osd_data
*osd_data
)
264 if (osd_data
->type
== CEPH_OSD_DATA_TYPE_PAGES
&& osd_data
->own_pages
) {
267 num_pages
= calc_pages_for((u64
)osd_data
->alignment
,
268 (u64
)osd_data
->length
);
269 ceph_release_page_vector(osd_data
->pages
, num_pages
);
271 ceph_osd_data_init(osd_data
);
274 static void osd_req_op_data_release(struct ceph_osd_request
*osd_req
,
277 struct ceph_osd_req_op
*op
;
279 BUG_ON(which
>= osd_req
->r_num_ops
);
280 op
= &osd_req
->r_ops
[which
];
283 case CEPH_OSD_OP_READ
:
284 case CEPH_OSD_OP_WRITE
:
285 ceph_osd_data_release(&op
->extent
.osd_data
);
287 case CEPH_OSD_OP_CALL
:
288 ceph_osd_data_release(&op
->cls
.request_info
);
289 ceph_osd_data_release(&op
->cls
.request_data
);
290 ceph_osd_data_release(&op
->cls
.response_data
);
300 void ceph_osdc_release_request(struct kref
*kref
)
302 struct ceph_osd_request
*req
;
305 req
= container_of(kref
, struct ceph_osd_request
, r_kref
);
307 ceph_msg_put(req
->r_request
);
309 ceph_msg_revoke_incoming(req
->r_reply
);
310 ceph_msg_put(req
->r_reply
);
313 for (which
= 0; which
< req
->r_num_ops
; which
++)
314 osd_req_op_data_release(req
, which
);
316 ceph_put_snap_context(req
->r_snapc
);
318 mempool_free(req
, req
->r_osdc
->req_mempool
);
320 kmem_cache_free(ceph_osd_request_cache
, req
);
323 EXPORT_SYMBOL(ceph_osdc_release_request
);
325 struct ceph_osd_request
*ceph_osdc_alloc_request(struct ceph_osd_client
*osdc
,
326 struct ceph_snap_context
*snapc
,
327 unsigned int num_ops
,
331 struct ceph_osd_request
*req
;
332 struct ceph_msg
*msg
;
335 BUILD_BUG_ON(CEPH_OSD_MAX_OP
> U16_MAX
);
336 BUG_ON(num_ops
> CEPH_OSD_MAX_OP
);
338 msg_size
= 4 + 4 + 8 + 8 + 4+8;
339 msg_size
+= 2 + 4 + 8 + 4 + 4; /* oloc */
340 msg_size
+= 1 + 8 + 4 + 4; /* pg_t */
341 msg_size
+= 4 + CEPH_MAX_OID_NAME_LEN
; /* oid */
342 msg_size
+= 2 + num_ops
*sizeof(struct ceph_osd_op
);
343 msg_size
+= 8; /* snapid */
344 msg_size
+= 8; /* snap_seq */
345 msg_size
+= 8 * (snapc
? snapc
->num_snaps
: 0); /* snaps */
349 req
= mempool_alloc(osdc
->req_mempool
, gfp_flags
);
350 memset(req
, 0, sizeof(*req
));
352 req
= kmem_cache_zalloc(ceph_osd_request_cache
, gfp_flags
);
358 req
->r_mempool
= use_mempool
;
359 req
->r_num_ops
= num_ops
;
361 kref_init(&req
->r_kref
);
362 init_completion(&req
->r_completion
);
363 init_completion(&req
->r_safe_completion
);
364 RB_CLEAR_NODE(&req
->r_node
);
365 INIT_LIST_HEAD(&req
->r_unsafe_item
);
366 INIT_LIST_HEAD(&req
->r_linger_item
);
367 INIT_LIST_HEAD(&req
->r_linger_osd
);
368 INIT_LIST_HEAD(&req
->r_req_lru_item
);
369 INIT_LIST_HEAD(&req
->r_osd_item
);
371 req
->r_base_oloc
.pool
= -1;
372 req
->r_target_oloc
.pool
= -1;
374 /* create reply message */
376 msg
= ceph_msgpool_get(&osdc
->msgpool_op_reply
, 0);
378 msg
= ceph_msg_new(CEPH_MSG_OSD_OPREPLY
,
379 OSD_OPREPLY_FRONT_LEN
, gfp_flags
, true);
381 ceph_osdc_put_request(req
);
386 /* create request message; allow space for oid */
388 msg
= ceph_msgpool_get(&osdc
->msgpool_op
, 0);
390 msg
= ceph_msg_new(CEPH_MSG_OSD_OP
, msg_size
, gfp_flags
, true);
392 ceph_osdc_put_request(req
);
396 memset(msg
->front
.iov_base
, 0, msg
->front
.iov_len
);
398 req
->r_request
= msg
;
402 EXPORT_SYMBOL(ceph_osdc_alloc_request
);
404 static bool osd_req_opcode_valid(u16 opcode
)
407 case CEPH_OSD_OP_READ
:
408 case CEPH_OSD_OP_STAT
:
409 case CEPH_OSD_OP_MAPEXT
:
410 case CEPH_OSD_OP_MASKTRUNC
:
411 case CEPH_OSD_OP_SPARSE_READ
:
412 case CEPH_OSD_OP_NOTIFY
:
413 case CEPH_OSD_OP_NOTIFY_ACK
:
414 case CEPH_OSD_OP_ASSERT_VER
:
415 case CEPH_OSD_OP_WRITE
:
416 case CEPH_OSD_OP_WRITEFULL
:
417 case CEPH_OSD_OP_TRUNCATE
:
418 case CEPH_OSD_OP_ZERO
:
419 case CEPH_OSD_OP_DELETE
:
420 case CEPH_OSD_OP_APPEND
:
421 case CEPH_OSD_OP_STARTSYNC
:
422 case CEPH_OSD_OP_SETTRUNC
:
423 case CEPH_OSD_OP_TRIMTRUNC
:
424 case CEPH_OSD_OP_TMAPUP
:
425 case CEPH_OSD_OP_TMAPPUT
:
426 case CEPH_OSD_OP_TMAPGET
:
427 case CEPH_OSD_OP_CREATE
:
428 case CEPH_OSD_OP_ROLLBACK
:
429 case CEPH_OSD_OP_WATCH
:
430 case CEPH_OSD_OP_OMAPGETKEYS
:
431 case CEPH_OSD_OP_OMAPGETVALS
:
432 case CEPH_OSD_OP_OMAPGETHEADER
:
433 case CEPH_OSD_OP_OMAPGETVALSBYKEYS
:
434 case CEPH_OSD_OP_OMAPSETVALS
:
435 case CEPH_OSD_OP_OMAPSETHEADER
:
436 case CEPH_OSD_OP_OMAPCLEAR
:
437 case CEPH_OSD_OP_OMAPRMKEYS
:
438 case CEPH_OSD_OP_OMAP_CMP
:
439 case CEPH_OSD_OP_SETALLOCHINT
:
440 case CEPH_OSD_OP_CLONERANGE
:
441 case CEPH_OSD_OP_ASSERT_SRC_VERSION
:
442 case CEPH_OSD_OP_SRC_CMPXATTR
:
443 case CEPH_OSD_OP_GETXATTR
:
444 case CEPH_OSD_OP_GETXATTRS
:
445 case CEPH_OSD_OP_CMPXATTR
:
446 case CEPH_OSD_OP_SETXATTR
:
447 case CEPH_OSD_OP_SETXATTRS
:
448 case CEPH_OSD_OP_RESETXATTRS
:
449 case CEPH_OSD_OP_RMXATTR
:
450 case CEPH_OSD_OP_PULL
:
451 case CEPH_OSD_OP_PUSH
:
452 case CEPH_OSD_OP_BALANCEREADS
:
453 case CEPH_OSD_OP_UNBALANCEREADS
:
454 case CEPH_OSD_OP_SCRUB
:
455 case CEPH_OSD_OP_SCRUB_RESERVE
:
456 case CEPH_OSD_OP_SCRUB_UNRESERVE
:
457 case CEPH_OSD_OP_SCRUB_STOP
:
458 case CEPH_OSD_OP_SCRUB_MAP
:
459 case CEPH_OSD_OP_WRLOCK
:
460 case CEPH_OSD_OP_WRUNLOCK
:
461 case CEPH_OSD_OP_RDLOCK
:
462 case CEPH_OSD_OP_RDUNLOCK
:
463 case CEPH_OSD_OP_UPLOCK
:
464 case CEPH_OSD_OP_DNLOCK
:
465 case CEPH_OSD_OP_CALL
:
466 case CEPH_OSD_OP_PGLS
:
467 case CEPH_OSD_OP_PGLS_FILTER
:
475 * This is an osd op init function for opcodes that have no data or
476 * other information associated with them. It also serves as a
477 * common init routine for all the other init functions, below.
479 static struct ceph_osd_req_op
*
480 _osd_req_op_init(struct ceph_osd_request
*osd_req
, unsigned int which
,
483 struct ceph_osd_req_op
*op
;
485 BUG_ON(which
>= osd_req
->r_num_ops
);
486 BUG_ON(!osd_req_opcode_valid(opcode
));
488 op
= &osd_req
->r_ops
[which
];
489 memset(op
, 0, sizeof (*op
));
495 void osd_req_op_init(struct ceph_osd_request
*osd_req
,
496 unsigned int which
, u16 opcode
)
498 (void)_osd_req_op_init(osd_req
, which
, opcode
);
500 EXPORT_SYMBOL(osd_req_op_init
);
502 void osd_req_op_extent_init(struct ceph_osd_request
*osd_req
,
503 unsigned int which
, u16 opcode
,
504 u64 offset
, u64 length
,
505 u64 truncate_size
, u32 truncate_seq
)
507 struct ceph_osd_req_op
*op
= _osd_req_op_init(osd_req
, which
, opcode
);
508 size_t payload_len
= 0;
510 BUG_ON(opcode
!= CEPH_OSD_OP_READ
&& opcode
!= CEPH_OSD_OP_WRITE
&&
511 opcode
!= CEPH_OSD_OP_DELETE
&& opcode
!= CEPH_OSD_OP_ZERO
&&
512 opcode
!= CEPH_OSD_OP_TRUNCATE
);
514 op
->extent
.offset
= offset
;
515 op
->extent
.length
= length
;
516 op
->extent
.truncate_size
= truncate_size
;
517 op
->extent
.truncate_seq
= truncate_seq
;
518 if (opcode
== CEPH_OSD_OP_WRITE
)
519 payload_len
+= length
;
521 op
->payload_len
= payload_len
;
523 EXPORT_SYMBOL(osd_req_op_extent_init
);
525 void osd_req_op_extent_update(struct ceph_osd_request
*osd_req
,
526 unsigned int which
, u64 length
)
528 struct ceph_osd_req_op
*op
;
531 BUG_ON(which
>= osd_req
->r_num_ops
);
532 op
= &osd_req
->r_ops
[which
];
533 previous
= op
->extent
.length
;
535 if (length
== previous
)
536 return; /* Nothing to do */
537 BUG_ON(length
> previous
);
539 op
->extent
.length
= length
;
540 op
->payload_len
-= previous
- length
;
542 EXPORT_SYMBOL(osd_req_op_extent_update
);
544 void osd_req_op_cls_init(struct ceph_osd_request
*osd_req
, unsigned int which
,
545 u16 opcode
, const char *class, const char *method
)
547 struct ceph_osd_req_op
*op
= _osd_req_op_init(osd_req
, which
, opcode
);
548 struct ceph_pagelist
*pagelist
;
549 size_t payload_len
= 0;
552 BUG_ON(opcode
!= CEPH_OSD_OP_CALL
);
554 pagelist
= kmalloc(sizeof (*pagelist
), GFP_NOFS
);
556 ceph_pagelist_init(pagelist
);
558 op
->cls
.class_name
= class;
559 size
= strlen(class);
560 BUG_ON(size
> (size_t) U8_MAX
);
561 op
->cls
.class_len
= size
;
562 ceph_pagelist_append(pagelist
, class, size
);
565 op
->cls
.method_name
= method
;
566 size
= strlen(method
);
567 BUG_ON(size
> (size_t) U8_MAX
);
568 op
->cls
.method_len
= size
;
569 ceph_pagelist_append(pagelist
, method
, size
);
572 osd_req_op_cls_request_info_pagelist(osd_req
, which
, pagelist
);
574 op
->cls
.argc
= 0; /* currently unused */
576 op
->payload_len
= payload_len
;
578 EXPORT_SYMBOL(osd_req_op_cls_init
);
580 void osd_req_op_watch_init(struct ceph_osd_request
*osd_req
,
581 unsigned int which
, u16 opcode
,
582 u64 cookie
, u64 version
, int flag
)
584 struct ceph_osd_req_op
*op
= _osd_req_op_init(osd_req
, which
, opcode
);
586 BUG_ON(opcode
!= CEPH_OSD_OP_NOTIFY_ACK
&& opcode
!= CEPH_OSD_OP_WATCH
);
588 op
->watch
.cookie
= cookie
;
589 op
->watch
.ver
= version
;
590 if (opcode
== CEPH_OSD_OP_WATCH
&& flag
)
591 op
->watch
.flag
= (u8
)1;
593 EXPORT_SYMBOL(osd_req_op_watch_init
);
595 void osd_req_op_alloc_hint_init(struct ceph_osd_request
*osd_req
,
597 u64 expected_object_size
,
598 u64 expected_write_size
)
600 struct ceph_osd_req_op
*op
= _osd_req_op_init(osd_req
, which
,
601 CEPH_OSD_OP_SETALLOCHINT
);
603 op
->alloc_hint
.expected_object_size
= expected_object_size
;
604 op
->alloc_hint
.expected_write_size
= expected_write_size
;
607 * CEPH_OSD_OP_SETALLOCHINT op is advisory and therefore deemed
608 * not worth a feature bit. Set FAILOK per-op flag to make
609 * sure older osds don't trip over an unsupported opcode.
611 op
->flags
|= CEPH_OSD_OP_FLAG_FAILOK
;
613 EXPORT_SYMBOL(osd_req_op_alloc_hint_init
);
615 static void ceph_osdc_msg_data_add(struct ceph_msg
*msg
,
616 struct ceph_osd_data
*osd_data
)
618 u64 length
= ceph_osd_data_length(osd_data
);
620 if (osd_data
->type
== CEPH_OSD_DATA_TYPE_PAGES
) {
621 BUG_ON(length
> (u64
) SIZE_MAX
);
623 ceph_msg_data_add_pages(msg
, osd_data
->pages
,
624 length
, osd_data
->alignment
);
625 } else if (osd_data
->type
== CEPH_OSD_DATA_TYPE_PAGELIST
) {
627 ceph_msg_data_add_pagelist(msg
, osd_data
->pagelist
);
629 } else if (osd_data
->type
== CEPH_OSD_DATA_TYPE_BIO
) {
630 ceph_msg_data_add_bio(msg
, osd_data
->bio
, length
);
633 BUG_ON(osd_data
->type
!= CEPH_OSD_DATA_TYPE_NONE
);
637 static u64
osd_req_encode_op(struct ceph_osd_request
*req
,
638 struct ceph_osd_op
*dst
, unsigned int which
)
640 struct ceph_osd_req_op
*src
;
641 struct ceph_osd_data
*osd_data
;
642 u64 request_data_len
= 0;
645 BUG_ON(which
>= req
->r_num_ops
);
646 src
= &req
->r_ops
[which
];
647 if (WARN_ON(!osd_req_opcode_valid(src
->op
))) {
648 pr_err("unrecognized osd opcode %d\n", src
->op
);
654 case CEPH_OSD_OP_STAT
:
655 osd_data
= &src
->raw_data_in
;
656 ceph_osdc_msg_data_add(req
->r_reply
, osd_data
);
658 case CEPH_OSD_OP_READ
:
659 case CEPH_OSD_OP_WRITE
:
660 case CEPH_OSD_OP_ZERO
:
661 case CEPH_OSD_OP_DELETE
:
662 case CEPH_OSD_OP_TRUNCATE
:
663 if (src
->op
== CEPH_OSD_OP_WRITE
)
664 request_data_len
= src
->extent
.length
;
665 dst
->extent
.offset
= cpu_to_le64(src
->extent
.offset
);
666 dst
->extent
.length
= cpu_to_le64(src
->extent
.length
);
667 dst
->extent
.truncate_size
=
668 cpu_to_le64(src
->extent
.truncate_size
);
669 dst
->extent
.truncate_seq
=
670 cpu_to_le32(src
->extent
.truncate_seq
);
671 osd_data
= &src
->extent
.osd_data
;
672 if (src
->op
== CEPH_OSD_OP_WRITE
)
673 ceph_osdc_msg_data_add(req
->r_request
, osd_data
);
675 ceph_osdc_msg_data_add(req
->r_reply
, osd_data
);
677 case CEPH_OSD_OP_CALL
:
678 dst
->cls
.class_len
= src
->cls
.class_len
;
679 dst
->cls
.method_len
= src
->cls
.method_len
;
680 osd_data
= &src
->cls
.request_info
;
681 ceph_osdc_msg_data_add(req
->r_request
, osd_data
);
682 BUG_ON(osd_data
->type
!= CEPH_OSD_DATA_TYPE_PAGELIST
);
683 request_data_len
= osd_data
->pagelist
->length
;
685 osd_data
= &src
->cls
.request_data
;
686 data_length
= ceph_osd_data_length(osd_data
);
688 BUG_ON(osd_data
->type
== CEPH_OSD_DATA_TYPE_NONE
);
689 dst
->cls
.indata_len
= cpu_to_le32(data_length
);
690 ceph_osdc_msg_data_add(req
->r_request
, osd_data
);
691 src
->payload_len
+= data_length
;
692 request_data_len
+= data_length
;
694 osd_data
= &src
->cls
.response_data
;
695 ceph_osdc_msg_data_add(req
->r_reply
, osd_data
);
697 case CEPH_OSD_OP_STARTSYNC
:
699 case CEPH_OSD_OP_NOTIFY_ACK
:
700 case CEPH_OSD_OP_WATCH
:
701 dst
->watch
.cookie
= cpu_to_le64(src
->watch
.cookie
);
702 dst
->watch
.ver
= cpu_to_le64(src
->watch
.ver
);
703 dst
->watch
.flag
= src
->watch
.flag
;
705 case CEPH_OSD_OP_SETALLOCHINT
:
706 dst
->alloc_hint
.expected_object_size
=
707 cpu_to_le64(src
->alloc_hint
.expected_object_size
);
708 dst
->alloc_hint
.expected_write_size
=
709 cpu_to_le64(src
->alloc_hint
.expected_write_size
);
712 pr_err("unsupported osd opcode %s\n",
713 ceph_osd_op_name(src
->op
));
719 dst
->op
= cpu_to_le16(src
->op
);
720 dst
->flags
= cpu_to_le32(src
->flags
);
721 dst
->payload_len
= cpu_to_le32(src
->payload_len
);
723 return request_data_len
;
727 * build new request AND message, calculate layout, and adjust file
730 * if the file was recently truncated, we include information about its
731 * old and new size so that the object can be updated appropriately. (we
732 * avoid synchronously deleting truncated objects because it's slow.)
734 * if @do_sync, include a 'startsync' command so that the osd will flush
737 struct ceph_osd_request
*ceph_osdc_new_request(struct ceph_osd_client
*osdc
,
738 struct ceph_file_layout
*layout
,
739 struct ceph_vino vino
,
740 u64 off
, u64
*plen
, int num_ops
,
741 int opcode
, int flags
,
742 struct ceph_snap_context
*snapc
,
747 struct ceph_osd_request
*req
;
755 BUG_ON(opcode
!= CEPH_OSD_OP_READ
&& opcode
!= CEPH_OSD_OP_WRITE
&&
756 opcode
!= CEPH_OSD_OP_DELETE
&& opcode
!= CEPH_OSD_OP_ZERO
&&
757 opcode
!= CEPH_OSD_OP_TRUNCATE
);
759 req
= ceph_osdc_alloc_request(osdc
, snapc
, num_ops
, use_mempool
,
762 return ERR_PTR(-ENOMEM
);
764 req
->r_flags
= flags
;
766 /* calculate max write size */
767 r
= calc_layout(layout
, off
, plen
, &objnum
, &objoff
, &objlen
);
769 ceph_osdc_put_request(req
);
773 object_size
= le32_to_cpu(layout
->fl_object_size
);
774 object_base
= off
- objoff
;
775 if (!(truncate_seq
== 1 && truncate_size
== -1ULL)) {
776 if (truncate_size
<= object_base
) {
779 truncate_size
-= object_base
;
780 if (truncate_size
> object_size
)
781 truncate_size
= object_size
;
785 osd_req_op_extent_init(req
, 0, opcode
, objoff
, objlen
,
786 truncate_size
, truncate_seq
);
789 * A second op in the ops array means the caller wants to
790 * also issue a include a 'startsync' command so that the
791 * osd will flush data quickly.
794 osd_req_op_init(req
, 1, CEPH_OSD_OP_STARTSYNC
);
796 req
->r_base_oloc
.pool
= ceph_file_layout_pg_pool(*layout
);
798 snprintf(req
->r_base_oid
.name
, sizeof(req
->r_base_oid
.name
),
799 "%llx.%08llx", vino
.ino
, objnum
);
800 req
->r_base_oid
.name_len
= strlen(req
->r_base_oid
.name
);
804 EXPORT_SYMBOL(ceph_osdc_new_request
);
807 * We keep osd requests in an rbtree, sorted by ->r_tid.
809 static void __insert_request(struct ceph_osd_client
*osdc
,
810 struct ceph_osd_request
*new)
812 struct rb_node
**p
= &osdc
->requests
.rb_node
;
813 struct rb_node
*parent
= NULL
;
814 struct ceph_osd_request
*req
= NULL
;
818 req
= rb_entry(parent
, struct ceph_osd_request
, r_node
);
819 if (new->r_tid
< req
->r_tid
)
821 else if (new->r_tid
> req
->r_tid
)
827 rb_link_node(&new->r_node
, parent
, p
);
828 rb_insert_color(&new->r_node
, &osdc
->requests
);
831 static struct ceph_osd_request
*__lookup_request(struct ceph_osd_client
*osdc
,
834 struct ceph_osd_request
*req
;
835 struct rb_node
*n
= osdc
->requests
.rb_node
;
838 req
= rb_entry(n
, struct ceph_osd_request
, r_node
);
839 if (tid
< req
->r_tid
)
841 else if (tid
> req
->r_tid
)
849 static struct ceph_osd_request
*
850 __lookup_request_ge(struct ceph_osd_client
*osdc
,
853 struct ceph_osd_request
*req
;
854 struct rb_node
*n
= osdc
->requests
.rb_node
;
857 req
= rb_entry(n
, struct ceph_osd_request
, r_node
);
858 if (tid
< req
->r_tid
) {
862 } else if (tid
> req
->r_tid
) {
872 * Resubmit requests pending on the given osd.
874 static void __kick_osd_requests(struct ceph_osd_client
*osdc
,
875 struct ceph_osd
*osd
)
877 struct ceph_osd_request
*req
, *nreq
;
881 dout("__kick_osd_requests osd%d\n", osd
->o_osd
);
882 err
= __reset_osd(osdc
, osd
);
886 * Build up a list of requests to resend by traversing the
887 * osd's list of requests. Requests for a given object are
888 * sent in tid order, and that is also the order they're
889 * kept on this list. Therefore all requests that are in
890 * flight will be found first, followed by all requests that
891 * have not yet been sent. And to resend requests while
892 * preserving this order we will want to put any sent
893 * requests back on the front of the osd client's unsent
896 * So we build a separate ordered list of already-sent
897 * requests for the affected osd and splice it onto the
898 * front of the osd client's unsent list. Once we've seen a
899 * request that has not yet been sent we're done. Those
900 * requests are already sitting right where they belong.
902 list_for_each_entry(req
, &osd
->o_requests
, r_osd_item
) {
905 list_move_tail(&req
->r_req_lru_item
, &resend
);
906 dout("requeueing %p tid %llu osd%d\n", req
, req
->r_tid
,
909 req
->r_flags
|= CEPH_OSD_FLAG_RETRY
;
911 list_splice(&resend
, &osdc
->req_unsent
);
914 * Linger requests are re-registered before sending, which
915 * sets up a new tid for each. We add them to the unsent
916 * list at the end to keep things in tid order.
918 list_for_each_entry_safe(req
, nreq
, &osd
->o_linger_requests
,
921 * reregister request prior to unregistering linger so
922 * that r_osd is preserved.
924 BUG_ON(!list_empty(&req
->r_req_lru_item
));
925 __register_request(osdc
, req
);
926 list_add_tail(&req
->r_req_lru_item
, &osdc
->req_unsent
);
927 list_add_tail(&req
->r_osd_item
, &req
->r_osd
->o_requests
);
928 __unregister_linger_request(osdc
, req
);
929 dout("requeued lingering %p tid %llu osd%d\n", req
, req
->r_tid
,
935 * If the osd connection drops, we need to resubmit all requests.
937 static void osd_reset(struct ceph_connection
*con
)
939 struct ceph_osd
*osd
= con
->private;
940 struct ceph_osd_client
*osdc
;
944 dout("osd_reset osd%d\n", osd
->o_osd
);
946 down_read(&osdc
->map_sem
);
947 mutex_lock(&osdc
->request_mutex
);
948 __kick_osd_requests(osdc
, osd
);
950 mutex_unlock(&osdc
->request_mutex
);
951 up_read(&osdc
->map_sem
);
955 * Track open sessions with osds.
957 static struct ceph_osd
*create_osd(struct ceph_osd_client
*osdc
, int onum
)
959 struct ceph_osd
*osd
;
961 osd
= kzalloc(sizeof(*osd
), GFP_NOFS
);
965 atomic_set(&osd
->o_ref
, 1);
968 RB_CLEAR_NODE(&osd
->o_node
);
969 INIT_LIST_HEAD(&osd
->o_requests
);
970 INIT_LIST_HEAD(&osd
->o_linger_requests
);
971 INIT_LIST_HEAD(&osd
->o_osd_lru
);
972 osd
->o_incarnation
= 1;
974 ceph_con_init(&osd
->o_con
, osd
, &osd_con_ops
, &osdc
->client
->msgr
);
976 INIT_LIST_HEAD(&osd
->o_keepalive_item
);
980 static struct ceph_osd
*get_osd(struct ceph_osd
*osd
)
982 if (atomic_inc_not_zero(&osd
->o_ref
)) {
983 dout("get_osd %p %d -> %d\n", osd
, atomic_read(&osd
->o_ref
)-1,
984 atomic_read(&osd
->o_ref
));
987 dout("get_osd %p FAIL\n", osd
);
992 static void put_osd(struct ceph_osd
*osd
)
994 dout("put_osd %p %d -> %d\n", osd
, atomic_read(&osd
->o_ref
),
995 atomic_read(&osd
->o_ref
) - 1);
996 if (atomic_dec_and_test(&osd
->o_ref
) && osd
->o_auth
.authorizer
) {
997 struct ceph_auth_client
*ac
= osd
->o_osdc
->client
->monc
.auth
;
999 ceph_auth_destroy_authorizer(ac
, osd
->o_auth
.authorizer
);
1005 * remove an osd from our map
1007 static void __remove_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*osd
)
1009 dout("__remove_osd %p\n", osd
);
1010 BUG_ON(!list_empty(&osd
->o_requests
));
1011 rb_erase(&osd
->o_node
, &osdc
->osds
);
1012 list_del_init(&osd
->o_osd_lru
);
1013 ceph_con_close(&osd
->o_con
);
1017 static void remove_all_osds(struct ceph_osd_client
*osdc
)
1019 dout("%s %p\n", __func__
, osdc
);
1020 mutex_lock(&osdc
->request_mutex
);
1021 while (!RB_EMPTY_ROOT(&osdc
->osds
)) {
1022 struct ceph_osd
*osd
= rb_entry(rb_first(&osdc
->osds
),
1023 struct ceph_osd
, o_node
);
1024 __remove_osd(osdc
, osd
);
1026 mutex_unlock(&osdc
->request_mutex
);
1029 static void __move_osd_to_lru(struct ceph_osd_client
*osdc
,
1030 struct ceph_osd
*osd
)
1032 dout("__move_osd_to_lru %p\n", osd
);
1033 BUG_ON(!list_empty(&osd
->o_osd_lru
));
1034 list_add_tail(&osd
->o_osd_lru
, &osdc
->osd_lru
);
1035 osd
->lru_ttl
= jiffies
+ osdc
->client
->options
->osd_idle_ttl
* HZ
;
1038 static void __remove_osd_from_lru(struct ceph_osd
*osd
)
1040 dout("__remove_osd_from_lru %p\n", osd
);
1041 if (!list_empty(&osd
->o_osd_lru
))
1042 list_del_init(&osd
->o_osd_lru
);
1045 static void remove_old_osds(struct ceph_osd_client
*osdc
)
1047 struct ceph_osd
*osd
, *nosd
;
1049 dout("__remove_old_osds %p\n", osdc
);
1050 mutex_lock(&osdc
->request_mutex
);
1051 list_for_each_entry_safe(osd
, nosd
, &osdc
->osd_lru
, o_osd_lru
) {
1052 if (time_before(jiffies
, osd
->lru_ttl
))
1054 __remove_osd(osdc
, osd
);
1056 mutex_unlock(&osdc
->request_mutex
);
1062 static int __reset_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*osd
)
1064 struct ceph_entity_addr
*peer_addr
;
1066 dout("__reset_osd %p osd%d\n", osd
, osd
->o_osd
);
1067 if (list_empty(&osd
->o_requests
) &&
1068 list_empty(&osd
->o_linger_requests
)) {
1069 __remove_osd(osdc
, osd
);
1074 peer_addr
= &osdc
->osdmap
->osd_addr
[osd
->o_osd
];
1075 if (!memcmp(peer_addr
, &osd
->o_con
.peer_addr
, sizeof (*peer_addr
)) &&
1076 !ceph_con_opened(&osd
->o_con
)) {
1077 struct ceph_osd_request
*req
;
1079 dout("osd addr hasn't changed and connection never opened, "
1080 "letting msgr retry\n");
1081 /* touch each r_stamp for handle_timeout()'s benfit */
1082 list_for_each_entry(req
, &osd
->o_requests
, r_osd_item
)
1083 req
->r_stamp
= jiffies
;
1088 ceph_con_close(&osd
->o_con
);
1089 ceph_con_open(&osd
->o_con
, CEPH_ENTITY_TYPE_OSD
, osd
->o_osd
, peer_addr
);
1090 osd
->o_incarnation
++;
1095 static void __insert_osd(struct ceph_osd_client
*osdc
, struct ceph_osd
*new)
1097 struct rb_node
**p
= &osdc
->osds
.rb_node
;
1098 struct rb_node
*parent
= NULL
;
1099 struct ceph_osd
*osd
= NULL
;
1101 dout("__insert_osd %p osd%d\n", new, new->o_osd
);
1104 osd
= rb_entry(parent
, struct ceph_osd
, o_node
);
1105 if (new->o_osd
< osd
->o_osd
)
1107 else if (new->o_osd
> osd
->o_osd
)
1108 p
= &(*p
)->rb_right
;
1113 rb_link_node(&new->o_node
, parent
, p
);
1114 rb_insert_color(&new->o_node
, &osdc
->osds
);
1117 static struct ceph_osd
*__lookup_osd(struct ceph_osd_client
*osdc
, int o
)
1119 struct ceph_osd
*osd
;
1120 struct rb_node
*n
= osdc
->osds
.rb_node
;
1123 osd
= rb_entry(n
, struct ceph_osd
, o_node
);
1126 else if (o
> osd
->o_osd
)
1134 static void __schedule_osd_timeout(struct ceph_osd_client
*osdc
)
1136 schedule_delayed_work(&osdc
->timeout_work
,
1137 osdc
->client
->options
->osd_keepalive_timeout
* HZ
);
1140 static void __cancel_osd_timeout(struct ceph_osd_client
*osdc
)
1142 cancel_delayed_work(&osdc
->timeout_work
);
1146 * Register request, assign tid. If this is the first request, set up
1147 * the timeout event.
1149 static void __register_request(struct ceph_osd_client
*osdc
,
1150 struct ceph_osd_request
*req
)
1152 req
->r_tid
= ++osdc
->last_tid
;
1153 req
->r_request
->hdr
.tid
= cpu_to_le64(req
->r_tid
);
1154 dout("__register_request %p tid %lld\n", req
, req
->r_tid
);
1155 __insert_request(osdc
, req
);
1156 ceph_osdc_get_request(req
);
1157 osdc
->num_requests
++;
1158 if (osdc
->num_requests
== 1) {
1159 dout(" first request, scheduling timeout\n");
1160 __schedule_osd_timeout(osdc
);
1165 * called under osdc->request_mutex
1167 static void __unregister_request(struct ceph_osd_client
*osdc
,
1168 struct ceph_osd_request
*req
)
1170 if (RB_EMPTY_NODE(&req
->r_node
)) {
1171 dout("__unregister_request %p tid %lld not registered\n",
1176 dout("__unregister_request %p tid %lld\n", req
, req
->r_tid
);
1177 rb_erase(&req
->r_node
, &osdc
->requests
);
1178 osdc
->num_requests
--;
1181 /* make sure the original request isn't in flight. */
1182 ceph_msg_revoke(req
->r_request
);
1184 list_del_init(&req
->r_osd_item
);
1185 if (list_empty(&req
->r_osd
->o_requests
) &&
1186 list_empty(&req
->r_osd
->o_linger_requests
)) {
1187 dout("moving osd to %p lru\n", req
->r_osd
);
1188 __move_osd_to_lru(osdc
, req
->r_osd
);
1190 if (list_empty(&req
->r_linger_item
))
1194 list_del_init(&req
->r_req_lru_item
);
1195 ceph_osdc_put_request(req
);
1197 if (osdc
->num_requests
== 0) {
1198 dout(" no requests, canceling timeout\n");
1199 __cancel_osd_timeout(osdc
);
1204 * Cancel a previously queued request message
1206 static void __cancel_request(struct ceph_osd_request
*req
)
1208 if (req
->r_sent
&& req
->r_osd
) {
1209 ceph_msg_revoke(req
->r_request
);
1214 static void __register_linger_request(struct ceph_osd_client
*osdc
,
1215 struct ceph_osd_request
*req
)
1217 dout("__register_linger_request %p\n", req
);
1218 ceph_osdc_get_request(req
);
1219 list_add_tail(&req
->r_linger_item
, &osdc
->req_linger
);
1221 list_add_tail(&req
->r_linger_osd
,
1222 &req
->r_osd
->o_linger_requests
);
1225 static void __unregister_linger_request(struct ceph_osd_client
*osdc
,
1226 struct ceph_osd_request
*req
)
1228 dout("__unregister_linger_request %p\n", req
);
1229 list_del_init(&req
->r_linger_item
);
1231 list_del_init(&req
->r_linger_osd
);
1233 if (list_empty(&req
->r_osd
->o_requests
) &&
1234 list_empty(&req
->r_osd
->o_linger_requests
)) {
1235 dout("moving osd to %p lru\n", req
->r_osd
);
1236 __move_osd_to_lru(osdc
, req
->r_osd
);
1238 if (list_empty(&req
->r_osd_item
))
1241 ceph_osdc_put_request(req
);
1244 void ceph_osdc_unregister_linger_request(struct ceph_osd_client
*osdc
,
1245 struct ceph_osd_request
*req
)
1247 mutex_lock(&osdc
->request_mutex
);
1248 if (req
->r_linger
) {
1250 __unregister_linger_request(osdc
, req
);
1252 mutex_unlock(&osdc
->request_mutex
);
1254 EXPORT_SYMBOL(ceph_osdc_unregister_linger_request
);
1256 void ceph_osdc_set_request_linger(struct ceph_osd_client
*osdc
,
1257 struct ceph_osd_request
*req
)
1259 if (!req
->r_linger
) {
1260 dout("set_request_linger %p\n", req
);
1264 EXPORT_SYMBOL(ceph_osdc_set_request_linger
);
1267 * Returns whether a request should be blocked from being sent
1268 * based on the current osdmap and osd_client settings.
1270 * Caller should hold map_sem for read.
1272 static bool __req_should_be_paused(struct ceph_osd_client
*osdc
,
1273 struct ceph_osd_request
*req
)
1275 bool pauserd
= ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_PAUSERD
);
1276 bool pausewr
= ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_PAUSEWR
) ||
1277 ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_FULL
);
1278 return (req
->r_flags
& CEPH_OSD_FLAG_READ
&& pauserd
) ||
1279 (req
->r_flags
& CEPH_OSD_FLAG_WRITE
&& pausewr
);
1283 * Calculate mapping of a request to a PG. Takes tiering into account.
1285 static int __calc_request_pg(struct ceph_osdmap
*osdmap
,
1286 struct ceph_osd_request
*req
,
1287 struct ceph_pg
*pg_out
)
1289 bool need_check_tiering
;
1291 need_check_tiering
= false;
1292 if (req
->r_target_oloc
.pool
== -1) {
1293 req
->r_target_oloc
= req
->r_base_oloc
; /* struct */
1294 need_check_tiering
= true;
1296 if (req
->r_target_oid
.name_len
== 0) {
1297 ceph_oid_copy(&req
->r_target_oid
, &req
->r_base_oid
);
1298 need_check_tiering
= true;
1301 if (need_check_tiering
&&
1302 (req
->r_flags
& CEPH_OSD_FLAG_IGNORE_OVERLAY
) == 0) {
1303 struct ceph_pg_pool_info
*pi
;
1305 pi
= ceph_pg_pool_by_id(osdmap
, req
->r_target_oloc
.pool
);
1307 if ((req
->r_flags
& CEPH_OSD_FLAG_READ
) &&
1309 req
->r_target_oloc
.pool
= pi
->read_tier
;
1310 if ((req
->r_flags
& CEPH_OSD_FLAG_WRITE
) &&
1311 pi
->write_tier
>= 0)
1312 req
->r_target_oloc
.pool
= pi
->write_tier
;
1314 /* !pi is caught in ceph_oloc_oid_to_pg() */
1317 return ceph_oloc_oid_to_pg(osdmap
, &req
->r_target_oloc
,
1318 &req
->r_target_oid
, pg_out
);
1322 * Pick an osd (the first 'up' osd in the pg), allocate the osd struct
1323 * (as needed), and set the request r_osd appropriately. If there is
1324 * no up osd, set r_osd to NULL. Move the request to the appropriate list
1325 * (unsent, homeless) or leave on in-flight lru.
1327 * Return 0 if unchanged, 1 if changed, or negative on error.
1329 * Caller should hold map_sem for read and request_mutex.
1331 static int __map_request(struct ceph_osd_client
*osdc
,
1332 struct ceph_osd_request
*req
, int force_resend
)
1334 struct ceph_pg pgid
;
1335 int acting
[CEPH_PG_MAX_SIZE
];
1340 dout("map_request %p tid %lld\n", req
, req
->r_tid
);
1342 err
= __calc_request_pg(osdc
->osdmap
, req
, &pgid
);
1344 list_move(&req
->r_req_lru_item
, &osdc
->req_notarget
);
1349 num
= ceph_calc_pg_acting(osdc
->osdmap
, pgid
, acting
, &o
);
1353 was_paused
= req
->r_paused
;
1354 req
->r_paused
= __req_should_be_paused(osdc
, req
);
1355 if (was_paused
&& !req
->r_paused
)
1358 if ((!force_resend
&&
1359 req
->r_osd
&& req
->r_osd
->o_osd
== o
&&
1360 req
->r_sent
>= req
->r_osd
->o_incarnation
&&
1361 req
->r_num_pg_osds
== num
&&
1362 memcmp(req
->r_pg_osds
, acting
, sizeof(acting
[0])*num
) == 0) ||
1363 (req
->r_osd
== NULL
&& o
== -1) ||
1365 return 0; /* no change */
1367 dout("map_request tid %llu pgid %lld.%x osd%d (was osd%d)\n",
1368 req
->r_tid
, pgid
.pool
, pgid
.seed
, o
,
1369 req
->r_osd
? req
->r_osd
->o_osd
: -1);
1371 /* record full pg acting set */
1372 memcpy(req
->r_pg_osds
, acting
, sizeof(acting
[0]) * num
);
1373 req
->r_num_pg_osds
= num
;
1376 __cancel_request(req
);
1377 list_del_init(&req
->r_osd_item
);
1381 req
->r_osd
= __lookup_osd(osdc
, o
);
1382 if (!req
->r_osd
&& o
>= 0) {
1384 req
->r_osd
= create_osd(osdc
, o
);
1386 list_move(&req
->r_req_lru_item
, &osdc
->req_notarget
);
1390 dout("map_request osd %p is osd%d\n", req
->r_osd
, o
);
1391 __insert_osd(osdc
, req
->r_osd
);
1393 ceph_con_open(&req
->r_osd
->o_con
,
1394 CEPH_ENTITY_TYPE_OSD
, o
,
1395 &osdc
->osdmap
->osd_addr
[o
]);
1399 __remove_osd_from_lru(req
->r_osd
);
1400 list_add_tail(&req
->r_osd_item
, &req
->r_osd
->o_requests
);
1401 list_move_tail(&req
->r_req_lru_item
, &osdc
->req_unsent
);
1403 list_move_tail(&req
->r_req_lru_item
, &osdc
->req_notarget
);
1405 err
= 1; /* osd or pg changed */
1412 * caller should hold map_sem (for read) and request_mutex
1414 static void __send_request(struct ceph_osd_client
*osdc
,
1415 struct ceph_osd_request
*req
)
1419 dout("send_request %p tid %llu to osd%d flags %d pg %lld.%x\n",
1420 req
, req
->r_tid
, req
->r_osd
->o_osd
, req
->r_flags
,
1421 (unsigned long long)req
->r_pgid
.pool
, req
->r_pgid
.seed
);
1423 /* fill in message content that changes each time we send it */
1424 put_unaligned_le32(osdc
->osdmap
->epoch
, req
->r_request_osdmap_epoch
);
1425 put_unaligned_le32(req
->r_flags
, req
->r_request_flags
);
1426 put_unaligned_le64(req
->r_target_oloc
.pool
, req
->r_request_pool
);
1427 p
= req
->r_request_pgid
;
1428 ceph_encode_64(&p
, req
->r_pgid
.pool
);
1429 ceph_encode_32(&p
, req
->r_pgid
.seed
);
1430 put_unaligned_le64(1, req
->r_request_attempts
); /* FIXME */
1431 memcpy(req
->r_request_reassert_version
, &req
->r_reassert_version
,
1432 sizeof(req
->r_reassert_version
));
1434 req
->r_stamp
= jiffies
;
1435 list_move_tail(&req
->r_req_lru_item
, &osdc
->req_lru
);
1437 ceph_msg_get(req
->r_request
); /* send consumes a ref */
1439 req
->r_sent
= req
->r_osd
->o_incarnation
;
1441 ceph_con_send(&req
->r_osd
->o_con
, req
->r_request
);
1445 * Send any requests in the queue (req_unsent).
1447 static void __send_queued(struct ceph_osd_client
*osdc
)
1449 struct ceph_osd_request
*req
, *tmp
;
1451 dout("__send_queued\n");
1452 list_for_each_entry_safe(req
, tmp
, &osdc
->req_unsent
, r_req_lru_item
)
1453 __send_request(osdc
, req
);
1457 * Caller should hold map_sem for read and request_mutex.
1459 static int __ceph_osdc_start_request(struct ceph_osd_client
*osdc
,
1460 struct ceph_osd_request
*req
,
1465 __register_request(osdc
, req
);
1467 req
->r_got_reply
= 0;
1468 rc
= __map_request(osdc
, req
, 0);
1471 dout("osdc_start_request failed map, "
1472 " will retry %lld\n", req
->r_tid
);
1475 __unregister_request(osdc
, req
);
1480 if (req
->r_osd
== NULL
) {
1481 dout("send_request %p no up osds in pg\n", req
);
1482 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
1484 __send_queued(osdc
);
1491 * Timeout callback, called every N seconds when 1 or more osd
1492 * requests has been active for more than N seconds. When this
1493 * happens, we ping all OSDs with requests who have timed out to
1494 * ensure any communications channel reset is detected. Reset the
1495 * request timeouts another N seconds in the future as we go.
1496 * Reschedule the timeout event another N seconds in future (unless
1497 * there are no open requests).
1499 static void handle_timeout(struct work_struct
*work
)
1501 struct ceph_osd_client
*osdc
=
1502 container_of(work
, struct ceph_osd_client
, timeout_work
.work
);
1503 struct ceph_osd_request
*req
;
1504 struct ceph_osd
*osd
;
1505 unsigned long keepalive
=
1506 osdc
->client
->options
->osd_keepalive_timeout
* HZ
;
1507 struct list_head slow_osds
;
1509 down_read(&osdc
->map_sem
);
1511 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
1513 mutex_lock(&osdc
->request_mutex
);
1516 * ping osds that are a bit slow. this ensures that if there
1517 * is a break in the TCP connection we will notice, and reopen
1518 * a connection with that osd (from the fault callback).
1520 INIT_LIST_HEAD(&slow_osds
);
1521 list_for_each_entry(req
, &osdc
->req_lru
, r_req_lru_item
) {
1522 if (time_before(jiffies
, req
->r_stamp
+ keepalive
))
1527 dout(" tid %llu is slow, will send keepalive on osd%d\n",
1528 req
->r_tid
, osd
->o_osd
);
1529 list_move_tail(&osd
->o_keepalive_item
, &slow_osds
);
1531 while (!list_empty(&slow_osds
)) {
1532 osd
= list_entry(slow_osds
.next
, struct ceph_osd
,
1534 list_del_init(&osd
->o_keepalive_item
);
1535 ceph_con_keepalive(&osd
->o_con
);
1538 __schedule_osd_timeout(osdc
);
1539 __send_queued(osdc
);
1540 mutex_unlock(&osdc
->request_mutex
);
1541 up_read(&osdc
->map_sem
);
1544 static void handle_osds_timeout(struct work_struct
*work
)
1546 struct ceph_osd_client
*osdc
=
1547 container_of(work
, struct ceph_osd_client
,
1548 osds_timeout_work
.work
);
1549 unsigned long delay
=
1550 osdc
->client
->options
->osd_idle_ttl
* HZ
>> 2;
1552 dout("osds timeout\n");
1553 down_read(&osdc
->map_sem
);
1554 remove_old_osds(osdc
);
1555 up_read(&osdc
->map_sem
);
1557 schedule_delayed_work(&osdc
->osds_timeout_work
,
1558 round_jiffies_relative(delay
));
1561 static int ceph_oloc_decode(void **p
, void *end
,
1562 struct ceph_object_locator
*oloc
)
1564 u8 struct_v
, struct_cv
;
1569 ceph_decode_need(p
, end
, 1 + 1 + 4, e_inval
);
1570 struct_v
= ceph_decode_8(p
);
1571 struct_cv
= ceph_decode_8(p
);
1573 pr_warn("got v %d < 3 cv %d of ceph_object_locator\n",
1574 struct_v
, struct_cv
);
1577 if (struct_cv
> 6) {
1578 pr_warn("got v %d cv %d > 6 of ceph_object_locator\n",
1579 struct_v
, struct_cv
);
1582 len
= ceph_decode_32(p
);
1583 ceph_decode_need(p
, end
, len
, e_inval
);
1584 struct_end
= *p
+ len
;
1586 oloc
->pool
= ceph_decode_64(p
);
1587 *p
+= 4; /* skip preferred */
1589 len
= ceph_decode_32(p
);
1591 pr_warn("ceph_object_locator::key is set\n");
1595 if (struct_v
>= 5) {
1596 len
= ceph_decode_32(p
);
1598 pr_warn("ceph_object_locator::nspace is set\n");
1603 if (struct_v
>= 6) {
1604 s64 hash
= ceph_decode_64(p
);
1606 pr_warn("ceph_object_locator::hash is set\n");
1621 static int ceph_redirect_decode(void **p
, void *end
,
1622 struct ceph_request_redirect
*redir
)
1624 u8 struct_v
, struct_cv
;
1629 ceph_decode_need(p
, end
, 1 + 1 + 4, e_inval
);
1630 struct_v
= ceph_decode_8(p
);
1631 struct_cv
= ceph_decode_8(p
);
1632 if (struct_cv
> 1) {
1633 pr_warn("got v %d cv %d > 1 of ceph_request_redirect\n",
1634 struct_v
, struct_cv
);
1637 len
= ceph_decode_32(p
);
1638 ceph_decode_need(p
, end
, len
, e_inval
);
1639 struct_end
= *p
+ len
;
1641 ret
= ceph_oloc_decode(p
, end
, &redir
->oloc
);
1645 len
= ceph_decode_32(p
);
1647 pr_warn("ceph_request_redirect::object_name is set\n");
1651 len
= ceph_decode_32(p
);
1652 *p
+= len
; /* skip osd_instructions */
1664 static void complete_request(struct ceph_osd_request
*req
)
1666 complete_all(&req
->r_safe_completion
); /* fsync waiter */
1670 * handle osd op reply. either call the callback if it is specified,
1671 * or do the completion to wake up the waiting thread.
1673 static void handle_reply(struct ceph_osd_client
*osdc
, struct ceph_msg
*msg
,
1674 struct ceph_connection
*con
)
1677 struct ceph_osd_request
*req
;
1678 struct ceph_request_redirect redir
;
1681 unsigned int numops
;
1682 int payload_len
, flags
;
1688 u64 reassert_version
;
1690 int already_completed
;
1694 tid
= le64_to_cpu(msg
->hdr
.tid
);
1695 dout("handle_reply %p tid %llu\n", msg
, tid
);
1697 p
= msg
->front
.iov_base
;
1698 end
= p
+ msg
->front
.iov_len
;
1700 ceph_decode_need(&p
, end
, 4, bad
);
1701 object_len
= ceph_decode_32(&p
);
1702 ceph_decode_need(&p
, end
, object_len
, bad
);
1705 err
= ceph_decode_pgid(&p
, end
, &pg
);
1709 ceph_decode_need(&p
, end
, 8 + 4 + 4 + 8 + 4, bad
);
1710 flags
= ceph_decode_64(&p
);
1711 result
= ceph_decode_32(&p
);
1712 reassert_epoch
= ceph_decode_32(&p
);
1713 reassert_version
= ceph_decode_64(&p
);
1714 osdmap_epoch
= ceph_decode_32(&p
);
1717 down_read(&osdc
->map_sem
);
1718 mutex_lock(&osdc
->request_mutex
);
1719 req
= __lookup_request(osdc
, tid
);
1721 dout("handle_reply tid %llu dne\n", tid
);
1724 ceph_osdc_get_request(req
);
1726 dout("handle_reply %p tid %llu req %p result %d\n", msg
, tid
,
1729 ceph_decode_need(&p
, end
, 4, bad_put
);
1730 numops
= ceph_decode_32(&p
);
1731 if (numops
> CEPH_OSD_MAX_OP
)
1733 if (numops
!= req
->r_num_ops
)
1736 ceph_decode_need(&p
, end
, numops
* sizeof(struct ceph_osd_op
), bad_put
);
1737 for (i
= 0; i
< numops
; i
++) {
1738 struct ceph_osd_op
*op
= p
;
1741 len
= le32_to_cpu(op
->payload_len
);
1742 req
->r_reply_op_len
[i
] = len
;
1743 dout(" op %d has %d bytes\n", i
, len
);
1747 bytes
= le32_to_cpu(msg
->hdr
.data_len
);
1748 if (payload_len
!= bytes
) {
1749 pr_warning("sum of op payload lens %d != data_len %d",
1750 payload_len
, bytes
);
1754 ceph_decode_need(&p
, end
, 4 + numops
* 4, bad_put
);
1755 retry_attempt
= ceph_decode_32(&p
);
1756 for (i
= 0; i
< numops
; i
++)
1757 req
->r_reply_op_result
[i
] = ceph_decode_32(&p
);
1759 if (le16_to_cpu(msg
->hdr
.version
) >= 6) {
1760 p
+= 8 + 4; /* skip replay_version */
1761 p
+= 8; /* skip user_version */
1763 err
= ceph_redirect_decode(&p
, end
, &redir
);
1767 redir
.oloc
.pool
= -1;
1770 if (redir
.oloc
.pool
!= -1) {
1771 dout("redirect pool %lld\n", redir
.oloc
.pool
);
1773 __unregister_request(osdc
, req
);
1775 req
->r_target_oloc
= redir
.oloc
; /* struct */
1778 * Start redirect requests with nofail=true. If
1779 * mapping fails, request will end up on the notarget
1780 * list, waiting for the new osdmap (which can take
1781 * a while), even though the original request mapped
1782 * successfully. In the future we might want to follow
1783 * original request's nofail setting here.
1785 err
= __ceph_osdc_start_request(osdc
, req
, true);
1791 already_completed
= req
->r_got_reply
;
1792 if (!req
->r_got_reply
) {
1793 req
->r_result
= result
;
1794 dout("handle_reply result %d bytes %d\n", req
->r_result
,
1796 if (req
->r_result
== 0)
1797 req
->r_result
= bytes
;
1799 /* in case this is a write and we need to replay, */
1800 req
->r_reassert_version
.epoch
= cpu_to_le32(reassert_epoch
);
1801 req
->r_reassert_version
.version
= cpu_to_le64(reassert_version
);
1803 req
->r_got_reply
= 1;
1804 } else if ((flags
& CEPH_OSD_FLAG_ONDISK
) == 0) {
1805 dout("handle_reply tid %llu dup ack\n", tid
);
1809 dout("handle_reply tid %llu flags %d\n", tid
, flags
);
1811 if (req
->r_linger
&& (flags
& CEPH_OSD_FLAG_ONDISK
))
1812 __register_linger_request(osdc
, req
);
1814 /* either this is a read, or we got the safe response */
1816 (flags
& CEPH_OSD_FLAG_ONDISK
) ||
1817 ((flags
& CEPH_OSD_FLAG_WRITE
) == 0))
1818 __unregister_request(osdc
, req
);
1820 mutex_unlock(&osdc
->request_mutex
);
1821 up_read(&osdc
->map_sem
);
1823 if (!already_completed
) {
1824 if (req
->r_unsafe_callback
&&
1825 result
>= 0 && !(flags
& CEPH_OSD_FLAG_ONDISK
))
1826 req
->r_unsafe_callback(req
, true);
1827 if (req
->r_callback
)
1828 req
->r_callback(req
, msg
);
1830 complete_all(&req
->r_completion
);
1833 if (flags
& CEPH_OSD_FLAG_ONDISK
) {
1834 if (req
->r_unsafe_callback
&& already_completed
)
1835 req
->r_unsafe_callback(req
, false);
1836 complete_request(req
);
1840 dout("req=%p req->r_linger=%d\n", req
, req
->r_linger
);
1841 ceph_osdc_put_request(req
);
1844 mutex_unlock(&osdc
->request_mutex
);
1845 up_read(&osdc
->map_sem
);
1849 req
->r_result
= -EIO
;
1850 __unregister_request(osdc
, req
);
1851 if (req
->r_callback
)
1852 req
->r_callback(req
, msg
);
1854 complete_all(&req
->r_completion
);
1855 complete_request(req
);
1856 ceph_osdc_put_request(req
);
1858 mutex_unlock(&osdc
->request_mutex
);
1859 up_read(&osdc
->map_sem
);
1861 pr_err("corrupt osd_op_reply got %d %d\n",
1862 (int)msg
->front
.iov_len
, le32_to_cpu(msg
->hdr
.front_len
));
1866 static void reset_changed_osds(struct ceph_osd_client
*osdc
)
1868 struct rb_node
*p
, *n
;
1870 for (p
= rb_first(&osdc
->osds
); p
; p
= n
) {
1871 struct ceph_osd
*osd
= rb_entry(p
, struct ceph_osd
, o_node
);
1874 if (!ceph_osd_is_up(osdc
->osdmap
, osd
->o_osd
) ||
1875 memcmp(&osd
->o_con
.peer_addr
,
1876 ceph_osd_addr(osdc
->osdmap
,
1878 sizeof(struct ceph_entity_addr
)) != 0)
1879 __reset_osd(osdc
, osd
);
1884 * Requeue requests whose mapping to an OSD has changed. If requests map to
1885 * no osd, request a new map.
1887 * Caller should hold map_sem for read.
1889 static void kick_requests(struct ceph_osd_client
*osdc
, bool force_resend
,
1890 bool force_resend_writes
)
1892 struct ceph_osd_request
*req
, *nreq
;
1896 bool force_resend_req
;
1898 dout("kick_requests %s %s\n", force_resend
? " (force resend)" : "",
1899 force_resend_writes
? " (force resend writes)" : "");
1900 mutex_lock(&osdc
->request_mutex
);
1901 for (p
= rb_first(&osdc
->requests
); p
; ) {
1902 req
= rb_entry(p
, struct ceph_osd_request
, r_node
);
1906 * For linger requests that have not yet been
1907 * registered, move them to the linger list; they'll
1908 * be sent to the osd in the loop below. Unregister
1909 * the request before re-registering it as a linger
1910 * request to ensure the __map_request() below
1911 * will decide it needs to be sent.
1913 if (req
->r_linger
&& list_empty(&req
->r_linger_item
)) {
1914 dout("%p tid %llu restart on osd%d\n",
1916 req
->r_osd
? req
->r_osd
->o_osd
: -1);
1917 ceph_osdc_get_request(req
);
1918 __unregister_request(osdc
, req
);
1919 __register_linger_request(osdc
, req
);
1920 ceph_osdc_put_request(req
);
1924 force_resend_req
= force_resend
||
1925 (force_resend_writes
&&
1926 req
->r_flags
& CEPH_OSD_FLAG_WRITE
);
1927 err
= __map_request(osdc
, req
, force_resend_req
);
1929 continue; /* error */
1930 if (req
->r_osd
== NULL
) {
1931 dout("%p tid %llu maps to no osd\n", req
, req
->r_tid
);
1932 needmap
++; /* request a newer map */
1933 } else if (err
> 0) {
1934 if (!req
->r_linger
) {
1935 dout("%p tid %llu requeued on osd%d\n", req
,
1937 req
->r_osd
? req
->r_osd
->o_osd
: -1);
1938 req
->r_flags
|= CEPH_OSD_FLAG_RETRY
;
1943 list_for_each_entry_safe(req
, nreq
, &osdc
->req_linger
,
1945 dout("linger req=%p req->r_osd=%p\n", req
, req
->r_osd
);
1947 err
= __map_request(osdc
, req
,
1948 force_resend
|| force_resend_writes
);
1949 dout("__map_request returned %d\n", err
);
1951 continue; /* no change and no osd was specified */
1953 continue; /* hrm! */
1954 if (req
->r_osd
== NULL
) {
1955 dout("tid %llu maps to no valid osd\n", req
->r_tid
);
1956 needmap
++; /* request a newer map */
1960 dout("kicking lingering %p tid %llu osd%d\n", req
, req
->r_tid
,
1961 req
->r_osd
? req
->r_osd
->o_osd
: -1);
1962 __register_request(osdc
, req
);
1963 __unregister_linger_request(osdc
, req
);
1965 reset_changed_osds(osdc
);
1966 mutex_unlock(&osdc
->request_mutex
);
1969 dout("%d requests for down osds, need new map\n", needmap
);
1970 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
1976 * Process updated osd map.
1978 * The message contains any number of incremental and full maps, normally
1979 * indicating some sort of topology change in the cluster. Kick requests
1980 * off to different OSDs as needed.
1982 void ceph_osdc_handle_map(struct ceph_osd_client
*osdc
, struct ceph_msg
*msg
)
1984 void *p
, *end
, *next
;
1985 u32 nr_maps
, maplen
;
1987 struct ceph_osdmap
*newmap
= NULL
, *oldmap
;
1989 struct ceph_fsid fsid
;
1992 dout("handle_map have %u\n", osdc
->osdmap
? osdc
->osdmap
->epoch
: 0);
1993 p
= msg
->front
.iov_base
;
1994 end
= p
+ msg
->front
.iov_len
;
1997 ceph_decode_need(&p
, end
, sizeof(fsid
), bad
);
1998 ceph_decode_copy(&p
, &fsid
, sizeof(fsid
));
1999 if (ceph_check_fsid(osdc
->client
, &fsid
) < 0)
2002 down_write(&osdc
->map_sem
);
2004 was_full
= ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_FULL
);
2006 /* incremental maps */
2007 ceph_decode_32_safe(&p
, end
, nr_maps
, bad
);
2008 dout(" %d inc maps\n", nr_maps
);
2009 while (nr_maps
> 0) {
2010 ceph_decode_need(&p
, end
, 2*sizeof(u32
), bad
);
2011 epoch
= ceph_decode_32(&p
);
2012 maplen
= ceph_decode_32(&p
);
2013 ceph_decode_need(&p
, end
, maplen
, bad
);
2015 if (osdc
->osdmap
&& osdc
->osdmap
->epoch
+1 == epoch
) {
2016 dout("applying incremental map %u len %d\n",
2018 newmap
= osdmap_apply_incremental(&p
, next
,
2020 &osdc
->client
->msgr
);
2021 if (IS_ERR(newmap
)) {
2022 err
= PTR_ERR(newmap
);
2026 if (newmap
!= osdc
->osdmap
) {
2027 ceph_osdmap_destroy(osdc
->osdmap
);
2028 osdc
->osdmap
= newmap
;
2030 was_full
= was_full
||
2031 ceph_osdmap_flag(osdc
->osdmap
,
2033 kick_requests(osdc
, 0, was_full
);
2035 dout("ignoring incremental map %u len %d\n",
2045 ceph_decode_32_safe(&p
, end
, nr_maps
, bad
);
2046 dout(" %d full maps\n", nr_maps
);
2048 ceph_decode_need(&p
, end
, 2*sizeof(u32
), bad
);
2049 epoch
= ceph_decode_32(&p
);
2050 maplen
= ceph_decode_32(&p
);
2051 ceph_decode_need(&p
, end
, maplen
, bad
);
2053 dout("skipping non-latest full map %u len %d\n",
2055 } else if (osdc
->osdmap
&& osdc
->osdmap
->epoch
>= epoch
) {
2056 dout("skipping full map %u len %d, "
2057 "older than our %u\n", epoch
, maplen
,
2058 osdc
->osdmap
->epoch
);
2060 int skipped_map
= 0;
2062 dout("taking full map %u len %d\n", epoch
, maplen
);
2063 newmap
= ceph_osdmap_decode(&p
, p
+maplen
);
2064 if (IS_ERR(newmap
)) {
2065 err
= PTR_ERR(newmap
);
2069 oldmap
= osdc
->osdmap
;
2070 osdc
->osdmap
= newmap
;
2072 if (oldmap
->epoch
+ 1 < newmap
->epoch
)
2074 ceph_osdmap_destroy(oldmap
);
2076 was_full
= was_full
||
2077 ceph_osdmap_flag(osdc
->osdmap
,
2079 kick_requests(osdc
, skipped_map
, was_full
);
2088 downgrade_write(&osdc
->map_sem
);
2089 ceph_monc_got_osdmap(&osdc
->client
->monc
, osdc
->osdmap
->epoch
);
2092 * subscribe to subsequent osdmap updates if full to ensure
2093 * we find out when we are no longer full and stop returning
2096 if (ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_FULL
) ||
2097 ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_PAUSERD
) ||
2098 ceph_osdmap_flag(osdc
->osdmap
, CEPH_OSDMAP_PAUSEWR
))
2099 ceph_monc_request_next_osdmap(&osdc
->client
->monc
);
2101 mutex_lock(&osdc
->request_mutex
);
2102 __send_queued(osdc
);
2103 mutex_unlock(&osdc
->request_mutex
);
2104 up_read(&osdc
->map_sem
);
2105 wake_up_all(&osdc
->client
->auth_wq
);
2109 pr_err("osdc handle_map corrupt msg\n");
2111 up_write(&osdc
->map_sem
);
2115 * watch/notify callback event infrastructure
2117 * These callbacks are used both for watch and notify operations.
2119 static void __release_event(struct kref
*kref
)
2121 struct ceph_osd_event
*event
=
2122 container_of(kref
, struct ceph_osd_event
, kref
);
2124 dout("__release_event %p\n", event
);
2128 static void get_event(struct ceph_osd_event
*event
)
2130 kref_get(&event
->kref
);
2133 void ceph_osdc_put_event(struct ceph_osd_event
*event
)
2135 kref_put(&event
->kref
, __release_event
);
2137 EXPORT_SYMBOL(ceph_osdc_put_event
);
2139 static void __insert_event(struct ceph_osd_client
*osdc
,
2140 struct ceph_osd_event
*new)
2142 struct rb_node
**p
= &osdc
->event_tree
.rb_node
;
2143 struct rb_node
*parent
= NULL
;
2144 struct ceph_osd_event
*event
= NULL
;
2148 event
= rb_entry(parent
, struct ceph_osd_event
, node
);
2149 if (new->cookie
< event
->cookie
)
2151 else if (new->cookie
> event
->cookie
)
2152 p
= &(*p
)->rb_right
;
2157 rb_link_node(&new->node
, parent
, p
);
2158 rb_insert_color(&new->node
, &osdc
->event_tree
);
2161 static struct ceph_osd_event
*__find_event(struct ceph_osd_client
*osdc
,
2164 struct rb_node
**p
= &osdc
->event_tree
.rb_node
;
2165 struct rb_node
*parent
= NULL
;
2166 struct ceph_osd_event
*event
= NULL
;
2170 event
= rb_entry(parent
, struct ceph_osd_event
, node
);
2171 if (cookie
< event
->cookie
)
2173 else if (cookie
> event
->cookie
)
2174 p
= &(*p
)->rb_right
;
2181 static void __remove_event(struct ceph_osd_event
*event
)
2183 struct ceph_osd_client
*osdc
= event
->osdc
;
2185 if (!RB_EMPTY_NODE(&event
->node
)) {
2186 dout("__remove_event removed %p\n", event
);
2187 rb_erase(&event
->node
, &osdc
->event_tree
);
2188 ceph_osdc_put_event(event
);
2190 dout("__remove_event didn't remove %p\n", event
);
2194 int ceph_osdc_create_event(struct ceph_osd_client
*osdc
,
2195 void (*event_cb
)(u64
, u64
, u8
, void *),
2196 void *data
, struct ceph_osd_event
**pevent
)
2198 struct ceph_osd_event
*event
;
2200 event
= kmalloc(sizeof(*event
), GFP_NOIO
);
2204 dout("create_event %p\n", event
);
2205 event
->cb
= event_cb
;
2206 event
->one_shot
= 0;
2209 INIT_LIST_HEAD(&event
->osd_node
);
2210 RB_CLEAR_NODE(&event
->node
);
2211 kref_init(&event
->kref
); /* one ref for us */
2212 kref_get(&event
->kref
); /* one ref for the caller */
2214 spin_lock(&osdc
->event_lock
);
2215 event
->cookie
= ++osdc
->event_count
;
2216 __insert_event(osdc
, event
);
2217 spin_unlock(&osdc
->event_lock
);
2222 EXPORT_SYMBOL(ceph_osdc_create_event
);
2224 void ceph_osdc_cancel_event(struct ceph_osd_event
*event
)
2226 struct ceph_osd_client
*osdc
= event
->osdc
;
2228 dout("cancel_event %p\n", event
);
2229 spin_lock(&osdc
->event_lock
);
2230 __remove_event(event
);
2231 spin_unlock(&osdc
->event_lock
);
2232 ceph_osdc_put_event(event
); /* caller's */
2234 EXPORT_SYMBOL(ceph_osdc_cancel_event
);
2237 static void do_event_work(struct work_struct
*work
)
2239 struct ceph_osd_event_work
*event_work
=
2240 container_of(work
, struct ceph_osd_event_work
, work
);
2241 struct ceph_osd_event
*event
= event_work
->event
;
2242 u64 ver
= event_work
->ver
;
2243 u64 notify_id
= event_work
->notify_id
;
2244 u8 opcode
= event_work
->opcode
;
2246 dout("do_event_work completing %p\n", event
);
2247 event
->cb(ver
, notify_id
, opcode
, event
->data
);
2248 dout("do_event_work completed %p\n", event
);
2249 ceph_osdc_put_event(event
);
2255 * Process osd watch notifications
2257 static void handle_watch_notify(struct ceph_osd_client
*osdc
,
2258 struct ceph_msg
*msg
)
2262 u64 cookie
, ver
, notify_id
;
2264 struct ceph_osd_event
*event
;
2265 struct ceph_osd_event_work
*event_work
;
2267 p
= msg
->front
.iov_base
;
2268 end
= p
+ msg
->front
.iov_len
;
2270 ceph_decode_8_safe(&p
, end
, proto_ver
, bad
);
2271 ceph_decode_8_safe(&p
, end
, opcode
, bad
);
2272 ceph_decode_64_safe(&p
, end
, cookie
, bad
);
2273 ceph_decode_64_safe(&p
, end
, ver
, bad
);
2274 ceph_decode_64_safe(&p
, end
, notify_id
, bad
);
2276 spin_lock(&osdc
->event_lock
);
2277 event
= __find_event(osdc
, cookie
);
2279 BUG_ON(event
->one_shot
);
2282 spin_unlock(&osdc
->event_lock
);
2283 dout("handle_watch_notify cookie %lld ver %lld event %p\n",
2284 cookie
, ver
, event
);
2286 event_work
= kmalloc(sizeof(*event_work
), GFP_NOIO
);
2288 dout("ERROR: could not allocate event_work\n");
2291 INIT_WORK(&event_work
->work
, do_event_work
);
2292 event_work
->event
= event
;
2293 event_work
->ver
= ver
;
2294 event_work
->notify_id
= notify_id
;
2295 event_work
->opcode
= opcode
;
2296 if (!queue_work(osdc
->notify_wq
, &event_work
->work
)) {
2297 dout("WARNING: failed to queue notify event work\n");
2305 ceph_osdc_put_event(event
);
2309 pr_err("osdc handle_watch_notify corrupt msg\n");
2313 * build new request AND message
2316 void ceph_osdc_build_request(struct ceph_osd_request
*req
, u64 off
,
2317 struct ceph_snap_context
*snapc
, u64 snap_id
,
2318 struct timespec
*mtime
)
2320 struct ceph_msg
*msg
= req
->r_request
;
2323 int flags
= req
->r_flags
;
2327 req
->r_snapid
= snap_id
;
2328 req
->r_snapc
= ceph_get_snap_context(snapc
);
2330 /* encode request */
2331 msg
->hdr
.version
= cpu_to_le16(4);
2333 p
= msg
->front
.iov_base
;
2334 ceph_encode_32(&p
, 1); /* client_inc is always 1 */
2335 req
->r_request_osdmap_epoch
= p
;
2337 req
->r_request_flags
= p
;
2339 if (req
->r_flags
& CEPH_OSD_FLAG_WRITE
)
2340 ceph_encode_timespec(p
, mtime
);
2341 p
+= sizeof(struct ceph_timespec
);
2342 req
->r_request_reassert_version
= p
;
2343 p
+= sizeof(struct ceph_eversion
); /* will get filled in */
2346 ceph_encode_8(&p
, 4);
2347 ceph_encode_8(&p
, 4);
2348 ceph_encode_32(&p
, 8 + 4 + 4);
2349 req
->r_request_pool
= p
;
2351 ceph_encode_32(&p
, -1); /* preferred */
2352 ceph_encode_32(&p
, 0); /* key len */
2354 ceph_encode_8(&p
, 1);
2355 req
->r_request_pgid
= p
;
2357 ceph_encode_32(&p
, -1); /* preferred */
2360 ceph_encode_32(&p
, req
->r_base_oid
.name_len
);
2361 memcpy(p
, req
->r_base_oid
.name
, req
->r_base_oid
.name_len
);
2362 dout("oid '%.*s' len %d\n", req
->r_base_oid
.name_len
,
2363 req
->r_base_oid
.name
, req
->r_base_oid
.name_len
);
2364 p
+= req
->r_base_oid
.name_len
;
2366 /* ops--can imply data */
2367 ceph_encode_16(&p
, (u16
)req
->r_num_ops
);
2369 for (i
= 0; i
< req
->r_num_ops
; i
++) {
2370 data_len
+= osd_req_encode_op(req
, p
, i
);
2371 p
+= sizeof(struct ceph_osd_op
);
2375 ceph_encode_64(&p
, req
->r_snapid
);
2376 ceph_encode_64(&p
, req
->r_snapc
? req
->r_snapc
->seq
: 0);
2377 ceph_encode_32(&p
, req
->r_snapc
? req
->r_snapc
->num_snaps
: 0);
2379 for (i
= 0; i
< snapc
->num_snaps
; i
++) {
2380 ceph_encode_64(&p
, req
->r_snapc
->snaps
[i
]);
2384 req
->r_request_attempts
= p
;
2388 if (flags
& CEPH_OSD_FLAG_WRITE
) {
2392 * The header "data_off" is a hint to the receiver
2393 * allowing it to align received data into its
2394 * buffers such that there's no need to re-copy
2395 * it before writing it to disk (direct I/O).
2397 data_off
= (u16
) (off
& 0xffff);
2398 req
->r_request
->hdr
.data_off
= cpu_to_le16(data_off
);
2400 req
->r_request
->hdr
.data_len
= cpu_to_le32(data_len
);
2402 BUG_ON(p
> msg
->front
.iov_base
+ msg
->front
.iov_len
);
2403 msg_size
= p
- msg
->front
.iov_base
;
2404 msg
->front
.iov_len
= msg_size
;
2405 msg
->hdr
.front_len
= cpu_to_le32(msg_size
);
2407 dout("build_request msg_size was %d\n", (int)msg_size
);
2409 EXPORT_SYMBOL(ceph_osdc_build_request
);
2412 * Register request, send initial attempt.
2414 int ceph_osdc_start_request(struct ceph_osd_client
*osdc
,
2415 struct ceph_osd_request
*req
,
2420 down_read(&osdc
->map_sem
);
2421 mutex_lock(&osdc
->request_mutex
);
2423 rc
= __ceph_osdc_start_request(osdc
, req
, nofail
);
2425 mutex_unlock(&osdc
->request_mutex
);
2426 up_read(&osdc
->map_sem
);
2430 EXPORT_SYMBOL(ceph_osdc_start_request
);
2433 * wait for a request to complete
2435 int ceph_osdc_wait_request(struct ceph_osd_client
*osdc
,
2436 struct ceph_osd_request
*req
)
2440 rc
= wait_for_completion_interruptible(&req
->r_completion
);
2442 mutex_lock(&osdc
->request_mutex
);
2443 __cancel_request(req
);
2444 __unregister_request(osdc
, req
);
2445 mutex_unlock(&osdc
->request_mutex
);
2446 complete_request(req
);
2447 dout("wait_request tid %llu canceled/timed out\n", req
->r_tid
);
2451 dout("wait_request tid %llu result %d\n", req
->r_tid
, req
->r_result
);
2452 return req
->r_result
;
2454 EXPORT_SYMBOL(ceph_osdc_wait_request
);
2457 * sync - wait for all in-flight requests to flush. avoid starvation.
2459 void ceph_osdc_sync(struct ceph_osd_client
*osdc
)
2461 struct ceph_osd_request
*req
;
2462 u64 last_tid
, next_tid
= 0;
2464 mutex_lock(&osdc
->request_mutex
);
2465 last_tid
= osdc
->last_tid
;
2467 req
= __lookup_request_ge(osdc
, next_tid
);
2470 if (req
->r_tid
> last_tid
)
2473 next_tid
= req
->r_tid
+ 1;
2474 if ((req
->r_flags
& CEPH_OSD_FLAG_WRITE
) == 0)
2477 ceph_osdc_get_request(req
);
2478 mutex_unlock(&osdc
->request_mutex
);
2479 dout("sync waiting on tid %llu (last is %llu)\n",
2480 req
->r_tid
, last_tid
);
2481 wait_for_completion(&req
->r_safe_completion
);
2482 mutex_lock(&osdc
->request_mutex
);
2483 ceph_osdc_put_request(req
);
2485 mutex_unlock(&osdc
->request_mutex
);
2486 dout("sync done (thru tid %llu)\n", last_tid
);
2488 EXPORT_SYMBOL(ceph_osdc_sync
);
2491 * Call all pending notify callbacks - for use after a watch is
2492 * unregistered, to make sure no more callbacks for it will be invoked
2494 void ceph_osdc_flush_notifies(struct ceph_osd_client
*osdc
)
2496 flush_workqueue(osdc
->notify_wq
);
2498 EXPORT_SYMBOL(ceph_osdc_flush_notifies
);
2504 int ceph_osdc_init(struct ceph_osd_client
*osdc
, struct ceph_client
*client
)
2509 osdc
->client
= client
;
2510 osdc
->osdmap
= NULL
;
2511 init_rwsem(&osdc
->map_sem
);
2512 init_completion(&osdc
->map_waiters
);
2513 osdc
->last_requested_map
= 0;
2514 mutex_init(&osdc
->request_mutex
);
2516 osdc
->osds
= RB_ROOT
;
2517 INIT_LIST_HEAD(&osdc
->osd_lru
);
2518 osdc
->requests
= RB_ROOT
;
2519 INIT_LIST_HEAD(&osdc
->req_lru
);
2520 INIT_LIST_HEAD(&osdc
->req_unsent
);
2521 INIT_LIST_HEAD(&osdc
->req_notarget
);
2522 INIT_LIST_HEAD(&osdc
->req_linger
);
2523 osdc
->num_requests
= 0;
2524 INIT_DELAYED_WORK(&osdc
->timeout_work
, handle_timeout
);
2525 INIT_DELAYED_WORK(&osdc
->osds_timeout_work
, handle_osds_timeout
);
2526 spin_lock_init(&osdc
->event_lock
);
2527 osdc
->event_tree
= RB_ROOT
;
2528 osdc
->event_count
= 0;
2530 schedule_delayed_work(&osdc
->osds_timeout_work
,
2531 round_jiffies_relative(osdc
->client
->options
->osd_idle_ttl
* HZ
));
2534 osdc
->req_mempool
= mempool_create_kmalloc_pool(10,
2535 sizeof(struct ceph_osd_request
));
2536 if (!osdc
->req_mempool
)
2539 err
= ceph_msgpool_init(&osdc
->msgpool_op
, CEPH_MSG_OSD_OP
,
2540 OSD_OP_FRONT_LEN
, 10, true,
2544 err
= ceph_msgpool_init(&osdc
->msgpool_op_reply
, CEPH_MSG_OSD_OPREPLY
,
2545 OSD_OPREPLY_FRONT_LEN
, 10, true,
2551 osdc
->notify_wq
= create_singlethread_workqueue("ceph-watch-notify");
2552 if (!osdc
->notify_wq
)
2553 goto out_msgpool_reply
;
2558 ceph_msgpool_destroy(&osdc
->msgpool_op_reply
);
2560 ceph_msgpool_destroy(&osdc
->msgpool_op
);
2562 mempool_destroy(osdc
->req_mempool
);
2567 void ceph_osdc_stop(struct ceph_osd_client
*osdc
)
2569 flush_workqueue(osdc
->notify_wq
);
2570 destroy_workqueue(osdc
->notify_wq
);
2571 cancel_delayed_work_sync(&osdc
->timeout_work
);
2572 cancel_delayed_work_sync(&osdc
->osds_timeout_work
);
2574 ceph_osdmap_destroy(osdc
->osdmap
);
2575 osdc
->osdmap
= NULL
;
2577 remove_all_osds(osdc
);
2578 mempool_destroy(osdc
->req_mempool
);
2579 ceph_msgpool_destroy(&osdc
->msgpool_op
);
2580 ceph_msgpool_destroy(&osdc
->msgpool_op_reply
);
2584 * Read some contiguous pages. If we cross a stripe boundary, shorten
2585 * *plen. Return number of bytes read, or error.
2587 int ceph_osdc_readpages(struct ceph_osd_client
*osdc
,
2588 struct ceph_vino vino
, struct ceph_file_layout
*layout
,
2590 u32 truncate_seq
, u64 truncate_size
,
2591 struct page
**pages
, int num_pages
, int page_align
)
2593 struct ceph_osd_request
*req
;
2596 dout("readpages on ino %llx.%llx on %llu~%llu\n", vino
.ino
,
2597 vino
.snap
, off
, *plen
);
2598 req
= ceph_osdc_new_request(osdc
, layout
, vino
, off
, plen
, 1,
2599 CEPH_OSD_OP_READ
, CEPH_OSD_FLAG_READ
,
2600 NULL
, truncate_seq
, truncate_size
,
2603 return PTR_ERR(req
);
2605 /* it may be a short read due to an object boundary */
2607 osd_req_op_extent_osd_data_pages(req
, 0,
2608 pages
, *plen
, page_align
, false, false);
2610 dout("readpages final extent is %llu~%llu (%llu bytes align %d)\n",
2611 off
, *plen
, *plen
, page_align
);
2613 ceph_osdc_build_request(req
, off
, NULL
, vino
.snap
, NULL
);
2615 rc
= ceph_osdc_start_request(osdc
, req
, false);
2617 rc
= ceph_osdc_wait_request(osdc
, req
);
2619 ceph_osdc_put_request(req
);
2620 dout("readpages result %d\n", rc
);
2623 EXPORT_SYMBOL(ceph_osdc_readpages
);
2626 * do a synchronous write on N pages
2628 int ceph_osdc_writepages(struct ceph_osd_client
*osdc
, struct ceph_vino vino
,
2629 struct ceph_file_layout
*layout
,
2630 struct ceph_snap_context
*snapc
,
2632 u32 truncate_seq
, u64 truncate_size
,
2633 struct timespec
*mtime
,
2634 struct page
**pages
, int num_pages
)
2636 struct ceph_osd_request
*req
;
2638 int page_align
= off
& ~PAGE_MASK
;
2640 BUG_ON(vino
.snap
!= CEPH_NOSNAP
); /* snapshots aren't writeable */
2641 req
= ceph_osdc_new_request(osdc
, layout
, vino
, off
, &len
, 1,
2643 CEPH_OSD_FLAG_ONDISK
| CEPH_OSD_FLAG_WRITE
,
2644 snapc
, truncate_seq
, truncate_size
,
2647 return PTR_ERR(req
);
2649 /* it may be a short write due to an object boundary */
2650 osd_req_op_extent_osd_data_pages(req
, 0, pages
, len
, page_align
,
2652 dout("writepages %llu~%llu (%llu bytes)\n", off
, len
, len
);
2654 ceph_osdc_build_request(req
, off
, snapc
, CEPH_NOSNAP
, mtime
);
2656 rc
= ceph_osdc_start_request(osdc
, req
, true);
2658 rc
= ceph_osdc_wait_request(osdc
, req
);
2660 ceph_osdc_put_request(req
);
2663 dout("writepages result %d\n", rc
);
2666 EXPORT_SYMBOL(ceph_osdc_writepages
);
2668 int ceph_osdc_setup(void)
2670 BUG_ON(ceph_osd_request_cache
);
2671 ceph_osd_request_cache
= kmem_cache_create("ceph_osd_request",
2672 sizeof (struct ceph_osd_request
),
2673 __alignof__(struct ceph_osd_request
),
2676 return ceph_osd_request_cache
? 0 : -ENOMEM
;
2678 EXPORT_SYMBOL(ceph_osdc_setup
);
2680 void ceph_osdc_cleanup(void)
2682 BUG_ON(!ceph_osd_request_cache
);
2683 kmem_cache_destroy(ceph_osd_request_cache
);
2684 ceph_osd_request_cache
= NULL
;
2686 EXPORT_SYMBOL(ceph_osdc_cleanup
);
2689 * handle incoming message
2691 static void dispatch(struct ceph_connection
*con
, struct ceph_msg
*msg
)
2693 struct ceph_osd
*osd
= con
->private;
2694 struct ceph_osd_client
*osdc
;
2695 int type
= le16_to_cpu(msg
->hdr
.type
);
2702 case CEPH_MSG_OSD_MAP
:
2703 ceph_osdc_handle_map(osdc
, msg
);
2705 case CEPH_MSG_OSD_OPREPLY
:
2706 handle_reply(osdc
, msg
, con
);
2708 case CEPH_MSG_WATCH_NOTIFY
:
2709 handle_watch_notify(osdc
, msg
);
2713 pr_err("received unknown message type %d %s\n", type
,
2714 ceph_msg_type_name(type
));
2721 * lookup and return message for incoming reply. set up reply message
2724 static struct ceph_msg
*get_reply(struct ceph_connection
*con
,
2725 struct ceph_msg_header
*hdr
,
2728 struct ceph_osd
*osd
= con
->private;
2729 struct ceph_osd_client
*osdc
= osd
->o_osdc
;
2731 struct ceph_osd_request
*req
;
2732 int front_len
= le32_to_cpu(hdr
->front_len
);
2733 int data_len
= le32_to_cpu(hdr
->data_len
);
2736 tid
= le64_to_cpu(hdr
->tid
);
2737 mutex_lock(&osdc
->request_mutex
);
2738 req
= __lookup_request(osdc
, tid
);
2742 dout("get_reply unknown tid %llu from osd%d\n", tid
,
2747 if (req
->r_reply
->con
)
2748 dout("%s revoking msg %p from old con %p\n", __func__
,
2749 req
->r_reply
, req
->r_reply
->con
);
2750 ceph_msg_revoke_incoming(req
->r_reply
);
2752 if (front_len
> req
->r_reply
->front_alloc_len
) {
2753 pr_warning("get_reply front %d > preallocated %d (%u#%llu)\n",
2754 front_len
, req
->r_reply
->front_alloc_len
,
2755 (unsigned int)con
->peer_name
.type
,
2756 le64_to_cpu(con
->peer_name
.num
));
2757 m
= ceph_msg_new(CEPH_MSG_OSD_OPREPLY
, front_len
, GFP_NOFS
,
2761 ceph_msg_put(req
->r_reply
);
2764 m
= ceph_msg_get(req
->r_reply
);
2767 struct ceph_osd_data
*osd_data
;
2770 * XXX This is assuming there is only one op containing
2771 * XXX page data. Probably OK for reads, but this
2772 * XXX ought to be done more generally.
2774 osd_data
= osd_req_op_extent_osd_data(req
, 0);
2775 if (osd_data
->type
== CEPH_OSD_DATA_TYPE_PAGES
) {
2776 if (osd_data
->pages
&&
2777 unlikely(osd_data
->length
< data_len
)) {
2779 pr_warning("tid %lld reply has %d bytes "
2780 "we had only %llu bytes ready\n",
2781 tid
, data_len
, osd_data
->length
);
2790 dout("get_reply tid %lld %p\n", tid
, m
);
2793 mutex_unlock(&osdc
->request_mutex
);
2798 static struct ceph_msg
*alloc_msg(struct ceph_connection
*con
,
2799 struct ceph_msg_header
*hdr
,
2802 struct ceph_osd
*osd
= con
->private;
2803 int type
= le16_to_cpu(hdr
->type
);
2804 int front
= le32_to_cpu(hdr
->front_len
);
2808 case CEPH_MSG_OSD_MAP
:
2809 case CEPH_MSG_WATCH_NOTIFY
:
2810 return ceph_msg_new(type
, front
, GFP_NOFS
, false);
2811 case CEPH_MSG_OSD_OPREPLY
:
2812 return get_reply(con
, hdr
, skip
);
2814 pr_info("alloc_msg unexpected msg type %d from osd%d\n", type
,
2822 * Wrappers to refcount containing ceph_osd struct
2824 static struct ceph_connection
*get_osd_con(struct ceph_connection
*con
)
2826 struct ceph_osd
*osd
= con
->private;
2832 static void put_osd_con(struct ceph_connection
*con
)
2834 struct ceph_osd
*osd
= con
->private;
2842 * Note: returned pointer is the address of a structure that's
2843 * managed separately. Caller must *not* attempt to free it.
2845 static struct ceph_auth_handshake
*get_authorizer(struct ceph_connection
*con
,
2846 int *proto
, int force_new
)
2848 struct ceph_osd
*o
= con
->private;
2849 struct ceph_osd_client
*osdc
= o
->o_osdc
;
2850 struct ceph_auth_client
*ac
= osdc
->client
->monc
.auth
;
2851 struct ceph_auth_handshake
*auth
= &o
->o_auth
;
2853 if (force_new
&& auth
->authorizer
) {
2854 ceph_auth_destroy_authorizer(ac
, auth
->authorizer
);
2855 auth
->authorizer
= NULL
;
2857 if (!auth
->authorizer
) {
2858 int ret
= ceph_auth_create_authorizer(ac
, CEPH_ENTITY_TYPE_OSD
,
2861 return ERR_PTR(ret
);
2863 int ret
= ceph_auth_update_authorizer(ac
, CEPH_ENTITY_TYPE_OSD
,
2866 return ERR_PTR(ret
);
2868 *proto
= ac
->protocol
;
2874 static int verify_authorizer_reply(struct ceph_connection
*con
, int len
)
2876 struct ceph_osd
*o
= con
->private;
2877 struct ceph_osd_client
*osdc
= o
->o_osdc
;
2878 struct ceph_auth_client
*ac
= osdc
->client
->monc
.auth
;
2880 return ceph_auth_verify_authorizer_reply(ac
, o
->o_auth
.authorizer
, len
);
2883 static int invalidate_authorizer(struct ceph_connection
*con
)
2885 struct ceph_osd
*o
= con
->private;
2886 struct ceph_osd_client
*osdc
= o
->o_osdc
;
2887 struct ceph_auth_client
*ac
= osdc
->client
->monc
.auth
;
2889 ceph_auth_invalidate_authorizer(ac
, CEPH_ENTITY_TYPE_OSD
);
2890 return ceph_monc_validate_auth(&osdc
->client
->monc
);
2893 static const struct ceph_connection_operations osd_con_ops
= {
2896 .dispatch
= dispatch
,
2897 .get_authorizer
= get_authorizer
,
2898 .verify_authorizer_reply
= verify_authorizer_reply
,
2899 .invalidate_authorizer
= invalidate_authorizer
,
2900 .alloc_msg
= alloc_msg
,