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");
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
);
416 cct
->_conf
->remove_observer(this);
418 map
<int,OSDSession
*>::iterator p
;
419 while (!osd_sessions
.empty()) {
420 p
= osd_sessions
.begin();
421 close_session(p
->second
);
424 while(!check_latest_map_lingers
.empty()) {
425 map
<uint64_t, LingerOp
*>::iterator i
= check_latest_map_lingers
.begin();
427 check_latest_map_lingers
.erase(i
->first
);
430 while(!check_latest_map_ops
.empty()) {
431 map
<ceph_tid_t
, Op
*>::iterator i
= check_latest_map_ops
.begin();
433 check_latest_map_ops
.erase(i
->first
);
436 while(!check_latest_map_commands
.empty()) {
437 map
<ceph_tid_t
, CommandOp
*>::iterator i
438 = check_latest_map_commands
.begin();
440 check_latest_map_commands
.erase(i
->first
);
443 while(!poolstat_ops
.empty()) {
444 map
<ceph_tid_t
,PoolStatOp
*>::iterator i
= poolstat_ops
.begin();
446 poolstat_ops
.erase(i
->first
);
449 while(!statfs_ops
.empty()) {
450 map
<ceph_tid_t
, StatfsOp
*>::iterator i
= statfs_ops
.begin();
452 statfs_ops
.erase(i
->first
);
455 while(!pool_ops
.empty()) {
456 map
<ceph_tid_t
, PoolOp
*>::iterator i
= pool_ops
.begin();
458 pool_ops
.erase(i
->first
);
461 ldout(cct
, 20) << __func__
<< " clearing up homeless session..." << dendl
;
462 while(!homeless_session
->linger_ops
.empty()) {
463 std::map
<uint64_t, LingerOp
*>::iterator i
464 = homeless_session
->linger_ops
.begin();
465 ldout(cct
, 10) << " linger_op " << i
->first
<< dendl
;
466 LingerOp
*lop
= i
->second
;
468 OSDSession::unique_lock
swl(homeless_session
->lock
);
469 _session_linger_op_remove(homeless_session
, lop
);
471 linger_ops
.erase(lop
->linger_id
);
472 linger_ops_set
.erase(lop
);
476 while(!homeless_session
->ops
.empty()) {
477 std::map
<ceph_tid_t
, Op
*>::iterator i
= homeless_session
->ops
.begin();
478 ldout(cct
, 10) << " op " << i
->first
<< dendl
;
481 OSDSession::unique_lock
swl(homeless_session
->lock
);
482 _session_op_remove(homeless_session
, op
);
487 while(!homeless_session
->command_ops
.empty()) {
488 std::map
<ceph_tid_t
, CommandOp
*>::iterator i
489 = homeless_session
->command_ops
.begin();
490 ldout(cct
, 10) << " command_op " << i
->first
<< dendl
;
491 CommandOp
*cop
= i
->second
;
493 OSDSession::unique_lock
swl(homeless_session
->lock
);
494 _session_command_op_remove(homeless_session
, cop
);
500 if (timer
.cancel_event(tick_event
)) {
501 ldout(cct
, 10) << " successfully canceled tick" << dendl
;
507 cct
->get_perfcounters_collection()->remove(logger
);
512 // Let go of Objecter write lock so timer thread can shutdown
515 // Outside of lock to avoid cycle WRT calls to RequestStateHook
516 // This is safe because we guarantee no concurrent calls to
517 // shutdown() with the ::initialized check at start.
518 if (m_request_state_hook
) {
519 AdminSocket
* admin_socket
= cct
->get_admin_socket();
520 admin_socket
->unregister_command("objecter_requests");
521 delete m_request_state_hook
;
522 m_request_state_hook
= NULL
;
526 void Objecter::_send_linger(LingerOp
*info
,
529 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
532 Context
*oncommit
= NULL
;
533 LingerOp::shared_lock
watchl(info
->watch_lock
);
534 bufferlist
*poutbl
= NULL
;
535 if (info
->registered
&& info
->is_watch
) {
536 ldout(cct
, 15) << "send_linger " << info
->linger_id
<< " reconnect"
538 opv
.push_back(OSDOp());
539 opv
.back().op
.op
= CEPH_OSD_OP_WATCH
;
540 opv
.back().op
.watch
.cookie
= info
->get_cookie();
541 opv
.back().op
.watch
.op
= CEPH_OSD_WATCH_OP_RECONNECT
;
542 opv
.back().op
.watch
.gen
= ++info
->register_gen
;
543 oncommit
= new C_Linger_Reconnect(this, info
);
545 ldout(cct
, 15) << "send_linger " << info
->linger_id
<< " register"
548 C_Linger_Commit
*c
= new C_Linger_Commit(this, info
);
549 if (!info
->is_watch
) {
556 Op
*o
= new Op(info
->target
.base_oid
, info
->target
.base_oloc
,
557 opv
, info
->target
.flags
| CEPH_OSD_FLAG_READ
,
558 oncommit
, info
->pobjver
);
560 o
->snapid
= info
->snap
;
561 o
->snapc
= info
->snapc
;
562 o
->mtime
= info
->mtime
;
564 o
->target
= info
->target
;
567 // do not resend this; we will send a new op to reregister
568 o
->should_resend
= false;
570 if (info
->register_tid
) {
571 // repeat send. cancel old registeration op, if any.
572 OSDSession::unique_lock
sl(info
->session
->lock
);
573 if (info
->session
->ops
.count(info
->register_tid
)) {
574 Op
*o
= info
->session
->ops
[info
->register_tid
];
575 _op_cancel_map_check(o
);
576 _cancel_linger_op(o
);
580 _op_submit(o
, sul
, &info
->register_tid
);
583 _op_submit_with_budget(o
, sul
, &info
->register_tid
);
586 logger
->inc(l_osdc_linger_send
);
589 void Objecter::_linger_commit(LingerOp
*info
, int r
, bufferlist
& outbl
)
591 LingerOp::unique_lock
wl(info
->watch_lock
);
592 ldout(cct
, 10) << "_linger_commit " << info
->linger_id
<< dendl
;
593 if (info
->on_reg_commit
) {
594 info
->on_reg_commit
->complete(r
);
595 info
->on_reg_commit
= NULL
;
597 if (r
< 0 && info
->on_notify_finish
) {
598 info
->on_notify_finish
->complete(r
);
599 info
->on_notify_finish
= nullptr;
602 // only tell the user the first time we do this
603 info
->registered
= true;
604 info
->pobjver
= NULL
;
606 if (!info
->is_watch
) {
607 // make note of the notify_id
608 bufferlist::iterator p
= outbl
.begin();
610 ::decode(info
->notify_id
, p
);
611 ldout(cct
, 10) << "_linger_commit notify_id=" << info
->notify_id
614 catch (buffer::error
& e
) {
619 struct C_DoWatchError
: public Context
{
621 Objecter::LingerOp
*info
;
623 C_DoWatchError(Objecter
*o
, Objecter::LingerOp
*i
, int r
)
624 : objecter(o
), info(i
), err(r
) {
626 info
->_queued_async();
628 void finish(int r
) override
{
629 Objecter::unique_lock
wl(objecter
->rwlock
);
630 bool canceled
= info
->canceled
;
634 info
->watch_context
->handle_error(info
->get_cookie(), err
);
637 info
->finished_async();
642 int Objecter::_normalize_watch_error(int r
)
644 // translate ENOENT -> ENOTCONN so that a delete->disconnection
645 // notification and a failure to reconnect becuase we raced with
646 // the delete appear the same to the user.
652 void Objecter::_linger_reconnect(LingerOp
*info
, int r
)
654 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
<< " = " << r
655 << " (last_error " << info
->last_error
<< ")" << dendl
;
657 LingerOp::unique_lock
wl(info
->watch_lock
);
658 if (!info
->last_error
) {
659 r
= _normalize_watch_error(r
);
660 info
->last_error
= r
;
661 if (info
->watch_context
) {
662 finisher
->queue(new C_DoWatchError(this, info
, r
));
669 void Objecter::_send_linger_ping(LingerOp
*info
)
671 // rwlock is locked unique
672 // info->session->lock is locked
674 if (cct
->_conf
->objecter_inject_no_watch_ping
) {
675 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
<< " SKIPPING"
679 if (osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
)) {
680 ldout(cct
, 10) << __func__
<< " PAUSERD" << dendl
;
684 ceph::mono_time now
= ceph::mono_clock::now();
685 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
<< " now " << now
688 vector
<OSDOp
> opv(1);
689 opv
[0].op
.op
= CEPH_OSD_OP_WATCH
;
690 opv
[0].op
.watch
.cookie
= info
->get_cookie();
691 opv
[0].op
.watch
.op
= CEPH_OSD_WATCH_OP_PING
;
692 opv
[0].op
.watch
.gen
= info
->register_gen
;
693 C_Linger_Ping
*onack
= new C_Linger_Ping(this, info
);
694 Op
*o
= new Op(info
->target
.base_oid
, info
->target
.base_oloc
,
695 opv
, info
->target
.flags
| CEPH_OSD_FLAG_READ
,
697 o
->target
= info
->target
;
698 o
->should_resend
= false;
700 MOSDOp
*m
= _prepare_osd_op(o
);
702 _session_op_assign(info
->session
, o
);
704 info
->ping_tid
= o
->tid
;
707 logger
->inc(l_osdc_linger_ping
);
710 void Objecter::_linger_ping(LingerOp
*info
, int r
, mono_time sent
,
711 uint32_t register_gen
)
713 LingerOp::unique_lock
l(info
->watch_lock
);
714 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
715 << " sent " << sent
<< " gen " << register_gen
<< " = " << r
716 << " (last_error " << info
->last_error
717 << " register_gen " << info
->register_gen
<< ")" << dendl
;
718 if (info
->register_gen
== register_gen
) {
720 info
->watch_valid_thru
= sent
;
721 } else if (r
< 0 && !info
->last_error
) {
722 r
= _normalize_watch_error(r
);
723 info
->last_error
= r
;
724 if (info
->watch_context
) {
725 finisher
->queue(new C_DoWatchError(this, info
, r
));
729 ldout(cct
, 20) << " ignoring old gen" << dendl
;
733 int Objecter::linger_check(LingerOp
*info
)
735 LingerOp::shared_lock
l(info
->watch_lock
);
737 mono_time stamp
= info
->watch_valid_thru
;
738 if (!info
->watch_pending_async
.empty())
739 stamp
= MIN(info
->watch_valid_thru
, info
->watch_pending_async
.front());
740 auto age
= mono_clock::now() - stamp
;
742 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
743 << " err " << info
->last_error
744 << " age " << age
<< dendl
;
745 if (info
->last_error
)
746 return info
->last_error
;
747 // return a safe upper bound (we are truncating to ms)
749 1 + std::chrono::duration_cast
<std::chrono::milliseconds
>(age
).count();
752 void Objecter::linger_cancel(LingerOp
*info
)
754 unique_lock
wl(rwlock
);
755 _linger_cancel(info
);
759 void Objecter::_linger_cancel(LingerOp
*info
)
761 // rwlock is locked unique
762 ldout(cct
, 20) << __func__
<< " linger_id=" << info
->linger_id
<< dendl
;
763 if (!info
->canceled
) {
764 OSDSession
*s
= info
->session
;
765 OSDSession::unique_lock
sl(s
->lock
);
766 _session_linger_op_remove(s
, info
);
769 linger_ops
.erase(info
->linger_id
);
770 linger_ops_set
.erase(info
);
771 assert(linger_ops
.size() == linger_ops_set
.size());
773 info
->canceled
= true;
776 logger
->dec(l_osdc_linger_active
);
782 Objecter::LingerOp
*Objecter::linger_register(const object_t
& oid
,
783 const object_locator_t
& oloc
,
786 LingerOp
*info
= new LingerOp
;
787 info
->target
.base_oid
= oid
;
788 info
->target
.base_oloc
= oloc
;
789 if (info
->target
.base_oloc
.key
== oid
)
790 info
->target
.base_oloc
.key
.clear();
791 info
->target
.flags
= flags
;
792 info
->watch_valid_thru
= mono_clock::now();
794 unique_lock
l(rwlock
);
797 info
->linger_id
= ++max_linger_id
;
798 ldout(cct
, 10) << __func__
<< " info " << info
799 << " linger_id " << info
->linger_id
800 << " cookie " << info
->get_cookie()
802 linger_ops
[info
->linger_id
] = info
;
803 linger_ops_set
.insert(info
);
804 assert(linger_ops
.size() == linger_ops_set
.size());
806 info
->get(); // for the caller
810 ceph_tid_t
Objecter::linger_watch(LingerOp
*info
,
812 const SnapContext
& snapc
,
818 info
->is_watch
= true;
821 info
->target
.flags
|= CEPH_OSD_FLAG_WRITE
;
825 info
->pobjver
= objver
;
826 info
->on_reg_commit
= oncommit
;
828 shunique_lock
sul(rwlock
, ceph::acquire_unique
);
829 _linger_submit(info
, sul
);
830 logger
->inc(l_osdc_linger_active
);
832 return info
->linger_id
;
835 ceph_tid_t
Objecter::linger_notify(LingerOp
*info
,
837 snapid_t snap
, bufferlist
& inbl
,
843 info
->target
.flags
|= CEPH_OSD_FLAG_READ
;
846 info
->poutbl
= poutbl
;
847 info
->pobjver
= objver
;
848 info
->on_reg_commit
= onfinish
;
850 shunique_lock
sul(rwlock
, ceph::acquire_unique
);
851 _linger_submit(info
, sul
);
852 logger
->inc(l_osdc_linger_active
);
854 return info
->linger_id
;
857 void Objecter::_linger_submit(LingerOp
*info
, shunique_lock
& sul
)
859 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
860 assert(info
->linger_id
);
862 // Populate Op::target
863 OSDSession
*s
= NULL
;
864 _calc_target(&info
->target
, nullptr);
866 // Create LingerOp<->OSDSession relation
867 int r
= _get_session(info
->target
.osd
, &s
, sul
);
869 OSDSession::unique_lock
sl(s
->lock
);
870 _session_linger_op_assign(s
, info
);
874 _send_linger(info
, sul
);
877 struct C_DoWatchNotify
: public Context
{
879 Objecter::LingerOp
*info
;
881 C_DoWatchNotify(Objecter
*o
, Objecter::LingerOp
*i
, MWatchNotify
*m
)
882 : objecter(o
), info(i
), msg(m
) {
884 info
->_queued_async();
887 void finish(int r
) override
{
888 objecter
->_do_watch_notify(info
, msg
);
892 void Objecter::handle_watch_notify(MWatchNotify
*m
)
894 shared_lock
l(rwlock
);
899 LingerOp
*info
= reinterpret_cast<LingerOp
*>(m
->cookie
);
900 if (linger_ops_set
.count(info
) == 0) {
901 ldout(cct
, 7) << __func__
<< " cookie " << m
->cookie
<< " dne" << dendl
;
904 LingerOp::unique_lock
wl(info
->watch_lock
);
905 if (m
->opcode
== CEPH_WATCH_EVENT_DISCONNECT
) {
906 if (!info
->last_error
) {
907 info
->last_error
= -ENOTCONN
;
908 if (info
->watch_context
) {
909 finisher
->queue(new C_DoWatchError(this, info
, -ENOTCONN
));
912 } else if (!info
->is_watch
) {
913 // we have CEPH_WATCH_EVENT_NOTIFY_COMPLETE; we can do this inline
914 // since we know the only user (librados) is safe to call in
915 // fast-dispatch context
916 if (info
->notify_id
&&
917 info
->notify_id
!= m
->notify_id
) {
918 ldout(cct
, 10) << __func__
<< " reply notify " << m
->notify_id
919 << " != " << info
->notify_id
<< ", ignoring" << dendl
;
920 } else if (info
->on_notify_finish
) {
921 info
->notify_result_bl
->claim(m
->get_data());
922 info
->on_notify_finish
->complete(m
->return_code
);
924 // if we race with reconnect we might get a second notify; only
925 // notify the caller once!
926 info
->on_notify_finish
= NULL
;
929 finisher
->queue(new C_DoWatchNotify(this, info
, m
));
933 void Objecter::_do_watch_notify(LingerOp
*info
, MWatchNotify
*m
)
935 ldout(cct
, 10) << __func__
<< " " << *m
<< dendl
;
937 shared_lock
l(rwlock
);
940 if (info
->canceled
) {
945 // notify completion?
946 assert(info
->is_watch
);
947 assert(info
->watch_context
);
948 assert(m
->opcode
!= CEPH_WATCH_EVENT_DISCONNECT
);
953 case CEPH_WATCH_EVENT_NOTIFY
:
954 info
->watch_context
->handle_notify(m
->notify_id
, m
->cookie
,
955 m
->notifier_gid
, m
->bl
);
960 info
->finished_async();
965 bool Objecter::ms_dispatch(Message
*m
)
967 ldout(cct
, 10) << __func__
<< " " << cct
<< " " << *m
<< dendl
;
971 switch (m
->get_type()) {
972 // these we exlusively handle
973 case CEPH_MSG_OSD_OPREPLY
:
974 handle_osd_op_reply(static_cast<MOSDOpReply
*>(m
));
977 case CEPH_MSG_OSD_BACKOFF
:
978 handle_osd_backoff(static_cast<MOSDBackoff
*>(m
));
981 case CEPH_MSG_WATCH_NOTIFY
:
982 handle_watch_notify(static_cast<MWatchNotify
*>(m
));
986 case MSG_COMMAND_REPLY
:
987 if (m
->get_source().type() == CEPH_ENTITY_TYPE_OSD
) {
988 handle_command_reply(static_cast<MCommandReply
*>(m
));
994 case MSG_GETPOOLSTATSREPLY
:
995 handle_get_pool_stats_reply(static_cast<MGetPoolStatsReply
*>(m
));
998 case CEPH_MSG_POOLOP_REPLY
:
999 handle_pool_op_reply(static_cast<MPoolOpReply
*>(m
));
1002 case CEPH_MSG_STATFS_REPLY
:
1003 handle_fs_stats_reply(static_cast<MStatfsReply
*>(m
));
1006 // these we give others a chance to inspect
1009 case CEPH_MSG_OSD_MAP
:
1010 handle_osd_map(static_cast<MOSDMap
*>(m
));
1016 void Objecter::_scan_requests(OSDSession
*s
,
1019 map
<int64_t, bool> *pool_full_map
,
1020 map
<ceph_tid_t
, Op
*>& need_resend
,
1021 list
<LingerOp
*>& need_resend_linger
,
1022 map
<ceph_tid_t
, CommandOp
*>& need_resend_command
,
1025 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
1027 list
<LingerOp
*> unregister_lingers
;
1029 OSDSession::unique_lock
sl(s
->lock
);
1031 // check for changed linger mappings (_before_ regular ops)
1032 map
<ceph_tid_t
,LingerOp
*>::iterator lp
= s
->linger_ops
.begin();
1033 while (lp
!= s
->linger_ops
.end()) {
1034 LingerOp
*op
= lp
->second
;
1035 assert(op
->session
== s
);
1036 // check_linger_pool_dne() may touch linger_ops; prevent iterator
1039 ldout(cct
, 10) << " checking linger op " << op
->linger_id
<< dendl
;
1040 bool unregister
, force_resend_writes
= cluster_full
;
1041 int r
= _recalc_linger_op_target(op
, sul
);
1043 force_resend_writes
= force_resend_writes
||
1044 (*pool_full_map
)[op
->target
.base_oloc
.pool
];
1046 case RECALC_OP_TARGET_NO_ACTION
:
1047 if (!force_resend
&& !force_resend_writes
)
1050 case RECALC_OP_TARGET_NEED_RESEND
:
1051 need_resend_linger
.push_back(op
);
1052 _linger_cancel_map_check(op
);
1054 case RECALC_OP_TARGET_POOL_DNE
:
1055 _check_linger_pool_dne(op
, &unregister
);
1057 ldout(cct
, 10) << " need to unregister linger op "
1058 << op
->linger_id
<< dendl
;
1060 unregister_lingers
.push_back(op
);
1066 // check for changed request mappings
1067 map
<ceph_tid_t
,Op
*>::iterator p
= s
->ops
.begin();
1068 while (p
!= s
->ops
.end()) {
1070 ++p
; // check_op_pool_dne() may touch ops; prevent iterator invalidation
1071 ldout(cct
, 10) << " checking op " << op
->tid
<< dendl
;
1072 bool force_resend_writes
= cluster_full
;
1074 force_resend_writes
= force_resend_writes
||
1075 (*pool_full_map
)[op
->target
.base_oloc
.pool
];
1076 int r
= _calc_target(&op
->target
,
1077 op
->session
? op
->session
->con
.get() : nullptr);
1079 case RECALC_OP_TARGET_NO_ACTION
:
1080 if (!force_resend
&& !(force_resend_writes
&& op
->respects_full()))
1083 case RECALC_OP_TARGET_NEED_RESEND
:
1085 _session_op_remove(op
->session
, op
);
1087 need_resend
[op
->tid
] = op
;
1088 _op_cancel_map_check(op
);
1090 case RECALC_OP_TARGET_POOL_DNE
:
1091 _check_op_pool_dne(op
, &sl
);
1097 map
<ceph_tid_t
,CommandOp
*>::iterator cp
= s
->command_ops
.begin();
1098 while (cp
!= s
->command_ops
.end()) {
1099 CommandOp
*c
= cp
->second
;
1101 ldout(cct
, 10) << " checking command " << c
->tid
<< dendl
;
1102 bool force_resend_writes
= cluster_full
;
1104 force_resend_writes
= force_resend_writes
||
1105 (*pool_full_map
)[c
->target_pg
.pool()];
1106 int r
= _calc_command_target(c
, sul
);
1108 case RECALC_OP_TARGET_NO_ACTION
:
1109 // resend if skipped map; otherwise do nothing.
1110 if (!force_resend
&& !force_resend_writes
)
1113 case RECALC_OP_TARGET_NEED_RESEND
:
1114 need_resend_command
[c
->tid
] = c
;
1116 _session_command_op_remove(c
->session
, c
);
1118 _command_cancel_map_check(c
);
1120 case RECALC_OP_TARGET_POOL_DNE
:
1121 case RECALC_OP_TARGET_OSD_DNE
:
1122 case RECALC_OP_TARGET_OSD_DOWN
:
1123 _check_command_map_dne(c
);
1130 for (list
<LingerOp
*>::iterator iter
= unregister_lingers
.begin();
1131 iter
!= unregister_lingers
.end();
1133 _linger_cancel(*iter
);
1138 void Objecter::handle_osd_map(MOSDMap
*m
)
1140 shunique_lock
sul(rwlock
, acquire_unique
);
1146 if (m
->fsid
!= monc
->get_fsid()) {
1147 ldout(cct
, 0) << "handle_osd_map fsid " << m
->fsid
1148 << " != " << monc
->get_fsid() << dendl
;
1152 bool was_pauserd
= osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
);
1153 bool cluster_full
= _osdmap_full_flag();
1154 bool was_pausewr
= osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
) || cluster_full
||
1155 _osdmap_has_pool_full();
1156 map
<int64_t, bool> pool_full_map
;
1157 for (map
<int64_t, pg_pool_t
>::const_iterator it
1158 = osdmap
->get_pools().begin();
1159 it
!= osdmap
->get_pools().end(); ++it
)
1160 pool_full_map
[it
->first
] = _osdmap_pool_full(it
->second
);
1163 list
<LingerOp
*> need_resend_linger
;
1164 map
<ceph_tid_t
, Op
*> need_resend
;
1165 map
<ceph_tid_t
, CommandOp
*> need_resend_command
;
1167 if (m
->get_last() <= osdmap
->get_epoch()) {
1168 ldout(cct
, 3) << "handle_osd_map ignoring epochs ["
1169 << m
->get_first() << "," << m
->get_last()
1170 << "] <= " << osdmap
->get_epoch() << dendl
;
1172 ldout(cct
, 3) << "handle_osd_map got epochs ["
1173 << m
->get_first() << "," << m
->get_last()
1174 << "] > " << osdmap
->get_epoch() << dendl
;
1176 if (osdmap
->get_epoch()) {
1177 bool skipped_map
= false;
1178 // we want incrementals
1179 for (epoch_t e
= osdmap
->get_epoch() + 1;
1183 if (osdmap
->get_epoch() == e
-1 &&
1184 m
->incremental_maps
.count(e
)) {
1185 ldout(cct
, 3) << "handle_osd_map decoding incremental epoch " << e
1187 OSDMap::Incremental
inc(m
->incremental_maps
[e
]);
1188 osdmap
->apply_incremental(inc
);
1190 emit_blacklist_events(inc
);
1192 logger
->inc(l_osdc_map_inc
);
1194 else if (m
->maps
.count(e
)) {
1195 ldout(cct
, 3) << "handle_osd_map decoding full epoch " << e
<< dendl
;
1196 OSDMap
*new_osdmap
= new OSDMap();
1197 new_osdmap
->decode(m
->maps
[e
]);
1199 emit_blacklist_events(*osdmap
, *new_osdmap
);
1201 osdmap
= new_osdmap
;
1203 logger
->inc(l_osdc_map_full
);
1206 if (e
>= m
->get_oldest()) {
1207 ldout(cct
, 3) << "handle_osd_map requesting missing epoch "
1208 << osdmap
->get_epoch()+1 << dendl
;
1209 _maybe_request_map();
1212 ldout(cct
, 3) << "handle_osd_map missing epoch "
1213 << osdmap
->get_epoch()+1
1214 << ", jumping to " << m
->get_oldest() << dendl
;
1215 e
= m
->get_oldest() - 1;
1219 logger
->set(l_osdc_map_epoch
, osdmap
->get_epoch());
1221 cluster_full
= cluster_full
|| _osdmap_full_flag();
1222 update_pool_full_map(pool_full_map
);
1224 // check all outstanding requests on every epoch
1225 _scan_requests(homeless_session
, skipped_map
, cluster_full
,
1226 &pool_full_map
, need_resend
,
1227 need_resend_linger
, need_resend_command
, sul
);
1228 for (map
<int,OSDSession
*>::iterator p
= osd_sessions
.begin();
1229 p
!= osd_sessions
.end(); ) {
1230 OSDSession
*s
= p
->second
;
1231 _scan_requests(s
, skipped_map
, cluster_full
,
1232 &pool_full_map
, need_resend
,
1233 need_resend_linger
, need_resend_command
, sul
);
1235 // osd down or addr change?
1236 if (!osdmap
->is_up(s
->osd
) ||
1238 s
->con
->get_peer_addr() != osdmap
->get_inst(s
->osd
).addr
)) {
1243 assert(e
== osdmap
->get_epoch());
1247 // first map. we want the full thing.
1248 if (m
->maps
.count(m
->get_last())) {
1249 for (map
<int,OSDSession
*>::iterator p
= osd_sessions
.begin();
1250 p
!= osd_sessions
.end(); ++p
) {
1251 OSDSession
*s
= p
->second
;
1252 _scan_requests(s
, false, false, NULL
, need_resend
,
1253 need_resend_linger
, need_resend_command
, sul
);
1255 ldout(cct
, 3) << "handle_osd_map decoding full epoch "
1256 << m
->get_last() << dendl
;
1257 osdmap
->decode(m
->maps
[m
->get_last()]);
1259 _scan_requests(homeless_session
, false, false, NULL
,
1260 need_resend
, need_resend_linger
,
1261 need_resend_command
, sul
);
1263 ldout(cct
, 3) << "handle_osd_map hmm, i want a full map, requesting"
1265 monc
->sub_want("osdmap", 0, CEPH_SUBSCRIBE_ONETIME
);
1271 // make sure need_resend targets reflect latest map
1272 for (auto p
= need_resend
.begin(); p
!= need_resend
.end(); ) {
1274 if (op
->target
.epoch
< osdmap
->get_epoch()) {
1275 ldout(cct
, 10) << __func__
<< " checking op " << p
->first
<< dendl
;
1276 int r
= _calc_target(&op
->target
, nullptr);
1277 if (r
== RECALC_OP_TARGET_POOL_DNE
) {
1278 p
= need_resend
.erase(p
);
1279 _check_op_pool_dne(op
, nullptr);
1288 bool pauserd
= osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
);
1289 bool pausewr
= osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
) || _osdmap_full_flag()
1290 || _osdmap_has_pool_full();
1293 if (was_pauserd
|| was_pausewr
|| pauserd
|| pausewr
||
1294 osdmap
->get_epoch() < epoch_barrier
) {
1295 _maybe_request_map();
1299 for (map
<ceph_tid_t
, Op
*>::iterator p
= need_resend
.begin();
1300 p
!= need_resend
.end(); ++p
) {
1302 OSDSession
*s
= op
->session
;
1303 bool mapped_session
= false;
1305 int r
= _map_session(&op
->target
, &s
, sul
);
1307 mapped_session
= true;
1311 OSDSession::unique_lock
sl(s
->lock
);
1312 if (mapped_session
) {
1313 _session_op_assign(s
, op
);
1315 if (op
->should_resend
) {
1316 if (!op
->session
->is_homeless() && !op
->target
.paused
) {
1317 logger
->inc(l_osdc_op_resend
);
1321 _op_cancel_map_check(op
);
1322 _cancel_linger_op(op
);
1327 for (list
<LingerOp
*>::iterator p
= need_resend_linger
.begin();
1328 p
!= need_resend_linger
.end(); ++p
) {
1331 _calc_target(&op
->target
, nullptr);
1332 OSDSession
*s
= NULL
;
1333 const int r
= _get_session(op
->target
.osd
, &s
, sul
);
1339 if (!op
->session
->is_homeless()) {
1340 logger
->inc(l_osdc_linger_resend
);
1341 _send_linger(op
, sul
);
1344 for (map
<ceph_tid_t
,CommandOp
*>::iterator p
= need_resend_command
.begin();
1345 p
!= need_resend_command
.end(); ++p
) {
1346 CommandOp
*c
= p
->second
;
1347 if (c
->target
.osd
>= 0) {
1348 _assign_command_session(c
, sul
);
1349 if (c
->session
&& !c
->session
->is_homeless()) {
1357 // finish any Contexts that were waiting on a map update
1358 map
<epoch_t
,list
< pair
< Context
*, int > > >::iterator p
=
1359 waiting_for_map
.begin();
1360 while (p
!= waiting_for_map
.end() &&
1361 p
->first
<= osdmap
->get_epoch()) {
1362 //go through the list and call the onfinish methods
1363 for (list
<pair
<Context
*, int> >::iterator i
= p
->second
.begin();
1364 i
!= p
->second
.end(); ++i
) {
1365 i
->first
->complete(i
->second
);
1367 waiting_for_map
.erase(p
++);
1370 monc
->sub_got("osdmap", osdmap
->get_epoch());
1372 if (!waiting_for_map
.empty()) {
1373 _maybe_request_map();
1377 void Objecter::enable_blacklist_events()
1379 unique_lock
wl(rwlock
);
1381 blacklist_events_enabled
= true;
1384 void Objecter::consume_blacklist_events(std::set
<entity_addr_t
> *events
)
1386 unique_lock
wl(rwlock
);
1388 if (events
->empty()) {
1389 events
->swap(blacklist_events
);
1391 for (const auto &i
: blacklist_events
) {
1394 blacklist_events
.clear();
1398 void Objecter::emit_blacklist_events(const OSDMap::Incremental
&inc
)
1400 if (!blacklist_events_enabled
) {
1404 for (const auto &i
: inc
.new_blacklist
) {
1405 blacklist_events
.insert(i
.first
);
1409 void Objecter::emit_blacklist_events(const OSDMap
&old_osd_map
,
1410 const OSDMap
&new_osd_map
)
1412 if (!blacklist_events_enabled
) {
1416 std::set
<entity_addr_t
> old_set
;
1417 std::set
<entity_addr_t
> new_set
;
1419 old_osd_map
.get_blacklist(&old_set
);
1420 new_osd_map
.get_blacklist(&new_set
);
1422 std::set
<entity_addr_t
> delta_set
;
1423 std::set_difference(
1424 new_set
.begin(), new_set
.end(), old_set
.begin(), old_set
.end(),
1425 std::inserter(delta_set
, delta_set
.begin()));
1426 blacklist_events
.insert(delta_set
.begin(), delta_set
.end());
1431 void Objecter::C_Op_Map_Latest::finish(int r
)
1433 if (r
== -EAGAIN
|| r
== -ECANCELED
)
1436 lgeneric_subdout(objecter
->cct
, objecter
, 10)
1437 << "op_map_latest r=" << r
<< " tid=" << tid
1438 << " latest " << latest
<< dendl
;
1440 Objecter::unique_lock
wl(objecter
->rwlock
);
1442 map
<ceph_tid_t
, Op
*>::iterator iter
=
1443 objecter
->check_latest_map_ops
.find(tid
);
1444 if (iter
== objecter
->check_latest_map_ops
.end()) {
1445 lgeneric_subdout(objecter
->cct
, objecter
, 10)
1446 << "op_map_latest op "<< tid
<< " not found" << dendl
;
1450 Op
*op
= iter
->second
;
1451 objecter
->check_latest_map_ops
.erase(iter
);
1453 lgeneric_subdout(objecter
->cct
, objecter
, 20)
1454 << "op_map_latest op "<< op
<< dendl
;
1456 if (op
->map_dne_bound
== 0)
1457 op
->map_dne_bound
= latest
;
1459 OSDSession::unique_lock
sl(op
->session
->lock
, defer_lock
);
1460 objecter
->_check_op_pool_dne(op
, &sl
);
1465 int Objecter::pool_snap_by_name(int64_t poolid
, const char *snap_name
,
1466 snapid_t
*snap
) const
1468 shared_lock
rl(rwlock
);
1470 auto& pools
= osdmap
->get_pools();
1471 auto iter
= pools
.find(poolid
);
1472 if (iter
== pools
.end()) {
1475 const pg_pool_t
& pg_pool
= iter
->second
;
1476 for (auto p
= pg_pool
.snaps
.begin();
1477 p
!= pg_pool
.snaps
.end();
1479 if (p
->second
.name
== snap_name
) {
1487 int Objecter::pool_snap_get_info(int64_t poolid
, snapid_t snap
,
1488 pool_snap_info_t
*info
) const
1490 shared_lock
rl(rwlock
);
1492 auto& pools
= osdmap
->get_pools();
1493 auto iter
= pools
.find(poolid
);
1494 if (iter
== pools
.end()) {
1497 const pg_pool_t
& pg_pool
= iter
->second
;
1498 auto p
= pg_pool
.snaps
.find(snap
);
1499 if (p
== pg_pool
.snaps
.end())
1506 int Objecter::pool_snap_list(int64_t poolid
, vector
<uint64_t> *snaps
)
1508 shared_lock
rl(rwlock
);
1510 const pg_pool_t
*pi
= osdmap
->get_pg_pool(poolid
);
1513 for (map
<snapid_t
,pool_snap_info_t
>::const_iterator p
= pi
->snaps
.begin();
1514 p
!= pi
->snaps
.end();
1516 snaps
->push_back(p
->first
);
1521 // sl may be unlocked.
1522 void Objecter::_check_op_pool_dne(Op
*op
, unique_lock
*sl
)
1524 // rwlock is locked unique
1526 if (op
->target
.pool_ever_existed
) {
1527 // the pool previously existed and now it does not, which means it
1529 op
->map_dne_bound
= osdmap
->get_epoch();
1530 ldout(cct
, 10) << "check_op_pool_dne tid " << op
->tid
1531 << " pool previously exists but now does not"
1534 ldout(cct
, 10) << "check_op_pool_dne tid " << op
->tid
1535 << " current " << osdmap
->get_epoch()
1536 << " map_dne_bound " << op
->map_dne_bound
1539 if (op
->map_dne_bound
> 0) {
1540 if (osdmap
->get_epoch() >= op
->map_dne_bound
) {
1541 // we had a new enough map
1542 ldout(cct
, 10) << "check_op_pool_dne tid " << op
->tid
1543 << " concluding pool " << op
->target
.base_pgid
.pool()
1546 op
->onfinish
->complete(-ENOENT
);
1549 OSDSession
*s
= op
->session
;
1552 assert(sl
->mutex() == &s
->lock
);
1553 bool session_locked
= sl
->owns_lock();
1554 if (!session_locked
) {
1558 if (!session_locked
) {
1562 _finish_op(op
, 0); // no session
1566 _send_op_map_check(op
);
1570 void Objecter::_send_op_map_check(Op
*op
)
1572 // rwlock is locked unique
1574 if (check_latest_map_ops
.count(op
->tid
) == 0) {
1576 check_latest_map_ops
[op
->tid
] = op
;
1577 C_Op_Map_Latest
*c
= new C_Op_Map_Latest(this, op
->tid
);
1578 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
1582 void Objecter::_op_cancel_map_check(Op
*op
)
1584 // rwlock is locked unique
1585 map
<ceph_tid_t
, Op
*>::iterator iter
=
1586 check_latest_map_ops
.find(op
->tid
);
1587 if (iter
!= check_latest_map_ops
.end()) {
1588 Op
*op
= iter
->second
;
1590 check_latest_map_ops
.erase(iter
);
1594 // linger pool check
1596 void Objecter::C_Linger_Map_Latest::finish(int r
)
1598 if (r
== -EAGAIN
|| r
== -ECANCELED
) {
1599 // ignore callback; we will retry in resend_mon_ops()
1603 unique_lock
wl(objecter
->rwlock
);
1605 map
<uint64_t, LingerOp
*>::iterator iter
=
1606 objecter
->check_latest_map_lingers
.find(linger_id
);
1607 if (iter
== objecter
->check_latest_map_lingers
.end()) {
1611 LingerOp
*op
= iter
->second
;
1612 objecter
->check_latest_map_lingers
.erase(iter
);
1614 if (op
->map_dne_bound
== 0)
1615 op
->map_dne_bound
= latest
;
1618 objecter
->_check_linger_pool_dne(op
, &unregister
);
1621 objecter
->_linger_cancel(op
);
1627 void Objecter::_check_linger_pool_dne(LingerOp
*op
, bool *need_unregister
)
1629 // rwlock is locked unique
1631 *need_unregister
= false;
1633 if (op
->register_gen
> 0) {
1634 ldout(cct
, 10) << "_check_linger_pool_dne linger_id " << op
->linger_id
1635 << " pool previously existed but now does not"
1637 op
->map_dne_bound
= osdmap
->get_epoch();
1639 ldout(cct
, 10) << "_check_linger_pool_dne linger_id " << op
->linger_id
1640 << " current " << osdmap
->get_epoch()
1641 << " map_dne_bound " << op
->map_dne_bound
1644 if (op
->map_dne_bound
> 0) {
1645 if (osdmap
->get_epoch() >= op
->map_dne_bound
) {
1646 LingerOp::unique_lock wl
{op
->watch_lock
};
1647 if (op
->on_reg_commit
) {
1648 op
->on_reg_commit
->complete(-ENOENT
);
1649 op
->on_reg_commit
= nullptr;
1651 if (op
->on_notify_finish
) {
1652 op
->on_notify_finish
->complete(-ENOENT
);
1653 op
->on_notify_finish
= nullptr;
1655 *need_unregister
= true;
1658 _send_linger_map_check(op
);
1662 void Objecter::_send_linger_map_check(LingerOp
*op
)
1665 if (check_latest_map_lingers
.count(op
->linger_id
) == 0) {
1667 check_latest_map_lingers
[op
->linger_id
] = op
;
1668 C_Linger_Map_Latest
*c
= new C_Linger_Map_Latest(this, op
->linger_id
);
1669 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
1673 void Objecter::_linger_cancel_map_check(LingerOp
*op
)
1675 // rwlock is locked unique
1677 map
<uint64_t, LingerOp
*>::iterator iter
=
1678 check_latest_map_lingers
.find(op
->linger_id
);
1679 if (iter
!= check_latest_map_lingers
.end()) {
1680 LingerOp
*op
= iter
->second
;
1682 check_latest_map_lingers
.erase(iter
);
1686 // command pool check
1688 void Objecter::C_Command_Map_Latest::finish(int r
)
1690 if (r
== -EAGAIN
|| r
== -ECANCELED
) {
1691 // ignore callback; we will retry in resend_mon_ops()
1695 unique_lock
wl(objecter
->rwlock
);
1697 map
<uint64_t, CommandOp
*>::iterator iter
=
1698 objecter
->check_latest_map_commands
.find(tid
);
1699 if (iter
== objecter
->check_latest_map_commands
.end()) {
1703 CommandOp
*c
= iter
->second
;
1704 objecter
->check_latest_map_commands
.erase(iter
);
1706 if (c
->map_dne_bound
== 0)
1707 c
->map_dne_bound
= latest
;
1709 OSDSession::unique_lock
sul(c
->session
->lock
);
1710 objecter
->_check_command_map_dne(c
);
1716 void Objecter::_check_command_map_dne(CommandOp
*c
)
1718 // rwlock is locked unique
1719 // session is locked unique
1721 ldout(cct
, 10) << "_check_command_map_dne tid " << c
->tid
1722 << " current " << osdmap
->get_epoch()
1723 << " map_dne_bound " << c
->map_dne_bound
1725 if (c
->map_dne_bound
> 0) {
1726 if (osdmap
->get_epoch() >= c
->map_dne_bound
) {
1727 _finish_command(c
, c
->map_check_error
, c
->map_check_error_str
);
1730 _send_command_map_check(c
);
1734 void Objecter::_send_command_map_check(CommandOp
*c
)
1736 // rwlock is locked unique
1737 // session is locked unique
1740 if (check_latest_map_commands
.count(c
->tid
) == 0) {
1742 check_latest_map_commands
[c
->tid
] = c
;
1743 C_Command_Map_Latest
*f
= new C_Command_Map_Latest(this, c
->tid
);
1744 monc
->get_version("osdmap", &f
->latest
, NULL
, f
);
1748 void Objecter::_command_cancel_map_check(CommandOp
*c
)
1750 // rwlock is locked uniqe
1752 map
<uint64_t, CommandOp
*>::iterator iter
=
1753 check_latest_map_commands
.find(c
->tid
);
1754 if (iter
!= check_latest_map_commands
.end()) {
1755 CommandOp
*c
= iter
->second
;
1757 check_latest_map_commands
.erase(iter
);
1763 * Look up OSDSession by OSD id.
1765 * @returns 0 on success, or -EAGAIN if the lock context requires
1766 * promotion to write.
1768 int Objecter::_get_session(int osd
, OSDSession
**session
, shunique_lock
& sul
)
1770 assert(sul
&& sul
.mutex() == &rwlock
);
1773 *session
= homeless_session
;
1774 ldout(cct
, 20) << __func__
<< " osd=" << osd
<< " returning homeless"
1779 map
<int,OSDSession
*>::iterator p
= osd_sessions
.find(osd
);
1780 if (p
!= osd_sessions
.end()) {
1781 OSDSession
*s
= p
->second
;
1784 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << osd
<< " "
1785 << s
->get_nref() << dendl
;
1788 if (!sul
.owns_lock()) {
1791 OSDSession
*s
= new OSDSession(cct
, osd
);
1792 osd_sessions
[osd
] = s
;
1793 s
->con
= messenger
->get_connection(osdmap
->get_inst(osd
));
1794 s
->con
->set_priv(s
->get());
1795 logger
->inc(l_osdc_osd_session_open
);
1796 logger
->set(l_osdc_osd_sessions
, osd_sessions
.size());
1799 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << osd
<< " "
1800 << s
->get_nref() << dendl
;
1804 void Objecter::put_session(Objecter::OSDSession
*s
)
1806 if (s
&& !s
->is_homeless()) {
1807 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << s
->osd
<< " "
1808 << s
->get_nref() << dendl
;
1813 void Objecter::get_session(Objecter::OSDSession
*s
)
1817 if (!s
->is_homeless()) {
1818 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << s
->osd
<< " "
1819 << s
->get_nref() << dendl
;
1824 void Objecter::_reopen_session(OSDSession
*s
)
1826 // s->lock is locked
1828 entity_inst_t inst
= osdmap
->get_inst(s
->osd
);
1829 ldout(cct
, 10) << "reopen_session osd." << s
->osd
<< " session, addr now "
1832 s
->con
->set_priv(NULL
);
1833 s
->con
->mark_down();
1834 logger
->inc(l_osdc_osd_session_close
);
1836 s
->con
= messenger
->get_connection(inst
);
1837 s
->con
->set_priv(s
->get());
1839 logger
->inc(l_osdc_osd_session_open
);
1842 void Objecter::close_session(OSDSession
*s
)
1844 // rwlock is locked unique
1846 ldout(cct
, 10) << "close_session for osd." << s
->osd
<< dendl
;
1848 s
->con
->set_priv(NULL
);
1849 s
->con
->mark_down();
1850 logger
->inc(l_osdc_osd_session_close
);
1852 OSDSession::unique_lock
sl(s
->lock
);
1854 std::list
<LingerOp
*> homeless_lingers
;
1855 std::list
<CommandOp
*> homeless_commands
;
1856 std::list
<Op
*> homeless_ops
;
1858 while (!s
->linger_ops
.empty()) {
1859 std::map
<uint64_t, LingerOp
*>::iterator i
= s
->linger_ops
.begin();
1860 ldout(cct
, 10) << " linger_op " << i
->first
<< dendl
;
1861 homeless_lingers
.push_back(i
->second
);
1862 _session_linger_op_remove(s
, i
->second
);
1865 while (!s
->ops
.empty()) {
1866 std::map
<ceph_tid_t
, Op
*>::iterator i
= s
->ops
.begin();
1867 ldout(cct
, 10) << " op " << i
->first
<< dendl
;
1868 homeless_ops
.push_back(i
->second
);
1869 _session_op_remove(s
, i
->second
);
1872 while (!s
->command_ops
.empty()) {
1873 std::map
<ceph_tid_t
, CommandOp
*>::iterator i
= s
->command_ops
.begin();
1874 ldout(cct
, 10) << " command_op " << i
->first
<< dendl
;
1875 homeless_commands
.push_back(i
->second
);
1876 _session_command_op_remove(s
, i
->second
);
1879 osd_sessions
.erase(s
->osd
);
1883 // Assign any leftover ops to the homeless session
1885 OSDSession::unique_lock
hsl(homeless_session
->lock
);
1886 for (std::list
<LingerOp
*>::iterator i
= homeless_lingers
.begin();
1887 i
!= homeless_lingers
.end(); ++i
) {
1888 _session_linger_op_assign(homeless_session
, *i
);
1890 for (std::list
<Op
*>::iterator i
= homeless_ops
.begin();
1891 i
!= homeless_ops
.end(); ++i
) {
1892 _session_op_assign(homeless_session
, *i
);
1894 for (std::list
<CommandOp
*>::iterator i
= homeless_commands
.begin();
1895 i
!= homeless_commands
.end(); ++i
) {
1896 _session_command_op_assign(homeless_session
, *i
);
1900 logger
->set(l_osdc_osd_sessions
, osd_sessions
.size());
1903 void Objecter::wait_for_osd_map()
1905 unique_lock
l(rwlock
);
1906 if (osdmap
->get_epoch()) {
1911 // Leave this since it goes with C_SafeCond
1916 C_SafeCond
*context
= new C_SafeCond(&lock
, &cond
, &done
, NULL
);
1917 waiting_for_map
[0].push_back(pair
<Context
*, int>(context
, 0));
1924 struct C_Objecter_GetVersion
: public Context
{
1926 uint64_t oldest
, newest
;
1928 C_Objecter_GetVersion(Objecter
*o
, Context
*c
)
1929 : objecter(o
), oldest(0), newest(0), fin(c
) {}
1930 void finish(int r
) override
{
1932 objecter
->get_latest_version(oldest
, newest
, fin
);
1933 } else if (r
== -EAGAIN
) { // try again as instructed
1934 objecter
->wait_for_latest_osdmap(fin
);
1936 // it doesn't return any other error codes!
1942 void Objecter::wait_for_latest_osdmap(Context
*fin
)
1944 ldout(cct
, 10) << __func__
<< dendl
;
1945 C_Objecter_GetVersion
*c
= new C_Objecter_GetVersion(this, fin
);
1946 monc
->get_version("osdmap", &c
->newest
, &c
->oldest
, c
);
1949 void Objecter::get_latest_version(epoch_t oldest
, epoch_t newest
, Context
*fin
)
1951 unique_lock
wl(rwlock
);
1952 _get_latest_version(oldest
, newest
, fin
);
1955 void Objecter::_get_latest_version(epoch_t oldest
, epoch_t newest
,
1958 // rwlock is locked unique
1959 if (osdmap
->get_epoch() >= newest
) {
1960 ldout(cct
, 10) << __func__
<< " latest " << newest
<< ", have it" << dendl
;
1966 ldout(cct
, 10) << __func__
<< " latest " << newest
<< ", waiting" << dendl
;
1967 _wait_for_new_map(fin
, newest
, 0);
1970 void Objecter::maybe_request_map()
1972 shared_lock
rl(rwlock
);
1973 _maybe_request_map();
1976 void Objecter::_maybe_request_map()
1980 if (_osdmap_full_flag()
1981 || osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
)
1982 || osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
)) {
1983 ldout(cct
, 10) << "_maybe_request_map subscribing (continuous) to next "
1984 "osd map (FULL flag is set)" << dendl
;
1987 << "_maybe_request_map subscribing (onetime) to next osd map" << dendl
;
1988 flag
= CEPH_SUBSCRIBE_ONETIME
;
1990 epoch_t epoch
= osdmap
->get_epoch() ? osdmap
->get_epoch()+1 : 0;
1991 if (monc
->sub_want("osdmap", epoch
, flag
)) {
1996 void Objecter::_wait_for_new_map(Context
*c
, epoch_t epoch
, int err
)
1998 // rwlock is locked unique
1999 waiting_for_map
[epoch
].push_back(pair
<Context
*, int>(c
, err
));
2000 _maybe_request_map();
2005 * Use this together with wait_for_map: this is a pre-check to avoid
2006 * allocating a Context for wait_for_map if we can see that we
2007 * definitely already have the epoch.
2009 * This does *not* replace the need to handle the return value of
2010 * wait_for_map: just because we don't have it in this pre-check
2011 * doesn't mean we won't have it when calling back into wait_for_map,
2012 * since the objecter lock is dropped in between.
2014 bool Objecter::have_map(const epoch_t epoch
)
2016 shared_lock
rl(rwlock
);
2017 if (osdmap
->get_epoch() >= epoch
) {
2024 bool Objecter::wait_for_map(epoch_t epoch
, Context
*c
, int err
)
2026 unique_lock
wl(rwlock
);
2027 if (osdmap
->get_epoch() >= epoch
) {
2030 _wait_for_new_map(c
, epoch
, err
);
2034 void Objecter::kick_requests(OSDSession
*session
)
2036 ldout(cct
, 10) << "kick_requests for osd." << session
->osd
<< dendl
;
2038 map
<uint64_t, LingerOp
*> lresend
;
2039 unique_lock
wl(rwlock
);
2041 OSDSession::unique_lock
sl(session
->lock
);
2042 _kick_requests(session
, lresend
);
2045 _linger_ops_resend(lresend
, wl
);
2048 void Objecter::_kick_requests(OSDSession
*session
,
2049 map
<uint64_t, LingerOp
*>& lresend
)
2051 // rwlock is locked unique
2054 session
->backoffs
.clear();
2055 session
->backoffs_by_id
.clear();
2058 map
<ceph_tid_t
,Op
*> resend
; // resend in tid order
2059 for (map
<ceph_tid_t
, Op
*>::iterator p
= session
->ops
.begin();
2060 p
!= session
->ops
.end();) {
2063 logger
->inc(l_osdc_op_resend
);
2064 if (op
->should_resend
) {
2065 if (!op
->target
.paused
)
2066 resend
[op
->tid
] = op
;
2068 _op_cancel_map_check(op
);
2069 _cancel_linger_op(op
);
2073 while (!resend
.empty()) {
2074 _send_op(resend
.begin()->second
);
2075 resend
.erase(resend
.begin());
2079 for (map
<ceph_tid_t
, LingerOp
*>::iterator j
= session
->linger_ops
.begin();
2080 j
!= session
->linger_ops
.end(); ++j
) {
2081 LingerOp
*op
= j
->second
;
2083 logger
->inc(l_osdc_linger_resend
);
2084 assert(lresend
.count(j
->first
) == 0);
2085 lresend
[j
->first
] = op
;
2089 map
<uint64_t,CommandOp
*> cresend
; // resend in order
2090 for (map
<ceph_tid_t
, CommandOp
*>::iterator k
= session
->command_ops
.begin();
2091 k
!= session
->command_ops
.end(); ++k
) {
2092 logger
->inc(l_osdc_command_resend
);
2093 cresend
[k
->first
] = k
->second
;
2095 while (!cresend
.empty()) {
2096 _send_command(cresend
.begin()->second
);
2097 cresend
.erase(cresend
.begin());
2101 void Objecter::_linger_ops_resend(map
<uint64_t, LingerOp
*>& lresend
,
2104 assert(ul
.owns_lock());
2105 shunique_lock
sul(std::move(ul
));
2106 while (!lresend
.empty()) {
2107 LingerOp
*op
= lresend
.begin()->second
;
2108 if (!op
->canceled
) {
2109 _send_linger(op
, sul
);
2112 lresend
.erase(lresend
.begin());
2114 ul
= unique_lock(sul
.release_to_unique());
2117 void Objecter::start_tick()
2119 assert(tick_event
== 0);
2121 timer
.add_event(ceph::make_timespan(cct
->_conf
->objecter_tick_interval
),
2122 &Objecter::tick
, this);
2125 void Objecter::tick()
2127 shared_lock
rl(rwlock
);
2129 ldout(cct
, 10) << "tick" << dendl
;
2131 // we are only called by C_Tick
2135 // we raced with shutdown
2136 ldout(cct
, 10) << __func__
<< " raced with shutdown" << dendl
;
2140 set
<OSDSession
*> toping
;
2143 // look for laggy requests
2144 auto cutoff
= ceph::mono_clock::now();
2145 cutoff
-= ceph::make_timespan(cct
->_conf
->objecter_timeout
); // timeout
2147 unsigned laggy_ops
= 0;
2149 for (map
<int,OSDSession
*>::iterator siter
= osd_sessions
.begin();
2150 siter
!= osd_sessions
.end(); ++siter
) {
2151 OSDSession
*s
= siter
->second
;
2152 OSDSession::lock_guard
l(s
->lock
);
2154 for (map
<ceph_tid_t
,Op
*>::iterator p
= s
->ops
.begin();
2158 assert(op
->session
);
2159 if (op
->stamp
< cutoff
) {
2160 ldout(cct
, 2) << " tid " << p
->first
<< " on osd." << op
->session
->osd
2161 << " is laggy" << dendl
;
2166 for (map
<uint64_t,LingerOp
*>::iterator p
= s
->linger_ops
.begin();
2167 p
!= s
->linger_ops
.end();
2169 LingerOp
*op
= p
->second
;
2170 LingerOp::unique_lock
wl(op
->watch_lock
);
2171 assert(op
->session
);
2172 ldout(cct
, 10) << " pinging osd that serves lingering tid " << p
->first
2173 << " (osd." << op
->session
->osd
<< ")" << dendl
;
2175 if (op
->is_watch
&& op
->registered
&& !op
->last_error
)
2176 _send_linger_ping(op
);
2178 for (map
<uint64_t,CommandOp
*>::iterator p
= s
->command_ops
.begin();
2179 p
!= s
->command_ops
.end();
2181 CommandOp
*op
= p
->second
;
2182 assert(op
->session
);
2183 ldout(cct
, 10) << " pinging osd that serves command tid " << p
->first
2184 << " (osd." << op
->session
->osd
<< ")" << dendl
;
2190 if (num_homeless_ops
|| !toping
.empty()) {
2191 _maybe_request_map();
2194 logger
->set(l_osdc_op_laggy
, laggy_ops
);
2195 logger
->set(l_osdc_osd_laggy
, toping
.size());
2197 if (!toping
.empty()) {
2198 // send a ping to these osds, to ensure we detect any session resets
2199 // (osd reply message policy is lossy)
2200 for (set
<OSDSession
*>::const_iterator i
= toping
.begin();
2203 (*i
)->con
->send_message(new MPing
);
2207 // Make sure we don't resechedule if we wake up after shutdown
2209 tick_event
= timer
.reschedule_me(ceph::make_timespan(
2210 cct
->_conf
->objecter_tick_interval
));
2214 void Objecter::resend_mon_ops()
2216 unique_lock
wl(rwlock
);
2218 ldout(cct
, 10) << "resend_mon_ops" << dendl
;
2220 for (map
<ceph_tid_t
,PoolStatOp
*>::iterator p
= poolstat_ops
.begin();
2221 p
!= poolstat_ops
.end();
2223 _poolstat_submit(p
->second
);
2224 logger
->inc(l_osdc_poolstat_resend
);
2227 for (map
<ceph_tid_t
,StatfsOp
*>::iterator p
= statfs_ops
.begin();
2228 p
!= statfs_ops
.end();
2230 _fs_stats_submit(p
->second
);
2231 logger
->inc(l_osdc_statfs_resend
);
2234 for (map
<ceph_tid_t
,PoolOp
*>::iterator p
= pool_ops
.begin();
2235 p
!= pool_ops
.end();
2237 _pool_op_submit(p
->second
);
2238 logger
->inc(l_osdc_poolop_resend
);
2241 for (map
<ceph_tid_t
, Op
*>::iterator p
= check_latest_map_ops
.begin();
2242 p
!= check_latest_map_ops
.end();
2244 C_Op_Map_Latest
*c
= new C_Op_Map_Latest(this, p
->second
->tid
);
2245 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
2248 for (map
<uint64_t, LingerOp
*>::iterator p
= check_latest_map_lingers
.begin();
2249 p
!= check_latest_map_lingers
.end();
2251 C_Linger_Map_Latest
*c
2252 = new C_Linger_Map_Latest(this, p
->second
->linger_id
);
2253 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
2256 for (map
<uint64_t, CommandOp
*>::iterator p
2257 = check_latest_map_commands
.begin();
2258 p
!= check_latest_map_commands
.end();
2260 C_Command_Map_Latest
*c
= new C_Command_Map_Latest(this, p
->second
->tid
);
2261 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
2265 // read | write ---------------------------
2267 void Objecter::op_submit(Op
*op
, ceph_tid_t
*ptid
, int *ctx_budget
)
2269 shunique_lock
rl(rwlock
, ceph::acquire_shared
);
2273 op
->trace
.event("op submit");
2274 _op_submit_with_budget(op
, rl
, ptid
, ctx_budget
);
2277 void Objecter::_op_submit_with_budget(Op
*op
, shunique_lock
& sul
,
2281 assert(initialized
);
2283 assert(op
->ops
.size() == op
->out_bl
.size());
2284 assert(op
->ops
.size() == op
->out_rval
.size());
2285 assert(op
->ops
.size() == op
->out_handler
.size());
2287 // throttle. before we look at any state, because
2288 // _take_op_budget() may drop our lock while it blocks.
2289 if (!op
->ctx_budgeted
|| (ctx_budget
&& (*ctx_budget
== -1))) {
2290 int op_budget
= _take_op_budget(op
, sul
);
2291 // take and pass out the budget for the first OP
2292 // in the context session
2293 if (ctx_budget
&& (*ctx_budget
== -1)) {
2294 *ctx_budget
= op_budget
;
2298 if (osd_timeout
> timespan(0)) {
2300 op
->tid
= ++last_tid
;
2302 op
->ontimeout
= timer
.add_event(osd_timeout
,
2304 op_cancel(tid
, -ETIMEDOUT
); });
2307 _op_submit(op
, sul
, ptid
);
2310 void Objecter::_send_op_account(Op
*op
)
2314 // add to gather set(s)
2318 ldout(cct
, 20) << " note: not requesting reply" << dendl
;
2321 logger
->inc(l_osdc_op_active
);
2322 logger
->inc(l_osdc_op
);
2324 if ((op
->target
.flags
& (CEPH_OSD_FLAG_READ
| CEPH_OSD_FLAG_WRITE
)) ==
2325 (CEPH_OSD_FLAG_READ
|CEPH_OSD_FLAG_WRITE
))
2326 logger
->inc(l_osdc_op_rmw
);
2327 else if (op
->target
.flags
& CEPH_OSD_FLAG_WRITE
)
2328 logger
->inc(l_osdc_op_w
);
2329 else if (op
->target
.flags
& CEPH_OSD_FLAG_READ
)
2330 logger
->inc(l_osdc_op_r
);
2332 if (op
->target
.flags
& CEPH_OSD_FLAG_PGOP
)
2333 logger
->inc(l_osdc_op_pg
);
2335 for (vector
<OSDOp
>::iterator p
= op
->ops
.begin(); p
!= op
->ops
.end(); ++p
) {
2336 int code
= l_osdc_osdop_other
;
2338 case CEPH_OSD_OP_STAT
: code
= l_osdc_osdop_stat
; break;
2339 case CEPH_OSD_OP_CREATE
: code
= l_osdc_osdop_create
; break;
2340 case CEPH_OSD_OP_READ
: code
= l_osdc_osdop_read
; break;
2341 case CEPH_OSD_OP_WRITE
: code
= l_osdc_osdop_write
; break;
2342 case CEPH_OSD_OP_WRITEFULL
: code
= l_osdc_osdop_writefull
; break;
2343 case CEPH_OSD_OP_WRITESAME
: code
= l_osdc_osdop_writesame
; break;
2344 case CEPH_OSD_OP_APPEND
: code
= l_osdc_osdop_append
; break;
2345 case CEPH_OSD_OP_ZERO
: code
= l_osdc_osdop_zero
; break;
2346 case CEPH_OSD_OP_TRUNCATE
: code
= l_osdc_osdop_truncate
; break;
2347 case CEPH_OSD_OP_DELETE
: code
= l_osdc_osdop_delete
; break;
2348 case CEPH_OSD_OP_MAPEXT
: code
= l_osdc_osdop_mapext
; break;
2349 case CEPH_OSD_OP_SPARSE_READ
: code
= l_osdc_osdop_sparse_read
; break;
2350 case CEPH_OSD_OP_GETXATTR
: code
= l_osdc_osdop_getxattr
; break;
2351 case CEPH_OSD_OP_SETXATTR
: code
= l_osdc_osdop_setxattr
; break;
2352 case CEPH_OSD_OP_CMPXATTR
: code
= l_osdc_osdop_cmpxattr
; break;
2353 case CEPH_OSD_OP_RMXATTR
: code
= l_osdc_osdop_rmxattr
; break;
2354 case CEPH_OSD_OP_RESETXATTRS
: code
= l_osdc_osdop_resetxattrs
; break;
2355 case CEPH_OSD_OP_TMAPUP
: code
= l_osdc_osdop_tmap_up
; break;
2356 case CEPH_OSD_OP_TMAPPUT
: code
= l_osdc_osdop_tmap_put
; break;
2357 case CEPH_OSD_OP_TMAPGET
: code
= l_osdc_osdop_tmap_get
; break;
2359 // OMAP read operations
2360 case CEPH_OSD_OP_OMAPGETVALS
:
2361 case CEPH_OSD_OP_OMAPGETKEYS
:
2362 case CEPH_OSD_OP_OMAPGETHEADER
:
2363 case CEPH_OSD_OP_OMAPGETVALSBYKEYS
:
2364 case CEPH_OSD_OP_OMAP_CMP
: code
= l_osdc_osdop_omap_rd
; break;
2366 // OMAP write operations
2367 case CEPH_OSD_OP_OMAPSETVALS
:
2368 case CEPH_OSD_OP_OMAPSETHEADER
: code
= l_osdc_osdop_omap_wr
; break;
2370 // OMAP del operations
2371 case CEPH_OSD_OP_OMAPCLEAR
:
2372 case CEPH_OSD_OP_OMAPRMKEYS
: code
= l_osdc_osdop_omap_del
; break;
2374 case CEPH_OSD_OP_CALL
: code
= l_osdc_osdop_call
; break;
2375 case CEPH_OSD_OP_WATCH
: code
= l_osdc_osdop_watch
; break;
2376 case CEPH_OSD_OP_NOTIFY
: code
= l_osdc_osdop_notify
; break;
2383 void Objecter::_op_submit(Op
*op
, shunique_lock
& sul
, ceph_tid_t
*ptid
)
2387 ldout(cct
, 10) << __func__
<< " op " << op
<< dendl
;
2390 assert(op
->session
== NULL
);
2391 OSDSession
*s
= NULL
;
2393 bool check_for_latest_map
= _calc_target(&op
->target
, nullptr)
2394 == RECALC_OP_TARGET_POOL_DNE
;
2396 // Try to get a session, including a retry if we need to take write lock
2397 int r
= _get_session(op
->target
.osd
, &s
, sul
);
2399 (check_for_latest_map
&& sul
.owns_lock_shared())) {
2400 epoch_t orig_epoch
= osdmap
->get_epoch();
2402 if (cct
->_conf
->objecter_debug_inject_relock_delay
) {
2406 if (orig_epoch
!= osdmap
->get_epoch()) {
2407 // map changed; recalculate mapping
2408 ldout(cct
, 10) << __func__
<< " relock raced with osdmap, recalc target"
2410 check_for_latest_map
= _calc_target(&op
->target
, nullptr)
2411 == RECALC_OP_TARGET_POOL_DNE
;
2421 r
= _get_session(op
->target
.osd
, &s
, sul
);
2424 assert(s
); // may be homeless
2426 _send_op_account(op
);
2430 assert(op
->target
.flags
& (CEPH_OSD_FLAG_READ
|CEPH_OSD_FLAG_WRITE
));
2432 if (osdmap_full_try
) {
2433 op
->target
.flags
|= CEPH_OSD_FLAG_FULL_TRY
;
2436 bool need_send
= false;
2438 if (osdmap
->get_epoch() < epoch_barrier
) {
2439 ldout(cct
, 10) << " barrier, paused " << op
<< " tid " << op
->tid
2441 op
->target
.paused
= true;
2442 _maybe_request_map();
2443 } else if ((op
->target
.flags
& CEPH_OSD_FLAG_WRITE
) &&
2444 osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
)) {
2445 ldout(cct
, 10) << " paused modify " << op
<< " tid " << op
->tid
2447 op
->target
.paused
= true;
2448 _maybe_request_map();
2449 } else if ((op
->target
.flags
& CEPH_OSD_FLAG_READ
) &&
2450 osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
)) {
2451 ldout(cct
, 10) << " paused read " << op
<< " tid " << op
->tid
2453 op
->target
.paused
= true;
2454 _maybe_request_map();
2455 } else if (op
->respects_full() &&
2456 (_osdmap_full_flag() ||
2457 _osdmap_pool_full(op
->target
.base_oloc
.pool
))) {
2458 ldout(cct
, 0) << " FULL, paused modify " << op
<< " tid "
2459 << op
->tid
<< dendl
;
2460 op
->target
.paused
= true;
2461 _maybe_request_map();
2462 } else if (!s
->is_homeless()) {
2465 _maybe_request_map();
2470 m
= _prepare_osd_op(op
);
2473 OSDSession::unique_lock
sl(s
->lock
);
2475 op
->tid
= ++last_tid
;
2477 ldout(cct
, 10) << "_op_submit oid " << op
->target
.base_oid
2478 << " '" << op
->target
.base_oloc
<< "' '"
2479 << op
->target
.target_oloc
<< "' " << op
->ops
<< " tid "
2480 << op
->tid
<< " osd." << (!s
->is_homeless() ? s
->osd
: -1)
2483 _session_op_assign(s
, op
);
2489 // Last chance to touch Op here, after giving up session lock it can
2490 // be freed at any time by response handler.
2491 ceph_tid_t tid
= op
->tid
;
2492 if (check_for_latest_map
) {
2493 _send_op_map_check(op
);
2502 ldout(cct
, 5) << num_in_flight
<< " in flight" << dendl
;
2505 int Objecter::op_cancel(OSDSession
*s
, ceph_tid_t tid
, int r
)
2507 assert(initialized
);
2509 OSDSession::unique_lock
sl(s
->lock
);
2511 map
<ceph_tid_t
, Op
*>::iterator p
= s
->ops
.find(tid
);
2512 if (p
== s
->ops
.end()) {
2513 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne in session "
2519 ldout(cct
, 20) << " revoking rx buffer for " << tid
2520 << " on " << s
->con
<< dendl
;
2521 s
->con
->revoke_rx_buffer(tid
);
2524 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " in session " << s
->osd
2529 op
->onfinish
->complete(r
);
2530 op
->onfinish
= NULL
;
2532 _op_cancel_map_check(op
);
2539 int Objecter::op_cancel(ceph_tid_t tid
, int r
)
2543 unique_lock
wl(rwlock
);
2544 ret
= _op_cancel(tid
, r
);
2549 int Objecter::op_cancel(const vector
<ceph_tid_t
>& tids
, int r
)
2551 unique_lock
wl(rwlock
);
2552 ldout(cct
,10) << __func__
<< " " << tids
<< dendl
;
2553 for (auto tid
: tids
) {
2559 int Objecter::_op_cancel(ceph_tid_t tid
, int r
)
2563 ldout(cct
, 5) << __func__
<< ": cancelling tid " << tid
<< " r=" << r
2568 for (map
<int, OSDSession
*>::iterator siter
= osd_sessions
.begin();
2569 siter
!= osd_sessions
.end(); ++siter
) {
2570 OSDSession
*s
= siter
->second
;
2571 OSDSession::shared_lock
sl(s
->lock
);
2572 if (s
->ops
.find(tid
) != s
->ops
.end()) {
2574 ret
= op_cancel(s
, tid
, r
);
2575 if (ret
== -ENOENT
) {
2576 /* oh no! raced, maybe tid moved to another session, restarting */
2583 ldout(cct
, 5) << __func__
<< ": tid " << tid
2584 << " not found in live sessions" << dendl
;
2586 // Handle case where the op is in homeless session
2587 OSDSession::shared_lock
sl(homeless_session
->lock
);
2588 if (homeless_session
->ops
.find(tid
) != homeless_session
->ops
.end()) {
2590 ret
= op_cancel(homeless_session
, tid
, r
);
2591 if (ret
== -ENOENT
) {
2592 /* oh no! raced, maybe tid moved to another session, restarting */
2601 ldout(cct
, 5) << __func__
<< ": tid " << tid
2602 << " not found in homeless session" << dendl
;
2608 epoch_t
Objecter::op_cancel_writes(int r
, int64_t pool
)
2610 unique_lock
wl(rwlock
);
2612 std::vector
<ceph_tid_t
> to_cancel
;
2615 for (map
<int, OSDSession
*>::iterator siter
= osd_sessions
.begin();
2616 siter
!= osd_sessions
.end(); ++siter
) {
2617 OSDSession
*s
= siter
->second
;
2618 OSDSession::shared_lock
sl(s
->lock
);
2619 for (map
<ceph_tid_t
, Op
*>::iterator op_i
= s
->ops
.begin();
2620 op_i
!= s
->ops
.end(); ++op_i
) {
2621 if (op_i
->second
->target
.flags
& CEPH_OSD_FLAG_WRITE
2622 && (pool
== -1 || op_i
->second
->target
.target_oloc
.pool
== pool
)) {
2623 to_cancel
.push_back(op_i
->first
);
2628 for (std::vector
<ceph_tid_t
>::iterator titer
= to_cancel
.begin();
2629 titer
!= to_cancel
.end();
2631 int cancel_result
= op_cancel(s
, *titer
, r
);
2632 // We hold rwlock across search and cancellation, so cancels
2633 // should always succeed
2634 assert(cancel_result
== 0);
2636 if (!found
&& to_cancel
.size())
2641 const epoch_t epoch
= osdmap
->get_epoch();
2652 bool Objecter::is_pg_changed(
2654 const vector
<int>& oldacting
,
2656 const vector
<int>& newacting
,
2659 if (OSDMap::primary_changed(
2665 if (any_change
&& oldacting
!= newacting
)
2667 return false; // same primary (tho replicas may have changed)
2670 bool Objecter::target_should_be_paused(op_target_t
*t
)
2672 const pg_pool_t
*pi
= osdmap
->get_pg_pool(t
->base_oloc
.pool
);
2673 bool pauserd
= osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
);
2674 bool pausewr
= osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
) ||
2675 _osdmap_full_flag() || _osdmap_pool_full(*pi
);
2677 return (t
->flags
& CEPH_OSD_FLAG_READ
&& pauserd
) ||
2678 (t
->flags
& CEPH_OSD_FLAG_WRITE
&& pausewr
) ||
2679 (osdmap
->get_epoch() < epoch_barrier
);
2683 * Locking public accessor for _osdmap_full_flag
2685 bool Objecter::osdmap_full_flag() const
2687 shared_lock
rl(rwlock
);
2689 return _osdmap_full_flag();
2692 bool Objecter::osdmap_pool_full(const int64_t pool_id
) const
2694 shared_lock
rl(rwlock
);
2696 if (_osdmap_full_flag()) {
2700 return _osdmap_pool_full(pool_id
);
2703 bool Objecter::_osdmap_pool_full(const int64_t pool_id
) const
2705 const pg_pool_t
*pool
= osdmap
->get_pg_pool(pool_id
);
2707 ldout(cct
, 4) << __func__
<< ": DNE pool " << pool_id
<< dendl
;
2711 return _osdmap_pool_full(*pool
);
2714 bool Objecter::_osdmap_has_pool_full() const
2716 for (map
<int64_t, pg_pool_t
>::const_iterator it
2717 = osdmap
->get_pools().begin();
2718 it
!= osdmap
->get_pools().end(); ++it
) {
2719 if (_osdmap_pool_full(it
->second
))
2725 bool Objecter::_osdmap_pool_full(const pg_pool_t
&p
) const
2727 return p
.has_flag(pg_pool_t::FLAG_FULL
) && honor_osdmap_full
;
2731 * Wrapper around osdmap->test_flag for special handling of the FULL flag.
2733 bool Objecter::_osdmap_full_flag() const
2735 // Ignore the FULL flag if the caller has honor_osdmap_full
2736 return osdmap
->test_flag(CEPH_OSDMAP_FULL
) && honor_osdmap_full
;
2739 void Objecter::update_pool_full_map(map
<int64_t, bool>& pool_full_map
)
2741 for (map
<int64_t, pg_pool_t
>::const_iterator it
2742 = osdmap
->get_pools().begin();
2743 it
!= osdmap
->get_pools().end(); ++it
) {
2744 if (pool_full_map
.find(it
->first
) == pool_full_map
.end()) {
2745 pool_full_map
[it
->first
] = _osdmap_pool_full(it
->second
);
2747 pool_full_map
[it
->first
] = _osdmap_pool_full(it
->second
) ||
2748 pool_full_map
[it
->first
];
2753 int64_t Objecter::get_object_hash_position(int64_t pool
, const string
& key
,
2756 shared_lock
rl(rwlock
);
2757 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
2760 return p
->hash_key(key
, ns
);
2763 int64_t Objecter::get_object_pg_hash_position(int64_t pool
, const string
& key
,
2766 shared_lock
rl(rwlock
);
2767 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
2770 return p
->raw_hash_to_pg(p
->hash_key(key
, ns
));
2773 int Objecter::_calc_target(op_target_t
*t
, Connection
*con
, bool any_change
)
2776 bool is_read
= t
->flags
& CEPH_OSD_FLAG_READ
;
2777 bool is_write
= t
->flags
& CEPH_OSD_FLAG_WRITE
;
2778 t
->epoch
= osdmap
->get_epoch();
2779 ldout(cct
,20) << __func__
<< " epoch " << t
->epoch
2780 << " base " << t
->base_oid
<< " " << t
->base_oloc
2781 << " precalc_pgid " << (int)t
->precalc_pgid
2782 << " pgid " << t
->base_pgid
2783 << (is_read
? " is_read" : "")
2784 << (is_write
? " is_write" : "")
2787 const pg_pool_t
*pi
= osdmap
->get_pg_pool(t
->base_oloc
.pool
);
2790 return RECALC_OP_TARGET_POOL_DNE
;
2792 ldout(cct
,30) << __func__
<< " base pi " << pi
2793 << " pg_num " << pi
->get_pg_num() << dendl
;
2795 bool force_resend
= false;
2796 if (osdmap
->get_epoch() == pi
->last_force_op_resend
) {
2797 if (t
->last_force_resend
< pi
->last_force_op_resend
) {
2798 t
->last_force_resend
= pi
->last_force_op_resend
;
2799 force_resend
= true;
2800 } else if (t
->last_force_resend
== 0) {
2801 force_resend
= true;
2806 t
->target_oid
= t
->base_oid
;
2807 t
->target_oloc
= t
->base_oloc
;
2808 if ((t
->flags
& CEPH_OSD_FLAG_IGNORE_OVERLAY
) == 0) {
2809 if (is_read
&& pi
->has_read_tier())
2810 t
->target_oloc
.pool
= pi
->read_tier
;
2811 if (is_write
&& pi
->has_write_tier())
2812 t
->target_oloc
.pool
= pi
->write_tier
;
2813 pi
= osdmap
->get_pg_pool(t
->target_oloc
.pool
);
2816 return RECALC_OP_TARGET_POOL_DNE
;
2821 if (t
->precalc_pgid
) {
2822 assert(t
->flags
& CEPH_OSD_FLAG_IGNORE_OVERLAY
);
2823 assert(t
->base_oid
.name
.empty()); // make sure this is a pg op
2824 assert(t
->base_oloc
.pool
== (int64_t)t
->base_pgid
.pool());
2825 pgid
= t
->base_pgid
;
2827 int ret
= osdmap
->object_locator_to_pg(t
->target_oid
, t
->target_oloc
,
2829 if (ret
== -ENOENT
) {
2831 return RECALC_OP_TARGET_POOL_DNE
;
2834 ldout(cct
,20) << __func__
<< " target " << t
->target_oid
<< " "
2835 << t
->target_oloc
<< " -> pgid " << pgid
<< dendl
;
2836 ldout(cct
,30) << __func__
<< " target pi " << pi
2837 << " pg_num " << pi
->get_pg_num() << dendl
;
2838 t
->pool_ever_existed
= true;
2840 int size
= pi
->size
;
2841 int min_size
= pi
->min_size
;
2842 unsigned pg_num
= pi
->get_pg_num();
2843 int up_primary
, acting_primary
;
2844 vector
<int> up
, acting
;
2845 osdmap
->pg_to_up_acting_osds(pgid
, &up
, &up_primary
,
2846 &acting
, &acting_primary
);
2847 bool sort_bitwise
= osdmap
->test_flag(CEPH_OSDMAP_SORTBITWISE
);
2848 bool recovery_deletes
= osdmap
->test_flag(CEPH_OSDMAP_RECOVERY_DELETES
);
2849 unsigned prev_seed
= ceph_stable_mod(pgid
.ps(), t
->pg_num
, t
->pg_num_mask
);
2850 pg_t
prev_pgid(prev_seed
, pgid
.pool());
2851 if (any_change
&& PastIntervals::is_new_interval(
2868 t
->recovery_deletes
,
2871 force_resend
= true;
2874 bool unpaused
= false;
2875 if (t
->paused
&& !target_should_be_paused(t
)) {
2880 bool legacy_change
=
2883 t
->acting_primary
, t
->acting
, acting_primary
, acting
,
2884 t
->used_replica
|| any_change
);
2887 split
= prev_pgid
.is_split(t
->pg_num
, pg_num
, nullptr);
2890 if (legacy_change
|| split
|| force_resend
) {
2893 t
->acting_primary
= acting_primary
;
2894 t
->up_primary
= up_primary
;
2897 t
->min_size
= min_size
;
2899 t
->pg_num_mask
= pi
->get_pg_num_mask();
2900 osdmap
->get_primary_shard(
2901 pg_t(ceph_stable_mod(pgid
.ps(), t
->pg_num
, t
->pg_num_mask
), pgid
.pool()),
2903 t
->sort_bitwise
= sort_bitwise
;
2904 t
->recovery_deletes
= recovery_deletes
;
2905 ldout(cct
, 10) << __func__
<< " "
2906 << " raw pgid " << pgid
<< " -> actual " << t
->actual_pgid
2907 << " acting " << acting
2908 << " primary " << acting_primary
<< dendl
;
2909 t
->used_replica
= false;
2910 if (acting_primary
== -1) {
2914 bool read
= is_read
&& !is_write
;
2915 if (read
&& (t
->flags
& CEPH_OSD_FLAG_BALANCE_READS
)) {
2916 int p
= rand() % acting
.size();
2918 t
->used_replica
= true;
2920 ldout(cct
, 10) << " chose random osd." << osd
<< " of " << acting
2922 } else if (read
&& (t
->flags
& CEPH_OSD_FLAG_LOCALIZE_READS
) &&
2923 acting
.size() > 1) {
2924 // look for a local replica. prefer the primary if the
2925 // distance is the same.
2927 int best_locality
= 0;
2928 for (unsigned i
= 0; i
< acting
.size(); ++i
) {
2929 int locality
= osdmap
->crush
->get_common_ancestor_distance(
2930 cct
, acting
[i
], crush_location
);
2931 ldout(cct
, 20) << __func__
<< " localize: rank " << i
2932 << " osd." << acting
[i
]
2933 << " locality " << locality
<< dendl
;
2935 (locality
>= 0 && best_locality
>= 0 &&
2936 locality
< best_locality
) ||
2937 (best_locality
< 0 && locality
>= 0)) {
2939 best_locality
= locality
;
2941 t
->used_replica
= true;
2947 osd
= acting_primary
;
2952 if (legacy_change
|| unpaused
|| force_resend
) {
2953 return RECALC_OP_TARGET_NEED_RESEND
;
2955 if (split
&& con
&& con
->has_features(CEPH_FEATUREMASK_RESEND_ON_SPLIT
)) {
2956 return RECALC_OP_TARGET_NEED_RESEND
;
2958 return RECALC_OP_TARGET_NO_ACTION
;
2961 int Objecter::_map_session(op_target_t
*target
, OSDSession
**s
,
2964 _calc_target(target
, nullptr);
2965 return _get_session(target
->osd
, s
, sul
);
2968 void Objecter::_session_op_assign(OSDSession
*to
, Op
*op
)
2970 // to->lock is locked
2971 assert(op
->session
== NULL
);
2976 to
->ops
[op
->tid
] = op
;
2978 if (to
->is_homeless()) {
2982 ldout(cct
, 15) << __func__
<< " " << to
->osd
<< " " << op
->tid
<< dendl
;
2985 void Objecter::_session_op_remove(OSDSession
*from
, Op
*op
)
2987 assert(op
->session
== from
);
2988 // from->lock is locked
2990 if (from
->is_homeless()) {
2994 from
->ops
.erase(op
->tid
);
2998 ldout(cct
, 15) << __func__
<< " " << from
->osd
<< " " << op
->tid
<< dendl
;
3001 void Objecter::_session_linger_op_assign(OSDSession
*to
, LingerOp
*op
)
3003 // to lock is locked unique
3004 assert(op
->session
== NULL
);
3006 if (to
->is_homeless()) {
3012 to
->linger_ops
[op
->linger_id
] = op
;
3014 ldout(cct
, 15) << __func__
<< " " << to
->osd
<< " " << op
->linger_id
3018 void Objecter::_session_linger_op_remove(OSDSession
*from
, LingerOp
*op
)
3020 assert(from
== op
->session
);
3021 // from->lock is locked unique
3023 if (from
->is_homeless()) {
3027 from
->linger_ops
.erase(op
->linger_id
);
3031 ldout(cct
, 15) << __func__
<< " " << from
->osd
<< " " << op
->linger_id
3035 void Objecter::_session_command_op_remove(OSDSession
*from
, CommandOp
*op
)
3037 assert(from
== op
->session
);
3038 // from->lock is locked
3040 if (from
->is_homeless()) {
3044 from
->command_ops
.erase(op
->tid
);
3048 ldout(cct
, 15) << __func__
<< " " << from
->osd
<< " " << op
->tid
<< dendl
;
3051 void Objecter::_session_command_op_assign(OSDSession
*to
, CommandOp
*op
)
3053 // to->lock is locked
3054 assert(op
->session
== NULL
);
3057 if (to
->is_homeless()) {
3063 to
->command_ops
[op
->tid
] = op
;
3065 ldout(cct
, 15) << __func__
<< " " << to
->osd
<< " " << op
->tid
<< dendl
;
3068 int Objecter::_recalc_linger_op_target(LingerOp
*linger_op
,
3071 // rwlock is locked unique
3073 int r
= _calc_target(&linger_op
->target
, nullptr, true);
3074 if (r
== RECALC_OP_TARGET_NEED_RESEND
) {
3075 ldout(cct
, 10) << "recalc_linger_op_target tid " << linger_op
->linger_id
3076 << " pgid " << linger_op
->target
.pgid
3077 << " acting " << linger_op
->target
.acting
<< dendl
;
3079 OSDSession
*s
= NULL
;
3080 r
= _get_session(linger_op
->target
.osd
, &s
, sul
);
3083 if (linger_op
->session
!= s
) {
3084 // NB locking two sessions (s and linger_op->session) at the
3085 // same time here is only safe because we are the only one that
3086 // takes two, and we are holding rwlock for write. Disable
3087 // lockdep because it doesn't know that.
3088 OSDSession::unique_lock
sl(s
->lock
);
3089 _session_linger_op_remove(linger_op
->session
, linger_op
);
3090 _session_linger_op_assign(s
, linger_op
);
3094 return RECALC_OP_TARGET_NEED_RESEND
;
3099 void Objecter::_cancel_linger_op(Op
*op
)
3101 ldout(cct
, 15) << "cancel_op " << op
->tid
<< dendl
;
3103 assert(!op
->should_resend
);
3105 delete op
->onfinish
;
3112 void Objecter::_finish_op(Op
*op
, int r
)
3114 ldout(cct
, 15) << "finish_op " << op
->tid
<< dendl
;
3116 // op->session->lock is locked unique or op->session is null
3118 if (!op
->ctx_budgeted
&& op
->budgeted
)
3121 if (op
->ontimeout
&& r
!= -ETIMEDOUT
)
3122 timer
.cancel_event(op
->ontimeout
);
3125 _session_op_remove(op
->session
, op
);
3128 logger
->dec(l_osdc_op_active
);
3130 assert(check_latest_map_ops
.find(op
->tid
) == check_latest_map_ops
.end());
3137 void Objecter::finish_op(OSDSession
*session
, ceph_tid_t tid
)
3139 ldout(cct
, 15) << "finish_op " << tid
<< dendl
;
3140 shared_lock
rl(rwlock
);
3142 OSDSession::unique_lock
wl(session
->lock
);
3144 map
<ceph_tid_t
, Op
*>::iterator iter
= session
->ops
.find(tid
);
3145 if (iter
== session
->ops
.end())
3148 Op
*op
= iter
->second
;
3153 MOSDOp
*Objecter::_prepare_osd_op(Op
*op
)
3157 int flags
= op
->target
.flags
;
3158 flags
|= CEPH_OSD_FLAG_KNOWN_REDIR
;
3160 // Nothing checks this any longer, but needed for compatibility with
3161 // pre-luminous osds
3162 flags
|= CEPH_OSD_FLAG_ONDISK
;
3164 if (!honor_osdmap_full
)
3165 flags
|= CEPH_OSD_FLAG_FULL_FORCE
;
3167 op
->target
.paused
= false;
3168 op
->stamp
= ceph::mono_clock::now();
3170 hobject_t hobj
= op
->target
.get_hobj();
3171 MOSDOp
*m
= new MOSDOp(client_inc
, op
->tid
,
3172 hobj
, op
->target
.actual_pgid
,
3173 osdmap
->get_epoch(),
3174 flags
, op
->features
);
3176 m
->set_snapid(op
->snapid
);
3177 m
->set_snap_seq(op
->snapc
.seq
);
3178 m
->set_snaps(op
->snapc
.snaps
);
3181 m
->set_mtime(op
->mtime
);
3182 m
->set_retry_attempt(op
->attempts
++);
3184 if (!op
->trace
.valid() && cct
->_conf
->osdc_blkin_trace_all
) {
3185 op
->trace
.init("op", &trace_endpoint
);
3189 m
->set_priority(op
->priority
);
3191 m
->set_priority(cct
->_conf
->osd_client_op_priority
);
3193 if (op
->reqid
!= osd_reqid_t()) {
3194 m
->set_reqid(op
->reqid
);
3197 logger
->inc(l_osdc_op_send
);
3199 for (unsigned i
= 0; i
< m
->ops
.size(); i
++) {
3200 sum
+= m
->ops
[i
].indata
.length();
3202 logger
->inc(l_osdc_op_send_bytes
, sum
);
3207 void Objecter::_send_op(Op
*op
, MOSDOp
*m
)
3210 // op->session->lock is locked
3213 auto p
= op
->session
->backoffs
.find(op
->target
.actual_pgid
);
3214 if (p
!= op
->session
->backoffs
.end()) {
3215 hobject_t hoid
= op
->target
.get_hobj();
3216 auto q
= p
->second
.lower_bound(hoid
);
3217 if (q
!= p
->second
.begin()) {
3219 if (hoid
>= q
->second
.end
) {
3223 if (q
!= p
->second
.end()) {
3224 ldout(cct
, 20) << __func__
<< " ? " << q
->first
<< " [" << q
->second
.begin
3225 << "," << q
->second
.end
<< ")" << dendl
;
3226 int r
= cmp(hoid
, q
->second
.begin
);
3227 if (r
== 0 || (r
> 0 && hoid
< q
->second
.end
)) {
3228 ldout(cct
, 10) << __func__
<< " backoff " << op
->target
.actual_pgid
3229 << " id " << q
->second
.id
<< " on " << hoid
3230 << ", queuing " << op
<< " tid " << op
->tid
<< dendl
;
3237 assert(op
->tid
> 0);
3238 m
= _prepare_osd_op(op
);
3241 if (op
->target
.actual_pgid
!= m
->get_spg()) {
3242 ldout(cct
, 10) << __func__
<< " " << op
->tid
<< " pgid change from "
3243 << m
->get_spg() << " to " << op
->target
.actual_pgid
3244 << ", updating and reencoding" << dendl
;
3245 m
->set_spg(op
->target
.actual_pgid
);
3246 m
->clear_payload(); // reencode
3249 ldout(cct
, 15) << "_send_op " << op
->tid
<< " to "
3250 << op
->target
.actual_pgid
<< " on osd." << op
->session
->osd
3253 ConnectionRef con
= op
->session
->con
;
3256 // preallocated rx buffer?
3258 ldout(cct
, 20) << " revoking rx buffer for " << op
->tid
<< " on "
3259 << op
->con
<< dendl
;
3260 op
->con
->revoke_rx_buffer(op
->tid
);
3263 op
->ontimeout
== 0 && // only post rx_buffer if no timeout; see #9582
3264 op
->outbl
->length()) {
3265 ldout(cct
, 20) << " posting rx buffer for " << op
->tid
<< " on " << con
3268 op
->con
->post_rx_buffer(op
->tid
, *op
->outbl
);
3271 op
->incarnation
= op
->session
->incarnation
;
3273 m
->set_tid(op
->tid
);
3275 if (op
->trace
.valid()) {
3276 m
->trace
.init("op msg", nullptr, &op
->trace
);
3278 op
->session
->con
->send_message(m
);
3281 int Objecter::calc_op_budget(Op
*op
)
3284 for (vector
<OSDOp
>::iterator i
= op
->ops
.begin();
3287 if (i
->op
.op
& CEPH_OSD_OP_MODE_WR
) {
3288 op_budget
+= i
->indata
.length();
3289 } else if (ceph_osd_op_mode_read(i
->op
.op
)) {
3290 if (ceph_osd_op_type_data(i
->op
.op
)) {
3291 if ((int64_t)i
->op
.extent
.length
> 0)
3292 op_budget
+= (int64_t)i
->op
.extent
.length
;
3293 } else if (ceph_osd_op_type_attr(i
->op
.op
)) {
3294 op_budget
+= i
->op
.xattr
.name_len
+ i
->op
.xattr
.value_len
;
3301 void Objecter::_throttle_op(Op
*op
,
3305 assert(sul
&& sul
.mutex() == &rwlock
);
3306 bool locked_for_write
= sul
.owns_lock();
3309 op_budget
= calc_op_budget(op
);
3310 if (!op_throttle_bytes
.get_or_fail(op_budget
)) { //couldn't take right now
3312 op_throttle_bytes
.get(op_budget
);
3313 if (locked_for_write
)
3318 if (!op_throttle_ops
.get_or_fail(1)) { //couldn't take right now
3320 op_throttle_ops
.get(1);
3321 if (locked_for_write
)
3328 void Objecter::unregister_op(Op
*op
)
3330 OSDSession::unique_lock
sl(op
->session
->lock
);
3331 op
->session
->ops
.erase(op
->tid
);
3333 put_session(op
->session
);
3339 /* This function DOES put the passed message before returning */
3340 void Objecter::handle_osd_op_reply(MOSDOpReply
*m
)
3342 ldout(cct
, 10) << "in handle_osd_op_reply" << dendl
;
3345 ceph_tid_t tid
= m
->get_tid();
3347 shunique_lock
sul(rwlock
, ceph::acquire_shared
);
3353 ConnectionRef con
= m
->get_connection();
3354 OSDSession
*s
= static_cast<OSDSession
*>(con
->get_priv());
3355 if (!s
|| s
->con
!= con
) {
3356 ldout(cct
, 7) << __func__
<< " no session on con " << con
<< dendl
;
3364 OSDSession::unique_lock
sl(s
->lock
);
3366 map
<ceph_tid_t
, Op
*>::iterator iter
= s
->ops
.find(tid
);
3367 if (iter
== s
->ops
.end()) {
3368 ldout(cct
, 7) << "handle_osd_op_reply " << tid
3369 << (m
->is_ondisk() ? " ondisk" : (m
->is_onnvram() ?
3370 " onnvram" : " ack"))
3371 << " ... stray" << dendl
;
3378 ldout(cct
, 7) << "handle_osd_op_reply " << tid
3379 << (m
->is_ondisk() ? " ondisk" :
3380 (m
->is_onnvram() ? " onnvram" : " ack"))
3381 << " uv " << m
->get_user_version()
3382 << " in " << m
->get_pg()
3383 << " attempt " << m
->get_retry_attempt()
3385 Op
*op
= iter
->second
;
3386 op
->trace
.event("osd op reply");
3388 if (retry_writes_after_first_reply
&& op
->attempts
== 1 &&
3389 (op
->target
.flags
& CEPH_OSD_FLAG_WRITE
)) {
3390 ldout(cct
, 7) << "retrying write after first reply: " << tid
<< dendl
;
3394 _session_op_remove(s
, op
);
3398 _op_submit(op
, sul
, NULL
);
3403 if (m
->get_retry_attempt() >= 0) {
3404 if (m
->get_retry_attempt() != (op
->attempts
- 1)) {
3405 ldout(cct
, 7) << " ignoring reply from attempt "
3406 << m
->get_retry_attempt()
3407 << " from " << m
->get_source_inst()
3408 << "; last attempt " << (op
->attempts
- 1) << " sent to "
3409 << op
->session
->con
->get_peer_addr() << dendl
;
3416 // we don't know the request attempt because the server is old, so
3417 // just accept this one. we may do ACK callbacks we shouldn't
3418 // have, but that is better than doing callbacks out of order.
3421 Context
*onfinish
= 0;
3423 int rc
= m
->get_result();
3425 if (m
->is_redirect_reply()) {
3426 ldout(cct
, 5) << " got redirect reply; redirecting" << dendl
;
3429 _session_op_remove(s
, op
);
3433 // FIXME: two redirects could race and reorder
3436 m
->get_redirect().combine_with_locator(op
->target
.target_oloc
,
3437 op
->target
.target_oid
.name
);
3438 op
->target
.flags
|= (CEPH_OSD_FLAG_REDIRECTED
| CEPH_OSD_FLAG_IGNORE_OVERLAY
);
3439 _op_submit(op
, sul
, NULL
);
3444 if (rc
== -EAGAIN
) {
3445 ldout(cct
, 7) << " got -EAGAIN, resubmitting" << dendl
;
3448 _session_op_remove(s
, op
);
3453 op
->target
.flags
&= ~(CEPH_OSD_FLAG_BALANCE_READS
|
3454 CEPH_OSD_FLAG_LOCALIZE_READS
);
3455 op
->target
.pgid
= pg_t();
3456 _op_submit(op
, sul
, NULL
);
3464 *op
->objver
= m
->get_user_version();
3465 if (op
->reply_epoch
)
3466 *op
->reply_epoch
= m
->get_map_epoch();
3467 if (op
->data_offset
)
3468 *op
->data_offset
= m
->get_header().data_off
;
3473 op
->con
->revoke_rx_buffer(op
->tid
);
3474 m
->claim_data(*op
->outbl
);
3478 // per-op result demuxing
3479 vector
<OSDOp
> out_ops
;
3480 m
->claim_ops(out_ops
);
3482 if (out_ops
.size() != op
->ops
.size())
3483 ldout(cct
, 0) << "WARNING: tid " << op
->tid
<< " reply ops " << out_ops
3484 << " != request ops " << op
->ops
3485 << " from " << m
->get_source_inst() << dendl
;
3487 vector
<bufferlist
*>::iterator pb
= op
->out_bl
.begin();
3488 vector
<int*>::iterator pr
= op
->out_rval
.begin();
3489 vector
<Context
*>::iterator ph
= op
->out_handler
.begin();
3490 assert(op
->out_bl
.size() == op
->out_rval
.size());
3491 assert(op
->out_bl
.size() == op
->out_handler
.size());
3492 vector
<OSDOp
>::iterator p
= out_ops
.begin();
3493 for (unsigned i
= 0;
3494 p
!= out_ops
.end() && pb
!= op
->out_bl
.end();
3495 ++i
, ++p
, ++pb
, ++pr
, ++ph
) {
3496 ldout(cct
, 10) << " op " << i
<< " rval " << p
->rval
3497 << " len " << p
->outdata
.length() << dendl
;
3500 // set rval before running handlers so that handlers
3501 // can change it if e.g. decoding fails
3503 **pr
= ceph_to_hostos_errno(p
->rval
);
3505 ldout(cct
, 10) << " op " << i
<< " handler " << *ph
<< dendl
;
3506 (*ph
)->complete(ceph_to_hostos_errno(p
->rval
));
3511 // NOTE: we assume that since we only request ONDISK ever we will
3512 // only ever get back one (type of) ack ever.
3516 onfinish
= op
->onfinish
;
3517 op
->onfinish
= NULL
;
3519 logger
->inc(l_osdc_op_reply
);
3521 /* get it before we call _finish_op() */
3522 auto completion_lock
= s
->get_lock(op
->target
.base_oid
);
3524 ldout(cct
, 15) << "handle_osd_op_reply completed tid " << tid
<< dendl
;
3527 ldout(cct
, 5) << num_in_flight
<< " in flight" << dendl
;
3529 // serialize completions
3530 if (completion_lock
.mutex()) {
3531 completion_lock
.lock();
3537 onfinish
->complete(rc
);
3539 if (completion_lock
.mutex()) {
3540 completion_lock
.unlock();
3547 void Objecter::handle_osd_backoff(MOSDBackoff
*m
)
3549 ldout(cct
, 10) << __func__
<< " " << *m
<< dendl
;
3550 shunique_lock
sul(rwlock
, ceph::acquire_shared
);
3556 ConnectionRef con
= m
->get_connection();
3557 OSDSession
*s
= static_cast<OSDSession
*>(con
->get_priv());
3558 if (!s
|| s
->con
!= con
) {
3559 ldout(cct
, 7) << __func__
<< " no session on con " << con
<< dendl
;
3567 s
->put(); // from get_priv() above
3569 OSDSession::unique_lock
sl(s
->lock
);
3572 case CEPH_OSD_BACKOFF_OP_BLOCK
:
3575 OSDBackoff
& b
= s
->backoffs
[m
->pgid
][m
->begin
];
3576 s
->backoffs_by_id
.insert(make_pair(m
->id
, &b
));
3582 // ack with original backoff's epoch so that the osd can discard this if
3583 // there was a pg split.
3584 Message
*r
= new MOSDBackoff(m
->pgid
,
3586 CEPH_OSD_BACKOFF_OP_ACK_BLOCK
,
3587 m
->id
, m
->begin
, m
->end
);
3588 // this priority must match the MOSDOps from _prepare_osd_op
3589 r
->set_priority(cct
->_conf
->osd_client_op_priority
);
3590 con
->send_message(r
);
3594 case CEPH_OSD_BACKOFF_OP_UNBLOCK
:
3596 auto p
= s
->backoffs_by_id
.find(m
->id
);
3597 if (p
!= s
->backoffs_by_id
.end()) {
3598 OSDBackoff
*b
= p
->second
;
3599 if (b
->begin
!= m
->begin
&&
3601 lderr(cct
) << __func__
<< " got " << m
->pgid
<< " id " << m
->id
3603 << m
->begin
<< "," << m
->end
<< ") but backoff is ["
3604 << b
->begin
<< "," << b
->end
<< ")" << dendl
;
3605 // hrmpf, unblock it anyway.
3607 ldout(cct
, 10) << __func__
<< " unblock backoff " << b
->pgid
3609 << " [" << b
->begin
<< "," << b
->end
3611 auto spgp
= s
->backoffs
.find(b
->pgid
);
3612 assert(spgp
!= s
->backoffs
.end());
3613 spgp
->second
.erase(b
->begin
);
3614 if (spgp
->second
.empty()) {
3615 s
->backoffs
.erase(spgp
);
3617 s
->backoffs_by_id
.erase(p
);
3619 // check for any ops to resend
3620 for (auto& q
: s
->ops
) {
3621 if (q
.second
->target
.actual_pgid
== m
->pgid
) {
3622 int r
= q
.second
->target
.contained_by(m
->begin
, m
->end
);
3623 ldout(cct
, 20) << __func__
<< " contained_by " << r
<< " on "
3624 << q
.second
->target
.get_hobj() << dendl
;
3631 lderr(cct
) << __func__
<< " " << m
->pgid
<< " id " << m
->id
3633 << m
->begin
<< "," << m
->end
<< ") but backoff dne" << dendl
;
3639 ldout(cct
, 10) << __func__
<< " unrecognized op " << (int)m
->op
<< dendl
;
3649 uint32_t Objecter::list_nobjects_seek(NListContext
*list_context
,
3652 shared_lock
rl(rwlock
);
3653 list_context
->pos
= hobject_t(object_t(), string(), CEPH_NOSNAP
,
3654 pos
, list_context
->pool_id
, string());
3655 ldout(cct
, 10) << __func__
<< list_context
3656 << " pos " << pos
<< " -> " << list_context
->pos
<< dendl
;
3657 pg_t actual
= osdmap
->raw_pg_to_pg(pg_t(pos
, list_context
->pool_id
));
3658 list_context
->current_pg
= actual
.ps();
3659 list_context
->at_end_of_pool
= false;
3663 uint32_t Objecter::list_nobjects_seek(NListContext
*list_context
,
3664 const hobject_t
& cursor
)
3666 shared_lock
rl(rwlock
);
3667 ldout(cct
, 10) << "list_nobjects_seek " << list_context
<< dendl
;
3668 list_context
->pos
= cursor
;
3669 list_context
->at_end_of_pool
= false;
3670 pg_t actual
= osdmap
->raw_pg_to_pg(pg_t(cursor
.get_hash(), list_context
->pool_id
));
3671 list_context
->current_pg
= actual
.ps();
3672 list_context
->sort_bitwise
= true;
3673 return list_context
->current_pg
;
3676 void Objecter::list_nobjects_get_cursor(NListContext
*list_context
,
3679 shared_lock
rl(rwlock
);
3680 if (list_context
->list
.empty()) {
3681 *cursor
= list_context
->pos
;
3683 const librados::ListObjectImpl
& entry
= list_context
->list
.front();
3684 const string
*key
= (entry
.locator
.empty() ? &entry
.oid
: &entry
.locator
);
3685 uint32_t h
= osdmap
->get_pg_pool(list_context
->pool_id
)->hash_key(*key
, entry
.nspace
);
3686 *cursor
= hobject_t(entry
.oid
, entry
.locator
, list_context
->pool_snap_seq
, h
, list_context
->pool_id
, entry
.nspace
);
3690 void Objecter::list_nobjects(NListContext
*list_context
, Context
*onfinish
)
3692 ldout(cct
, 10) << __func__
<< " pool_id " << list_context
->pool_id
3693 << " pool_snap_seq " << list_context
->pool_snap_seq
3694 << " max_entries " << list_context
->max_entries
3695 << " list_context " << list_context
3696 << " onfinish " << onfinish
3697 << " current_pg " << list_context
->current_pg
3698 << " pos " << list_context
->pos
<< dendl
;
3700 shared_lock
rl(rwlock
);
3701 const pg_pool_t
*pool
= osdmap
->get_pg_pool(list_context
->pool_id
);
3702 if (!pool
) { // pool is gone
3704 put_nlist_context_budget(list_context
);
3705 onfinish
->complete(-ENOENT
);
3708 int pg_num
= pool
->get_pg_num();
3709 bool sort_bitwise
= osdmap
->test_flag(CEPH_OSDMAP_SORTBITWISE
);
3711 if (list_context
->pos
.is_min()) {
3712 list_context
->starting_pg_num
= 0;
3713 list_context
->sort_bitwise
= sort_bitwise
;
3714 list_context
->starting_pg_num
= pg_num
;
3716 if (list_context
->sort_bitwise
!= sort_bitwise
) {
3717 list_context
->pos
= hobject_t(
3718 object_t(), string(), CEPH_NOSNAP
,
3719 list_context
->current_pg
, list_context
->pool_id
, string());
3720 list_context
->sort_bitwise
= sort_bitwise
;
3721 ldout(cct
, 10) << " hobject sort order changed, restarting this pg at "
3722 << list_context
->pos
<< dendl
;
3724 if (list_context
->starting_pg_num
!= pg_num
) {
3725 if (!sort_bitwise
) {
3726 // start reading from the beginning; the pgs have changed
3727 ldout(cct
, 10) << " pg_num changed; restarting with " << pg_num
<< dendl
;
3728 list_context
->pos
= collection_list_handle_t();
3730 list_context
->starting_pg_num
= pg_num
;
3733 if (list_context
->pos
.is_max()) {
3734 ldout(cct
, 20) << __func__
<< " end of pool, list "
3735 << list_context
->list
<< dendl
;
3736 if (list_context
->list
.empty()) {
3737 list_context
->at_end_of_pool
= true;
3739 // release the listing context's budget once all
3740 // OPs (in the session) are finished
3741 put_nlist_context_budget(list_context
);
3742 onfinish
->complete(0);
3747 op
.pg_nls(list_context
->max_entries
, list_context
->filter
,
3748 list_context
->pos
, osdmap
->get_epoch());
3749 list_context
->bl
.clear();
3750 C_NList
*onack
= new C_NList(list_context
, onfinish
, this);
3751 object_locator_t
oloc(list_context
->pool_id
, list_context
->nspace
);
3753 // note current_pg in case we don't have (or lose) SORTBITWISE
3754 list_context
->current_pg
= pool
->raw_hash_to_pg(list_context
->pos
.get_hash());
3757 pg_read(list_context
->current_pg
, oloc
, op
,
3758 &list_context
->bl
, 0, onack
, &onack
->epoch
,
3759 &list_context
->ctx_budget
);
3762 void Objecter::_nlist_reply(NListContext
*list_context
, int r
,
3763 Context
*final_finish
, epoch_t reply_epoch
)
3765 ldout(cct
, 10) << __func__
<< " " << list_context
<< dendl
;
3767 bufferlist::iterator iter
= list_context
->bl
.begin();
3768 pg_nls_response_t response
;
3769 bufferlist extra_info
;
3770 ::decode(response
, iter
);
3772 ::decode(extra_info
, iter
);
3775 // if the osd returns 1 (newer code), or handle MAX, it means we
3776 // hit the end of the pg.
3777 if ((response
.handle
.is_max() || r
== 1) &&
3778 !list_context
->sort_bitwise
) {
3779 // legacy OSD and !sortbitwise, figure out the next PG on our own
3780 ++list_context
->current_pg
;
3781 if (list_context
->current_pg
== list_context
->starting_pg_num
) {
3783 list_context
->pos
= hobject_t::get_max();
3786 list_context
->pos
= hobject_t(object_t(), string(), CEPH_NOSNAP
,
3787 list_context
->current_pg
,
3788 list_context
->pool_id
, string());
3791 list_context
->pos
= response
.handle
;
3794 int response_size
= response
.entries
.size();
3795 ldout(cct
, 20) << " response.entries.size " << response_size
3796 << ", response.entries " << response
.entries
3797 << ", handle " << response
.handle
3798 << ", tentative new pos " << list_context
->pos
<< dendl
;
3799 list_context
->extra_info
.append(extra_info
);
3800 if (response_size
) {
3801 list_context
->list
.splice(list_context
->list
.end(), response
.entries
);
3804 if (list_context
->list
.size() >= list_context
->max_entries
) {
3805 ldout(cct
, 20) << " hit max, returning results so far, "
3806 << list_context
->list
<< dendl
;
3807 // release the listing context's budget once all
3808 // OPs (in the session) are finished
3809 put_nlist_context_budget(list_context
);
3810 final_finish
->complete(0);
3815 list_nobjects(list_context
, final_finish
);
3818 void Objecter::put_nlist_context_budget(NListContext
*list_context
)
3820 if (list_context
->ctx_budget
>= 0) {
3821 ldout(cct
, 10) << " release listing context's budget " <<
3822 list_context
->ctx_budget
<< dendl
;
3823 put_op_budget_bytes(list_context
->ctx_budget
);
3824 list_context
->ctx_budget
= -1;
3830 int Objecter::create_pool_snap(int64_t pool
, string
& snap_name
,
3833 unique_lock
wl(rwlock
);
3834 ldout(cct
, 10) << "create_pool_snap; pool: " << pool
<< "; snap: "
3835 << snap_name
<< dendl
;
3837 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
3840 if (p
->snap_exists(snap_name
.c_str()))
3843 PoolOp
*op
= new PoolOp
;
3846 op
->tid
= ++last_tid
;
3848 op
->name
= snap_name
;
3849 op
->onfinish
= onfinish
;
3850 op
->pool_op
= POOL_OP_CREATE_SNAP
;
3851 pool_ops
[op
->tid
] = op
;
3858 struct C_SelfmanagedSnap
: public Context
{
3862 C_SelfmanagedSnap(snapid_t
*ps
, Context
*f
) : psnapid(ps
), fin(f
) {}
3863 void finish(int r
) override
{
3865 bufferlist::iterator p
= bl
.begin();
3866 ::decode(*psnapid
, p
);
3872 int Objecter::allocate_selfmanaged_snap(int64_t pool
, snapid_t
*psnapid
,
3875 unique_lock
wl(rwlock
);
3876 ldout(cct
, 10) << "allocate_selfmanaged_snap; pool: " << pool
<< dendl
;
3877 PoolOp
*op
= new PoolOp
;
3878 if (!op
) return -ENOMEM
;
3879 op
->tid
= ++last_tid
;
3881 C_SelfmanagedSnap
*fin
= new C_SelfmanagedSnap(psnapid
, onfinish
);
3884 op
->pool_op
= POOL_OP_CREATE_UNMANAGED_SNAP
;
3885 pool_ops
[op
->tid
] = op
;
3891 int Objecter::delete_pool_snap(int64_t pool
, string
& snap_name
,
3894 unique_lock
wl(rwlock
);
3895 ldout(cct
, 10) << "delete_pool_snap; pool: " << pool
<< "; snap: "
3896 << snap_name
<< dendl
;
3898 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
3901 if (!p
->snap_exists(snap_name
.c_str()))
3904 PoolOp
*op
= new PoolOp
;
3907 op
->tid
= ++last_tid
;
3909 op
->name
= snap_name
;
3910 op
->onfinish
= onfinish
;
3911 op
->pool_op
= POOL_OP_DELETE_SNAP
;
3912 pool_ops
[op
->tid
] = op
;
3919 int Objecter::delete_selfmanaged_snap(int64_t pool
, snapid_t snap
,
3922 unique_lock
wl(rwlock
);
3923 ldout(cct
, 10) << "delete_selfmanaged_snap; pool: " << pool
<< "; snap: "
3925 PoolOp
*op
= new PoolOp
;
3926 if (!op
) return -ENOMEM
;
3927 op
->tid
= ++last_tid
;
3929 op
->onfinish
= onfinish
;
3930 op
->pool_op
= POOL_OP_DELETE_UNMANAGED_SNAP
;
3932 pool_ops
[op
->tid
] = op
;
3939 int Objecter::create_pool(string
& name
, Context
*onfinish
, uint64_t auid
,
3942 unique_lock
wl(rwlock
);
3943 ldout(cct
, 10) << "create_pool name=" << name
<< dendl
;
3945 if (osdmap
->lookup_pg_pool_name(name
) >= 0)
3948 PoolOp
*op
= new PoolOp
;
3951 op
->tid
= ++last_tid
;
3954 op
->onfinish
= onfinish
;
3955 op
->pool_op
= POOL_OP_CREATE
;
3956 pool_ops
[op
->tid
] = op
;
3958 op
->crush_rule
= crush_rule
;
3965 int Objecter::delete_pool(int64_t pool
, Context
*onfinish
)
3967 unique_lock
wl(rwlock
);
3968 ldout(cct
, 10) << "delete_pool " << pool
<< dendl
;
3970 if (!osdmap
->have_pg_pool(pool
))
3973 _do_delete_pool(pool
, onfinish
);
3977 int Objecter::delete_pool(const string
&pool_name
, Context
*onfinish
)
3979 unique_lock
wl(rwlock
);
3980 ldout(cct
, 10) << "delete_pool " << pool_name
<< dendl
;
3982 int64_t pool
= osdmap
->lookup_pg_pool_name(pool_name
);
3986 _do_delete_pool(pool
, onfinish
);
3990 void Objecter::_do_delete_pool(int64_t pool
, Context
*onfinish
)
3992 PoolOp
*op
= new PoolOp
;
3993 op
->tid
= ++last_tid
;
3995 op
->name
= "delete";
3996 op
->onfinish
= onfinish
;
3997 op
->pool_op
= POOL_OP_DELETE
;
3998 pool_ops
[op
->tid
] = op
;
4003 * change the auid owner of a pool by contacting the monitor.
4004 * This requires the current connection to have write permissions
4005 * on both the pool's current auid and the new (parameter) auid.
4006 * Uses the standard Context callback when done.
4008 int Objecter::change_pool_auid(int64_t pool
, Context
*onfinish
, uint64_t auid
)
4010 unique_lock
wl(rwlock
);
4011 ldout(cct
, 10) << "change_pool_auid " << pool
<< " to " << auid
<< dendl
;
4012 PoolOp
*op
= new PoolOp
;
4013 if (!op
) return -ENOMEM
;
4014 op
->tid
= ++last_tid
;
4016 op
->name
= "change_pool_auid";
4017 op
->onfinish
= onfinish
;
4018 op
->pool_op
= POOL_OP_AUID_CHANGE
;
4020 pool_ops
[op
->tid
] = op
;
4022 logger
->set(l_osdc_poolop_active
, pool_ops
.size());
4028 void Objecter::pool_op_submit(PoolOp
*op
)
4031 if (mon_timeout
> timespan(0)) {
4032 op
->ontimeout
= timer
.add_event(mon_timeout
,
4034 pool_op_cancel(op
->tid
, -ETIMEDOUT
); });
4036 _pool_op_submit(op
);
4039 void Objecter::_pool_op_submit(PoolOp
*op
)
4041 // rwlock is locked unique
4043 ldout(cct
, 10) << "pool_op_submit " << op
->tid
<< dendl
;
4044 MPoolOp
*m
= new MPoolOp(monc
->get_fsid(), op
->tid
, op
->pool
,
4045 op
->name
, op
->pool_op
,
4046 op
->auid
, last_seen_osdmap_version
);
4047 if (op
->snapid
) m
->snapid
= op
->snapid
;
4048 if (op
->crush_rule
) m
->crush_rule
= op
->crush_rule
;
4049 monc
->send_mon_message(m
);
4050 op
->last_submit
= ceph::mono_clock::now();
4052 logger
->inc(l_osdc_poolop_send
);
4056 * Handle a reply to a PoolOp message. Check that we sent the message
4057 * and give the caller responsibility for the returned bufferlist.
4058 * Then either call the finisher or stash the PoolOp, depending on if we
4059 * have a new enough map.
4060 * Lastly, clean up the message and PoolOp.
4062 void Objecter::handle_pool_op_reply(MPoolOpReply
*m
)
4065 shunique_lock
sul(rwlock
, acquire_shared
);
4072 ldout(cct
, 10) << "handle_pool_op_reply " << *m
<< dendl
;
4073 ceph_tid_t tid
= m
->get_tid();
4074 map
<ceph_tid_t
, PoolOp
*>::iterator iter
= pool_ops
.find(tid
);
4075 if (iter
!= pool_ops
.end()) {
4076 PoolOp
*op
= iter
->second
;
4077 ldout(cct
, 10) << "have request " << tid
<< " at " << op
<< " Op: "
4078 << ceph_pool_op_name(op
->pool_op
) << dendl
;
4080 op
->blp
->claim(m
->response_data
);
4081 if (m
->version
> last_seen_osdmap_version
)
4082 last_seen_osdmap_version
= m
->version
;
4083 if (osdmap
->get_epoch() < m
->epoch
) {
4086 // recheck op existence since we have let go of rwlock
4087 // (for promotion) above.
4088 iter
= pool_ops
.find(tid
);
4089 if (iter
== pool_ops
.end())
4090 goto done
; // op is gone.
4091 if (osdmap
->get_epoch() < m
->epoch
) {
4092 ldout(cct
, 20) << "waiting for client to reach epoch " << m
->epoch
4093 << " before calling back" << dendl
;
4094 _wait_for_new_map(op
->onfinish
, m
->epoch
, m
->replyCode
);
4096 // map epoch changed, probably because a MOSDMap message
4097 // sneaked in. Do caller-specified callback now or else
4098 // we lose it forever.
4099 assert(op
->onfinish
);
4100 op
->onfinish
->complete(m
->replyCode
);
4103 assert(op
->onfinish
);
4104 op
->onfinish
->complete(m
->replyCode
);
4106 op
->onfinish
= NULL
;
4107 if (!sul
.owns_lock()) {
4111 iter
= pool_ops
.find(tid
);
4112 if (iter
!= pool_ops
.end()) {
4113 _finish_pool_op(op
, 0);
4116 ldout(cct
, 10) << "unknown request " << tid
<< dendl
;
4120 // Not strictly necessary, since we'll release it on return.
4123 ldout(cct
, 10) << "done" << dendl
;
4127 int Objecter::pool_op_cancel(ceph_tid_t tid
, int r
)
4129 assert(initialized
);
4131 unique_lock
wl(rwlock
);
4133 map
<ceph_tid_t
, PoolOp
*>::iterator it
= pool_ops
.find(tid
);
4134 if (it
== pool_ops
.end()) {
4135 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4139 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4141 PoolOp
*op
= it
->second
;
4143 op
->onfinish
->complete(r
);
4145 _finish_pool_op(op
, r
);
4149 void Objecter::_finish_pool_op(PoolOp
*op
, int r
)
4151 // rwlock is locked unique
4152 pool_ops
.erase(op
->tid
);
4153 logger
->set(l_osdc_poolop_active
, pool_ops
.size());
4155 if (op
->ontimeout
&& r
!= -ETIMEDOUT
) {
4156 timer
.cancel_event(op
->ontimeout
);
4164 void Objecter::get_pool_stats(list
<string
>& pools
,
4165 map
<string
,pool_stat_t
> *result
,
4168 ldout(cct
, 10) << "get_pool_stats " << pools
<< dendl
;
4170 PoolStatOp
*op
= new PoolStatOp
;
4171 op
->tid
= ++last_tid
;
4173 op
->pool_stats
= result
;
4174 op
->onfinish
= onfinish
;
4175 if (mon_timeout
> timespan(0)) {
4176 op
->ontimeout
= timer
.add_event(mon_timeout
,
4178 pool_stat_op_cancel(op
->tid
,
4184 unique_lock
wl(rwlock
);
4186 poolstat_ops
[op
->tid
] = op
;
4188 logger
->set(l_osdc_poolstat_active
, poolstat_ops
.size());
4190 _poolstat_submit(op
);
4193 void Objecter::_poolstat_submit(PoolStatOp
*op
)
4195 ldout(cct
, 10) << "_poolstat_submit " << op
->tid
<< dendl
;
4196 monc
->send_mon_message(new MGetPoolStats(monc
->get_fsid(), op
->tid
,
4198 last_seen_pgmap_version
));
4199 op
->last_submit
= ceph::mono_clock::now();
4201 logger
->inc(l_osdc_poolstat_send
);
4204 void Objecter::handle_get_pool_stats_reply(MGetPoolStatsReply
*m
)
4206 ldout(cct
, 10) << "handle_get_pool_stats_reply " << *m
<< dendl
;
4207 ceph_tid_t tid
= m
->get_tid();
4209 unique_lock
wl(rwlock
);
4215 map
<ceph_tid_t
, PoolStatOp
*>::iterator iter
= poolstat_ops
.find(tid
);
4216 if (iter
!= poolstat_ops
.end()) {
4217 PoolStatOp
*op
= poolstat_ops
[tid
];
4218 ldout(cct
, 10) << "have request " << tid
<< " at " << op
<< dendl
;
4219 *op
->pool_stats
= m
->pool_stats
;
4220 if (m
->version
> last_seen_pgmap_version
) {
4221 last_seen_pgmap_version
= m
->version
;
4223 op
->onfinish
->complete(0);
4224 _finish_pool_stat_op(op
, 0);
4226 ldout(cct
, 10) << "unknown request " << tid
<< dendl
;
4228 ldout(cct
, 10) << "done" << dendl
;
4232 int Objecter::pool_stat_op_cancel(ceph_tid_t tid
, int r
)
4234 assert(initialized
);
4236 unique_lock
wl(rwlock
);
4238 map
<ceph_tid_t
, PoolStatOp
*>::iterator it
= poolstat_ops
.find(tid
);
4239 if (it
== poolstat_ops
.end()) {
4240 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4244 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4246 PoolStatOp
*op
= it
->second
;
4248 op
->onfinish
->complete(r
);
4249 _finish_pool_stat_op(op
, r
);
4253 void Objecter::_finish_pool_stat_op(PoolStatOp
*op
, int r
)
4255 // rwlock is locked unique
4257 poolstat_ops
.erase(op
->tid
);
4258 logger
->set(l_osdc_poolstat_active
, poolstat_ops
.size());
4260 if (op
->ontimeout
&& r
!= -ETIMEDOUT
)
4261 timer
.cancel_event(op
->ontimeout
);
4266 void Objecter::get_fs_stats(ceph_statfs
& result
,
4267 boost::optional
<int64_t> data_pool
,
4270 ldout(cct
, 10) << "get_fs_stats" << dendl
;
4271 unique_lock
l(rwlock
);
4273 StatfsOp
*op
= new StatfsOp
;
4274 op
->tid
= ++last_tid
;
4275 op
->stats
= &result
;
4276 op
->data_pool
= data_pool
;
4277 op
->onfinish
= onfinish
;
4278 if (mon_timeout
> timespan(0)) {
4279 op
->ontimeout
= timer
.add_event(mon_timeout
,
4281 statfs_op_cancel(op
->tid
,
4286 statfs_ops
[op
->tid
] = op
;
4288 logger
->set(l_osdc_statfs_active
, statfs_ops
.size());
4290 _fs_stats_submit(op
);
4293 void Objecter::_fs_stats_submit(StatfsOp
*op
)
4295 // rwlock is locked unique
4297 ldout(cct
, 10) << "fs_stats_submit" << op
->tid
<< dendl
;
4298 monc
->send_mon_message(new MStatfs(monc
->get_fsid(), op
->tid
,
4300 last_seen_pgmap_version
));
4301 op
->last_submit
= ceph::mono_clock::now();
4303 logger
->inc(l_osdc_statfs_send
);
4306 void Objecter::handle_fs_stats_reply(MStatfsReply
*m
)
4308 unique_lock
wl(rwlock
);
4314 ldout(cct
, 10) << "handle_fs_stats_reply " << *m
<< dendl
;
4315 ceph_tid_t tid
= m
->get_tid();
4317 if (statfs_ops
.count(tid
)) {
4318 StatfsOp
*op
= statfs_ops
[tid
];
4319 ldout(cct
, 10) << "have request " << tid
<< " at " << op
<< dendl
;
4320 *(op
->stats
) = m
->h
.st
;
4321 if (m
->h
.version
> last_seen_pgmap_version
)
4322 last_seen_pgmap_version
= m
->h
.version
;
4323 op
->onfinish
->complete(0);
4324 _finish_statfs_op(op
, 0);
4326 ldout(cct
, 10) << "unknown request " << tid
<< dendl
;
4329 ldout(cct
, 10) << "done" << dendl
;
4332 int Objecter::statfs_op_cancel(ceph_tid_t tid
, int r
)
4334 assert(initialized
);
4336 unique_lock
wl(rwlock
);
4338 map
<ceph_tid_t
, StatfsOp
*>::iterator it
= statfs_ops
.find(tid
);
4339 if (it
== statfs_ops
.end()) {
4340 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4344 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4346 StatfsOp
*op
= it
->second
;
4348 op
->onfinish
->complete(r
);
4349 _finish_statfs_op(op
, r
);
4353 void Objecter::_finish_statfs_op(StatfsOp
*op
, int r
)
4355 // rwlock is locked unique
4357 statfs_ops
.erase(op
->tid
);
4358 logger
->set(l_osdc_statfs_active
, statfs_ops
.size());
4360 if (op
->ontimeout
&& r
!= -ETIMEDOUT
)
4361 timer
.cancel_event(op
->ontimeout
);
4368 void Objecter::_sg_read_finish(vector
<ObjectExtent
>& extents
,
4369 vector
<bufferlist
>& resultbl
,
4370 bufferlist
*bl
, Context
*onfinish
)
4373 ldout(cct
, 15) << "_sg_read_finish" << dendl
;
4375 if (extents
.size() > 1) {
4376 Striper::StripedReadResult r
;
4377 vector
<bufferlist
>::iterator bit
= resultbl
.begin();
4378 for (vector
<ObjectExtent
>::iterator eit
= extents
.begin();
4379 eit
!= extents
.end();
4381 r
.add_partial_result(cct
, *bit
, eit
->buffer_extents
);
4384 r
.assemble_result(cct
, *bl
, false);
4386 ldout(cct
, 15) << " only one frag" << dendl
;
4387 bl
->claim(resultbl
[0]);
4391 uint64_t bytes_read
= bl
->length();
4392 ldout(cct
, 7) << "_sg_read_finish " << bytes_read
<< " bytes" << dendl
;
4395 onfinish
->complete(bytes_read
);// > 0 ? bytes_read:m->get_result());
4400 void Objecter::ms_handle_connect(Connection
*con
)
4402 ldout(cct
, 10) << "ms_handle_connect " << con
<< dendl
;
4406 if (con
->get_peer_type() == CEPH_ENTITY_TYPE_MON
)
4410 bool Objecter::ms_handle_reset(Connection
*con
)
4414 if (con
->get_peer_type() == CEPH_ENTITY_TYPE_OSD
) {
4415 OSDSession
*session
= static_cast<OSDSession
*>(con
->get_priv());
4417 ldout(cct
, 1) << "ms_handle_reset " << con
<< " session " << session
4418 << " osd." << session
->osd
<< dendl
;
4419 unique_lock
wl(rwlock
);
4424 map
<uint64_t, LingerOp
*> lresend
;
4425 OSDSession::unique_lock
sl(session
->lock
);
4426 _reopen_session(session
);
4427 _kick_requests(session
, lresend
);
4429 _linger_ops_resend(lresend
, wl
);
4431 maybe_request_map();
4439 void Objecter::ms_handle_remote_reset(Connection
*con
)
4442 * treat these the same.
4444 ms_handle_reset(con
);
4447 bool Objecter::ms_handle_refused(Connection
*con
)
4450 if (osdmap
&& (con
->get_peer_type() == CEPH_ENTITY_TYPE_OSD
)) {
4451 int osd
= osdmap
->identify_osd(con
->get_peer_addr());
4453 ldout(cct
, 1) << "ms_handle_refused on osd." << osd
<< dendl
;
4459 bool Objecter::ms_get_authorizer(int dest_type
,
4460 AuthAuthorizer
**authorizer
,
4465 if (dest_type
== CEPH_ENTITY_TYPE_MON
)
4467 *authorizer
= monc
->build_authorizer(dest_type
);
4468 return *authorizer
!= NULL
;
4471 void Objecter::op_target_t::dump(Formatter
*f
) const
4473 f
->dump_stream("pg") << pgid
;
4474 f
->dump_int("osd", osd
);
4475 f
->dump_stream("object_id") << base_oid
;
4476 f
->dump_stream("object_locator") << base_oloc
;
4477 f
->dump_stream("target_object_id") << target_oid
;
4478 f
->dump_stream("target_object_locator") << target_oloc
;
4479 f
->dump_int("paused", (int)paused
);
4480 f
->dump_int("used_replica", (int)used_replica
);
4481 f
->dump_int("precalc_pgid", (int)precalc_pgid
);
4484 void Objecter::_dump_active(OSDSession
*s
)
4486 for (map
<ceph_tid_t
,Op
*>::iterator p
= s
->ops
.begin();
4490 ldout(cct
, 20) << op
->tid
<< "\t" << op
->target
.pgid
4491 << "\tosd." << (op
->session
? op
->session
->osd
: -1)
4492 << "\t" << op
->target
.base_oid
4493 << "\t" << op
->ops
<< dendl
;
4497 void Objecter::_dump_active()
4499 ldout(cct
, 20) << "dump_active .. " << num_homeless_ops
<< " homeless"
4501 for (map
<int, OSDSession
*>::iterator siter
= osd_sessions
.begin();
4502 siter
!= osd_sessions
.end(); ++siter
) {
4503 OSDSession
*s
= siter
->second
;
4504 OSDSession::shared_lock
sl(s
->lock
);
4508 _dump_active(homeless_session
);
4511 void Objecter::dump_active()
4513 shared_lock
rl(rwlock
);
4518 void Objecter::dump_requests(Formatter
*fmt
)
4520 // Read-lock on Objecter held here
4521 fmt
->open_object_section("requests");
4523 dump_linger_ops(fmt
);
4525 dump_pool_stat_ops(fmt
);
4526 dump_statfs_ops(fmt
);
4527 dump_command_ops(fmt
);
4528 fmt
->close_section(); // requests object
4531 void Objecter::_dump_ops(const OSDSession
*s
, Formatter
*fmt
)
4533 for (map
<ceph_tid_t
,Op
*>::const_iterator p
= s
->ops
.begin();
4537 fmt
->open_object_section("op");
4538 fmt
->dump_unsigned("tid", op
->tid
);
4539 op
->target
.dump(fmt
);
4540 fmt
->dump_stream("last_sent") << op
->stamp
;
4541 fmt
->dump_int("attempts", op
->attempts
);
4542 fmt
->dump_stream("snapid") << op
->snapid
;
4543 fmt
->dump_stream("snap_context") << op
->snapc
;
4544 fmt
->dump_stream("mtime") << op
->mtime
;
4546 fmt
->open_array_section("osd_ops");
4547 for (vector
<OSDOp
>::const_iterator it
= op
->ops
.begin();
4548 it
!= op
->ops
.end();
4550 fmt
->dump_stream("osd_op") << *it
;
4552 fmt
->close_section(); // osd_ops array
4554 fmt
->close_section(); // op object
4558 void Objecter::dump_ops(Formatter
*fmt
)
4560 // Read-lock on Objecter held
4561 fmt
->open_array_section("ops");
4562 for (map
<int, OSDSession
*>::const_iterator siter
= osd_sessions
.begin();
4563 siter
!= osd_sessions
.end(); ++siter
) {
4564 OSDSession
*s
= siter
->second
;
4565 OSDSession::shared_lock
sl(s
->lock
);
4569 _dump_ops(homeless_session
, fmt
);
4570 fmt
->close_section(); // ops array
4573 void Objecter::_dump_linger_ops(const OSDSession
*s
, Formatter
*fmt
)
4575 for (map
<uint64_t, LingerOp
*>::const_iterator p
= s
->linger_ops
.begin();
4576 p
!= s
->linger_ops
.end();
4578 LingerOp
*op
= p
->second
;
4579 fmt
->open_object_section("linger_op");
4580 fmt
->dump_unsigned("linger_id", op
->linger_id
);
4581 op
->target
.dump(fmt
);
4582 fmt
->dump_stream("snapid") << op
->snap
;
4583 fmt
->dump_stream("registered") << op
->registered
;
4584 fmt
->close_section(); // linger_op object
4588 void Objecter::dump_linger_ops(Formatter
*fmt
)
4590 // We have a read-lock on the objecter
4591 fmt
->open_array_section("linger_ops");
4592 for (map
<int, OSDSession
*>::const_iterator siter
= osd_sessions
.begin();
4593 siter
!= osd_sessions
.end(); ++siter
) {
4594 OSDSession
*s
= siter
->second
;
4595 OSDSession::shared_lock
sl(s
->lock
);
4596 _dump_linger_ops(s
, fmt
);
4599 _dump_linger_ops(homeless_session
, fmt
);
4600 fmt
->close_section(); // linger_ops array
4603 void Objecter::_dump_command_ops(const OSDSession
*s
, Formatter
*fmt
)
4605 for (map
<uint64_t, CommandOp
*>::const_iterator p
= s
->command_ops
.begin();
4606 p
!= s
->command_ops
.end();
4608 CommandOp
*op
= p
->second
;
4609 fmt
->open_object_section("command_op");
4610 fmt
->dump_unsigned("command_id", op
->tid
);
4611 fmt
->dump_int("osd", op
->session
? op
->session
->osd
: -1);
4612 fmt
->open_array_section("command");
4613 for (vector
<string
>::const_iterator q
= op
->cmd
.begin();
4614 q
!= op
->cmd
.end(); ++q
)
4615 fmt
->dump_string("word", *q
);
4616 fmt
->close_section();
4617 if (op
->target_osd
>= 0)
4618 fmt
->dump_int("target_osd", op
->target_osd
);
4620 fmt
->dump_stream("target_pg") << op
->target_pg
;
4621 fmt
->close_section(); // command_op object
4625 void Objecter::dump_command_ops(Formatter
*fmt
)
4627 // We have a read-lock on the Objecter here
4628 fmt
->open_array_section("command_ops");
4629 for (map
<int, OSDSession
*>::const_iterator siter
= osd_sessions
.begin();
4630 siter
!= osd_sessions
.end(); ++siter
) {
4631 OSDSession
*s
= siter
->second
;
4632 OSDSession::shared_lock
sl(s
->lock
);
4633 _dump_command_ops(s
, fmt
);
4636 _dump_command_ops(homeless_session
, fmt
);
4637 fmt
->close_section(); // command_ops array
4640 void Objecter::dump_pool_ops(Formatter
*fmt
) const
4642 fmt
->open_array_section("pool_ops");
4643 for (map
<ceph_tid_t
, PoolOp
*>::const_iterator p
= pool_ops
.begin();
4644 p
!= pool_ops
.end();
4646 PoolOp
*op
= p
->second
;
4647 fmt
->open_object_section("pool_op");
4648 fmt
->dump_unsigned("tid", op
->tid
);
4649 fmt
->dump_int("pool", op
->pool
);
4650 fmt
->dump_string("name", op
->name
);
4651 fmt
->dump_int("operation_type", op
->pool_op
);
4652 fmt
->dump_unsigned("auid", op
->auid
);
4653 fmt
->dump_unsigned("crush_rule", op
->crush_rule
);
4654 fmt
->dump_stream("snapid") << op
->snapid
;
4655 fmt
->dump_stream("last_sent") << op
->last_submit
;
4656 fmt
->close_section(); // pool_op object
4658 fmt
->close_section(); // pool_ops array
4661 void Objecter::dump_pool_stat_ops(Formatter
*fmt
) const
4663 fmt
->open_array_section("pool_stat_ops");
4664 for (map
<ceph_tid_t
, PoolStatOp
*>::const_iterator p
= poolstat_ops
.begin();
4665 p
!= poolstat_ops
.end();
4667 PoolStatOp
*op
= p
->second
;
4668 fmt
->open_object_section("pool_stat_op");
4669 fmt
->dump_unsigned("tid", op
->tid
);
4670 fmt
->dump_stream("last_sent") << op
->last_submit
;
4672 fmt
->open_array_section("pools");
4673 for (list
<string
>::const_iterator it
= op
->pools
.begin();
4674 it
!= op
->pools
.end();
4676 fmt
->dump_string("pool", *it
);
4678 fmt
->close_section(); // pools array
4680 fmt
->close_section(); // pool_stat_op object
4682 fmt
->close_section(); // pool_stat_ops array
4685 void Objecter::dump_statfs_ops(Formatter
*fmt
) const
4687 fmt
->open_array_section("statfs_ops");
4688 for (map
<ceph_tid_t
, StatfsOp
*>::const_iterator p
= statfs_ops
.begin();
4689 p
!= statfs_ops
.end();
4691 StatfsOp
*op
= p
->second
;
4692 fmt
->open_object_section("statfs_op");
4693 fmt
->dump_unsigned("tid", op
->tid
);
4694 fmt
->dump_stream("last_sent") << op
->last_submit
;
4695 fmt
->close_section(); // statfs_op object
4697 fmt
->close_section(); // statfs_ops array
4700 Objecter::RequestStateHook::RequestStateHook(Objecter
*objecter
) :
4701 m_objecter(objecter
)
4705 bool Objecter::RequestStateHook::call(std::string command
, cmdmap_t
& cmdmap
,
4706 std::string format
, bufferlist
& out
)
4708 Formatter
*f
= Formatter::create(format
, "json-pretty", "json-pretty");
4709 shared_lock
rl(m_objecter
->rwlock
);
4710 m_objecter
->dump_requests(f
);
4716 void Objecter::blacklist_self(bool set
)
4718 ldout(cct
, 10) << "blacklist_self " << (set
? "add" : "rm") << dendl
;
4721 cmd
.push_back("{\"prefix\":\"osd blacklist\", ");
4723 cmd
.push_back("\"blacklistop\":\"add\",");
4725 cmd
.push_back("\"blacklistop\":\"rm\",");
4727 ss
<< messenger
->get_myaddr();
4728 cmd
.push_back("\"addr\":\"" + ss
.str() + "\"");
4730 MMonCommand
*m
= new MMonCommand(monc
->get_fsid());
4733 monc
->send_mon_message(m
);
4738 void Objecter::handle_command_reply(MCommandReply
*m
)
4740 unique_lock
wl(rwlock
);
4746 ConnectionRef con
= m
->get_connection();
4747 OSDSession
*s
= static_cast<OSDSession
*>(con
->get_priv());
4748 if (!s
|| s
->con
!= con
) {
4749 ldout(cct
, 7) << __func__
<< " no session on con " << con
<< dendl
;
4756 OSDSession::shared_lock
sl(s
->lock
);
4757 map
<ceph_tid_t
,CommandOp
*>::iterator p
= s
->command_ops
.find(m
->get_tid());
4758 if (p
== s
->command_ops
.end()) {
4759 ldout(cct
, 10) << "handle_command_reply tid " << m
->get_tid()
4760 << " not found" << dendl
;
4768 CommandOp
*c
= p
->second
;
4770 m
->get_connection() != c
->session
->con
) {
4771 ldout(cct
, 10) << "handle_command_reply tid " << m
->get_tid()
4772 << " got reply from wrong connection "
4773 << m
->get_connection() << " " << m
->get_source_inst()
4782 c
->poutbl
->claim(m
->get_data());
4787 OSDSession::unique_lock
sul(s
->lock
);
4788 _finish_command(c
, m
->r
, m
->rs
);
4796 void Objecter::submit_command(CommandOp
*c
, ceph_tid_t
*ptid
)
4798 shunique_lock
sul(rwlock
, ceph::acquire_unique
);
4800 ceph_tid_t tid
= ++last_tid
;
4801 ldout(cct
, 10) << "_submit_command " << tid
<< " " << c
->cmd
<< dendl
;
4805 OSDSession::unique_lock
hs_wl(homeless_session
->lock
);
4806 _session_command_op_assign(homeless_session
, c
);
4809 _calc_command_target(c
, sul
);
4810 _assign_command_session(c
, sul
);
4811 if (osd_timeout
> timespan(0)) {
4812 c
->ontimeout
= timer
.add_event(osd_timeout
,
4814 command_op_cancel(c
->session
, tid
,
4818 if (!c
->session
->is_homeless()) {
4821 _maybe_request_map();
4823 if (c
->map_check_error
)
4824 _send_command_map_check(c
);
4827 logger
->inc(l_osdc_command_active
);
4830 int Objecter::_calc_command_target(CommandOp
*c
, shunique_lock
& sul
)
4832 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
4834 c
->map_check_error
= 0;
4836 // ignore overlays, just like we do with pg ops
4837 c
->target
.flags
|= CEPH_OSD_FLAG_IGNORE_OVERLAY
;
4839 if (c
->target_osd
>= 0) {
4840 if (!osdmap
->exists(c
->target_osd
)) {
4841 c
->map_check_error
= -ENOENT
;
4842 c
->map_check_error_str
= "osd dne";
4844 return RECALC_OP_TARGET_OSD_DNE
;
4846 if (osdmap
->is_down(c
->target_osd
)) {
4847 c
->map_check_error
= -ENXIO
;
4848 c
->map_check_error_str
= "osd down";
4850 return RECALC_OP_TARGET_OSD_DOWN
;
4852 c
->target
.osd
= c
->target_osd
;
4854 int ret
= _calc_target(&(c
->target
), nullptr, true);
4855 if (ret
== RECALC_OP_TARGET_POOL_DNE
) {
4856 c
->map_check_error
= -ENOENT
;
4857 c
->map_check_error_str
= "pool dne";
4860 } else if (ret
== RECALC_OP_TARGET_OSD_DOWN
) {
4861 c
->map_check_error
= -ENXIO
;
4862 c
->map_check_error_str
= "osd down";
4869 int r
= _get_session(c
->target
.osd
, &s
, sul
);
4870 assert(r
!= -EAGAIN
); /* shouldn't happen as we're holding the write lock */
4872 if (c
->session
!= s
) {
4874 return RECALC_OP_TARGET_NEED_RESEND
;
4879 ldout(cct
, 20) << "_recalc_command_target " << c
->tid
<< " no change, "
4880 << c
->session
<< dendl
;
4882 return RECALC_OP_TARGET_NO_ACTION
;
4885 void Objecter::_assign_command_session(CommandOp
*c
,
4888 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
4891 int r
= _get_session(c
->target
.osd
, &s
, sul
);
4892 assert(r
!= -EAGAIN
); /* shouldn't happen as we're holding the write lock */
4894 if (c
->session
!= s
) {
4896 OSDSession
*cs
= c
->session
;
4897 OSDSession::unique_lock
csl(cs
->lock
);
4898 _session_command_op_remove(c
->session
, c
);
4901 OSDSession::unique_lock
sl(s
->lock
);
4902 _session_command_op_assign(s
, c
);
4908 void Objecter::_send_command(CommandOp
*c
)
4910 ldout(cct
, 10) << "_send_command " << c
->tid
<< dendl
;
4912 assert(c
->session
->con
);
4913 MCommand
*m
= new MCommand(monc
->monmap
.fsid
);
4915 m
->set_data(c
->inbl
);
4917 c
->session
->con
->send_message(m
);
4918 logger
->inc(l_osdc_command_send
);
4921 int Objecter::command_op_cancel(OSDSession
*s
, ceph_tid_t tid
, int r
)
4923 assert(initialized
);
4925 unique_lock
wl(rwlock
);
4927 map
<ceph_tid_t
, CommandOp
*>::iterator it
= s
->command_ops
.find(tid
);
4928 if (it
== s
->command_ops
.end()) {
4929 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4933 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4935 CommandOp
*op
= it
->second
;
4936 _command_cancel_map_check(op
);
4937 OSDSession::unique_lock
sl(op
->session
->lock
);
4938 _finish_command(op
, r
, "");
4943 void Objecter::_finish_command(CommandOp
*c
, int r
, string rs
)
4945 // rwlock is locked unique
4946 // session lock is locked
4948 ldout(cct
, 10) << "_finish_command " << c
->tid
<< " = " << r
<< " "
4953 c
->onfinish
->complete(r
);
4955 if (c
->ontimeout
&& r
!= -ETIMEDOUT
)
4956 timer
.cancel_event(c
->ontimeout
);
4958 OSDSession
*s
= c
->session
;
4959 _session_command_op_remove(c
->session
, c
);
4963 logger
->dec(l_osdc_command_active
);
4966 Objecter::OSDSession::~OSDSession()
4968 // Caller is responsible for re-assigning or
4969 // destroying any ops that were assigned to us
4970 assert(ops
.empty());
4971 assert(linger_ops
.empty());
4972 assert(command_ops
.empty());
4975 Objecter::~Objecter()
4979 assert(homeless_session
->get_nref() == 1);
4980 assert(num_homeless_ops
== 0);
4981 homeless_session
->put();
4983 assert(osd_sessions
.empty());
4984 assert(poolstat_ops
.empty());
4985 assert(statfs_ops
.empty());
4986 assert(pool_ops
.empty());
4987 assert(waiting_for_map
.empty());
4988 assert(linger_ops
.empty());
4989 assert(check_latest_map_lingers
.empty());
4990 assert(check_latest_map_ops
.empty());
4991 assert(check_latest_map_commands
.empty());
4993 assert(!m_request_state_hook
);
4998 * Wait until this OSD map epoch is received before
4999 * sending any more operations to OSDs. Use this
5000 * when it is known that the client can't trust
5001 * anything from before this epoch (e.g. due to
5002 * client blacklist at this epoch).
5004 void Objecter::set_epoch_barrier(epoch_t epoch
)
5006 unique_lock
wl(rwlock
);
5008 ldout(cct
, 7) << __func__
<< ": barrier " << epoch
<< " (was "
5009 << epoch_barrier
<< ") current epoch " << osdmap
->get_epoch()
5011 if (epoch
> epoch_barrier
) {
5012 epoch_barrier
= epoch
;
5013 _maybe_request_map();
5019 hobject_t
Objecter::enumerate_objects_begin()
5024 hobject_t
Objecter::enumerate_objects_end()
5026 return hobject_t::get_max();
5029 struct C_EnumerateReply
: public Context
{
5034 std::list
<librados::ListObjectImpl
> *result
;
5035 const hobject_t end
;
5036 const int64_t pool_id
;
5042 C_EnumerateReply(Objecter
*objecter_
, hobject_t
*next_
,
5043 std::list
<librados::ListObjectImpl
> *result_
,
5044 const hobject_t end_
, const int64_t pool_id_
, Context
*on_finish_
) :
5045 objecter(objecter_
), next(next_
), result(result_
),
5046 end(end_
), pool_id(pool_id_
), on_finish(on_finish_
),
5050 void finish(int r
) override
{
5051 objecter
->_enumerate_reply(
5052 bl
, r
, end
, pool_id
, budget
, epoch
, result
, next
, on_finish
);
5056 void Objecter::enumerate_objects(
5058 const std::string
&ns
,
5059 const hobject_t
&start
,
5060 const hobject_t
&end
,
5062 const bufferlist
&filter_bl
,
5063 std::list
<librados::ListObjectImpl
> *result
,
5069 if (!end
.is_max() && start
> end
) {
5070 lderr(cct
) << __func__
<< ": start " << start
<< " > end " << end
<< dendl
;
5071 on_finish
->complete(-EINVAL
);
5076 lderr(cct
) << __func__
<< ": result size may not be zero" << dendl
;
5077 on_finish
->complete(-EINVAL
);
5081 if (start
.is_max()) {
5082 on_finish
->complete(0);
5086 shared_lock
rl(rwlock
);
5087 assert(osdmap
->get_epoch());
5088 if (!osdmap
->test_flag(CEPH_OSDMAP_SORTBITWISE
)) {
5090 lderr(cct
) << __func__
<< ": SORTBITWISE cluster flag not set" << dendl
;
5091 on_finish
->complete(-EOPNOTSUPP
);
5094 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool_id
);
5096 lderr(cct
) << __func__
<< ": pool " << pool_id
<< " DNE in osd epoch "
5097 << osdmap
->get_epoch() << dendl
;
5099 on_finish
->complete(-ENOENT
);
5105 ldout(cct
, 20) << __func__
<< ": start=" << start
<< " end=" << end
<< dendl
;
5107 // Stash completion state
5108 C_EnumerateReply
*on_ack
= new C_EnumerateReply(
5109 this, next
, result
, end
, pool_id
, on_finish
);
5112 op
.pg_nls(max
, filter_bl
, start
, 0);
5114 // Issue. See you later in _enumerate_reply
5115 object_locator_t
oloc(pool_id
, ns
);
5116 pg_read(start
.get_hash(), oloc
, op
,
5117 &on_ack
->bl
, 0, on_ack
, &on_ack
->epoch
, &on_ack
->budget
);
5120 void Objecter::_enumerate_reply(
5123 const hobject_t
&end
,
5124 const int64_t pool_id
,
5126 epoch_t reply_epoch
,
5127 std::list
<librados::ListObjectImpl
> *result
,
5132 put_op_budget_bytes(budget
);
5136 ldout(cct
, 4) << __func__
<< ": remote error " << r
<< dendl
;
5137 on_finish
->complete(r
);
5141 assert(next
!= NULL
);
5143 // Decode the results
5144 bufferlist::iterator iter
= bl
.begin();
5145 pg_nls_response_t response
;
5147 // XXX extra_info doesn't seem used anywhere?
5148 bufferlist extra_info
;
5149 ::decode(response
, iter
);
5151 ::decode(extra_info
, iter
);
5154 ldout(cct
, 10) << __func__
<< ": got " << response
.entries
.size()
5155 << " handle " << response
.handle
5156 << " reply_epoch " << reply_epoch
<< dendl
;
5157 ldout(cct
, 20) << __func__
<< ": response.entries.size "
5158 << response
.entries
.size() << ", response.entries "
5159 << response
.entries
<< dendl
;
5160 if (response
.handle
<= end
) {
5161 *next
= response
.handle
;
5163 ldout(cct
, 10) << __func__
<< ": adjusted next down to end " << end
5167 // drop anything after 'end'
5168 shared_lock
rl(rwlock
);
5169 const pg_pool_t
*pool
= osdmap
->get_pg_pool(pool_id
);
5171 // pool is gone, drop any results which are now meaningless.
5173 on_finish
->complete(-ENOENT
);
5176 while (!response
.entries
.empty()) {
5177 uint32_t hash
= response
.entries
.back().locator
.empty() ?
5178 pool
->hash_key(response
.entries
.back().oid
,
5179 response
.entries
.back().nspace
) :
5180 pool
->hash_key(response
.entries
.back().locator
,
5181 response
.entries
.back().nspace
);
5182 hobject_t
last(response
.entries
.back().oid
,
5183 response
.entries
.back().locator
,
5187 response
.entries
.back().nspace
);
5190 ldout(cct
, 20) << __func__
<< " dropping item " << last
5191 << " >= end " << end
<< dendl
;
5192 response
.entries
.pop_back();
5196 if (!response
.entries
.empty()) {
5197 result
->merge(response
.entries
);
5200 // release the listing context's budget once all
5201 // OPs (in the session) are finished
5203 put_nlist_context_budget(list_context
);
5205 on_finish
->complete(r
);
5210 using namespace librados
;
5212 template <typename T
>
5213 void do_decode(std::vector
<T
>& items
, std::vector
<bufferlist
>& bls
)
5215 for (auto bl
: bls
) {
5216 auto p
= bl
.begin();
5223 struct C_ObjectOperation_scrub_ls
: public Context
{
5226 std::vector
<inconsistent_obj_t
> *objects
= nullptr;
5227 std::vector
<inconsistent_snapset_t
> *snapsets
= nullptr;
5230 C_ObjectOperation_scrub_ls(uint32_t *interval
,
5231 std::vector
<inconsistent_obj_t
> *objects
,
5233 : interval(interval
), objects(objects
), rval(rval
) {}
5234 C_ObjectOperation_scrub_ls(uint32_t *interval
,
5235 std::vector
<inconsistent_snapset_t
> *snapsets
,
5237 : interval(interval
), snapsets(snapsets
), rval(rval
) {}
5238 void finish(int r
) override
{
5239 if (r
< 0 && r
!= -EAGAIN
) {
5250 } catch (buffer::error
&) {
5257 scrub_ls_result_t result
;
5258 auto p
= bl
.begin();
5260 *interval
= result
.interval
;
5262 do_decode(*objects
, result
.vals
);
5264 do_decode(*snapsets
, result
.vals
);
5269 template <typename T
>
5270 void do_scrub_ls(::ObjectOperation
*op
,
5271 const scrub_ls_arg_t
& arg
,
5272 std::vector
<T
> *items
,
5276 OSDOp
& osd_op
= op
->add_op(CEPH_OSD_OP_SCRUBLS
);
5277 op
->flags
|= CEPH_OSD_FLAG_PGOP
;
5279 arg
.encode(osd_op
.indata
);
5280 unsigned p
= op
->ops
.size() - 1;
5281 auto *h
= new C_ObjectOperation_scrub_ls
{interval
, items
, rval
};
5282 op
->out_handler
[p
] = h
;
5283 op
->out_bl
[p
] = &h
->bl
;
5284 op
->out_rval
[p
] = rval
;
5288 void ::ObjectOperation::scrub_ls(const librados::object_id_t
& start_after
,
5289 uint64_t max_to_get
,
5290 std::vector
<librados::inconsistent_obj_t
> *objects
,
5294 scrub_ls_arg_t arg
= {*interval
, 0, start_after
, max_to_get
};
5295 do_scrub_ls(this, arg
, objects
, interval
, rval
);
5298 void ::ObjectOperation::scrub_ls(const librados::object_id_t
& start_after
,
5299 uint64_t max_to_get
,
5300 std::vector
<librados::inconsistent_snapset_t
> *snapsets
,
5304 scrub_ls_arg_t arg
= {*interval
, 1, start_after
, max_to_get
};
5305 do_scrub_ls(this, arg
, snapsets
, interval
, rval
);