1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
16 #include "osd/OSDMap.h"
19 #include "mon/MonClient.h"
21 #include "msg/Messenger.h"
22 #include "msg/Message.h"
24 #include "messages/MPing.h"
25 #include "messages/MOSDOp.h"
26 #include "messages/MOSDOpReply.h"
27 #include "messages/MOSDBackoff.h"
28 #include "messages/MOSDMap.h"
30 #include "messages/MPoolOp.h"
31 #include "messages/MPoolOpReply.h"
33 #include "messages/MGetPoolStats.h"
34 #include "messages/MGetPoolStatsReply.h"
35 #include "messages/MStatfs.h"
36 #include "messages/MStatfsReply.h"
38 #include "messages/MMonCommand.h"
40 #include "messages/MCommand.h"
41 #include "messages/MCommandReply.h"
43 #include "messages/MWatchNotify.h"
47 #include "common/config.h"
48 #include "common/perf_counters.h"
49 #include "common/scrub_types.h"
50 #include "include/str_list.h"
51 #include "common/errno.h"
52 #include "common/EventTrace.h"
54 using ceph::real_time
;
55 using ceph::real_clock
;
57 using ceph::mono_clock
;
58 using ceph::mono_time
;
63 #define dout_subsys ceph_subsys_objecter
65 #define dout_prefix *_dout << messenger->get_myname() << ".objecter "
69 l_osdc_first
= 123200,
87 l_osdc_osdop_writefull
,
88 l_osdc_osdop_writesame
,
91 l_osdc_osdop_truncate
,
94 l_osdc_osdop_sparse_read
,
95 l_osdc_osdop_clonerange
,
96 l_osdc_osdop_getxattr
,
97 l_osdc_osdop_setxattr
,
98 l_osdc_osdop_cmpxattr
,
100 l_osdc_osdop_resetxattrs
,
101 l_osdc_osdop_tmap_up
,
102 l_osdc_osdop_tmap_put
,
103 l_osdc_osdop_tmap_get
,
107 l_osdc_osdop_src_cmpxattr
,
109 l_osdc_osdop_pgls_filter
,
112 l_osdc_linger_active
,
114 l_osdc_linger_resend
,
117 l_osdc_poolop_active
,
119 l_osdc_poolop_resend
,
121 l_osdc_poolstat_active
,
122 l_osdc_poolstat_send
,
123 l_osdc_poolstat_resend
,
125 l_osdc_statfs_active
,
127 l_osdc_statfs_resend
,
129 l_osdc_command_active
,
131 l_osdc_command_resend
,
138 l_osdc_osd_session_open
,
139 l_osdc_osd_session_close
,
142 l_osdc_osdop_omap_wr
,
143 l_osdc_osdop_omap_rd
,
144 l_osdc_osdop_omap_del
,
150 // config obs ----------------------------
152 static const char *config_keys
[] = {
157 class Objecter::RequestStateHook
: public AdminSocketHook
{
158 Objecter
*m_objecter
;
160 explicit RequestStateHook(Objecter
*objecter
);
161 bool call(std::string command
, cmdmap_t
& cmdmap
, std::string format
,
162 bufferlist
& out
) override
;
166 * This is a more limited form of C_Contexts, but that requires
167 * a ceph_context which we don't have here.
169 class ObjectOperation::C_TwoContexts
: public Context
{
173 C_TwoContexts(Context
*first
, Context
*second
) :
174 first(first
), second(second
) {}
175 void finish(int r
) override
{
182 ~C_TwoContexts() override
{
188 void ObjectOperation::add_handler(Context
*extra
) {
189 size_t last
= out_handler
.size() - 1;
190 Context
*orig
= out_handler
[last
];
192 Context
*wrapper
= new C_TwoContexts(orig
, extra
);
193 out_handler
[last
] = wrapper
;
195 out_handler
[last
] = extra
;
199 Objecter::OSDSession::unique_completion_lock
Objecter::OSDSession::get_lock(
202 if (oid
.name
.empty())
203 return unique_completion_lock();
205 static constexpr uint32_t HASH_PRIME
= 1021;
206 uint32_t h
= ceph_str_hash_linux(oid
.name
.c_str(), oid
.name
.size())
209 return unique_completion_lock(completion_locks
[h
% num_locks
],
213 const char** Objecter::get_tracked_conf_keys() const
219 void Objecter::handle_conf_change(const struct md_config_t
*conf
,
220 const std::set
<std::string
> &changed
)
222 if (changed
.count("crush_location")) {
223 update_crush_location();
227 void Objecter::update_crush_location()
229 unique_lock
wl(rwlock
);
230 crush_location
= cct
->crush_location
.get_location();
233 // messages ------------------------------
236 * initialize only internal data structures, don't initiate cluster interaction
238 void Objecter::init()
240 assert(!initialized
);
243 PerfCountersBuilder
pcb(cct
, "objecter", l_osdc_first
, l_osdc_last
);
245 pcb
.add_u64(l_osdc_op_active
, "op_active", "Operations active", "actv",
246 PerfCountersBuilder::PRIO_CRITICAL
);
247 pcb
.add_u64(l_osdc_op_laggy
, "op_laggy", "Laggy operations");
248 pcb
.add_u64_counter(l_osdc_op_send
, "op_send", "Sent operations");
249 pcb
.add_u64_counter(l_osdc_op_send_bytes
, "op_send_bytes", "Sent data", NULL
, 0, unit_t(BYTES
));
250 pcb
.add_u64_counter(l_osdc_op_resend
, "op_resend", "Resent operations");
251 pcb
.add_u64_counter(l_osdc_op_reply
, "op_reply", "Operation reply");
253 pcb
.add_u64_counter(l_osdc_op
, "op", "Operations");
254 pcb
.add_u64_counter(l_osdc_op_r
, "op_r", "Read operations", "rd",
255 PerfCountersBuilder::PRIO_CRITICAL
);
256 pcb
.add_u64_counter(l_osdc_op_w
, "op_w", "Write operations", "wr",
257 PerfCountersBuilder::PRIO_CRITICAL
);
258 pcb
.add_u64_counter(l_osdc_op_rmw
, "op_rmw", "Read-modify-write operations",
259 "rdwr", PerfCountersBuilder::PRIO_INTERESTING
);
260 pcb
.add_u64_counter(l_osdc_op_pg
, "op_pg", "PG operation");
262 pcb
.add_u64_counter(l_osdc_osdop_stat
, "osdop_stat", "Stat operations");
263 pcb
.add_u64_counter(l_osdc_osdop_create
, "osdop_create",
264 "Create object operations");
265 pcb
.add_u64_counter(l_osdc_osdop_read
, "osdop_read", "Read operations");
266 pcb
.add_u64_counter(l_osdc_osdop_write
, "osdop_write", "Write operations");
267 pcb
.add_u64_counter(l_osdc_osdop_writefull
, "osdop_writefull",
268 "Write full object operations");
269 pcb
.add_u64_counter(l_osdc_osdop_writesame
, "osdop_writesame",
270 "Write same operations");
271 pcb
.add_u64_counter(l_osdc_osdop_append
, "osdop_append",
273 pcb
.add_u64_counter(l_osdc_osdop_zero
, "osdop_zero",
274 "Set object to zero operations");
275 pcb
.add_u64_counter(l_osdc_osdop_truncate
, "osdop_truncate",
276 "Truncate object operations");
277 pcb
.add_u64_counter(l_osdc_osdop_delete
, "osdop_delete",
278 "Delete object operations");
279 pcb
.add_u64_counter(l_osdc_osdop_mapext
, "osdop_mapext",
280 "Map extent operations");
281 pcb
.add_u64_counter(l_osdc_osdop_sparse_read
, "osdop_sparse_read",
282 "Sparse read operations");
283 pcb
.add_u64_counter(l_osdc_osdop_clonerange
, "osdop_clonerange",
284 "Clone range operations");
285 pcb
.add_u64_counter(l_osdc_osdop_getxattr
, "osdop_getxattr",
286 "Get xattr operations");
287 pcb
.add_u64_counter(l_osdc_osdop_setxattr
, "osdop_setxattr",
288 "Set xattr operations");
289 pcb
.add_u64_counter(l_osdc_osdop_cmpxattr
, "osdop_cmpxattr",
290 "Xattr comparison operations");
291 pcb
.add_u64_counter(l_osdc_osdop_rmxattr
, "osdop_rmxattr",
292 "Remove xattr operations");
293 pcb
.add_u64_counter(l_osdc_osdop_resetxattrs
, "osdop_resetxattrs",
294 "Reset xattr operations");
295 pcb
.add_u64_counter(l_osdc_osdop_tmap_up
, "osdop_tmap_up",
296 "TMAP update operations");
297 pcb
.add_u64_counter(l_osdc_osdop_tmap_put
, "osdop_tmap_put",
298 "TMAP put operations");
299 pcb
.add_u64_counter(l_osdc_osdop_tmap_get
, "osdop_tmap_get",
300 "TMAP get operations");
301 pcb
.add_u64_counter(l_osdc_osdop_call
, "osdop_call",
302 "Call (execute) operations");
303 pcb
.add_u64_counter(l_osdc_osdop_watch
, "osdop_watch",
304 "Watch by object operations");
305 pcb
.add_u64_counter(l_osdc_osdop_notify
, "osdop_notify",
306 "Notify about object operations");
307 pcb
.add_u64_counter(l_osdc_osdop_src_cmpxattr
, "osdop_src_cmpxattr",
308 "Extended attribute comparison in multi operations");
309 pcb
.add_u64_counter(l_osdc_osdop_pgls
, "osdop_pgls");
310 pcb
.add_u64_counter(l_osdc_osdop_pgls_filter
, "osdop_pgls_filter");
311 pcb
.add_u64_counter(l_osdc_osdop_other
, "osdop_other", "Other operations");
313 pcb
.add_u64(l_osdc_linger_active
, "linger_active",
314 "Active lingering operations");
315 pcb
.add_u64_counter(l_osdc_linger_send
, "linger_send",
316 "Sent lingering operations");
317 pcb
.add_u64_counter(l_osdc_linger_resend
, "linger_resend",
318 "Resent lingering operations");
319 pcb
.add_u64_counter(l_osdc_linger_ping
, "linger_ping",
320 "Sent pings to lingering operations");
322 pcb
.add_u64(l_osdc_poolop_active
, "poolop_active",
323 "Active pool operations");
324 pcb
.add_u64_counter(l_osdc_poolop_send
, "poolop_send",
325 "Sent pool operations");
326 pcb
.add_u64_counter(l_osdc_poolop_resend
, "poolop_resend",
327 "Resent pool operations");
329 pcb
.add_u64(l_osdc_poolstat_active
, "poolstat_active",
330 "Active get pool stat operations");
331 pcb
.add_u64_counter(l_osdc_poolstat_send
, "poolstat_send",
332 "Pool stat operations sent");
333 pcb
.add_u64_counter(l_osdc_poolstat_resend
, "poolstat_resend",
334 "Resent pool stats");
336 pcb
.add_u64(l_osdc_statfs_active
, "statfs_active", "Statfs operations");
337 pcb
.add_u64_counter(l_osdc_statfs_send
, "statfs_send", "Sent FS stats");
338 pcb
.add_u64_counter(l_osdc_statfs_resend
, "statfs_resend",
341 pcb
.add_u64(l_osdc_command_active
, "command_active", "Active commands");
342 pcb
.add_u64_counter(l_osdc_command_send
, "command_send",
344 pcb
.add_u64_counter(l_osdc_command_resend
, "command_resend",
347 pcb
.add_u64(l_osdc_map_epoch
, "map_epoch", "OSD map epoch");
348 pcb
.add_u64_counter(l_osdc_map_full
, "map_full",
349 "Full OSD maps received");
350 pcb
.add_u64_counter(l_osdc_map_inc
, "map_inc",
351 "Incremental OSD maps received");
353 pcb
.add_u64(l_osdc_osd_sessions
, "osd_sessions",
354 "Open sessions"); // open sessions
355 pcb
.add_u64_counter(l_osdc_osd_session_open
, "osd_session_open",
357 pcb
.add_u64_counter(l_osdc_osd_session_close
, "osd_session_close",
359 pcb
.add_u64(l_osdc_osd_laggy
, "osd_laggy", "Laggy OSD sessions");
361 pcb
.add_u64_counter(l_osdc_osdop_omap_wr
, "omap_wr",
362 "OSD OMAP write operations");
363 pcb
.add_u64_counter(l_osdc_osdop_omap_rd
, "omap_rd",
364 "OSD OMAP read operations");
365 pcb
.add_u64_counter(l_osdc_osdop_omap_del
, "omap_del",
366 "OSD OMAP delete operations");
368 logger
= pcb
.create_perf_counters();
369 cct
->get_perfcounters_collection()->add(logger
);
372 m_request_state_hook
= new RequestStateHook(this);
373 AdminSocket
* admin_socket
= cct
->get_admin_socket();
374 int ret
= admin_socket
->register_command("objecter_requests",
376 m_request_state_hook
,
377 "show in-progress osd requests");
379 /* Don't warn on EEXIST, happens if multiple ceph clients
380 * are instantiated from one process */
381 if (ret
< 0 && ret
!= -EEXIST
) {
382 lderr(cct
) << "error registering admin socket command: "
383 << cpp_strerror(ret
) << dendl
;
386 update_crush_location();
388 cct
->_conf
->add_observer(this);
394 * ok, cluster interaction can happen
396 void Objecter::start(const OSDMap
* o
)
398 shared_lock
rl(rwlock
);
402 osdmap
->deepish_copy_from(*o
);
403 } else if (osdmap
->get_epoch() == 0) {
404 _maybe_request_map();
408 void Objecter::shutdown()
412 unique_lock
wl(rwlock
);
417 cct
->_conf
->remove_observer(this);
420 map
<int,OSDSession
*>::iterator p
;
421 while (!osd_sessions
.empty()) {
422 p
= osd_sessions
.begin();
423 close_session(p
->second
);
426 while(!check_latest_map_lingers
.empty()) {
427 map
<uint64_t, LingerOp
*>::iterator i
= check_latest_map_lingers
.begin();
429 check_latest_map_lingers
.erase(i
->first
);
432 while(!check_latest_map_ops
.empty()) {
433 map
<ceph_tid_t
, Op
*>::iterator i
= check_latest_map_ops
.begin();
435 check_latest_map_ops
.erase(i
->first
);
438 while(!check_latest_map_commands
.empty()) {
439 map
<ceph_tid_t
, CommandOp
*>::iterator i
440 = check_latest_map_commands
.begin();
442 check_latest_map_commands
.erase(i
->first
);
445 while(!poolstat_ops
.empty()) {
446 map
<ceph_tid_t
,PoolStatOp
*>::iterator i
= poolstat_ops
.begin();
448 poolstat_ops
.erase(i
->first
);
451 while(!statfs_ops
.empty()) {
452 map
<ceph_tid_t
, StatfsOp
*>::iterator i
= statfs_ops
.begin();
454 statfs_ops
.erase(i
->first
);
457 while(!pool_ops
.empty()) {
458 map
<ceph_tid_t
, PoolOp
*>::iterator i
= pool_ops
.begin();
460 pool_ops
.erase(i
->first
);
463 ldout(cct
, 20) << __func__
<< " clearing up homeless session..." << dendl
;
464 while(!homeless_session
->linger_ops
.empty()) {
465 std::map
<uint64_t, LingerOp
*>::iterator i
466 = homeless_session
->linger_ops
.begin();
467 ldout(cct
, 10) << " linger_op " << i
->first
<< dendl
;
468 LingerOp
*lop
= i
->second
;
470 OSDSession::unique_lock
swl(homeless_session
->lock
);
471 _session_linger_op_remove(homeless_session
, lop
);
473 linger_ops
.erase(lop
->linger_id
);
474 linger_ops_set
.erase(lop
);
478 while(!homeless_session
->ops
.empty()) {
479 std::map
<ceph_tid_t
, Op
*>::iterator i
= homeless_session
->ops
.begin();
480 ldout(cct
, 10) << " op " << i
->first
<< dendl
;
483 OSDSession::unique_lock
swl(homeless_session
->lock
);
484 _session_op_remove(homeless_session
, op
);
489 while(!homeless_session
->command_ops
.empty()) {
490 std::map
<ceph_tid_t
, CommandOp
*>::iterator i
491 = homeless_session
->command_ops
.begin();
492 ldout(cct
, 10) << " command_op " << i
->first
<< dendl
;
493 CommandOp
*cop
= i
->second
;
495 OSDSession::unique_lock
swl(homeless_session
->lock
);
496 _session_command_op_remove(homeless_session
, cop
);
502 if (timer
.cancel_event(tick_event
)) {
503 ldout(cct
, 10) << " successfully canceled tick" << dendl
;
509 cct
->get_perfcounters_collection()->remove(logger
);
514 // Let go of Objecter write lock so timer thread can shutdown
517 // Outside of lock to avoid cycle WRT calls to RequestStateHook
518 // This is safe because we guarantee no concurrent calls to
519 // shutdown() with the ::initialized check at start.
520 if (m_request_state_hook
) {
521 AdminSocket
* admin_socket
= cct
->get_admin_socket();
522 admin_socket
->unregister_command("objecter_requests");
523 delete m_request_state_hook
;
524 m_request_state_hook
= NULL
;
528 void Objecter::_send_linger(LingerOp
*info
,
531 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
534 Context
*oncommit
= NULL
;
535 LingerOp::shared_lock
watchl(info
->watch_lock
);
536 bufferlist
*poutbl
= NULL
;
537 if (info
->registered
&& info
->is_watch
) {
538 ldout(cct
, 15) << "send_linger " << info
->linger_id
<< " reconnect"
540 opv
.push_back(OSDOp());
541 opv
.back().op
.op
= CEPH_OSD_OP_WATCH
;
542 opv
.back().op
.watch
.cookie
= info
->get_cookie();
543 opv
.back().op
.watch
.op
= CEPH_OSD_WATCH_OP_RECONNECT
;
544 opv
.back().op
.watch
.gen
= ++info
->register_gen
;
545 oncommit
= new C_Linger_Reconnect(this, info
);
547 ldout(cct
, 15) << "send_linger " << info
->linger_id
<< " register"
550 C_Linger_Commit
*c
= new C_Linger_Commit(this, info
);
551 if (!info
->is_watch
) {
558 Op
*o
= new Op(info
->target
.base_oid
, info
->target
.base_oloc
,
559 opv
, info
->target
.flags
| CEPH_OSD_FLAG_READ
,
560 oncommit
, info
->pobjver
);
562 o
->snapid
= info
->snap
;
563 o
->snapc
= info
->snapc
;
564 o
->mtime
= info
->mtime
;
566 o
->target
= info
->target
;
569 // do not resend this; we will send a new op to reregister
570 o
->should_resend
= false;
572 if (info
->register_tid
) {
573 // repeat send. cancel old registeration op, if any.
574 OSDSession::unique_lock
sl(info
->session
->lock
);
575 if (info
->session
->ops
.count(info
->register_tid
)) {
576 Op
*o
= info
->session
->ops
[info
->register_tid
];
577 _op_cancel_map_check(o
);
578 _cancel_linger_op(o
);
582 _op_submit(o
, sul
, &info
->register_tid
);
585 _op_submit_with_budget(o
, sul
, &info
->register_tid
);
588 logger
->inc(l_osdc_linger_send
);
591 void Objecter::_linger_commit(LingerOp
*info
, int r
, bufferlist
& outbl
)
593 LingerOp::unique_lock
wl(info
->watch_lock
);
594 ldout(cct
, 10) << "_linger_commit " << info
->linger_id
<< dendl
;
595 if (info
->on_reg_commit
) {
596 info
->on_reg_commit
->complete(r
);
597 info
->on_reg_commit
= NULL
;
599 if (r
< 0 && info
->on_notify_finish
) {
600 info
->on_notify_finish
->complete(r
);
601 info
->on_notify_finish
= nullptr;
604 // only tell the user the first time we do this
605 info
->registered
= true;
606 info
->pobjver
= NULL
;
608 if (!info
->is_watch
) {
609 // make note of the notify_id
610 bufferlist::iterator p
= outbl
.begin();
612 ::decode(info
->notify_id
, p
);
613 ldout(cct
, 10) << "_linger_commit notify_id=" << info
->notify_id
616 catch (buffer::error
& e
) {
621 struct C_DoWatchError
: public Context
{
623 Objecter::LingerOp
*info
;
625 C_DoWatchError(Objecter
*o
, Objecter::LingerOp
*i
, int r
)
626 : objecter(o
), info(i
), err(r
) {
628 info
->_queued_async();
630 void finish(int r
) override
{
631 Objecter::unique_lock
wl(objecter
->rwlock
);
632 bool canceled
= info
->canceled
;
636 info
->watch_context
->handle_error(info
->get_cookie(), err
);
639 info
->finished_async();
644 int Objecter::_normalize_watch_error(int r
)
646 // translate ENOENT -> ENOTCONN so that a delete->disconnection
647 // notification and a failure to reconnect becuase we raced with
648 // the delete appear the same to the user.
654 void Objecter::_linger_reconnect(LingerOp
*info
, int r
)
656 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
<< " = " << r
657 << " (last_error " << info
->last_error
<< ")" << dendl
;
659 LingerOp::unique_lock
wl(info
->watch_lock
);
660 if (!info
->last_error
) {
661 r
= _normalize_watch_error(r
);
662 info
->last_error
= r
;
663 if (info
->watch_context
) {
664 finisher
->queue(new C_DoWatchError(this, info
, r
));
671 void Objecter::_send_linger_ping(LingerOp
*info
)
673 // rwlock is locked unique
674 // info->session->lock is locked
676 if (cct
->_conf
->objecter_inject_no_watch_ping
) {
677 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
<< " SKIPPING"
681 if (osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
)) {
682 ldout(cct
, 10) << __func__
<< " PAUSERD" << dendl
;
686 ceph::mono_time now
= ceph::mono_clock::now();
687 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
<< " now " << now
690 vector
<OSDOp
> opv(1);
691 opv
[0].op
.op
= CEPH_OSD_OP_WATCH
;
692 opv
[0].op
.watch
.cookie
= info
->get_cookie();
693 opv
[0].op
.watch
.op
= CEPH_OSD_WATCH_OP_PING
;
694 opv
[0].op
.watch
.gen
= info
->register_gen
;
695 C_Linger_Ping
*onack
= new C_Linger_Ping(this, info
);
696 Op
*o
= new Op(info
->target
.base_oid
, info
->target
.base_oloc
,
697 opv
, info
->target
.flags
| CEPH_OSD_FLAG_READ
,
699 o
->target
= info
->target
;
700 o
->should_resend
= false;
702 MOSDOp
*m
= _prepare_osd_op(o
);
704 _session_op_assign(info
->session
, o
);
706 info
->ping_tid
= o
->tid
;
709 logger
->inc(l_osdc_linger_ping
);
712 void Objecter::_linger_ping(LingerOp
*info
, int r
, mono_time sent
,
713 uint32_t register_gen
)
715 LingerOp::unique_lock
l(info
->watch_lock
);
716 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
717 << " sent " << sent
<< " gen " << register_gen
<< " = " << r
718 << " (last_error " << info
->last_error
719 << " register_gen " << info
->register_gen
<< ")" << dendl
;
720 if (info
->register_gen
== register_gen
) {
722 info
->watch_valid_thru
= sent
;
723 } else if (r
< 0 && !info
->last_error
) {
724 r
= _normalize_watch_error(r
);
725 info
->last_error
= r
;
726 if (info
->watch_context
) {
727 finisher
->queue(new C_DoWatchError(this, info
, r
));
731 ldout(cct
, 20) << " ignoring old gen" << dendl
;
735 int Objecter::linger_check(LingerOp
*info
)
737 LingerOp::shared_lock
l(info
->watch_lock
);
739 mono_time stamp
= info
->watch_valid_thru
;
740 if (!info
->watch_pending_async
.empty())
741 stamp
= MIN(info
->watch_valid_thru
, info
->watch_pending_async
.front());
742 auto age
= mono_clock::now() - stamp
;
744 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
745 << " err " << info
->last_error
746 << " age " << age
<< dendl
;
747 if (info
->last_error
)
748 return info
->last_error
;
749 // return a safe upper bound (we are truncating to ms)
751 1 + std::chrono::duration_cast
<std::chrono::milliseconds
>(age
).count();
754 void Objecter::linger_cancel(LingerOp
*info
)
756 unique_lock
wl(rwlock
);
757 _linger_cancel(info
);
761 void Objecter::_linger_cancel(LingerOp
*info
)
763 // rwlock is locked unique
764 ldout(cct
, 20) << __func__
<< " linger_id=" << info
->linger_id
<< dendl
;
765 if (!info
->canceled
) {
766 OSDSession
*s
= info
->session
;
767 OSDSession::unique_lock
sl(s
->lock
);
768 _session_linger_op_remove(s
, info
);
771 linger_ops
.erase(info
->linger_id
);
772 linger_ops_set
.erase(info
);
773 assert(linger_ops
.size() == linger_ops_set
.size());
775 info
->canceled
= true;
778 logger
->dec(l_osdc_linger_active
);
784 Objecter::LingerOp
*Objecter::linger_register(const object_t
& oid
,
785 const object_locator_t
& oloc
,
788 LingerOp
*info
= new LingerOp
;
789 info
->target
.base_oid
= oid
;
790 info
->target
.base_oloc
= oloc
;
791 if (info
->target
.base_oloc
.key
== oid
)
792 info
->target
.base_oloc
.key
.clear();
793 info
->target
.flags
= flags
;
794 info
->watch_valid_thru
= mono_clock::now();
796 unique_lock
l(rwlock
);
799 info
->linger_id
= ++max_linger_id
;
800 ldout(cct
, 10) << __func__
<< " info " << info
801 << " linger_id " << info
->linger_id
802 << " cookie " << info
->get_cookie()
804 linger_ops
[info
->linger_id
] = info
;
805 linger_ops_set
.insert(info
);
806 assert(linger_ops
.size() == linger_ops_set
.size());
808 info
->get(); // for the caller
812 ceph_tid_t
Objecter::linger_watch(LingerOp
*info
,
814 const SnapContext
& snapc
,
820 info
->is_watch
= true;
823 info
->target
.flags
|= CEPH_OSD_FLAG_WRITE
;
827 info
->pobjver
= objver
;
828 info
->on_reg_commit
= oncommit
;
830 shunique_lock
sul(rwlock
, ceph::acquire_unique
);
831 _linger_submit(info
, sul
);
832 logger
->inc(l_osdc_linger_active
);
834 return info
->linger_id
;
837 ceph_tid_t
Objecter::linger_notify(LingerOp
*info
,
839 snapid_t snap
, bufferlist
& inbl
,
845 info
->target
.flags
|= CEPH_OSD_FLAG_READ
;
848 info
->poutbl
= poutbl
;
849 info
->pobjver
= objver
;
850 info
->on_reg_commit
= onfinish
;
852 shunique_lock
sul(rwlock
, ceph::acquire_unique
);
853 _linger_submit(info
, sul
);
854 logger
->inc(l_osdc_linger_active
);
856 return info
->linger_id
;
859 void Objecter::_linger_submit(LingerOp
*info
, shunique_lock
& sul
)
861 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
862 assert(info
->linger_id
);
864 // Populate Op::target
865 OSDSession
*s
= NULL
;
866 _calc_target(&info
->target
, nullptr);
868 // Create LingerOp<->OSDSession relation
869 int r
= _get_session(info
->target
.osd
, &s
, sul
);
871 OSDSession::unique_lock
sl(s
->lock
);
872 _session_linger_op_assign(s
, info
);
876 _send_linger(info
, sul
);
879 struct C_DoWatchNotify
: public Context
{
881 Objecter::LingerOp
*info
;
883 C_DoWatchNotify(Objecter
*o
, Objecter::LingerOp
*i
, MWatchNotify
*m
)
884 : objecter(o
), info(i
), msg(m
) {
886 info
->_queued_async();
889 void finish(int r
) override
{
890 objecter
->_do_watch_notify(info
, msg
);
894 void Objecter::handle_watch_notify(MWatchNotify
*m
)
896 shared_lock
l(rwlock
);
901 LingerOp
*info
= reinterpret_cast<LingerOp
*>(m
->cookie
);
902 if (linger_ops_set
.count(info
) == 0) {
903 ldout(cct
, 7) << __func__
<< " cookie " << m
->cookie
<< " dne" << dendl
;
906 LingerOp::unique_lock
wl(info
->watch_lock
);
907 if (m
->opcode
== CEPH_WATCH_EVENT_DISCONNECT
) {
908 if (!info
->last_error
) {
909 info
->last_error
= -ENOTCONN
;
910 if (info
->watch_context
) {
911 finisher
->queue(new C_DoWatchError(this, info
, -ENOTCONN
));
914 } else if (!info
->is_watch
) {
915 // we have CEPH_WATCH_EVENT_NOTIFY_COMPLETE; we can do this inline
916 // since we know the only user (librados) is safe to call in
917 // fast-dispatch context
918 if (info
->notify_id
&&
919 info
->notify_id
!= m
->notify_id
) {
920 ldout(cct
, 10) << __func__
<< " reply notify " << m
->notify_id
921 << " != " << info
->notify_id
<< ", ignoring" << dendl
;
922 } else if (info
->on_notify_finish
) {
923 info
->notify_result_bl
->claim(m
->get_data());
924 info
->on_notify_finish
->complete(m
->return_code
);
926 // if we race with reconnect we might get a second notify; only
927 // notify the caller once!
928 info
->on_notify_finish
= NULL
;
931 finisher
->queue(new C_DoWatchNotify(this, info
, m
));
935 void Objecter::_do_watch_notify(LingerOp
*info
, MWatchNotify
*m
)
937 ldout(cct
, 10) << __func__
<< " " << *m
<< dendl
;
939 shared_lock
l(rwlock
);
942 if (info
->canceled
) {
947 // notify completion?
948 assert(info
->is_watch
);
949 assert(info
->watch_context
);
950 assert(m
->opcode
!= CEPH_WATCH_EVENT_DISCONNECT
);
955 case CEPH_WATCH_EVENT_NOTIFY
:
956 info
->watch_context
->handle_notify(m
->notify_id
, m
->cookie
,
957 m
->notifier_gid
, m
->bl
);
962 info
->finished_async();
967 bool Objecter::ms_dispatch(Message
*m
)
969 ldout(cct
, 10) << __func__
<< " " << cct
<< " " << *m
<< dendl
;
973 switch (m
->get_type()) {
974 // these we exlusively handle
975 case CEPH_MSG_OSD_OPREPLY
:
976 handle_osd_op_reply(static_cast<MOSDOpReply
*>(m
));
979 case CEPH_MSG_OSD_BACKOFF
:
980 handle_osd_backoff(static_cast<MOSDBackoff
*>(m
));
983 case CEPH_MSG_WATCH_NOTIFY
:
984 handle_watch_notify(static_cast<MWatchNotify
*>(m
));
988 case MSG_COMMAND_REPLY
:
989 if (m
->get_source().type() == CEPH_ENTITY_TYPE_OSD
) {
990 handle_command_reply(static_cast<MCommandReply
*>(m
));
996 case MSG_GETPOOLSTATSREPLY
:
997 handle_get_pool_stats_reply(static_cast<MGetPoolStatsReply
*>(m
));
1000 case CEPH_MSG_POOLOP_REPLY
:
1001 handle_pool_op_reply(static_cast<MPoolOpReply
*>(m
));
1004 case CEPH_MSG_STATFS_REPLY
:
1005 handle_fs_stats_reply(static_cast<MStatfsReply
*>(m
));
1008 // these we give others a chance to inspect
1011 case CEPH_MSG_OSD_MAP
:
1012 handle_osd_map(static_cast<MOSDMap
*>(m
));
1018 void Objecter::_scan_requests(OSDSession
*s
,
1021 map
<int64_t, bool> *pool_full_map
,
1022 map
<ceph_tid_t
, Op
*>& need_resend
,
1023 list
<LingerOp
*>& need_resend_linger
,
1024 map
<ceph_tid_t
, CommandOp
*>& need_resend_command
,
1027 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
1029 list
<LingerOp
*> unregister_lingers
;
1031 OSDSession::unique_lock
sl(s
->lock
);
1033 // check for changed linger mappings (_before_ regular ops)
1034 map
<ceph_tid_t
,LingerOp
*>::iterator lp
= s
->linger_ops
.begin();
1035 while (lp
!= s
->linger_ops
.end()) {
1036 LingerOp
*op
= lp
->second
;
1037 assert(op
->session
== s
);
1038 // check_linger_pool_dne() may touch linger_ops; prevent iterator
1041 ldout(cct
, 10) << " checking linger op " << op
->linger_id
<< dendl
;
1042 bool unregister
, force_resend_writes
= cluster_full
;
1043 int r
= _recalc_linger_op_target(op
, sul
);
1045 force_resend_writes
= force_resend_writes
||
1046 (*pool_full_map
)[op
->target
.base_oloc
.pool
];
1048 case RECALC_OP_TARGET_NO_ACTION
:
1049 if (!force_resend
&& !force_resend_writes
)
1052 case RECALC_OP_TARGET_NEED_RESEND
:
1053 need_resend_linger
.push_back(op
);
1054 _linger_cancel_map_check(op
);
1056 case RECALC_OP_TARGET_POOL_DNE
:
1057 _check_linger_pool_dne(op
, &unregister
);
1059 ldout(cct
, 10) << " need to unregister linger op "
1060 << op
->linger_id
<< dendl
;
1062 unregister_lingers
.push_back(op
);
1068 // check for changed request mappings
1069 map
<ceph_tid_t
,Op
*>::iterator p
= s
->ops
.begin();
1070 while (p
!= s
->ops
.end()) {
1072 ++p
; // check_op_pool_dne() may touch ops; prevent iterator invalidation
1073 ldout(cct
, 10) << " checking op " << op
->tid
<< dendl
;
1074 bool force_resend_writes
= cluster_full
;
1076 force_resend_writes
= force_resend_writes
||
1077 (*pool_full_map
)[op
->target
.base_oloc
.pool
];
1078 int r
= _calc_target(&op
->target
,
1079 op
->session
? op
->session
->con
.get() : nullptr);
1081 case RECALC_OP_TARGET_NO_ACTION
:
1082 if (!force_resend
&& !(force_resend_writes
&& op
->respects_full()))
1085 case RECALC_OP_TARGET_NEED_RESEND
:
1087 _session_op_remove(op
->session
, op
);
1089 need_resend
[op
->tid
] = op
;
1090 _op_cancel_map_check(op
);
1092 case RECALC_OP_TARGET_POOL_DNE
:
1093 _check_op_pool_dne(op
, &sl
);
1099 map
<ceph_tid_t
,CommandOp
*>::iterator cp
= s
->command_ops
.begin();
1100 while (cp
!= s
->command_ops
.end()) {
1101 CommandOp
*c
= cp
->second
;
1103 ldout(cct
, 10) << " checking command " << c
->tid
<< dendl
;
1104 bool force_resend_writes
= cluster_full
;
1106 force_resend_writes
= force_resend_writes
||
1107 (*pool_full_map
)[c
->target_pg
.pool()];
1108 int r
= _calc_command_target(c
, sul
);
1110 case RECALC_OP_TARGET_NO_ACTION
:
1111 // resend if skipped map; otherwise do nothing.
1112 if (!force_resend
&& !force_resend_writes
)
1115 case RECALC_OP_TARGET_NEED_RESEND
:
1116 need_resend_command
[c
->tid
] = c
;
1118 _session_command_op_remove(c
->session
, c
);
1120 _command_cancel_map_check(c
);
1122 case RECALC_OP_TARGET_POOL_DNE
:
1123 case RECALC_OP_TARGET_OSD_DNE
:
1124 case RECALC_OP_TARGET_OSD_DOWN
:
1125 _check_command_map_dne(c
);
1132 for (list
<LingerOp
*>::iterator iter
= unregister_lingers
.begin();
1133 iter
!= unregister_lingers
.end();
1135 _linger_cancel(*iter
);
1140 void Objecter::handle_osd_map(MOSDMap
*m
)
1142 shunique_lock
sul(rwlock
, acquire_unique
);
1148 if (m
->fsid
!= monc
->get_fsid()) {
1149 ldout(cct
, 0) << "handle_osd_map fsid " << m
->fsid
1150 << " != " << monc
->get_fsid() << dendl
;
1154 bool was_pauserd
= osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
);
1155 bool cluster_full
= _osdmap_full_flag();
1156 bool was_pausewr
= osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
) || cluster_full
||
1157 _osdmap_has_pool_full();
1158 map
<int64_t, bool> pool_full_map
;
1159 for (map
<int64_t, pg_pool_t
>::const_iterator it
1160 = osdmap
->get_pools().begin();
1161 it
!= osdmap
->get_pools().end(); ++it
)
1162 pool_full_map
[it
->first
] = _osdmap_pool_full(it
->second
);
1165 list
<LingerOp
*> need_resend_linger
;
1166 map
<ceph_tid_t
, Op
*> need_resend
;
1167 map
<ceph_tid_t
, CommandOp
*> need_resend_command
;
1169 if (m
->get_last() <= osdmap
->get_epoch()) {
1170 ldout(cct
, 3) << "handle_osd_map ignoring epochs ["
1171 << m
->get_first() << "," << m
->get_last()
1172 << "] <= " << osdmap
->get_epoch() << dendl
;
1174 ldout(cct
, 3) << "handle_osd_map got epochs ["
1175 << m
->get_first() << "," << m
->get_last()
1176 << "] > " << osdmap
->get_epoch() << dendl
;
1178 if (osdmap
->get_epoch()) {
1179 bool skipped_map
= false;
1180 // we want incrementals
1181 for (epoch_t e
= osdmap
->get_epoch() + 1;
1185 if (osdmap
->get_epoch() == e
-1 &&
1186 m
->incremental_maps
.count(e
)) {
1187 ldout(cct
, 3) << "handle_osd_map decoding incremental epoch " << e
1189 OSDMap::Incremental
inc(m
->incremental_maps
[e
]);
1190 osdmap
->apply_incremental(inc
);
1192 emit_blacklist_events(inc
);
1194 logger
->inc(l_osdc_map_inc
);
1196 else if (m
->maps
.count(e
)) {
1197 ldout(cct
, 3) << "handle_osd_map decoding full epoch " << e
<< dendl
;
1198 OSDMap
*new_osdmap
= new OSDMap();
1199 new_osdmap
->decode(m
->maps
[e
]);
1201 emit_blacklist_events(*osdmap
, *new_osdmap
);
1203 osdmap
= new_osdmap
;
1205 logger
->inc(l_osdc_map_full
);
1208 if (e
>= m
->get_oldest()) {
1209 ldout(cct
, 3) << "handle_osd_map requesting missing epoch "
1210 << osdmap
->get_epoch()+1 << dendl
;
1211 _maybe_request_map();
1214 ldout(cct
, 3) << "handle_osd_map missing epoch "
1215 << osdmap
->get_epoch()+1
1216 << ", jumping to " << m
->get_oldest() << dendl
;
1217 e
= m
->get_oldest() - 1;
1221 logger
->set(l_osdc_map_epoch
, osdmap
->get_epoch());
1223 cluster_full
= cluster_full
|| _osdmap_full_flag();
1224 update_pool_full_map(pool_full_map
);
1226 // check all outstanding requests on every epoch
1227 _scan_requests(homeless_session
, skipped_map
, cluster_full
,
1228 &pool_full_map
, need_resend
,
1229 need_resend_linger
, need_resend_command
, sul
);
1230 for (map
<int,OSDSession
*>::iterator p
= osd_sessions
.begin();
1231 p
!= osd_sessions
.end(); ) {
1232 OSDSession
*s
= p
->second
;
1233 _scan_requests(s
, skipped_map
, cluster_full
,
1234 &pool_full_map
, need_resend
,
1235 need_resend_linger
, need_resend_command
, sul
);
1237 // osd down or addr change?
1238 if (!osdmap
->is_up(s
->osd
) ||
1240 s
->con
->get_peer_addr() != osdmap
->get_inst(s
->osd
).addr
)) {
1245 assert(e
== osdmap
->get_epoch());
1249 // first map. we want the full thing.
1250 if (m
->maps
.count(m
->get_last())) {
1251 for (map
<int,OSDSession
*>::iterator p
= osd_sessions
.begin();
1252 p
!= osd_sessions
.end(); ++p
) {
1253 OSDSession
*s
= p
->second
;
1254 _scan_requests(s
, false, false, NULL
, need_resend
,
1255 need_resend_linger
, need_resend_command
, sul
);
1257 ldout(cct
, 3) << "handle_osd_map decoding full epoch "
1258 << m
->get_last() << dendl
;
1259 osdmap
->decode(m
->maps
[m
->get_last()]);
1261 _scan_requests(homeless_session
, false, false, NULL
,
1262 need_resend
, need_resend_linger
,
1263 need_resend_command
, sul
);
1265 ldout(cct
, 3) << "handle_osd_map hmm, i want a full map, requesting"
1267 monc
->sub_want("osdmap", 0, CEPH_SUBSCRIBE_ONETIME
);
1273 // make sure need_resend targets reflect latest map
1274 for (auto p
= need_resend
.begin(); p
!= need_resend
.end(); ) {
1276 if (op
->target
.epoch
< osdmap
->get_epoch()) {
1277 ldout(cct
, 10) << __func__
<< " checking op " << p
->first
<< dendl
;
1278 int r
= _calc_target(&op
->target
, nullptr);
1279 if (r
== RECALC_OP_TARGET_POOL_DNE
) {
1280 p
= need_resend
.erase(p
);
1281 _check_op_pool_dne(op
, nullptr);
1290 bool pauserd
= osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
);
1291 bool pausewr
= osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
) || _osdmap_full_flag()
1292 || _osdmap_has_pool_full();
1295 if (was_pauserd
|| was_pausewr
|| pauserd
|| pausewr
||
1296 osdmap
->get_epoch() < epoch_barrier
) {
1297 _maybe_request_map();
1301 for (map
<ceph_tid_t
, Op
*>::iterator p
= need_resend
.begin();
1302 p
!= need_resend
.end(); ++p
) {
1304 OSDSession
*s
= op
->session
;
1305 bool mapped_session
= false;
1307 int r
= _map_session(&op
->target
, &s
, sul
);
1309 mapped_session
= true;
1313 OSDSession::unique_lock
sl(s
->lock
);
1314 if (mapped_session
) {
1315 _session_op_assign(s
, op
);
1317 if (op
->should_resend
) {
1318 if (!op
->session
->is_homeless() && !op
->target
.paused
) {
1319 logger
->inc(l_osdc_op_resend
);
1323 _op_cancel_map_check(op
);
1324 _cancel_linger_op(op
);
1329 for (list
<LingerOp
*>::iterator p
= need_resend_linger
.begin();
1330 p
!= need_resend_linger
.end(); ++p
) {
1333 _calc_target(&op
->target
, nullptr);
1334 OSDSession
*s
= NULL
;
1335 const int r
= _get_session(op
->target
.osd
, &s
, sul
);
1341 if (!op
->session
->is_homeless()) {
1342 logger
->inc(l_osdc_linger_resend
);
1343 _send_linger(op
, sul
);
1346 for (map
<ceph_tid_t
,CommandOp
*>::iterator p
= need_resend_command
.begin();
1347 p
!= need_resend_command
.end(); ++p
) {
1348 CommandOp
*c
= p
->second
;
1349 if (c
->target
.osd
>= 0) {
1350 _assign_command_session(c
, sul
);
1351 if (c
->session
&& !c
->session
->is_homeless()) {
1359 // finish any Contexts that were waiting on a map update
1360 map
<epoch_t
,list
< pair
< Context
*, int > > >::iterator p
=
1361 waiting_for_map
.begin();
1362 while (p
!= waiting_for_map
.end() &&
1363 p
->first
<= osdmap
->get_epoch()) {
1364 //go through the list and call the onfinish methods
1365 for (list
<pair
<Context
*, int> >::iterator i
= p
->second
.begin();
1366 i
!= p
->second
.end(); ++i
) {
1367 i
->first
->complete(i
->second
);
1369 waiting_for_map
.erase(p
++);
1372 monc
->sub_got("osdmap", osdmap
->get_epoch());
1374 if (!waiting_for_map
.empty()) {
1375 _maybe_request_map();
1379 void Objecter::enable_blacklist_events()
1381 unique_lock
wl(rwlock
);
1383 blacklist_events_enabled
= true;
1386 void Objecter::consume_blacklist_events(std::set
<entity_addr_t
> *events
)
1388 unique_lock
wl(rwlock
);
1390 if (events
->empty()) {
1391 events
->swap(blacklist_events
);
1393 for (const auto &i
: blacklist_events
) {
1396 blacklist_events
.clear();
1400 void Objecter::emit_blacklist_events(const OSDMap::Incremental
&inc
)
1402 if (!blacklist_events_enabled
) {
1406 for (const auto &i
: inc
.new_blacklist
) {
1407 blacklist_events
.insert(i
.first
);
1411 void Objecter::emit_blacklist_events(const OSDMap
&old_osd_map
,
1412 const OSDMap
&new_osd_map
)
1414 if (!blacklist_events_enabled
) {
1418 std::set
<entity_addr_t
> old_set
;
1419 std::set
<entity_addr_t
> new_set
;
1421 old_osd_map
.get_blacklist(&old_set
);
1422 new_osd_map
.get_blacklist(&new_set
);
1424 std::set
<entity_addr_t
> delta_set
;
1425 std::set_difference(
1426 new_set
.begin(), new_set
.end(), old_set
.begin(), old_set
.end(),
1427 std::inserter(delta_set
, delta_set
.begin()));
1428 blacklist_events
.insert(delta_set
.begin(), delta_set
.end());
1433 void Objecter::C_Op_Map_Latest::finish(int r
)
1435 if (r
== -EAGAIN
|| r
== -ECANCELED
)
1438 lgeneric_subdout(objecter
->cct
, objecter
, 10)
1439 << "op_map_latest r=" << r
<< " tid=" << tid
1440 << " latest " << latest
<< dendl
;
1442 Objecter::unique_lock
wl(objecter
->rwlock
);
1444 map
<ceph_tid_t
, Op
*>::iterator iter
=
1445 objecter
->check_latest_map_ops
.find(tid
);
1446 if (iter
== objecter
->check_latest_map_ops
.end()) {
1447 lgeneric_subdout(objecter
->cct
, objecter
, 10)
1448 << "op_map_latest op "<< tid
<< " not found" << dendl
;
1452 Op
*op
= iter
->second
;
1453 objecter
->check_latest_map_ops
.erase(iter
);
1455 lgeneric_subdout(objecter
->cct
, objecter
, 20)
1456 << "op_map_latest op "<< op
<< dendl
;
1458 if (op
->map_dne_bound
== 0)
1459 op
->map_dne_bound
= latest
;
1461 OSDSession::unique_lock
sl(op
->session
->lock
, defer_lock
);
1462 objecter
->_check_op_pool_dne(op
, &sl
);
1467 int Objecter::pool_snap_by_name(int64_t poolid
, const char *snap_name
,
1468 snapid_t
*snap
) const
1470 shared_lock
rl(rwlock
);
1472 auto& pools
= osdmap
->get_pools();
1473 auto iter
= pools
.find(poolid
);
1474 if (iter
== pools
.end()) {
1477 const pg_pool_t
& pg_pool
= iter
->second
;
1478 for (auto p
= pg_pool
.snaps
.begin();
1479 p
!= pg_pool
.snaps
.end();
1481 if (p
->second
.name
== snap_name
) {
1489 int Objecter::pool_snap_get_info(int64_t poolid
, snapid_t snap
,
1490 pool_snap_info_t
*info
) const
1492 shared_lock
rl(rwlock
);
1494 auto& pools
= osdmap
->get_pools();
1495 auto iter
= pools
.find(poolid
);
1496 if (iter
== pools
.end()) {
1499 const pg_pool_t
& pg_pool
= iter
->second
;
1500 auto p
= pg_pool
.snaps
.find(snap
);
1501 if (p
== pg_pool
.snaps
.end())
1508 int Objecter::pool_snap_list(int64_t poolid
, vector
<uint64_t> *snaps
)
1510 shared_lock
rl(rwlock
);
1512 const pg_pool_t
*pi
= osdmap
->get_pg_pool(poolid
);
1515 for (map
<snapid_t
,pool_snap_info_t
>::const_iterator p
= pi
->snaps
.begin();
1516 p
!= pi
->snaps
.end();
1518 snaps
->push_back(p
->first
);
1523 // sl may be unlocked.
1524 void Objecter::_check_op_pool_dne(Op
*op
, unique_lock
*sl
)
1526 // rwlock is locked unique
1528 if (op
->target
.pool_ever_existed
) {
1529 // the pool previously existed and now it does not, which means it
1531 op
->map_dne_bound
= osdmap
->get_epoch();
1532 ldout(cct
, 10) << "check_op_pool_dne tid " << op
->tid
1533 << " pool previously exists but now does not"
1536 ldout(cct
, 10) << "check_op_pool_dne tid " << op
->tid
1537 << " current " << osdmap
->get_epoch()
1538 << " map_dne_bound " << op
->map_dne_bound
1541 if (op
->map_dne_bound
> 0) {
1542 if (osdmap
->get_epoch() >= op
->map_dne_bound
) {
1543 // we had a new enough map
1544 ldout(cct
, 10) << "check_op_pool_dne tid " << op
->tid
1545 << " concluding pool " << op
->target
.base_pgid
.pool()
1548 op
->onfinish
->complete(-ENOENT
);
1551 OSDSession
*s
= op
->session
;
1554 assert(sl
->mutex() == &s
->lock
);
1555 bool session_locked
= sl
->owns_lock();
1556 if (!session_locked
) {
1560 if (!session_locked
) {
1564 _finish_op(op
, 0); // no session
1568 _send_op_map_check(op
);
1572 void Objecter::_send_op_map_check(Op
*op
)
1574 // rwlock is locked unique
1576 if (check_latest_map_ops
.count(op
->tid
) == 0) {
1578 check_latest_map_ops
[op
->tid
] = op
;
1579 C_Op_Map_Latest
*c
= new C_Op_Map_Latest(this, op
->tid
);
1580 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
1584 void Objecter::_op_cancel_map_check(Op
*op
)
1586 // rwlock is locked unique
1587 map
<ceph_tid_t
, Op
*>::iterator iter
=
1588 check_latest_map_ops
.find(op
->tid
);
1589 if (iter
!= check_latest_map_ops
.end()) {
1590 Op
*op
= iter
->second
;
1592 check_latest_map_ops
.erase(iter
);
1596 // linger pool check
1598 void Objecter::C_Linger_Map_Latest::finish(int r
)
1600 if (r
== -EAGAIN
|| r
== -ECANCELED
) {
1601 // ignore callback; we will retry in resend_mon_ops()
1605 unique_lock
wl(objecter
->rwlock
);
1607 map
<uint64_t, LingerOp
*>::iterator iter
=
1608 objecter
->check_latest_map_lingers
.find(linger_id
);
1609 if (iter
== objecter
->check_latest_map_lingers
.end()) {
1613 LingerOp
*op
= iter
->second
;
1614 objecter
->check_latest_map_lingers
.erase(iter
);
1616 if (op
->map_dne_bound
== 0)
1617 op
->map_dne_bound
= latest
;
1620 objecter
->_check_linger_pool_dne(op
, &unregister
);
1623 objecter
->_linger_cancel(op
);
1629 void Objecter::_check_linger_pool_dne(LingerOp
*op
, bool *need_unregister
)
1631 // rwlock is locked unique
1633 *need_unregister
= false;
1635 if (op
->register_gen
> 0) {
1636 ldout(cct
, 10) << "_check_linger_pool_dne linger_id " << op
->linger_id
1637 << " pool previously existed but now does not"
1639 op
->map_dne_bound
= osdmap
->get_epoch();
1641 ldout(cct
, 10) << "_check_linger_pool_dne linger_id " << op
->linger_id
1642 << " current " << osdmap
->get_epoch()
1643 << " map_dne_bound " << op
->map_dne_bound
1646 if (op
->map_dne_bound
> 0) {
1647 if (osdmap
->get_epoch() >= op
->map_dne_bound
) {
1648 LingerOp::unique_lock wl
{op
->watch_lock
};
1649 if (op
->on_reg_commit
) {
1650 op
->on_reg_commit
->complete(-ENOENT
);
1651 op
->on_reg_commit
= nullptr;
1653 if (op
->on_notify_finish
) {
1654 op
->on_notify_finish
->complete(-ENOENT
);
1655 op
->on_notify_finish
= nullptr;
1657 *need_unregister
= true;
1660 _send_linger_map_check(op
);
1664 void Objecter::_send_linger_map_check(LingerOp
*op
)
1667 if (check_latest_map_lingers
.count(op
->linger_id
) == 0) {
1669 check_latest_map_lingers
[op
->linger_id
] = op
;
1670 C_Linger_Map_Latest
*c
= new C_Linger_Map_Latest(this, op
->linger_id
);
1671 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
1675 void Objecter::_linger_cancel_map_check(LingerOp
*op
)
1677 // rwlock is locked unique
1679 map
<uint64_t, LingerOp
*>::iterator iter
=
1680 check_latest_map_lingers
.find(op
->linger_id
);
1681 if (iter
!= check_latest_map_lingers
.end()) {
1682 LingerOp
*op
= iter
->second
;
1684 check_latest_map_lingers
.erase(iter
);
1688 // command pool check
1690 void Objecter::C_Command_Map_Latest::finish(int r
)
1692 if (r
== -EAGAIN
|| r
== -ECANCELED
) {
1693 // ignore callback; we will retry in resend_mon_ops()
1697 unique_lock
wl(objecter
->rwlock
);
1699 map
<uint64_t, CommandOp
*>::iterator iter
=
1700 objecter
->check_latest_map_commands
.find(tid
);
1701 if (iter
== objecter
->check_latest_map_commands
.end()) {
1705 CommandOp
*c
= iter
->second
;
1706 objecter
->check_latest_map_commands
.erase(iter
);
1708 if (c
->map_dne_bound
== 0)
1709 c
->map_dne_bound
= latest
;
1711 OSDSession::unique_lock
sul(c
->session
->lock
);
1712 objecter
->_check_command_map_dne(c
);
1718 void Objecter::_check_command_map_dne(CommandOp
*c
)
1720 // rwlock is locked unique
1721 // session is locked unique
1723 ldout(cct
, 10) << "_check_command_map_dne tid " << c
->tid
1724 << " current " << osdmap
->get_epoch()
1725 << " map_dne_bound " << c
->map_dne_bound
1727 if (c
->map_dne_bound
> 0) {
1728 if (osdmap
->get_epoch() >= c
->map_dne_bound
) {
1729 _finish_command(c
, c
->map_check_error
, c
->map_check_error_str
);
1732 _send_command_map_check(c
);
1736 void Objecter::_send_command_map_check(CommandOp
*c
)
1738 // rwlock is locked unique
1739 // session is locked unique
1742 if (check_latest_map_commands
.count(c
->tid
) == 0) {
1744 check_latest_map_commands
[c
->tid
] = c
;
1745 C_Command_Map_Latest
*f
= new C_Command_Map_Latest(this, c
->tid
);
1746 monc
->get_version("osdmap", &f
->latest
, NULL
, f
);
1750 void Objecter::_command_cancel_map_check(CommandOp
*c
)
1752 // rwlock is locked uniqe
1754 map
<uint64_t, CommandOp
*>::iterator iter
=
1755 check_latest_map_commands
.find(c
->tid
);
1756 if (iter
!= check_latest_map_commands
.end()) {
1757 CommandOp
*c
= iter
->second
;
1759 check_latest_map_commands
.erase(iter
);
1765 * Look up OSDSession by OSD id.
1767 * @returns 0 on success, or -EAGAIN if the lock context requires
1768 * promotion to write.
1770 int Objecter::_get_session(int osd
, OSDSession
**session
, shunique_lock
& sul
)
1772 assert(sul
&& sul
.mutex() == &rwlock
);
1775 *session
= homeless_session
;
1776 ldout(cct
, 20) << __func__
<< " osd=" << osd
<< " returning homeless"
1781 map
<int,OSDSession
*>::iterator p
= osd_sessions
.find(osd
);
1782 if (p
!= osd_sessions
.end()) {
1783 OSDSession
*s
= p
->second
;
1786 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << osd
<< " "
1787 << s
->get_nref() << dendl
;
1790 if (!sul
.owns_lock()) {
1793 OSDSession
*s
= new OSDSession(cct
, osd
);
1794 osd_sessions
[osd
] = s
;
1795 s
->con
= messenger
->get_connection(osdmap
->get_inst(osd
));
1796 s
->con
->set_priv(s
->get());
1797 logger
->inc(l_osdc_osd_session_open
);
1798 logger
->set(l_osdc_osd_sessions
, osd_sessions
.size());
1801 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << osd
<< " "
1802 << s
->get_nref() << dendl
;
1806 void Objecter::put_session(Objecter::OSDSession
*s
)
1808 if (s
&& !s
->is_homeless()) {
1809 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << s
->osd
<< " "
1810 << s
->get_nref() << dendl
;
1815 void Objecter::get_session(Objecter::OSDSession
*s
)
1819 if (!s
->is_homeless()) {
1820 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << s
->osd
<< " "
1821 << s
->get_nref() << dendl
;
1826 void Objecter::_reopen_session(OSDSession
*s
)
1828 // rwlock is locked unique
1829 // s->lock is locked
1831 entity_inst_t inst
= osdmap
->get_inst(s
->osd
);
1832 ldout(cct
, 10) << "reopen_session osd." << s
->osd
<< " session, addr now "
1835 s
->con
->set_priv(NULL
);
1836 s
->con
->mark_down();
1837 logger
->inc(l_osdc_osd_session_close
);
1839 s
->con
= messenger
->get_connection(inst
);
1840 s
->con
->set_priv(s
->get());
1842 logger
->inc(l_osdc_osd_session_open
);
1845 void Objecter::close_session(OSDSession
*s
)
1847 // rwlock is locked unique
1849 ldout(cct
, 10) << "close_session for osd." << s
->osd
<< dendl
;
1851 s
->con
->set_priv(NULL
);
1852 s
->con
->mark_down();
1853 logger
->inc(l_osdc_osd_session_close
);
1855 OSDSession::unique_lock
sl(s
->lock
);
1857 std::list
<LingerOp
*> homeless_lingers
;
1858 std::list
<CommandOp
*> homeless_commands
;
1859 std::list
<Op
*> homeless_ops
;
1861 while (!s
->linger_ops
.empty()) {
1862 std::map
<uint64_t, LingerOp
*>::iterator i
= s
->linger_ops
.begin();
1863 ldout(cct
, 10) << " linger_op " << i
->first
<< dendl
;
1864 homeless_lingers
.push_back(i
->second
);
1865 _session_linger_op_remove(s
, i
->second
);
1868 while (!s
->ops
.empty()) {
1869 std::map
<ceph_tid_t
, Op
*>::iterator i
= s
->ops
.begin();
1870 ldout(cct
, 10) << " op " << i
->first
<< dendl
;
1871 homeless_ops
.push_back(i
->second
);
1872 _session_op_remove(s
, i
->second
);
1875 while (!s
->command_ops
.empty()) {
1876 std::map
<ceph_tid_t
, CommandOp
*>::iterator i
= s
->command_ops
.begin();
1877 ldout(cct
, 10) << " command_op " << i
->first
<< dendl
;
1878 homeless_commands
.push_back(i
->second
);
1879 _session_command_op_remove(s
, i
->second
);
1882 osd_sessions
.erase(s
->osd
);
1886 // Assign any leftover ops to the homeless session
1888 OSDSession::unique_lock
hsl(homeless_session
->lock
);
1889 for (std::list
<LingerOp
*>::iterator i
= homeless_lingers
.begin();
1890 i
!= homeless_lingers
.end(); ++i
) {
1891 _session_linger_op_assign(homeless_session
, *i
);
1893 for (std::list
<Op
*>::iterator i
= homeless_ops
.begin();
1894 i
!= homeless_ops
.end(); ++i
) {
1895 _session_op_assign(homeless_session
, *i
);
1897 for (std::list
<CommandOp
*>::iterator i
= homeless_commands
.begin();
1898 i
!= homeless_commands
.end(); ++i
) {
1899 _session_command_op_assign(homeless_session
, *i
);
1903 logger
->set(l_osdc_osd_sessions
, osd_sessions
.size());
1906 void Objecter::wait_for_osd_map()
1908 unique_lock
l(rwlock
);
1909 if (osdmap
->get_epoch()) {
1914 // Leave this since it goes with C_SafeCond
1919 C_SafeCond
*context
= new C_SafeCond(&lock
, &cond
, &done
, NULL
);
1920 waiting_for_map
[0].push_back(pair
<Context
*, int>(context
, 0));
1927 struct C_Objecter_GetVersion
: public Context
{
1929 uint64_t oldest
, newest
;
1931 C_Objecter_GetVersion(Objecter
*o
, Context
*c
)
1932 : objecter(o
), oldest(0), newest(0), fin(c
) {}
1933 void finish(int r
) override
{
1935 objecter
->get_latest_version(oldest
, newest
, fin
);
1936 } else if (r
== -EAGAIN
) { // try again as instructed
1937 objecter
->wait_for_latest_osdmap(fin
);
1939 // it doesn't return any other error codes!
1945 void Objecter::wait_for_latest_osdmap(Context
*fin
)
1947 ldout(cct
, 10) << __func__
<< dendl
;
1948 C_Objecter_GetVersion
*c
= new C_Objecter_GetVersion(this, fin
);
1949 monc
->get_version("osdmap", &c
->newest
, &c
->oldest
, c
);
1952 void Objecter::get_latest_version(epoch_t oldest
, epoch_t newest
, Context
*fin
)
1954 unique_lock
wl(rwlock
);
1955 _get_latest_version(oldest
, newest
, fin
);
1958 void Objecter::_get_latest_version(epoch_t oldest
, epoch_t newest
,
1961 // rwlock is locked unique
1962 if (osdmap
->get_epoch() >= newest
) {
1963 ldout(cct
, 10) << __func__
<< " latest " << newest
<< ", have it" << dendl
;
1969 ldout(cct
, 10) << __func__
<< " latest " << newest
<< ", waiting" << dendl
;
1970 _wait_for_new_map(fin
, newest
, 0);
1973 void Objecter::maybe_request_map()
1975 shared_lock
rl(rwlock
);
1976 _maybe_request_map();
1979 void Objecter::_maybe_request_map()
1983 if (_osdmap_full_flag()
1984 || osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
)
1985 || osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
)) {
1986 ldout(cct
, 10) << "_maybe_request_map subscribing (continuous) to next "
1987 "osd map (FULL flag is set)" << dendl
;
1990 << "_maybe_request_map subscribing (onetime) to next osd map" << dendl
;
1991 flag
= CEPH_SUBSCRIBE_ONETIME
;
1993 epoch_t epoch
= osdmap
->get_epoch() ? osdmap
->get_epoch()+1 : 0;
1994 if (monc
->sub_want("osdmap", epoch
, flag
)) {
1999 void Objecter::_wait_for_new_map(Context
*c
, epoch_t epoch
, int err
)
2001 // rwlock is locked unique
2002 waiting_for_map
[epoch
].push_back(pair
<Context
*, int>(c
, err
));
2003 _maybe_request_map();
2008 * Use this together with wait_for_map: this is a pre-check to avoid
2009 * allocating a Context for wait_for_map if we can see that we
2010 * definitely already have the epoch.
2012 * This does *not* replace the need to handle the return value of
2013 * wait_for_map: just because we don't have it in this pre-check
2014 * doesn't mean we won't have it when calling back into wait_for_map,
2015 * since the objecter lock is dropped in between.
2017 bool Objecter::have_map(const epoch_t epoch
)
2019 shared_lock
rl(rwlock
);
2020 if (osdmap
->get_epoch() >= epoch
) {
2027 bool Objecter::wait_for_map(epoch_t epoch
, Context
*c
, int err
)
2029 unique_lock
wl(rwlock
);
2030 if (osdmap
->get_epoch() >= epoch
) {
2033 _wait_for_new_map(c
, epoch
, err
);
2037 void Objecter::kick_requests(OSDSession
*session
)
2039 ldout(cct
, 10) << "kick_requests for osd." << session
->osd
<< dendl
;
2041 map
<uint64_t, LingerOp
*> lresend
;
2042 unique_lock
wl(rwlock
);
2044 OSDSession::unique_lock
sl(session
->lock
);
2045 _kick_requests(session
, lresend
);
2048 _linger_ops_resend(lresend
, wl
);
2051 void Objecter::_kick_requests(OSDSession
*session
,
2052 map
<uint64_t, LingerOp
*>& lresend
)
2054 // rwlock is locked unique
2057 session
->backoffs
.clear();
2058 session
->backoffs_by_id
.clear();
2061 map
<ceph_tid_t
,Op
*> resend
; // resend in tid order
2062 for (map
<ceph_tid_t
, Op
*>::iterator p
= session
->ops
.begin();
2063 p
!= session
->ops
.end();) {
2066 logger
->inc(l_osdc_op_resend
);
2067 if (op
->should_resend
) {
2068 if (!op
->target
.paused
)
2069 resend
[op
->tid
] = op
;
2071 _op_cancel_map_check(op
);
2072 _cancel_linger_op(op
);
2076 while (!resend
.empty()) {
2077 _send_op(resend
.begin()->second
);
2078 resend
.erase(resend
.begin());
2082 for (map
<ceph_tid_t
, LingerOp
*>::iterator j
= session
->linger_ops
.begin();
2083 j
!= session
->linger_ops
.end(); ++j
) {
2084 LingerOp
*op
= j
->second
;
2086 logger
->inc(l_osdc_linger_resend
);
2087 assert(lresend
.count(j
->first
) == 0);
2088 lresend
[j
->first
] = op
;
2092 map
<uint64_t,CommandOp
*> cresend
; // resend in order
2093 for (map
<ceph_tid_t
, CommandOp
*>::iterator k
= session
->command_ops
.begin();
2094 k
!= session
->command_ops
.end(); ++k
) {
2095 logger
->inc(l_osdc_command_resend
);
2096 cresend
[k
->first
] = k
->second
;
2098 while (!cresend
.empty()) {
2099 _send_command(cresend
.begin()->second
);
2100 cresend
.erase(cresend
.begin());
2104 void Objecter::_linger_ops_resend(map
<uint64_t, LingerOp
*>& lresend
,
2107 assert(ul
.owns_lock());
2108 shunique_lock
sul(std::move(ul
));
2109 while (!lresend
.empty()) {
2110 LingerOp
*op
= lresend
.begin()->second
;
2111 if (!op
->canceled
) {
2112 _send_linger(op
, sul
);
2115 lresend
.erase(lresend
.begin());
2117 ul
= unique_lock(sul
.release_to_unique());
2120 void Objecter::start_tick()
2122 assert(tick_event
== 0);
2124 timer
.add_event(ceph::make_timespan(cct
->_conf
->objecter_tick_interval
),
2125 &Objecter::tick
, this);
2128 void Objecter::tick()
2130 shared_lock
rl(rwlock
);
2132 ldout(cct
, 10) << "tick" << dendl
;
2134 // we are only called by C_Tick
2138 // we raced with shutdown
2139 ldout(cct
, 10) << __func__
<< " raced with shutdown" << dendl
;
2143 set
<OSDSession
*> toping
;
2146 // look for laggy requests
2147 auto cutoff
= ceph::mono_clock::now();
2148 cutoff
-= ceph::make_timespan(cct
->_conf
->objecter_timeout
); // timeout
2150 unsigned laggy_ops
= 0;
2152 for (map
<int,OSDSession
*>::iterator siter
= osd_sessions
.begin();
2153 siter
!= osd_sessions
.end(); ++siter
) {
2154 OSDSession
*s
= siter
->second
;
2155 OSDSession::lock_guard
l(s
->lock
);
2157 for (map
<ceph_tid_t
,Op
*>::iterator p
= s
->ops
.begin();
2161 assert(op
->session
);
2162 if (op
->stamp
< cutoff
) {
2163 ldout(cct
, 2) << " tid " << p
->first
<< " on osd." << op
->session
->osd
2164 << " is laggy" << dendl
;
2169 for (map
<uint64_t,LingerOp
*>::iterator p
= s
->linger_ops
.begin();
2170 p
!= s
->linger_ops
.end();
2172 LingerOp
*op
= p
->second
;
2173 LingerOp::unique_lock
wl(op
->watch_lock
);
2174 assert(op
->session
);
2175 ldout(cct
, 10) << " pinging osd that serves lingering tid " << p
->first
2176 << " (osd." << op
->session
->osd
<< ")" << dendl
;
2178 if (op
->is_watch
&& op
->registered
&& !op
->last_error
)
2179 _send_linger_ping(op
);
2181 for (map
<uint64_t,CommandOp
*>::iterator p
= s
->command_ops
.begin();
2182 p
!= s
->command_ops
.end();
2184 CommandOp
*op
= p
->second
;
2185 assert(op
->session
);
2186 ldout(cct
, 10) << " pinging osd that serves command tid " << p
->first
2187 << " (osd." << op
->session
->osd
<< ")" << dendl
;
2193 if (num_homeless_ops
|| !toping
.empty()) {
2194 _maybe_request_map();
2197 logger
->set(l_osdc_op_laggy
, laggy_ops
);
2198 logger
->set(l_osdc_osd_laggy
, toping
.size());
2200 if (!toping
.empty()) {
2201 // send a ping to these osds, to ensure we detect any session resets
2202 // (osd reply message policy is lossy)
2203 for (set
<OSDSession
*>::const_iterator i
= toping
.begin();
2206 (*i
)->con
->send_message(new MPing
);
2210 // Make sure we don't resechedule if we wake up after shutdown
2212 tick_event
= timer
.reschedule_me(ceph::make_timespan(
2213 cct
->_conf
->objecter_tick_interval
));
2217 void Objecter::resend_mon_ops()
2219 unique_lock
wl(rwlock
);
2221 ldout(cct
, 10) << "resend_mon_ops" << dendl
;
2223 for (map
<ceph_tid_t
,PoolStatOp
*>::iterator p
= poolstat_ops
.begin();
2224 p
!= poolstat_ops
.end();
2226 _poolstat_submit(p
->second
);
2227 logger
->inc(l_osdc_poolstat_resend
);
2230 for (map
<ceph_tid_t
,StatfsOp
*>::iterator p
= statfs_ops
.begin();
2231 p
!= statfs_ops
.end();
2233 _fs_stats_submit(p
->second
);
2234 logger
->inc(l_osdc_statfs_resend
);
2237 for (map
<ceph_tid_t
,PoolOp
*>::iterator p
= pool_ops
.begin();
2238 p
!= pool_ops
.end();
2240 _pool_op_submit(p
->second
);
2241 logger
->inc(l_osdc_poolop_resend
);
2244 for (map
<ceph_tid_t
, Op
*>::iterator p
= check_latest_map_ops
.begin();
2245 p
!= check_latest_map_ops
.end();
2247 C_Op_Map_Latest
*c
= new C_Op_Map_Latest(this, p
->second
->tid
);
2248 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
2251 for (map
<uint64_t, LingerOp
*>::iterator p
= check_latest_map_lingers
.begin();
2252 p
!= check_latest_map_lingers
.end();
2254 C_Linger_Map_Latest
*c
2255 = new C_Linger_Map_Latest(this, p
->second
->linger_id
);
2256 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
2259 for (map
<uint64_t, CommandOp
*>::iterator p
2260 = check_latest_map_commands
.begin();
2261 p
!= check_latest_map_commands
.end();
2263 C_Command_Map_Latest
*c
= new C_Command_Map_Latest(this, p
->second
->tid
);
2264 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
2268 // read | write ---------------------------
2270 void Objecter::op_submit(Op
*op
, ceph_tid_t
*ptid
, int *ctx_budget
)
2272 shunique_lock
rl(rwlock
, ceph::acquire_shared
);
2276 op
->trace
.event("op submit");
2277 _op_submit_with_budget(op
, rl
, ptid
, ctx_budget
);
2280 void Objecter::_op_submit_with_budget(Op
*op
, shunique_lock
& sul
,
2284 assert(initialized
);
2286 assert(op
->ops
.size() == op
->out_bl
.size());
2287 assert(op
->ops
.size() == op
->out_rval
.size());
2288 assert(op
->ops
.size() == op
->out_handler
.size());
2290 // throttle. before we look at any state, because
2291 // _take_op_budget() may drop our lock while it blocks.
2292 if (!op
->ctx_budgeted
|| (ctx_budget
&& (*ctx_budget
== -1))) {
2293 int op_budget
= _take_op_budget(op
, sul
);
2294 // take and pass out the budget for the first OP
2295 // in the context session
2296 if (ctx_budget
&& (*ctx_budget
== -1)) {
2297 *ctx_budget
= op_budget
;
2301 if (osd_timeout
> timespan(0)) {
2303 op
->tid
= ++last_tid
;
2305 op
->ontimeout
= timer
.add_event(osd_timeout
,
2307 op_cancel(tid
, -ETIMEDOUT
); });
2310 _op_submit(op
, sul
, ptid
);
2313 void Objecter::_send_op_account(Op
*op
)
2317 // add to gather set(s)
2321 ldout(cct
, 20) << " note: not requesting reply" << dendl
;
2324 logger
->inc(l_osdc_op_active
);
2325 logger
->inc(l_osdc_op
);
2327 if ((op
->target
.flags
& (CEPH_OSD_FLAG_READ
| CEPH_OSD_FLAG_WRITE
)) ==
2328 (CEPH_OSD_FLAG_READ
|CEPH_OSD_FLAG_WRITE
))
2329 logger
->inc(l_osdc_op_rmw
);
2330 else if (op
->target
.flags
& CEPH_OSD_FLAG_WRITE
)
2331 logger
->inc(l_osdc_op_w
);
2332 else if (op
->target
.flags
& CEPH_OSD_FLAG_READ
)
2333 logger
->inc(l_osdc_op_r
);
2335 if (op
->target
.flags
& CEPH_OSD_FLAG_PGOP
)
2336 logger
->inc(l_osdc_op_pg
);
2338 for (vector
<OSDOp
>::iterator p
= op
->ops
.begin(); p
!= op
->ops
.end(); ++p
) {
2339 int code
= l_osdc_osdop_other
;
2341 case CEPH_OSD_OP_STAT
: code
= l_osdc_osdop_stat
; break;
2342 case CEPH_OSD_OP_CREATE
: code
= l_osdc_osdop_create
; break;
2343 case CEPH_OSD_OP_READ
: code
= l_osdc_osdop_read
; break;
2344 case CEPH_OSD_OP_WRITE
: code
= l_osdc_osdop_write
; break;
2345 case CEPH_OSD_OP_WRITEFULL
: code
= l_osdc_osdop_writefull
; break;
2346 case CEPH_OSD_OP_WRITESAME
: code
= l_osdc_osdop_writesame
; break;
2347 case CEPH_OSD_OP_APPEND
: code
= l_osdc_osdop_append
; break;
2348 case CEPH_OSD_OP_ZERO
: code
= l_osdc_osdop_zero
; break;
2349 case CEPH_OSD_OP_TRUNCATE
: code
= l_osdc_osdop_truncate
; break;
2350 case CEPH_OSD_OP_DELETE
: code
= l_osdc_osdop_delete
; break;
2351 case CEPH_OSD_OP_MAPEXT
: code
= l_osdc_osdop_mapext
; break;
2352 case CEPH_OSD_OP_SPARSE_READ
: code
= l_osdc_osdop_sparse_read
; break;
2353 case CEPH_OSD_OP_GETXATTR
: code
= l_osdc_osdop_getxattr
; break;
2354 case CEPH_OSD_OP_SETXATTR
: code
= l_osdc_osdop_setxattr
; break;
2355 case CEPH_OSD_OP_CMPXATTR
: code
= l_osdc_osdop_cmpxattr
; break;
2356 case CEPH_OSD_OP_RMXATTR
: code
= l_osdc_osdop_rmxattr
; break;
2357 case CEPH_OSD_OP_RESETXATTRS
: code
= l_osdc_osdop_resetxattrs
; break;
2358 case CEPH_OSD_OP_TMAPUP
: code
= l_osdc_osdop_tmap_up
; break;
2359 case CEPH_OSD_OP_TMAPPUT
: code
= l_osdc_osdop_tmap_put
; break;
2360 case CEPH_OSD_OP_TMAPGET
: code
= l_osdc_osdop_tmap_get
; break;
2362 // OMAP read operations
2363 case CEPH_OSD_OP_OMAPGETVALS
:
2364 case CEPH_OSD_OP_OMAPGETKEYS
:
2365 case CEPH_OSD_OP_OMAPGETHEADER
:
2366 case CEPH_OSD_OP_OMAPGETVALSBYKEYS
:
2367 case CEPH_OSD_OP_OMAP_CMP
: code
= l_osdc_osdop_omap_rd
; break;
2369 // OMAP write operations
2370 case CEPH_OSD_OP_OMAPSETVALS
:
2371 case CEPH_OSD_OP_OMAPSETHEADER
: code
= l_osdc_osdop_omap_wr
; break;
2373 // OMAP del operations
2374 case CEPH_OSD_OP_OMAPCLEAR
:
2375 case CEPH_OSD_OP_OMAPRMKEYS
: code
= l_osdc_osdop_omap_del
; break;
2377 case CEPH_OSD_OP_CALL
: code
= l_osdc_osdop_call
; break;
2378 case CEPH_OSD_OP_WATCH
: code
= l_osdc_osdop_watch
; break;
2379 case CEPH_OSD_OP_NOTIFY
: code
= l_osdc_osdop_notify
; break;
2386 void Objecter::_op_submit(Op
*op
, shunique_lock
& sul
, ceph_tid_t
*ptid
)
2390 ldout(cct
, 10) << __func__
<< " op " << op
<< dendl
;
2393 assert(op
->session
== NULL
);
2394 OSDSession
*s
= NULL
;
2396 bool check_for_latest_map
= _calc_target(&op
->target
, nullptr)
2397 == RECALC_OP_TARGET_POOL_DNE
;
2399 // Try to get a session, including a retry if we need to take write lock
2400 int r
= _get_session(op
->target
.osd
, &s
, sul
);
2402 (check_for_latest_map
&& sul
.owns_lock_shared())) {
2403 epoch_t orig_epoch
= osdmap
->get_epoch();
2405 if (cct
->_conf
->objecter_debug_inject_relock_delay
) {
2409 if (orig_epoch
!= osdmap
->get_epoch()) {
2410 // map changed; recalculate mapping
2411 ldout(cct
, 10) << __func__
<< " relock raced with osdmap, recalc target"
2413 check_for_latest_map
= _calc_target(&op
->target
, nullptr)
2414 == RECALC_OP_TARGET_POOL_DNE
;
2424 r
= _get_session(op
->target
.osd
, &s
, sul
);
2427 assert(s
); // may be homeless
2429 _send_op_account(op
);
2433 assert(op
->target
.flags
& (CEPH_OSD_FLAG_READ
|CEPH_OSD_FLAG_WRITE
));
2435 if (osdmap_full_try
) {
2436 op
->target
.flags
|= CEPH_OSD_FLAG_FULL_TRY
;
2439 bool need_send
= false;
2441 if (osdmap
->get_epoch() < epoch_barrier
) {
2442 ldout(cct
, 10) << " barrier, paused " << op
<< " tid " << op
->tid
2444 op
->target
.paused
= true;
2445 _maybe_request_map();
2446 } else if ((op
->target
.flags
& CEPH_OSD_FLAG_WRITE
) &&
2447 osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
)) {
2448 ldout(cct
, 10) << " paused modify " << op
<< " tid " << op
->tid
2450 op
->target
.paused
= true;
2451 _maybe_request_map();
2452 } else if ((op
->target
.flags
& CEPH_OSD_FLAG_READ
) &&
2453 osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
)) {
2454 ldout(cct
, 10) << " paused read " << op
<< " tid " << op
->tid
2456 op
->target
.paused
= true;
2457 _maybe_request_map();
2458 } else if (op
->respects_full() &&
2459 (_osdmap_full_flag() ||
2460 _osdmap_pool_full(op
->target
.base_oloc
.pool
))) {
2461 ldout(cct
, 0) << " FULL, paused modify " << op
<< " tid "
2462 << op
->tid
<< dendl
;
2463 op
->target
.paused
= true;
2464 _maybe_request_map();
2465 } else if (!s
->is_homeless()) {
2468 _maybe_request_map();
2473 m
= _prepare_osd_op(op
);
2476 OSDSession::unique_lock
sl(s
->lock
);
2478 op
->tid
= ++last_tid
;
2480 ldout(cct
, 10) << "_op_submit oid " << op
->target
.base_oid
2481 << " '" << op
->target
.base_oloc
<< "' '"
2482 << op
->target
.target_oloc
<< "' " << op
->ops
<< " tid "
2483 << op
->tid
<< " osd." << (!s
->is_homeless() ? s
->osd
: -1)
2486 _session_op_assign(s
, op
);
2492 // Last chance to touch Op here, after giving up session lock it can
2493 // be freed at any time by response handler.
2494 ceph_tid_t tid
= op
->tid
;
2495 if (check_for_latest_map
) {
2496 _send_op_map_check(op
);
2505 ldout(cct
, 5) << num_in_flight
<< " in flight" << dendl
;
2508 int Objecter::op_cancel(OSDSession
*s
, ceph_tid_t tid
, int r
)
2510 assert(initialized
);
2512 OSDSession::unique_lock
sl(s
->lock
);
2514 map
<ceph_tid_t
, Op
*>::iterator p
= s
->ops
.find(tid
);
2515 if (p
== s
->ops
.end()) {
2516 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne in session "
2522 ldout(cct
, 20) << " revoking rx buffer for " << tid
2523 << " on " << s
->con
<< dendl
;
2524 s
->con
->revoke_rx_buffer(tid
);
2527 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " in session " << s
->osd
2532 op
->onfinish
->complete(r
);
2533 op
->onfinish
= NULL
;
2535 _op_cancel_map_check(op
);
2542 int Objecter::op_cancel(ceph_tid_t tid
, int r
)
2546 unique_lock
wl(rwlock
);
2547 ret
= _op_cancel(tid
, r
);
2552 int Objecter::op_cancel(const vector
<ceph_tid_t
>& tids
, int r
)
2554 unique_lock
wl(rwlock
);
2555 ldout(cct
,10) << __func__
<< " " << tids
<< dendl
;
2556 for (auto tid
: tids
) {
2562 int Objecter::_op_cancel(ceph_tid_t tid
, int r
)
2566 ldout(cct
, 5) << __func__
<< ": cancelling tid " << tid
<< " r=" << r
2571 for (map
<int, OSDSession
*>::iterator siter
= osd_sessions
.begin();
2572 siter
!= osd_sessions
.end(); ++siter
) {
2573 OSDSession
*s
= siter
->second
;
2574 OSDSession::shared_lock
sl(s
->lock
);
2575 if (s
->ops
.find(tid
) != s
->ops
.end()) {
2577 ret
= op_cancel(s
, tid
, r
);
2578 if (ret
== -ENOENT
) {
2579 /* oh no! raced, maybe tid moved to another session, restarting */
2586 ldout(cct
, 5) << __func__
<< ": tid " << tid
2587 << " not found in live sessions" << dendl
;
2589 // Handle case where the op is in homeless session
2590 OSDSession::shared_lock
sl(homeless_session
->lock
);
2591 if (homeless_session
->ops
.find(tid
) != homeless_session
->ops
.end()) {
2593 ret
= op_cancel(homeless_session
, tid
, r
);
2594 if (ret
== -ENOENT
) {
2595 /* oh no! raced, maybe tid moved to another session, restarting */
2604 ldout(cct
, 5) << __func__
<< ": tid " << tid
2605 << " not found in homeless session" << dendl
;
2611 epoch_t
Objecter::op_cancel_writes(int r
, int64_t pool
)
2613 unique_lock
wl(rwlock
);
2615 std::vector
<ceph_tid_t
> to_cancel
;
2618 for (map
<int, OSDSession
*>::iterator siter
= osd_sessions
.begin();
2619 siter
!= osd_sessions
.end(); ++siter
) {
2620 OSDSession
*s
= siter
->second
;
2621 OSDSession::shared_lock
sl(s
->lock
);
2622 for (map
<ceph_tid_t
, Op
*>::iterator op_i
= s
->ops
.begin();
2623 op_i
!= s
->ops
.end(); ++op_i
) {
2624 if (op_i
->second
->target
.flags
& CEPH_OSD_FLAG_WRITE
2625 && (pool
== -1 || op_i
->second
->target
.target_oloc
.pool
== pool
)) {
2626 to_cancel
.push_back(op_i
->first
);
2631 for (std::vector
<ceph_tid_t
>::iterator titer
= to_cancel
.begin();
2632 titer
!= to_cancel
.end();
2634 int cancel_result
= op_cancel(s
, *titer
, r
);
2635 // We hold rwlock across search and cancellation, so cancels
2636 // should always succeed
2637 assert(cancel_result
== 0);
2639 if (!found
&& to_cancel
.size())
2644 const epoch_t epoch
= osdmap
->get_epoch();
2655 bool Objecter::is_pg_changed(
2657 const vector
<int>& oldacting
,
2659 const vector
<int>& newacting
,
2662 if (OSDMap::primary_changed(
2668 if (any_change
&& oldacting
!= newacting
)
2670 return false; // same primary (tho replicas may have changed)
2673 bool Objecter::target_should_be_paused(op_target_t
*t
)
2675 const pg_pool_t
*pi
= osdmap
->get_pg_pool(t
->base_oloc
.pool
);
2676 bool pauserd
= osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
);
2677 bool pausewr
= osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
) ||
2678 _osdmap_full_flag() || _osdmap_pool_full(*pi
);
2680 return (t
->flags
& CEPH_OSD_FLAG_READ
&& pauserd
) ||
2681 (t
->flags
& CEPH_OSD_FLAG_WRITE
&& pausewr
) ||
2682 (osdmap
->get_epoch() < epoch_barrier
);
2686 * Locking public accessor for _osdmap_full_flag
2688 bool Objecter::osdmap_full_flag() const
2690 shared_lock
rl(rwlock
);
2692 return _osdmap_full_flag();
2695 bool Objecter::osdmap_pool_full(const int64_t pool_id
) const
2697 shared_lock
rl(rwlock
);
2699 if (_osdmap_full_flag()) {
2703 return _osdmap_pool_full(pool_id
);
2706 bool Objecter::_osdmap_pool_full(const int64_t pool_id
) const
2708 const pg_pool_t
*pool
= osdmap
->get_pg_pool(pool_id
);
2710 ldout(cct
, 4) << __func__
<< ": DNE pool " << pool_id
<< dendl
;
2714 return _osdmap_pool_full(*pool
);
2717 bool Objecter::_osdmap_has_pool_full() const
2719 for (map
<int64_t, pg_pool_t
>::const_iterator it
2720 = osdmap
->get_pools().begin();
2721 it
!= osdmap
->get_pools().end(); ++it
) {
2722 if (_osdmap_pool_full(it
->second
))
2728 bool Objecter::_osdmap_pool_full(const pg_pool_t
&p
) const
2730 return p
.has_flag(pg_pool_t::FLAG_FULL
) && honor_osdmap_full
;
2734 * Wrapper around osdmap->test_flag for special handling of the FULL flag.
2736 bool Objecter::_osdmap_full_flag() const
2738 // Ignore the FULL flag if the caller has honor_osdmap_full
2739 return osdmap
->test_flag(CEPH_OSDMAP_FULL
) && honor_osdmap_full
;
2742 void Objecter::update_pool_full_map(map
<int64_t, bool>& pool_full_map
)
2744 for (map
<int64_t, pg_pool_t
>::const_iterator it
2745 = osdmap
->get_pools().begin();
2746 it
!= osdmap
->get_pools().end(); ++it
) {
2747 if (pool_full_map
.find(it
->first
) == pool_full_map
.end()) {
2748 pool_full_map
[it
->first
] = _osdmap_pool_full(it
->second
);
2750 pool_full_map
[it
->first
] = _osdmap_pool_full(it
->second
) ||
2751 pool_full_map
[it
->first
];
2756 int64_t Objecter::get_object_hash_position(int64_t pool
, const string
& key
,
2759 shared_lock
rl(rwlock
);
2760 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
2763 return p
->hash_key(key
, ns
);
2766 int64_t Objecter::get_object_pg_hash_position(int64_t pool
, const string
& key
,
2769 shared_lock
rl(rwlock
);
2770 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
2773 return p
->raw_hash_to_pg(p
->hash_key(key
, ns
));
2776 int Objecter::_calc_target(op_target_t
*t
, Connection
*con
, bool any_change
)
2779 bool is_read
= t
->flags
& CEPH_OSD_FLAG_READ
;
2780 bool is_write
= t
->flags
& CEPH_OSD_FLAG_WRITE
;
2781 t
->epoch
= osdmap
->get_epoch();
2782 ldout(cct
,20) << __func__
<< " epoch " << t
->epoch
2783 << " base " << t
->base_oid
<< " " << t
->base_oloc
2784 << " precalc_pgid " << (int)t
->precalc_pgid
2785 << " pgid " << t
->base_pgid
2786 << (is_read
? " is_read" : "")
2787 << (is_write
? " is_write" : "")
2790 const pg_pool_t
*pi
= osdmap
->get_pg_pool(t
->base_oloc
.pool
);
2793 return RECALC_OP_TARGET_POOL_DNE
;
2795 ldout(cct
,30) << __func__
<< " base pi " << pi
2796 << " pg_num " << pi
->get_pg_num() << dendl
;
2798 bool force_resend
= false;
2799 if (osdmap
->get_epoch() == pi
->last_force_op_resend
) {
2800 if (t
->last_force_resend
< pi
->last_force_op_resend
) {
2801 t
->last_force_resend
= pi
->last_force_op_resend
;
2802 force_resend
= true;
2803 } else if (t
->last_force_resend
== 0) {
2804 force_resend
= true;
2809 t
->target_oid
= t
->base_oid
;
2810 t
->target_oloc
= t
->base_oloc
;
2811 if ((t
->flags
& CEPH_OSD_FLAG_IGNORE_OVERLAY
) == 0) {
2812 if (is_read
&& pi
->has_read_tier())
2813 t
->target_oloc
.pool
= pi
->read_tier
;
2814 if (is_write
&& pi
->has_write_tier())
2815 t
->target_oloc
.pool
= pi
->write_tier
;
2816 pi
= osdmap
->get_pg_pool(t
->target_oloc
.pool
);
2819 return RECALC_OP_TARGET_POOL_DNE
;
2824 if (t
->precalc_pgid
) {
2825 assert(t
->flags
& CEPH_OSD_FLAG_IGNORE_OVERLAY
);
2826 assert(t
->base_oid
.name
.empty()); // make sure this is a pg op
2827 assert(t
->base_oloc
.pool
== (int64_t)t
->base_pgid
.pool());
2828 pgid
= t
->base_pgid
;
2830 int ret
= osdmap
->object_locator_to_pg(t
->target_oid
, t
->target_oloc
,
2832 if (ret
== -ENOENT
) {
2834 return RECALC_OP_TARGET_POOL_DNE
;
2837 ldout(cct
,20) << __func__
<< " target " << t
->target_oid
<< " "
2838 << t
->target_oloc
<< " -> pgid " << pgid
<< dendl
;
2839 ldout(cct
,30) << __func__
<< " target pi " << pi
2840 << " pg_num " << pi
->get_pg_num() << dendl
;
2841 t
->pool_ever_existed
= true;
2843 int size
= pi
->size
;
2844 int min_size
= pi
->min_size
;
2845 unsigned pg_num
= pi
->get_pg_num();
2846 int up_primary
, acting_primary
;
2847 vector
<int> up
, acting
;
2848 osdmap
->pg_to_up_acting_osds(pgid
, &up
, &up_primary
,
2849 &acting
, &acting_primary
);
2850 bool sort_bitwise
= osdmap
->test_flag(CEPH_OSDMAP_SORTBITWISE
);
2851 bool recovery_deletes
= osdmap
->test_flag(CEPH_OSDMAP_RECOVERY_DELETES
);
2852 unsigned prev_seed
= ceph_stable_mod(pgid
.ps(), t
->pg_num
, t
->pg_num_mask
);
2853 pg_t
prev_pgid(prev_seed
, pgid
.pool());
2854 if (any_change
&& PastIntervals::is_new_interval(
2871 t
->recovery_deletes
,
2874 force_resend
= true;
2877 bool unpaused
= false;
2878 bool should_be_paused
= target_should_be_paused(t
);
2879 if (t
->paused
&& !should_be_paused
) {
2882 t
->paused
= should_be_paused
;
2884 bool legacy_change
=
2887 t
->acting_primary
, t
->acting
, acting_primary
, acting
,
2888 t
->used_replica
|| any_change
);
2891 split
= prev_pgid
.is_split(t
->pg_num
, pg_num
, nullptr);
2894 if (legacy_change
|| split
|| force_resend
) {
2897 t
->acting_primary
= acting_primary
;
2898 t
->up_primary
= up_primary
;
2901 t
->min_size
= min_size
;
2903 t
->pg_num_mask
= pi
->get_pg_num_mask();
2904 osdmap
->get_primary_shard(
2905 pg_t(ceph_stable_mod(pgid
.ps(), t
->pg_num
, t
->pg_num_mask
), pgid
.pool()),
2907 t
->sort_bitwise
= sort_bitwise
;
2908 t
->recovery_deletes
= recovery_deletes
;
2909 ldout(cct
, 10) << __func__
<< " "
2910 << " raw pgid " << pgid
<< " -> actual " << t
->actual_pgid
2911 << " acting " << acting
2912 << " primary " << acting_primary
<< dendl
;
2913 t
->used_replica
= false;
2914 if (acting_primary
== -1) {
2918 bool read
= is_read
&& !is_write
;
2919 if (read
&& (t
->flags
& CEPH_OSD_FLAG_BALANCE_READS
)) {
2920 int p
= rand() % acting
.size();
2922 t
->used_replica
= true;
2924 ldout(cct
, 10) << " chose random osd." << osd
<< " of " << acting
2926 } else if (read
&& (t
->flags
& CEPH_OSD_FLAG_LOCALIZE_READS
) &&
2927 acting
.size() > 1) {
2928 // look for a local replica. prefer the primary if the
2929 // distance is the same.
2931 int best_locality
= 0;
2932 for (unsigned i
= 0; i
< acting
.size(); ++i
) {
2933 int locality
= osdmap
->crush
->get_common_ancestor_distance(
2934 cct
, acting
[i
], crush_location
);
2935 ldout(cct
, 20) << __func__
<< " localize: rank " << i
2936 << " osd." << acting
[i
]
2937 << " locality " << locality
<< dendl
;
2939 (locality
>= 0 && best_locality
>= 0 &&
2940 locality
< best_locality
) ||
2941 (best_locality
< 0 && locality
>= 0)) {
2943 best_locality
= locality
;
2945 t
->used_replica
= true;
2951 osd
= acting_primary
;
2956 if (legacy_change
|| unpaused
|| force_resend
) {
2957 return RECALC_OP_TARGET_NEED_RESEND
;
2960 (osdmap
->require_osd_release
>= CEPH_RELEASE_LUMINOUS
||
2961 HAVE_FEATURE(osdmap
->get_xinfo(acting_primary
).features
,
2962 RESEND_ON_SPLIT
))) {
2963 return RECALC_OP_TARGET_NEED_RESEND
;
2965 return RECALC_OP_TARGET_NO_ACTION
;
2968 int Objecter::_map_session(op_target_t
*target
, OSDSession
**s
,
2971 _calc_target(target
, nullptr);
2972 return _get_session(target
->osd
, s
, sul
);
2975 void Objecter::_session_op_assign(OSDSession
*to
, Op
*op
)
2977 // to->lock is locked
2978 assert(op
->session
== NULL
);
2983 to
->ops
[op
->tid
] = op
;
2985 if (to
->is_homeless()) {
2989 ldout(cct
, 15) << __func__
<< " " << to
->osd
<< " " << op
->tid
<< dendl
;
2992 void Objecter::_session_op_remove(OSDSession
*from
, Op
*op
)
2994 assert(op
->session
== from
);
2995 // from->lock is locked
2997 if (from
->is_homeless()) {
3001 from
->ops
.erase(op
->tid
);
3005 ldout(cct
, 15) << __func__
<< " " << from
->osd
<< " " << op
->tid
<< dendl
;
3008 void Objecter::_session_linger_op_assign(OSDSession
*to
, LingerOp
*op
)
3010 // to lock is locked unique
3011 assert(op
->session
== NULL
);
3013 if (to
->is_homeless()) {
3019 to
->linger_ops
[op
->linger_id
] = op
;
3021 ldout(cct
, 15) << __func__
<< " " << to
->osd
<< " " << op
->linger_id
3025 void Objecter::_session_linger_op_remove(OSDSession
*from
, LingerOp
*op
)
3027 assert(from
== op
->session
);
3028 // from->lock is locked unique
3030 if (from
->is_homeless()) {
3034 from
->linger_ops
.erase(op
->linger_id
);
3038 ldout(cct
, 15) << __func__
<< " " << from
->osd
<< " " << op
->linger_id
3042 void Objecter::_session_command_op_remove(OSDSession
*from
, CommandOp
*op
)
3044 assert(from
== op
->session
);
3045 // from->lock is locked
3047 if (from
->is_homeless()) {
3051 from
->command_ops
.erase(op
->tid
);
3055 ldout(cct
, 15) << __func__
<< " " << from
->osd
<< " " << op
->tid
<< dendl
;
3058 void Objecter::_session_command_op_assign(OSDSession
*to
, CommandOp
*op
)
3060 // to->lock is locked
3061 assert(op
->session
== NULL
);
3064 if (to
->is_homeless()) {
3070 to
->command_ops
[op
->tid
] = op
;
3072 ldout(cct
, 15) << __func__
<< " " << to
->osd
<< " " << op
->tid
<< dendl
;
3075 int Objecter::_recalc_linger_op_target(LingerOp
*linger_op
,
3078 // rwlock is locked unique
3080 int r
= _calc_target(&linger_op
->target
, nullptr, true);
3081 if (r
== RECALC_OP_TARGET_NEED_RESEND
) {
3082 ldout(cct
, 10) << "recalc_linger_op_target tid " << linger_op
->linger_id
3083 << " pgid " << linger_op
->target
.pgid
3084 << " acting " << linger_op
->target
.acting
<< dendl
;
3086 OSDSession
*s
= NULL
;
3087 r
= _get_session(linger_op
->target
.osd
, &s
, sul
);
3090 if (linger_op
->session
!= s
) {
3091 // NB locking two sessions (s and linger_op->session) at the
3092 // same time here is only safe because we are the only one that
3093 // takes two, and we are holding rwlock for write. Disable
3094 // lockdep because it doesn't know that.
3095 OSDSession::unique_lock
sl(s
->lock
);
3096 _session_linger_op_remove(linger_op
->session
, linger_op
);
3097 _session_linger_op_assign(s
, linger_op
);
3101 return RECALC_OP_TARGET_NEED_RESEND
;
3106 void Objecter::_cancel_linger_op(Op
*op
)
3108 ldout(cct
, 15) << "cancel_op " << op
->tid
<< dendl
;
3110 assert(!op
->should_resend
);
3112 delete op
->onfinish
;
3119 void Objecter::_finish_op(Op
*op
, int r
)
3121 ldout(cct
, 15) << "finish_op " << op
->tid
<< dendl
;
3123 // op->session->lock is locked unique or op->session is null
3125 if (!op
->ctx_budgeted
&& op
->budgeted
)
3128 if (op
->ontimeout
&& r
!= -ETIMEDOUT
)
3129 timer
.cancel_event(op
->ontimeout
);
3132 _session_op_remove(op
->session
, op
);
3135 logger
->dec(l_osdc_op_active
);
3137 assert(check_latest_map_ops
.find(op
->tid
) == check_latest_map_ops
.end());
3144 void Objecter::finish_op(OSDSession
*session
, ceph_tid_t tid
)
3146 ldout(cct
, 15) << "finish_op " << tid
<< dendl
;
3147 shared_lock
rl(rwlock
);
3149 OSDSession::unique_lock
wl(session
->lock
);
3151 map
<ceph_tid_t
, Op
*>::iterator iter
= session
->ops
.find(tid
);
3152 if (iter
== session
->ops
.end())
3155 Op
*op
= iter
->second
;
3160 MOSDOp
*Objecter::_prepare_osd_op(Op
*op
)
3164 int flags
= op
->target
.flags
;
3165 flags
|= CEPH_OSD_FLAG_KNOWN_REDIR
;
3167 // Nothing checks this any longer, but needed for compatibility with
3168 // pre-luminous osds
3169 flags
|= CEPH_OSD_FLAG_ONDISK
;
3171 if (!honor_osdmap_full
)
3172 flags
|= CEPH_OSD_FLAG_FULL_FORCE
;
3174 op
->target
.paused
= false;
3175 op
->stamp
= ceph::mono_clock::now();
3177 hobject_t hobj
= op
->target
.get_hobj();
3178 MOSDOp
*m
= new MOSDOp(client_inc
, op
->tid
,
3179 hobj
, op
->target
.actual_pgid
,
3180 osdmap
->get_epoch(),
3181 flags
, op
->features
);
3183 m
->set_snapid(op
->snapid
);
3184 m
->set_snap_seq(op
->snapc
.seq
);
3185 m
->set_snaps(op
->snapc
.snaps
);
3188 m
->set_mtime(op
->mtime
);
3189 m
->set_retry_attempt(op
->attempts
++);
3191 if (!op
->trace
.valid() && cct
->_conf
->osdc_blkin_trace_all
) {
3192 op
->trace
.init("op", &trace_endpoint
);
3196 m
->set_priority(op
->priority
);
3198 m
->set_priority(cct
->_conf
->osd_client_op_priority
);
3200 if (op
->reqid
!= osd_reqid_t()) {
3201 m
->set_reqid(op
->reqid
);
3204 logger
->inc(l_osdc_op_send
);
3206 for (unsigned i
= 0; i
< m
->ops
.size(); i
++) {
3207 sum
+= m
->ops
[i
].indata
.length();
3209 logger
->inc(l_osdc_op_send_bytes
, sum
);
3214 void Objecter::_send_op(Op
*op
, MOSDOp
*m
)
3217 // op->session->lock is locked
3220 auto p
= op
->session
->backoffs
.find(op
->target
.actual_pgid
);
3221 if (p
!= op
->session
->backoffs
.end()) {
3222 hobject_t hoid
= op
->target
.get_hobj();
3223 auto q
= p
->second
.lower_bound(hoid
);
3224 if (q
!= p
->second
.begin()) {
3226 if (hoid
>= q
->second
.end
) {
3230 if (q
!= p
->second
.end()) {
3231 ldout(cct
, 20) << __func__
<< " ? " << q
->first
<< " [" << q
->second
.begin
3232 << "," << q
->second
.end
<< ")" << dendl
;
3233 int r
= cmp(hoid
, q
->second
.begin
);
3234 if (r
== 0 || (r
> 0 && hoid
< q
->second
.end
)) {
3235 ldout(cct
, 10) << __func__
<< " backoff " << op
->target
.actual_pgid
3236 << " id " << q
->second
.id
<< " on " << hoid
3237 << ", queuing " << op
<< " tid " << op
->tid
<< dendl
;
3244 assert(op
->tid
> 0);
3245 m
= _prepare_osd_op(op
);
3248 if (op
->target
.actual_pgid
!= m
->get_spg()) {
3249 ldout(cct
, 10) << __func__
<< " " << op
->tid
<< " pgid change from "
3250 << m
->get_spg() << " to " << op
->target
.actual_pgid
3251 << ", updating and reencoding" << dendl
;
3252 m
->set_spg(op
->target
.actual_pgid
);
3253 m
->clear_payload(); // reencode
3256 ldout(cct
, 15) << "_send_op " << op
->tid
<< " to "
3257 << op
->target
.actual_pgid
<< " on osd." << op
->session
->osd
3260 ConnectionRef con
= op
->session
->con
;
3263 // preallocated rx buffer?
3265 ldout(cct
, 20) << " revoking rx buffer for " << op
->tid
<< " on "
3266 << op
->con
<< dendl
;
3267 op
->con
->revoke_rx_buffer(op
->tid
);
3270 op
->ontimeout
== 0 && // only post rx_buffer if no timeout; see #9582
3271 op
->outbl
->length()) {
3272 ldout(cct
, 20) << " posting rx buffer for " << op
->tid
<< " on " << con
3275 op
->con
->post_rx_buffer(op
->tid
, *op
->outbl
);
3278 op
->incarnation
= op
->session
->incarnation
;
3280 m
->set_tid(op
->tid
);
3282 if (op
->trace
.valid()) {
3283 m
->trace
.init("op msg", nullptr, &op
->trace
);
3285 op
->session
->con
->send_message(m
);
3288 int Objecter::calc_op_budget(Op
*op
)
3291 for (vector
<OSDOp
>::iterator i
= op
->ops
.begin();
3294 if (i
->op
.op
& CEPH_OSD_OP_MODE_WR
) {
3295 op_budget
+= i
->indata
.length();
3296 } else if (ceph_osd_op_mode_read(i
->op
.op
)) {
3297 if (ceph_osd_op_uses_extent(i
->op
.op
)) {
3298 if ((int64_t)i
->op
.extent
.length
> 0)
3299 op_budget
+= (int64_t)i
->op
.extent
.length
;
3300 } else if (ceph_osd_op_type_attr(i
->op
.op
)) {
3301 op_budget
+= i
->op
.xattr
.name_len
+ i
->op
.xattr
.value_len
;
3308 void Objecter::_throttle_op(Op
*op
,
3312 assert(sul
&& sul
.mutex() == &rwlock
);
3313 bool locked_for_write
= sul
.owns_lock();
3316 op_budget
= calc_op_budget(op
);
3317 if (!op_throttle_bytes
.get_or_fail(op_budget
)) { //couldn't take right now
3319 op_throttle_bytes
.get(op_budget
);
3320 if (locked_for_write
)
3325 if (!op_throttle_ops
.get_or_fail(1)) { //couldn't take right now
3327 op_throttle_ops
.get(1);
3328 if (locked_for_write
)
3335 void Objecter::unregister_op(Op
*op
)
3337 OSDSession::unique_lock
sl(op
->session
->lock
);
3338 op
->session
->ops
.erase(op
->tid
);
3340 put_session(op
->session
);
3346 /* This function DOES put the passed message before returning */
3347 void Objecter::handle_osd_op_reply(MOSDOpReply
*m
)
3349 ldout(cct
, 10) << "in handle_osd_op_reply" << dendl
;
3352 ceph_tid_t tid
= m
->get_tid();
3354 shunique_lock
sul(rwlock
, ceph::acquire_shared
);
3360 ConnectionRef con
= m
->get_connection();
3361 OSDSession
*s
= static_cast<OSDSession
*>(con
->get_priv());
3362 if (!s
|| s
->con
!= con
) {
3363 ldout(cct
, 7) << __func__
<< " no session on con " << con
<< dendl
;
3371 OSDSession::unique_lock
sl(s
->lock
);
3373 map
<ceph_tid_t
, Op
*>::iterator iter
= s
->ops
.find(tid
);
3374 if (iter
== s
->ops
.end()) {
3375 ldout(cct
, 7) << "handle_osd_op_reply " << tid
3376 << (m
->is_ondisk() ? " ondisk" : (m
->is_onnvram() ?
3377 " onnvram" : " ack"))
3378 << " ... stray" << dendl
;
3385 ldout(cct
, 7) << "handle_osd_op_reply " << tid
3386 << (m
->is_ondisk() ? " ondisk" :
3387 (m
->is_onnvram() ? " onnvram" : " ack"))
3388 << " uv " << m
->get_user_version()
3389 << " in " << m
->get_pg()
3390 << " attempt " << m
->get_retry_attempt()
3392 Op
*op
= iter
->second
;
3393 op
->trace
.event("osd op reply");
3395 if (retry_writes_after_first_reply
&& op
->attempts
== 1 &&
3396 (op
->target
.flags
& CEPH_OSD_FLAG_WRITE
)) {
3397 ldout(cct
, 7) << "retrying write after first reply: " << tid
<< dendl
;
3401 _session_op_remove(s
, op
);
3405 _op_submit(op
, sul
, NULL
);
3410 if (m
->get_retry_attempt() >= 0) {
3411 if (m
->get_retry_attempt() != (op
->attempts
- 1)) {
3412 ldout(cct
, 7) << " ignoring reply from attempt "
3413 << m
->get_retry_attempt()
3414 << " from " << m
->get_source_inst()
3415 << "; last attempt " << (op
->attempts
- 1) << " sent to "
3416 << op
->session
->con
->get_peer_addr() << dendl
;
3423 // we don't know the request attempt because the server is old, so
3424 // just accept this one. we may do ACK callbacks we shouldn't
3425 // have, but that is better than doing callbacks out of order.
3428 Context
*onfinish
= 0;
3430 int rc
= m
->get_result();
3432 if (m
->is_redirect_reply()) {
3433 ldout(cct
, 5) << " got redirect reply; redirecting" << dendl
;
3436 _session_op_remove(s
, op
);
3440 // FIXME: two redirects could race and reorder
3443 m
->get_redirect().combine_with_locator(op
->target
.target_oloc
,
3444 op
->target
.target_oid
.name
);
3445 op
->target
.flags
|= (CEPH_OSD_FLAG_REDIRECTED
|
3446 CEPH_OSD_FLAG_IGNORE_CACHE
|
3447 CEPH_OSD_FLAG_IGNORE_OVERLAY
);
3448 _op_submit(op
, sul
, NULL
);
3453 if (rc
== -EAGAIN
) {
3454 ldout(cct
, 7) << " got -EAGAIN, resubmitting" << dendl
;
3457 _session_op_remove(s
, op
);
3462 op
->target
.flags
&= ~(CEPH_OSD_FLAG_BALANCE_READS
|
3463 CEPH_OSD_FLAG_LOCALIZE_READS
);
3464 op
->target
.pgid
= pg_t();
3465 _op_submit(op
, sul
, NULL
);
3473 *op
->objver
= m
->get_user_version();
3474 if (op
->reply_epoch
)
3475 *op
->reply_epoch
= m
->get_map_epoch();
3476 if (op
->data_offset
)
3477 *op
->data_offset
= m
->get_header().data_off
;
3482 op
->con
->revoke_rx_buffer(op
->tid
);
3483 m
->claim_data(*op
->outbl
);
3487 // per-op result demuxing
3488 vector
<OSDOp
> out_ops
;
3489 m
->claim_ops(out_ops
);
3491 if (out_ops
.size() != op
->ops
.size())
3492 ldout(cct
, 0) << "WARNING: tid " << op
->tid
<< " reply ops " << out_ops
3493 << " != request ops " << op
->ops
3494 << " from " << m
->get_source_inst() << dendl
;
3496 vector
<bufferlist
*>::iterator pb
= op
->out_bl
.begin();
3497 vector
<int*>::iterator pr
= op
->out_rval
.begin();
3498 vector
<Context
*>::iterator ph
= op
->out_handler
.begin();
3499 assert(op
->out_bl
.size() == op
->out_rval
.size());
3500 assert(op
->out_bl
.size() == op
->out_handler
.size());
3501 vector
<OSDOp
>::iterator p
= out_ops
.begin();
3502 for (unsigned i
= 0;
3503 p
!= out_ops
.end() && pb
!= op
->out_bl
.end();
3504 ++i
, ++p
, ++pb
, ++pr
, ++ph
) {
3505 ldout(cct
, 10) << " op " << i
<< " rval " << p
->rval
3506 << " len " << p
->outdata
.length() << dendl
;
3509 // set rval before running handlers so that handlers
3510 // can change it if e.g. decoding fails
3512 **pr
= ceph_to_hostos_errno(p
->rval
);
3514 ldout(cct
, 10) << " op " << i
<< " handler " << *ph
<< dendl
;
3515 (*ph
)->complete(ceph_to_hostos_errno(p
->rval
));
3520 // NOTE: we assume that since we only request ONDISK ever we will
3521 // only ever get back one (type of) ack ever.
3525 onfinish
= op
->onfinish
;
3526 op
->onfinish
= NULL
;
3528 logger
->inc(l_osdc_op_reply
);
3530 /* get it before we call _finish_op() */
3531 auto completion_lock
= s
->get_lock(op
->target
.base_oid
);
3533 ldout(cct
, 15) << "handle_osd_op_reply completed tid " << tid
<< dendl
;
3536 ldout(cct
, 5) << num_in_flight
<< " in flight" << dendl
;
3538 // serialize completions
3539 if (completion_lock
.mutex()) {
3540 completion_lock
.lock();
3546 onfinish
->complete(rc
);
3548 if (completion_lock
.mutex()) {
3549 completion_lock
.unlock();
3556 void Objecter::handle_osd_backoff(MOSDBackoff
*m
)
3558 ldout(cct
, 10) << __func__
<< " " << *m
<< dendl
;
3559 shunique_lock
sul(rwlock
, ceph::acquire_shared
);
3565 ConnectionRef con
= m
->get_connection();
3566 OSDSession
*s
= static_cast<OSDSession
*>(con
->get_priv());
3567 if (!s
|| s
->con
!= con
) {
3568 ldout(cct
, 7) << __func__
<< " no session on con " << con
<< dendl
;
3576 s
->put(); // from get_priv() above
3578 OSDSession::unique_lock
sl(s
->lock
);
3581 case CEPH_OSD_BACKOFF_OP_BLOCK
:
3584 OSDBackoff
& b
= s
->backoffs
[m
->pgid
][m
->begin
];
3585 s
->backoffs_by_id
.insert(make_pair(m
->id
, &b
));
3591 // ack with original backoff's epoch so that the osd can discard this if
3592 // there was a pg split.
3593 Message
*r
= new MOSDBackoff(m
->pgid
,
3595 CEPH_OSD_BACKOFF_OP_ACK_BLOCK
,
3596 m
->id
, m
->begin
, m
->end
);
3597 // this priority must match the MOSDOps from _prepare_osd_op
3598 r
->set_priority(cct
->_conf
->osd_client_op_priority
);
3599 con
->send_message(r
);
3603 case CEPH_OSD_BACKOFF_OP_UNBLOCK
:
3605 auto p
= s
->backoffs_by_id
.find(m
->id
);
3606 if (p
!= s
->backoffs_by_id
.end()) {
3607 OSDBackoff
*b
= p
->second
;
3608 if (b
->begin
!= m
->begin
&&
3610 lderr(cct
) << __func__
<< " got " << m
->pgid
<< " id " << m
->id
3612 << m
->begin
<< "," << m
->end
<< ") but backoff is ["
3613 << b
->begin
<< "," << b
->end
<< ")" << dendl
;
3614 // hrmpf, unblock it anyway.
3616 ldout(cct
, 10) << __func__
<< " unblock backoff " << b
->pgid
3618 << " [" << b
->begin
<< "," << b
->end
3620 auto spgp
= s
->backoffs
.find(b
->pgid
);
3621 assert(spgp
!= s
->backoffs
.end());
3622 spgp
->second
.erase(b
->begin
);
3623 if (spgp
->second
.empty()) {
3624 s
->backoffs
.erase(spgp
);
3626 s
->backoffs_by_id
.erase(p
);
3628 // check for any ops to resend
3629 for (auto& q
: s
->ops
) {
3630 if (q
.second
->target
.actual_pgid
== m
->pgid
) {
3631 int r
= q
.second
->target
.contained_by(m
->begin
, m
->end
);
3632 ldout(cct
, 20) << __func__
<< " contained_by " << r
<< " on "
3633 << q
.second
->target
.get_hobj() << dendl
;
3640 lderr(cct
) << __func__
<< " " << m
->pgid
<< " id " << m
->id
3642 << m
->begin
<< "," << m
->end
<< ") but backoff dne" << dendl
;
3648 ldout(cct
, 10) << __func__
<< " unrecognized op " << (int)m
->op
<< dendl
;
3658 uint32_t Objecter::list_nobjects_seek(NListContext
*list_context
,
3661 shared_lock
rl(rwlock
);
3662 list_context
->pos
= hobject_t(object_t(), string(), CEPH_NOSNAP
,
3663 pos
, list_context
->pool_id
, string());
3664 ldout(cct
, 10) << __func__
<< list_context
3665 << " pos " << pos
<< " -> " << list_context
->pos
<< dendl
;
3666 pg_t actual
= osdmap
->raw_pg_to_pg(pg_t(pos
, list_context
->pool_id
));
3667 list_context
->current_pg
= actual
.ps();
3668 list_context
->at_end_of_pool
= false;
3672 uint32_t Objecter::list_nobjects_seek(NListContext
*list_context
,
3673 const hobject_t
& cursor
)
3675 shared_lock
rl(rwlock
);
3676 ldout(cct
, 10) << "list_nobjects_seek " << list_context
<< dendl
;
3677 list_context
->pos
= cursor
;
3678 list_context
->at_end_of_pool
= false;
3679 pg_t actual
= osdmap
->raw_pg_to_pg(pg_t(cursor
.get_hash(), list_context
->pool_id
));
3680 list_context
->current_pg
= actual
.ps();
3681 list_context
->sort_bitwise
= true;
3682 return list_context
->current_pg
;
3685 void Objecter::list_nobjects_get_cursor(NListContext
*list_context
,
3688 shared_lock
rl(rwlock
);
3689 if (list_context
->list
.empty()) {
3690 *cursor
= list_context
->pos
;
3692 const librados::ListObjectImpl
& entry
= list_context
->list
.front();
3693 const string
*key
= (entry
.locator
.empty() ? &entry
.oid
: &entry
.locator
);
3694 uint32_t h
= osdmap
->get_pg_pool(list_context
->pool_id
)->hash_key(*key
, entry
.nspace
);
3695 *cursor
= hobject_t(entry
.oid
, entry
.locator
, list_context
->pool_snap_seq
, h
, list_context
->pool_id
, entry
.nspace
);
3699 void Objecter::list_nobjects(NListContext
*list_context
, Context
*onfinish
)
3701 ldout(cct
, 10) << __func__
<< " pool_id " << list_context
->pool_id
3702 << " pool_snap_seq " << list_context
->pool_snap_seq
3703 << " max_entries " << list_context
->max_entries
3704 << " list_context " << list_context
3705 << " onfinish " << onfinish
3706 << " current_pg " << list_context
->current_pg
3707 << " pos " << list_context
->pos
<< dendl
;
3709 shared_lock
rl(rwlock
);
3710 const pg_pool_t
*pool
= osdmap
->get_pg_pool(list_context
->pool_id
);
3711 if (!pool
) { // pool is gone
3713 put_nlist_context_budget(list_context
);
3714 onfinish
->complete(-ENOENT
);
3717 int pg_num
= pool
->get_pg_num();
3718 bool sort_bitwise
= osdmap
->test_flag(CEPH_OSDMAP_SORTBITWISE
);
3720 if (list_context
->pos
.is_min()) {
3721 list_context
->starting_pg_num
= 0;
3722 list_context
->sort_bitwise
= sort_bitwise
;
3723 list_context
->starting_pg_num
= pg_num
;
3725 if (list_context
->sort_bitwise
!= sort_bitwise
) {
3726 list_context
->pos
= hobject_t(
3727 object_t(), string(), CEPH_NOSNAP
,
3728 list_context
->current_pg
, list_context
->pool_id
, string());
3729 list_context
->sort_bitwise
= sort_bitwise
;
3730 ldout(cct
, 10) << " hobject sort order changed, restarting this pg at "
3731 << list_context
->pos
<< dendl
;
3733 if (list_context
->starting_pg_num
!= pg_num
) {
3734 if (!sort_bitwise
) {
3735 // start reading from the beginning; the pgs have changed
3736 ldout(cct
, 10) << " pg_num changed; restarting with " << pg_num
<< dendl
;
3737 list_context
->pos
= collection_list_handle_t();
3739 list_context
->starting_pg_num
= pg_num
;
3742 if (list_context
->pos
.is_max()) {
3743 ldout(cct
, 20) << __func__
<< " end of pool, list "
3744 << list_context
->list
<< dendl
;
3745 if (list_context
->list
.empty()) {
3746 list_context
->at_end_of_pool
= true;
3748 // release the listing context's budget once all
3749 // OPs (in the session) are finished
3750 put_nlist_context_budget(list_context
);
3751 onfinish
->complete(0);
3756 op
.pg_nls(list_context
->max_entries
, list_context
->filter
,
3757 list_context
->pos
, osdmap
->get_epoch());
3758 list_context
->bl
.clear();
3759 C_NList
*onack
= new C_NList(list_context
, onfinish
, this);
3760 object_locator_t
oloc(list_context
->pool_id
, list_context
->nspace
);
3762 // note current_pg in case we don't have (or lose) SORTBITWISE
3763 list_context
->current_pg
= pool
->raw_hash_to_pg(list_context
->pos
.get_hash());
3766 pg_read(list_context
->current_pg
, oloc
, op
,
3767 &list_context
->bl
, 0, onack
, &onack
->epoch
,
3768 &list_context
->ctx_budget
);
3771 void Objecter::_nlist_reply(NListContext
*list_context
, int r
,
3772 Context
*final_finish
, epoch_t reply_epoch
)
3774 ldout(cct
, 10) << __func__
<< " " << list_context
<< dendl
;
3776 bufferlist::iterator iter
= list_context
->bl
.begin();
3777 pg_nls_response_t response
;
3778 bufferlist extra_info
;
3779 ::decode(response
, iter
);
3781 ::decode(extra_info
, iter
);
3784 // if the osd returns 1 (newer code), or handle MAX, it means we
3785 // hit the end of the pg.
3786 if ((response
.handle
.is_max() || r
== 1) &&
3787 !list_context
->sort_bitwise
) {
3788 // legacy OSD and !sortbitwise, figure out the next PG on our own
3789 ++list_context
->current_pg
;
3790 if (list_context
->current_pg
== list_context
->starting_pg_num
) {
3792 list_context
->pos
= hobject_t::get_max();
3795 list_context
->pos
= hobject_t(object_t(), string(), CEPH_NOSNAP
,
3796 list_context
->current_pg
,
3797 list_context
->pool_id
, string());
3800 list_context
->pos
= response
.handle
;
3803 int response_size
= response
.entries
.size();
3804 ldout(cct
, 20) << " response.entries.size " << response_size
3805 << ", response.entries " << response
.entries
3806 << ", handle " << response
.handle
3807 << ", tentative new pos " << list_context
->pos
<< dendl
;
3808 list_context
->extra_info
.append(extra_info
);
3809 if (response_size
) {
3810 list_context
->list
.splice(list_context
->list
.end(), response
.entries
);
3813 if (list_context
->list
.size() >= list_context
->max_entries
) {
3814 ldout(cct
, 20) << " hit max, returning results so far, "
3815 << list_context
->list
<< dendl
;
3816 // release the listing context's budget once all
3817 // OPs (in the session) are finished
3818 put_nlist_context_budget(list_context
);
3819 final_finish
->complete(0);
3824 list_nobjects(list_context
, final_finish
);
3827 void Objecter::put_nlist_context_budget(NListContext
*list_context
)
3829 if (list_context
->ctx_budget
>= 0) {
3830 ldout(cct
, 10) << " release listing context's budget " <<
3831 list_context
->ctx_budget
<< dendl
;
3832 put_op_budget_bytes(list_context
->ctx_budget
);
3833 list_context
->ctx_budget
= -1;
3839 int Objecter::create_pool_snap(int64_t pool
, string
& snap_name
,
3842 unique_lock
wl(rwlock
);
3843 ldout(cct
, 10) << "create_pool_snap; pool: " << pool
<< "; snap: "
3844 << snap_name
<< dendl
;
3846 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
3849 if (p
->snap_exists(snap_name
.c_str()))
3852 PoolOp
*op
= new PoolOp
;
3855 op
->tid
= ++last_tid
;
3857 op
->name
= snap_name
;
3858 op
->onfinish
= onfinish
;
3859 op
->pool_op
= POOL_OP_CREATE_SNAP
;
3860 pool_ops
[op
->tid
] = op
;
3867 struct C_SelfmanagedSnap
: public Context
{
3871 C_SelfmanagedSnap(snapid_t
*ps
, Context
*f
) : psnapid(ps
), fin(f
) {}
3872 void finish(int r
) override
{
3874 bufferlist::iterator p
= bl
.begin();
3875 ::decode(*psnapid
, p
);
3881 int Objecter::allocate_selfmanaged_snap(int64_t pool
, snapid_t
*psnapid
,
3884 unique_lock
wl(rwlock
);
3885 ldout(cct
, 10) << "allocate_selfmanaged_snap; pool: " << pool
<< dendl
;
3886 PoolOp
*op
= new PoolOp
;
3887 if (!op
) return -ENOMEM
;
3888 op
->tid
= ++last_tid
;
3890 C_SelfmanagedSnap
*fin
= new C_SelfmanagedSnap(psnapid
, onfinish
);
3893 op
->pool_op
= POOL_OP_CREATE_UNMANAGED_SNAP
;
3894 pool_ops
[op
->tid
] = op
;
3900 int Objecter::delete_pool_snap(int64_t pool
, string
& snap_name
,
3903 unique_lock
wl(rwlock
);
3904 ldout(cct
, 10) << "delete_pool_snap; pool: " << pool
<< "; snap: "
3905 << snap_name
<< dendl
;
3907 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
3910 if (!p
->snap_exists(snap_name
.c_str()))
3913 PoolOp
*op
= new PoolOp
;
3916 op
->tid
= ++last_tid
;
3918 op
->name
= snap_name
;
3919 op
->onfinish
= onfinish
;
3920 op
->pool_op
= POOL_OP_DELETE_SNAP
;
3921 pool_ops
[op
->tid
] = op
;
3928 int Objecter::delete_selfmanaged_snap(int64_t pool
, snapid_t snap
,
3931 unique_lock
wl(rwlock
);
3932 ldout(cct
, 10) << "delete_selfmanaged_snap; pool: " << pool
<< "; snap: "
3934 PoolOp
*op
= new PoolOp
;
3935 if (!op
) return -ENOMEM
;
3936 op
->tid
= ++last_tid
;
3938 op
->onfinish
= onfinish
;
3939 op
->pool_op
= POOL_OP_DELETE_UNMANAGED_SNAP
;
3941 pool_ops
[op
->tid
] = op
;
3948 int Objecter::create_pool(string
& name
, Context
*onfinish
, uint64_t auid
,
3951 unique_lock
wl(rwlock
);
3952 ldout(cct
, 10) << "create_pool name=" << name
<< dendl
;
3954 if (osdmap
->lookup_pg_pool_name(name
) >= 0)
3957 PoolOp
*op
= new PoolOp
;
3960 op
->tid
= ++last_tid
;
3963 op
->onfinish
= onfinish
;
3964 op
->pool_op
= POOL_OP_CREATE
;
3965 pool_ops
[op
->tid
] = op
;
3967 op
->crush_rule
= crush_rule
;
3974 int Objecter::delete_pool(int64_t pool
, Context
*onfinish
)
3976 unique_lock
wl(rwlock
);
3977 ldout(cct
, 10) << "delete_pool " << pool
<< dendl
;
3979 if (!osdmap
->have_pg_pool(pool
))
3982 _do_delete_pool(pool
, onfinish
);
3986 int Objecter::delete_pool(const string
&pool_name
, Context
*onfinish
)
3988 unique_lock
wl(rwlock
);
3989 ldout(cct
, 10) << "delete_pool " << pool_name
<< dendl
;
3991 int64_t pool
= osdmap
->lookup_pg_pool_name(pool_name
);
3995 _do_delete_pool(pool
, onfinish
);
3999 void Objecter::_do_delete_pool(int64_t pool
, Context
*onfinish
)
4001 PoolOp
*op
= new PoolOp
;
4002 op
->tid
= ++last_tid
;
4004 op
->name
= "delete";
4005 op
->onfinish
= onfinish
;
4006 op
->pool_op
= POOL_OP_DELETE
;
4007 pool_ops
[op
->tid
] = op
;
4012 * change the auid owner of a pool by contacting the monitor.
4013 * This requires the current connection to have write permissions
4014 * on both the pool's current auid and the new (parameter) auid.
4015 * Uses the standard Context callback when done.
4017 int Objecter::change_pool_auid(int64_t pool
, Context
*onfinish
, uint64_t auid
)
4019 unique_lock
wl(rwlock
);
4020 ldout(cct
, 10) << "change_pool_auid " << pool
<< " to " << auid
<< dendl
;
4021 PoolOp
*op
= new PoolOp
;
4022 if (!op
) return -ENOMEM
;
4023 op
->tid
= ++last_tid
;
4025 op
->name
= "change_pool_auid";
4026 op
->onfinish
= onfinish
;
4027 op
->pool_op
= POOL_OP_AUID_CHANGE
;
4029 pool_ops
[op
->tid
] = op
;
4031 logger
->set(l_osdc_poolop_active
, pool_ops
.size());
4037 void Objecter::pool_op_submit(PoolOp
*op
)
4040 if (mon_timeout
> timespan(0)) {
4041 op
->ontimeout
= timer
.add_event(mon_timeout
,
4043 pool_op_cancel(op
->tid
, -ETIMEDOUT
); });
4045 _pool_op_submit(op
);
4048 void Objecter::_pool_op_submit(PoolOp
*op
)
4050 // rwlock is locked unique
4052 ldout(cct
, 10) << "pool_op_submit " << op
->tid
<< dendl
;
4053 MPoolOp
*m
= new MPoolOp(monc
->get_fsid(), op
->tid
, op
->pool
,
4054 op
->name
, op
->pool_op
,
4055 op
->auid
, last_seen_osdmap_version
);
4056 if (op
->snapid
) m
->snapid
= op
->snapid
;
4057 if (op
->crush_rule
) m
->crush_rule
= op
->crush_rule
;
4058 monc
->send_mon_message(m
);
4059 op
->last_submit
= ceph::mono_clock::now();
4061 logger
->inc(l_osdc_poolop_send
);
4065 * Handle a reply to a PoolOp message. Check that we sent the message
4066 * and give the caller responsibility for the returned bufferlist.
4067 * Then either call the finisher or stash the PoolOp, depending on if we
4068 * have a new enough map.
4069 * Lastly, clean up the message and PoolOp.
4071 void Objecter::handle_pool_op_reply(MPoolOpReply
*m
)
4074 shunique_lock
sul(rwlock
, acquire_shared
);
4081 ldout(cct
, 10) << "handle_pool_op_reply " << *m
<< dendl
;
4082 ceph_tid_t tid
= m
->get_tid();
4083 map
<ceph_tid_t
, PoolOp
*>::iterator iter
= pool_ops
.find(tid
);
4084 if (iter
!= pool_ops
.end()) {
4085 PoolOp
*op
= iter
->second
;
4086 ldout(cct
, 10) << "have request " << tid
<< " at " << op
<< " Op: "
4087 << ceph_pool_op_name(op
->pool_op
) << dendl
;
4089 op
->blp
->claim(m
->response_data
);
4090 if (m
->version
> last_seen_osdmap_version
)
4091 last_seen_osdmap_version
= m
->version
;
4092 if (osdmap
->get_epoch() < m
->epoch
) {
4095 // recheck op existence since we have let go of rwlock
4096 // (for promotion) above.
4097 iter
= pool_ops
.find(tid
);
4098 if (iter
== pool_ops
.end())
4099 goto done
; // op is gone.
4100 if (osdmap
->get_epoch() < m
->epoch
) {
4101 ldout(cct
, 20) << "waiting for client to reach epoch " << m
->epoch
4102 << " before calling back" << dendl
;
4103 _wait_for_new_map(op
->onfinish
, m
->epoch
, m
->replyCode
);
4105 // map epoch changed, probably because a MOSDMap message
4106 // sneaked in. Do caller-specified callback now or else
4107 // we lose it forever.
4108 assert(op
->onfinish
);
4109 op
->onfinish
->complete(m
->replyCode
);
4112 assert(op
->onfinish
);
4113 op
->onfinish
->complete(m
->replyCode
);
4115 op
->onfinish
= NULL
;
4116 if (!sul
.owns_lock()) {
4120 iter
= pool_ops
.find(tid
);
4121 if (iter
!= pool_ops
.end()) {
4122 _finish_pool_op(op
, 0);
4125 ldout(cct
, 10) << "unknown request " << tid
<< dendl
;
4129 // Not strictly necessary, since we'll release it on return.
4132 ldout(cct
, 10) << "done" << dendl
;
4136 int Objecter::pool_op_cancel(ceph_tid_t tid
, int r
)
4138 assert(initialized
);
4140 unique_lock
wl(rwlock
);
4142 map
<ceph_tid_t
, PoolOp
*>::iterator it
= pool_ops
.find(tid
);
4143 if (it
== pool_ops
.end()) {
4144 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4148 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4150 PoolOp
*op
= it
->second
;
4152 op
->onfinish
->complete(r
);
4154 _finish_pool_op(op
, r
);
4158 void Objecter::_finish_pool_op(PoolOp
*op
, int r
)
4160 // rwlock is locked unique
4161 pool_ops
.erase(op
->tid
);
4162 logger
->set(l_osdc_poolop_active
, pool_ops
.size());
4164 if (op
->ontimeout
&& r
!= -ETIMEDOUT
) {
4165 timer
.cancel_event(op
->ontimeout
);
4173 void Objecter::get_pool_stats(list
<string
>& pools
,
4174 map
<string
,pool_stat_t
> *result
,
4177 ldout(cct
, 10) << "get_pool_stats " << pools
<< dendl
;
4179 PoolStatOp
*op
= new PoolStatOp
;
4180 op
->tid
= ++last_tid
;
4182 op
->pool_stats
= result
;
4183 op
->onfinish
= onfinish
;
4184 if (mon_timeout
> timespan(0)) {
4185 op
->ontimeout
= timer
.add_event(mon_timeout
,
4187 pool_stat_op_cancel(op
->tid
,
4193 unique_lock
wl(rwlock
);
4195 poolstat_ops
[op
->tid
] = op
;
4197 logger
->set(l_osdc_poolstat_active
, poolstat_ops
.size());
4199 _poolstat_submit(op
);
4202 void Objecter::_poolstat_submit(PoolStatOp
*op
)
4204 ldout(cct
, 10) << "_poolstat_submit " << op
->tid
<< dendl
;
4205 monc
->send_mon_message(new MGetPoolStats(monc
->get_fsid(), op
->tid
,
4207 last_seen_pgmap_version
));
4208 op
->last_submit
= ceph::mono_clock::now();
4210 logger
->inc(l_osdc_poolstat_send
);
4213 void Objecter::handle_get_pool_stats_reply(MGetPoolStatsReply
*m
)
4215 ldout(cct
, 10) << "handle_get_pool_stats_reply " << *m
<< dendl
;
4216 ceph_tid_t tid
= m
->get_tid();
4218 unique_lock
wl(rwlock
);
4224 map
<ceph_tid_t
, PoolStatOp
*>::iterator iter
= poolstat_ops
.find(tid
);
4225 if (iter
!= poolstat_ops
.end()) {
4226 PoolStatOp
*op
= poolstat_ops
[tid
];
4227 ldout(cct
, 10) << "have request " << tid
<< " at " << op
<< dendl
;
4228 *op
->pool_stats
= m
->pool_stats
;
4229 if (m
->version
> last_seen_pgmap_version
) {
4230 last_seen_pgmap_version
= m
->version
;
4232 op
->onfinish
->complete(0);
4233 _finish_pool_stat_op(op
, 0);
4235 ldout(cct
, 10) << "unknown request " << tid
<< dendl
;
4237 ldout(cct
, 10) << "done" << dendl
;
4241 int Objecter::pool_stat_op_cancel(ceph_tid_t tid
, int r
)
4243 assert(initialized
);
4245 unique_lock
wl(rwlock
);
4247 map
<ceph_tid_t
, PoolStatOp
*>::iterator it
= poolstat_ops
.find(tid
);
4248 if (it
== poolstat_ops
.end()) {
4249 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4253 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4255 PoolStatOp
*op
= it
->second
;
4257 op
->onfinish
->complete(r
);
4258 _finish_pool_stat_op(op
, r
);
4262 void Objecter::_finish_pool_stat_op(PoolStatOp
*op
, int r
)
4264 // rwlock is locked unique
4266 poolstat_ops
.erase(op
->tid
);
4267 logger
->set(l_osdc_poolstat_active
, poolstat_ops
.size());
4269 if (op
->ontimeout
&& r
!= -ETIMEDOUT
)
4270 timer
.cancel_event(op
->ontimeout
);
4275 void Objecter::get_fs_stats(ceph_statfs
& result
,
4276 boost::optional
<int64_t> data_pool
,
4279 ldout(cct
, 10) << "get_fs_stats" << dendl
;
4280 unique_lock
l(rwlock
);
4282 StatfsOp
*op
= new StatfsOp
;
4283 op
->tid
= ++last_tid
;
4284 op
->stats
= &result
;
4285 op
->data_pool
= data_pool
;
4286 op
->onfinish
= onfinish
;
4287 if (mon_timeout
> timespan(0)) {
4288 op
->ontimeout
= timer
.add_event(mon_timeout
,
4290 statfs_op_cancel(op
->tid
,
4295 statfs_ops
[op
->tid
] = op
;
4297 logger
->set(l_osdc_statfs_active
, statfs_ops
.size());
4299 _fs_stats_submit(op
);
4302 void Objecter::_fs_stats_submit(StatfsOp
*op
)
4304 // rwlock is locked unique
4306 ldout(cct
, 10) << "fs_stats_submit" << op
->tid
<< dendl
;
4307 monc
->send_mon_message(new MStatfs(monc
->get_fsid(), op
->tid
,
4309 last_seen_pgmap_version
));
4310 op
->last_submit
= ceph::mono_clock::now();
4312 logger
->inc(l_osdc_statfs_send
);
4315 void Objecter::handle_fs_stats_reply(MStatfsReply
*m
)
4317 unique_lock
wl(rwlock
);
4323 ldout(cct
, 10) << "handle_fs_stats_reply " << *m
<< dendl
;
4324 ceph_tid_t tid
= m
->get_tid();
4326 if (statfs_ops
.count(tid
)) {
4327 StatfsOp
*op
= statfs_ops
[tid
];
4328 ldout(cct
, 10) << "have request " << tid
<< " at " << op
<< dendl
;
4329 *(op
->stats
) = m
->h
.st
;
4330 if (m
->h
.version
> last_seen_pgmap_version
)
4331 last_seen_pgmap_version
= m
->h
.version
;
4332 op
->onfinish
->complete(0);
4333 _finish_statfs_op(op
, 0);
4335 ldout(cct
, 10) << "unknown request " << tid
<< dendl
;
4338 ldout(cct
, 10) << "done" << dendl
;
4341 int Objecter::statfs_op_cancel(ceph_tid_t tid
, int r
)
4343 assert(initialized
);
4345 unique_lock
wl(rwlock
);
4347 map
<ceph_tid_t
, StatfsOp
*>::iterator it
= statfs_ops
.find(tid
);
4348 if (it
== statfs_ops
.end()) {
4349 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4353 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4355 StatfsOp
*op
= it
->second
;
4357 op
->onfinish
->complete(r
);
4358 _finish_statfs_op(op
, r
);
4362 void Objecter::_finish_statfs_op(StatfsOp
*op
, int r
)
4364 // rwlock is locked unique
4366 statfs_ops
.erase(op
->tid
);
4367 logger
->set(l_osdc_statfs_active
, statfs_ops
.size());
4369 if (op
->ontimeout
&& r
!= -ETIMEDOUT
)
4370 timer
.cancel_event(op
->ontimeout
);
4377 void Objecter::_sg_read_finish(vector
<ObjectExtent
>& extents
,
4378 vector
<bufferlist
>& resultbl
,
4379 bufferlist
*bl
, Context
*onfinish
)
4382 ldout(cct
, 15) << "_sg_read_finish" << dendl
;
4384 if (extents
.size() > 1) {
4385 Striper::StripedReadResult r
;
4386 vector
<bufferlist
>::iterator bit
= resultbl
.begin();
4387 for (vector
<ObjectExtent
>::iterator eit
= extents
.begin();
4388 eit
!= extents
.end();
4390 r
.add_partial_result(cct
, *bit
, eit
->buffer_extents
);
4393 r
.assemble_result(cct
, *bl
, false);
4395 ldout(cct
, 15) << " only one frag" << dendl
;
4396 bl
->claim(resultbl
[0]);
4400 uint64_t bytes_read
= bl
->length();
4401 ldout(cct
, 7) << "_sg_read_finish " << bytes_read
<< " bytes" << dendl
;
4404 onfinish
->complete(bytes_read
);// > 0 ? bytes_read:m->get_result());
4409 void Objecter::ms_handle_connect(Connection
*con
)
4411 ldout(cct
, 10) << "ms_handle_connect " << con
<< dendl
;
4415 if (con
->get_peer_type() == CEPH_ENTITY_TYPE_MON
)
4419 bool Objecter::ms_handle_reset(Connection
*con
)
4423 if (con
->get_peer_type() == CEPH_ENTITY_TYPE_OSD
) {
4424 unique_lock
wl(rwlock
);
4426 OSDSession
*session
= static_cast<OSDSession
*>(con
->get_priv());
4428 ldout(cct
, 1) << "ms_handle_reset " << con
<< " session " << session
4429 << " osd." << session
->osd
<< dendl
;
4430 // the session maybe had been closed if new osdmap just handled
4431 // says the osd down
4432 if (!(initialized
&& osdmap
->is_up(session
->osd
))) {
4433 ldout(cct
, 1) << "ms_handle_reset aborted,initialized=" << initialized
<< dendl
;
4437 map
<uint64_t, LingerOp
*> lresend
;
4438 OSDSession::unique_lock
sl(session
->lock
);
4439 _reopen_session(session
);
4440 _kick_requests(session
, lresend
);
4442 _linger_ops_resend(lresend
, wl
);
4444 maybe_request_map();
4452 void Objecter::ms_handle_remote_reset(Connection
*con
)
4455 * treat these the same.
4457 ms_handle_reset(con
);
4460 bool Objecter::ms_handle_refused(Connection
*con
)
4463 if (osdmap
&& (con
->get_peer_type() == CEPH_ENTITY_TYPE_OSD
)) {
4464 int osd
= osdmap
->identify_osd(con
->get_peer_addr());
4466 ldout(cct
, 1) << "ms_handle_refused on osd." << osd
<< dendl
;
4472 bool Objecter::ms_get_authorizer(int dest_type
,
4473 AuthAuthorizer
**authorizer
,
4478 if (dest_type
== CEPH_ENTITY_TYPE_MON
)
4480 *authorizer
= monc
->build_authorizer(dest_type
);
4481 return *authorizer
!= NULL
;
4484 void Objecter::op_target_t::dump(Formatter
*f
) const
4486 f
->dump_stream("pg") << pgid
;
4487 f
->dump_int("osd", osd
);
4488 f
->dump_stream("object_id") << base_oid
;
4489 f
->dump_stream("object_locator") << base_oloc
;
4490 f
->dump_stream("target_object_id") << target_oid
;
4491 f
->dump_stream("target_object_locator") << target_oloc
;
4492 f
->dump_int("paused", (int)paused
);
4493 f
->dump_int("used_replica", (int)used_replica
);
4494 f
->dump_int("precalc_pgid", (int)precalc_pgid
);
4497 void Objecter::_dump_active(OSDSession
*s
)
4499 for (map
<ceph_tid_t
,Op
*>::iterator p
= s
->ops
.begin();
4503 ldout(cct
, 20) << op
->tid
<< "\t" << op
->target
.pgid
4504 << "\tosd." << (op
->session
? op
->session
->osd
: -1)
4505 << "\t" << op
->target
.base_oid
4506 << "\t" << op
->ops
<< dendl
;
4510 void Objecter::_dump_active()
4512 ldout(cct
, 20) << "dump_active .. " << num_homeless_ops
<< " homeless"
4514 for (map
<int, OSDSession
*>::iterator siter
= osd_sessions
.begin();
4515 siter
!= osd_sessions
.end(); ++siter
) {
4516 OSDSession
*s
= siter
->second
;
4517 OSDSession::shared_lock
sl(s
->lock
);
4521 _dump_active(homeless_session
);
4524 void Objecter::dump_active()
4526 shared_lock
rl(rwlock
);
4531 void Objecter::dump_requests(Formatter
*fmt
)
4533 // Read-lock on Objecter held here
4534 fmt
->open_object_section("requests");
4536 dump_linger_ops(fmt
);
4538 dump_pool_stat_ops(fmt
);
4539 dump_statfs_ops(fmt
);
4540 dump_command_ops(fmt
);
4541 fmt
->close_section(); // requests object
4544 void Objecter::_dump_ops(const OSDSession
*s
, Formatter
*fmt
)
4546 for (map
<ceph_tid_t
,Op
*>::const_iterator p
= s
->ops
.begin();
4550 fmt
->open_object_section("op");
4551 fmt
->dump_unsigned("tid", op
->tid
);
4552 op
->target
.dump(fmt
);
4553 fmt
->dump_stream("last_sent") << op
->stamp
;
4554 fmt
->dump_int("attempts", op
->attempts
);
4555 fmt
->dump_stream("snapid") << op
->snapid
;
4556 fmt
->dump_stream("snap_context") << op
->snapc
;
4557 fmt
->dump_stream("mtime") << op
->mtime
;
4559 fmt
->open_array_section("osd_ops");
4560 for (vector
<OSDOp
>::const_iterator it
= op
->ops
.begin();
4561 it
!= op
->ops
.end();
4563 fmt
->dump_stream("osd_op") << *it
;
4565 fmt
->close_section(); // osd_ops array
4567 fmt
->close_section(); // op object
4571 void Objecter::dump_ops(Formatter
*fmt
)
4573 // Read-lock on Objecter held
4574 fmt
->open_array_section("ops");
4575 for (map
<int, OSDSession
*>::const_iterator siter
= osd_sessions
.begin();
4576 siter
!= osd_sessions
.end(); ++siter
) {
4577 OSDSession
*s
= siter
->second
;
4578 OSDSession::shared_lock
sl(s
->lock
);
4582 _dump_ops(homeless_session
, fmt
);
4583 fmt
->close_section(); // ops array
4586 void Objecter::_dump_linger_ops(const OSDSession
*s
, Formatter
*fmt
)
4588 for (map
<uint64_t, LingerOp
*>::const_iterator p
= s
->linger_ops
.begin();
4589 p
!= s
->linger_ops
.end();
4591 LingerOp
*op
= p
->second
;
4592 fmt
->open_object_section("linger_op");
4593 fmt
->dump_unsigned("linger_id", op
->linger_id
);
4594 op
->target
.dump(fmt
);
4595 fmt
->dump_stream("snapid") << op
->snap
;
4596 fmt
->dump_stream("registered") << op
->registered
;
4597 fmt
->close_section(); // linger_op object
4601 void Objecter::dump_linger_ops(Formatter
*fmt
)
4603 // We have a read-lock on the objecter
4604 fmt
->open_array_section("linger_ops");
4605 for (map
<int, OSDSession
*>::const_iterator siter
= osd_sessions
.begin();
4606 siter
!= osd_sessions
.end(); ++siter
) {
4607 OSDSession
*s
= siter
->second
;
4608 OSDSession::shared_lock
sl(s
->lock
);
4609 _dump_linger_ops(s
, fmt
);
4612 _dump_linger_ops(homeless_session
, fmt
);
4613 fmt
->close_section(); // linger_ops array
4616 void Objecter::_dump_command_ops(const OSDSession
*s
, Formatter
*fmt
)
4618 for (map
<uint64_t, CommandOp
*>::const_iterator p
= s
->command_ops
.begin();
4619 p
!= s
->command_ops
.end();
4621 CommandOp
*op
= p
->second
;
4622 fmt
->open_object_section("command_op");
4623 fmt
->dump_unsigned("command_id", op
->tid
);
4624 fmt
->dump_int("osd", op
->session
? op
->session
->osd
: -1);
4625 fmt
->open_array_section("command");
4626 for (vector
<string
>::const_iterator q
= op
->cmd
.begin();
4627 q
!= op
->cmd
.end(); ++q
)
4628 fmt
->dump_string("word", *q
);
4629 fmt
->close_section();
4630 if (op
->target_osd
>= 0)
4631 fmt
->dump_int("target_osd", op
->target_osd
);
4633 fmt
->dump_stream("target_pg") << op
->target_pg
;
4634 fmt
->close_section(); // command_op object
4638 void Objecter::dump_command_ops(Formatter
*fmt
)
4640 // We have a read-lock on the Objecter here
4641 fmt
->open_array_section("command_ops");
4642 for (map
<int, OSDSession
*>::const_iterator siter
= osd_sessions
.begin();
4643 siter
!= osd_sessions
.end(); ++siter
) {
4644 OSDSession
*s
= siter
->second
;
4645 OSDSession::shared_lock
sl(s
->lock
);
4646 _dump_command_ops(s
, fmt
);
4649 _dump_command_ops(homeless_session
, fmt
);
4650 fmt
->close_section(); // command_ops array
4653 void Objecter::dump_pool_ops(Formatter
*fmt
) const
4655 fmt
->open_array_section("pool_ops");
4656 for (map
<ceph_tid_t
, PoolOp
*>::const_iterator p
= pool_ops
.begin();
4657 p
!= pool_ops
.end();
4659 PoolOp
*op
= p
->second
;
4660 fmt
->open_object_section("pool_op");
4661 fmt
->dump_unsigned("tid", op
->tid
);
4662 fmt
->dump_int("pool", op
->pool
);
4663 fmt
->dump_string("name", op
->name
);
4664 fmt
->dump_int("operation_type", op
->pool_op
);
4665 fmt
->dump_unsigned("auid", op
->auid
);
4666 fmt
->dump_unsigned("crush_rule", op
->crush_rule
);
4667 fmt
->dump_stream("snapid") << op
->snapid
;
4668 fmt
->dump_stream("last_sent") << op
->last_submit
;
4669 fmt
->close_section(); // pool_op object
4671 fmt
->close_section(); // pool_ops array
4674 void Objecter::dump_pool_stat_ops(Formatter
*fmt
) const
4676 fmt
->open_array_section("pool_stat_ops");
4677 for (map
<ceph_tid_t
, PoolStatOp
*>::const_iterator p
= poolstat_ops
.begin();
4678 p
!= poolstat_ops
.end();
4680 PoolStatOp
*op
= p
->second
;
4681 fmt
->open_object_section("pool_stat_op");
4682 fmt
->dump_unsigned("tid", op
->tid
);
4683 fmt
->dump_stream("last_sent") << op
->last_submit
;
4685 fmt
->open_array_section("pools");
4686 for (list
<string
>::const_iterator it
= op
->pools
.begin();
4687 it
!= op
->pools
.end();
4689 fmt
->dump_string("pool", *it
);
4691 fmt
->close_section(); // pools array
4693 fmt
->close_section(); // pool_stat_op object
4695 fmt
->close_section(); // pool_stat_ops array
4698 void Objecter::dump_statfs_ops(Formatter
*fmt
) const
4700 fmt
->open_array_section("statfs_ops");
4701 for (map
<ceph_tid_t
, StatfsOp
*>::const_iterator p
= statfs_ops
.begin();
4702 p
!= statfs_ops
.end();
4704 StatfsOp
*op
= p
->second
;
4705 fmt
->open_object_section("statfs_op");
4706 fmt
->dump_unsigned("tid", op
->tid
);
4707 fmt
->dump_stream("last_sent") << op
->last_submit
;
4708 fmt
->close_section(); // statfs_op object
4710 fmt
->close_section(); // statfs_ops array
4713 Objecter::RequestStateHook::RequestStateHook(Objecter
*objecter
) :
4714 m_objecter(objecter
)
4718 bool Objecter::RequestStateHook::call(std::string command
, cmdmap_t
& cmdmap
,
4719 std::string format
, bufferlist
& out
)
4721 Formatter
*f
= Formatter::create(format
, "json-pretty", "json-pretty");
4722 shared_lock
rl(m_objecter
->rwlock
);
4723 m_objecter
->dump_requests(f
);
4729 void Objecter::blacklist_self(bool set
)
4731 ldout(cct
, 10) << "blacklist_self " << (set
? "add" : "rm") << dendl
;
4734 cmd
.push_back("{\"prefix\":\"osd blacklist\", ");
4736 cmd
.push_back("\"blacklistop\":\"add\",");
4738 cmd
.push_back("\"blacklistop\":\"rm\",");
4740 ss
<< messenger
->get_myaddr();
4741 cmd
.push_back("\"addr\":\"" + ss
.str() + "\"");
4743 MMonCommand
*m
= new MMonCommand(monc
->get_fsid());
4746 monc
->send_mon_message(m
);
4751 void Objecter::handle_command_reply(MCommandReply
*m
)
4753 unique_lock
wl(rwlock
);
4759 ConnectionRef con
= m
->get_connection();
4760 OSDSession
*s
= static_cast<OSDSession
*>(con
->get_priv());
4761 if (!s
|| s
->con
!= con
) {
4762 ldout(cct
, 7) << __func__
<< " no session on con " << con
<< dendl
;
4769 OSDSession::shared_lock
sl(s
->lock
);
4770 map
<ceph_tid_t
,CommandOp
*>::iterator p
= s
->command_ops
.find(m
->get_tid());
4771 if (p
== s
->command_ops
.end()) {
4772 ldout(cct
, 10) << "handle_command_reply tid " << m
->get_tid()
4773 << " not found" << dendl
;
4781 CommandOp
*c
= p
->second
;
4783 m
->get_connection() != c
->session
->con
) {
4784 ldout(cct
, 10) << "handle_command_reply tid " << m
->get_tid()
4785 << " got reply from wrong connection "
4786 << m
->get_connection() << " " << m
->get_source_inst()
4795 c
->poutbl
->claim(m
->get_data());
4800 OSDSession::unique_lock
sul(s
->lock
);
4801 _finish_command(c
, m
->r
, m
->rs
);
4809 void Objecter::submit_command(CommandOp
*c
, ceph_tid_t
*ptid
)
4811 shunique_lock
sul(rwlock
, ceph::acquire_unique
);
4813 ceph_tid_t tid
= ++last_tid
;
4814 ldout(cct
, 10) << "_submit_command " << tid
<< " " << c
->cmd
<< dendl
;
4818 OSDSession::unique_lock
hs_wl(homeless_session
->lock
);
4819 _session_command_op_assign(homeless_session
, c
);
4822 _calc_command_target(c
, sul
);
4823 _assign_command_session(c
, sul
);
4824 if (osd_timeout
> timespan(0)) {
4825 c
->ontimeout
= timer
.add_event(osd_timeout
,
4827 command_op_cancel(c
->session
, tid
,
4831 if (!c
->session
->is_homeless()) {
4834 _maybe_request_map();
4836 if (c
->map_check_error
)
4837 _send_command_map_check(c
);
4840 logger
->inc(l_osdc_command_active
);
4843 int Objecter::_calc_command_target(CommandOp
*c
, shunique_lock
& sul
)
4845 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
4847 c
->map_check_error
= 0;
4849 // ignore overlays, just like we do with pg ops
4850 c
->target
.flags
|= CEPH_OSD_FLAG_IGNORE_OVERLAY
;
4852 if (c
->target_osd
>= 0) {
4853 if (!osdmap
->exists(c
->target_osd
)) {
4854 c
->map_check_error
= -ENOENT
;
4855 c
->map_check_error_str
= "osd dne";
4857 return RECALC_OP_TARGET_OSD_DNE
;
4859 if (osdmap
->is_down(c
->target_osd
)) {
4860 c
->map_check_error
= -ENXIO
;
4861 c
->map_check_error_str
= "osd down";
4863 return RECALC_OP_TARGET_OSD_DOWN
;
4865 c
->target
.osd
= c
->target_osd
;
4867 int ret
= _calc_target(&(c
->target
), nullptr, true);
4868 if (ret
== RECALC_OP_TARGET_POOL_DNE
) {
4869 c
->map_check_error
= -ENOENT
;
4870 c
->map_check_error_str
= "pool dne";
4873 } else if (ret
== RECALC_OP_TARGET_OSD_DOWN
) {
4874 c
->map_check_error
= -ENXIO
;
4875 c
->map_check_error_str
= "osd down";
4882 int r
= _get_session(c
->target
.osd
, &s
, sul
);
4883 assert(r
!= -EAGAIN
); /* shouldn't happen as we're holding the write lock */
4885 if (c
->session
!= s
) {
4887 return RECALC_OP_TARGET_NEED_RESEND
;
4892 ldout(cct
, 20) << "_recalc_command_target " << c
->tid
<< " no change, "
4893 << c
->session
<< dendl
;
4895 return RECALC_OP_TARGET_NO_ACTION
;
4898 void Objecter::_assign_command_session(CommandOp
*c
,
4901 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
4904 int r
= _get_session(c
->target
.osd
, &s
, sul
);
4905 assert(r
!= -EAGAIN
); /* shouldn't happen as we're holding the write lock */
4907 if (c
->session
!= s
) {
4909 OSDSession
*cs
= c
->session
;
4910 OSDSession::unique_lock
csl(cs
->lock
);
4911 _session_command_op_remove(c
->session
, c
);
4914 OSDSession::unique_lock
sl(s
->lock
);
4915 _session_command_op_assign(s
, c
);
4921 void Objecter::_send_command(CommandOp
*c
)
4923 ldout(cct
, 10) << "_send_command " << c
->tid
<< dendl
;
4925 assert(c
->session
->con
);
4926 MCommand
*m
= new MCommand(monc
->monmap
.fsid
);
4928 m
->set_data(c
->inbl
);
4930 c
->session
->con
->send_message(m
);
4931 logger
->inc(l_osdc_command_send
);
4934 int Objecter::command_op_cancel(OSDSession
*s
, ceph_tid_t tid
, int r
)
4936 assert(initialized
);
4938 unique_lock
wl(rwlock
);
4940 map
<ceph_tid_t
, CommandOp
*>::iterator it
= s
->command_ops
.find(tid
);
4941 if (it
== s
->command_ops
.end()) {
4942 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4946 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4948 CommandOp
*op
= it
->second
;
4949 _command_cancel_map_check(op
);
4950 OSDSession::unique_lock
sl(op
->session
->lock
);
4951 _finish_command(op
, r
, "");
4956 void Objecter::_finish_command(CommandOp
*c
, int r
, string rs
)
4958 // rwlock is locked unique
4959 // session lock is locked
4961 ldout(cct
, 10) << "_finish_command " << c
->tid
<< " = " << r
<< " "
4966 c
->onfinish
->complete(r
);
4968 if (c
->ontimeout
&& r
!= -ETIMEDOUT
)
4969 timer
.cancel_event(c
->ontimeout
);
4971 OSDSession
*s
= c
->session
;
4972 _session_command_op_remove(c
->session
, c
);
4976 logger
->dec(l_osdc_command_active
);
4979 Objecter::OSDSession::~OSDSession()
4981 // Caller is responsible for re-assigning or
4982 // destroying any ops that were assigned to us
4983 assert(ops
.empty());
4984 assert(linger_ops
.empty());
4985 assert(command_ops
.empty());
4988 Objecter::~Objecter()
4992 assert(homeless_session
->get_nref() == 1);
4993 assert(num_homeless_ops
== 0);
4994 homeless_session
->put();
4996 assert(osd_sessions
.empty());
4997 assert(poolstat_ops
.empty());
4998 assert(statfs_ops
.empty());
4999 assert(pool_ops
.empty());
5000 assert(waiting_for_map
.empty());
5001 assert(linger_ops
.empty());
5002 assert(check_latest_map_lingers
.empty());
5003 assert(check_latest_map_ops
.empty());
5004 assert(check_latest_map_commands
.empty());
5006 assert(!m_request_state_hook
);
5011 * Wait until this OSD map epoch is received before
5012 * sending any more operations to OSDs. Use this
5013 * when it is known that the client can't trust
5014 * anything from before this epoch (e.g. due to
5015 * client blacklist at this epoch).
5017 void Objecter::set_epoch_barrier(epoch_t epoch
)
5019 unique_lock
wl(rwlock
);
5021 ldout(cct
, 7) << __func__
<< ": barrier " << epoch
<< " (was "
5022 << epoch_barrier
<< ") current epoch " << osdmap
->get_epoch()
5024 if (epoch
> epoch_barrier
) {
5025 epoch_barrier
= epoch
;
5026 _maybe_request_map();
5032 hobject_t
Objecter::enumerate_objects_begin()
5037 hobject_t
Objecter::enumerate_objects_end()
5039 return hobject_t::get_max();
5042 struct C_EnumerateReply
: public Context
{
5047 std::list
<librados::ListObjectImpl
> *result
;
5048 const hobject_t end
;
5049 const int64_t pool_id
;
5055 C_EnumerateReply(Objecter
*objecter_
, hobject_t
*next_
,
5056 std::list
<librados::ListObjectImpl
> *result_
,
5057 const hobject_t end_
, const int64_t pool_id_
, Context
*on_finish_
) :
5058 objecter(objecter_
), next(next_
), result(result_
),
5059 end(end_
), pool_id(pool_id_
), on_finish(on_finish_
),
5063 void finish(int r
) override
{
5064 objecter
->_enumerate_reply(
5065 bl
, r
, end
, pool_id
, budget
, epoch
, result
, next
, on_finish
);
5069 void Objecter::enumerate_objects(
5071 const std::string
&ns
,
5072 const hobject_t
&start
,
5073 const hobject_t
&end
,
5075 const bufferlist
&filter_bl
,
5076 std::list
<librados::ListObjectImpl
> *result
,
5082 if (!end
.is_max() && start
> end
) {
5083 lderr(cct
) << __func__
<< ": start " << start
<< " > end " << end
<< dendl
;
5084 on_finish
->complete(-EINVAL
);
5089 lderr(cct
) << __func__
<< ": result size may not be zero" << dendl
;
5090 on_finish
->complete(-EINVAL
);
5094 if (start
.is_max()) {
5095 on_finish
->complete(0);
5099 shared_lock
rl(rwlock
);
5100 assert(osdmap
->get_epoch());
5101 if (!osdmap
->test_flag(CEPH_OSDMAP_SORTBITWISE
)) {
5103 lderr(cct
) << __func__
<< ": SORTBITWISE cluster flag not set" << dendl
;
5104 on_finish
->complete(-EOPNOTSUPP
);
5107 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool_id
);
5109 lderr(cct
) << __func__
<< ": pool " << pool_id
<< " DNE in osd epoch "
5110 << osdmap
->get_epoch() << dendl
;
5112 on_finish
->complete(-ENOENT
);
5118 ldout(cct
, 20) << __func__
<< ": start=" << start
<< " end=" << end
<< dendl
;
5120 // Stash completion state
5121 C_EnumerateReply
*on_ack
= new C_EnumerateReply(
5122 this, next
, result
, end
, pool_id
, on_finish
);
5125 op
.pg_nls(max
, filter_bl
, start
, 0);
5127 // Issue. See you later in _enumerate_reply
5128 object_locator_t
oloc(pool_id
, ns
);
5129 pg_read(start
.get_hash(), oloc
, op
,
5130 &on_ack
->bl
, 0, on_ack
, &on_ack
->epoch
, &on_ack
->budget
);
5133 void Objecter::_enumerate_reply(
5136 const hobject_t
&end
,
5137 const int64_t pool_id
,
5139 epoch_t reply_epoch
,
5140 std::list
<librados::ListObjectImpl
> *result
,
5145 put_op_budget_bytes(budget
);
5149 ldout(cct
, 4) << __func__
<< ": remote error " << r
<< dendl
;
5150 on_finish
->complete(r
);
5154 assert(next
!= NULL
);
5156 // Decode the results
5157 bufferlist::iterator iter
= bl
.begin();
5158 pg_nls_response_t response
;
5160 // XXX extra_info doesn't seem used anywhere?
5161 bufferlist extra_info
;
5162 ::decode(response
, iter
);
5164 ::decode(extra_info
, iter
);
5167 ldout(cct
, 10) << __func__
<< ": got " << response
.entries
.size()
5168 << " handle " << response
.handle
5169 << " reply_epoch " << reply_epoch
<< dendl
;
5170 ldout(cct
, 20) << __func__
<< ": response.entries.size "
5171 << response
.entries
.size() << ", response.entries "
5172 << response
.entries
<< dendl
;
5173 if (response
.handle
<= end
) {
5174 *next
= response
.handle
;
5176 ldout(cct
, 10) << __func__
<< ": adjusted next down to end " << end
5180 // drop anything after 'end'
5181 shared_lock
rl(rwlock
);
5182 const pg_pool_t
*pool
= osdmap
->get_pg_pool(pool_id
);
5184 // pool is gone, drop any results which are now meaningless.
5186 on_finish
->complete(-ENOENT
);
5189 while (!response
.entries
.empty()) {
5190 uint32_t hash
= response
.entries
.back().locator
.empty() ?
5191 pool
->hash_key(response
.entries
.back().oid
,
5192 response
.entries
.back().nspace
) :
5193 pool
->hash_key(response
.entries
.back().locator
,
5194 response
.entries
.back().nspace
);
5195 hobject_t
last(response
.entries
.back().oid
,
5196 response
.entries
.back().locator
,
5200 response
.entries
.back().nspace
);
5203 ldout(cct
, 20) << __func__
<< " dropping item " << last
5204 << " >= end " << end
<< dendl
;
5205 response
.entries
.pop_back();
5209 if (!response
.entries
.empty()) {
5210 result
->merge(response
.entries
);
5213 // release the listing context's budget once all
5214 // OPs (in the session) are finished
5216 put_nlist_context_budget(list_context
);
5218 on_finish
->complete(r
);
5223 using namespace librados
;
5225 template <typename T
>
5226 void do_decode(std::vector
<T
>& items
, std::vector
<bufferlist
>& bls
)
5228 for (auto bl
: bls
) {
5229 auto p
= bl
.begin();
5236 struct C_ObjectOperation_scrub_ls
: public Context
{
5239 std::vector
<inconsistent_obj_t
> *objects
= nullptr;
5240 std::vector
<inconsistent_snapset_t
> *snapsets
= nullptr;
5243 C_ObjectOperation_scrub_ls(uint32_t *interval
,
5244 std::vector
<inconsistent_obj_t
> *objects
,
5246 : interval(interval
), objects(objects
), rval(rval
) {}
5247 C_ObjectOperation_scrub_ls(uint32_t *interval
,
5248 std::vector
<inconsistent_snapset_t
> *snapsets
,
5250 : interval(interval
), snapsets(snapsets
), rval(rval
) {}
5251 void finish(int r
) override
{
5252 if (r
< 0 && r
!= -EAGAIN
) {
5263 } catch (buffer::error
&) {
5270 scrub_ls_result_t result
;
5271 auto p
= bl
.begin();
5273 *interval
= result
.interval
;
5275 do_decode(*objects
, result
.vals
);
5277 do_decode(*snapsets
, result
.vals
);
5282 template <typename T
>
5283 void do_scrub_ls(::ObjectOperation
*op
,
5284 const scrub_ls_arg_t
& arg
,
5285 std::vector
<T
> *items
,
5289 OSDOp
& osd_op
= op
->add_op(CEPH_OSD_OP_SCRUBLS
);
5290 op
->flags
|= CEPH_OSD_FLAG_PGOP
;
5292 arg
.encode(osd_op
.indata
);
5293 unsigned p
= op
->ops
.size() - 1;
5294 auto *h
= new C_ObjectOperation_scrub_ls
{interval
, items
, rval
};
5295 op
->out_handler
[p
] = h
;
5296 op
->out_bl
[p
] = &h
->bl
;
5297 op
->out_rval
[p
] = rval
;
5301 void ::ObjectOperation::scrub_ls(const librados::object_id_t
& start_after
,
5302 uint64_t max_to_get
,
5303 std::vector
<librados::inconsistent_obj_t
> *objects
,
5307 scrub_ls_arg_t arg
= {*interval
, 0, start_after
, max_to_get
};
5308 do_scrub_ls(this, arg
, objects
, interval
, rval
);
5311 void ::ObjectOperation::scrub_ls(const librados::object_id_t
& start_after
,
5312 uint64_t max_to_get
,
5313 std::vector
<librados::inconsistent_snapset_t
> *snapsets
,
5317 scrub_ls_arg_t arg
= {*interval
, 1, start_after
, max_to_get
};
5318 do_scrub_ls(this, arg
, snapsets
, interval
, rval
);