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
;
598 // only tell the user the first time we do this
599 info
->registered
= true;
600 info
->pobjver
= NULL
;
602 if (!info
->is_watch
) {
603 // make note of the notify_id
604 bufferlist::iterator p
= outbl
.begin();
606 ::decode(info
->notify_id
, p
);
607 ldout(cct
, 10) << "_linger_commit notify_id=" << info
->notify_id
610 catch (buffer::error
& e
) {
615 struct C_DoWatchError
: public Context
{
617 Objecter::LingerOp
*info
;
619 C_DoWatchError(Objecter
*o
, Objecter::LingerOp
*i
, int r
)
620 : objecter(o
), info(i
), err(r
) {
622 info
->_queued_async();
624 void finish(int r
) override
{
625 Objecter::unique_lock
wl(objecter
->rwlock
);
626 bool canceled
= info
->canceled
;
630 info
->watch_context
->handle_error(info
->get_cookie(), err
);
633 info
->finished_async();
638 int Objecter::_normalize_watch_error(int r
)
640 // translate ENOENT -> ENOTCONN so that a delete->disconnection
641 // notification and a failure to reconnect becuase we raced with
642 // the delete appear the same to the user.
648 void Objecter::_linger_reconnect(LingerOp
*info
, int r
)
650 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
<< " = " << r
651 << " (last_error " << info
->last_error
<< ")" << dendl
;
653 LingerOp::unique_lock
wl(info
->watch_lock
);
654 if (!info
->last_error
) {
655 r
= _normalize_watch_error(r
);
656 info
->last_error
= r
;
657 if (info
->watch_context
) {
658 finisher
->queue(new C_DoWatchError(this, info
, r
));
665 void Objecter::_send_linger_ping(LingerOp
*info
)
667 // rwlock is locked unique
668 // info->session->lock is locked
670 if (cct
->_conf
->objecter_inject_no_watch_ping
) {
671 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
<< " SKIPPING"
675 if (osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
)) {
676 ldout(cct
, 10) << __func__
<< " PAUSERD" << dendl
;
680 ceph::mono_time now
= ceph::mono_clock::now();
681 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
<< " now " << now
684 vector
<OSDOp
> opv(1);
685 opv
[0].op
.op
= CEPH_OSD_OP_WATCH
;
686 opv
[0].op
.watch
.cookie
= info
->get_cookie();
687 opv
[0].op
.watch
.op
= CEPH_OSD_WATCH_OP_PING
;
688 opv
[0].op
.watch
.gen
= info
->register_gen
;
689 C_Linger_Ping
*onack
= new C_Linger_Ping(this, info
);
690 Op
*o
= new Op(info
->target
.base_oid
, info
->target
.base_oloc
,
691 opv
, info
->target
.flags
| CEPH_OSD_FLAG_READ
,
693 o
->target
= info
->target
;
694 o
->should_resend
= false;
696 MOSDOp
*m
= _prepare_osd_op(o
);
698 _session_op_assign(info
->session
, o
);
700 info
->ping_tid
= o
->tid
;
703 logger
->inc(l_osdc_linger_ping
);
706 void Objecter::_linger_ping(LingerOp
*info
, int r
, mono_time sent
,
707 uint32_t register_gen
)
709 LingerOp::unique_lock
l(info
->watch_lock
);
710 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
711 << " sent " << sent
<< " gen " << register_gen
<< " = " << r
712 << " (last_error " << info
->last_error
713 << " register_gen " << info
->register_gen
<< ")" << dendl
;
714 if (info
->register_gen
== register_gen
) {
716 info
->watch_valid_thru
= sent
;
717 } else if (r
< 0 && !info
->last_error
) {
718 r
= _normalize_watch_error(r
);
719 info
->last_error
= r
;
720 if (info
->watch_context
) {
721 finisher
->queue(new C_DoWatchError(this, info
, r
));
725 ldout(cct
, 20) << " ignoring old gen" << dendl
;
729 int Objecter::linger_check(LingerOp
*info
)
731 LingerOp::shared_lock
l(info
->watch_lock
);
733 mono_time stamp
= info
->watch_valid_thru
;
734 if (!info
->watch_pending_async
.empty())
735 stamp
= MIN(info
->watch_valid_thru
, info
->watch_pending_async
.front());
736 auto age
= mono_clock::now() - stamp
;
738 ldout(cct
, 10) << __func__
<< " " << info
->linger_id
739 << " err " << info
->last_error
740 << " age " << age
<< dendl
;
741 if (info
->last_error
)
742 return info
->last_error
;
743 // return a safe upper bound (we are truncating to ms)
745 1 + std::chrono::duration_cast
<std::chrono::milliseconds
>(age
).count();
748 void Objecter::linger_cancel(LingerOp
*info
)
750 unique_lock
wl(rwlock
);
751 _linger_cancel(info
);
755 void Objecter::_linger_cancel(LingerOp
*info
)
757 // rwlock is locked unique
758 ldout(cct
, 20) << __func__
<< " linger_id=" << info
->linger_id
<< dendl
;
759 if (!info
->canceled
) {
760 OSDSession
*s
= info
->session
;
761 OSDSession::unique_lock
sl(s
->lock
);
762 _session_linger_op_remove(s
, info
);
765 linger_ops
.erase(info
->linger_id
);
766 linger_ops_set
.erase(info
);
767 assert(linger_ops
.size() == linger_ops_set
.size());
769 info
->canceled
= true;
772 logger
->dec(l_osdc_linger_active
);
778 Objecter::LingerOp
*Objecter::linger_register(const object_t
& oid
,
779 const object_locator_t
& oloc
,
782 LingerOp
*info
= new LingerOp
;
783 info
->target
.base_oid
= oid
;
784 info
->target
.base_oloc
= oloc
;
785 if (info
->target
.base_oloc
.key
== oid
)
786 info
->target
.base_oloc
.key
.clear();
787 info
->target
.flags
= flags
;
788 info
->watch_valid_thru
= mono_clock::now();
790 unique_lock
l(rwlock
);
793 info
->linger_id
= ++max_linger_id
;
794 ldout(cct
, 10) << __func__
<< " info " << info
795 << " linger_id " << info
->linger_id
796 << " cookie " << info
->get_cookie()
798 linger_ops
[info
->linger_id
] = info
;
799 linger_ops_set
.insert(info
);
800 assert(linger_ops
.size() == linger_ops_set
.size());
802 info
->get(); // for the caller
806 ceph_tid_t
Objecter::linger_watch(LingerOp
*info
,
808 const SnapContext
& snapc
,
814 info
->is_watch
= true;
817 info
->target
.flags
|= CEPH_OSD_FLAG_WRITE
;
821 info
->pobjver
= objver
;
822 info
->on_reg_commit
= oncommit
;
824 shunique_lock
sul(rwlock
, ceph::acquire_unique
);
825 _linger_submit(info
, sul
);
826 logger
->inc(l_osdc_linger_active
);
828 return info
->linger_id
;
831 ceph_tid_t
Objecter::linger_notify(LingerOp
*info
,
833 snapid_t snap
, bufferlist
& inbl
,
839 info
->target
.flags
|= CEPH_OSD_FLAG_READ
;
842 info
->poutbl
= poutbl
;
843 info
->pobjver
= objver
;
844 info
->on_reg_commit
= onfinish
;
846 shunique_lock
sul(rwlock
, ceph::acquire_unique
);
847 _linger_submit(info
, sul
);
848 logger
->inc(l_osdc_linger_active
);
850 return info
->linger_id
;
853 void Objecter::_linger_submit(LingerOp
*info
, shunique_lock
& sul
)
855 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
856 assert(info
->linger_id
);
858 // Populate Op::target
859 OSDSession
*s
= NULL
;
860 _calc_target(&info
->target
, nullptr);
862 // Create LingerOp<->OSDSession relation
863 int r
= _get_session(info
->target
.osd
, &s
, sul
);
865 OSDSession::unique_lock
sl(s
->lock
);
866 _session_linger_op_assign(s
, info
);
870 _send_linger(info
, sul
);
873 struct C_DoWatchNotify
: public Context
{
875 Objecter::LingerOp
*info
;
877 C_DoWatchNotify(Objecter
*o
, Objecter::LingerOp
*i
, MWatchNotify
*m
)
878 : objecter(o
), info(i
), msg(m
) {
880 info
->_queued_async();
883 void finish(int r
) override
{
884 objecter
->_do_watch_notify(info
, msg
);
888 void Objecter::handle_watch_notify(MWatchNotify
*m
)
890 shared_lock
l(rwlock
);
895 LingerOp
*info
= reinterpret_cast<LingerOp
*>(m
->cookie
);
896 if (linger_ops_set
.count(info
) == 0) {
897 ldout(cct
, 7) << __func__
<< " cookie " << m
->cookie
<< " dne" << dendl
;
900 LingerOp::unique_lock
wl(info
->watch_lock
);
901 if (m
->opcode
== CEPH_WATCH_EVENT_DISCONNECT
) {
902 if (!info
->last_error
) {
903 info
->last_error
= -ENOTCONN
;
904 if (info
->watch_context
) {
905 finisher
->queue(new C_DoWatchError(this, info
, -ENOTCONN
));
908 } else if (!info
->is_watch
) {
909 // we have CEPH_WATCH_EVENT_NOTIFY_COMPLETE; we can do this inline
910 // since we know the only user (librados) is safe to call in
911 // fast-dispatch context
912 if (info
->notify_id
&&
913 info
->notify_id
!= m
->notify_id
) {
914 ldout(cct
, 10) << __func__
<< " reply notify " << m
->notify_id
915 << " != " << info
->notify_id
<< ", ignoring" << dendl
;
916 } else if (info
->on_notify_finish
) {
917 info
->notify_result_bl
->claim(m
->get_data());
918 info
->on_notify_finish
->complete(m
->return_code
);
920 // if we race with reconnect we might get a second notify; only
921 // notify the caller once!
922 info
->on_notify_finish
= NULL
;
925 finisher
->queue(new C_DoWatchNotify(this, info
, m
));
929 void Objecter::_do_watch_notify(LingerOp
*info
, MWatchNotify
*m
)
931 ldout(cct
, 10) << __func__
<< " " << *m
<< dendl
;
933 shared_lock
l(rwlock
);
936 if (info
->canceled
) {
941 // notify completion?
942 assert(info
->is_watch
);
943 assert(info
->watch_context
);
944 assert(m
->opcode
!= CEPH_WATCH_EVENT_DISCONNECT
);
949 case CEPH_WATCH_EVENT_NOTIFY
:
950 info
->watch_context
->handle_notify(m
->notify_id
, m
->cookie
,
951 m
->notifier_gid
, m
->bl
);
956 info
->finished_async();
961 bool Objecter::ms_dispatch(Message
*m
)
963 ldout(cct
, 10) << __func__
<< " " << cct
<< " " << *m
<< dendl
;
967 switch (m
->get_type()) {
968 // these we exlusively handle
969 case CEPH_MSG_OSD_OPREPLY
:
970 handle_osd_op_reply(static_cast<MOSDOpReply
*>(m
));
973 case CEPH_MSG_OSD_BACKOFF
:
974 handle_osd_backoff(static_cast<MOSDBackoff
*>(m
));
977 case CEPH_MSG_WATCH_NOTIFY
:
978 handle_watch_notify(static_cast<MWatchNotify
*>(m
));
982 case MSG_COMMAND_REPLY
:
983 if (m
->get_source().type() == CEPH_ENTITY_TYPE_OSD
) {
984 handle_command_reply(static_cast<MCommandReply
*>(m
));
990 case MSG_GETPOOLSTATSREPLY
:
991 handle_get_pool_stats_reply(static_cast<MGetPoolStatsReply
*>(m
));
994 case CEPH_MSG_POOLOP_REPLY
:
995 handle_pool_op_reply(static_cast<MPoolOpReply
*>(m
));
998 case CEPH_MSG_STATFS_REPLY
:
999 handle_fs_stats_reply(static_cast<MStatfsReply
*>(m
));
1002 // these we give others a chance to inspect
1005 case CEPH_MSG_OSD_MAP
:
1006 handle_osd_map(static_cast<MOSDMap
*>(m
));
1012 void Objecter::_scan_requests(OSDSession
*s
,
1015 map
<int64_t, bool> *pool_full_map
,
1016 map
<ceph_tid_t
, Op
*>& need_resend
,
1017 list
<LingerOp
*>& need_resend_linger
,
1018 map
<ceph_tid_t
, CommandOp
*>& need_resend_command
,
1021 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
1023 list
<LingerOp
*> unregister_lingers
;
1025 OSDSession::unique_lock
sl(s
->lock
);
1027 // check for changed linger mappings (_before_ regular ops)
1028 map
<ceph_tid_t
,LingerOp
*>::iterator lp
= s
->linger_ops
.begin();
1029 while (lp
!= s
->linger_ops
.end()) {
1030 LingerOp
*op
= lp
->second
;
1031 assert(op
->session
== s
);
1032 // check_linger_pool_dne() may touch linger_ops; prevent iterator
1035 ldout(cct
, 10) << " checking linger op " << op
->linger_id
<< dendl
;
1036 bool unregister
, force_resend_writes
= cluster_full
;
1037 int r
= _recalc_linger_op_target(op
, sul
);
1039 force_resend_writes
= force_resend_writes
||
1040 (*pool_full_map
)[op
->target
.base_oloc
.pool
];
1042 case RECALC_OP_TARGET_NO_ACTION
:
1043 if (!force_resend
&& !force_resend_writes
)
1046 case RECALC_OP_TARGET_NEED_RESEND
:
1047 need_resend_linger
.push_back(op
);
1048 _linger_cancel_map_check(op
);
1050 case RECALC_OP_TARGET_POOL_DNE
:
1051 _check_linger_pool_dne(op
, &unregister
);
1053 ldout(cct
, 10) << " need to unregister linger op "
1054 << op
->linger_id
<< dendl
;
1056 unregister_lingers
.push_back(op
);
1062 // check for changed request mappings
1063 map
<ceph_tid_t
,Op
*>::iterator p
= s
->ops
.begin();
1064 while (p
!= s
->ops
.end()) {
1066 ++p
; // check_op_pool_dne() may touch ops; prevent iterator invalidation
1067 ldout(cct
, 10) << " checking op " << op
->tid
<< dendl
;
1068 bool force_resend_writes
= cluster_full
;
1070 force_resend_writes
= force_resend_writes
||
1071 (*pool_full_map
)[op
->target
.base_oloc
.pool
];
1072 int r
= _calc_target(&op
->target
,
1073 op
->session
? op
->session
->con
.get() : nullptr);
1075 case RECALC_OP_TARGET_NO_ACTION
:
1076 if (!force_resend
&& !(force_resend_writes
&& op
->respects_full()))
1079 case RECALC_OP_TARGET_NEED_RESEND
:
1081 _session_op_remove(op
->session
, op
);
1083 need_resend
[op
->tid
] = op
;
1084 _op_cancel_map_check(op
);
1086 case RECALC_OP_TARGET_POOL_DNE
:
1087 _check_op_pool_dne(op
, &sl
);
1093 map
<ceph_tid_t
,CommandOp
*>::iterator cp
= s
->command_ops
.begin();
1094 while (cp
!= s
->command_ops
.end()) {
1095 CommandOp
*c
= cp
->second
;
1097 ldout(cct
, 10) << " checking command " << c
->tid
<< dendl
;
1098 bool force_resend_writes
= cluster_full
;
1100 force_resend_writes
= force_resend_writes
||
1101 (*pool_full_map
)[c
->target_pg
.pool()];
1102 int r
= _calc_command_target(c
, sul
);
1104 case RECALC_OP_TARGET_NO_ACTION
:
1105 // resend if skipped map; otherwise do nothing.
1106 if (!force_resend
&& !force_resend_writes
)
1109 case RECALC_OP_TARGET_NEED_RESEND
:
1110 need_resend_command
[c
->tid
] = c
;
1112 _session_command_op_remove(c
->session
, c
);
1114 _command_cancel_map_check(c
);
1116 case RECALC_OP_TARGET_POOL_DNE
:
1117 case RECALC_OP_TARGET_OSD_DNE
:
1118 case RECALC_OP_TARGET_OSD_DOWN
:
1119 _check_command_map_dne(c
);
1126 for (list
<LingerOp
*>::iterator iter
= unregister_lingers
.begin();
1127 iter
!= unregister_lingers
.end();
1129 _linger_cancel(*iter
);
1134 void Objecter::handle_osd_map(MOSDMap
*m
)
1136 shunique_lock
sul(rwlock
, acquire_unique
);
1142 if (m
->fsid
!= monc
->get_fsid()) {
1143 ldout(cct
, 0) << "handle_osd_map fsid " << m
->fsid
1144 << " != " << monc
->get_fsid() << dendl
;
1148 bool was_pauserd
= osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
);
1149 bool cluster_full
= _osdmap_full_flag();
1150 bool was_pausewr
= osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
) || cluster_full
||
1151 _osdmap_has_pool_full();
1152 map
<int64_t, bool> pool_full_map
;
1153 for (map
<int64_t, pg_pool_t
>::const_iterator it
1154 = osdmap
->get_pools().begin();
1155 it
!= osdmap
->get_pools().end(); ++it
)
1156 pool_full_map
[it
->first
] = _osdmap_pool_full(it
->second
);
1159 list
<LingerOp
*> need_resend_linger
;
1160 map
<ceph_tid_t
, Op
*> need_resend
;
1161 map
<ceph_tid_t
, CommandOp
*> need_resend_command
;
1163 if (m
->get_last() <= osdmap
->get_epoch()) {
1164 ldout(cct
, 3) << "handle_osd_map ignoring epochs ["
1165 << m
->get_first() << "," << m
->get_last()
1166 << "] <= " << osdmap
->get_epoch() << dendl
;
1168 ldout(cct
, 3) << "handle_osd_map got epochs ["
1169 << m
->get_first() << "," << m
->get_last()
1170 << "] > " << osdmap
->get_epoch() << dendl
;
1172 if (osdmap
->get_epoch()) {
1173 bool skipped_map
= false;
1174 // we want incrementals
1175 for (epoch_t e
= osdmap
->get_epoch() + 1;
1179 if (osdmap
->get_epoch() == e
-1 &&
1180 m
->incremental_maps
.count(e
)) {
1181 ldout(cct
, 3) << "handle_osd_map decoding incremental epoch " << e
1183 OSDMap::Incremental
inc(m
->incremental_maps
[e
]);
1184 osdmap
->apply_incremental(inc
);
1186 emit_blacklist_events(inc
);
1188 logger
->inc(l_osdc_map_inc
);
1190 else if (m
->maps
.count(e
)) {
1191 ldout(cct
, 3) << "handle_osd_map decoding full epoch " << e
<< dendl
;
1192 OSDMap
*new_osdmap
= new OSDMap();
1193 new_osdmap
->decode(m
->maps
[e
]);
1195 emit_blacklist_events(*osdmap
, *new_osdmap
);
1197 osdmap
= new_osdmap
;
1199 logger
->inc(l_osdc_map_full
);
1202 if (e
>= m
->get_oldest()) {
1203 ldout(cct
, 3) << "handle_osd_map requesting missing epoch "
1204 << osdmap
->get_epoch()+1 << dendl
;
1205 _maybe_request_map();
1208 ldout(cct
, 3) << "handle_osd_map missing epoch "
1209 << osdmap
->get_epoch()+1
1210 << ", jumping to " << m
->get_oldest() << dendl
;
1211 e
= m
->get_oldest() - 1;
1215 logger
->set(l_osdc_map_epoch
, osdmap
->get_epoch());
1217 cluster_full
= cluster_full
|| _osdmap_full_flag();
1218 update_pool_full_map(pool_full_map
);
1220 // check all outstanding requests on every epoch
1221 _scan_requests(homeless_session
, skipped_map
, cluster_full
,
1222 &pool_full_map
, need_resend
,
1223 need_resend_linger
, need_resend_command
, sul
);
1224 for (map
<int,OSDSession
*>::iterator p
= osd_sessions
.begin();
1225 p
!= osd_sessions
.end(); ) {
1226 OSDSession
*s
= p
->second
;
1227 _scan_requests(s
, skipped_map
, cluster_full
,
1228 &pool_full_map
, need_resend
,
1229 need_resend_linger
, need_resend_command
, sul
);
1231 // osd down or addr change?
1232 if (!osdmap
->is_up(s
->osd
) ||
1234 s
->con
->get_peer_addr() != osdmap
->get_inst(s
->osd
).addr
)) {
1239 assert(e
== osdmap
->get_epoch());
1243 // first map. we want the full thing.
1244 if (m
->maps
.count(m
->get_last())) {
1245 for (map
<int,OSDSession
*>::iterator p
= osd_sessions
.begin();
1246 p
!= osd_sessions
.end(); ++p
) {
1247 OSDSession
*s
= p
->second
;
1248 _scan_requests(s
, false, false, NULL
, need_resend
,
1249 need_resend_linger
, need_resend_command
, sul
);
1251 ldout(cct
, 3) << "handle_osd_map decoding full epoch "
1252 << m
->get_last() << dendl
;
1253 osdmap
->decode(m
->maps
[m
->get_last()]);
1255 _scan_requests(homeless_session
, false, false, NULL
,
1256 need_resend
, need_resend_linger
,
1257 need_resend_command
, sul
);
1259 ldout(cct
, 3) << "handle_osd_map hmm, i want a full map, requesting"
1261 monc
->sub_want("osdmap", 0, CEPH_SUBSCRIBE_ONETIME
);
1267 // make sure need_resend targets reflect latest map
1268 for (auto p
= need_resend
.begin(); p
!= need_resend
.end(); ) {
1270 if (op
->target
.epoch
< osdmap
->get_epoch()) {
1271 ldout(cct
, 10) << __func__
<< " checking op " << p
->first
<< dendl
;
1272 int r
= _calc_target(&op
->target
, nullptr);
1273 if (r
== RECALC_OP_TARGET_POOL_DNE
) {
1274 p
= need_resend
.erase(p
);
1275 _check_op_pool_dne(op
, nullptr);
1284 bool pauserd
= osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
);
1285 bool pausewr
= osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
) || _osdmap_full_flag()
1286 || _osdmap_has_pool_full();
1289 if (was_pauserd
|| was_pausewr
|| pauserd
|| pausewr
||
1290 osdmap
->get_epoch() < epoch_barrier
) {
1291 _maybe_request_map();
1295 for (map
<ceph_tid_t
, Op
*>::iterator p
= need_resend
.begin();
1296 p
!= need_resend
.end(); ++p
) {
1298 OSDSession
*s
= op
->session
;
1299 bool mapped_session
= false;
1301 int r
= _map_session(&op
->target
, &s
, sul
);
1303 mapped_session
= true;
1307 OSDSession::unique_lock
sl(s
->lock
);
1308 if (mapped_session
) {
1309 _session_op_assign(s
, op
);
1311 if (op
->should_resend
) {
1312 if (!op
->session
->is_homeless() && !op
->target
.paused
) {
1313 logger
->inc(l_osdc_op_resend
);
1317 _op_cancel_map_check(op
);
1318 _cancel_linger_op(op
);
1323 for (list
<LingerOp
*>::iterator p
= need_resend_linger
.begin();
1324 p
!= need_resend_linger
.end(); ++p
) {
1327 _calc_target(&op
->target
, nullptr);
1328 OSDSession
*s
= NULL
;
1329 int const r
= _get_session(op
->target
.osd
, &s
, sul
);
1335 if (!op
->session
->is_homeless()) {
1336 logger
->inc(l_osdc_linger_resend
);
1337 _send_linger(op
, sul
);
1340 for (map
<ceph_tid_t
,CommandOp
*>::iterator p
= need_resend_command
.begin();
1341 p
!= need_resend_command
.end(); ++p
) {
1342 CommandOp
*c
= p
->second
;
1343 if (c
->target
.osd
>= 0) {
1344 _assign_command_session(c
, sul
);
1345 if (c
->session
&& !c
->session
->is_homeless()) {
1353 // finish any Contexts that were waiting on a map update
1354 map
<epoch_t
,list
< pair
< Context
*, int > > >::iterator p
=
1355 waiting_for_map
.begin();
1356 while (p
!= waiting_for_map
.end() &&
1357 p
->first
<= osdmap
->get_epoch()) {
1358 //go through the list and call the onfinish methods
1359 for (list
<pair
<Context
*, int> >::iterator i
= p
->second
.begin();
1360 i
!= p
->second
.end(); ++i
) {
1361 i
->first
->complete(i
->second
);
1363 waiting_for_map
.erase(p
++);
1366 monc
->sub_got("osdmap", osdmap
->get_epoch());
1368 if (!waiting_for_map
.empty()) {
1369 _maybe_request_map();
1373 void Objecter::enable_blacklist_events()
1375 unique_lock
wl(rwlock
);
1377 blacklist_events_enabled
= true;
1380 void Objecter::consume_blacklist_events(std::set
<entity_addr_t
> *events
)
1382 unique_lock
wl(rwlock
);
1384 if (events
->empty()) {
1385 events
->swap(blacklist_events
);
1387 for (const auto &i
: blacklist_events
) {
1390 blacklist_events
.clear();
1394 void Objecter::emit_blacklist_events(const OSDMap::Incremental
&inc
)
1396 if (!blacklist_events_enabled
) {
1400 for (const auto &i
: inc
.new_blacklist
) {
1401 blacklist_events
.insert(i
.first
);
1405 void Objecter::emit_blacklist_events(const OSDMap
&old_osd_map
,
1406 const OSDMap
&new_osd_map
)
1408 if (!blacklist_events_enabled
) {
1412 std::set
<entity_addr_t
> old_set
;
1413 std::set
<entity_addr_t
> new_set
;
1415 old_osd_map
.get_blacklist(&old_set
);
1416 new_osd_map
.get_blacklist(&new_set
);
1418 std::set
<entity_addr_t
> delta_set
;
1419 std::set_difference(
1420 new_set
.begin(), new_set
.end(), old_set
.begin(), old_set
.end(),
1421 std::inserter(delta_set
, delta_set
.begin()));
1422 blacklist_events
.insert(delta_set
.begin(), delta_set
.end());
1427 void Objecter::C_Op_Map_Latest::finish(int r
)
1429 if (r
== -EAGAIN
|| r
== -ECANCELED
)
1432 lgeneric_subdout(objecter
->cct
, objecter
, 10)
1433 << "op_map_latest r=" << r
<< " tid=" << tid
1434 << " latest " << latest
<< dendl
;
1436 Objecter::unique_lock
wl(objecter
->rwlock
);
1438 map
<ceph_tid_t
, Op
*>::iterator iter
=
1439 objecter
->check_latest_map_ops
.find(tid
);
1440 if (iter
== objecter
->check_latest_map_ops
.end()) {
1441 lgeneric_subdout(objecter
->cct
, objecter
, 10)
1442 << "op_map_latest op "<< tid
<< " not found" << dendl
;
1446 Op
*op
= iter
->second
;
1447 objecter
->check_latest_map_ops
.erase(iter
);
1449 lgeneric_subdout(objecter
->cct
, objecter
, 20)
1450 << "op_map_latest op "<< op
<< dendl
;
1452 if (op
->map_dne_bound
== 0)
1453 op
->map_dne_bound
= latest
;
1455 OSDSession::unique_lock
sl(op
->session
->lock
, defer_lock
);
1456 objecter
->_check_op_pool_dne(op
, &sl
);
1461 int Objecter::pool_snap_by_name(int64_t poolid
, const char *snap_name
,
1462 snapid_t
*snap
) const
1464 shared_lock
rl(rwlock
);
1466 auto& pools
= osdmap
->get_pools();
1467 auto iter
= pools
.find(poolid
);
1468 if (iter
== pools
.end()) {
1471 const pg_pool_t
& pg_pool
= iter
->second
;
1472 for (auto p
= pg_pool
.snaps
.begin();
1473 p
!= pg_pool
.snaps
.end();
1475 if (p
->second
.name
== snap_name
) {
1483 int Objecter::pool_snap_get_info(int64_t poolid
, snapid_t snap
,
1484 pool_snap_info_t
*info
) const
1486 shared_lock
rl(rwlock
);
1488 auto& pools
= osdmap
->get_pools();
1489 auto iter
= pools
.find(poolid
);
1490 if (iter
== pools
.end()) {
1493 const pg_pool_t
& pg_pool
= iter
->second
;
1494 auto p
= pg_pool
.snaps
.find(snap
);
1495 if (p
== pg_pool
.snaps
.end())
1502 int Objecter::pool_snap_list(int64_t poolid
, vector
<uint64_t> *snaps
)
1504 shared_lock
rl(rwlock
);
1506 const pg_pool_t
*pi
= osdmap
->get_pg_pool(poolid
);
1509 for (map
<snapid_t
,pool_snap_info_t
>::const_iterator p
= pi
->snaps
.begin();
1510 p
!= pi
->snaps
.end();
1512 snaps
->push_back(p
->first
);
1517 // sl may be unlocked.
1518 void Objecter::_check_op_pool_dne(Op
*op
, unique_lock
*sl
)
1520 // rwlock is locked unique
1522 if (op
->target
.pool_ever_existed
) {
1523 // the pool previously existed and now it does not, which means it
1525 op
->map_dne_bound
= osdmap
->get_epoch();
1526 ldout(cct
, 10) << "check_op_pool_dne tid " << op
->tid
1527 << " pool previously exists but now does not"
1530 ldout(cct
, 10) << "check_op_pool_dne tid " << op
->tid
1531 << " current " << osdmap
->get_epoch()
1532 << " map_dne_bound " << op
->map_dne_bound
1535 if (op
->map_dne_bound
> 0) {
1536 if (osdmap
->get_epoch() >= op
->map_dne_bound
) {
1537 // we had a new enough map
1538 ldout(cct
, 10) << "check_op_pool_dne tid " << op
->tid
1539 << " concluding pool " << op
->target
.base_pgid
.pool()
1542 op
->onfinish
->complete(-ENOENT
);
1545 OSDSession
*s
= op
->session
;
1548 assert(sl
->mutex() == &s
->lock
);
1549 bool session_locked
= sl
->owns_lock();
1550 if (!session_locked
) {
1554 if (!session_locked
) {
1558 _finish_op(op
, 0); // no session
1562 _send_op_map_check(op
);
1566 void Objecter::_send_op_map_check(Op
*op
)
1568 // rwlock is locked unique
1570 if (check_latest_map_ops
.count(op
->tid
) == 0) {
1572 check_latest_map_ops
[op
->tid
] = op
;
1573 C_Op_Map_Latest
*c
= new C_Op_Map_Latest(this, op
->tid
);
1574 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
1578 void Objecter::_op_cancel_map_check(Op
*op
)
1580 // rwlock is locked unique
1581 map
<ceph_tid_t
, Op
*>::iterator iter
=
1582 check_latest_map_ops
.find(op
->tid
);
1583 if (iter
!= check_latest_map_ops
.end()) {
1584 Op
*op
= iter
->second
;
1586 check_latest_map_ops
.erase(iter
);
1590 // linger pool check
1592 void Objecter::C_Linger_Map_Latest::finish(int r
)
1594 if (r
== -EAGAIN
|| r
== -ECANCELED
) {
1595 // ignore callback; we will retry in resend_mon_ops()
1599 unique_lock
wl(objecter
->rwlock
);
1601 map
<uint64_t, LingerOp
*>::iterator iter
=
1602 objecter
->check_latest_map_lingers
.find(linger_id
);
1603 if (iter
== objecter
->check_latest_map_lingers
.end()) {
1607 LingerOp
*op
= iter
->second
;
1608 objecter
->check_latest_map_lingers
.erase(iter
);
1610 if (op
->map_dne_bound
== 0)
1611 op
->map_dne_bound
= latest
;
1614 objecter
->_check_linger_pool_dne(op
, &unregister
);
1617 objecter
->_linger_cancel(op
);
1623 void Objecter::_check_linger_pool_dne(LingerOp
*op
, bool *need_unregister
)
1625 // rwlock is locked unique
1627 *need_unregister
= false;
1629 if (op
->register_gen
> 0) {
1630 ldout(cct
, 10) << "_check_linger_pool_dne linger_id " << op
->linger_id
1631 << " pool previously existed but now does not"
1633 op
->map_dne_bound
= osdmap
->get_epoch();
1635 ldout(cct
, 10) << "_check_linger_pool_dne linger_id " << op
->linger_id
1636 << " current " << osdmap
->get_epoch()
1637 << " map_dne_bound " << op
->map_dne_bound
1640 if (op
->map_dne_bound
> 0) {
1641 if (osdmap
->get_epoch() >= op
->map_dne_bound
) {
1642 if (op
->on_reg_commit
) {
1643 op
->on_reg_commit
->complete(-ENOENT
);
1645 *need_unregister
= true;
1648 _send_linger_map_check(op
);
1652 void Objecter::_send_linger_map_check(LingerOp
*op
)
1655 if (check_latest_map_lingers
.count(op
->linger_id
) == 0) {
1657 check_latest_map_lingers
[op
->linger_id
] = op
;
1658 C_Linger_Map_Latest
*c
= new C_Linger_Map_Latest(this, op
->linger_id
);
1659 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
1663 void Objecter::_linger_cancel_map_check(LingerOp
*op
)
1665 // rwlock is locked unique
1667 map
<uint64_t, LingerOp
*>::iterator iter
=
1668 check_latest_map_lingers
.find(op
->linger_id
);
1669 if (iter
!= check_latest_map_lingers
.end()) {
1670 LingerOp
*op
= iter
->second
;
1672 check_latest_map_lingers
.erase(iter
);
1676 // command pool check
1678 void Objecter::C_Command_Map_Latest::finish(int r
)
1680 if (r
== -EAGAIN
|| r
== -ECANCELED
) {
1681 // ignore callback; we will retry in resend_mon_ops()
1685 unique_lock
wl(objecter
->rwlock
);
1687 map
<uint64_t, CommandOp
*>::iterator iter
=
1688 objecter
->check_latest_map_commands
.find(tid
);
1689 if (iter
== objecter
->check_latest_map_commands
.end()) {
1693 CommandOp
*c
= iter
->second
;
1694 objecter
->check_latest_map_commands
.erase(iter
);
1696 if (c
->map_dne_bound
== 0)
1697 c
->map_dne_bound
= latest
;
1699 objecter
->_check_command_map_dne(c
);
1704 void Objecter::_check_command_map_dne(CommandOp
*c
)
1706 // rwlock is locked unique
1708 ldout(cct
, 10) << "_check_command_map_dne tid " << c
->tid
1709 << " current " << osdmap
->get_epoch()
1710 << " map_dne_bound " << c
->map_dne_bound
1712 if (c
->map_dne_bound
> 0) {
1713 if (osdmap
->get_epoch() >= c
->map_dne_bound
) {
1714 _finish_command(c
, c
->map_check_error
, c
->map_check_error_str
);
1717 _send_command_map_check(c
);
1721 void Objecter::_send_command_map_check(CommandOp
*c
)
1723 // rwlock is locked unique
1726 if (check_latest_map_commands
.count(c
->tid
) == 0) {
1728 check_latest_map_commands
[c
->tid
] = c
;
1729 C_Command_Map_Latest
*f
= new C_Command_Map_Latest(this, c
->tid
);
1730 monc
->get_version("osdmap", &f
->latest
, NULL
, f
);
1734 void Objecter::_command_cancel_map_check(CommandOp
*c
)
1736 // rwlock is locked uniqe
1738 map
<uint64_t, CommandOp
*>::iterator iter
=
1739 check_latest_map_commands
.find(c
->tid
);
1740 if (iter
!= check_latest_map_commands
.end()) {
1741 CommandOp
*c
= iter
->second
;
1743 check_latest_map_commands
.erase(iter
);
1749 * Look up OSDSession by OSD id.
1751 * @returns 0 on success, or -EAGAIN if the lock context requires
1752 * promotion to write.
1754 int Objecter::_get_session(int osd
, OSDSession
**session
, shunique_lock
& sul
)
1756 assert(sul
&& sul
.mutex() == &rwlock
);
1759 *session
= homeless_session
;
1760 ldout(cct
, 20) << __func__
<< " osd=" << osd
<< " returning homeless"
1765 map
<int,OSDSession
*>::iterator p
= osd_sessions
.find(osd
);
1766 if (p
!= osd_sessions
.end()) {
1767 OSDSession
*s
= p
->second
;
1770 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << osd
<< " "
1771 << s
->get_nref() << dendl
;
1774 if (!sul
.owns_lock()) {
1777 OSDSession
*s
= new OSDSession(cct
, osd
);
1778 osd_sessions
[osd
] = s
;
1779 s
->con
= messenger
->get_connection(osdmap
->get_inst(osd
));
1780 s
->con
->set_priv(s
->get());
1781 logger
->inc(l_osdc_osd_session_open
);
1782 logger
->set(l_osdc_osd_sessions
, osd_sessions
.size());
1785 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << osd
<< " "
1786 << s
->get_nref() << dendl
;
1790 void Objecter::put_session(Objecter::OSDSession
*s
)
1792 if (s
&& !s
->is_homeless()) {
1793 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << s
->osd
<< " "
1794 << s
->get_nref() << dendl
;
1799 void Objecter::get_session(Objecter::OSDSession
*s
)
1803 if (!s
->is_homeless()) {
1804 ldout(cct
, 20) << __func__
<< " s=" << s
<< " osd=" << s
->osd
<< " "
1805 << s
->get_nref() << dendl
;
1810 void Objecter::_reopen_session(OSDSession
*s
)
1812 // s->lock is locked
1814 entity_inst_t inst
= osdmap
->get_inst(s
->osd
);
1815 ldout(cct
, 10) << "reopen_session osd." << s
->osd
<< " session, addr now "
1818 s
->con
->set_priv(NULL
);
1819 s
->con
->mark_down();
1820 logger
->inc(l_osdc_osd_session_close
);
1822 s
->con
= messenger
->get_connection(inst
);
1823 s
->con
->set_priv(s
->get());
1825 logger
->inc(l_osdc_osd_session_open
);
1828 void Objecter::close_session(OSDSession
*s
)
1830 // rwlock is locked unique
1832 ldout(cct
, 10) << "close_session for osd." << s
->osd
<< dendl
;
1834 s
->con
->set_priv(NULL
);
1835 s
->con
->mark_down();
1836 logger
->inc(l_osdc_osd_session_close
);
1838 OSDSession::unique_lock
sl(s
->lock
);
1840 std::list
<LingerOp
*> homeless_lingers
;
1841 std::list
<CommandOp
*> homeless_commands
;
1842 std::list
<Op
*> homeless_ops
;
1844 while (!s
->linger_ops
.empty()) {
1845 std::map
<uint64_t, LingerOp
*>::iterator i
= s
->linger_ops
.begin();
1846 ldout(cct
, 10) << " linger_op " << i
->first
<< dendl
;
1847 homeless_lingers
.push_back(i
->second
);
1848 _session_linger_op_remove(s
, i
->second
);
1851 while (!s
->ops
.empty()) {
1852 std::map
<ceph_tid_t
, Op
*>::iterator i
= s
->ops
.begin();
1853 ldout(cct
, 10) << " op " << i
->first
<< dendl
;
1854 homeless_ops
.push_back(i
->second
);
1855 _session_op_remove(s
, i
->second
);
1858 while (!s
->command_ops
.empty()) {
1859 std::map
<ceph_tid_t
, CommandOp
*>::iterator i
= s
->command_ops
.begin();
1860 ldout(cct
, 10) << " command_op " << i
->first
<< dendl
;
1861 homeless_commands
.push_back(i
->second
);
1862 _session_command_op_remove(s
, i
->second
);
1865 osd_sessions
.erase(s
->osd
);
1869 // Assign any leftover ops to the homeless session
1871 OSDSession::unique_lock
hsl(homeless_session
->lock
);
1872 for (std::list
<LingerOp
*>::iterator i
= homeless_lingers
.begin();
1873 i
!= homeless_lingers
.end(); ++i
) {
1874 _session_linger_op_assign(homeless_session
, *i
);
1876 for (std::list
<Op
*>::iterator i
= homeless_ops
.begin();
1877 i
!= homeless_ops
.end(); ++i
) {
1878 _session_op_assign(homeless_session
, *i
);
1880 for (std::list
<CommandOp
*>::iterator i
= homeless_commands
.begin();
1881 i
!= homeless_commands
.end(); ++i
) {
1882 _session_command_op_assign(homeless_session
, *i
);
1886 logger
->set(l_osdc_osd_sessions
, osd_sessions
.size());
1889 void Objecter::wait_for_osd_map()
1891 unique_lock
l(rwlock
);
1892 if (osdmap
->get_epoch()) {
1897 // Leave this since it goes with C_SafeCond
1902 C_SafeCond
*context
= new C_SafeCond(&lock
, &cond
, &done
, NULL
);
1903 waiting_for_map
[0].push_back(pair
<Context
*, int>(context
, 0));
1910 struct C_Objecter_GetVersion
: public Context
{
1912 uint64_t oldest
, newest
;
1914 C_Objecter_GetVersion(Objecter
*o
, Context
*c
)
1915 : objecter(o
), oldest(0), newest(0), fin(c
) {}
1916 void finish(int r
) override
{
1918 objecter
->get_latest_version(oldest
, newest
, fin
);
1919 } else if (r
== -EAGAIN
) { // try again as instructed
1920 objecter
->wait_for_latest_osdmap(fin
);
1922 // it doesn't return any other error codes!
1928 void Objecter::wait_for_latest_osdmap(Context
*fin
)
1930 ldout(cct
, 10) << __func__
<< dendl
;
1931 C_Objecter_GetVersion
*c
= new C_Objecter_GetVersion(this, fin
);
1932 monc
->get_version("osdmap", &c
->newest
, &c
->oldest
, c
);
1935 void Objecter::get_latest_version(epoch_t oldest
, epoch_t newest
, Context
*fin
)
1937 unique_lock
wl(rwlock
);
1938 _get_latest_version(oldest
, newest
, fin
);
1941 void Objecter::_get_latest_version(epoch_t oldest
, epoch_t newest
,
1944 // rwlock is locked unique
1945 if (osdmap
->get_epoch() >= newest
) {
1946 ldout(cct
, 10) << __func__
<< " latest " << newest
<< ", have it" << dendl
;
1952 ldout(cct
, 10) << __func__
<< " latest " << newest
<< ", waiting" << dendl
;
1953 _wait_for_new_map(fin
, newest
, 0);
1956 void Objecter::maybe_request_map()
1958 shared_lock
rl(rwlock
);
1959 _maybe_request_map();
1962 void Objecter::_maybe_request_map()
1966 if (_osdmap_full_flag()
1967 || osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
)
1968 || osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
)) {
1969 ldout(cct
, 10) << "_maybe_request_map subscribing (continuous) to next "
1970 "osd map (FULL flag is set)" << dendl
;
1973 << "_maybe_request_map subscribing (onetime) to next osd map" << dendl
;
1974 flag
= CEPH_SUBSCRIBE_ONETIME
;
1976 epoch_t epoch
= osdmap
->get_epoch() ? osdmap
->get_epoch()+1 : 0;
1977 if (monc
->sub_want("osdmap", epoch
, flag
)) {
1982 void Objecter::_wait_for_new_map(Context
*c
, epoch_t epoch
, int err
)
1984 // rwlock is locked unique
1985 waiting_for_map
[epoch
].push_back(pair
<Context
*, int>(c
, err
));
1986 _maybe_request_map();
1991 * Use this together with wait_for_map: this is a pre-check to avoid
1992 * allocating a Context for wait_for_map if we can see that we
1993 * definitely already have the epoch.
1995 * This does *not* replace the need to handle the return value of
1996 * wait_for_map: just because we don't have it in this pre-check
1997 * doesn't mean we won't have it when calling back into wait_for_map,
1998 * since the objecter lock is dropped in between.
2000 bool Objecter::have_map(const epoch_t epoch
)
2002 shared_lock
rl(rwlock
);
2003 if (osdmap
->get_epoch() >= epoch
) {
2010 bool Objecter::wait_for_map(epoch_t epoch
, Context
*c
, int err
)
2012 unique_lock
wl(rwlock
);
2013 if (osdmap
->get_epoch() >= epoch
) {
2016 _wait_for_new_map(c
, epoch
, err
);
2020 void Objecter::kick_requests(OSDSession
*session
)
2022 ldout(cct
, 10) << "kick_requests for osd." << session
->osd
<< dendl
;
2024 map
<uint64_t, LingerOp
*> lresend
;
2025 unique_lock
wl(rwlock
);
2027 OSDSession::unique_lock
sl(session
->lock
);
2028 _kick_requests(session
, lresend
);
2031 _linger_ops_resend(lresend
, wl
);
2034 void Objecter::_kick_requests(OSDSession
*session
,
2035 map
<uint64_t, LingerOp
*>& lresend
)
2037 // rwlock is locked unique
2040 session
->backoffs
.clear();
2041 session
->backoffs_by_id
.clear();
2044 map
<ceph_tid_t
,Op
*> resend
; // resend in tid order
2045 for (map
<ceph_tid_t
, Op
*>::iterator p
= session
->ops
.begin();
2046 p
!= session
->ops
.end();) {
2049 logger
->inc(l_osdc_op_resend
);
2050 if (op
->should_resend
) {
2051 if (!op
->target
.paused
)
2052 resend
[op
->tid
] = op
;
2054 _op_cancel_map_check(op
);
2055 _cancel_linger_op(op
);
2059 while (!resend
.empty()) {
2060 _send_op(resend
.begin()->second
);
2061 resend
.erase(resend
.begin());
2065 for (map
<ceph_tid_t
, LingerOp
*>::iterator j
= session
->linger_ops
.begin();
2066 j
!= session
->linger_ops
.end(); ++j
) {
2067 LingerOp
*op
= j
->second
;
2069 logger
->inc(l_osdc_linger_resend
);
2070 assert(lresend
.count(j
->first
) == 0);
2071 lresend
[j
->first
] = op
;
2075 map
<uint64_t,CommandOp
*> cresend
; // resend in order
2076 for (map
<ceph_tid_t
, CommandOp
*>::iterator k
= session
->command_ops
.begin();
2077 k
!= session
->command_ops
.end(); ++k
) {
2078 logger
->inc(l_osdc_command_resend
);
2079 cresend
[k
->first
] = k
->second
;
2081 while (!cresend
.empty()) {
2082 _send_command(cresend
.begin()->second
);
2083 cresend
.erase(cresend
.begin());
2087 void Objecter::_linger_ops_resend(map
<uint64_t, LingerOp
*>& lresend
,
2090 assert(ul
.owns_lock());
2091 shunique_lock
sul(std::move(ul
));
2092 while (!lresend
.empty()) {
2093 LingerOp
*op
= lresend
.begin()->second
;
2094 if (!op
->canceled
) {
2095 _send_linger(op
, sul
);
2098 lresend
.erase(lresend
.begin());
2100 ul
= unique_lock(sul
.release_to_unique());
2103 void Objecter::start_tick()
2105 assert(tick_event
== 0);
2107 timer
.add_event(ceph::make_timespan(cct
->_conf
->objecter_tick_interval
),
2108 &Objecter::tick
, this);
2111 void Objecter::tick()
2113 shared_lock
rl(rwlock
);
2115 ldout(cct
, 10) << "tick" << dendl
;
2117 // we are only called by C_Tick
2121 // we raced with shutdown
2122 ldout(cct
, 10) << __func__
<< " raced with shutdown" << dendl
;
2126 set
<OSDSession
*> toping
;
2129 // look for laggy requests
2130 auto cutoff
= ceph::mono_clock::now();
2131 cutoff
-= ceph::make_timespan(cct
->_conf
->objecter_timeout
); // timeout
2133 unsigned laggy_ops
= 0;
2135 for (map
<int,OSDSession
*>::iterator siter
= osd_sessions
.begin();
2136 siter
!= osd_sessions
.end(); ++siter
) {
2137 OSDSession
*s
= siter
->second
;
2138 OSDSession::lock_guard
l(s
->lock
);
2140 for (map
<ceph_tid_t
,Op
*>::iterator p
= s
->ops
.begin();
2144 assert(op
->session
);
2145 if (op
->stamp
< cutoff
) {
2146 ldout(cct
, 2) << " tid " << p
->first
<< " on osd." << op
->session
->osd
2147 << " is laggy" << dendl
;
2152 for (map
<uint64_t,LingerOp
*>::iterator p
= s
->linger_ops
.begin();
2153 p
!= s
->linger_ops
.end();
2155 LingerOp
*op
= p
->second
;
2156 LingerOp::unique_lock
wl(op
->watch_lock
);
2157 assert(op
->session
);
2158 ldout(cct
, 10) << " pinging osd that serves lingering tid " << p
->first
2159 << " (osd." << op
->session
->osd
<< ")" << dendl
;
2161 if (op
->is_watch
&& op
->registered
&& !op
->last_error
)
2162 _send_linger_ping(op
);
2164 for (map
<uint64_t,CommandOp
*>::iterator p
= s
->command_ops
.begin();
2165 p
!= s
->command_ops
.end();
2167 CommandOp
*op
= p
->second
;
2168 assert(op
->session
);
2169 ldout(cct
, 10) << " pinging osd that serves command tid " << p
->first
2170 << " (osd." << op
->session
->osd
<< ")" << dendl
;
2176 if (num_homeless_ops
|| !toping
.empty()) {
2177 _maybe_request_map();
2180 logger
->set(l_osdc_op_laggy
, laggy_ops
);
2181 logger
->set(l_osdc_osd_laggy
, toping
.size());
2183 if (!toping
.empty()) {
2184 // send a ping to these osds, to ensure we detect any session resets
2185 // (osd reply message policy is lossy)
2186 for (set
<OSDSession
*>::const_iterator i
= toping
.begin();
2189 (*i
)->con
->send_message(new MPing
);
2193 // Make sure we don't resechedule if we wake up after shutdown
2195 tick_event
= timer
.reschedule_me(ceph::make_timespan(
2196 cct
->_conf
->objecter_tick_interval
));
2200 void Objecter::resend_mon_ops()
2202 unique_lock
wl(rwlock
);
2204 ldout(cct
, 10) << "resend_mon_ops" << dendl
;
2206 for (map
<ceph_tid_t
,PoolStatOp
*>::iterator p
= poolstat_ops
.begin();
2207 p
!= poolstat_ops
.end();
2209 _poolstat_submit(p
->second
);
2210 logger
->inc(l_osdc_poolstat_resend
);
2213 for (map
<ceph_tid_t
,StatfsOp
*>::iterator p
= statfs_ops
.begin();
2214 p
!= statfs_ops
.end();
2216 _fs_stats_submit(p
->second
);
2217 logger
->inc(l_osdc_statfs_resend
);
2220 for (map
<ceph_tid_t
,PoolOp
*>::iterator p
= pool_ops
.begin();
2221 p
!= pool_ops
.end();
2223 _pool_op_submit(p
->second
);
2224 logger
->inc(l_osdc_poolop_resend
);
2227 for (map
<ceph_tid_t
, Op
*>::iterator p
= check_latest_map_ops
.begin();
2228 p
!= check_latest_map_ops
.end();
2230 C_Op_Map_Latest
*c
= new C_Op_Map_Latest(this, p
->second
->tid
);
2231 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
2234 for (map
<uint64_t, LingerOp
*>::iterator p
= check_latest_map_lingers
.begin();
2235 p
!= check_latest_map_lingers
.end();
2237 C_Linger_Map_Latest
*c
2238 = new C_Linger_Map_Latest(this, p
->second
->linger_id
);
2239 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
2242 for (map
<uint64_t, CommandOp
*>::iterator p
2243 = check_latest_map_commands
.begin();
2244 p
!= check_latest_map_commands
.end();
2246 C_Command_Map_Latest
*c
= new C_Command_Map_Latest(this, p
->second
->tid
);
2247 monc
->get_version("osdmap", &c
->latest
, NULL
, c
);
2251 // read | write ---------------------------
2253 void Objecter::op_submit(Op
*op
, ceph_tid_t
*ptid
, int *ctx_budget
)
2255 shunique_lock
rl(rwlock
, ceph::acquire_shared
);
2259 op
->trace
.event("op submit");
2260 _op_submit_with_budget(op
, rl
, ptid
, ctx_budget
);
2263 void Objecter::_op_submit_with_budget(Op
*op
, shunique_lock
& sul
,
2267 assert(initialized
);
2269 assert(op
->ops
.size() == op
->out_bl
.size());
2270 assert(op
->ops
.size() == op
->out_rval
.size());
2271 assert(op
->ops
.size() == op
->out_handler
.size());
2273 // throttle. before we look at any state, because
2274 // _take_op_budget() may drop our lock while it blocks.
2275 if (!op
->ctx_budgeted
|| (ctx_budget
&& (*ctx_budget
== -1))) {
2276 int op_budget
= _take_op_budget(op
, sul
);
2277 // take and pass out the budget for the first OP
2278 // in the context session
2279 if (ctx_budget
&& (*ctx_budget
== -1)) {
2280 *ctx_budget
= op_budget
;
2284 if (osd_timeout
> timespan(0)) {
2286 op
->tid
= ++last_tid
;
2288 op
->ontimeout
= timer
.add_event(osd_timeout
,
2290 op_cancel(tid
, -ETIMEDOUT
); });
2293 _op_submit(op
, sul
, ptid
);
2296 void Objecter::_send_op_account(Op
*op
)
2300 // add to gather set(s)
2304 ldout(cct
, 20) << " note: not requesting reply" << dendl
;
2307 logger
->inc(l_osdc_op_active
);
2308 logger
->inc(l_osdc_op
);
2310 if ((op
->target
.flags
& (CEPH_OSD_FLAG_READ
| CEPH_OSD_FLAG_WRITE
)) ==
2311 (CEPH_OSD_FLAG_READ
|CEPH_OSD_FLAG_WRITE
))
2312 logger
->inc(l_osdc_op_rmw
);
2313 else if (op
->target
.flags
& CEPH_OSD_FLAG_WRITE
)
2314 logger
->inc(l_osdc_op_w
);
2315 else if (op
->target
.flags
& CEPH_OSD_FLAG_READ
)
2316 logger
->inc(l_osdc_op_r
);
2318 if (op
->target
.flags
& CEPH_OSD_FLAG_PGOP
)
2319 logger
->inc(l_osdc_op_pg
);
2321 for (vector
<OSDOp
>::iterator p
= op
->ops
.begin(); p
!= op
->ops
.end(); ++p
) {
2322 int code
= l_osdc_osdop_other
;
2324 case CEPH_OSD_OP_STAT
: code
= l_osdc_osdop_stat
; break;
2325 case CEPH_OSD_OP_CREATE
: code
= l_osdc_osdop_create
; break;
2326 case CEPH_OSD_OP_READ
: code
= l_osdc_osdop_read
; break;
2327 case CEPH_OSD_OP_WRITE
: code
= l_osdc_osdop_write
; break;
2328 case CEPH_OSD_OP_WRITEFULL
: code
= l_osdc_osdop_writefull
; break;
2329 case CEPH_OSD_OP_WRITESAME
: code
= l_osdc_osdop_writesame
; break;
2330 case CEPH_OSD_OP_APPEND
: code
= l_osdc_osdop_append
; break;
2331 case CEPH_OSD_OP_ZERO
: code
= l_osdc_osdop_zero
; break;
2332 case CEPH_OSD_OP_TRUNCATE
: code
= l_osdc_osdop_truncate
; break;
2333 case CEPH_OSD_OP_DELETE
: code
= l_osdc_osdop_delete
; break;
2334 case CEPH_OSD_OP_MAPEXT
: code
= l_osdc_osdop_mapext
; break;
2335 case CEPH_OSD_OP_SPARSE_READ
: code
= l_osdc_osdop_sparse_read
; break;
2336 case CEPH_OSD_OP_GETXATTR
: code
= l_osdc_osdop_getxattr
; break;
2337 case CEPH_OSD_OP_SETXATTR
: code
= l_osdc_osdop_setxattr
; break;
2338 case CEPH_OSD_OP_CMPXATTR
: code
= l_osdc_osdop_cmpxattr
; break;
2339 case CEPH_OSD_OP_RMXATTR
: code
= l_osdc_osdop_rmxattr
; break;
2340 case CEPH_OSD_OP_RESETXATTRS
: code
= l_osdc_osdop_resetxattrs
; break;
2341 case CEPH_OSD_OP_TMAPUP
: code
= l_osdc_osdop_tmap_up
; break;
2342 case CEPH_OSD_OP_TMAPPUT
: code
= l_osdc_osdop_tmap_put
; break;
2343 case CEPH_OSD_OP_TMAPGET
: code
= l_osdc_osdop_tmap_get
; break;
2345 // OMAP read operations
2346 case CEPH_OSD_OP_OMAPGETVALS
:
2347 case CEPH_OSD_OP_OMAPGETKEYS
:
2348 case CEPH_OSD_OP_OMAPGETHEADER
:
2349 case CEPH_OSD_OP_OMAPGETVALSBYKEYS
:
2350 case CEPH_OSD_OP_OMAP_CMP
: code
= l_osdc_osdop_omap_rd
; break;
2352 // OMAP write operations
2353 case CEPH_OSD_OP_OMAPSETVALS
:
2354 case CEPH_OSD_OP_OMAPSETHEADER
: code
= l_osdc_osdop_omap_wr
; break;
2356 // OMAP del operations
2357 case CEPH_OSD_OP_OMAPCLEAR
:
2358 case CEPH_OSD_OP_OMAPRMKEYS
: code
= l_osdc_osdop_omap_del
; break;
2360 case CEPH_OSD_OP_CALL
: code
= l_osdc_osdop_call
; break;
2361 case CEPH_OSD_OP_WATCH
: code
= l_osdc_osdop_watch
; break;
2362 case CEPH_OSD_OP_NOTIFY
: code
= l_osdc_osdop_notify
; break;
2369 void Objecter::_op_submit(Op
*op
, shunique_lock
& sul
, ceph_tid_t
*ptid
)
2373 ldout(cct
, 10) << __func__
<< " op " << op
<< dendl
;
2376 assert(op
->session
== NULL
);
2377 OSDSession
*s
= NULL
;
2379 bool check_for_latest_map
= _calc_target(&op
->target
, nullptr)
2380 == RECALC_OP_TARGET_POOL_DNE
;
2382 // Try to get a session, including a retry if we need to take write lock
2383 int r
= _get_session(op
->target
.osd
, &s
, sul
);
2385 (check_for_latest_map
&& sul
.owns_lock_shared())) {
2386 epoch_t orig_epoch
= osdmap
->get_epoch();
2388 if (cct
->_conf
->objecter_debug_inject_relock_delay
) {
2392 if (orig_epoch
!= osdmap
->get_epoch()) {
2393 // map changed; recalculate mapping
2394 ldout(cct
, 10) << __func__
<< " relock raced with osdmap, recalc target"
2396 check_for_latest_map
= _calc_target(&op
->target
, nullptr)
2397 == RECALC_OP_TARGET_POOL_DNE
;
2407 r
= _get_session(op
->target
.osd
, &s
, sul
);
2410 assert(s
); // may be homeless
2412 _send_op_account(op
);
2416 assert(op
->target
.flags
& (CEPH_OSD_FLAG_READ
|CEPH_OSD_FLAG_WRITE
));
2418 if (osdmap_full_try
) {
2419 op
->target
.flags
|= CEPH_OSD_FLAG_FULL_TRY
;
2422 bool need_send
= false;
2424 if (osdmap
->get_epoch() < epoch_barrier
) {
2425 ldout(cct
, 10) << " barrier, paused " << op
<< " tid " << op
->tid
2427 op
->target
.paused
= true;
2428 _maybe_request_map();
2429 } else if ((op
->target
.flags
& CEPH_OSD_FLAG_WRITE
) &&
2430 osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
)) {
2431 ldout(cct
, 10) << " paused modify " << op
<< " tid " << op
->tid
2433 op
->target
.paused
= true;
2434 _maybe_request_map();
2435 } else if ((op
->target
.flags
& CEPH_OSD_FLAG_READ
) &&
2436 osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
)) {
2437 ldout(cct
, 10) << " paused read " << op
<< " tid " << op
->tid
2439 op
->target
.paused
= true;
2440 _maybe_request_map();
2441 } else if (op
->respects_full() &&
2442 (_osdmap_full_flag() ||
2443 _osdmap_pool_full(op
->target
.base_oloc
.pool
))) {
2444 ldout(cct
, 0) << " FULL, paused modify " << op
<< " tid "
2445 << op
->tid
<< dendl
;
2446 op
->target
.paused
= true;
2447 _maybe_request_map();
2448 } else if (!s
->is_homeless()) {
2451 _maybe_request_map();
2456 m
= _prepare_osd_op(op
);
2459 OSDSession::unique_lock
sl(s
->lock
);
2461 op
->tid
= ++last_tid
;
2463 ldout(cct
, 10) << "_op_submit oid " << op
->target
.base_oid
2464 << " '" << op
->target
.base_oloc
<< "' '"
2465 << op
->target
.target_oloc
<< "' " << op
->ops
<< " tid "
2466 << op
->tid
<< " osd." << (!s
->is_homeless() ? s
->osd
: -1)
2469 _session_op_assign(s
, op
);
2475 // Last chance to touch Op here, after giving up session lock it can
2476 // be freed at any time by response handler.
2477 ceph_tid_t tid
= op
->tid
;
2478 if (check_for_latest_map
) {
2479 _send_op_map_check(op
);
2488 ldout(cct
, 5) << num_in_flight
<< " in flight" << dendl
;
2491 int Objecter::op_cancel(OSDSession
*s
, ceph_tid_t tid
, int r
)
2493 assert(initialized
);
2495 OSDSession::unique_lock
sl(s
->lock
);
2497 map
<ceph_tid_t
, Op
*>::iterator p
= s
->ops
.find(tid
);
2498 if (p
== s
->ops
.end()) {
2499 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne in session "
2505 ldout(cct
, 20) << " revoking rx buffer for " << tid
2506 << " on " << s
->con
<< dendl
;
2507 s
->con
->revoke_rx_buffer(tid
);
2510 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " in session " << s
->osd
2515 op
->onfinish
->complete(r
);
2516 op
->onfinish
= NULL
;
2518 _op_cancel_map_check(op
);
2525 int Objecter::op_cancel(ceph_tid_t tid
, int r
)
2529 unique_lock
wl(rwlock
);
2530 ret
= _op_cancel(tid
, r
);
2535 int Objecter::_op_cancel(ceph_tid_t tid
, int r
)
2539 ldout(cct
, 5) << __func__
<< ": cancelling tid " << tid
<< " r=" << r
2544 for (map
<int, OSDSession
*>::iterator siter
= osd_sessions
.begin();
2545 siter
!= osd_sessions
.end(); ++siter
) {
2546 OSDSession
*s
= siter
->second
;
2547 OSDSession::shared_lock
sl(s
->lock
);
2548 if (s
->ops
.find(tid
) != s
->ops
.end()) {
2550 ret
= op_cancel(s
, tid
, r
);
2551 if (ret
== -ENOENT
) {
2552 /* oh no! raced, maybe tid moved to another session, restarting */
2559 ldout(cct
, 5) << __func__
<< ": tid " << tid
2560 << " not found in live sessions" << dendl
;
2562 // Handle case where the op is in homeless session
2563 OSDSession::shared_lock
sl(homeless_session
->lock
);
2564 if (homeless_session
->ops
.find(tid
) != homeless_session
->ops
.end()) {
2566 ret
= op_cancel(homeless_session
, tid
, r
);
2567 if (ret
== -ENOENT
) {
2568 /* oh no! raced, maybe tid moved to another session, restarting */
2577 ldout(cct
, 5) << __func__
<< ": tid " << tid
2578 << " not found in homeless session" << dendl
;
2584 epoch_t
Objecter::op_cancel_writes(int r
, int64_t pool
)
2586 unique_lock
wl(rwlock
);
2588 std::vector
<ceph_tid_t
> to_cancel
;
2591 for (map
<int, OSDSession
*>::iterator siter
= osd_sessions
.begin();
2592 siter
!= osd_sessions
.end(); ++siter
) {
2593 OSDSession
*s
= siter
->second
;
2594 OSDSession::shared_lock
sl(s
->lock
);
2595 for (map
<ceph_tid_t
, Op
*>::iterator op_i
= s
->ops
.begin();
2596 op_i
!= s
->ops
.end(); ++op_i
) {
2597 if (op_i
->second
->target
.flags
& CEPH_OSD_FLAG_WRITE
2598 && (pool
== -1 || op_i
->second
->target
.target_oloc
.pool
== pool
)) {
2599 to_cancel
.push_back(op_i
->first
);
2604 for (std::vector
<ceph_tid_t
>::iterator titer
= to_cancel
.begin();
2605 titer
!= to_cancel
.end();
2607 int cancel_result
= op_cancel(s
, *titer
, r
);
2608 // We hold rwlock across search and cancellation, so cancels
2609 // should always succeed
2610 assert(cancel_result
== 0);
2612 if (!found
&& to_cancel
.size())
2617 const epoch_t epoch
= osdmap
->get_epoch();
2628 bool Objecter::is_pg_changed(
2630 const vector
<int>& oldacting
,
2632 const vector
<int>& newacting
,
2635 if (OSDMap::primary_changed(
2641 if (any_change
&& oldacting
!= newacting
)
2643 return false; // same primary (tho replicas may have changed)
2646 bool Objecter::target_should_be_paused(op_target_t
*t
)
2648 const pg_pool_t
*pi
= osdmap
->get_pg_pool(t
->base_oloc
.pool
);
2649 bool pauserd
= osdmap
->test_flag(CEPH_OSDMAP_PAUSERD
);
2650 bool pausewr
= osdmap
->test_flag(CEPH_OSDMAP_PAUSEWR
) ||
2651 _osdmap_full_flag() || _osdmap_pool_full(*pi
);
2653 return (t
->flags
& CEPH_OSD_FLAG_READ
&& pauserd
) ||
2654 (t
->flags
& CEPH_OSD_FLAG_WRITE
&& pausewr
) ||
2655 (osdmap
->get_epoch() < epoch_barrier
);
2659 * Locking public accessor for _osdmap_full_flag
2661 bool Objecter::osdmap_full_flag() const
2663 shared_lock
rl(rwlock
);
2665 return _osdmap_full_flag();
2668 bool Objecter::osdmap_pool_full(const int64_t pool_id
) const
2670 shared_lock
rl(rwlock
);
2672 if (_osdmap_full_flag()) {
2676 return _osdmap_pool_full(pool_id
);
2679 bool Objecter::_osdmap_pool_full(const int64_t pool_id
) const
2681 const pg_pool_t
*pool
= osdmap
->get_pg_pool(pool_id
);
2683 ldout(cct
, 4) << __func__
<< ": DNE pool " << pool_id
<< dendl
;
2687 return _osdmap_pool_full(*pool
);
2690 bool Objecter::_osdmap_has_pool_full() const
2692 for (map
<int64_t, pg_pool_t
>::const_iterator it
2693 = osdmap
->get_pools().begin();
2694 it
!= osdmap
->get_pools().end(); ++it
) {
2695 if (_osdmap_pool_full(it
->second
))
2701 bool Objecter::_osdmap_pool_full(const pg_pool_t
&p
) const
2703 return p
.has_flag(pg_pool_t::FLAG_FULL
) && honor_osdmap_full
;
2707 * Wrapper around osdmap->test_flag for special handling of the FULL flag.
2709 bool Objecter::_osdmap_full_flag() const
2711 // Ignore the FULL flag if the caller has honor_osdmap_full
2712 return osdmap
->test_flag(CEPH_OSDMAP_FULL
) && honor_osdmap_full
;
2715 void Objecter::update_pool_full_map(map
<int64_t, bool>& pool_full_map
)
2717 for (map
<int64_t, pg_pool_t
>::const_iterator it
2718 = osdmap
->get_pools().begin();
2719 it
!= osdmap
->get_pools().end(); ++it
) {
2720 if (pool_full_map
.find(it
->first
) == pool_full_map
.end()) {
2721 pool_full_map
[it
->first
] = _osdmap_pool_full(it
->second
);
2723 pool_full_map
[it
->first
] = _osdmap_pool_full(it
->second
) ||
2724 pool_full_map
[it
->first
];
2729 int64_t Objecter::get_object_hash_position(int64_t pool
, const string
& key
,
2732 shared_lock
rl(rwlock
);
2733 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
2736 return p
->hash_key(key
, ns
);
2739 int64_t Objecter::get_object_pg_hash_position(int64_t pool
, const string
& key
,
2742 shared_lock
rl(rwlock
);
2743 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
2746 return p
->raw_hash_to_pg(p
->hash_key(key
, ns
));
2749 int Objecter::_calc_target(op_target_t
*t
, Connection
*con
, bool any_change
)
2752 bool is_read
= t
->flags
& CEPH_OSD_FLAG_READ
;
2753 bool is_write
= t
->flags
& CEPH_OSD_FLAG_WRITE
;
2754 t
->epoch
= osdmap
->get_epoch();
2755 ldout(cct
,20) << __func__
<< " epoch " << t
->epoch
2756 << " base " << t
->base_oid
<< " " << t
->base_oloc
2757 << " precalc_pgid " << (int)t
->precalc_pgid
2758 << " pgid " << t
->base_pgid
2759 << (is_read
? " is_read" : "")
2760 << (is_write
? " is_write" : "")
2763 const pg_pool_t
*pi
= osdmap
->get_pg_pool(t
->base_oloc
.pool
);
2766 return RECALC_OP_TARGET_POOL_DNE
;
2768 ldout(cct
,30) << __func__
<< " base pi " << pi
2769 << " pg_num " << pi
->get_pg_num() << dendl
;
2771 bool force_resend
= false;
2772 if (osdmap
->get_epoch() == pi
->last_force_op_resend
) {
2773 if (t
->last_force_resend
< pi
->last_force_op_resend
) {
2774 t
->last_force_resend
= pi
->last_force_op_resend
;
2775 force_resend
= true;
2776 } else if (t
->last_force_resend
== 0) {
2777 force_resend
= true;
2782 t
->target_oid
= t
->base_oid
;
2783 t
->target_oloc
= t
->base_oloc
;
2784 if ((t
->flags
& CEPH_OSD_FLAG_IGNORE_OVERLAY
) == 0) {
2785 if (is_read
&& pi
->has_read_tier())
2786 t
->target_oloc
.pool
= pi
->read_tier
;
2787 if (is_write
&& pi
->has_write_tier())
2788 t
->target_oloc
.pool
= pi
->write_tier
;
2789 pi
= osdmap
->get_pg_pool(t
->target_oloc
.pool
);
2792 return RECALC_OP_TARGET_POOL_DNE
;
2797 if (t
->precalc_pgid
) {
2798 assert(t
->flags
& CEPH_OSD_FLAG_IGNORE_OVERLAY
);
2799 assert(t
->base_oid
.name
.empty()); // make sure this is a pg op
2800 assert(t
->base_oloc
.pool
== (int64_t)t
->base_pgid
.pool());
2801 pgid
= t
->base_pgid
;
2803 int ret
= osdmap
->object_locator_to_pg(t
->target_oid
, t
->target_oloc
,
2805 if (ret
== -ENOENT
) {
2807 return RECALC_OP_TARGET_POOL_DNE
;
2810 ldout(cct
,20) << __func__
<< " target " << t
->target_oid
<< " "
2811 << t
->target_oloc
<< " -> pgid " << pgid
<< dendl
;
2812 ldout(cct
,30) << __func__
<< " target pi " << pi
2813 << " pg_num " << pi
->get_pg_num() << dendl
;
2814 t
->pool_ever_existed
= true;
2816 int size
= pi
->size
;
2817 int min_size
= pi
->min_size
;
2818 unsigned pg_num
= pi
->get_pg_num();
2819 int up_primary
, acting_primary
;
2820 vector
<int> up
, acting
;
2821 osdmap
->pg_to_up_acting_osds(pgid
, &up
, &up_primary
,
2822 &acting
, &acting_primary
);
2823 bool sort_bitwise
= osdmap
->test_flag(CEPH_OSDMAP_SORTBITWISE
);
2824 unsigned prev_seed
= ceph_stable_mod(pgid
.ps(), t
->pg_num
, t
->pg_num_mask
);
2825 pg_t
prev_pgid(prev_seed
, pgid
.pool());
2826 if (any_change
&& PastIntervals::is_new_interval(
2844 force_resend
= true;
2847 bool unpaused
= false;
2848 if (t
->paused
&& !target_should_be_paused(t
)) {
2853 bool legacy_change
=
2856 t
->acting_primary
, t
->acting
, acting_primary
, acting
,
2857 t
->used_replica
|| any_change
);
2860 split
= prev_pgid
.is_split(t
->pg_num
, pg_num
, nullptr);
2863 if (legacy_change
|| split
|| force_resend
) {
2866 t
->acting_primary
= acting_primary
;
2867 t
->up_primary
= up_primary
;
2870 t
->min_size
= min_size
;
2872 t
->pg_num_mask
= pi
->get_pg_num_mask();
2873 osdmap
->get_primary_shard(
2874 pg_t(ceph_stable_mod(pgid
.ps(), t
->pg_num
, t
->pg_num_mask
), pgid
.pool()),
2876 t
->sort_bitwise
= sort_bitwise
;
2877 ldout(cct
, 10) << __func__
<< " "
2878 << " raw pgid " << pgid
<< " -> actual " << t
->actual_pgid
2879 << " acting " << acting
2880 << " primary " << acting_primary
<< dendl
;
2881 t
->used_replica
= false;
2882 if (acting_primary
== -1) {
2886 bool read
= is_read
&& !is_write
;
2887 if (read
&& (t
->flags
& CEPH_OSD_FLAG_BALANCE_READS
)) {
2888 int p
= rand() % acting
.size();
2890 t
->used_replica
= true;
2892 ldout(cct
, 10) << " chose random osd." << osd
<< " of " << acting
2894 } else if (read
&& (t
->flags
& CEPH_OSD_FLAG_LOCALIZE_READS
) &&
2895 acting
.size() > 1) {
2896 // look for a local replica. prefer the primary if the
2897 // distance is the same.
2899 int best_locality
= 0;
2900 for (unsigned i
= 0; i
< acting
.size(); ++i
) {
2901 int locality
= osdmap
->crush
->get_common_ancestor_distance(
2902 cct
, acting
[i
], crush_location
);
2903 ldout(cct
, 20) << __func__
<< " localize: rank " << i
2904 << " osd." << acting
[i
]
2905 << " locality " << locality
<< dendl
;
2907 (locality
>= 0 && best_locality
>= 0 &&
2908 locality
< best_locality
) ||
2909 (best_locality
< 0 && locality
>= 0)) {
2911 best_locality
= locality
;
2913 t
->used_replica
= true;
2919 osd
= acting_primary
;
2924 if (legacy_change
|| unpaused
|| force_resend
) {
2925 return RECALC_OP_TARGET_NEED_RESEND
;
2927 if (split
&& con
&& con
->has_features(CEPH_FEATUREMASK_RESEND_ON_SPLIT
)) {
2928 return RECALC_OP_TARGET_NEED_RESEND
;
2930 return RECALC_OP_TARGET_NO_ACTION
;
2933 int Objecter::_map_session(op_target_t
*target
, OSDSession
**s
,
2936 _calc_target(target
, nullptr);
2937 return _get_session(target
->osd
, s
, sul
);
2940 void Objecter::_session_op_assign(OSDSession
*to
, Op
*op
)
2942 // to->lock is locked
2943 assert(op
->session
== NULL
);
2948 to
->ops
[op
->tid
] = op
;
2950 if (to
->is_homeless()) {
2954 ldout(cct
, 15) << __func__
<< " " << to
->osd
<< " " << op
->tid
<< dendl
;
2957 void Objecter::_session_op_remove(OSDSession
*from
, Op
*op
)
2959 assert(op
->session
== from
);
2960 // from->lock is locked
2962 if (from
->is_homeless()) {
2966 from
->ops
.erase(op
->tid
);
2970 ldout(cct
, 15) << __func__
<< " " << from
->osd
<< " " << op
->tid
<< dendl
;
2973 void Objecter::_session_linger_op_assign(OSDSession
*to
, LingerOp
*op
)
2975 // to lock is locked unique
2976 assert(op
->session
== NULL
);
2978 if (to
->is_homeless()) {
2984 to
->linger_ops
[op
->linger_id
] = op
;
2986 ldout(cct
, 15) << __func__
<< " " << to
->osd
<< " " << op
->linger_id
2990 void Objecter::_session_linger_op_remove(OSDSession
*from
, LingerOp
*op
)
2992 assert(from
== op
->session
);
2993 // from->lock is locked unique
2995 if (from
->is_homeless()) {
2999 from
->linger_ops
.erase(op
->linger_id
);
3003 ldout(cct
, 15) << __func__
<< " " << from
->osd
<< " " << op
->linger_id
3007 void Objecter::_session_command_op_remove(OSDSession
*from
, CommandOp
*op
)
3009 assert(from
== op
->session
);
3010 // from->lock is locked
3012 if (from
->is_homeless()) {
3016 from
->command_ops
.erase(op
->tid
);
3020 ldout(cct
, 15) << __func__
<< " " << from
->osd
<< " " << op
->tid
<< dendl
;
3023 void Objecter::_session_command_op_assign(OSDSession
*to
, CommandOp
*op
)
3025 // to->lock is locked
3026 assert(op
->session
== NULL
);
3029 if (to
->is_homeless()) {
3035 to
->command_ops
[op
->tid
] = op
;
3037 ldout(cct
, 15) << __func__
<< " " << to
->osd
<< " " << op
->tid
<< dendl
;
3040 int Objecter::_recalc_linger_op_target(LingerOp
*linger_op
,
3043 // rwlock is locked unique
3045 int r
= _calc_target(&linger_op
->target
, nullptr, true);
3046 if (r
== RECALC_OP_TARGET_NEED_RESEND
) {
3047 ldout(cct
, 10) << "recalc_linger_op_target tid " << linger_op
->linger_id
3048 << " pgid " << linger_op
->target
.pgid
3049 << " acting " << linger_op
->target
.acting
<< dendl
;
3051 OSDSession
*s
= NULL
;
3052 r
= _get_session(linger_op
->target
.osd
, &s
, sul
);
3055 if (linger_op
->session
!= s
) {
3056 // NB locking two sessions (s and linger_op->session) at the
3057 // same time here is only safe because we are the only one that
3058 // takes two, and we are holding rwlock for write. Disable
3059 // lockdep because it doesn't know that.
3060 OSDSession::unique_lock
sl(s
->lock
);
3061 _session_linger_op_remove(linger_op
->session
, linger_op
);
3062 _session_linger_op_assign(s
, linger_op
);
3066 return RECALC_OP_TARGET_NEED_RESEND
;
3071 void Objecter::_cancel_linger_op(Op
*op
)
3073 ldout(cct
, 15) << "cancel_op " << op
->tid
<< dendl
;
3075 assert(!op
->should_resend
);
3077 delete op
->onfinish
;
3084 void Objecter::_finish_op(Op
*op
, int r
)
3086 ldout(cct
, 15) << "finish_op " << op
->tid
<< dendl
;
3088 // op->session->lock is locked unique or op->session is null
3090 if (!op
->ctx_budgeted
&& op
->budgeted
)
3093 if (op
->ontimeout
&& r
!= -ETIMEDOUT
)
3094 timer
.cancel_event(op
->ontimeout
);
3097 _session_op_remove(op
->session
, op
);
3100 logger
->dec(l_osdc_op_active
);
3102 assert(check_latest_map_ops
.find(op
->tid
) == check_latest_map_ops
.end());
3109 void Objecter::finish_op(OSDSession
*session
, ceph_tid_t tid
)
3111 ldout(cct
, 15) << "finish_op " << tid
<< dendl
;
3112 shared_lock
rl(rwlock
);
3114 OSDSession::unique_lock
wl(session
->lock
);
3116 map
<ceph_tid_t
, Op
*>::iterator iter
= session
->ops
.find(tid
);
3117 if (iter
== session
->ops
.end())
3120 Op
*op
= iter
->second
;
3125 MOSDOp
*Objecter::_prepare_osd_op(Op
*op
)
3129 int flags
= op
->target
.flags
;
3130 flags
|= CEPH_OSD_FLAG_KNOWN_REDIR
;
3132 // Nothing checks this any longer, but needed for compatibility with
3133 // pre-luminous osds
3134 flags
|= CEPH_OSD_FLAG_ONDISK
;
3136 if (!honor_osdmap_full
)
3137 flags
|= CEPH_OSD_FLAG_FULL_FORCE
;
3139 op
->target
.paused
= false;
3140 op
->stamp
= ceph::mono_clock::now();
3142 hobject_t hobj
= op
->target
.get_hobj();
3143 MOSDOp
*m
= new MOSDOp(client_inc
, op
->tid
,
3144 hobj
, op
->target
.actual_pgid
,
3145 osdmap
->get_epoch(),
3146 flags
, op
->features
);
3148 m
->set_snapid(op
->snapid
);
3149 m
->set_snap_seq(op
->snapc
.seq
);
3150 m
->set_snaps(op
->snapc
.snaps
);
3153 m
->set_mtime(op
->mtime
);
3154 m
->set_retry_attempt(op
->attempts
++);
3156 if (!op
->trace
.valid() && cct
->_conf
->osdc_blkin_trace_all
) {
3157 op
->trace
.init("op", &trace_endpoint
);
3161 m
->set_priority(op
->priority
);
3163 m
->set_priority(cct
->_conf
->osd_client_op_priority
);
3165 if (op
->reqid
!= osd_reqid_t()) {
3166 m
->set_reqid(op
->reqid
);
3169 logger
->inc(l_osdc_op_send
);
3170 logger
->inc(l_osdc_op_send_bytes
, m
->get_data().length());
3175 void Objecter::_send_op(Op
*op
, MOSDOp
*m
)
3178 // op->session->lock is locked
3181 hobject_t hoid
= op
->target
.get_hobj();
3182 auto p
= op
->session
->backoffs
.find(op
->target
.actual_pgid
);
3183 if (p
!= op
->session
->backoffs
.end()) {
3184 auto q
= p
->second
.lower_bound(hoid
);
3185 if (q
!= p
->second
.begin()) {
3187 if (hoid
>= q
->second
.end
) {
3191 if (q
!= p
->second
.end()) {
3192 ldout(cct
, 20) << __func__
<< " ? " << q
->first
<< " [" << q
->second
.begin
3193 << "," << q
->second
.end
<< ")" << dendl
;
3194 int r
= cmp(hoid
, q
->second
.begin
);
3195 if (r
== 0 || (r
> 0 && hoid
< q
->second
.end
)) {
3196 ldout(cct
, 10) << __func__
<< " backoff " << op
->target
.actual_pgid
3197 << " id " << q
->second
.id
<< " on " << hoid
3198 << ", queuing " << op
<< " tid " << op
->tid
<< dendl
;
3205 assert(op
->tid
> 0);
3206 m
= _prepare_osd_op(op
);
3209 if (op
->target
.actual_pgid
!= m
->get_spg()) {
3210 ldout(cct
, 10) << __func__
<< " " << op
->tid
<< " pgid change from "
3211 << m
->get_spg() << " to " << op
->target
.actual_pgid
3212 << ", updating and reencoding" << dendl
;
3213 m
->set_spg(op
->target
.actual_pgid
);
3214 m
->clear_payload(); // reencode
3217 ldout(cct
, 15) << "_send_op " << op
->tid
<< " to "
3218 << op
->target
.actual_pgid
<< " on osd." << op
->session
->osd
3221 ConnectionRef con
= op
->session
->con
;
3224 // preallocated rx buffer?
3226 ldout(cct
, 20) << " revoking rx buffer for " << op
->tid
<< " on "
3227 << op
->con
<< dendl
;
3228 op
->con
->revoke_rx_buffer(op
->tid
);
3231 op
->ontimeout
== 0 && // only post rx_buffer if no timeout; see #9582
3232 op
->outbl
->length()) {
3233 ldout(cct
, 20) << " posting rx buffer for " << op
->tid
<< " on " << con
3236 op
->con
->post_rx_buffer(op
->tid
, *op
->outbl
);
3239 op
->incarnation
= op
->session
->incarnation
;
3241 m
->set_tid(op
->tid
);
3243 if (op
->trace
.valid()) {
3244 m
->trace
.init("op msg", nullptr, &op
->trace
);
3246 op
->session
->con
->send_message(m
);
3249 int Objecter::calc_op_budget(Op
*op
)
3252 for (vector
<OSDOp
>::iterator i
= op
->ops
.begin();
3255 if (i
->op
.op
& CEPH_OSD_OP_MODE_WR
) {
3256 op_budget
+= i
->indata
.length();
3257 } else if (ceph_osd_op_mode_read(i
->op
.op
)) {
3258 if (ceph_osd_op_type_data(i
->op
.op
)) {
3259 if ((int64_t)i
->op
.extent
.length
> 0)
3260 op_budget
+= (int64_t)i
->op
.extent
.length
;
3261 } else if (ceph_osd_op_type_attr(i
->op
.op
)) {
3262 op_budget
+= i
->op
.xattr
.name_len
+ i
->op
.xattr
.value_len
;
3269 void Objecter::_throttle_op(Op
*op
,
3273 assert(sul
&& sul
.mutex() == &rwlock
);
3274 bool locked_for_write
= sul
.owns_lock();
3277 op_budget
= calc_op_budget(op
);
3278 if (!op_throttle_bytes
.get_or_fail(op_budget
)) { //couldn't take right now
3280 op_throttle_bytes
.get(op_budget
);
3281 if (locked_for_write
)
3286 if (!op_throttle_ops
.get_or_fail(1)) { //couldn't take right now
3288 op_throttle_ops
.get(1);
3289 if (locked_for_write
)
3296 void Objecter::unregister_op(Op
*op
)
3298 OSDSession::unique_lock
sl(op
->session
->lock
);
3299 op
->session
->ops
.erase(op
->tid
);
3301 put_session(op
->session
);
3307 /* This function DOES put the passed message before returning */
3308 void Objecter::handle_osd_op_reply(MOSDOpReply
*m
)
3310 ldout(cct
, 10) << "in handle_osd_op_reply" << dendl
;
3313 ceph_tid_t tid
= m
->get_tid();
3315 shunique_lock
sul(rwlock
, ceph::acquire_shared
);
3321 ConnectionRef con
= m
->get_connection();
3322 OSDSession
*s
= static_cast<OSDSession
*>(con
->get_priv());
3323 if (!s
|| s
->con
!= con
) {
3324 ldout(cct
, 7) << __func__
<< " no session on con " << con
<< dendl
;
3332 OSDSession::unique_lock
sl(s
->lock
);
3334 map
<ceph_tid_t
, Op
*>::iterator iter
= s
->ops
.find(tid
);
3335 if (iter
== s
->ops
.end()) {
3336 ldout(cct
, 7) << "handle_osd_op_reply " << tid
3337 << (m
->is_ondisk() ? " ondisk" : (m
->is_onnvram() ?
3338 " onnvram" : " ack"))
3339 << " ... stray" << dendl
;
3346 ldout(cct
, 7) << "handle_osd_op_reply " << tid
3347 << (m
->is_ondisk() ? " ondisk" :
3348 (m
->is_onnvram() ? " onnvram" : " ack"))
3349 << " uv " << m
->get_user_version()
3350 << " in " << m
->get_pg()
3351 << " attempt " << m
->get_retry_attempt()
3353 Op
*op
= iter
->second
;
3354 op
->trace
.event("osd op reply");
3356 if (retry_writes_after_first_reply
&& op
->attempts
== 1 &&
3357 (op
->target
.flags
& CEPH_OSD_FLAG_WRITE
)) {
3358 ldout(cct
, 7) << "retrying write after first reply: " << tid
<< dendl
;
3362 _session_op_remove(s
, op
);
3366 _op_submit(op
, sul
, NULL
);
3371 if (m
->get_retry_attempt() >= 0) {
3372 if (m
->get_retry_attempt() != (op
->attempts
- 1)) {
3373 ldout(cct
, 7) << " ignoring reply from attempt "
3374 << m
->get_retry_attempt()
3375 << " from " << m
->get_source_inst()
3376 << "; last attempt " << (op
->attempts
- 1) << " sent to "
3377 << op
->session
->con
->get_peer_addr() << dendl
;
3384 // we don't know the request attempt because the server is old, so
3385 // just accept this one. we may do ACK callbacks we shouldn't
3386 // have, but that is better than doing callbacks out of order.
3389 Context
*onfinish
= 0;
3391 int rc
= m
->get_result();
3393 if (m
->is_redirect_reply()) {
3394 ldout(cct
, 5) << " got redirect reply; redirecting" << dendl
;
3397 _session_op_remove(s
, op
);
3401 // FIXME: two redirects could race and reorder
3404 m
->get_redirect().combine_with_locator(op
->target
.target_oloc
,
3405 op
->target
.target_oid
.name
);
3406 op
->target
.flags
|= CEPH_OSD_FLAG_REDIRECTED
;
3407 _op_submit(op
, sul
, NULL
);
3412 if (rc
== -EAGAIN
) {
3413 ldout(cct
, 7) << " got -EAGAIN, resubmitting" << dendl
;
3415 if ((op
->target
.flags
& CEPH_OSD_FLAG_BALANCE_READS
)
3416 && (op
->target
.acting_primary
!= op
->target
.osd
)) {
3419 _session_op_remove(s
, op
);
3424 op
->target
.flags
&= ~CEPH_OSD_FLAG_BALANCE_READS
;
3425 op
->target
.pgid
= pg_t();
3426 _op_submit(op
, sul
, NULL
);
3432 s
->ops
.erase(op
->tid
);
3433 op
->tid
= ++last_tid
;
3445 *op
->objver
= m
->get_user_version();
3446 if (op
->reply_epoch
)
3447 *op
->reply_epoch
= m
->get_map_epoch();
3448 if (op
->data_offset
)
3449 *op
->data_offset
= m
->get_header().data_off
;
3454 op
->con
->revoke_rx_buffer(op
->tid
);
3455 m
->claim_data(*op
->outbl
);
3459 // per-op result demuxing
3460 vector
<OSDOp
> out_ops
;
3461 m
->claim_ops(out_ops
);
3463 if (out_ops
.size() != op
->ops
.size())
3464 ldout(cct
, 0) << "WARNING: tid " << op
->tid
<< " reply ops " << out_ops
3465 << " != request ops " << op
->ops
3466 << " from " << m
->get_source_inst() << dendl
;
3468 vector
<bufferlist
*>::iterator pb
= op
->out_bl
.begin();
3469 vector
<int*>::iterator pr
= op
->out_rval
.begin();
3470 vector
<Context
*>::iterator ph
= op
->out_handler
.begin();
3471 assert(op
->out_bl
.size() == op
->out_rval
.size());
3472 assert(op
->out_bl
.size() == op
->out_handler
.size());
3473 vector
<OSDOp
>::iterator p
= out_ops
.begin();
3474 for (unsigned i
= 0;
3475 p
!= out_ops
.end() && pb
!= op
->out_bl
.end();
3476 ++i
, ++p
, ++pb
, ++pr
, ++ph
) {
3477 ldout(cct
, 10) << " op " << i
<< " rval " << p
->rval
3478 << " len " << p
->outdata
.length() << dendl
;
3481 // set rval before running handlers so that handlers
3482 // can change it if e.g. decoding fails
3484 **pr
= ceph_to_hostos_errno(p
->rval
);
3486 ldout(cct
, 10) << " op " << i
<< " handler " << *ph
<< dendl
;
3487 (*ph
)->complete(ceph_to_hostos_errno(p
->rval
));
3492 // NOTE: we assume that since we only request ONDISK ever we will
3493 // only ever get back one (type of) ack ever.
3497 onfinish
= op
->onfinish
;
3498 op
->onfinish
= NULL
;
3500 logger
->inc(l_osdc_op_reply
);
3502 /* get it before we call _finish_op() */
3503 auto completion_lock
= s
->get_lock(op
->target
.base_oid
);
3505 ldout(cct
, 15) << "handle_osd_op_reply completed tid " << tid
<< dendl
;
3508 ldout(cct
, 5) << num_in_flight
<< " in flight" << dendl
;
3510 // serialize completions
3511 if (completion_lock
.mutex()) {
3512 completion_lock
.lock();
3518 onfinish
->complete(rc
);
3520 if (completion_lock
.mutex()) {
3521 completion_lock
.unlock();
3528 void Objecter::handle_osd_backoff(MOSDBackoff
*m
)
3530 ldout(cct
, 10) << __func__
<< " " << *m
<< dendl
;
3531 shunique_lock
sul(rwlock
, ceph::acquire_shared
);
3537 ConnectionRef con
= m
->get_connection();
3538 OSDSession
*s
= static_cast<OSDSession
*>(con
->get_priv());
3539 if (!s
|| s
->con
!= con
) {
3540 ldout(cct
, 7) << __func__
<< " no session on con " << con
<< dendl
;
3548 s
->put(); // from get_priv() above
3550 OSDSession::unique_lock
sl(s
->lock
);
3553 case CEPH_OSD_BACKOFF_OP_BLOCK
:
3556 OSDBackoff
& b
= s
->backoffs
[m
->pgid
][m
->begin
];
3557 s
->backoffs_by_id
.insert(make_pair(m
->id
, &b
));
3563 // ack with original backoff's epoch so that the osd can discard this if
3564 // there was a pg split.
3565 Message
*r
= new MOSDBackoff(m
->pgid
,
3567 CEPH_OSD_BACKOFF_OP_ACK_BLOCK
,
3568 m
->id
, m
->begin
, m
->end
);
3569 // this priority must match the MOSDOps from _prepare_osd_op
3570 r
->set_priority(cct
->_conf
->osd_client_op_priority
);
3571 con
->send_message(r
);
3575 case CEPH_OSD_BACKOFF_OP_UNBLOCK
:
3577 auto p
= s
->backoffs_by_id
.find(m
->id
);
3578 if (p
!= s
->backoffs_by_id
.end()) {
3579 OSDBackoff
*b
= p
->second
;
3580 if (b
->begin
!= m
->begin
&&
3582 lderr(cct
) << __func__
<< " got " << m
->pgid
<< " id " << m
->id
3584 << m
->begin
<< "," << m
->end
<< ") but backoff is ["
3585 << b
->begin
<< "," << b
->end
<< ")" << dendl
;
3586 // hrmpf, unblock it anyway.
3588 ldout(cct
, 10) << __func__
<< " unblock backoff " << b
->pgid
3590 << " [" << b
->begin
<< "," << b
->end
3592 auto spgp
= s
->backoffs
.find(b
->pgid
);
3593 assert(spgp
!= s
->backoffs
.end());
3594 spgp
->second
.erase(b
->begin
);
3595 if (spgp
->second
.empty()) {
3596 s
->backoffs
.erase(spgp
);
3598 s
->backoffs_by_id
.erase(p
);
3600 // check for any ops to resend
3601 for (auto& q
: s
->ops
) {
3602 if (q
.second
->target
.actual_pgid
== m
->pgid
) {
3603 int r
= q
.second
->target
.contained_by(m
->begin
, m
->end
);
3604 ldout(cct
, 20) << __func__
<< " contained_by " << r
<< " on "
3605 << q
.second
->target
.get_hobj() << dendl
;
3612 lderr(cct
) << __func__
<< " " << m
->pgid
<< " id " << m
->id
3614 << m
->begin
<< "," << m
->end
<< ") but backoff dne" << dendl
;
3620 ldout(cct
, 10) << __func__
<< " unrecognized op " << (int)m
->op
<< dendl
;
3630 uint32_t Objecter::list_nobjects_seek(NListContext
*list_context
,
3633 shared_lock
rl(rwlock
);
3634 list_context
->pos
= hobject_t(object_t(), string(), CEPH_NOSNAP
,
3635 pos
, list_context
->pool_id
, string());
3636 ldout(cct
, 10) << __func__
<< list_context
3637 << " pos " << pos
<< " -> " << list_context
->pos
<< dendl
;
3638 pg_t actual
= osdmap
->raw_pg_to_pg(pg_t(pos
, list_context
->pool_id
));
3639 list_context
->current_pg
= actual
.ps();
3640 list_context
->at_end_of_pool
= false;
3644 uint32_t Objecter::list_nobjects_seek(NListContext
*list_context
,
3645 const hobject_t
& cursor
)
3647 shared_lock
rl(rwlock
);
3648 ldout(cct
, 10) << "list_nobjects_seek " << list_context
<< dendl
;
3649 list_context
->pos
= cursor
;
3650 list_context
->at_end_of_pool
= false;
3651 pg_t actual
= osdmap
->raw_pg_to_pg(pg_t(cursor
.get_hash(), list_context
->pool_id
));
3652 list_context
->current_pg
= actual
.ps();
3653 list_context
->sort_bitwise
= true;
3654 return list_context
->current_pg
;
3657 void Objecter::list_nobjects_get_cursor(NListContext
*list_context
,
3660 shared_lock
rl(rwlock
);
3661 if (list_context
->list
.empty()) {
3662 *cursor
= list_context
->pos
;
3664 const librados::ListObjectImpl
& entry
= list_context
->list
.front();
3665 const string
*key
= (entry
.locator
.empty() ? &entry
.oid
: &entry
.locator
);
3666 uint32_t h
= osdmap
->get_pg_pool(list_context
->pool_id
)->hash_key(*key
, entry
.nspace
);
3667 *cursor
= hobject_t(entry
.oid
, entry
.locator
, list_context
->pool_snap_seq
, h
, list_context
->pool_id
, entry
.nspace
);
3671 void Objecter::list_nobjects(NListContext
*list_context
, Context
*onfinish
)
3673 ldout(cct
, 10) << __func__
<< " pool_id " << list_context
->pool_id
3674 << " pool_snap_seq " << list_context
->pool_snap_seq
3675 << " max_entries " << list_context
->max_entries
3676 << " list_context " << list_context
3677 << " onfinish " << onfinish
3678 << " current_pg " << list_context
->current_pg
3679 << " pos " << list_context
->pos
<< dendl
;
3681 shared_lock
rl(rwlock
);
3682 const pg_pool_t
*pool
= osdmap
->get_pg_pool(list_context
->pool_id
);
3683 if (!pool
) { // pool is gone
3685 put_nlist_context_budget(list_context
);
3686 onfinish
->complete(-ENOENT
);
3689 int pg_num
= pool
->get_pg_num();
3690 bool sort_bitwise
= osdmap
->test_flag(CEPH_OSDMAP_SORTBITWISE
);
3692 if (list_context
->pos
.is_min()) {
3693 list_context
->starting_pg_num
= 0;
3694 list_context
->sort_bitwise
= sort_bitwise
;
3695 list_context
->starting_pg_num
= pg_num
;
3697 if (list_context
->sort_bitwise
!= sort_bitwise
) {
3698 list_context
->pos
= hobject_t(
3699 object_t(), string(), CEPH_NOSNAP
,
3700 list_context
->current_pg
, list_context
->pool_id
, string());
3701 list_context
->sort_bitwise
= sort_bitwise
;
3702 ldout(cct
, 10) << " hobject sort order changed, restarting this pg at "
3703 << list_context
->pos
<< dendl
;
3705 if (list_context
->starting_pg_num
!= pg_num
) {
3706 if (!sort_bitwise
) {
3707 // start reading from the beginning; the pgs have changed
3708 ldout(cct
, 10) << " pg_num changed; restarting with " << pg_num
<< dendl
;
3709 list_context
->pos
= collection_list_handle_t();
3711 list_context
->starting_pg_num
= pg_num
;
3714 if (list_context
->pos
.is_max()) {
3715 ldout(cct
, 20) << __func__
<< " end of pool, list "
3716 << list_context
->list
<< dendl
;
3717 if (list_context
->list
.empty()) {
3718 list_context
->at_end_of_pool
= true;
3720 // release the listing context's budget once all
3721 // OPs (in the session) are finished
3722 put_nlist_context_budget(list_context
);
3723 onfinish
->complete(0);
3728 op
.pg_nls(list_context
->max_entries
, list_context
->filter
,
3729 list_context
->pos
, osdmap
->get_epoch());
3730 list_context
->bl
.clear();
3731 C_NList
*onack
= new C_NList(list_context
, onfinish
, this);
3732 object_locator_t
oloc(list_context
->pool_id
, list_context
->nspace
);
3734 // note current_pg in case we don't have (or lose) SORTBITWISE
3735 list_context
->current_pg
= pool
->raw_hash_to_pg(list_context
->pos
.get_hash());
3738 pg_read(list_context
->current_pg
, oloc
, op
,
3739 &list_context
->bl
, 0, onack
, &onack
->epoch
,
3740 &list_context
->ctx_budget
);
3743 void Objecter::_nlist_reply(NListContext
*list_context
, int r
,
3744 Context
*final_finish
, epoch_t reply_epoch
)
3746 ldout(cct
, 10) << __func__
<< " " << list_context
<< dendl
;
3748 bufferlist::iterator iter
= list_context
->bl
.begin();
3749 pg_nls_response_t response
;
3750 bufferlist extra_info
;
3751 ::decode(response
, iter
);
3753 ::decode(extra_info
, iter
);
3756 // if the osd returns 1 (newer code), or handle MAX, it means we
3757 // hit the end of the pg.
3758 if ((response
.handle
.is_max() || r
== 1) &&
3759 !list_context
->sort_bitwise
) {
3760 // legacy OSD and !sortbitwise, figure out the next PG on our own
3761 ++list_context
->current_pg
;
3762 if (list_context
->current_pg
== list_context
->starting_pg_num
) {
3764 list_context
->pos
= hobject_t::get_max();
3767 list_context
->pos
= hobject_t(object_t(), string(), CEPH_NOSNAP
,
3768 list_context
->current_pg
,
3769 list_context
->pool_id
, string());
3772 list_context
->pos
= response
.handle
;
3775 int response_size
= response
.entries
.size();
3776 ldout(cct
, 20) << " response.entries.size " << response_size
3777 << ", response.entries " << response
.entries
3778 << ", handle " << response
.handle
3779 << ", tentative new pos " << list_context
->pos
<< dendl
;
3780 list_context
->extra_info
.append(extra_info
);
3781 if (response_size
) {
3782 list_context
->list
.splice(list_context
->list
.end(), response
.entries
);
3785 if (list_context
->list
.size() >= list_context
->max_entries
) {
3786 ldout(cct
, 20) << " hit max, returning results so far, "
3787 << list_context
->list
<< dendl
;
3788 // release the listing context's budget once all
3789 // OPs (in the session) are finished
3790 put_nlist_context_budget(list_context
);
3791 final_finish
->complete(0);
3796 list_nobjects(list_context
, final_finish
);
3799 void Objecter::put_nlist_context_budget(NListContext
*list_context
)
3801 if (list_context
->ctx_budget
>= 0) {
3802 ldout(cct
, 10) << " release listing context's budget " <<
3803 list_context
->ctx_budget
<< dendl
;
3804 put_op_budget_bytes(list_context
->ctx_budget
);
3805 list_context
->ctx_budget
= -1;
3811 int Objecter::create_pool_snap(int64_t pool
, string
& snap_name
,
3814 unique_lock
wl(rwlock
);
3815 ldout(cct
, 10) << "create_pool_snap; pool: " << pool
<< "; snap: "
3816 << snap_name
<< dendl
;
3818 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
3821 if (p
->snap_exists(snap_name
.c_str()))
3824 PoolOp
*op
= new PoolOp
;
3827 op
->tid
= ++last_tid
;
3829 op
->name
= snap_name
;
3830 op
->onfinish
= onfinish
;
3831 op
->pool_op
= POOL_OP_CREATE_SNAP
;
3832 pool_ops
[op
->tid
] = op
;
3839 struct C_SelfmanagedSnap
: public Context
{
3843 C_SelfmanagedSnap(snapid_t
*ps
, Context
*f
) : psnapid(ps
), fin(f
) {}
3844 void finish(int r
) override
{
3846 bufferlist::iterator p
= bl
.begin();
3847 ::decode(*psnapid
, p
);
3853 int Objecter::allocate_selfmanaged_snap(int64_t pool
, snapid_t
*psnapid
,
3856 unique_lock
wl(rwlock
);
3857 ldout(cct
, 10) << "allocate_selfmanaged_snap; pool: " << pool
<< dendl
;
3858 PoolOp
*op
= new PoolOp
;
3859 if (!op
) return -ENOMEM
;
3860 op
->tid
= ++last_tid
;
3862 C_SelfmanagedSnap
*fin
= new C_SelfmanagedSnap(psnapid
, onfinish
);
3865 op
->pool_op
= POOL_OP_CREATE_UNMANAGED_SNAP
;
3866 pool_ops
[op
->tid
] = op
;
3872 int Objecter::delete_pool_snap(int64_t pool
, string
& snap_name
,
3875 unique_lock
wl(rwlock
);
3876 ldout(cct
, 10) << "delete_pool_snap; pool: " << pool
<< "; snap: "
3877 << snap_name
<< dendl
;
3879 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool
);
3882 if (!p
->snap_exists(snap_name
.c_str()))
3885 PoolOp
*op
= new PoolOp
;
3888 op
->tid
= ++last_tid
;
3890 op
->name
= snap_name
;
3891 op
->onfinish
= onfinish
;
3892 op
->pool_op
= POOL_OP_DELETE_SNAP
;
3893 pool_ops
[op
->tid
] = op
;
3900 int Objecter::delete_selfmanaged_snap(int64_t pool
, snapid_t snap
,
3903 unique_lock
wl(rwlock
);
3904 ldout(cct
, 10) << "delete_selfmanaged_snap; pool: " << pool
<< "; snap: "
3906 PoolOp
*op
= new PoolOp
;
3907 if (!op
) return -ENOMEM
;
3908 op
->tid
= ++last_tid
;
3910 op
->onfinish
= onfinish
;
3911 op
->pool_op
= POOL_OP_DELETE_UNMANAGED_SNAP
;
3913 pool_ops
[op
->tid
] = op
;
3920 int Objecter::create_pool(string
& name
, Context
*onfinish
, uint64_t auid
,
3923 unique_lock
wl(rwlock
);
3924 ldout(cct
, 10) << "create_pool name=" << name
<< dendl
;
3926 if (osdmap
->lookup_pg_pool_name(name
) >= 0)
3929 PoolOp
*op
= new PoolOp
;
3932 op
->tid
= ++last_tid
;
3935 op
->onfinish
= onfinish
;
3936 op
->pool_op
= POOL_OP_CREATE
;
3937 pool_ops
[op
->tid
] = op
;
3939 op
->crush_rule
= crush_rule
;
3946 int Objecter::delete_pool(int64_t pool
, Context
*onfinish
)
3948 unique_lock
wl(rwlock
);
3949 ldout(cct
, 10) << "delete_pool " << pool
<< dendl
;
3951 if (!osdmap
->have_pg_pool(pool
))
3954 _do_delete_pool(pool
, onfinish
);
3958 int Objecter::delete_pool(const string
&pool_name
, Context
*onfinish
)
3960 unique_lock
wl(rwlock
);
3961 ldout(cct
, 10) << "delete_pool " << pool_name
<< dendl
;
3963 int64_t pool
= osdmap
->lookup_pg_pool_name(pool_name
);
3967 _do_delete_pool(pool
, onfinish
);
3971 void Objecter::_do_delete_pool(int64_t pool
, Context
*onfinish
)
3973 PoolOp
*op
= new PoolOp
;
3974 op
->tid
= ++last_tid
;
3976 op
->name
= "delete";
3977 op
->onfinish
= onfinish
;
3978 op
->pool_op
= POOL_OP_DELETE
;
3979 pool_ops
[op
->tid
] = op
;
3984 * change the auid owner of a pool by contacting the monitor.
3985 * This requires the current connection to have write permissions
3986 * on both the pool's current auid and the new (parameter) auid.
3987 * Uses the standard Context callback when done.
3989 int Objecter::change_pool_auid(int64_t pool
, Context
*onfinish
, uint64_t auid
)
3991 unique_lock
wl(rwlock
);
3992 ldout(cct
, 10) << "change_pool_auid " << pool
<< " to " << auid
<< dendl
;
3993 PoolOp
*op
= new PoolOp
;
3994 if (!op
) return -ENOMEM
;
3995 op
->tid
= ++last_tid
;
3997 op
->name
= "change_pool_auid";
3998 op
->onfinish
= onfinish
;
3999 op
->pool_op
= POOL_OP_AUID_CHANGE
;
4001 pool_ops
[op
->tid
] = op
;
4003 logger
->set(l_osdc_poolop_active
, pool_ops
.size());
4009 void Objecter::pool_op_submit(PoolOp
*op
)
4012 if (mon_timeout
> timespan(0)) {
4013 op
->ontimeout
= timer
.add_event(mon_timeout
,
4015 pool_op_cancel(op
->tid
, -ETIMEDOUT
); });
4017 _pool_op_submit(op
);
4020 void Objecter::_pool_op_submit(PoolOp
*op
)
4022 // rwlock is locked unique
4024 ldout(cct
, 10) << "pool_op_submit " << op
->tid
<< dendl
;
4025 MPoolOp
*m
= new MPoolOp(monc
->get_fsid(), op
->tid
, op
->pool
,
4026 op
->name
, op
->pool_op
,
4027 op
->auid
, last_seen_osdmap_version
);
4028 if (op
->snapid
) m
->snapid
= op
->snapid
;
4029 if (op
->crush_rule
) m
->crush_rule
= op
->crush_rule
;
4030 monc
->send_mon_message(m
);
4031 op
->last_submit
= ceph::mono_clock::now();
4033 logger
->inc(l_osdc_poolop_send
);
4037 * Handle a reply to a PoolOp message. Check that we sent the message
4038 * and give the caller responsibility for the returned bufferlist.
4039 * Then either call the finisher or stash the PoolOp, depending on if we
4040 * have a new enough map.
4041 * Lastly, clean up the message and PoolOp.
4043 void Objecter::handle_pool_op_reply(MPoolOpReply
*m
)
4046 shunique_lock
sul(rwlock
, acquire_shared
);
4053 ldout(cct
, 10) << "handle_pool_op_reply " << *m
<< dendl
;
4054 ceph_tid_t tid
= m
->get_tid();
4055 map
<ceph_tid_t
, PoolOp
*>::iterator iter
= pool_ops
.find(tid
);
4056 if (iter
!= pool_ops
.end()) {
4057 PoolOp
*op
= iter
->second
;
4058 ldout(cct
, 10) << "have request " << tid
<< " at " << op
<< " Op: "
4059 << ceph_pool_op_name(op
->pool_op
) << dendl
;
4061 op
->blp
->claim(m
->response_data
);
4062 if (m
->version
> last_seen_osdmap_version
)
4063 last_seen_osdmap_version
= m
->version
;
4064 if (osdmap
->get_epoch() < m
->epoch
) {
4067 // recheck op existence since we have let go of rwlock
4068 // (for promotion) above.
4069 iter
= pool_ops
.find(tid
);
4070 if (iter
== pool_ops
.end())
4071 goto done
; // op is gone.
4072 if (osdmap
->get_epoch() < m
->epoch
) {
4073 ldout(cct
, 20) << "waiting for client to reach epoch " << m
->epoch
4074 << " before calling back" << dendl
;
4075 _wait_for_new_map(op
->onfinish
, m
->epoch
, m
->replyCode
);
4077 // map epoch changed, probably because a MOSDMap message
4078 // sneaked in. Do caller-specified callback now or else
4079 // we lose it forever.
4080 assert(op
->onfinish
);
4081 op
->onfinish
->complete(m
->replyCode
);
4084 assert(op
->onfinish
);
4085 op
->onfinish
->complete(m
->replyCode
);
4087 op
->onfinish
= NULL
;
4088 if (!sul
.owns_lock()) {
4092 iter
= pool_ops
.find(tid
);
4093 if (iter
!= pool_ops
.end()) {
4094 _finish_pool_op(op
, 0);
4097 ldout(cct
, 10) << "unknown request " << tid
<< dendl
;
4101 // Not strictly necessary, since we'll release it on return.
4104 ldout(cct
, 10) << "done" << dendl
;
4108 int Objecter::pool_op_cancel(ceph_tid_t tid
, int r
)
4110 assert(initialized
);
4112 unique_lock
wl(rwlock
);
4114 map
<ceph_tid_t
, PoolOp
*>::iterator it
= pool_ops
.find(tid
);
4115 if (it
== pool_ops
.end()) {
4116 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4120 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4122 PoolOp
*op
= it
->second
;
4124 op
->onfinish
->complete(r
);
4126 _finish_pool_op(op
, r
);
4130 void Objecter::_finish_pool_op(PoolOp
*op
, int r
)
4132 // rwlock is locked unique
4133 pool_ops
.erase(op
->tid
);
4134 logger
->set(l_osdc_poolop_active
, pool_ops
.size());
4136 if (op
->ontimeout
&& r
!= -ETIMEDOUT
) {
4137 timer
.cancel_event(op
->ontimeout
);
4145 void Objecter::get_pool_stats(list
<string
>& pools
,
4146 map
<string
,pool_stat_t
> *result
,
4149 ldout(cct
, 10) << "get_pool_stats " << pools
<< dendl
;
4151 PoolStatOp
*op
= new PoolStatOp
;
4152 op
->tid
= ++last_tid
;
4154 op
->pool_stats
= result
;
4155 op
->onfinish
= onfinish
;
4156 if (mon_timeout
> timespan(0)) {
4157 op
->ontimeout
= timer
.add_event(mon_timeout
,
4159 pool_stat_op_cancel(op
->tid
,
4165 unique_lock
wl(rwlock
);
4167 poolstat_ops
[op
->tid
] = op
;
4169 logger
->set(l_osdc_poolstat_active
, poolstat_ops
.size());
4171 _poolstat_submit(op
);
4174 void Objecter::_poolstat_submit(PoolStatOp
*op
)
4176 ldout(cct
, 10) << "_poolstat_submit " << op
->tid
<< dendl
;
4177 monc
->send_mon_message(new MGetPoolStats(monc
->get_fsid(), op
->tid
,
4179 last_seen_pgmap_version
));
4180 op
->last_submit
= ceph::mono_clock::now();
4182 logger
->inc(l_osdc_poolstat_send
);
4185 void Objecter::handle_get_pool_stats_reply(MGetPoolStatsReply
*m
)
4187 ldout(cct
, 10) << "handle_get_pool_stats_reply " << *m
<< dendl
;
4188 ceph_tid_t tid
= m
->get_tid();
4190 unique_lock
wl(rwlock
);
4196 map
<ceph_tid_t
, PoolStatOp
*>::iterator iter
= poolstat_ops
.find(tid
);
4197 if (iter
!= poolstat_ops
.end()) {
4198 PoolStatOp
*op
= poolstat_ops
[tid
];
4199 ldout(cct
, 10) << "have request " << tid
<< " at " << op
<< dendl
;
4200 *op
->pool_stats
= m
->pool_stats
;
4201 if (m
->version
> last_seen_pgmap_version
) {
4202 last_seen_pgmap_version
= m
->version
;
4204 op
->onfinish
->complete(0);
4205 _finish_pool_stat_op(op
, 0);
4207 ldout(cct
, 10) << "unknown request " << tid
<< dendl
;
4209 ldout(cct
, 10) << "done" << dendl
;
4213 int Objecter::pool_stat_op_cancel(ceph_tid_t tid
, int r
)
4215 assert(initialized
);
4217 unique_lock
wl(rwlock
);
4219 map
<ceph_tid_t
, PoolStatOp
*>::iterator it
= poolstat_ops
.find(tid
);
4220 if (it
== poolstat_ops
.end()) {
4221 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4225 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4227 PoolStatOp
*op
= it
->second
;
4229 op
->onfinish
->complete(r
);
4230 _finish_pool_stat_op(op
, r
);
4234 void Objecter::_finish_pool_stat_op(PoolStatOp
*op
, int r
)
4236 // rwlock is locked unique
4238 poolstat_ops
.erase(op
->tid
);
4239 logger
->set(l_osdc_poolstat_active
, poolstat_ops
.size());
4241 if (op
->ontimeout
&& r
!= -ETIMEDOUT
)
4242 timer
.cancel_event(op
->ontimeout
);
4247 void Objecter::get_fs_stats(ceph_statfs
& result
, Context
*onfinish
)
4249 ldout(cct
, 10) << "get_fs_stats" << dendl
;
4250 unique_lock
l(rwlock
);
4252 StatfsOp
*op
= new StatfsOp
;
4253 op
->tid
= ++last_tid
;
4254 op
->stats
= &result
;
4255 op
->onfinish
= onfinish
;
4256 if (mon_timeout
> timespan(0)) {
4257 op
->ontimeout
= timer
.add_event(mon_timeout
,
4259 statfs_op_cancel(op
->tid
,
4264 statfs_ops
[op
->tid
] = op
;
4266 logger
->set(l_osdc_statfs_active
, statfs_ops
.size());
4268 _fs_stats_submit(op
);
4271 void Objecter::_fs_stats_submit(StatfsOp
*op
)
4273 // rwlock is locked unique
4275 ldout(cct
, 10) << "fs_stats_submit" << op
->tid
<< dendl
;
4276 monc
->send_mon_message(new MStatfs(monc
->get_fsid(), op
->tid
,
4277 last_seen_pgmap_version
));
4278 op
->last_submit
= ceph::mono_clock::now();
4280 logger
->inc(l_osdc_statfs_send
);
4283 void Objecter::handle_fs_stats_reply(MStatfsReply
*m
)
4285 unique_lock
wl(rwlock
);
4291 ldout(cct
, 10) << "handle_fs_stats_reply " << *m
<< dendl
;
4292 ceph_tid_t tid
= m
->get_tid();
4294 if (statfs_ops
.count(tid
)) {
4295 StatfsOp
*op
= statfs_ops
[tid
];
4296 ldout(cct
, 10) << "have request " << tid
<< " at " << op
<< dendl
;
4297 *(op
->stats
) = m
->h
.st
;
4298 if (m
->h
.version
> last_seen_pgmap_version
)
4299 last_seen_pgmap_version
= m
->h
.version
;
4300 op
->onfinish
->complete(0);
4301 _finish_statfs_op(op
, 0);
4303 ldout(cct
, 10) << "unknown request " << tid
<< dendl
;
4306 ldout(cct
, 10) << "done" << dendl
;
4309 int Objecter::statfs_op_cancel(ceph_tid_t tid
, int r
)
4311 assert(initialized
);
4313 unique_lock
wl(rwlock
);
4315 map
<ceph_tid_t
, StatfsOp
*>::iterator it
= statfs_ops
.find(tid
);
4316 if (it
== statfs_ops
.end()) {
4317 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4321 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4323 StatfsOp
*op
= it
->second
;
4325 op
->onfinish
->complete(r
);
4326 _finish_statfs_op(op
, r
);
4330 void Objecter::_finish_statfs_op(StatfsOp
*op
, int r
)
4332 // rwlock is locked unique
4334 statfs_ops
.erase(op
->tid
);
4335 logger
->set(l_osdc_statfs_active
, statfs_ops
.size());
4337 if (op
->ontimeout
&& r
!= -ETIMEDOUT
)
4338 timer
.cancel_event(op
->ontimeout
);
4345 void Objecter::_sg_read_finish(vector
<ObjectExtent
>& extents
,
4346 vector
<bufferlist
>& resultbl
,
4347 bufferlist
*bl
, Context
*onfinish
)
4350 ldout(cct
, 15) << "_sg_read_finish" << dendl
;
4352 if (extents
.size() > 1) {
4353 Striper::StripedReadResult r
;
4354 vector
<bufferlist
>::iterator bit
= resultbl
.begin();
4355 for (vector
<ObjectExtent
>::iterator eit
= extents
.begin();
4356 eit
!= extents
.end();
4358 r
.add_partial_result(cct
, *bit
, eit
->buffer_extents
);
4361 r
.assemble_result(cct
, *bl
, false);
4363 ldout(cct
, 15) << " only one frag" << dendl
;
4364 bl
->claim(resultbl
[0]);
4368 uint64_t bytes_read
= bl
->length();
4369 ldout(cct
, 7) << "_sg_read_finish " << bytes_read
<< " bytes" << dendl
;
4372 onfinish
->complete(bytes_read
);// > 0 ? bytes_read:m->get_result());
4377 void Objecter::ms_handle_connect(Connection
*con
)
4379 ldout(cct
, 10) << "ms_handle_connect " << con
<< dendl
;
4383 if (con
->get_peer_type() == CEPH_ENTITY_TYPE_MON
)
4387 bool Objecter::ms_handle_reset(Connection
*con
)
4391 if (con
->get_peer_type() == CEPH_ENTITY_TYPE_OSD
) {
4392 OSDSession
*session
= static_cast<OSDSession
*>(con
->get_priv());
4394 ldout(cct
, 1) << "ms_handle_reset " << con
<< " session " << session
4395 << " osd." << session
->osd
<< dendl
;
4396 unique_lock
wl(rwlock
);
4401 map
<uint64_t, LingerOp
*> lresend
;
4402 OSDSession::unique_lock
sl(session
->lock
);
4403 _reopen_session(session
);
4404 _kick_requests(session
, lresend
);
4406 _linger_ops_resend(lresend
, wl
);
4408 maybe_request_map();
4416 void Objecter::ms_handle_remote_reset(Connection
*con
)
4419 * treat these the same.
4421 ms_handle_reset(con
);
4424 bool Objecter::ms_handle_refused(Connection
*con
)
4427 if (osdmap
&& (con
->get_peer_type() == CEPH_ENTITY_TYPE_OSD
)) {
4428 int osd
= osdmap
->identify_osd(con
->get_peer_addr());
4430 ldout(cct
, 1) << "ms_handle_refused on osd." << osd
<< dendl
;
4436 bool Objecter::ms_get_authorizer(int dest_type
,
4437 AuthAuthorizer
**authorizer
,
4442 if (dest_type
== CEPH_ENTITY_TYPE_MON
)
4444 *authorizer
= monc
->build_authorizer(dest_type
);
4445 return *authorizer
!= NULL
;
4448 void Objecter::op_target_t::dump(Formatter
*f
) const
4450 f
->dump_stream("pg") << pgid
;
4451 f
->dump_int("osd", osd
);
4452 f
->dump_stream("object_id") << base_oid
;
4453 f
->dump_stream("object_locator") << base_oloc
;
4454 f
->dump_stream("target_object_id") << target_oid
;
4455 f
->dump_stream("target_object_locator") << target_oloc
;
4456 f
->dump_int("paused", (int)paused
);
4457 f
->dump_int("used_replica", (int)used_replica
);
4458 f
->dump_int("precalc_pgid", (int)precalc_pgid
);
4461 void Objecter::_dump_active(OSDSession
*s
)
4463 for (map
<ceph_tid_t
,Op
*>::iterator p
= s
->ops
.begin();
4467 ldout(cct
, 20) << op
->tid
<< "\t" << op
->target
.pgid
4468 << "\tosd." << (op
->session
? op
->session
->osd
: -1)
4469 << "\t" << op
->target
.base_oid
4470 << "\t" << op
->ops
<< dendl
;
4474 void Objecter::_dump_active()
4476 ldout(cct
, 20) << "dump_active .. " << num_homeless_ops
<< " homeless"
4478 for (map
<int, OSDSession
*>::iterator siter
= osd_sessions
.begin();
4479 siter
!= osd_sessions
.end(); ++siter
) {
4480 OSDSession
*s
= siter
->second
;
4481 OSDSession::shared_lock
sl(s
->lock
);
4485 _dump_active(homeless_session
);
4488 void Objecter::dump_active()
4490 shared_lock
rl(rwlock
);
4495 void Objecter::dump_requests(Formatter
*fmt
)
4497 // Read-lock on Objecter held here
4498 fmt
->open_object_section("requests");
4500 dump_linger_ops(fmt
);
4502 dump_pool_stat_ops(fmt
);
4503 dump_statfs_ops(fmt
);
4504 dump_command_ops(fmt
);
4505 fmt
->close_section(); // requests object
4508 void Objecter::_dump_ops(const OSDSession
*s
, Formatter
*fmt
)
4510 for (map
<ceph_tid_t
,Op
*>::const_iterator p
= s
->ops
.begin();
4514 fmt
->open_object_section("op");
4515 fmt
->dump_unsigned("tid", op
->tid
);
4516 op
->target
.dump(fmt
);
4517 fmt
->dump_stream("last_sent") << op
->stamp
;
4518 fmt
->dump_int("attempts", op
->attempts
);
4519 fmt
->dump_stream("snapid") << op
->snapid
;
4520 fmt
->dump_stream("snap_context") << op
->snapc
;
4521 fmt
->dump_stream("mtime") << op
->mtime
;
4523 fmt
->open_array_section("osd_ops");
4524 for (vector
<OSDOp
>::const_iterator it
= op
->ops
.begin();
4525 it
!= op
->ops
.end();
4527 fmt
->dump_stream("osd_op") << *it
;
4529 fmt
->close_section(); // osd_ops array
4531 fmt
->close_section(); // op object
4535 void Objecter::dump_ops(Formatter
*fmt
)
4537 // Read-lock on Objecter held
4538 fmt
->open_array_section("ops");
4539 for (map
<int, OSDSession
*>::const_iterator siter
= osd_sessions
.begin();
4540 siter
!= osd_sessions
.end(); ++siter
) {
4541 OSDSession
*s
= siter
->second
;
4542 OSDSession::shared_lock
sl(s
->lock
);
4546 _dump_ops(homeless_session
, fmt
);
4547 fmt
->close_section(); // ops array
4550 void Objecter::_dump_linger_ops(const OSDSession
*s
, Formatter
*fmt
)
4552 for (map
<uint64_t, LingerOp
*>::const_iterator p
= s
->linger_ops
.begin();
4553 p
!= s
->linger_ops
.end();
4555 LingerOp
*op
= p
->second
;
4556 fmt
->open_object_section("linger_op");
4557 fmt
->dump_unsigned("linger_id", op
->linger_id
);
4558 op
->target
.dump(fmt
);
4559 fmt
->dump_stream("snapid") << op
->snap
;
4560 fmt
->dump_stream("registered") << op
->registered
;
4561 fmt
->close_section(); // linger_op object
4565 void Objecter::dump_linger_ops(Formatter
*fmt
)
4567 // We have a read-lock on the objecter
4568 fmt
->open_array_section("linger_ops");
4569 for (map
<int, OSDSession
*>::const_iterator siter
= osd_sessions
.begin();
4570 siter
!= osd_sessions
.end(); ++siter
) {
4571 OSDSession
*s
= siter
->second
;
4572 OSDSession::shared_lock
sl(s
->lock
);
4573 _dump_linger_ops(s
, fmt
);
4576 _dump_linger_ops(homeless_session
, fmt
);
4577 fmt
->close_section(); // linger_ops array
4580 void Objecter::_dump_command_ops(const OSDSession
*s
, Formatter
*fmt
)
4582 for (map
<uint64_t, CommandOp
*>::const_iterator p
= s
->command_ops
.begin();
4583 p
!= s
->command_ops
.end();
4585 CommandOp
*op
= p
->second
;
4586 fmt
->open_object_section("command_op");
4587 fmt
->dump_unsigned("command_id", op
->tid
);
4588 fmt
->dump_int("osd", op
->session
? op
->session
->osd
: -1);
4589 fmt
->open_array_section("command");
4590 for (vector
<string
>::const_iterator q
= op
->cmd
.begin();
4591 q
!= op
->cmd
.end(); ++q
)
4592 fmt
->dump_string("word", *q
);
4593 fmt
->close_section();
4594 if (op
->target_osd
>= 0)
4595 fmt
->dump_int("target_osd", op
->target_osd
);
4597 fmt
->dump_stream("target_pg") << op
->target_pg
;
4598 fmt
->close_section(); // command_op object
4602 void Objecter::dump_command_ops(Formatter
*fmt
)
4604 // We have a read-lock on the Objecter here
4605 fmt
->open_array_section("command_ops");
4606 for (map
<int, OSDSession
*>::const_iterator siter
= osd_sessions
.begin();
4607 siter
!= osd_sessions
.end(); ++siter
) {
4608 OSDSession
*s
= siter
->second
;
4609 OSDSession::shared_lock
sl(s
->lock
);
4610 _dump_command_ops(s
, fmt
);
4613 _dump_command_ops(homeless_session
, fmt
);
4614 fmt
->close_section(); // command_ops array
4617 void Objecter::dump_pool_ops(Formatter
*fmt
) const
4619 fmt
->open_array_section("pool_ops");
4620 for (map
<ceph_tid_t
, PoolOp
*>::const_iterator p
= pool_ops
.begin();
4621 p
!= pool_ops
.end();
4623 PoolOp
*op
= p
->second
;
4624 fmt
->open_object_section("pool_op");
4625 fmt
->dump_unsigned("tid", op
->tid
);
4626 fmt
->dump_int("pool", op
->pool
);
4627 fmt
->dump_string("name", op
->name
);
4628 fmt
->dump_int("operation_type", op
->pool_op
);
4629 fmt
->dump_unsigned("auid", op
->auid
);
4630 fmt
->dump_unsigned("crush_rule", op
->crush_rule
);
4631 fmt
->dump_stream("snapid") << op
->snapid
;
4632 fmt
->dump_stream("last_sent") << op
->last_submit
;
4633 fmt
->close_section(); // pool_op object
4635 fmt
->close_section(); // pool_ops array
4638 void Objecter::dump_pool_stat_ops(Formatter
*fmt
) const
4640 fmt
->open_array_section("pool_stat_ops");
4641 for (map
<ceph_tid_t
, PoolStatOp
*>::const_iterator p
= poolstat_ops
.begin();
4642 p
!= poolstat_ops
.end();
4644 PoolStatOp
*op
= p
->second
;
4645 fmt
->open_object_section("pool_stat_op");
4646 fmt
->dump_unsigned("tid", op
->tid
);
4647 fmt
->dump_stream("last_sent") << op
->last_submit
;
4649 fmt
->open_array_section("pools");
4650 for (list
<string
>::const_iterator it
= op
->pools
.begin();
4651 it
!= op
->pools
.end();
4653 fmt
->dump_string("pool", *it
);
4655 fmt
->close_section(); // pools array
4657 fmt
->close_section(); // pool_stat_op object
4659 fmt
->close_section(); // pool_stat_ops array
4662 void Objecter::dump_statfs_ops(Formatter
*fmt
) const
4664 fmt
->open_array_section("statfs_ops");
4665 for (map
<ceph_tid_t
, StatfsOp
*>::const_iterator p
= statfs_ops
.begin();
4666 p
!= statfs_ops
.end();
4668 StatfsOp
*op
= p
->second
;
4669 fmt
->open_object_section("statfs_op");
4670 fmt
->dump_unsigned("tid", op
->tid
);
4671 fmt
->dump_stream("last_sent") << op
->last_submit
;
4672 fmt
->close_section(); // statfs_op object
4674 fmt
->close_section(); // statfs_ops array
4677 Objecter::RequestStateHook::RequestStateHook(Objecter
*objecter
) :
4678 m_objecter(objecter
)
4682 bool Objecter::RequestStateHook::call(std::string command
, cmdmap_t
& cmdmap
,
4683 std::string format
, bufferlist
& out
)
4685 Formatter
*f
= Formatter::create(format
, "json-pretty", "json-pretty");
4686 shared_lock
rl(m_objecter
->rwlock
);
4687 m_objecter
->dump_requests(f
);
4693 void Objecter::blacklist_self(bool set
)
4695 ldout(cct
, 10) << "blacklist_self " << (set
? "add" : "rm") << dendl
;
4698 cmd
.push_back("{\"prefix\":\"osd blacklist\", ");
4700 cmd
.push_back("\"blacklistop\":\"add\",");
4702 cmd
.push_back("\"blacklistop\":\"rm\",");
4704 ss
<< messenger
->get_myaddr();
4705 cmd
.push_back("\"addr\":\"" + ss
.str() + "\"");
4707 MMonCommand
*m
= new MMonCommand(monc
->get_fsid());
4710 monc
->send_mon_message(m
);
4715 void Objecter::handle_command_reply(MCommandReply
*m
)
4717 unique_lock
wl(rwlock
);
4723 ConnectionRef con
= m
->get_connection();
4724 OSDSession
*s
= static_cast<OSDSession
*>(con
->get_priv());
4725 if (!s
|| s
->con
!= con
) {
4726 ldout(cct
, 7) << __func__
<< " no session on con " << con
<< dendl
;
4733 OSDSession::shared_lock
sl(s
->lock
);
4734 map
<ceph_tid_t
,CommandOp
*>::iterator p
= s
->command_ops
.find(m
->get_tid());
4735 if (p
== s
->command_ops
.end()) {
4736 ldout(cct
, 10) << "handle_command_reply tid " << m
->get_tid()
4737 << " not found" << dendl
;
4745 CommandOp
*c
= p
->second
;
4747 m
->get_connection() != c
->session
->con
) {
4748 ldout(cct
, 10) << "handle_command_reply tid " << m
->get_tid()
4749 << " got reply from wrong connection "
4750 << m
->get_connection() << " " << m
->get_source_inst()
4759 c
->poutbl
->claim(m
->get_data());
4765 _finish_command(c
, m
->r
, m
->rs
);
4771 void Objecter::submit_command(CommandOp
*c
, ceph_tid_t
*ptid
)
4773 shunique_lock
sul(rwlock
, ceph::acquire_unique
);
4775 ceph_tid_t tid
= ++last_tid
;
4776 ldout(cct
, 10) << "_submit_command " << tid
<< " " << c
->cmd
<< dendl
;
4780 OSDSession::unique_lock
hs_wl(homeless_session
->lock
);
4781 _session_command_op_assign(homeless_session
, c
);
4784 _calc_command_target(c
, sul
);
4785 _assign_command_session(c
, sul
);
4786 if (osd_timeout
> timespan(0)) {
4787 c
->ontimeout
= timer
.add_event(osd_timeout
,
4789 command_op_cancel(c
->session
, tid
,
4793 if (!c
->session
->is_homeless()) {
4796 _maybe_request_map();
4798 if (c
->map_check_error
)
4799 _send_command_map_check(c
);
4802 logger
->inc(l_osdc_command_active
);
4805 int Objecter::_calc_command_target(CommandOp
*c
, shunique_lock
& sul
)
4807 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
4809 c
->map_check_error
= 0;
4811 // ignore overlays, just like we do with pg ops
4812 c
->target
.flags
|= CEPH_OSD_FLAG_IGNORE_OVERLAY
;
4814 if (c
->target_osd
>= 0) {
4815 if (!osdmap
->exists(c
->target_osd
)) {
4816 c
->map_check_error
= -ENOENT
;
4817 c
->map_check_error_str
= "osd dne";
4819 return RECALC_OP_TARGET_OSD_DNE
;
4821 if (osdmap
->is_down(c
->target_osd
)) {
4822 c
->map_check_error
= -ENXIO
;
4823 c
->map_check_error_str
= "osd down";
4825 return RECALC_OP_TARGET_OSD_DOWN
;
4827 c
->target
.osd
= c
->target_osd
;
4829 int ret
= _calc_target(&(c
->target
), nullptr, true);
4830 if (ret
== RECALC_OP_TARGET_POOL_DNE
) {
4831 c
->map_check_error
= -ENOENT
;
4832 c
->map_check_error_str
= "pool dne";
4835 } else if (ret
== RECALC_OP_TARGET_OSD_DOWN
) {
4836 c
->map_check_error
= -ENXIO
;
4837 c
->map_check_error_str
= "osd down";
4844 int r
= _get_session(c
->target
.osd
, &s
, sul
);
4845 assert(r
!= -EAGAIN
); /* shouldn't happen as we're holding the write lock */
4847 if (c
->session
!= s
) {
4849 return RECALC_OP_TARGET_NEED_RESEND
;
4854 ldout(cct
, 20) << "_recalc_command_target " << c
->tid
<< " no change, "
4855 << c
->session
<< dendl
;
4857 return RECALC_OP_TARGET_NO_ACTION
;
4860 void Objecter::_assign_command_session(CommandOp
*c
,
4863 assert(sul
.owns_lock() && sul
.mutex() == &rwlock
);
4866 int r
= _get_session(c
->target
.osd
, &s
, sul
);
4867 assert(r
!= -EAGAIN
); /* shouldn't happen as we're holding the write lock */
4869 if (c
->session
!= s
) {
4871 OSDSession
*cs
= c
->session
;
4872 OSDSession::unique_lock
csl(cs
->lock
);
4873 _session_command_op_remove(c
->session
, c
);
4876 OSDSession::unique_lock
sl(s
->lock
);
4877 _session_command_op_assign(s
, c
);
4883 void Objecter::_send_command(CommandOp
*c
)
4885 ldout(cct
, 10) << "_send_command " << c
->tid
<< dendl
;
4887 assert(c
->session
->con
);
4888 MCommand
*m
= new MCommand(monc
->monmap
.fsid
);
4890 m
->set_data(c
->inbl
);
4892 c
->session
->con
->send_message(m
);
4893 logger
->inc(l_osdc_command_send
);
4896 int Objecter::command_op_cancel(OSDSession
*s
, ceph_tid_t tid
, int r
)
4898 assert(initialized
);
4900 unique_lock
wl(rwlock
);
4902 map
<ceph_tid_t
, CommandOp
*>::iterator it
= s
->command_ops
.find(tid
);
4903 if (it
== s
->command_ops
.end()) {
4904 ldout(cct
, 10) << __func__
<< " tid " << tid
<< " dne" << dendl
;
4908 ldout(cct
, 10) << __func__
<< " tid " << tid
<< dendl
;
4910 CommandOp
*op
= it
->second
;
4911 _command_cancel_map_check(op
);
4912 _finish_command(op
, r
, "");
4916 void Objecter::_finish_command(CommandOp
*c
, int r
, string rs
)
4918 // rwlock is locked unique
4920 ldout(cct
, 10) << "_finish_command " << c
->tid
<< " = " << r
<< " "
4925 c
->onfinish
->complete(r
);
4927 if (c
->ontimeout
&& r
!= -ETIMEDOUT
)
4928 timer
.cancel_event(c
->ontimeout
);
4930 OSDSession
*s
= c
->session
;
4931 OSDSession::unique_lock
sl(s
->lock
);
4932 _session_command_op_remove(c
->session
, c
);
4937 logger
->dec(l_osdc_command_active
);
4940 Objecter::OSDSession::~OSDSession()
4942 // Caller is responsible for re-assigning or
4943 // destroying any ops that were assigned to us
4944 assert(ops
.empty());
4945 assert(linger_ops
.empty());
4946 assert(command_ops
.empty());
4949 Objecter::~Objecter()
4953 assert(homeless_session
->get_nref() == 1);
4954 assert(num_homeless_ops
== 0);
4955 homeless_session
->put();
4957 assert(osd_sessions
.empty());
4958 assert(poolstat_ops
.empty());
4959 assert(statfs_ops
.empty());
4960 assert(pool_ops
.empty());
4961 assert(waiting_for_map
.empty());
4962 assert(linger_ops
.empty());
4963 assert(check_latest_map_lingers
.empty());
4964 assert(check_latest_map_ops
.empty());
4965 assert(check_latest_map_commands
.empty());
4967 assert(!m_request_state_hook
);
4972 * Wait until this OSD map epoch is received before
4973 * sending any more operations to OSDs. Use this
4974 * when it is known that the client can't trust
4975 * anything from before this epoch (e.g. due to
4976 * client blacklist at this epoch).
4978 void Objecter::set_epoch_barrier(epoch_t epoch
)
4980 unique_lock
wl(rwlock
);
4982 ldout(cct
, 7) << __func__
<< ": barrier " << epoch
<< " (was "
4983 << epoch_barrier
<< ") current epoch " << osdmap
->get_epoch()
4985 if (epoch
> epoch_barrier
) {
4986 epoch_barrier
= epoch
;
4987 _maybe_request_map();
4993 hobject_t
Objecter::enumerate_objects_begin()
4998 hobject_t
Objecter::enumerate_objects_end()
5000 return hobject_t::get_max();
5003 struct C_EnumerateReply
: public Context
{
5008 std::list
<librados::ListObjectImpl
> *result
;
5009 const hobject_t end
;
5010 const int64_t pool_id
;
5016 C_EnumerateReply(Objecter
*objecter_
, hobject_t
*next_
,
5017 std::list
<librados::ListObjectImpl
> *result_
,
5018 const hobject_t end_
, const int64_t pool_id_
, Context
*on_finish_
) :
5019 objecter(objecter_
), next(next_
), result(result_
),
5020 end(end_
), pool_id(pool_id_
), on_finish(on_finish_
),
5024 void finish(int r
) override
{
5025 objecter
->_enumerate_reply(
5026 bl
, r
, end
, pool_id
, budget
, epoch
, result
, next
, on_finish
);
5030 void Objecter::enumerate_objects(
5032 const std::string
&ns
,
5033 const hobject_t
&start
,
5034 const hobject_t
&end
,
5036 const bufferlist
&filter_bl
,
5037 std::list
<librados::ListObjectImpl
> *result
,
5043 if (!end
.is_max() && start
> end
) {
5044 lderr(cct
) << __func__
<< ": start " << start
<< " > end " << end
<< dendl
;
5045 on_finish
->complete(-EINVAL
);
5050 lderr(cct
) << __func__
<< ": result size may not be zero" << dendl
;
5051 on_finish
->complete(-EINVAL
);
5055 if (start
.is_max()) {
5056 on_finish
->complete(0);
5060 shared_lock
rl(rwlock
);
5061 assert(osdmap
->get_epoch());
5062 if (!osdmap
->test_flag(CEPH_OSDMAP_SORTBITWISE
)) {
5064 lderr(cct
) << __func__
<< ": SORTBITWISE cluster flag not set" << dendl
;
5065 on_finish
->complete(-EOPNOTSUPP
);
5068 const pg_pool_t
*p
= osdmap
->get_pg_pool(pool_id
);
5070 lderr(cct
) << __func__
<< ": pool " << pool_id
<< " DNE in osd epoch "
5071 << osdmap
->get_epoch() << dendl
;
5073 on_finish
->complete(-ENOENT
);
5079 ldout(cct
, 20) << __func__
<< ": start=" << start
<< " end=" << end
<< dendl
;
5081 // Stash completion state
5082 C_EnumerateReply
*on_ack
= new C_EnumerateReply(
5083 this, next
, result
, end
, pool_id
, on_finish
);
5086 op
.pg_nls(max
, filter_bl
, start
, 0);
5088 // Issue. See you later in _enumerate_reply
5089 object_locator_t
oloc(pool_id
, ns
);
5090 pg_read(start
.get_hash(), oloc
, op
,
5091 &on_ack
->bl
, 0, on_ack
, &on_ack
->epoch
, &on_ack
->budget
);
5094 void Objecter::_enumerate_reply(
5097 const hobject_t
&end
,
5098 const int64_t pool_id
,
5100 epoch_t reply_epoch
,
5101 std::list
<librados::ListObjectImpl
> *result
,
5106 put_op_budget_bytes(budget
);
5110 ldout(cct
, 4) << __func__
<< ": remote error " << r
<< dendl
;
5111 on_finish
->complete(r
);
5115 assert(next
!= NULL
);
5117 // Decode the results
5118 bufferlist::iterator iter
= bl
.begin();
5119 pg_nls_response_t response
;
5121 // XXX extra_info doesn't seem used anywhere?
5122 bufferlist extra_info
;
5123 ::decode(response
, iter
);
5125 ::decode(extra_info
, iter
);
5128 ldout(cct
, 10) << __func__
<< ": got " << response
.entries
.size()
5129 << " handle " << response
.handle
5130 << " reply_epoch " << reply_epoch
<< dendl
;
5131 ldout(cct
, 20) << __func__
<< ": response.entries.size "
5132 << response
.entries
.size() << ", response.entries "
5133 << response
.entries
<< dendl
;
5134 if (response
.handle
<= end
) {
5135 *next
= response
.handle
;
5137 ldout(cct
, 10) << __func__
<< ": adjusted next down to end " << end
5141 // drop anything after 'end'
5142 shared_lock
rl(rwlock
);
5143 const pg_pool_t
*pool
= osdmap
->get_pg_pool(pool_id
);
5145 // pool is gone, drop any results which are now meaningless.
5147 on_finish
->complete(-ENOENT
);
5150 while (!response
.entries
.empty()) {
5151 uint32_t hash
= response
.entries
.back().locator
.empty() ?
5152 pool
->hash_key(response
.entries
.back().oid
,
5153 response
.entries
.back().nspace
) :
5154 pool
->hash_key(response
.entries
.back().locator
,
5155 response
.entries
.back().nspace
);
5156 hobject_t
last(response
.entries
.back().oid
,
5157 response
.entries
.back().locator
,
5161 response
.entries
.back().nspace
);
5164 ldout(cct
, 20) << __func__
<< " dropping item " << last
5165 << " >= end " << end
<< dendl
;
5166 response
.entries
.pop_back();
5170 if (!response
.entries
.empty()) {
5171 result
->merge(response
.entries
);
5174 // release the listing context's budget once all
5175 // OPs (in the session) are finished
5177 put_nlist_context_budget(list_context
);
5179 on_finish
->complete(r
);
5184 using namespace librados
;
5186 template <typename T
>
5187 void do_decode(std::vector
<T
>& items
, std::vector
<bufferlist
>& bls
)
5189 for (auto bl
: bls
) {
5190 auto p
= bl
.begin();
5197 struct C_ObjectOperation_scrub_ls
: public Context
{
5200 std::vector
<inconsistent_obj_t
> *objects
= nullptr;
5201 std::vector
<inconsistent_snapset_t
> *snapsets
= nullptr;
5204 C_ObjectOperation_scrub_ls(uint32_t *interval
,
5205 std::vector
<inconsistent_obj_t
> *objects
,
5207 : interval(interval
), objects(objects
), rval(rval
) {}
5208 C_ObjectOperation_scrub_ls(uint32_t *interval
,
5209 std::vector
<inconsistent_snapset_t
> *snapsets
,
5211 : interval(interval
), snapsets(snapsets
), rval(rval
) {}
5212 void finish(int r
) override
{
5213 if (r
< 0 && r
!= -EAGAIN
) {
5224 } catch (buffer::error
&) {
5231 scrub_ls_result_t result
;
5232 auto p
= bl
.begin();
5234 *interval
= result
.interval
;
5236 do_decode(*objects
, result
.vals
);
5238 do_decode(*snapsets
, result
.vals
);
5243 template <typename T
>
5244 void do_scrub_ls(::ObjectOperation
*op
,
5245 const scrub_ls_arg_t
& arg
,
5246 std::vector
<T
> *items
,
5250 OSDOp
& osd_op
= op
->add_op(CEPH_OSD_OP_SCRUBLS
);
5251 op
->flags
|= CEPH_OSD_FLAG_PGOP
;
5253 arg
.encode(osd_op
.indata
);
5254 unsigned p
= op
->ops
.size() - 1;
5255 auto *h
= new C_ObjectOperation_scrub_ls
{interval
, items
, rval
};
5256 op
->out_handler
[p
] = h
;
5257 op
->out_bl
[p
] = &h
->bl
;
5258 op
->out_rval
[p
] = rval
;
5262 void ::ObjectOperation::scrub_ls(const librados::object_id_t
& start_after
,
5263 uint64_t max_to_get
,
5264 std::vector
<librados::inconsistent_obj_t
> *objects
,
5268 scrub_ls_arg_t arg
= {*interval
, 0, start_after
, max_to_get
};
5269 do_scrub_ls(this, arg
, objects
, interval
, rval
);
5272 void ::ObjectOperation::scrub_ls(const librados::object_id_t
& start_after
,
5273 uint64_t max_to_get
,
5274 std::vector
<librados::inconsistent_snapset_t
> *snapsets
,
5278 scrub_ls_arg_t arg
= {*interval
, 1, start_after
, max_to_get
};
5279 do_scrub_ls(this, arg
, snapsets
, interval
, rval
);