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>
7 * Copyright (C) 2013,2014 Cloudwatt <libre.licensing@cloudwatt.com>
8 * Copyright (C) 2014 Red Hat <contact@redhat.com>
10 * Author: Loic Dachary <loic@dachary.org>
12 * This is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License version 2.1, as published by the Free Software
15 * Foundation. See file COPYING.
20 #include <boost/algorithm/string.hpp>
24 #include "mon/OSDMonitor.h"
25 #include "mon/Monitor.h"
26 #include "mon/MDSMonitor.h"
27 #include "mon/PGMonitor.h"
28 #include "mon/MgrStatMonitor.h"
29 #include "mon/AuthMonitor.h"
30 #include "mon/ConfigKeyService.h"
32 #include "mon/MonitorDBStore.h"
33 #include "mon/Session.h"
35 #include "crush/CrushWrapper.h"
36 #include "crush/CrushTester.h"
37 #include "crush/CrushTreeDumper.h"
39 #include "messages/MOSDBeacon.h"
40 #include "messages/MOSDFailure.h"
41 #include "messages/MOSDMarkMeDown.h"
42 #include "messages/MOSDFull.h"
43 #include "messages/MOSDMap.h"
44 #include "messages/MMonGetOSDMap.h"
45 #include "messages/MOSDBoot.h"
46 #include "messages/MOSDAlive.h"
47 #include "messages/MPoolOp.h"
48 #include "messages/MPoolOpReply.h"
49 #include "messages/MOSDPGCreate.h"
50 #include "messages/MOSDPGCreated.h"
51 #include "messages/MOSDPGTemp.h"
52 #include "messages/MMonCommand.h"
53 #include "messages/MRemoveSnaps.h"
54 #include "messages/MOSDScrub.h"
55 #include "messages/MRoute.h"
57 #include "common/TextTable.h"
58 #include "common/Timer.h"
59 #include "common/ceph_argparse.h"
60 #include "common/perf_counters.h"
61 #include "common/strtol.h"
63 #include "common/config.h"
64 #include "common/errno.h"
66 #include "erasure-code/ErasureCodePlugin.h"
67 #include "compressor/Compressor.h"
68 #include "common/Checksummer.h"
70 #include "include/compat.h"
71 #include "include/assert.h"
72 #include "include/stringify.h"
73 #include "include/util.h"
74 #include "common/cmdparse.h"
75 #include "include/str_list.h"
76 #include "include/str_map.h"
77 #include "include/scope_guard.h"
79 #include "json_spirit/json_spirit_reader.h"
81 #include <boost/algorithm/string/predicate.hpp>
83 #define dout_subsys ceph_subsys_mon
84 #define OSD_PG_CREATING_PREFIX "osd_pg_creating"
88 const uint32_t MAX_POOL_APPLICATIONS
= 4;
89 const uint32_t MAX_POOL_APPLICATION_KEYS
= 64;
90 const uint32_t MAX_POOL_APPLICATION_LENGTH
= 128;
92 } // anonymous namespace
94 void LastEpochClean::Lec::report(ps_t ps
, epoch_t last_epoch_clean
)
96 if (epoch_by_pg
.size() <= ps
) {
97 epoch_by_pg
.resize(ps
+ 1, 0);
99 const auto old_lec
= epoch_by_pg
[ps
];
100 if (old_lec
>= last_epoch_clean
) {
104 epoch_by_pg
[ps
] = last_epoch_clean
;
105 if (last_epoch_clean
< floor
) {
106 floor
= last_epoch_clean
;
107 } else if (last_epoch_clean
> floor
) {
108 if (old_lec
== floor
) {
109 // probably should increase floor?
110 auto new_floor
= std::min_element(std::begin(epoch_by_pg
),
111 std::end(epoch_by_pg
));
115 if (ps
!= next_missing
) {
118 for (; next_missing
< epoch_by_pg
.size(); next_missing
++) {
119 if (epoch_by_pg
[next_missing
] == 0) {
125 void LastEpochClean::remove_pool(uint64_t pool
)
127 report_by_pool
.erase(pool
);
130 void LastEpochClean::report(const pg_t
& pg
, epoch_t last_epoch_clean
)
132 auto& lec
= report_by_pool
[pg
.pool()];
133 return lec
.report(pg
.ps(), last_epoch_clean
);
136 epoch_t
LastEpochClean::get_lower_bound(const OSDMap
& latest
) const
138 auto floor
= latest
.get_epoch();
139 for (auto& pool
: latest
.get_pools()) {
140 auto reported
= report_by_pool
.find(pool
.first
);
141 if (reported
== report_by_pool
.end()) {
144 if (reported
->second
.next_missing
< pool
.second
.get_pg_num()) {
147 if (reported
->second
.floor
< floor
) {
148 floor
= reported
->second
.floor
;
155 struct C_UpdateCreatingPGs
: public Context
{
159 C_UpdateCreatingPGs(OSDMonitor
*osdmon
, epoch_t e
) :
160 osdmon(osdmon
), start(ceph_clock_now()), epoch(e
) {}
161 void finish(int r
) override
{
163 utime_t end
= ceph_clock_now();
164 dout(10) << "osdmap epoch " << epoch
<< " mapping took "
165 << (end
- start
) << " seconds" << dendl
;
166 osdmon
->update_creating_pgs();
167 osdmon
->check_pg_creates_subs();
173 #define dout_prefix _prefix(_dout, mon, osdmap)
174 static ostream
& _prefix(std::ostream
*_dout
, Monitor
*mon
, const OSDMap
& osdmap
) {
175 return *_dout
<< "mon." << mon
->name
<< "@" << mon
->rank
176 << "(" << mon
->get_state_name()
177 << ").osd e" << osdmap
.get_epoch() << " ";
180 OSDMonitor::OSDMonitor(
184 const string
& service_name
)
185 : PaxosService(mn
, p
, service_name
),
187 inc_osd_cache(g_conf
->mon_osd_cache_size
),
188 full_osd_cache(g_conf
->mon_osd_cache_size
),
189 last_attempted_minwait_time(utime_t()),
190 mapper(mn
->cct
, &mn
->cpu_tp
),
191 op_tracker(cct
, true, 1)
194 bool OSDMonitor::_have_pending_crush()
196 return pending_inc
.crush
.length() > 0;
199 CrushWrapper
&OSDMonitor::_get_stable_crush()
201 return *osdmap
.crush
;
204 void OSDMonitor::_get_pending_crush(CrushWrapper
& newcrush
)
207 if (pending_inc
.crush
.length())
208 bl
= pending_inc
.crush
;
210 osdmap
.crush
->encode(bl
, CEPH_FEATURES_SUPPORTED_DEFAULT
);
212 bufferlist::iterator p
= bl
.begin();
216 void OSDMonitor::create_initial()
218 dout(10) << "create_initial for " << mon
->monmap
->fsid
<< dendl
;
223 mon
->store
->get("mkfs", "osdmap", bl
);
227 newmap
.set_fsid(mon
->monmap
->fsid
);
229 newmap
.build_simple(g_ceph_context
, 0, mon
->monmap
->fsid
, 0);
232 newmap
.created
= newmap
.modified
= ceph_clock_now();
234 // new clusters should sort bitwise by default.
235 newmap
.set_flag(CEPH_OSDMAP_SORTBITWISE
);
237 // new cluster should require latest by default
238 if (g_conf
->mon_debug_no_require_luminous
) {
239 newmap
.require_osd_release
= CEPH_RELEASE_KRAKEN
;
240 derr
<< __func__
<< " mon_debug_no_require_luminous=true" << dendl
;
242 newmap
.require_osd_release
= CEPH_RELEASE_LUMINOUS
;
243 newmap
.flags
|= CEPH_OSDMAP_RECOVERY_DELETES
;
244 newmap
.full_ratio
= g_conf
->mon_osd_full_ratio
;
245 if (newmap
.full_ratio
> 1.0) newmap
.full_ratio
/= 100;
246 newmap
.backfillfull_ratio
= g_conf
->mon_osd_backfillfull_ratio
;
247 if (newmap
.backfillfull_ratio
> 1.0) newmap
.backfillfull_ratio
/= 100;
248 newmap
.nearfull_ratio
= g_conf
->mon_osd_nearfull_ratio
;
249 if (newmap
.nearfull_ratio
> 1.0) newmap
.nearfull_ratio
/= 100;
250 int r
= ceph_release_from_name(
251 g_conf
->mon_osd_initial_require_min_compat_client
.c_str());
253 assert(0 == "mon_osd_initial_require_min_compat_client is not valid");
255 newmap
.require_min_compat_client
= r
;
258 // encode into pending incremental
259 newmap
.encode(pending_inc
.fullmap
,
260 mon
->get_quorum_con_features() | CEPH_FEATURE_RESERVED
);
261 pending_inc
.full_crc
= newmap
.get_crc();
262 dout(20) << " full crc " << pending_inc
.full_crc
<< dendl
;
265 void OSDMonitor::get_store_prefixes(std::set
<string
>& s
)
267 s
.insert(service_name
);
268 s
.insert(OSD_PG_CREATING_PREFIX
);
271 void OSDMonitor::update_from_paxos(bool *need_bootstrap
)
273 version_t version
= get_last_committed();
274 if (version
== osdmap
.epoch
)
276 assert(version
> osdmap
.epoch
);
278 dout(15) << "update_from_paxos paxos e " << version
279 << ", my e " << osdmap
.epoch
<< dendl
;
282 if (!mapping_job
->is_done()) {
283 dout(1) << __func__
<< " mapping job "
284 << mapping_job
.get() << " did not complete, "
285 << mapping_job
->shards
<< " left, canceling" << dendl
;
286 mapping_job
->abort();
294 * We will possibly have a stashed latest that *we* wrote, and we will
295 * always be sure to have the oldest full map in the first..last range
296 * due to encode_trim_extra(), which includes the oldest full map in the trim
299 * encode_trim_extra() does not however write the full map's
300 * version to 'full_latest'. This is only done when we are building the
301 * full maps from the incremental versions. But don't panic! We make sure
302 * that the following conditions find whichever full map version is newer.
304 version_t latest_full
= get_version_latest_full();
305 if (latest_full
== 0 && get_first_committed() > 1)
306 latest_full
= get_first_committed();
308 if (get_first_committed() > 1 &&
309 latest_full
< get_first_committed()) {
310 // the monitor could be just sync'ed with its peer, and the latest_full key
311 // is not encoded in the paxos commits in encode_pending(), so we need to
312 // make sure we get it pointing to a proper version.
313 version_t lc
= get_last_committed();
314 version_t fc
= get_first_committed();
316 dout(10) << __func__
<< " looking for valid full map in interval"
317 << " [" << fc
<< ", " << lc
<< "]" << dendl
;
320 for (version_t v
= lc
; v
>= fc
; v
--) {
321 string full_key
= "full_" + stringify(v
);
322 if (mon
->store
->exists(get_service_name(), full_key
)) {
323 dout(10) << __func__
<< " found latest full map v " << v
<< dendl
;
329 assert(latest_full
> 0);
330 auto t(std::make_shared
<MonitorDBStore::Transaction
>());
331 put_version_latest_full(t
, latest_full
);
332 mon
->store
->apply_transaction(t
);
333 dout(10) << __func__
<< " updated the on-disk full map version to "
334 << latest_full
<< dendl
;
337 if ((latest_full
> 0) && (latest_full
> osdmap
.epoch
)) {
338 bufferlist latest_bl
;
339 get_version_full(latest_full
, latest_bl
);
340 assert(latest_bl
.length() != 0);
341 dout(7) << __func__
<< " loading latest full map e" << latest_full
<< dendl
;
342 osdmap
.decode(latest_bl
);
345 if (mon
->monmap
->get_required_features().contains_all(
346 ceph::features::mon::FEATURE_LUMINOUS
)) {
348 if (!mon
->store
->get(OSD_PG_CREATING_PREFIX
, "creating", bl
)) {
350 std::lock_guard
<std::mutex
> l(creating_pgs_lock
);
351 creating_pgs
.decode(p
);
352 dout(7) << __func__
<< " loading creating_pgs last_scan_epoch "
353 << creating_pgs
.last_scan_epoch
354 << " with " << creating_pgs
.pgs
.size() << " pgs" << dendl
;
356 dout(1) << __func__
<< " missing creating pgs; upgrade from post-kraken?"
361 // make sure we're using the right pg service.. remove me post-luminous!
362 if (osdmap
.require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
363 dout(10) << __func__
<< " pgservice is mgrstat" << dendl
;
364 mon
->pgservice
= mon
->mgrstatmon()->get_pg_stat_service();
366 dout(10) << __func__
<< " pgservice is pg" << dendl
;
367 mon
->pgservice
= mon
->pgmon()->get_pg_stat_service();
370 // walk through incrementals
371 MonitorDBStore::TransactionRef t
;
373 while (version
> osdmap
.epoch
) {
375 int err
= get_version(osdmap
.epoch
+1, inc_bl
);
377 assert(inc_bl
.length());
379 dout(7) << "update_from_paxos applying incremental " << osdmap
.epoch
+1
381 OSDMap::Incremental
inc(inc_bl
);
382 err
= osdmap
.apply_incremental(inc
);
386 t
.reset(new MonitorDBStore::Transaction
);
388 // Write out the full map for all past epochs. Encode the full
389 // map with the same features as the incremental. If we don't
390 // know, use the quorum features. If we don't know those either,
391 // encode with all features.
392 uint64_t f
= inc
.encode_features
;
394 f
= mon
->get_quorum_con_features();
398 osdmap
.encode(full_bl
, f
| CEPH_FEATURE_RESERVED
);
399 tx_size
+= full_bl
.length();
401 bufferlist orig_full_bl
;
402 get_version_full(osdmap
.epoch
, orig_full_bl
);
403 if (orig_full_bl
.length()) {
404 // the primary provided the full map
405 assert(inc
.have_crc
);
406 if (inc
.full_crc
!= osdmap
.crc
) {
407 // This will happen if the mons were running mixed versions in
408 // the past or some other circumstance made the full encoded
409 // maps divergent. Reloading here will bring us back into
410 // sync with the primary for this and all future maps. OSDs
411 // will also be brought back into sync when they discover the
412 // crc mismatch and request a full map from a mon.
413 derr
<< __func__
<< " full map CRC mismatch, resetting to canonical"
416 osdmap
.decode(orig_full_bl
);
419 assert(!inc
.have_crc
);
420 put_version_full(t
, osdmap
.epoch
, full_bl
);
422 put_version_latest_full(t
, osdmap
.epoch
);
425 dout(1) << osdmap
<< dendl
;
427 if (osdmap
.epoch
== 1) {
428 t
->erase("mkfs", "osdmap");
431 // make sure we're using the right pg service.. remove me post-luminous!
432 if (osdmap
.require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
433 dout(10) << __func__
<< " pgservice is mgrstat" << dendl
;
434 mon
->pgservice
= mon
->mgrstatmon()->get_pg_stat_service();
436 dout(10) << __func__
<< " pgservice is pg" << dendl
;
437 mon
->pgservice
= mon
->pgmon()->get_pg_stat_service();
440 if (tx_size
> g_conf
->mon_sync_max_payload_size
*2) {
441 mon
->store
->apply_transaction(t
);
442 t
= MonitorDBStore::TransactionRef();
445 if (mon
->monmap
->get_required_features().contains_all(
446 ceph::features::mon::FEATURE_LUMINOUS
)) {
447 for (const auto &osd_state
: inc
.new_state
) {
448 if (osd_state
.second
& CEPH_OSD_UP
) {
449 // could be marked up *or* down, but we're too lazy to check which
450 last_osd_report
.erase(osd_state
.first
);
452 if (osd_state
.second
& CEPH_OSD_EXISTS
) {
453 // could be created *or* destroyed, but we can safely drop it
454 osd_epochs
.erase(osd_state
.first
);
461 mon
->store
->apply_transaction(t
);
464 for (int o
= 0; o
< osdmap
.get_max_osd(); o
++) {
465 if (osdmap
.is_out(o
))
467 auto found
= down_pending_out
.find(o
);
468 if (osdmap
.is_down(o
)) {
469 // populate down -> out map
470 if (found
== down_pending_out
.end()) {
471 dout(10) << " adding osd." << o
<< " to down_pending_out map" << dendl
;
472 down_pending_out
[o
] = ceph_clock_now();
475 if (found
!= down_pending_out
.end()) {
476 dout(10) << " removing osd." << o
<< " from down_pending_out map" << dendl
;
477 down_pending_out
.erase(found
);
481 // XXX: need to trim MonSession connected with a osd whose id > max_osd?
483 if (mon
->is_leader()) {
484 // kick pgmon, make sure it's seen the latest map
485 mon
->pgmon()->check_osd_map(osdmap
.epoch
);
489 check_pg_creates_subs();
491 share_map_with_random_osd();
496 // make sure our feature bits reflect the latest map
497 update_msgr_features();
499 if (!mon
->is_leader()) {
500 // will be called by on_active() on the leader, avoid doing so twice
505 void OSDMonitor::start_mapping()
507 // initiate mapping job
509 dout(10) << __func__
<< " canceling previous mapping_job " << mapping_job
.get()
511 mapping_job
->abort();
513 if (!osdmap
.get_pools().empty()) {
514 auto fin
= new C_UpdateCreatingPGs(this, osdmap
.get_epoch());
515 mapping_job
= mapping
.start_update(osdmap
, mapper
,
516 g_conf
->mon_osd_mapping_pgs_per_chunk
);
517 dout(10) << __func__
<< " started mapping job " << mapping_job
.get()
518 << " at " << fin
->start
<< dendl
;
519 mapping_job
->set_finish_event(fin
);
521 dout(10) << __func__
<< " no pools, no mapping job" << dendl
;
522 mapping_job
= nullptr;
526 void OSDMonitor::update_msgr_features()
529 types
.insert((int)entity_name_t::TYPE_OSD
);
530 types
.insert((int)entity_name_t::TYPE_CLIENT
);
531 types
.insert((int)entity_name_t::TYPE_MDS
);
532 types
.insert((int)entity_name_t::TYPE_MON
);
533 for (set
<int>::iterator q
= types
.begin(); q
!= types
.end(); ++q
) {
535 uint64_t features
= osdmap
.get_features(*q
, &mask
);
536 if ((mon
->messenger
->get_policy(*q
).features_required
& mask
) != features
) {
537 dout(0) << "crush map has features " << features
<< ", adjusting msgr requires" << dendl
;
538 Messenger::Policy p
= mon
->messenger
->get_policy(*q
);
539 p
.features_required
= (p
.features_required
& ~mask
) | features
;
540 mon
->messenger
->set_policy(*q
, p
);
545 void OSDMonitor::on_active()
549 if (mon
->is_leader()) {
550 mon
->clog
->debug() << "osdmap " << osdmap
;
552 list
<MonOpRequestRef
> ls
;
553 take_all_failures(ls
);
554 while (!ls
.empty()) {
555 MonOpRequestRef op
= ls
.front();
556 op
->mark_osdmon_event(__func__
);
564 void OSDMonitor::on_restart()
566 last_osd_report
.clear();
568 if (mon
->is_leader()) {
569 // fix ruleset != ruleid
570 if (osdmap
.crush
->has_legacy_rulesets() &&
571 !osdmap
.crush
->has_multirule_rulesets()) {
572 CrushWrapper newcrush
;
573 _get_pending_crush(newcrush
);
574 int r
= newcrush
.renumber_rules_by_ruleset();
576 dout(1) << __func__
<< " crush map has ruleset != rule id; fixing" << dendl
;
577 pending_inc
.crush
.clear();
578 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
580 dout(10) << __func__
<< " unable to renumber rules by ruleset" << dendl
;
586 void OSDMonitor::on_shutdown()
588 dout(10) << __func__
<< dendl
;
590 dout(10) << __func__
<< " canceling previous mapping_job " << mapping_job
.get()
592 mapping_job
->abort();
595 // discard failure info, waiters
596 list
<MonOpRequestRef
> ls
;
597 take_all_failures(ls
);
601 void OSDMonitor::update_logger()
603 dout(10) << "update_logger" << dendl
;
605 mon
->cluster_logger
->set(l_cluster_num_osd
, osdmap
.get_num_osds());
606 mon
->cluster_logger
->set(l_cluster_num_osd_up
, osdmap
.get_num_up_osds());
607 mon
->cluster_logger
->set(l_cluster_num_osd_in
, osdmap
.get_num_in_osds());
608 mon
->cluster_logger
->set(l_cluster_osd_epoch
, osdmap
.get_epoch());
611 void OSDMonitor::create_pending()
613 pending_inc
= OSDMap::Incremental(osdmap
.epoch
+1);
614 pending_inc
.fsid
= mon
->monmap
->fsid
;
616 dout(10) << "create_pending e " << pending_inc
.epoch
<< dendl
;
618 // clean up pg_temp, primary_temp
619 OSDMap::clean_temps(g_ceph_context
, osdmap
, &pending_inc
);
620 dout(10) << "create_pending did clean_temps" << dendl
;
622 // On upgrade OSDMap has new field set by mon_osd_backfillfull_ratio config
623 // instead of osd_backfill_full_ratio config
624 if (osdmap
.backfillfull_ratio
<= 0) {
625 pending_inc
.new_backfillfull_ratio
= g_conf
->mon_osd_backfillfull_ratio
;
626 if (pending_inc
.new_backfillfull_ratio
> 1.0)
627 pending_inc
.new_backfillfull_ratio
/= 100;
628 dout(1) << __func__
<< " setting backfillfull_ratio = "
629 << pending_inc
.new_backfillfull_ratio
<< dendl
;
631 if (osdmap
.get_epoch() > 0 &&
632 osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
633 // transition full ratios from PGMap to OSDMap (on upgrade)
634 float full_ratio
= mon
->pgservice
->get_full_ratio();
635 float nearfull_ratio
= mon
->pgservice
->get_nearfull_ratio();
636 if (osdmap
.full_ratio
!= full_ratio
) {
637 dout(10) << __func__
<< " full_ratio " << osdmap
.full_ratio
638 << " -> " << full_ratio
<< " (from pgmap)" << dendl
;
639 pending_inc
.new_full_ratio
= full_ratio
;
641 if (osdmap
.nearfull_ratio
!= nearfull_ratio
) {
642 dout(10) << __func__
<< " nearfull_ratio " << osdmap
.nearfull_ratio
643 << " -> " << nearfull_ratio
<< " (from pgmap)" << dendl
;
644 pending_inc
.new_nearfull_ratio
= nearfull_ratio
;
647 // safety check (this shouldn't really happen)
648 if (osdmap
.full_ratio
<= 0) {
649 pending_inc
.new_full_ratio
= g_conf
->mon_osd_full_ratio
;
650 if (pending_inc
.new_full_ratio
> 1.0)
651 pending_inc
.new_full_ratio
/= 100;
652 dout(1) << __func__
<< " setting full_ratio = "
653 << pending_inc
.new_full_ratio
<< dendl
;
655 if (osdmap
.nearfull_ratio
<= 0) {
656 pending_inc
.new_nearfull_ratio
= g_conf
->mon_osd_nearfull_ratio
;
657 if (pending_inc
.new_nearfull_ratio
> 1.0)
658 pending_inc
.new_nearfull_ratio
/= 100;
659 dout(1) << __func__
<< " setting nearfull_ratio = "
660 << pending_inc
.new_nearfull_ratio
<< dendl
;
666 OSDMonitor::update_pending_pgs(const OSDMap::Incremental
& inc
)
668 dout(10) << __func__
<< dendl
;
669 creating_pgs_t pending_creatings
;
671 std::lock_guard
<std::mutex
> l(creating_pgs_lock
);
672 pending_creatings
= creating_pgs
;
674 // check for new or old pools
675 if (pending_creatings
.last_scan_epoch
< inc
.epoch
) {
676 if (osdmap
.get_epoch() &&
677 osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
679 mon
->pgservice
->maybe_add_creating_pgs(creating_pgs
.last_scan_epoch
,
682 dout(7) << __func__
<< " " << added
<< " pgs added from pgmap" << dendl
;
685 queued
+= scan_for_creating_pgs(osdmap
.get_pools(),
689 queued
+= scan_for_creating_pgs(inc
.new_pools
,
693 dout(10) << __func__
<< " " << queued
<< " pools queued" << dendl
;
694 for (auto deleted_pool
: inc
.old_pools
) {
695 auto removed
= pending_creatings
.remove_pool(deleted_pool
);
696 dout(10) << __func__
<< " " << removed
697 << " pg removed because containing pool deleted: "
698 << deleted_pool
<< dendl
;
699 last_epoch_clean
.remove_pool(deleted_pool
);
701 // pgmon updates its creating_pgs in check_osd_map() which is called by
702 // on_active() and check_osd_map() could be delayed if lease expires, so its
703 // creating_pgs could be stale in comparison with the one of osdmon. let's
704 // trim them here. otherwise, they will be added back after being erased.
705 unsigned removed
= 0;
706 for (auto& pg
: pending_created_pgs
) {
707 dout(20) << __func__
<< " noting created pg " << pg
<< dendl
;
708 pending_creatings
.created_pools
.insert(pg
.pool());
709 removed
+= pending_creatings
.pgs
.erase(pg
);
711 pending_created_pgs
.clear();
712 dout(10) << __func__
<< " " << removed
713 << " pgs removed because they're created" << dendl
;
714 pending_creatings
.last_scan_epoch
= osdmap
.get_epoch();
718 unsigned max
= MAX(1, g_conf
->mon_osd_max_creating_pgs
);
719 const auto total
= pending_creatings
.pgs
.size();
720 while (pending_creatings
.pgs
.size() < max
&&
721 !pending_creatings
.queue
.empty()) {
722 auto p
= pending_creatings
.queue
.begin();
723 int64_t poolid
= p
->first
;
724 dout(10) << __func__
<< " pool " << poolid
725 << " created " << p
->second
.created
726 << " modified " << p
->second
.modified
727 << " [" << p
->second
.start
<< "-" << p
->second
.end
<< ")"
729 int n
= MIN(max
- pending_creatings
.pgs
.size(),
730 p
->second
.end
- p
->second
.start
);
731 ps_t first
= p
->second
.start
;
732 ps_t end
= first
+ n
;
733 for (ps_t ps
= first
; ps
< end
; ++ps
) {
734 const pg_t pgid
{ps
, static_cast<uint64_t>(poolid
)};
735 // NOTE: use the *current* epoch as the PG creation epoch so that the
736 // OSD does not have to generate a long set of PastIntervals.
737 pending_creatings
.pgs
.emplace(pgid
, make_pair(inc
.epoch
,
738 p
->second
.modified
));
739 dout(10) << __func__
<< " adding " << pgid
<< dendl
;
741 p
->second
.start
= end
;
742 if (p
->second
.done()) {
743 dout(10) << __func__
<< " done with queue for " << poolid
<< dendl
;
744 pending_creatings
.queue
.erase(p
);
746 dout(10) << __func__
<< " pool " << poolid
747 << " now [" << p
->second
.start
<< "-" << p
->second
.end
<< ")"
751 dout(10) << __func__
<< " queue remaining: " << pending_creatings
.queue
.size()
752 << " pools" << dendl
;
754 << " " << (pending_creatings
.pgs
.size() - total
)
755 << "/" << pending_creatings
.pgs
.size()
756 << " pgs added from queued pools" << dendl
;
757 return pending_creatings
;
760 void OSDMonitor::maybe_prime_pg_temp()
763 if (pending_inc
.crush
.length()) {
764 dout(10) << __func__
<< " new crush map, all" << dendl
;
768 if (!pending_inc
.new_up_client
.empty()) {
769 dout(10) << __func__
<< " new up osds, all" << dendl
;
773 // check for interesting OSDs
775 for (auto p
= pending_inc
.new_state
.begin();
776 !all
&& p
!= pending_inc
.new_state
.end();
778 if ((p
->second
& CEPH_OSD_UP
) &&
779 osdmap
.is_up(p
->first
)) {
780 osds
.insert(p
->first
);
783 for (map
<int32_t,uint32_t>::iterator p
= pending_inc
.new_weight
.begin();
784 !all
&& p
!= pending_inc
.new_weight
.end();
786 if (p
->second
< osdmap
.get_weight(p
->first
)) {
788 osds
.insert(p
->first
);
790 dout(10) << __func__
<< " osd." << p
->first
<< " weight increase, all"
796 if (!all
&& osds
.empty())
801 mapping
.get_osd_acting_pgs(*osds
.begin()).size() * osds
.size();
802 if (estimate
> mapping
.get_num_pgs() *
803 g_conf
->mon_osd_prime_pg_temp_max_estimate
) {
804 dout(10) << __func__
<< " estimate " << estimate
<< " pgs on "
805 << osds
.size() << " osds >= "
806 << g_conf
->mon_osd_prime_pg_temp_max_estimate
<< " of total "
807 << mapping
.get_num_pgs() << " pgs, all"
811 dout(10) << __func__
<< " estimate " << estimate
<< " pgs on "
812 << osds
.size() << " osds" << dendl
;
817 next
.deepish_copy_from(osdmap
);
818 next
.apply_incremental(pending_inc
);
820 if (next
.get_pools().empty()) {
821 dout(10) << __func__
<< " no pools, no pg_temp priming" << dendl
;
823 PrimeTempJob
job(next
, this);
824 mapper
.queue(&job
, g_conf
->mon_osd_mapping_pgs_per_chunk
);
825 if (job
.wait_for(g_conf
->mon_osd_prime_pg_temp_max_time
)) {
826 dout(10) << __func__
<< " done in " << job
.get_duration() << dendl
;
828 dout(10) << __func__
<< " did not finish in "
829 << g_conf
->mon_osd_prime_pg_temp_max_time
830 << ", stopping" << dendl
;
834 dout(10) << __func__
<< " " << osds
.size() << " interesting osds" << dendl
;
835 utime_t stop
= ceph_clock_now();
836 stop
+= g_conf
->mon_osd_prime_pg_temp_max_time
;
837 const int chunk
= 1000;
839 std::unordered_set
<pg_t
> did_pgs
;
840 for (auto osd
: osds
) {
841 auto& pgs
= mapping
.get_osd_acting_pgs(osd
);
842 dout(20) << __func__
<< " osd." << osd
<< " " << pgs
<< dendl
;
843 for (auto pgid
: pgs
) {
844 if (!did_pgs
.insert(pgid
).second
) {
847 prime_pg_temp(next
, pgid
);
850 if (ceph_clock_now() > stop
) {
851 dout(10) << __func__
<< " consumed more than "
852 << g_conf
->mon_osd_prime_pg_temp_max_time
853 << " seconds, stopping"
863 void OSDMonitor::prime_pg_temp(
867 if (mon
->monmap
->get_required_features().contains_all(
868 ceph::features::mon::FEATURE_LUMINOUS
)) {
869 // TODO: remove this creating_pgs direct access?
870 if (creating_pgs
.pgs
.count(pgid
)) {
874 if (mon
->pgservice
->is_creating_pg(pgid
)) {
878 if (!osdmap
.pg_exists(pgid
)) {
882 vector
<int> up
, acting
;
883 mapping
.get(pgid
, &up
, nullptr, &acting
, nullptr);
885 vector
<int> next_up
, next_acting
;
886 int next_up_primary
, next_acting_primary
;
887 next
.pg_to_up_acting_osds(pgid
, &next_up
, &next_up_primary
,
888 &next_acting
, &next_acting_primary
);
889 if (acting
== next_acting
&& next_up
!= next_acting
)
890 return; // no change since last epoch
893 return; // if previously empty now we can be no worse off
894 const pg_pool_t
*pool
= next
.get_pg_pool(pgid
.pool());
895 if (pool
&& acting
.size() < pool
->min_size
)
896 return; // can be no worse off than before
898 if (next_up
== next_acting
) {
900 dout(20) << __func__
<< "next_up === next_acting now, clear pg_temp"
904 dout(20) << __func__
<< " " << pgid
<< " " << up
<< "/" << acting
905 << " -> " << next_up
<< "/" << next_acting
906 << ", priming " << acting
909 Mutex::Locker
l(prime_pg_temp_lock
);
910 // do not touch a mapping if a change is pending
911 pending_inc
.new_pg_temp
.emplace(
913 mempool::osdmap::vector
<int>(acting
.begin(), acting
.end()));
918 * @note receiving a transaction in this function gives a fair amount of
919 * freedom to the service implementation if it does need it. It shouldn't.
921 void OSDMonitor::encode_pending(MonitorDBStore::TransactionRef t
)
923 dout(10) << "encode_pending e " << pending_inc
.epoch
926 // finalize up pending_inc
927 pending_inc
.modified
= ceph_clock_now();
929 int r
= pending_inc
.propagate_snaps_to_tiers(g_ceph_context
, osdmap
);
933 if (!mapping_job
->is_done()) {
934 dout(1) << __func__
<< " skipping prime_pg_temp; mapping job "
935 << mapping_job
.get() << " did not complete, "
936 << mapping_job
->shards
<< " left" << dendl
;
937 mapping_job
->abort();
938 } else if (mapping
.get_epoch() < osdmap
.get_epoch()) {
939 dout(1) << __func__
<< " skipping prime_pg_temp; mapping job "
940 << mapping_job
.get() << " is prior epoch "
941 << mapping
.get_epoch() << dendl
;
943 if (g_conf
->mon_osd_prime_pg_temp
) {
944 maybe_prime_pg_temp();
947 } else if (g_conf
->mon_osd_prime_pg_temp
) {
948 dout(1) << __func__
<< " skipping prime_pg_temp; mapping job did not start"
953 // ensure we don't have blank new_state updates. these are interrpeted as
954 // CEPH_OSD_UP (and almost certainly not what we want!).
955 auto p
= pending_inc
.new_state
.begin();
956 while (p
!= pending_inc
.new_state
.end()) {
957 if (p
->second
== 0) {
958 dout(10) << "new_state for osd." << p
->first
<< " is 0, removing" << dendl
;
959 p
= pending_inc
.new_state
.erase(p
);
969 tmp
.deepish_copy_from(osdmap
);
970 tmp
.apply_incremental(pending_inc
);
972 if (tmp
.require_osd_release
>= CEPH_RELEASE_LUMINOUS
) {
973 // set or clear full/nearfull?
974 int full
, backfill
, nearfull
;
975 tmp
.count_full_nearfull_osds(&full
, &backfill
, &nearfull
);
977 if (!tmp
.test_flag(CEPH_OSDMAP_FULL
)) {
978 dout(10) << __func__
<< " setting full flag" << dendl
;
979 add_flag(CEPH_OSDMAP_FULL
);
980 remove_flag(CEPH_OSDMAP_NEARFULL
);
983 if (tmp
.test_flag(CEPH_OSDMAP_FULL
)) {
984 dout(10) << __func__
<< " clearing full flag" << dendl
;
985 remove_flag(CEPH_OSDMAP_FULL
);
988 if (!tmp
.test_flag(CEPH_OSDMAP_NEARFULL
)) {
989 dout(10) << __func__
<< " setting nearfull flag" << dendl
;
990 add_flag(CEPH_OSDMAP_NEARFULL
);
993 if (tmp
.test_flag(CEPH_OSDMAP_NEARFULL
)) {
994 dout(10) << __func__
<< " clearing nearfull flag" << dendl
;
995 remove_flag(CEPH_OSDMAP_NEARFULL
);
1000 // min_compat_client?
1001 if (tmp
.require_min_compat_client
== 0) {
1002 auto mv
= tmp
.get_min_compat_client();
1003 dout(1) << __func__
<< " setting require_min_compat_client to currently "
1004 << "required " << ceph_release_name(mv
) << dendl
;
1005 mon
->clog
->info() << "setting require_min_compat_client to currently "
1006 << "required " << ceph_release_name(mv
);
1007 pending_inc
.new_require_min_compat_client
= mv
;
1010 if (osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
1011 // convert ec profile ruleset-* -> crush-*
1012 for (auto& p
: tmp
.erasure_code_profiles
) {
1013 bool changed
= false;
1014 map
<string
,string
> newprofile
;
1015 for (auto& q
: p
.second
) {
1016 if (q
.first
.find("ruleset-") == 0) {
1017 string key
= "crush-";
1018 key
+= q
.first
.substr(8);
1019 newprofile
[key
] = q
.second
;
1021 dout(20) << " updating ec profile " << p
.first
1022 << " key " << q
.first
<< " -> " << key
<< dendl
;
1024 newprofile
[q
.first
] = q
.second
;
1028 dout(10) << " updated ec profile " << p
.first
<< ": "
1029 << newprofile
<< dendl
;
1030 pending_inc
.new_erasure_code_profiles
[p
.first
] = newprofile
;
1034 // auto-enable pool applications upon upgrade
1035 // NOTE: this can be removed post-Luminous assuming upgrades need to
1036 // proceed through Luminous
1037 for (auto &pool_pair
: tmp
.pools
) {
1038 int64_t pool_id
= pool_pair
.first
;
1039 pg_pool_t pg_pool
= pool_pair
.second
;
1040 if (pg_pool
.is_tier()) {
1044 std::string pool_name
= tmp
.get_pool_name(pool_id
);
1045 uint32_t match_count
= 0;
1048 FSMap
const &pending_fsmap
= mon
->mdsmon()->get_pending();
1049 if (pending_fsmap
.pool_in_use(pool_id
)) {
1050 dout(10) << __func__
<< " auto-enabling CephFS on pool '"
1051 << pool_name
<< "'" << dendl
;
1052 pg_pool
.application_metadata
.insert(
1053 {pg_pool_t::APPLICATION_NAME_CEPHFS
, {}});
1057 // RBD heuristics (default OpenStack pool names from docs and
1059 if (boost::algorithm::contains(pool_name
, "rbd") ||
1060 pool_name
== "images" || pool_name
== "volumes" ||
1061 pool_name
== "backups" || pool_name
== "vms") {
1062 dout(10) << __func__
<< " auto-enabling RBD on pool '"
1063 << pool_name
<< "'" << dendl
;
1064 pg_pool
.application_metadata
.insert(
1065 {pg_pool_t::APPLICATION_NAME_RBD
, {}});
1070 if (boost::algorithm::contains(pool_name
, ".rgw") ||
1071 boost::algorithm::contains(pool_name
, ".log") ||
1072 boost::algorithm::contains(pool_name
, ".intent-log") ||
1073 boost::algorithm::contains(pool_name
, ".usage") ||
1074 boost::algorithm::contains(pool_name
, ".users")) {
1075 dout(10) << __func__
<< " auto-enabling RGW on pool '"
1076 << pool_name
<< "'" << dendl
;
1077 pg_pool
.application_metadata
.insert(
1078 {pg_pool_t::APPLICATION_NAME_RGW
, {}});
1082 // OpenStack gnocchi (from ceph-ansible)
1083 if (pool_name
== "metrics" && match_count
== 0) {
1084 dout(10) << __func__
<< " auto-enabling OpenStack Gnocchi on pool '"
1085 << pool_name
<< "'" << dendl
;
1086 pg_pool
.application_metadata
.insert({"openstack_gnocchi", {}});
1090 if (match_count
== 1) {
1091 pg_pool
.last_change
= pending_inc
.epoch
;
1092 pending_inc
.new_pools
[pool_id
] = pg_pool
;
1093 } else if (match_count
> 1) {
1094 auto pstat
= mon
->pgservice
->get_pool_stat(pool_id
);
1095 if (pstat
!= nullptr && pstat
->stats
.sum
.num_objects
> 0) {
1096 mon
->clog
->info() << "unable to auto-enable application for pool "
1097 << "'" << pool_name
<< "'";
1106 for (auto i
= pending_inc
.new_state
.begin();
1107 i
!= pending_inc
.new_state
.end();
1109 int s
= i
->second
? i
->second
: CEPH_OSD_UP
;
1110 if (s
& CEPH_OSD_UP
)
1111 dout(2) << " osd." << i
->first
<< " DOWN" << dendl
;
1112 if (s
& CEPH_OSD_EXISTS
)
1113 dout(2) << " osd." << i
->first
<< " DNE" << dendl
;
1115 for (map
<int32_t,entity_addr_t
>::iterator i
= pending_inc
.new_up_client
.begin();
1116 i
!= pending_inc
.new_up_client
.end();
1118 //FIXME: insert cluster addresses too
1119 dout(2) << " osd." << i
->first
<< " UP " << i
->second
<< dendl
;
1121 for (map
<int32_t,uint32_t>::iterator i
= pending_inc
.new_weight
.begin();
1122 i
!= pending_inc
.new_weight
.end();
1124 if (i
->second
== CEPH_OSD_OUT
) {
1125 dout(2) << " osd." << i
->first
<< " OUT" << dendl
;
1126 } else if (i
->second
== CEPH_OSD_IN
) {
1127 dout(2) << " osd." << i
->first
<< " IN" << dendl
;
1129 dout(2) << " osd." << i
->first
<< " WEIGHT " << hex
<< i
->second
<< dec
<< dendl
;
1133 // features for osdmap and its incremental
1134 uint64_t features
= mon
->get_quorum_con_features();
1136 // encode full map and determine its crc
1139 tmp
.deepish_copy_from(osdmap
);
1140 tmp
.apply_incremental(pending_inc
);
1142 // determine appropriate features
1143 if (tmp
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
1144 dout(10) << __func__
<< " encoding without feature SERVER_LUMINOUS"
1146 features
&= ~CEPH_FEATURE_SERVER_LUMINOUS
;
1148 if (tmp
.require_osd_release
< CEPH_RELEASE_KRAKEN
) {
1149 dout(10) << __func__
<< " encoding without feature SERVER_KRAKEN | "
1150 << "MSG_ADDR2" << dendl
;
1151 features
&= ~(CEPH_FEATURE_SERVER_KRAKEN
|
1152 CEPH_FEATURE_MSG_ADDR2
);
1154 if (tmp
.require_osd_release
< CEPH_RELEASE_JEWEL
) {
1155 dout(10) << __func__
<< " encoding without feature SERVER_JEWEL" << dendl
;
1156 features
&= ~CEPH_FEATURE_SERVER_JEWEL
;
1158 dout(10) << __func__
<< " encoding full map with " << features
<< dendl
;
1161 ::encode(tmp
, fullbl
, features
| CEPH_FEATURE_RESERVED
);
1162 pending_inc
.full_crc
= tmp
.get_crc();
1164 // include full map in the txn. note that old monitors will
1165 // overwrite this. new ones will now skip the local full map
1166 // encode and reload from this.
1167 put_version_full(t
, pending_inc
.epoch
, fullbl
);
1171 assert(get_last_committed() + 1 == pending_inc
.epoch
);
1172 ::encode(pending_inc
, bl
, features
| CEPH_FEATURE_RESERVED
);
1174 dout(20) << " full_crc " << tmp
.get_crc()
1175 << " inc_crc " << pending_inc
.inc_crc
<< dendl
;
1177 /* put everything in the transaction */
1178 put_version(t
, pending_inc
.epoch
, bl
);
1179 put_last_committed(t
, pending_inc
.epoch
);
1182 for (map
<int,bufferlist
>::iterator p
= pending_metadata
.begin();
1183 p
!= pending_metadata
.end();
1185 t
->put(OSD_METADATA_PREFIX
, stringify(p
->first
), p
->second
);
1186 for (set
<int>::iterator p
= pending_metadata_rm
.begin();
1187 p
!= pending_metadata_rm
.end();
1189 t
->erase(OSD_METADATA_PREFIX
, stringify(*p
));
1190 pending_metadata
.clear();
1191 pending_metadata_rm
.clear();
1193 // and pg creating, also!
1194 if (mon
->monmap
->get_required_features().contains_all(
1195 ceph::features::mon::FEATURE_LUMINOUS
)) {
1196 auto pending_creatings
= update_pending_pgs(pending_inc
);
1197 if (osdmap
.get_epoch() &&
1198 osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
1199 dout(7) << __func__
<< " in the middle of upgrading, "
1200 << " trimming pending creating_pgs using pgmap" << dendl
;
1201 mon
->pgservice
->maybe_trim_creating_pgs(&pending_creatings
);
1203 bufferlist creatings_bl
;
1204 ::encode(pending_creatings
, creatings_bl
);
1205 t
->put(OSD_PG_CREATING_PREFIX
, "creating", creatings_bl
);
1209 health_check_map_t next
;
1210 tmp
.check_health(&next
);
1211 encode_health(next
, t
);
1214 void OSDMonitor::trim_creating_pgs(creating_pgs_t
* creating_pgs
,
1215 const ceph::unordered_map
<pg_t
,pg_stat_t
>& pg_stat
)
1217 auto p
= creating_pgs
->pgs
.begin();
1218 while (p
!= creating_pgs
->pgs
.end()) {
1219 auto q
= pg_stat
.find(p
->first
);
1220 if (q
!= pg_stat
.end() &&
1221 !(q
->second
.state
& PG_STATE_CREATING
)) {
1222 dout(20) << __func__
<< " pgmap shows " << p
->first
<< " is created"
1224 p
= creating_pgs
->pgs
.erase(p
);
1231 int OSDMonitor::load_metadata(int osd
, map
<string
, string
>& m
, ostream
*err
)
1234 int r
= mon
->store
->get(OSD_METADATA_PREFIX
, stringify(osd
), bl
);
1238 bufferlist::iterator p
= bl
.begin();
1241 catch (buffer::error
& e
) {
1243 *err
<< "osd." << osd
<< " metadata is corrupt";
1249 void OSDMonitor::count_metadata(const string
& field
, map
<string
,int> *out
)
1251 for (int osd
= 0; osd
< osdmap
.get_max_osd(); ++osd
) {
1252 if (osdmap
.is_up(osd
)) {
1253 map
<string
,string
> meta
;
1254 load_metadata(osd
, meta
, nullptr);
1255 auto p
= meta
.find(field
);
1256 if (p
== meta
.end()) {
1257 (*out
)["unknown"]++;
1259 (*out
)[p
->second
]++;
1265 void OSDMonitor::count_metadata(const string
& field
, Formatter
*f
)
1267 map
<string
,int> by_val
;
1268 count_metadata(field
, &by_val
);
1269 f
->open_object_section(field
.c_str());
1270 for (auto& p
: by_val
) {
1271 f
->dump_int(p
.first
.c_str(), p
.second
);
1276 int OSDMonitor::get_osd_objectstore_type(int osd
, string
*type
)
1278 map
<string
, string
> metadata
;
1279 int r
= load_metadata(osd
, metadata
, nullptr);
1283 auto it
= metadata
.find("osd_objectstore");
1284 if (it
== metadata
.end())
1290 bool OSDMonitor::is_pool_currently_all_bluestore(int64_t pool_id
,
1291 const pg_pool_t
&pool
,
1294 // just check a few pgs for efficiency - this can't give a guarantee anyway,
1295 // since filestore osds could always join the pool later
1296 set
<int> checked_osds
;
1297 for (unsigned ps
= 0; ps
< MIN(8, pool
.get_pg_num()); ++ps
) {
1298 vector
<int> up
, acting
;
1299 pg_t
pgid(ps
, pool_id
, -1);
1300 osdmap
.pg_to_up_acting_osds(pgid
, up
, acting
);
1301 for (int osd
: up
) {
1302 if (checked_osds
.find(osd
) != checked_osds
.end())
1304 string objectstore_type
;
1305 int r
= get_osd_objectstore_type(osd
, &objectstore_type
);
1306 // allow with missing metadata, e.g. due to an osd never booting yet
1307 if (r
< 0 || objectstore_type
== "bluestore") {
1308 checked_osds
.insert(osd
);
1311 *err
<< "osd." << osd
<< " uses " << objectstore_type
;
1318 int OSDMonitor::dump_osd_metadata(int osd
, Formatter
*f
, ostream
*err
)
1320 map
<string
,string
> m
;
1321 if (int r
= load_metadata(osd
, m
, err
))
1323 for (map
<string
,string
>::iterator p
= m
.begin(); p
!= m
.end(); ++p
)
1324 f
->dump_string(p
->first
.c_str(), p
->second
);
1328 void OSDMonitor::print_nodes(Formatter
*f
)
1330 // group OSDs by their hosts
1331 map
<string
, list
<int> > osds
; // hostname => osd
1332 for (int osd
= 0; osd
< osdmap
.get_max_osd(); osd
++) {
1333 map
<string
, string
> m
;
1334 if (load_metadata(osd
, m
, NULL
)) {
1337 map
<string
, string
>::iterator hostname
= m
.find("hostname");
1338 if (hostname
== m
.end()) {
1339 // not likely though
1342 osds
[hostname
->second
].push_back(osd
);
1345 dump_services(f
, osds
, "osd");
1348 void OSDMonitor::share_map_with_random_osd()
1350 if (osdmap
.get_num_up_osds() == 0) {
1351 dout(10) << __func__
<< " no up osds, don't share with anyone" << dendl
;
1355 MonSession
*s
= mon
->session_map
.get_random_osd_session(&osdmap
);
1357 dout(10) << __func__
<< " no up osd on our session map" << dendl
;
1361 dout(10) << "committed, telling random " << s
->inst
<< " all about it" << dendl
;
1362 // whatev, they'll request more if they need it
1363 MOSDMap
*m
= build_incremental(osdmap
.get_epoch() - 1, osdmap
.get_epoch());
1364 s
->con
->send_message(m
);
1365 // NOTE: do *not* record osd has up to this epoch (as we do
1366 // elsewhere) as they may still need to request older values.
1369 version_t
OSDMonitor::get_trim_to()
1371 if (mon
->get_quorum().empty()) {
1372 dout(10) << __func__
<< ": quorum not formed" << dendl
;
1377 if (mon
->monmap
->get_required_features().contains_all(
1378 ceph::features::mon::FEATURE_LUMINOUS
)) {
1380 // TODO: Get this hidden in PGStatService
1381 std::lock_guard
<std::mutex
> l(creating_pgs_lock
);
1382 if (!creating_pgs
.pgs
.empty()) {
1386 floor
= get_min_last_epoch_clean();
1388 if (!mon
->pgservice
->is_readable())
1390 if (mon
->pgservice
->have_creating_pgs()) {
1393 floor
= mon
->pgservice
->get_min_last_epoch_clean();
1396 dout(10) << " min_last_epoch_clean " << floor
<< dendl
;
1397 if (g_conf
->mon_osd_force_trim_to
> 0 &&
1398 g_conf
->mon_osd_force_trim_to
< (int)get_last_committed()) {
1399 floor
= g_conf
->mon_osd_force_trim_to
;
1400 dout(10) << " explicit mon_osd_force_trim_to = " << floor
<< dendl
;
1402 unsigned min
= g_conf
->mon_min_osdmap_epochs
;
1403 if (floor
+ min
> get_last_committed()) {
1404 if (min
< get_last_committed())
1405 floor
= get_last_committed() - min
;
1409 if (floor
> get_first_committed())
1415 epoch_t
OSDMonitor::get_min_last_epoch_clean() const
1417 auto floor
= last_epoch_clean
.get_lower_bound(osdmap
);
1418 // also scan osd epochs
1419 // don't trim past the oldest reported osd epoch
1420 for (auto& osd_epoch
: osd_epochs
) {
1421 if (osd_epoch
.second
< floor
) {
1422 floor
= osd_epoch
.second
;
1428 void OSDMonitor::encode_trim_extra(MonitorDBStore::TransactionRef tx
,
1431 dout(10) << __func__
<< " including full map for e " << first
<< dendl
;
1433 get_version_full(first
, bl
);
1434 put_version_full(tx
, first
, bl
);
1439 bool OSDMonitor::preprocess_query(MonOpRequestRef op
)
1441 op
->mark_osdmon_event(__func__
);
1442 Message
*m
= op
->get_req();
1443 dout(10) << "preprocess_query " << *m
<< " from " << m
->get_orig_source_inst() << dendl
;
1445 switch (m
->get_type()) {
1447 case MSG_MON_COMMAND
:
1448 return preprocess_command(op
);
1449 case CEPH_MSG_MON_GET_OSDMAP
:
1450 return preprocess_get_osdmap(op
);
1453 case MSG_OSD_MARK_ME_DOWN
:
1454 return preprocess_mark_me_down(op
);
1456 return preprocess_full(op
);
1457 case MSG_OSD_FAILURE
:
1458 return preprocess_failure(op
);
1460 return preprocess_boot(op
);
1462 return preprocess_alive(op
);
1463 case MSG_OSD_PG_CREATED
:
1464 return preprocess_pg_created(op
);
1465 case MSG_OSD_PGTEMP
:
1466 return preprocess_pgtemp(op
);
1467 case MSG_OSD_BEACON
:
1468 return preprocess_beacon(op
);
1470 case CEPH_MSG_POOLOP
:
1471 return preprocess_pool_op(op
);
1473 case MSG_REMOVE_SNAPS
:
1474 return preprocess_remove_snaps(op
);
1482 bool OSDMonitor::prepare_update(MonOpRequestRef op
)
1484 op
->mark_osdmon_event(__func__
);
1485 Message
*m
= op
->get_req();
1486 dout(7) << "prepare_update " << *m
<< " from " << m
->get_orig_source_inst() << dendl
;
1488 switch (m
->get_type()) {
1490 case MSG_OSD_MARK_ME_DOWN
:
1491 return prepare_mark_me_down(op
);
1493 return prepare_full(op
);
1494 case MSG_OSD_FAILURE
:
1495 return prepare_failure(op
);
1497 return prepare_boot(op
);
1499 return prepare_alive(op
);
1500 case MSG_OSD_PG_CREATED
:
1501 return prepare_pg_created(op
);
1502 case MSG_OSD_PGTEMP
:
1503 return prepare_pgtemp(op
);
1504 case MSG_OSD_BEACON
:
1505 return prepare_beacon(op
);
1507 case MSG_MON_COMMAND
:
1508 return prepare_command(op
);
1510 case CEPH_MSG_POOLOP
:
1511 return prepare_pool_op(op
);
1513 case MSG_REMOVE_SNAPS
:
1514 return prepare_remove_snaps(op
);
1524 bool OSDMonitor::should_propose(double& delay
)
1526 dout(10) << "should_propose" << dendl
;
1528 // if full map, propose immediately! any subsequent changes will be clobbered.
1529 if (pending_inc
.fullmap
.length())
1532 // adjust osd weights?
1533 if (!osd_weight
.empty() &&
1534 osd_weight
.size() == (unsigned)osdmap
.get_max_osd()) {
1535 dout(0) << " adjusting osd weights based on " << osd_weight
<< dendl
;
1536 osdmap
.adjust_osd_weights(osd_weight
, pending_inc
);
1542 // propose as fast as possible if updating up_thru or pg_temp
1543 // want to merge OSDMap changes as much as possible
1544 if ((pending_inc
.new_primary_temp
.size() == 1
1545 || pending_inc
.new_up_thru
.size() == 1)
1546 && pending_inc
.new_state
.size() < 2) {
1547 dout(15) << " propose as fast as possible for up_thru/pg_temp" << dendl
;
1549 utime_t now
= ceph_clock_now();
1550 if (now
- last_attempted_minwait_time
> g_conf
->paxos_propose_interval
1551 && now
- paxos
->get_last_commit_time() > g_conf
->paxos_min_wait
) {
1552 delay
= g_conf
->paxos_min_wait
;
1553 last_attempted_minwait_time
= now
;
1558 return PaxosService::should_propose(delay
);
1563 // ---------------------------
1566 bool OSDMonitor::preprocess_get_osdmap(MonOpRequestRef op
)
1568 op
->mark_osdmon_event(__func__
);
1569 MMonGetOSDMap
*m
= static_cast<MMonGetOSDMap
*>(op
->get_req());
1570 dout(10) << __func__
<< " " << *m
<< dendl
;
1571 MOSDMap
*reply
= new MOSDMap(mon
->monmap
->fsid
);
1572 epoch_t first
= get_first_committed();
1573 epoch_t last
= osdmap
.get_epoch();
1574 int max
= g_conf
->osd_map_message_max
;
1575 for (epoch_t e
= MAX(first
, m
->get_full_first());
1576 e
<= MIN(last
, m
->get_full_last()) && max
> 0;
1578 int r
= get_version_full(e
, reply
->maps
[e
]);
1581 for (epoch_t e
= MAX(first
, m
->get_inc_first());
1582 e
<= MIN(last
, m
->get_inc_last()) && max
> 0;
1584 int r
= get_version(e
, reply
->incremental_maps
[e
]);
1587 reply
->oldest_map
= first
;
1588 reply
->newest_map
= last
;
1589 mon
->send_reply(op
, reply
);
1594 // ---------------------------
1599 bool OSDMonitor::check_source(PaxosServiceMessage
*m
, uuid_d fsid
) {
1600 // check permissions
1601 MonSession
*session
= m
->get_session();
1604 if (!session
->is_capable("osd", MON_CAP_X
)) {
1605 dout(0) << "got MOSDFailure from entity with insufficient caps "
1606 << session
->caps
<< dendl
;
1609 if (fsid
!= mon
->monmap
->fsid
) {
1610 dout(0) << "check_source: on fsid " << fsid
1611 << " != " << mon
->monmap
->fsid
<< dendl
;
1618 bool OSDMonitor::preprocess_failure(MonOpRequestRef op
)
1620 op
->mark_osdmon_event(__func__
);
1621 MOSDFailure
*m
= static_cast<MOSDFailure
*>(op
->get_req());
1622 // who is target_osd
1623 int badboy
= m
->get_target().name
.num();
1625 // check permissions
1626 if (check_source(m
, m
->fsid
))
1629 // first, verify the reporting host is valid
1630 if (m
->get_orig_source().is_osd()) {
1631 int from
= m
->get_orig_source().num();
1632 if (!osdmap
.exists(from
) ||
1633 osdmap
.get_addr(from
) != m
->get_orig_source_inst().addr
||
1634 (osdmap
.is_down(from
) && m
->if_osd_failed())) {
1635 dout(5) << "preprocess_failure from dead osd." << from
<< ", ignoring" << dendl
;
1636 send_incremental(op
, m
->get_epoch()+1);
1643 if (osdmap
.is_down(badboy
)) {
1644 dout(5) << "preprocess_failure dne(/dup?): " << m
->get_target() << ", from " << m
->get_orig_source_inst() << dendl
;
1645 if (m
->get_epoch() < osdmap
.get_epoch())
1646 send_incremental(op
, m
->get_epoch()+1);
1649 if (osdmap
.get_inst(badboy
) != m
->get_target()) {
1650 dout(5) << "preprocess_failure wrong osd: report " << m
->get_target() << " != map's " << osdmap
.get_inst(badboy
)
1651 << ", from " << m
->get_orig_source_inst() << dendl
;
1652 if (m
->get_epoch() < osdmap
.get_epoch())
1653 send_incremental(op
, m
->get_epoch()+1);
1657 // already reported?
1658 if (osdmap
.is_down(badboy
) ||
1659 osdmap
.get_up_from(badboy
) > m
->get_epoch()) {
1660 dout(5) << "preprocess_failure dup/old: " << m
->get_target() << ", from " << m
->get_orig_source_inst() << dendl
;
1661 if (m
->get_epoch() < osdmap
.get_epoch())
1662 send_incremental(op
, m
->get_epoch()+1);
1666 if (!can_mark_down(badboy
)) {
1667 dout(5) << "preprocess_failure ignoring report of " << m
->get_target() << " from " << m
->get_orig_source_inst() << dendl
;
1671 dout(10) << "preprocess_failure new: " << m
->get_target() << ", from " << m
->get_orig_source_inst() << dendl
;
1678 class C_AckMarkedDown
: public C_MonOp
{
1684 : C_MonOp(op
), osdmon(osdmon
) {}
1686 void _finish(int) override
{
1687 MOSDMarkMeDown
*m
= static_cast<MOSDMarkMeDown
*>(op
->get_req());
1688 osdmon
->mon
->send_reply(
1694 false)); // ACK itself does not request an ack
1696 ~C_AckMarkedDown() override
{
1700 bool OSDMonitor::preprocess_mark_me_down(MonOpRequestRef op
)
1702 op
->mark_osdmon_event(__func__
);
1703 MOSDMarkMeDown
*m
= static_cast<MOSDMarkMeDown
*>(op
->get_req());
1704 int requesting_down
= m
->get_target().name
.num();
1705 int from
= m
->get_orig_source().num();
1707 // check permissions
1708 if (check_source(m
, m
->fsid
))
1711 // first, verify the reporting host is valid
1712 if (!m
->get_orig_source().is_osd())
1715 if (!osdmap
.exists(from
) ||
1716 osdmap
.is_down(from
) ||
1717 osdmap
.get_addr(from
) != m
->get_target().addr
) {
1718 dout(5) << "preprocess_mark_me_down from dead osd."
1719 << from
<< ", ignoring" << dendl
;
1720 send_incremental(op
, m
->get_epoch()+1);
1724 // no down might be set
1725 if (!can_mark_down(requesting_down
))
1728 dout(10) << "MOSDMarkMeDown for: " << m
->get_target() << dendl
;
1732 if (m
->request_ack
) {
1733 Context
*c(new C_AckMarkedDown(this, op
));
1739 bool OSDMonitor::prepare_mark_me_down(MonOpRequestRef op
)
1741 op
->mark_osdmon_event(__func__
);
1742 MOSDMarkMeDown
*m
= static_cast<MOSDMarkMeDown
*>(op
->get_req());
1743 int target_osd
= m
->get_target().name
.num();
1745 assert(osdmap
.is_up(target_osd
));
1746 assert(osdmap
.get_addr(target_osd
) == m
->get_target().addr
);
1748 mon
->clog
->info() << "osd." << target_osd
<< " marked itself down";
1749 pending_inc
.new_state
[target_osd
] = CEPH_OSD_UP
;
1751 wait_for_finished_proposal(op
, new C_AckMarkedDown(this, op
));
1755 bool OSDMonitor::can_mark_down(int i
)
1757 if (osdmap
.test_flag(CEPH_OSDMAP_NODOWN
)) {
1758 dout(5) << __func__
<< " NODOWN flag set, will not mark osd." << i
1759 << " down" << dendl
;
1763 if (osdmap
.is_nodown(i
)) {
1764 dout(5) << __func__
<< " osd." << i
<< " is marked as nodown, "
1765 << "will not mark it down" << dendl
;
1769 int num_osds
= osdmap
.get_num_osds();
1770 if (num_osds
== 0) {
1771 dout(5) << __func__
<< " no osds" << dendl
;
1774 int up
= osdmap
.get_num_up_osds() - pending_inc
.get_net_marked_down(&osdmap
);
1775 float up_ratio
= (float)up
/ (float)num_osds
;
1776 if (up_ratio
< g_conf
->mon_osd_min_up_ratio
) {
1777 dout(2) << __func__
<< " current up_ratio " << up_ratio
<< " < min "
1778 << g_conf
->mon_osd_min_up_ratio
1779 << ", will not mark osd." << i
<< " down" << dendl
;
1785 bool OSDMonitor::can_mark_up(int i
)
1787 if (osdmap
.test_flag(CEPH_OSDMAP_NOUP
)) {
1788 dout(5) << __func__
<< " NOUP flag set, will not mark osd." << i
1793 if (osdmap
.is_noup(i
)) {
1794 dout(5) << __func__
<< " osd." << i
<< " is marked as noup, "
1795 << "will not mark it up" << dendl
;
1803 * @note the parameter @p i apparently only exists here so we can output the
1804 * osd's id on messages.
1806 bool OSDMonitor::can_mark_out(int i
)
1808 if (osdmap
.test_flag(CEPH_OSDMAP_NOOUT
)) {
1809 dout(5) << __func__
<< " NOOUT flag set, will not mark osds out" << dendl
;
1813 if (osdmap
.is_noout(i
)) {
1814 dout(5) << __func__
<< " osd." << i
<< " is marked as noout, "
1815 << "will not mark it out" << dendl
;
1819 int num_osds
= osdmap
.get_num_osds();
1820 if (num_osds
== 0) {
1821 dout(5) << __func__
<< " no osds" << dendl
;
1824 int in
= osdmap
.get_num_in_osds() - pending_inc
.get_net_marked_out(&osdmap
);
1825 float in_ratio
= (float)in
/ (float)num_osds
;
1826 if (in_ratio
< g_conf
->mon_osd_min_in_ratio
) {
1828 dout(5) << __func__
<< " current in_ratio " << in_ratio
<< " < min "
1829 << g_conf
->mon_osd_min_in_ratio
1830 << ", will not mark osd." << i
<< " out" << dendl
;
1832 dout(5) << __func__
<< " current in_ratio " << in_ratio
<< " < min "
1833 << g_conf
->mon_osd_min_in_ratio
1834 << ", will not mark osds out" << dendl
;
1841 bool OSDMonitor::can_mark_in(int i
)
1843 if (osdmap
.test_flag(CEPH_OSDMAP_NOIN
)) {
1844 dout(5) << __func__
<< " NOIN flag set, will not mark osd." << i
1849 if (osdmap
.is_noin(i
)) {
1850 dout(5) << __func__
<< " osd." << i
<< " is marked as noin, "
1851 << "will not mark it in" << dendl
;
1858 bool OSDMonitor::check_failures(utime_t now
)
1860 bool found_failure
= false;
1861 for (map
<int,failure_info_t
>::iterator p
= failure_info
.begin();
1862 p
!= failure_info
.end();
1864 if (can_mark_down(p
->first
)) {
1865 found_failure
|= check_failure(now
, p
->first
, p
->second
);
1868 return found_failure
;
1871 bool OSDMonitor::check_failure(utime_t now
, int target_osd
, failure_info_t
& fi
)
1873 // already pending failure?
1874 if (pending_inc
.new_state
.count(target_osd
) &&
1875 pending_inc
.new_state
[target_osd
] & CEPH_OSD_UP
) {
1876 dout(10) << " already pending failure" << dendl
;
1880 set
<string
> reporters_by_subtree
;
1881 string reporter_subtree_level
= g_conf
->mon_osd_reporter_subtree_level
;
1882 utime_t
orig_grace(g_conf
->osd_heartbeat_grace
, 0);
1883 utime_t max_failed_since
= fi
.get_failed_since();
1884 utime_t failed_for
= now
- max_failed_since
;
1886 utime_t grace
= orig_grace
;
1887 double my_grace
= 0, peer_grace
= 0;
1889 if (g_conf
->mon_osd_adjust_heartbeat_grace
) {
1890 double halflife
= (double)g_conf
->mon_osd_laggy_halflife
;
1891 decay_k
= ::log(.5) / halflife
;
1893 // scale grace period based on historical probability of 'lagginess'
1894 // (false positive failures due to slowness).
1895 const osd_xinfo_t
& xi
= osdmap
.get_xinfo(target_osd
);
1896 double decay
= exp((double)failed_for
* decay_k
);
1897 dout(20) << " halflife " << halflife
<< " decay_k " << decay_k
1898 << " failed_for " << failed_for
<< " decay " << decay
<< dendl
;
1899 my_grace
= decay
* (double)xi
.laggy_interval
* xi
.laggy_probability
;
1903 // consider the peers reporting a failure a proxy for a potential
1904 // 'subcluster' over the overall cluster that is similarly
1905 // laggy. this is clearly not true in all cases, but will sometimes
1906 // help us localize the grace correction to a subset of the system
1907 // (say, a rack with a bad switch) that is unhappy.
1908 assert(fi
.reporters
.size());
1909 for (map
<int,failure_reporter_t
>::iterator p
= fi
.reporters
.begin();
1910 p
!= fi
.reporters
.end();
1912 // get the parent bucket whose type matches with "reporter_subtree_level".
1913 // fall back to OSD if the level doesn't exist.
1914 map
<string
, string
> reporter_loc
= osdmap
.crush
->get_full_location(p
->first
);
1915 map
<string
, string
>::iterator iter
= reporter_loc
.find(reporter_subtree_level
);
1916 if (iter
== reporter_loc
.end()) {
1917 reporters_by_subtree
.insert("osd." + to_string(p
->first
));
1919 reporters_by_subtree
.insert(iter
->second
);
1921 if (g_conf
->mon_osd_adjust_heartbeat_grace
) {
1922 const osd_xinfo_t
& xi
= osdmap
.get_xinfo(p
->first
);
1923 utime_t elapsed
= now
- xi
.down_stamp
;
1924 double decay
= exp((double)elapsed
* decay_k
);
1925 peer_grace
+= decay
* (double)xi
.laggy_interval
* xi
.laggy_probability
;
1929 if (g_conf
->mon_osd_adjust_heartbeat_grace
) {
1930 peer_grace
/= (double)fi
.reporters
.size();
1931 grace
+= peer_grace
;
1934 dout(10) << " osd." << target_osd
<< " has "
1935 << fi
.reporters
.size() << " reporters, "
1936 << grace
<< " grace (" << orig_grace
<< " + " << my_grace
1937 << " + " << peer_grace
<< "), max_failed_since " << max_failed_since
1940 if (failed_for
>= grace
&&
1941 (int)reporters_by_subtree
.size() >= g_conf
->mon_osd_min_down_reporters
) {
1942 dout(1) << " we have enough reporters to mark osd." << target_osd
1943 << " down" << dendl
;
1944 pending_inc
.new_state
[target_osd
] = CEPH_OSD_UP
;
1946 mon
->clog
->info() << "osd." << target_osd
<< " failed ("
1947 << osdmap
.crush
->get_full_location_ordered_string(
1950 << (int)reporters_by_subtree
.size()
1951 << " reporters from different "
1952 << reporter_subtree_level
<< " after "
1953 << failed_for
<< " >= grace " << grace
<< ")";
1959 void OSDMonitor::force_failure(int target_osd
, int by
)
1961 // already pending failure?
1962 if (pending_inc
.new_state
.count(target_osd
) &&
1963 pending_inc
.new_state
[target_osd
] & CEPH_OSD_UP
) {
1964 dout(10) << " already pending failure" << dendl
;
1968 dout(1) << " we're forcing failure of osd." << target_osd
<< dendl
;
1969 pending_inc
.new_state
[target_osd
] = CEPH_OSD_UP
;
1971 mon
->clog
->info() << "osd." << target_osd
<< " failed ("
1972 << osdmap
.crush
->get_full_location_ordered_string(target_osd
)
1973 << ") (connection refused reported by osd." << by
<< ")";
1977 bool OSDMonitor::prepare_failure(MonOpRequestRef op
)
1979 op
->mark_osdmon_event(__func__
);
1980 MOSDFailure
*m
= static_cast<MOSDFailure
*>(op
->get_req());
1981 dout(1) << "prepare_failure " << m
->get_target()
1982 << " from " << m
->get_orig_source_inst()
1983 << " is reporting failure:" << m
->if_osd_failed() << dendl
;
1985 int target_osd
= m
->get_target().name
.num();
1986 int reporter
= m
->get_orig_source().num();
1987 assert(osdmap
.is_up(target_osd
));
1988 assert(osdmap
.get_addr(target_osd
) == m
->get_target().addr
);
1990 if (m
->if_osd_failed()) {
1991 // calculate failure time
1992 utime_t now
= ceph_clock_now();
1993 utime_t failed_since
=
1994 m
->get_recv_stamp() - utime_t(m
->failed_for
, 0);
1997 if (m
->is_immediate()) {
1998 mon
->clog
->debug() << m
->get_target() << " reported immediately failed by "
1999 << m
->get_orig_source_inst();
2000 force_failure(target_osd
, reporter
);
2003 mon
->clog
->debug() << m
->get_target() << " reported failed by "
2004 << m
->get_orig_source_inst();
2006 failure_info_t
& fi
= failure_info
[target_osd
];
2007 MonOpRequestRef old_op
= fi
.add_report(reporter
, failed_since
, op
);
2009 mon
->no_reply(old_op
);
2012 return check_failure(now
, target_osd
, fi
);
2014 // remove the report
2015 mon
->clog
->debug() << m
->get_target() << " failure report canceled by "
2016 << m
->get_orig_source_inst();
2017 if (failure_info
.count(target_osd
)) {
2018 failure_info_t
& fi
= failure_info
[target_osd
];
2019 MonOpRequestRef report_op
= fi
.cancel_report(reporter
);
2021 mon
->no_reply(report_op
);
2023 if (fi
.reporters
.empty()) {
2024 dout(10) << " removing last failure_info for osd." << target_osd
2026 failure_info
.erase(target_osd
);
2028 dout(10) << " failure_info for osd." << target_osd
<< " now "
2029 << fi
.reporters
.size() << " reporters" << dendl
;
2032 dout(10) << " no failure_info for osd." << target_osd
<< dendl
;
2040 void OSDMonitor::process_failures()
2042 map
<int,failure_info_t
>::iterator p
= failure_info
.begin();
2043 while (p
!= failure_info
.end()) {
2044 if (osdmap
.is_up(p
->first
)) {
2047 dout(10) << "process_failures osd." << p
->first
<< dendl
;
2048 list
<MonOpRequestRef
> ls
;
2049 p
->second
.take_report_messages(ls
);
2050 failure_info
.erase(p
++);
2052 while (!ls
.empty()) {
2053 MonOpRequestRef o
= ls
.front();
2055 o
->mark_event(__func__
);
2056 MOSDFailure
*m
= o
->get_req
<MOSDFailure
>();
2057 send_latest(o
, m
->get_epoch());
2065 void OSDMonitor::take_all_failures(list
<MonOpRequestRef
>& ls
)
2067 dout(10) << __func__
<< " on " << failure_info
.size() << " osds" << dendl
;
2069 for (map
<int,failure_info_t
>::iterator p
= failure_info
.begin();
2070 p
!= failure_info
.end();
2072 p
->second
.take_report_messages(ls
);
2074 failure_info
.clear();
2080 bool OSDMonitor::preprocess_boot(MonOpRequestRef op
)
2082 op
->mark_osdmon_event(__func__
);
2083 MOSDBoot
*m
= static_cast<MOSDBoot
*>(op
->get_req());
2084 int from
= m
->get_orig_source_inst().name
.num();
2086 // check permissions, ignore if failed (no response expected)
2087 MonSession
*session
= m
->get_session();
2090 if (!session
->is_capable("osd", MON_CAP_X
)) {
2091 dout(0) << "got preprocess_boot message from entity with insufficient caps"
2092 << session
->caps
<< dendl
;
2096 if (m
->sb
.cluster_fsid
!= mon
->monmap
->fsid
) {
2097 dout(0) << "preprocess_boot on fsid " << m
->sb
.cluster_fsid
2098 << " != " << mon
->monmap
->fsid
<< dendl
;
2102 if (m
->get_orig_source_inst().addr
.is_blank_ip()) {
2103 dout(0) << "preprocess_boot got blank addr for " << m
->get_orig_source_inst() << dendl
;
2107 assert(m
->get_orig_source_inst().name
.is_osd());
2109 // check if osd has required features to boot
2110 if ((osdmap
.get_features(CEPH_ENTITY_TYPE_OSD
, NULL
) &
2111 CEPH_FEATURE_OSD_ERASURE_CODES
) &&
2112 !(m
->get_connection()->get_features() & CEPH_FEATURE_OSD_ERASURE_CODES
)) {
2113 dout(0) << __func__
<< " osdmap requires erasure code but osd at "
2114 << m
->get_orig_source_inst()
2115 << " doesn't announce support -- ignore" << dendl
;
2119 if ((osdmap
.get_features(CEPH_ENTITY_TYPE_OSD
, NULL
) &
2120 CEPH_FEATURE_ERASURE_CODE_PLUGINS_V2
) &&
2121 !(m
->get_connection()->get_features() & CEPH_FEATURE_ERASURE_CODE_PLUGINS_V2
)) {
2122 dout(0) << __func__
<< " osdmap requires erasure code plugins v2 but osd at "
2123 << m
->get_orig_source_inst()
2124 << " doesn't announce support -- ignore" << dendl
;
2128 if ((osdmap
.get_features(CEPH_ENTITY_TYPE_OSD
, NULL
) &
2129 CEPH_FEATURE_ERASURE_CODE_PLUGINS_V3
) &&
2130 !(m
->get_connection()->get_features() & CEPH_FEATURE_ERASURE_CODE_PLUGINS_V3
)) {
2131 dout(0) << __func__
<< " osdmap requires erasure code plugins v3 but osd at "
2132 << m
->get_orig_source_inst()
2133 << " doesn't announce support -- ignore" << dendl
;
2137 if (osdmap
.require_osd_release
>= CEPH_RELEASE_LUMINOUS
&&
2138 !HAVE_FEATURE(m
->osd_features
, SERVER_LUMINOUS
)) {
2139 mon
->clog
->info() << "disallowing boot of OSD "
2140 << m
->get_orig_source_inst()
2141 << " because the osdmap requires"
2142 << " CEPH_FEATURE_SERVER_LUMINOUS"
2143 << " but the osd lacks CEPH_FEATURE_SERVER_LUMINOUS";
2147 if (osdmap
.require_osd_release
>= CEPH_RELEASE_JEWEL
&&
2148 !(m
->osd_features
& CEPH_FEATURE_SERVER_JEWEL
)) {
2149 mon
->clog
->info() << "disallowing boot of OSD "
2150 << m
->get_orig_source_inst()
2151 << " because the osdmap requires"
2152 << " CEPH_FEATURE_SERVER_JEWEL"
2153 << " but the osd lacks CEPH_FEATURE_SERVER_JEWEL";
2157 if (osdmap
.require_osd_release
>= CEPH_RELEASE_KRAKEN
&&
2158 !HAVE_FEATURE(m
->osd_features
, SERVER_KRAKEN
)) {
2159 mon
->clog
->info() << "disallowing boot of OSD "
2160 << m
->get_orig_source_inst()
2161 << " because the osdmap requires"
2162 << " CEPH_FEATURE_SERVER_KRAKEN"
2163 << " but the osd lacks CEPH_FEATURE_SERVER_KRAKEN";
2167 if (osdmap
.test_flag(CEPH_OSDMAP_SORTBITWISE
) &&
2168 !(m
->osd_features
& CEPH_FEATURE_OSD_BITWISE_HOBJ_SORT
)) {
2169 mon
->clog
->info() << "disallowing boot of OSD "
2170 << m
->get_orig_source_inst()
2171 << " because 'sortbitwise' osdmap flag is set and OSD lacks the OSD_BITWISE_HOBJ_SORT feature";
2175 if (osdmap
.test_flag(CEPH_OSDMAP_RECOVERY_DELETES
) &&
2176 !(m
->osd_features
& CEPH_FEATURE_OSD_RECOVERY_DELETES
)) {
2177 mon
->clog
->info() << "disallowing boot of OSD "
2178 << m
->get_orig_source_inst()
2179 << " because 'recovery_deletes' osdmap flag is set and OSD lacks the OSD_RECOVERY_DELETES feature";
2183 if (any_of(osdmap
.get_pools().begin(),
2184 osdmap
.get_pools().end(),
2185 [](const std::pair
<int64_t,pg_pool_t
>& pool
)
2186 { return pool
.second
.use_gmt_hitset
; })) {
2187 assert(osdmap
.get_num_up_osds() == 0 ||
2188 osdmap
.get_up_osd_features() & CEPH_FEATURE_OSD_HITSET_GMT
);
2189 if (!(m
->osd_features
& CEPH_FEATURE_OSD_HITSET_GMT
)) {
2190 dout(0) << __func__
<< " one or more pools uses GMT hitsets but osd at "
2191 << m
->get_orig_source_inst()
2192 << " doesn't announce support -- ignore" << dendl
;
2197 // make sure upgrades stop at luminous
2198 if (HAVE_FEATURE(m
->osd_features
, SERVER_M
) &&
2199 osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
2200 mon
->clog
->info() << "disallowing boot of post-luminous OSD "
2201 << m
->get_orig_source_inst()
2202 << " because require_osd_release < luminous";
2206 // make sure upgrades stop at jewel
2207 if (HAVE_FEATURE(m
->osd_features
, SERVER_KRAKEN
) &&
2208 osdmap
.require_osd_release
< CEPH_RELEASE_JEWEL
) {
2209 mon
->clog
->info() << "disallowing boot of post-jewel OSD "
2210 << m
->get_orig_source_inst()
2211 << " because require_osd_release < jewel";
2215 // make sure upgrades stop at hammer
2216 // * HAMMER_0_94_4 is the required hammer feature
2217 // * MON_METADATA is the first post-hammer feature
2218 if (osdmap
.get_num_up_osds() > 0) {
2219 if ((m
->osd_features
& CEPH_FEATURE_MON_METADATA
) &&
2220 !(osdmap
.get_up_osd_features() & CEPH_FEATURE_HAMMER_0_94_4
)) {
2221 mon
->clog
->info() << "disallowing boot of post-hammer OSD "
2222 << m
->get_orig_source_inst()
2223 << " because one or more up OSDs is pre-hammer v0.94.4";
2226 if (!(m
->osd_features
& CEPH_FEATURE_HAMMER_0_94_4
) &&
2227 (osdmap
.get_up_osd_features() & CEPH_FEATURE_MON_METADATA
)) {
2228 mon
->clog
->info() << "disallowing boot of pre-hammer v0.94.4 OSD "
2229 << m
->get_orig_source_inst()
2230 << " because all up OSDs are post-hammer";
2236 if (osdmap
.is_up(from
) &&
2237 osdmap
.get_inst(from
) == m
->get_orig_source_inst() &&
2238 osdmap
.get_cluster_addr(from
) == m
->cluster_addr
) {
2240 dout(7) << "preprocess_boot dup from " << m
->get_orig_source_inst()
2241 << " == " << osdmap
.get_inst(from
) << dendl
;
2246 if (osdmap
.exists(from
) &&
2247 !osdmap
.get_uuid(from
).is_zero() &&
2248 osdmap
.get_uuid(from
) != m
->sb
.osd_fsid
) {
2249 dout(7) << __func__
<< " from " << m
->get_orig_source_inst()
2250 << " clashes with existing osd: different fsid"
2251 << " (ours: " << osdmap
.get_uuid(from
)
2252 << " ; theirs: " << m
->sb
.osd_fsid
<< ")" << dendl
;
2256 if (osdmap
.exists(from
) &&
2257 osdmap
.get_info(from
).up_from
> m
->version
&&
2258 osdmap
.get_most_recent_inst(from
) == m
->get_orig_source_inst()) {
2259 dout(7) << "prepare_boot msg from before last up_from, ignoring" << dendl
;
2260 send_latest(op
, m
->sb
.current_epoch
+1);
2265 if (!can_mark_up(from
)) {
2266 dout(7) << "preprocess_boot ignoring boot from " << m
->get_orig_source_inst() << dendl
;
2267 send_latest(op
, m
->sb
.current_epoch
+1);
2271 dout(10) << "preprocess_boot from " << m
->get_orig_source_inst() << dendl
;
2278 bool OSDMonitor::prepare_boot(MonOpRequestRef op
)
2280 op
->mark_osdmon_event(__func__
);
2281 MOSDBoot
*m
= static_cast<MOSDBoot
*>(op
->get_req());
2282 dout(7) << __func__
<< " from " << m
->get_orig_source_inst() << " sb " << m
->sb
2283 << " cluster_addr " << m
->cluster_addr
2284 << " hb_back_addr " << m
->hb_back_addr
2285 << " hb_front_addr " << m
->hb_front_addr
2288 assert(m
->get_orig_source().is_osd());
2289 int from
= m
->get_orig_source().num();
2291 // does this osd exist?
2292 if (from
>= osdmap
.get_max_osd()) {
2293 dout(1) << "boot from osd." << from
<< " >= max_osd "
2294 << osdmap
.get_max_osd() << dendl
;
2298 int oldstate
= osdmap
.exists(from
) ? osdmap
.get_state(from
) : CEPH_OSD_NEW
;
2299 if (pending_inc
.new_state
.count(from
))
2300 oldstate
^= pending_inc
.new_state
[from
];
2302 // already up? mark down first?
2303 if (osdmap
.is_up(from
)) {
2304 dout(7) << __func__
<< " was up, first marking down "
2305 << osdmap
.get_inst(from
) << dendl
;
2306 // preprocess should have caught these; if not, assert.
2307 assert(osdmap
.get_inst(from
) != m
->get_orig_source_inst() ||
2308 osdmap
.get_cluster_addr(from
) != m
->cluster_addr
);
2309 assert(osdmap
.get_uuid(from
) == m
->sb
.osd_fsid
);
2311 if (pending_inc
.new_state
.count(from
) == 0 ||
2312 (pending_inc
.new_state
[from
] & CEPH_OSD_UP
) == 0) {
2313 // mark previous guy down
2314 pending_inc
.new_state
[from
] = CEPH_OSD_UP
;
2316 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
2317 } else if (pending_inc
.new_up_client
.count(from
)) {
2318 // already prepared, just wait
2319 dout(7) << __func__
<< " already prepared, waiting on "
2320 << m
->get_orig_source_addr() << dendl
;
2321 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
2324 pending_inc
.new_up_client
[from
] = m
->get_orig_source_addr();
2325 if (!m
->cluster_addr
.is_blank_ip())
2326 pending_inc
.new_up_cluster
[from
] = m
->cluster_addr
;
2327 pending_inc
.new_hb_back_up
[from
] = m
->hb_back_addr
;
2328 if (!m
->hb_front_addr
.is_blank_ip())
2329 pending_inc
.new_hb_front_up
[from
] = m
->hb_front_addr
;
2331 down_pending_out
.erase(from
); // if any
2334 osd_weight
[from
] = m
->sb
.weight
;
2337 dout(10) << " setting osd." << from
<< " uuid to " << m
->sb
.osd_fsid
2339 if (!osdmap
.exists(from
) || osdmap
.get_uuid(from
) != m
->sb
.osd_fsid
) {
2340 // preprocess should have caught this; if not, assert.
2341 assert(!osdmap
.exists(from
) || osdmap
.get_uuid(from
).is_zero());
2342 pending_inc
.new_uuid
[from
] = m
->sb
.osd_fsid
;
2346 if (m
->sb
.newest_map
== 0 && osdmap
.exists(from
)) {
2347 const osd_info_t
& i
= osdmap
.get_info(from
);
2348 if (i
.up_from
> i
.lost_at
) {
2349 dout(10) << " fresh osd; marking lost_at too" << dendl
;
2350 pending_inc
.new_lost
[from
] = osdmap
.get_epoch();
2355 bufferlist osd_metadata
;
2356 ::encode(m
->metadata
, osd_metadata
);
2357 pending_metadata
[from
] = osd_metadata
;
2358 pending_metadata_rm
.erase(from
);
2360 // adjust last clean unmount epoch?
2361 const osd_info_t
& info
= osdmap
.get_info(from
);
2362 dout(10) << " old osd_info: " << info
<< dendl
;
2363 if (m
->sb
.mounted
> info
.last_clean_begin
||
2364 (m
->sb
.mounted
== info
.last_clean_begin
&&
2365 m
->sb
.clean_thru
> info
.last_clean_end
)) {
2366 epoch_t begin
= m
->sb
.mounted
;
2367 epoch_t end
= m
->sb
.clean_thru
;
2369 dout(10) << __func__
<< " osd." << from
<< " last_clean_interval "
2370 << "[" << info
.last_clean_begin
<< "," << info
.last_clean_end
2371 << ") -> [" << begin
<< "-" << end
<< ")"
2373 pending_inc
.new_last_clean_interval
[from
] =
2374 pair
<epoch_t
,epoch_t
>(begin
, end
);
2377 osd_xinfo_t xi
= osdmap
.get_xinfo(from
);
2378 if (m
->boot_epoch
== 0) {
2379 xi
.laggy_probability
*= (1.0 - g_conf
->mon_osd_laggy_weight
);
2380 xi
.laggy_interval
*= (1.0 - g_conf
->mon_osd_laggy_weight
);
2381 dout(10) << " not laggy, new xi " << xi
<< dendl
;
2383 if (xi
.down_stamp
.sec()) {
2384 int interval
= ceph_clock_now().sec() -
2385 xi
.down_stamp
.sec();
2386 if (g_conf
->mon_osd_laggy_max_interval
&&
2387 (interval
> g_conf
->mon_osd_laggy_max_interval
)) {
2388 interval
= g_conf
->mon_osd_laggy_max_interval
;
2391 interval
* g_conf
->mon_osd_laggy_weight
+
2392 xi
.laggy_interval
* (1.0 - g_conf
->mon_osd_laggy_weight
);
2394 xi
.laggy_probability
=
2395 g_conf
->mon_osd_laggy_weight
+
2396 xi
.laggy_probability
* (1.0 - g_conf
->mon_osd_laggy_weight
);
2397 dout(10) << " laggy, now xi " << xi
<< dendl
;
2400 // set features shared by the osd
2401 if (m
->osd_features
)
2402 xi
.features
= m
->osd_features
;
2404 xi
.features
= m
->get_connection()->get_features();
2407 if ((g_conf
->mon_osd_auto_mark_auto_out_in
&&
2408 (oldstate
& CEPH_OSD_AUTOOUT
)) ||
2409 (g_conf
->mon_osd_auto_mark_new_in
&& (oldstate
& CEPH_OSD_NEW
)) ||
2410 (g_conf
->mon_osd_auto_mark_in
)) {
2411 if (can_mark_in(from
)) {
2412 if (osdmap
.osd_xinfo
[from
].old_weight
> 0) {
2413 pending_inc
.new_weight
[from
] = osdmap
.osd_xinfo
[from
].old_weight
;
2416 pending_inc
.new_weight
[from
] = CEPH_OSD_IN
;
2419 dout(7) << __func__
<< " NOIN set, will not mark in "
2420 << m
->get_orig_source_addr() << dendl
;
2424 pending_inc
.new_xinfo
[from
] = xi
;
2427 wait_for_finished_proposal(op
, new C_Booted(this, op
));
2432 void OSDMonitor::_booted(MonOpRequestRef op
, bool logit
)
2434 op
->mark_osdmon_event(__func__
);
2435 MOSDBoot
*m
= static_cast<MOSDBoot
*>(op
->get_req());
2436 dout(7) << "_booted " << m
->get_orig_source_inst()
2437 << " w " << m
->sb
.weight
<< " from " << m
->sb
.current_epoch
<< dendl
;
2440 mon
->clog
->info() << m
->get_orig_source_inst() << " boot";
2443 send_latest(op
, m
->sb
.current_epoch
+1);
2450 bool OSDMonitor::preprocess_full(MonOpRequestRef op
)
2452 op
->mark_osdmon_event(__func__
);
2453 MOSDFull
*m
= static_cast<MOSDFull
*>(op
->get_req());
2454 int from
= m
->get_orig_source().num();
2456 unsigned mask
= CEPH_OSD_NEARFULL
| CEPH_OSD_BACKFILLFULL
| CEPH_OSD_FULL
;
2458 // check permissions, ignore if failed
2459 MonSession
*session
= m
->get_session();
2462 if (!session
->is_capable("osd", MON_CAP_X
)) {
2463 dout(0) << "MOSDFull from entity with insufficient privileges:"
2464 << session
->caps
<< dendl
;
2468 // ignore a full message from the osd instance that already went down
2469 if (!osdmap
.exists(from
)) {
2470 dout(7) << __func__
<< " ignoring full message from nonexistent "
2471 << m
->get_orig_source_inst() << dendl
;
2474 if ((!osdmap
.is_up(from
) &&
2475 osdmap
.get_most_recent_inst(from
) == m
->get_orig_source_inst()) ||
2476 (osdmap
.is_up(from
) &&
2477 osdmap
.get_inst(from
) != m
->get_orig_source_inst())) {
2478 dout(7) << __func__
<< " ignoring full message from down "
2479 << m
->get_orig_source_inst() << dendl
;
2483 OSDMap::calc_state_set(osdmap
.get_state(from
), state
);
2485 if ((osdmap
.get_state(from
) & mask
) == m
->state
) {
2486 dout(7) << __func__
<< " state already " << state
<< " for osd." << from
2487 << " " << m
->get_orig_source_inst() << dendl
;
2488 _reply_map(op
, m
->version
);
2492 dout(10) << __func__
<< " want state " << state
<< " for osd." << from
2493 << " " << m
->get_orig_source_inst() << dendl
;
2500 bool OSDMonitor::prepare_full(MonOpRequestRef op
)
2502 op
->mark_osdmon_event(__func__
);
2503 const MOSDFull
*m
= static_cast<MOSDFull
*>(op
->get_req());
2504 const int from
= m
->get_orig_source().num();
2506 const unsigned mask
= CEPH_OSD_NEARFULL
| CEPH_OSD_BACKFILLFULL
| CEPH_OSD_FULL
;
2507 const unsigned want_state
= m
->state
& mask
; // safety first
2509 unsigned cur_state
= osdmap
.get_state(from
);
2510 auto p
= pending_inc
.new_state
.find(from
);
2511 if (p
!= pending_inc
.new_state
.end()) {
2512 cur_state
^= p
->second
;
2516 set
<string
> want_state_set
, cur_state_set
;
2517 OSDMap::calc_state_set(want_state
, want_state_set
);
2518 OSDMap::calc_state_set(cur_state
, cur_state_set
);
2520 if (cur_state
!= want_state
) {
2521 if (p
!= pending_inc
.new_state
.end()) {
2524 pending_inc
.new_state
[from
] = 0;
2526 pending_inc
.new_state
[from
] |= (osdmap
.get_state(from
) & mask
) ^ want_state
;
2527 dout(7) << __func__
<< " osd." << from
<< " " << cur_state_set
2528 << " -> " << want_state_set
<< dendl
;
2530 dout(7) << __func__
<< " osd." << from
<< " " << cur_state_set
2531 << " = wanted " << want_state_set
<< ", just waiting" << dendl
;
2534 wait_for_finished_proposal(op
, new C_ReplyMap(this, op
, m
->version
));
2541 bool OSDMonitor::preprocess_alive(MonOpRequestRef op
)
2543 op
->mark_osdmon_event(__func__
);
2544 MOSDAlive
*m
= static_cast<MOSDAlive
*>(op
->get_req());
2545 int from
= m
->get_orig_source().num();
2547 // check permissions, ignore if failed
2548 MonSession
*session
= m
->get_session();
2551 if (!session
->is_capable("osd", MON_CAP_X
)) {
2552 dout(0) << "attempt to send MOSDAlive from entity with insufficient privileges:"
2553 << session
->caps
<< dendl
;
2557 if (!osdmap
.is_up(from
) ||
2558 osdmap
.get_inst(from
) != m
->get_orig_source_inst()) {
2559 dout(7) << "preprocess_alive ignoring alive message from down " << m
->get_orig_source_inst() << dendl
;
2563 if (osdmap
.get_up_thru(from
) >= m
->want
) {
2565 dout(7) << "preprocess_alive want up_thru " << m
->want
<< " dup from " << m
->get_orig_source_inst() << dendl
;
2566 _reply_map(op
, m
->version
);
2570 dout(10) << "preprocess_alive want up_thru " << m
->want
2571 << " from " << m
->get_orig_source_inst() << dendl
;
2578 bool OSDMonitor::prepare_alive(MonOpRequestRef op
)
2580 op
->mark_osdmon_event(__func__
);
2581 MOSDAlive
*m
= static_cast<MOSDAlive
*>(op
->get_req());
2582 int from
= m
->get_orig_source().num();
2584 if (0) { // we probably don't care much about these
2585 mon
->clog
->debug() << m
->get_orig_source_inst() << " alive";
2588 dout(7) << "prepare_alive want up_thru " << m
->want
<< " have " << m
->version
2589 << " from " << m
->get_orig_source_inst() << dendl
;
2591 update_up_thru(from
, m
->version
); // set to the latest map the OSD has
2592 wait_for_finished_proposal(op
, new C_ReplyMap(this, op
, m
->version
));
2596 void OSDMonitor::_reply_map(MonOpRequestRef op
, epoch_t e
)
2598 op
->mark_osdmon_event(__func__
);
2599 dout(7) << "_reply_map " << e
2600 << " from " << op
->get_req()->get_orig_source_inst()
2606 bool OSDMonitor::preprocess_pg_created(MonOpRequestRef op
)
2608 op
->mark_osdmon_event(__func__
);
2609 auto m
= static_cast<MOSDPGCreated
*>(op
->get_req());
2610 dout(10) << __func__
<< " " << *m
<< dendl
;
2611 auto session
= m
->get_session();
2613 dout(10) << __func__
<< ": no monitor session!" << dendl
;
2616 if (!session
->is_capable("osd", MON_CAP_X
)) {
2617 derr
<< __func__
<< " received from entity "
2618 << "with insufficient privileges " << session
->caps
<< dendl
;
2621 // always forward the "created!" to the leader
2625 bool OSDMonitor::prepare_pg_created(MonOpRequestRef op
)
2627 op
->mark_osdmon_event(__func__
);
2628 auto m
= static_cast<MOSDPGCreated
*>(op
->get_req());
2629 dout(10) << __func__
<< " " << *m
<< dendl
;
2630 auto src
= m
->get_orig_source();
2631 auto from
= src
.num();
2632 if (!src
.is_osd() ||
2633 !mon
->osdmon()->osdmap
.is_up(from
) ||
2634 m
->get_orig_source_inst() != mon
->osdmon()->osdmap
.get_inst(from
)) {
2635 dout(1) << __func__
<< " ignoring stats from non-active osd." << dendl
;
2638 pending_created_pgs
.push_back(m
->pgid
);
2645 bool OSDMonitor::preprocess_pgtemp(MonOpRequestRef op
)
2647 MOSDPGTemp
*m
= static_cast<MOSDPGTemp
*>(op
->get_req());
2648 dout(10) << "preprocess_pgtemp " << *m
<< dendl
;
2649 mempool::osdmap::vector
<int> empty
;
2650 int from
= m
->get_orig_source().num();
2651 size_t ignore_cnt
= 0;
2654 MonSession
*session
= m
->get_session();
2657 if (!session
->is_capable("osd", MON_CAP_X
)) {
2658 dout(0) << "attempt to send MOSDPGTemp from entity with insufficient caps "
2659 << session
->caps
<< dendl
;
2663 if (!osdmap
.is_up(from
) ||
2664 osdmap
.get_inst(from
) != m
->get_orig_source_inst()) {
2665 dout(7) << "ignoring pgtemp message from down " << m
->get_orig_source_inst() << dendl
;
2669 for (auto p
= m
->pg_temp
.begin(); p
!= m
->pg_temp
.end(); ++p
) {
2670 dout(20) << " " << p
->first
2671 << (osdmap
.pg_temp
->count(p
->first
) ? osdmap
.pg_temp
->get(p
->first
) : empty
)
2672 << " -> " << p
->second
<< dendl
;
2674 // does the pool exist?
2675 if (!osdmap
.have_pg_pool(p
->first
.pool())) {
2677 * 1. If the osdmap does not have the pool, it means the pool has been
2678 * removed in-between the osd sending this message and us handling it.
2679 * 2. If osdmap doesn't have the pool, it is safe to assume the pool does
2680 * not exist in the pending either, as the osds would not send a
2681 * message about a pool they know nothing about (yet).
2682 * 3. However, if the pool does exist in the pending, then it must be a
2683 * new pool, and not relevant to this message (see 1).
2685 dout(10) << __func__
<< " ignore " << p
->first
<< " -> " << p
->second
2686 << ": pool has been removed" << dendl
;
2691 int acting_primary
= -1;
2692 osdmap
.pg_to_up_acting_osds(
2693 p
->first
, nullptr, nullptr, nullptr, &acting_primary
);
2694 if (acting_primary
!= from
) {
2695 /* If the source isn't the primary based on the current osdmap, we know
2696 * that the interval changed and that we can discard this message.
2697 * Indeed, we must do so to avoid 16127 since we can't otherwise determine
2698 * which of two pg temp mappings on the same pg is more recent.
2700 dout(10) << __func__
<< " ignore " << p
->first
<< " -> " << p
->second
2701 << ": primary has changed" << dendl
;
2707 if (p
->second
.empty() && (osdmap
.pg_temp
->count(p
->first
) ||
2708 osdmap
.primary_temp
->count(p
->first
)))
2711 // NOTE: we assume that this will clear pg_primary, so consider
2712 // an existing pg_primary field to imply a change
2713 if (p
->second
.size() &&
2714 (osdmap
.pg_temp
->count(p
->first
) == 0 ||
2715 !vectors_equal(osdmap
.pg_temp
->get(p
->first
), p
->second
) ||
2716 osdmap
.primary_temp
->count(p
->first
)))
2720 // should we ignore all the pgs?
2721 if (ignore_cnt
== m
->pg_temp
.size())
2724 dout(7) << "preprocess_pgtemp e" << m
->map_epoch
<< " no changes from " << m
->get_orig_source_inst() << dendl
;
2725 _reply_map(op
, m
->map_epoch
);
2732 void OSDMonitor::update_up_thru(int from
, epoch_t up_thru
)
2734 epoch_t old_up_thru
= osdmap
.get_up_thru(from
);
2735 auto ut
= pending_inc
.new_up_thru
.find(from
);
2736 if (ut
!= pending_inc
.new_up_thru
.end()) {
2737 old_up_thru
= ut
->second
;
2739 if (up_thru
> old_up_thru
) {
2740 // set up_thru too, so the osd doesn't have to ask again
2741 pending_inc
.new_up_thru
[from
] = up_thru
;
2745 bool OSDMonitor::prepare_pgtemp(MonOpRequestRef op
)
2747 op
->mark_osdmon_event(__func__
);
2748 MOSDPGTemp
*m
= static_cast<MOSDPGTemp
*>(op
->get_req());
2749 int from
= m
->get_orig_source().num();
2750 dout(7) << "prepare_pgtemp e" << m
->map_epoch
<< " from " << m
->get_orig_source_inst() << dendl
;
2751 for (map
<pg_t
,vector
<int32_t> >::iterator p
= m
->pg_temp
.begin(); p
!= m
->pg_temp
.end(); ++p
) {
2752 uint64_t pool
= p
->first
.pool();
2753 if (pending_inc
.old_pools
.count(pool
)) {
2754 dout(10) << __func__
<< " ignore " << p
->first
<< " -> " << p
->second
2755 << ": pool pending removal" << dendl
;
2758 if (!osdmap
.have_pg_pool(pool
)) {
2759 dout(10) << __func__
<< " ignore " << p
->first
<< " -> " << p
->second
2760 << ": pool has been removed" << dendl
;
2763 pending_inc
.new_pg_temp
[p
->first
] =
2764 mempool::osdmap::vector
<int>(p
->second
.begin(), p
->second
.end());
2766 // unconditionally clear pg_primary (until this message can encode
2767 // a change for that, too.. at which point we need to also fix
2768 // preprocess_pg_temp)
2769 if (osdmap
.primary_temp
->count(p
->first
) ||
2770 pending_inc
.new_primary_temp
.count(p
->first
))
2771 pending_inc
.new_primary_temp
[p
->first
] = -1;
2774 // set up_thru too, so the osd doesn't have to ask again
2775 update_up_thru(from
, m
->map_epoch
);
2777 wait_for_finished_proposal(op
, new C_ReplyMap(this, op
, m
->map_epoch
));
2784 bool OSDMonitor::preprocess_remove_snaps(MonOpRequestRef op
)
2786 op
->mark_osdmon_event(__func__
);
2787 MRemoveSnaps
*m
= static_cast<MRemoveSnaps
*>(op
->get_req());
2788 dout(7) << "preprocess_remove_snaps " << *m
<< dendl
;
2790 // check privilege, ignore if failed
2791 MonSession
*session
= m
->get_session();
2794 if (!session
->caps
.is_capable(
2796 CEPH_ENTITY_TYPE_MON
,
2797 session
->entity_name
,
2798 "osd", "osd pool rmsnap", {}, true, true, false)) {
2799 dout(0) << "got preprocess_remove_snaps from entity with insufficient caps "
2800 << session
->caps
<< dendl
;
2804 for (map
<int, vector
<snapid_t
> >::iterator q
= m
->snaps
.begin();
2805 q
!= m
->snaps
.end();
2807 if (!osdmap
.have_pg_pool(q
->first
)) {
2808 dout(10) << " ignoring removed_snaps " << q
->second
<< " on non-existent pool " << q
->first
<< dendl
;
2811 const pg_pool_t
*pi
= osdmap
.get_pg_pool(q
->first
);
2812 for (vector
<snapid_t
>::iterator p
= q
->second
.begin();
2813 p
!= q
->second
.end();
2815 if (*p
> pi
->get_snap_seq() ||
2816 !pi
->removed_snaps
.contains(*p
))
2825 bool OSDMonitor::prepare_remove_snaps(MonOpRequestRef op
)
2827 op
->mark_osdmon_event(__func__
);
2828 MRemoveSnaps
*m
= static_cast<MRemoveSnaps
*>(op
->get_req());
2829 dout(7) << "prepare_remove_snaps " << *m
<< dendl
;
2831 for (map
<int, vector
<snapid_t
> >::iterator p
= m
->snaps
.begin();
2832 p
!= m
->snaps
.end();
2835 if (!osdmap
.have_pg_pool(p
->first
)) {
2836 dout(10) << " ignoring removed_snaps " << p
->second
<< " on non-existent pool " << p
->first
<< dendl
;
2840 pg_pool_t
& pi
= osdmap
.pools
[p
->first
];
2841 for (vector
<snapid_t
>::iterator q
= p
->second
.begin();
2842 q
!= p
->second
.end();
2844 if (!pi
.removed_snaps
.contains(*q
) &&
2845 (!pending_inc
.new_pools
.count(p
->first
) ||
2846 !pending_inc
.new_pools
[p
->first
].removed_snaps
.contains(*q
))) {
2847 pg_pool_t
*newpi
= pending_inc
.get_new_pool(p
->first
, &pi
);
2848 newpi
->removed_snaps
.insert(*q
);
2849 dout(10) << " pool " << p
->first
<< " removed_snaps added " << *q
2850 << " (now " << newpi
->removed_snaps
<< ")" << dendl
;
2851 if (*q
> newpi
->get_snap_seq()) {
2852 dout(10) << " pool " << p
->first
<< " snap_seq " << newpi
->get_snap_seq() << " -> " << *q
<< dendl
;
2853 newpi
->set_snap_seq(*q
);
2855 newpi
->set_snap_epoch(pending_inc
.epoch
);
2863 bool OSDMonitor::preprocess_beacon(MonOpRequestRef op
)
2865 op
->mark_osdmon_event(__func__
);
2866 auto beacon
= static_cast<MOSDBeacon
*>(op
->get_req());
2868 auto session
= beacon
->get_session();
2870 dout(10) << __func__
<< " no monitor session!" << dendl
;
2873 if (!session
->is_capable("osd", MON_CAP_X
)) {
2874 derr
<< __func__
<< " received from entity "
2875 << "with insufficient privileges " << session
->caps
<< dendl
;
2878 // Always forward the beacon to the leader, even if they are the same as
2879 // the old one. The leader will mark as down osds that haven't sent
2880 // beacon for a few minutes.
2884 bool OSDMonitor::prepare_beacon(MonOpRequestRef op
)
2886 op
->mark_osdmon_event(__func__
);
2887 const auto beacon
= static_cast<MOSDBeacon
*>(op
->get_req());
2888 const auto src
= beacon
->get_orig_source();
2889 dout(10) << __func__
<< " " << *beacon
2890 << " from " << src
<< dendl
;
2891 int from
= src
.num();
2893 if (!src
.is_osd() ||
2894 !osdmap
.is_up(from
) ||
2895 beacon
->get_orig_source_inst() != osdmap
.get_inst(from
)) {
2896 dout(1) << " ignoring beacon from non-active osd." << dendl
;
2900 last_osd_report
[from
] = ceph_clock_now();
2901 osd_epochs
[from
] = beacon
->version
;
2903 for (const auto& pg
: beacon
->pgs
) {
2904 last_epoch_clean
.report(pg
, beacon
->min_last_epoch_clean
);
2912 void OSDMonitor::send_latest(MonOpRequestRef op
, epoch_t start
)
2914 op
->mark_osdmon_event(__func__
);
2915 dout(5) << "send_latest to " << op
->get_req()->get_orig_source_inst()
2916 << " start " << start
<< dendl
;
2920 send_incremental(op
, start
);
2924 MOSDMap
*OSDMonitor::build_latest_full()
2926 MOSDMap
*r
= new MOSDMap(mon
->monmap
->fsid
);
2927 get_version_full(osdmap
.get_epoch(), r
->maps
[osdmap
.get_epoch()]);
2928 r
->oldest_map
= get_first_committed();
2929 r
->newest_map
= osdmap
.get_epoch();
2933 MOSDMap
*OSDMonitor::build_incremental(epoch_t from
, epoch_t to
)
2935 dout(10) << "build_incremental [" << from
<< ".." << to
<< "]" << dendl
;
2936 MOSDMap
*m
= new MOSDMap(mon
->monmap
->fsid
);
2937 m
->oldest_map
= get_first_committed();
2938 m
->newest_map
= osdmap
.get_epoch();
2940 for (epoch_t e
= to
; e
>= from
&& e
> 0; e
--) {
2942 int err
= get_version(e
, bl
);
2944 assert(bl
.length());
2945 // if (get_version(e, bl) > 0) {
2946 dout(20) << "build_incremental inc " << e
<< " "
2947 << bl
.length() << " bytes" << dendl
;
2948 m
->incremental_maps
[e
] = bl
;
2950 assert(err
== -ENOENT
);
2951 assert(!bl
.length());
2952 get_version_full(e
, bl
);
2953 if (bl
.length() > 0) {
2954 //else if (get_version("full", e, bl) > 0) {
2955 dout(20) << "build_incremental full " << e
<< " "
2956 << bl
.length() << " bytes" << dendl
;
2959 ceph_abort(); // we should have all maps.
2966 void OSDMonitor::send_full(MonOpRequestRef op
)
2968 op
->mark_osdmon_event(__func__
);
2969 dout(5) << "send_full to " << op
->get_req()->get_orig_source_inst() << dendl
;
2970 mon
->send_reply(op
, build_latest_full());
2973 void OSDMonitor::send_incremental(MonOpRequestRef op
, epoch_t first
)
2975 op
->mark_osdmon_event(__func__
);
2977 MonSession
*s
= op
->get_session();
2981 s
->proxy_con
->has_feature(CEPH_FEATURE_MON_ROUTE_OSDMAP
)) {
2982 // oh, we can tell the other mon to do it
2983 dout(10) << __func__
<< " asking proxying mon to send_incremental from "
2985 MRoute
*r
= new MRoute(s
->proxy_tid
, NULL
);
2986 r
->send_osdmap_first
= first
;
2987 s
->proxy_con
->send_message(r
);
2988 op
->mark_event("reply: send routed send_osdmap_first reply");
2991 send_incremental(first
, s
, false, op
);
2995 void OSDMonitor::send_incremental(epoch_t first
,
2996 MonSession
*session
,
2998 MonOpRequestRef req
)
3000 dout(5) << "send_incremental [" << first
<< ".." << osdmap
.get_epoch() << "]"
3001 << " to " << session
->inst
<< dendl
;
3003 if (first
<= session
->osd_epoch
) {
3004 dout(10) << __func__
<< " " << session
->inst
<< " should already have epoch "
3005 << session
->osd_epoch
<< dendl
;
3006 first
= session
->osd_epoch
+ 1;
3009 if (first
< get_first_committed()) {
3010 first
= get_first_committed();
3012 int err
= get_version_full(first
, bl
);
3014 assert(bl
.length());
3016 dout(20) << "send_incremental starting with base full "
3017 << first
<< " " << bl
.length() << " bytes" << dendl
;
3019 MOSDMap
*m
= new MOSDMap(osdmap
.get_fsid());
3020 m
->oldest_map
= get_first_committed();
3021 m
->newest_map
= osdmap
.get_epoch();
3022 m
->maps
[first
] = bl
;
3025 mon
->send_reply(req
, m
);
3026 session
->osd_epoch
= first
;
3029 session
->con
->send_message(m
);
3030 session
->osd_epoch
= first
;
3035 while (first
<= osdmap
.get_epoch()) {
3036 epoch_t last
= MIN(first
+ g_conf
->osd_map_message_max
- 1,
3037 osdmap
.get_epoch());
3038 MOSDMap
*m
= build_incremental(first
, last
);
3041 // send some maps. it may not be all of them, but it will get them
3043 mon
->send_reply(req
, m
);
3045 session
->con
->send_message(m
);
3048 session
->osd_epoch
= last
;
3054 int OSDMonitor::get_version(version_t ver
, bufferlist
& bl
)
3056 if (inc_osd_cache
.lookup(ver
, &bl
)) {
3059 int ret
= PaxosService::get_version(ver
, bl
);
3061 inc_osd_cache
.add(ver
, bl
);
3066 int OSDMonitor::get_version_full(version_t ver
, bufferlist
& bl
)
3068 if (full_osd_cache
.lookup(ver
, &bl
)) {
3071 int ret
= PaxosService::get_version_full(ver
, bl
);
3073 full_osd_cache
.add(ver
, bl
);
3078 epoch_t
OSDMonitor::blacklist(const entity_addr_t
& a
, utime_t until
)
3080 dout(10) << "blacklist " << a
<< " until " << until
<< dendl
;
3081 pending_inc
.new_blacklist
[a
] = until
;
3082 return pending_inc
.epoch
;
3086 void OSDMonitor::check_osdmap_subs()
3088 dout(10) << __func__
<< dendl
;
3089 if (!osdmap
.get_epoch()) {
3092 auto osdmap_subs
= mon
->session_map
.subs
.find("osdmap");
3093 if (osdmap_subs
== mon
->session_map
.subs
.end()) {
3096 auto p
= osdmap_subs
->second
->begin();
3100 check_osdmap_sub(sub
);
3104 void OSDMonitor::check_osdmap_sub(Subscription
*sub
)
3106 dout(10) << __func__
<< " " << sub
<< " next " << sub
->next
3107 << (sub
->onetime
? " (onetime)":" (ongoing)") << dendl
;
3108 if (sub
->next
<= osdmap
.get_epoch()) {
3110 send_incremental(sub
->next
, sub
->session
, sub
->incremental_onetime
);
3112 sub
->session
->con
->send_message(build_latest_full());
3114 mon
->session_map
.remove_sub(sub
);
3116 sub
->next
= osdmap
.get_epoch() + 1;
3120 void OSDMonitor::check_pg_creates_subs()
3122 if (!mon
->monmap
->get_required_features().contains_all(
3123 ceph::features::mon::FEATURE_LUMINOUS
)) {
3124 // PGMonitor takes care of this in pre-luminous era.
3127 if (!osdmap
.get_num_up_osds()) {
3130 assert(osdmap
.get_up_osd_features() & CEPH_FEATURE_MON_STATEFUL_SUB
);
3131 mon
->with_session_map([this](const MonSessionMap
& session_map
) {
3132 auto pg_creates_subs
= session_map
.subs
.find("osd_pg_creates");
3133 if (pg_creates_subs
== session_map
.subs
.end()) {
3136 for (auto sub
: *pg_creates_subs
->second
) {
3137 check_pg_creates_sub(sub
);
3142 void OSDMonitor::check_pg_creates_sub(Subscription
*sub
)
3144 dout(20) << __func__
<< " .. " << sub
->session
->inst
<< dendl
;
3145 assert(sub
->type
== "osd_pg_creates");
3146 // only send these if the OSD is up. we will check_subs() when they do
3147 // come up so they will get the creates then.
3148 if (sub
->session
->inst
.name
.is_osd() &&
3149 mon
->osdmon()->osdmap
.is_up(sub
->session
->inst
.name
.num())) {
3150 sub
->next
= send_pg_creates(sub
->session
->inst
.name
.num(),
3151 sub
->session
->con
.get(),
3156 void OSDMonitor::do_application_enable(int64_t pool_id
,
3157 const std::string
&app_name
)
3159 assert(paxos
->is_plugged());
3161 dout(20) << __func__
<< ": pool_id=" << pool_id
<< ", app_name=" << app_name
3164 auto pp
= osdmap
.get_pg_pool(pool_id
);
3165 assert(pp
!= nullptr);
3168 if (pending_inc
.new_pools
.count(pool_id
)) {
3169 p
= pending_inc
.new_pools
[pool_id
];
3172 p
.application_metadata
.insert({app_name
, {}});
3173 p
.last_change
= pending_inc
.epoch
;
3174 pending_inc
.new_pools
[pool_id
] = p
;
3177 unsigned OSDMonitor::scan_for_creating_pgs(
3178 const mempool::osdmap::map
<int64_t,pg_pool_t
>& pools
,
3179 const mempool::osdmap::set
<int64_t>& removed_pools
,
3181 creating_pgs_t
* creating_pgs
) const
3183 unsigned queued
= 0;
3184 for (auto& p
: pools
) {
3185 int64_t poolid
= p
.first
;
3186 const pg_pool_t
& pool
= p
.second
;
3187 int ruleno
= osdmap
.crush
->find_rule(pool
.get_crush_rule(),
3188 pool
.get_type(), pool
.get_size());
3189 if (ruleno
< 0 || !osdmap
.crush
->rule_exists(ruleno
))
3192 const auto last_scan_epoch
= creating_pgs
->last_scan_epoch
;
3193 const auto created
= pool
.get_last_change();
3194 if (last_scan_epoch
&& created
<= last_scan_epoch
) {
3195 dout(10) << __func__
<< " no change in pool " << poolid
3196 << " " << pool
<< dendl
;
3199 if (removed_pools
.count(poolid
)) {
3200 dout(10) << __func__
<< " pool is being removed: " << poolid
3201 << " " << pool
<< dendl
;
3204 dout(10) << __func__
<< " queueing pool create for " << poolid
3205 << " " << pool
<< dendl
;
3206 if (creating_pgs
->create_pool(poolid
, pool
.get_pg_num(),
3207 created
, modified
)) {
3214 void OSDMonitor::update_creating_pgs()
3216 dout(10) << __func__
<< " " << creating_pgs
.pgs
.size() << " pgs creating, "
3217 << creating_pgs
.queue
.size() << " pools in queue" << dendl
;
3218 decltype(creating_pgs_by_osd_epoch
) new_pgs_by_osd_epoch
;
3219 std::lock_guard
<std::mutex
> l(creating_pgs_lock
);
3220 for (const auto& pg
: creating_pgs
.pgs
) {
3221 int acting_primary
= -1;
3222 auto pgid
= pg
.first
;
3223 auto mapped
= pg
.second
.first
;
3224 dout(20) << __func__
<< " looking up " << pgid
<< "@" << mapped
<< dendl
;
3225 mapping
.get(pgid
, nullptr, nullptr, nullptr, &acting_primary
);
3226 // check the previous creating_pgs, look for the target to whom the pg was
3227 // previously mapped
3228 for (const auto& pgs_by_epoch
: creating_pgs_by_osd_epoch
) {
3229 const auto last_acting_primary
= pgs_by_epoch
.first
;
3230 for (auto& pgs
: pgs_by_epoch
.second
) {
3231 if (pgs
.second
.count(pgid
)) {
3232 if (last_acting_primary
== acting_primary
) {
3235 dout(20) << __func__
<< " " << pgid
<< " "
3236 << " acting_primary:" << last_acting_primary
3237 << " -> " << acting_primary
<< dendl
;
3238 // note epoch if the target of the create message changed.
3239 mapped
= mapping
.get_epoch();
3244 mapped
= mapping
.get_epoch();
3248 dout(10) << __func__
<< " will instruct osd." << acting_primary
3249 << " to create " << pgid
<< "@" << mapped
<< dendl
;
3250 new_pgs_by_osd_epoch
[acting_primary
][mapped
].insert(pgid
);
3252 creating_pgs_by_osd_epoch
= std::move(new_pgs_by_osd_epoch
);
3253 creating_pgs_epoch
= mapping
.get_epoch();
3256 epoch_t
OSDMonitor::send_pg_creates(int osd
, Connection
*con
, epoch_t next
) const
3258 dout(30) << __func__
<< " osd." << osd
<< " next=" << next
3259 << " " << creating_pgs_by_osd_epoch
<< dendl
;
3260 std::lock_guard
<std::mutex
> l(creating_pgs_lock
);
3261 auto creating_pgs_by_epoch
= creating_pgs_by_osd_epoch
.find(osd
);
3262 if (creating_pgs_by_epoch
== creating_pgs_by_osd_epoch
.end())
3264 assert(!creating_pgs_by_epoch
->second
.empty());
3266 MOSDPGCreate
*m
= nullptr;
3268 for (auto epoch_pgs
= creating_pgs_by_epoch
->second
.lower_bound(next
);
3269 epoch_pgs
!= creating_pgs_by_epoch
->second
.end(); ++epoch_pgs
) {
3270 auto epoch
= epoch_pgs
->first
;
3271 auto& pgs
= epoch_pgs
->second
;
3272 dout(20) << __func__
<< " osd." << osd
<< " from " << next
3273 << " : epoch " << epoch
<< " " << pgs
.size() << " pgs" << dendl
;
3275 for (auto& pg
: pgs
) {
3277 m
= new MOSDPGCreate(creating_pgs_epoch
);
3278 // Need the create time from the monitor using its clock to set
3279 // last_scrub_stamp upon pg creation.
3280 auto create
= creating_pgs
.pgs
.find(pg
);
3281 assert(create
!= creating_pgs
.pgs
.end());
3282 m
->mkpg
.emplace(pg
, pg_create_t
{create
->second
.first
, pg
, 0});
3283 m
->ctimes
.emplace(pg
, create
->second
.second
);
3284 dout(20) << __func__
<< " will create " << pg
3285 << " at " << create
->second
.first
<< dendl
;
3289 dout(20) << __func__
<< " osd." << osd
<< " from " << next
3290 << " has nothing to send" << dendl
;
3293 con
->send_message(m
);
3294 // sub is current through last + 1
3301 void OSDMonitor::tick()
3303 if (!is_active()) return;
3305 dout(10) << osdmap
<< dendl
;
3307 if (!mon
->is_leader()) return;
3309 bool do_propose
= false;
3310 utime_t now
= ceph_clock_now();
3312 if (osdmap
.require_osd_release
>= CEPH_RELEASE_LUMINOUS
&&
3313 mon
->monmap
->get_required_features().contains_all(
3314 ceph::features::mon::FEATURE_LUMINOUS
)) {
3315 if (handle_osd_timeouts(now
, last_osd_report
)) {
3321 if (check_failures(now
))
3324 // mark down osds out?
3326 /* can_mark_out() checks if we can mark osds as being out. The -1 has no
3327 * influence at all. The decision is made based on the ratio of "in" osds,
3328 * and the function returns false if this ratio is lower that the minimum
3329 * ratio set by g_conf->mon_osd_min_in_ratio. So it's not really up to us.
3331 if (can_mark_out(-1)) {
3332 set
<int> down_cache
; // quick cache of down subtrees
3334 map
<int,utime_t
>::iterator i
= down_pending_out
.begin();
3335 while (i
!= down_pending_out
.end()) {
3341 if (osdmap
.is_down(o
) &&
3344 utime_t
orig_grace(g_conf
->mon_osd_down_out_interval
, 0);
3345 utime_t grace
= orig_grace
;
3346 double my_grace
= 0.0;
3348 if (g_conf
->mon_osd_adjust_down_out_interval
) {
3349 // scale grace period the same way we do the heartbeat grace.
3350 const osd_xinfo_t
& xi
= osdmap
.get_xinfo(o
);
3351 double halflife
= (double)g_conf
->mon_osd_laggy_halflife
;
3352 double decay_k
= ::log(.5) / halflife
;
3353 double decay
= exp((double)down
* decay_k
);
3354 dout(20) << "osd." << o
<< " laggy halflife " << halflife
<< " decay_k " << decay_k
3355 << " down for " << down
<< " decay " << decay
<< dendl
;
3356 my_grace
= decay
* (double)xi
.laggy_interval
* xi
.laggy_probability
;
3360 // is this an entire large subtree down?
3361 if (g_conf
->mon_osd_down_out_subtree_limit
.length()) {
3362 int type
= osdmap
.crush
->get_type_id(g_conf
->mon_osd_down_out_subtree_limit
);
3364 if (osdmap
.containing_subtree_is_down(g_ceph_context
, o
, type
, &down_cache
)) {
3365 dout(10) << "tick entire containing " << g_conf
->mon_osd_down_out_subtree_limit
3366 << " subtree for osd." << o
<< " is down; resetting timer" << dendl
;
3367 // reset timer, too.
3368 down_pending_out
[o
] = now
;
3374 bool down_out
= !osdmap
.is_destroyed(o
) &&
3375 g_conf
->mon_osd_down_out_interval
> 0 && down
.sec() >= grace
;
3376 bool destroyed_out
= osdmap
.is_destroyed(o
) &&
3377 g_conf
->mon_osd_destroyed_out_interval
> 0 &&
3378 // this is not precise enough as we did not make a note when this osd
3379 // was marked as destroyed, but let's not bother with that
3380 // complexity for now.
3381 down
.sec() >= g_conf
->mon_osd_destroyed_out_interval
;
3382 if (down_out
|| destroyed_out
) {
3383 dout(10) << "tick marking osd." << o
<< " OUT after " << down
3384 << " sec (target " << grace
<< " = " << orig_grace
<< " + " << my_grace
<< ")" << dendl
;
3385 pending_inc
.new_weight
[o
] = CEPH_OSD_OUT
;
3387 // set the AUTOOUT bit.
3388 if (pending_inc
.new_state
.count(o
) == 0)
3389 pending_inc
.new_state
[o
] = 0;
3390 pending_inc
.new_state
[o
] |= CEPH_OSD_AUTOOUT
;
3392 // remember previous weight
3393 if (pending_inc
.new_xinfo
.count(o
) == 0)
3394 pending_inc
.new_xinfo
[o
] = osdmap
.osd_xinfo
[o
];
3395 pending_inc
.new_xinfo
[o
].old_weight
= osdmap
.osd_weight
[o
];
3399 mon
->clog
->info() << "Marking osd." << o
<< " out (has been down for "
3400 << int(down
.sec()) << " seconds)";
3405 down_pending_out
.erase(o
);
3408 dout(10) << "tick NOOUT flag set, not checking down osds" << dendl
;
3411 // expire blacklisted items?
3412 for (ceph::unordered_map
<entity_addr_t
,utime_t
>::iterator p
= osdmap
.blacklist
.begin();
3413 p
!= osdmap
.blacklist
.end();
3415 if (p
->second
< now
) {
3416 dout(10) << "expiring blacklist item " << p
->first
<< " expired " << p
->second
<< " < now " << now
<< dendl
;
3417 pending_inc
.old_blacklist
.push_back(p
->first
);
3422 // if map full setting has changed, get that info out there!
3423 if (osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
&&
3424 mon
->pgservice
->is_readable()) {
3425 // for pre-luminous compat only!
3426 if (mon
->pgservice
->have_full_osds()) {
3427 dout(5) << "There are full osds, setting full flag" << dendl
;
3428 add_flag(CEPH_OSDMAP_FULL
);
3429 } else if (osdmap
.test_flag(CEPH_OSDMAP_FULL
)){
3430 dout(10) << "No full osds, removing full flag" << dendl
;
3431 remove_flag(CEPH_OSDMAP_FULL
);
3434 if (mon
->pgservice
->have_nearfull_osds()) {
3435 dout(5) << "There are near full osds, setting nearfull flag" << dendl
;
3436 add_flag(CEPH_OSDMAP_NEARFULL
);
3437 } else if (osdmap
.test_flag(CEPH_OSDMAP_NEARFULL
)){
3438 dout(10) << "No near full osds, removing nearfull flag" << dendl
;
3439 remove_flag(CEPH_OSDMAP_NEARFULL
);
3441 if (pending_inc
.new_flags
!= -1 &&
3442 (pending_inc
.new_flags
^ osdmap
.flags
) & (CEPH_OSDMAP_FULL
| CEPH_OSDMAP_NEARFULL
)) {
3443 dout(1) << "New setting for" <<
3444 (pending_inc
.new_flags
& CEPH_OSDMAP_FULL
? " CEPH_OSDMAP_FULL" : "") <<
3445 (pending_inc
.new_flags
& CEPH_OSDMAP_NEARFULL
? " CEPH_OSDMAP_NEARFULL" : "")
3446 << " -- doing propose" << dendl
;
3451 if (update_pools_status())
3455 !pending_inc
.new_pg_temp
.empty()) // also propose if we adjusted pg_temp
3459 bool OSDMonitor::handle_osd_timeouts(const utime_t
&now
,
3460 std::map
<int,utime_t
> &last_osd_report
)
3462 utime_t
timeo(g_conf
->mon_osd_report_timeout
, 0);
3463 if (now
- mon
->get_leader_since() < timeo
) {
3464 // We haven't been the leader for long enough to consider OSD timeouts
3468 int max_osd
= osdmap
.get_max_osd();
3469 bool new_down
= false;
3471 for (int i
=0; i
< max_osd
; ++i
) {
3472 dout(30) << __func__
<< ": checking up on osd " << i
<< dendl
;
3473 if (!osdmap
.exists(i
)) {
3474 last_osd_report
.erase(i
); // if any
3477 if (!osdmap
.is_up(i
))
3479 const std::map
<int,utime_t
>::const_iterator t
= last_osd_report
.find(i
);
3480 if (t
== last_osd_report
.end()) {
3481 // it wasn't in the map; start the timer.
3482 last_osd_report
[i
] = now
;
3483 } else if (can_mark_down(i
)) {
3484 utime_t diff
= now
- t
->second
;
3486 mon
->clog
->info() << "osd." << i
<< " marked down after no beacon for "
3487 << diff
<< " seconds";
3488 derr
<< "no beacon from osd." << i
<< " since " << t
->second
3489 << ", " << diff
<< " seconds ago. marking down" << dendl
;
3490 pending_inc
.new_state
[i
] = CEPH_OSD_UP
;
3498 void OSDMonitor::get_health(list
<pair
<health_status_t
,string
> >& summary
,
3499 list
<pair
<health_status_t
,string
> > *detail
,
3500 CephContext
*cct
) const
3502 int num_osds
= osdmap
.get_num_osds();
3504 if (num_osds
== 0) {
3505 summary
.push_back(make_pair(HEALTH_ERR
, "no osds"));
3507 int num_in_osds
= 0;
3508 int num_down_in_osds
= 0;
3510 set
<int> down_in_osds
;
3511 set
<int> up_in_osds
;
3512 set
<int> subtree_up
;
3513 unordered_map
<int, set
<int> > subtree_type_down
;
3514 unordered_map
<int, int> num_osds_subtree
;
3515 int max_type
= osdmap
.crush
->get_max_type_id();
3517 for (int i
= 0; i
< osdmap
.get_max_osd(); i
++) {
3518 if (!osdmap
.exists(i
)) {
3519 if (osdmap
.crush
->item_exists(i
)) {
3524 if (osdmap
.is_out(i
))
3527 if (down_in_osds
.count(i
) || up_in_osds
.count(i
))
3529 if (!osdmap
.is_up(i
)) {
3530 down_in_osds
.insert(i
);
3533 for (int type
= 0; type
<= max_type
; type
++) {
3534 if (!osdmap
.crush
->get_type_name(type
))
3536 int r
= osdmap
.crush
->get_immediate_parent_id(current
, &parent_id
);
3539 // break early if this parent is already marked as up
3540 if (subtree_up
.count(parent_id
))
3542 type
= osdmap
.crush
->get_bucket_type(parent_id
);
3543 if (!osdmap
.subtree_type_is_down(
3544 g_ceph_context
, parent_id
, type
,
3545 &down_in_osds
, &up_in_osds
, &subtree_up
, &subtree_type_down
))
3547 current
= parent_id
;
3552 // calculate the number of down osds in each down subtree and
3553 // store it in num_osds_subtree
3554 for (int type
= 1; type
<= max_type
; type
++) {
3555 if (!osdmap
.crush
->get_type_name(type
))
3557 for (auto j
= subtree_type_down
[type
].begin();
3558 j
!= subtree_type_down
[type
].end();
3562 int num
= osdmap
.crush
->get_children(*j
, &children
);
3563 num_osds_subtree
[*j
] = num
;
3567 int num_children
= osdmap
.crush
->get_children(*j
, &children
);
3568 if (num_children
== 0)
3570 for (auto l
= children
.begin(); l
!= children
.end(); ++l
) {
3571 if (num_osds_subtree
[*l
] > 0) {
3572 num
= num
+ num_osds_subtree
[*l
];
3575 num_osds_subtree
[*j
] = num
;
3579 num_down_in_osds
= down_in_osds
.size();
3580 assert(num_down_in_osds
<= num_in_osds
);
3581 if (num_down_in_osds
> 0) {
3582 // summary of down subtree types and osds
3583 for (int type
= max_type
; type
> 0; type
--) {
3584 if (!osdmap
.crush
->get_type_name(type
))
3586 if (subtree_type_down
[type
].size() > 0) {
3588 ss
<< subtree_type_down
[type
].size() << " "
3589 << osdmap
.crush
->get_type_name(type
);
3590 if (subtree_type_down
[type
].size() > 1) {
3593 int sum_down_osds
= 0;
3594 for (auto j
= subtree_type_down
[type
].begin();
3595 j
!= subtree_type_down
[type
].end();
3597 sum_down_osds
= sum_down_osds
+ num_osds_subtree
[*j
];
3599 ss
<< " (" << sum_down_osds
<< " osds) down";
3600 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3604 ss
<< down_in_osds
.size() << " osds down";
3605 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3608 // details of down subtree types
3609 for (int type
= max_type
; type
> 0; type
--) {
3610 if (!osdmap
.crush
->get_type_name(type
))
3612 for (auto j
= subtree_type_down
[type
].rbegin();
3613 j
!= subtree_type_down
[type
].rend();
3616 ss
<< osdmap
.crush
->get_type_name(type
);
3618 ss
<< osdmap
.crush
->get_item_name(*j
);
3619 // at the top level, do not print location
3620 if (type
!= max_type
) {
3622 ss
<< osdmap
.crush
->get_full_location_ordered_string(*j
);
3625 int num
= num_osds_subtree
[*j
];
3626 ss
<< " (" << num
<< " osds)";
3628 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3631 // details of down osds
3632 for (auto it
= down_in_osds
.begin(); it
!= down_in_osds
.end(); ++it
) {
3634 ss
<< "osd." << *it
<< " (";
3635 ss
<< osdmap
.crush
->get_full_location_ordered_string(*it
);
3637 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3642 if (!osds
.empty()) {
3644 ss
<< osds
.size() << " osds exist in the crush map but not in the osdmap";
3645 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3647 ss
<< " (osds: " << osds
<< ")";
3648 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3652 // note: we leave it to ceph-mgr to generate details health warnings
3653 // with actual osd utilizations
3656 uint64_t warn_flags
=
3658 CEPH_OSDMAP_PAUSERD
|
3659 CEPH_OSDMAP_PAUSEWR
|
3660 CEPH_OSDMAP_PAUSEREC
|
3662 CEPH_OSDMAP_NODOWN
|
3665 CEPH_OSDMAP_NOBACKFILL
|
3666 CEPH_OSDMAP_NORECOVER
|
3667 CEPH_OSDMAP_NOSCRUB
|
3668 CEPH_OSDMAP_NODEEP_SCRUB
|
3669 CEPH_OSDMAP_NOTIERAGENT
|
3670 CEPH_OSDMAP_NOREBALANCE
;
3671 if (osdmap
.test_flag(warn_flags
)) {
3673 ss
<< osdmap
.get_flag_string(osdmap
.get_flags() & warn_flags
)
3675 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3677 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3680 // old crush tunables?
3681 if (g_conf
->mon_warn_on_legacy_crush_tunables
) {
3682 string min
= osdmap
.crush
->get_min_required_version();
3683 if (min
< g_conf
->mon_crush_min_required_version
) {
3685 ss
<< "crush map has legacy tunables (require " << min
3686 << ", min is " << g_conf
->mon_crush_min_required_version
<< ")";
3687 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3689 ss
<< "; see http://docs.ceph.com/docs/master/rados/operations/crush-map/#tunables";
3690 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3694 if (g_conf
->mon_warn_on_crush_straw_calc_version_zero
) {
3695 if (osdmap
.crush
->get_straw_calc_version() == 0) {
3697 ss
<< "crush map has straw_calc_version=0";
3698 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3700 ss
<< "; see http://docs.ceph.com/docs/master/rados/operations/crush-map/#tunables";
3701 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3706 // hit_set-less cache_mode?
3707 if (g_conf
->mon_warn_on_cache_pools_without_hit_sets
) {
3708 int problem_cache_pools
= 0;
3709 for (map
<int64_t, pg_pool_t
>::const_iterator p
= osdmap
.pools
.begin();
3710 p
!= osdmap
.pools
.end();
3712 const pg_pool_t
& info
= p
->second
;
3713 if (info
.cache_mode_requires_hit_set() &&
3714 info
.hit_set_params
.get_type() == HitSet::TYPE_NONE
) {
3715 ++problem_cache_pools
;
3718 ss
<< "pool '" << osdmap
.get_pool_name(p
->first
)
3719 << "' with cache_mode " << info
.get_cache_mode_name()
3720 << " needs hit_set_type to be set but it is not";
3721 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3725 if (problem_cache_pools
) {
3727 ss
<< problem_cache_pools
<< " cache pools are missing hit_sets";
3728 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3732 if (osdmap
.crush
->has_multirule_rulesets()) {
3734 ss
<< "CRUSH map contains multirule rulesets";
3735 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3737 ss
<< "; please manually fix the map";
3738 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3742 // Not using 'sortbitwise' and should be?
3743 if (!osdmap
.test_flag(CEPH_OSDMAP_SORTBITWISE
) &&
3744 (osdmap
.get_up_osd_features() &
3745 CEPH_FEATURE_OSD_BITWISE_HOBJ_SORT
)) {
3747 ss
<< "no legacy OSD present but 'sortbitwise' flag is not set";
3748 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3751 // Warn if 'mon_osd_down_out_interval' is set to zero.
3752 // Having this option set to zero on the leader acts much like the
3753 // 'noout' flag. It's hard to figure out what's going wrong with clusters
3754 // without the 'noout' flag set but acting like that just the same, so
3755 // we report a HEALTH_WARN in case this option is set to zero.
3756 // This is an ugly hack to get the warning out, but until we find a way
3757 // to spread global options throughout the mon cluster and have all mons
3758 // using a base set of the same options, we need to work around this sort
3760 // There's also the obvious drawback that if this is set on a single
3761 // monitor on a 3-monitor cluster, this warning will only be shown every
3762 // third monitor connection.
3763 if (g_conf
->mon_warn_on_osd_down_out_interval_zero
&&
3764 g_conf
->mon_osd_down_out_interval
== 0) {
3766 ss
<< "mon." << mon
->name
<< " has mon_osd_down_out_interval set to 0";
3767 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3769 ss
<< "; this has the same effect as the 'noout' flag";
3770 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3774 // warn about upgrade flags that can be set but are not.
3775 if (g_conf
->mon_debug_no_require_luminous
) {
3776 // ignore these checks
3777 } else if (HAVE_FEATURE(osdmap
.get_up_osd_features(), SERVER_LUMINOUS
) &&
3778 osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
3779 string msg
= "all OSDs are running luminous or later but"
3780 " require_osd_release < luminous";
3781 summary
.push_back(make_pair(HEALTH_WARN
, msg
));
3783 detail
->push_back(make_pair(HEALTH_WARN
, msg
));
3785 } else if (HAVE_FEATURE(osdmap
.get_up_osd_features(), SERVER_KRAKEN
) &&
3786 osdmap
.require_osd_release
< CEPH_RELEASE_KRAKEN
) {
3787 string msg
= "all OSDs are running kraken or later but"
3788 " require_osd_release < kraken";
3789 summary
.push_back(make_pair(HEALTH_WARN
, msg
));
3791 detail
->push_back(make_pair(HEALTH_WARN
, msg
));
3793 } else if (HAVE_FEATURE(osdmap
.get_up_osd_features(), SERVER_JEWEL
) &&
3794 osdmap
.require_osd_release
< CEPH_RELEASE_JEWEL
) {
3795 string msg
= "all OSDs are running jewel or later but"
3796 " require_osd_release < jewel";
3797 summary
.push_back(make_pair(HEALTH_WARN
, msg
));
3799 detail
->push_back(make_pair(HEALTH_WARN
, msg
));
3803 for (auto it
: osdmap
.get_pools()) {
3804 const pg_pool_t
&pool
= it
.second
;
3805 if (pool
.has_flag(pg_pool_t::FLAG_FULL
)) {
3806 const string
& pool_name
= osdmap
.get_pool_name(it
.first
);
3808 ss
<< "pool '" << pool_name
<< "' is full";
3809 summary
.push_back(make_pair(HEALTH_WARN
, ss
.str()));
3811 detail
->push_back(make_pair(HEALTH_WARN
, ss
.str()));
3817 void OSDMonitor::dump_info(Formatter
*f
)
3819 f
->open_object_section("osdmap");
3823 f
->open_array_section("osd_metadata");
3824 for (int i
=0; i
<osdmap
.get_max_osd(); ++i
) {
3825 if (osdmap
.exists(i
)) {
3826 f
->open_object_section("osd");
3827 f
->dump_unsigned("id", i
);
3828 dump_osd_metadata(i
, f
, NULL
);
3834 f
->dump_unsigned("osdmap_first_committed", get_first_committed());
3835 f
->dump_unsigned("osdmap_last_committed", get_last_committed());
3837 f
->open_object_section("crushmap");
3838 osdmap
.crush
->dump(f
);
3843 enum osd_pool_get_choices
{
3844 SIZE
, MIN_SIZE
, CRASH_REPLAY_INTERVAL
,
3845 PG_NUM
, PGP_NUM
, CRUSH_RULE
, HASHPSPOOL
,
3846 NODELETE
, NOPGCHANGE
, NOSIZECHANGE
,
3847 WRITE_FADVISE_DONTNEED
, NOSCRUB
, NODEEP_SCRUB
,
3848 HIT_SET_TYPE
, HIT_SET_PERIOD
, HIT_SET_COUNT
, HIT_SET_FPP
,
3849 USE_GMT_HITSET
, AUID
, TARGET_MAX_OBJECTS
, TARGET_MAX_BYTES
,
3850 CACHE_TARGET_DIRTY_RATIO
, CACHE_TARGET_DIRTY_HIGH_RATIO
,
3851 CACHE_TARGET_FULL_RATIO
,
3852 CACHE_MIN_FLUSH_AGE
, CACHE_MIN_EVICT_AGE
,
3853 ERASURE_CODE_PROFILE
, MIN_READ_RECENCY_FOR_PROMOTE
,
3854 MIN_WRITE_RECENCY_FOR_PROMOTE
, FAST_READ
,
3855 HIT_SET_GRADE_DECAY_RATE
, HIT_SET_SEARCH_LAST_N
,
3856 SCRUB_MIN_INTERVAL
, SCRUB_MAX_INTERVAL
, DEEP_SCRUB_INTERVAL
,
3857 RECOVERY_PRIORITY
, RECOVERY_OP_PRIORITY
, SCRUB_PRIORITY
,
3858 COMPRESSION_MODE
, COMPRESSION_ALGORITHM
, COMPRESSION_REQUIRED_RATIO
,
3859 COMPRESSION_MAX_BLOB_SIZE
, COMPRESSION_MIN_BLOB_SIZE
,
3860 CSUM_TYPE
, CSUM_MAX_BLOCK
, CSUM_MIN_BLOCK
};
3862 std::set
<osd_pool_get_choices
>
3863 subtract_second_from_first(const std::set
<osd_pool_get_choices
>& first
,
3864 const std::set
<osd_pool_get_choices
>& second
)
3866 std::set
<osd_pool_get_choices
> result
;
3867 std::set_difference(first
.begin(), first
.end(),
3868 second
.begin(), second
.end(),
3869 std::inserter(result
, result
.end()));
3875 bool OSDMonitor::preprocess_command(MonOpRequestRef op
)
3877 op
->mark_osdmon_event(__func__
);
3878 MMonCommand
*m
= static_cast<MMonCommand
*>(op
->get_req());
3881 stringstream ss
, ds
;
3883 map
<string
, cmd_vartype
> cmdmap
;
3884 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
3885 string rs
= ss
.str();
3886 mon
->reply_command(op
, -EINVAL
, rs
, get_last_committed());
3890 MonSession
*session
= m
->get_session();
3892 mon
->reply_command(op
, -EACCES
, "access denied", get_last_committed());
3897 cmd_getval(g_ceph_context
, cmdmap
, "prefix", prefix
);
3900 cmd_getval(g_ceph_context
, cmdmap
, "format", format
, string("plain"));
3901 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
));
3903 if (prefix
== "osd stat") {
3904 osdmap
.print_summary(f
.get(), ds
, "");
3910 else if (prefix
== "osd perf" ||
3911 prefix
== "osd blocked-by") {
3912 r
= mon
->pgservice
->process_pg_command(prefix
, cmdmap
,
3913 osdmap
, f
.get(), &ss
, &rdata
);
3915 else if (prefix
== "osd dump" ||
3916 prefix
== "osd tree" ||
3917 prefix
== "osd ls" ||
3918 prefix
== "osd getmap" ||
3919 prefix
== "osd getcrushmap" ||
3920 prefix
== "osd ls-tree") {
3925 cmd_getval(g_ceph_context
, cmdmap
, "epoch", epochnum
, (int64_t)osdmap
.get_epoch());
3928 bufferlist osdmap_bl
;
3929 int err
= get_version_full(epoch
, osdmap_bl
);
3930 if (err
== -ENOENT
) {
3932 ss
<< "there is no map for epoch " << epoch
;
3936 assert(osdmap_bl
.length());
3939 if (epoch
== osdmap
.get_epoch()) {
3943 p
->decode(osdmap_bl
);
3946 auto sg
= make_scope_guard([&] {
3952 if (prefix
== "osd dump") {
3955 f
->open_object_section("osdmap");
3965 } else if (prefix
== "osd ls") {
3967 f
->open_array_section("osds");
3968 for (int i
= 0; i
< osdmap
.get_max_osd(); i
++) {
3969 if (osdmap
.exists(i
)) {
3970 f
->dump_int("osd", i
);
3977 for (int i
= 0; i
< osdmap
.get_max_osd(); i
++) {
3978 if (osdmap
.exists(i
)) {
3987 } else if (prefix
== "osd tree") {
3988 vector
<string
> states
;
3989 cmd_getval(g_ceph_context
, cmdmap
, "states", states
);
3990 unsigned filter
= 0;
3991 for (auto& s
: states
) {
3993 filter
|= OSDMap::DUMP_UP
;
3994 } else if (s
== "down") {
3995 filter
|= OSDMap::DUMP_DOWN
;
3996 } else if (s
== "in") {
3997 filter
|= OSDMap::DUMP_IN
;
3998 } else if (s
== "out") {
3999 filter
|= OSDMap::DUMP_OUT
;
4000 } else if (s
== "destroyed") {
4001 filter
|= OSDMap::DUMP_DESTROYED
;
4003 ss
<< "unrecognized state '" << s
<< "'";
4008 if ((filter
& (OSDMap::DUMP_IN
|OSDMap::DUMP_OUT
)) ==
4009 (OSDMap::DUMP_IN
|OSDMap::DUMP_OUT
)) {
4010 ss
<< "cannot specify both 'in' and 'out'";
4014 if (((filter
& (OSDMap::DUMP_UP
|OSDMap::DUMP_DOWN
)) ==
4015 (OSDMap::DUMP_UP
|OSDMap::DUMP_DOWN
)) ||
4016 ((filter
& (OSDMap::DUMP_UP
|OSDMap::DUMP_DESTROYED
)) ==
4017 (OSDMap::DUMP_UP
|OSDMap::DUMP_DESTROYED
)) ||
4018 ((filter
& (OSDMap::DUMP_DOWN
|OSDMap::DUMP_DESTROYED
)) ==
4019 (OSDMap::DUMP_DOWN
|OSDMap::DUMP_DESTROYED
))) {
4020 ss
<< "can specify only one of 'up', 'down' and 'destroyed'";
4025 f
->open_object_section("tree");
4026 p
->print_tree(f
.get(), NULL
, filter
);
4030 p
->print_tree(NULL
, &ds
, filter
);
4033 } else if (prefix
== "osd getmap") {
4034 rdata
.append(osdmap_bl
);
4035 ss
<< "got osdmap epoch " << p
->get_epoch();
4036 } else if (prefix
== "osd getcrushmap") {
4037 p
->crush
->encode(rdata
, mon
->get_quorum_con_features());
4038 ss
<< p
->get_crush_version();
4039 } else if (prefix
== "osd ls-tree") {
4041 cmd_getval(g_ceph_context
, cmdmap
, "name", bucket_name
);
4043 r
= p
->get_osds_by_bucket_name(bucket_name
, &osds
);
4045 ss
<< "\"" << bucket_name
<< "\" does not exist";
4048 ss
<< "can not parse bucket name:\"" << bucket_name
<< "\"";
4053 f
->open_array_section("osds");
4054 for (auto &i
: osds
) {
4055 if (osdmap
.exists(i
)) {
4056 f
->dump_int("osd", i
);
4063 for (auto &i
: osds
) {
4064 if (osdmap
.exists(i
)) {
4075 } else if (prefix
== "osd df") {
4077 cmd_getval(g_ceph_context
, cmdmap
, "output_method", method
);
4078 print_osd_utilization(osdmap
, mon
->pgservice
, ds
,
4079 f
.get(), method
== "tree");
4081 } else if (prefix
== "osd getmaxosd") {
4083 f
->open_object_section("getmaxosd");
4084 f
->dump_unsigned("epoch", osdmap
.get_epoch());
4085 f
->dump_int("max_osd", osdmap
.get_max_osd());
4089 ds
<< "max_osd = " << osdmap
.get_max_osd() << " in epoch " << osdmap
.get_epoch();
4092 } else if (prefix
== "osd utilization") {
4094 osdmap
.summarize_mapping_stats(NULL
, NULL
, &out
, f
.get());
4101 } else if (prefix
== "osd find") {
4103 if (!cmd_getval(g_ceph_context
, cmdmap
, "id", osd
)) {
4104 ss
<< "unable to parse osd id value '"
4105 << cmd_vartype_stringify(cmdmap
["id"]) << "'";
4109 if (!osdmap
.exists(osd
)) {
4110 ss
<< "osd." << osd
<< " does not exist";
4115 cmd_getval(g_ceph_context
, cmdmap
, "format", format
);
4116 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json-pretty"));
4117 f
->open_object_section("osd_location");
4118 f
->dump_int("osd", osd
);
4119 f
->dump_stream("ip") << osdmap
.get_addr(osd
);
4120 f
->open_object_section("crush_location");
4121 map
<string
,string
> loc
= osdmap
.crush
->get_full_location(osd
);
4122 for (map
<string
,string
>::iterator p
= loc
.begin(); p
!= loc
.end(); ++p
)
4123 f
->dump_string(p
->first
.c_str(), p
->second
);
4127 } else if (prefix
== "osd metadata") {
4129 if (cmd_vartype_stringify(cmdmap
["id"]).size() &&
4130 !cmd_getval(g_ceph_context
, cmdmap
, "id", osd
)) {
4131 ss
<< "unable to parse osd id value '"
4132 << cmd_vartype_stringify(cmdmap
["id"]) << "'";
4136 if (osd
>= 0 && !osdmap
.exists(osd
)) {
4137 ss
<< "osd." << osd
<< " does not exist";
4142 cmd_getval(g_ceph_context
, cmdmap
, "format", format
);
4143 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json-pretty"));
4145 f
->open_object_section("osd_metadata");
4146 f
->dump_unsigned("id", osd
);
4147 r
= dump_osd_metadata(osd
, f
.get(), &ss
);
4153 f
->open_array_section("osd_metadata");
4154 for (int i
=0; i
<osdmap
.get_max_osd(); ++i
) {
4155 if (osdmap
.exists(i
)) {
4156 f
->open_object_section("osd");
4157 f
->dump_unsigned("id", i
);
4158 r
= dump_osd_metadata(i
, f
.get(), NULL
);
4159 if (r
== -EINVAL
|| r
== -ENOENT
) {
4160 // Drop error, continue to get other daemons' metadata
4161 dout(4) << "No metadata for osd." << i
<< dendl
;
4173 } else if (prefix
== "osd versions") {
4175 f
.reset(Formatter::create("json-pretty"));
4176 count_metadata("ceph_version", f
.get());
4179 } else if (prefix
== "osd count-metadata") {
4181 f
.reset(Formatter::create("json-pretty"));
4183 cmd_getval(g_ceph_context
, cmdmap
, "property", field
);
4184 count_metadata(field
, f
.get());
4187 } else if (prefix
== "osd map") {
4188 string poolstr
, objstr
, namespacestr
;
4189 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
4190 cmd_getval(g_ceph_context
, cmdmap
, "object", objstr
);
4191 cmd_getval(g_ceph_context
, cmdmap
, "nspace", namespacestr
);
4193 int64_t pool
= osdmap
.lookup_pg_pool_name(poolstr
.c_str());
4195 ss
<< "pool " << poolstr
<< " does not exist";
4199 object_locator_t
oloc(pool
, namespacestr
);
4200 object_t
oid(objstr
);
4201 pg_t pgid
= osdmap
.object_locator_to_pg(oid
, oloc
);
4202 pg_t mpgid
= osdmap
.raw_pg_to_pg(pgid
);
4203 vector
<int> up
, acting
;
4205 osdmap
.pg_to_up_acting_osds(mpgid
, &up
, &up_p
, &acting
, &acting_p
);
4208 if (!namespacestr
.empty())
4209 fullobjname
= namespacestr
+ string("/") + oid
.name
;
4211 fullobjname
= oid
.name
;
4213 f
->open_object_section("osd_map");
4214 f
->dump_unsigned("epoch", osdmap
.get_epoch());
4215 f
->dump_string("pool", poolstr
);
4216 f
->dump_int("pool_id", pool
);
4217 f
->dump_stream("objname") << fullobjname
;
4218 f
->dump_stream("raw_pgid") << pgid
;
4219 f
->dump_stream("pgid") << mpgid
;
4220 f
->open_array_section("up");
4221 for (vector
<int>::iterator p
= up
.begin(); p
!= up
.end(); ++p
)
4222 f
->dump_int("osd", *p
);
4224 f
->dump_int("up_primary", up_p
);
4225 f
->open_array_section("acting");
4226 for (vector
<int>::iterator p
= acting
.begin(); p
!= acting
.end(); ++p
)
4227 f
->dump_int("osd", *p
);
4229 f
->dump_int("acting_primary", acting_p
);
4230 f
->close_section(); // osd_map
4233 ds
<< "osdmap e" << osdmap
.get_epoch()
4234 << " pool '" << poolstr
<< "' (" << pool
<< ")"
4235 << " object '" << fullobjname
<< "' ->"
4236 << " pg " << pgid
<< " (" << mpgid
<< ")"
4237 << " -> up (" << pg_vector_string(up
) << ", p" << up_p
<< ") acting ("
4238 << pg_vector_string(acting
) << ", p" << acting_p
<< ")";
4242 } else if (prefix
== "pg map") {
4245 cmd_getval(g_ceph_context
, cmdmap
, "pgid", pgidstr
);
4246 if (!pgid
.parse(pgidstr
.c_str())) {
4247 ss
<< "invalid pgid '" << pgidstr
<< "'";
4251 vector
<int> up
, acting
;
4252 if (!osdmap
.have_pg_pool(pgid
.pool())) {
4253 ss
<< "pg '" << pgidstr
<< "' does not exist";
4257 pg_t mpgid
= osdmap
.raw_pg_to_pg(pgid
);
4258 osdmap
.pg_to_up_acting_osds(pgid
, up
, acting
);
4260 f
->open_object_section("pg_map");
4261 f
->dump_unsigned("epoch", osdmap
.get_epoch());
4262 f
->dump_stream("raw_pgid") << pgid
;
4263 f
->dump_stream("pgid") << mpgid
;
4264 f
->open_array_section("up");
4265 for (auto osd
: up
) {
4266 f
->dump_int("up_osd", osd
);
4269 f
->open_array_section("acting");
4270 for (auto osd
: acting
) {
4271 f
->dump_int("acting_osd", osd
);
4277 ds
<< "osdmap e" << osdmap
.get_epoch()
4278 << " pg " << pgid
<< " (" << mpgid
<< ")"
4279 << " -> up " << up
<< " acting " << acting
;
4284 } else if (prefix
== "osd scrub" ||
4285 prefix
== "osd deep-scrub" ||
4286 prefix
== "osd repair") {
4288 cmd_getval(g_ceph_context
, cmdmap
, "who", whostr
);
4289 vector
<string
> pvec
;
4290 get_str_vec(prefix
, pvec
);
4292 if (whostr
== "*" || whostr
== "all" || whostr
== "any") {
4295 for (int i
= 0; i
< osdmap
.get_max_osd(); i
++)
4296 if (osdmap
.is_up(i
)) {
4297 ss
<< (c
++ ? "," : "") << i
;
4298 mon
->try_send_message(new MOSDScrub(osdmap
.get_fsid(),
4299 pvec
.back() == "repair",
4300 pvec
.back() == "deep-scrub"),
4301 osdmap
.get_inst(i
));
4304 ss
<< " instructed to " << pvec
.back();
4306 long osd
= parse_osd_id(whostr
.c_str(), &ss
);
4309 } else if (osdmap
.is_up(osd
)) {
4310 mon
->try_send_message(new MOSDScrub(osdmap
.get_fsid(),
4311 pvec
.back() == "repair",
4312 pvec
.back() == "deep-scrub"),
4313 osdmap
.get_inst(osd
));
4314 ss
<< "osd." << osd
<< " instructed to " << pvec
.back();
4316 ss
<< "osd." << osd
<< " is not up";
4320 } else if (prefix
== "osd lspools") {
4322 cmd_getval(g_ceph_context
, cmdmap
, "auid", auid
, int64_t(0));
4324 f
->open_array_section("pools");
4325 for (map
<int64_t, pg_pool_t
>::iterator p
= osdmap
.pools
.begin();
4326 p
!= osdmap
.pools
.end();
4328 if (!auid
|| p
->second
.auid
== (uint64_t)auid
) {
4330 f
->open_object_section("pool");
4331 f
->dump_int("poolnum", p
->first
);
4332 f
->dump_string("poolname", osdmap
.pool_name
[p
->first
]);
4335 ds
<< p
->first
<< ' ' << osdmap
.pool_name
[p
->first
] << ',';
4344 } else if (prefix
== "osd blacklist ls") {
4346 f
->open_array_section("blacklist");
4348 for (ceph::unordered_map
<entity_addr_t
,utime_t
>::iterator p
= osdmap
.blacklist
.begin();
4349 p
!= osdmap
.blacklist
.end();
4352 f
->open_object_section("entry");
4353 f
->dump_stream("addr") << p
->first
;
4354 f
->dump_stream("until") << p
->second
;
4359 ss
<< p
->first
<< " " << p
->second
;
4369 ss
<< "listed " << osdmap
.blacklist
.size() << " entries";
4371 } else if (prefix
== "osd pool ls") {
4373 cmd_getval(g_ceph_context
, cmdmap
, "detail", detail
);
4374 if (!f
&& detail
== "detail") {
4376 osdmap
.print_pools(ss
);
4377 rdata
.append(ss
.str());
4380 f
->open_array_section("pools");
4381 for (map
<int64_t,pg_pool_t
>::const_iterator it
= osdmap
.get_pools().begin();
4382 it
!= osdmap
.get_pools().end();
4385 if (detail
== "detail") {
4386 f
->open_object_section("pool");
4387 f
->dump_string("pool_name", osdmap
.get_pool_name(it
->first
));
4388 it
->second
.dump(f
.get());
4391 f
->dump_string("pool_name", osdmap
.get_pool_name(it
->first
));
4394 rdata
.append(osdmap
.get_pool_name(it
->first
) + "\n");
4403 } else if (prefix
== "osd crush get-tunable") {
4405 cmd_getval(g_ceph_context
, cmdmap
, "tunable", tunable
);
4408 f
->open_object_section("tunable");
4409 if (tunable
== "straw_calc_version") {
4411 f
->dump_int(tunable
.c_str(), osdmap
.crush
->get_straw_calc_version());
4413 rss
<< osdmap
.crush
->get_straw_calc_version() << "\n";
4422 rdata
.append(rss
.str());
4426 } else if (prefix
== "osd pool get") {
4428 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
4429 int64_t pool
= osdmap
.lookup_pg_pool_name(poolstr
.c_str());
4431 ss
<< "unrecognized pool '" << poolstr
<< "'";
4436 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool
);
4438 cmd_getval(g_ceph_context
, cmdmap
, "var", var
);
4440 typedef std::map
<std::string
, osd_pool_get_choices
> choices_map_t
;
4441 const choices_map_t ALL_CHOICES
= {
4443 {"min_size", MIN_SIZE
},
4444 {"crash_replay_interval", CRASH_REPLAY_INTERVAL
},
4445 {"pg_num", PG_NUM
}, {"pgp_num", PGP_NUM
},
4446 {"crush_rule", CRUSH_RULE
},
4447 {"hashpspool", HASHPSPOOL
}, {"nodelete", NODELETE
},
4448 {"nopgchange", NOPGCHANGE
}, {"nosizechange", NOSIZECHANGE
},
4449 {"noscrub", NOSCRUB
}, {"nodeep-scrub", NODEEP_SCRUB
},
4450 {"write_fadvise_dontneed", WRITE_FADVISE_DONTNEED
},
4451 {"hit_set_type", HIT_SET_TYPE
}, {"hit_set_period", HIT_SET_PERIOD
},
4452 {"hit_set_count", HIT_SET_COUNT
}, {"hit_set_fpp", HIT_SET_FPP
},
4453 {"use_gmt_hitset", USE_GMT_HITSET
},
4454 {"auid", AUID
}, {"target_max_objects", TARGET_MAX_OBJECTS
},
4455 {"target_max_bytes", TARGET_MAX_BYTES
},
4456 {"cache_target_dirty_ratio", CACHE_TARGET_DIRTY_RATIO
},
4457 {"cache_target_dirty_high_ratio", CACHE_TARGET_DIRTY_HIGH_RATIO
},
4458 {"cache_target_full_ratio", CACHE_TARGET_FULL_RATIO
},
4459 {"cache_min_flush_age", CACHE_MIN_FLUSH_AGE
},
4460 {"cache_min_evict_age", CACHE_MIN_EVICT_AGE
},
4461 {"erasure_code_profile", ERASURE_CODE_PROFILE
},
4462 {"min_read_recency_for_promote", MIN_READ_RECENCY_FOR_PROMOTE
},
4463 {"min_write_recency_for_promote", MIN_WRITE_RECENCY_FOR_PROMOTE
},
4464 {"fast_read", FAST_READ
},
4465 {"hit_set_grade_decay_rate", HIT_SET_GRADE_DECAY_RATE
},
4466 {"hit_set_search_last_n", HIT_SET_SEARCH_LAST_N
},
4467 {"scrub_min_interval", SCRUB_MIN_INTERVAL
},
4468 {"scrub_max_interval", SCRUB_MAX_INTERVAL
},
4469 {"deep_scrub_interval", DEEP_SCRUB_INTERVAL
},
4470 {"recovery_priority", RECOVERY_PRIORITY
},
4471 {"recovery_op_priority", RECOVERY_OP_PRIORITY
},
4472 {"scrub_priority", SCRUB_PRIORITY
},
4473 {"compression_mode", COMPRESSION_MODE
},
4474 {"compression_algorithm", COMPRESSION_ALGORITHM
},
4475 {"compression_required_ratio", COMPRESSION_REQUIRED_RATIO
},
4476 {"compression_max_blob_size", COMPRESSION_MAX_BLOB_SIZE
},
4477 {"compression_min_blob_size", COMPRESSION_MIN_BLOB_SIZE
},
4478 {"csum_type", CSUM_TYPE
},
4479 {"csum_max_block", CSUM_MAX_BLOCK
},
4480 {"csum_min_block", CSUM_MIN_BLOCK
},
4483 typedef std::set
<osd_pool_get_choices
> choices_set_t
;
4485 const choices_set_t ONLY_TIER_CHOICES
= {
4486 HIT_SET_TYPE
, HIT_SET_PERIOD
, HIT_SET_COUNT
, HIT_SET_FPP
,
4487 TARGET_MAX_OBJECTS
, TARGET_MAX_BYTES
, CACHE_TARGET_FULL_RATIO
,
4488 CACHE_TARGET_DIRTY_RATIO
, CACHE_TARGET_DIRTY_HIGH_RATIO
,
4489 CACHE_MIN_FLUSH_AGE
, CACHE_MIN_EVICT_AGE
,
4490 MIN_READ_RECENCY_FOR_PROMOTE
,
4491 MIN_WRITE_RECENCY_FOR_PROMOTE
,
4492 HIT_SET_GRADE_DECAY_RATE
, HIT_SET_SEARCH_LAST_N
4494 const choices_set_t ONLY_ERASURE_CHOICES
= {
4495 ERASURE_CODE_PROFILE
4498 choices_set_t selected_choices
;
4500 for(choices_map_t::const_iterator it
= ALL_CHOICES
.begin();
4501 it
!= ALL_CHOICES
.end(); ++it
) {
4502 selected_choices
.insert(it
->second
);
4506 selected_choices
= subtract_second_from_first(selected_choices
,
4510 if(!p
->is_erasure()) {
4511 selected_choices
= subtract_second_from_first(selected_choices
,
4512 ONLY_ERASURE_CHOICES
);
4514 } else /* var != "all" */ {
4515 choices_map_t::const_iterator found
= ALL_CHOICES
.find(var
);
4516 osd_pool_get_choices selected
= found
->second
;
4518 if (!p
->is_tier() &&
4519 ONLY_TIER_CHOICES
.find(selected
) != ONLY_TIER_CHOICES
.end()) {
4520 ss
<< "pool '" << poolstr
4521 << "' is not a tier pool: variable not applicable";
4526 if (!p
->is_erasure() &&
4527 ONLY_ERASURE_CHOICES
.find(selected
)
4528 != ONLY_ERASURE_CHOICES
.end()) {
4529 ss
<< "pool '" << poolstr
4530 << "' is not a erasure pool: variable not applicable";
4535 selected_choices
.insert(selected
);
4539 for(choices_set_t::const_iterator it
= selected_choices
.begin();
4540 it
!= selected_choices
.end(); ++it
) {
4541 choices_map_t::const_iterator i
;
4542 for (i
= ALL_CHOICES
.begin(); i
!= ALL_CHOICES
.end(); ++i
) {
4543 if (i
->second
== *it
) {
4547 assert(i
!= ALL_CHOICES
.end());
4548 bool pool_opt
= pool_opts_t::is_opt_name(i
->first
);
4550 f
->open_object_section("pool");
4551 f
->dump_string("pool", poolstr
);
4552 f
->dump_int("pool_id", pool
);
4556 f
->dump_int("pg_num", p
->get_pg_num());
4559 f
->dump_int("pgp_num", p
->get_pgp_num());
4562 f
->dump_int("auid", p
->get_auid());
4565 f
->dump_int("size", p
->get_size());
4568 f
->dump_int("min_size", p
->get_min_size());
4570 case CRASH_REPLAY_INTERVAL
:
4571 f
->dump_int("crash_replay_interval",
4572 p
->get_crash_replay_interval());
4575 if (osdmap
.crush
->rule_exists(p
->get_crush_rule())) {
4576 f
->dump_string("crush_rule", osdmap
.crush
->get_rule_name(
4577 p
->get_crush_rule()));
4579 f
->dump_string("crush_rule", stringify(p
->get_crush_rule()));
4586 case WRITE_FADVISE_DONTNEED
:
4589 f
->dump_string(i
->first
.c_str(),
4590 p
->has_flag(pg_pool_t::get_flag_by_name(i
->first
)) ?
4593 case HIT_SET_PERIOD
:
4594 f
->dump_int("hit_set_period", p
->hit_set_period
);
4597 f
->dump_int("hit_set_count", p
->hit_set_count
);
4600 f
->dump_string("hit_set_type",
4601 HitSet::get_type_name(p
->hit_set_params
.get_type()));
4605 if (p
->hit_set_params
.get_type() == HitSet::TYPE_BLOOM
) {
4606 BloomHitSet::Params
*bloomp
=
4607 static_cast<BloomHitSet::Params
*>(p
->hit_set_params
.impl
.get());
4608 f
->dump_float("hit_set_fpp", bloomp
->get_fpp());
4609 } else if(var
!= "all") {
4611 ss
<< "hit set is not of type Bloom; " <<
4612 "invalid to get a false positive rate!";
4618 case USE_GMT_HITSET
:
4619 f
->dump_bool("use_gmt_hitset", p
->use_gmt_hitset
);
4621 case TARGET_MAX_OBJECTS
:
4622 f
->dump_unsigned("target_max_objects", p
->target_max_objects
);
4624 case TARGET_MAX_BYTES
:
4625 f
->dump_unsigned("target_max_bytes", p
->target_max_bytes
);
4627 case CACHE_TARGET_DIRTY_RATIO
:
4628 f
->dump_unsigned("cache_target_dirty_ratio_micro",
4629 p
->cache_target_dirty_ratio_micro
);
4630 f
->dump_float("cache_target_dirty_ratio",
4631 ((float)p
->cache_target_dirty_ratio_micro
/1000000));
4633 case CACHE_TARGET_DIRTY_HIGH_RATIO
:
4634 f
->dump_unsigned("cache_target_dirty_high_ratio_micro",
4635 p
->cache_target_dirty_high_ratio_micro
);
4636 f
->dump_float("cache_target_dirty_high_ratio",
4637 ((float)p
->cache_target_dirty_high_ratio_micro
/1000000));
4639 case CACHE_TARGET_FULL_RATIO
:
4640 f
->dump_unsigned("cache_target_full_ratio_micro",
4641 p
->cache_target_full_ratio_micro
);
4642 f
->dump_float("cache_target_full_ratio",
4643 ((float)p
->cache_target_full_ratio_micro
/1000000));
4645 case CACHE_MIN_FLUSH_AGE
:
4646 f
->dump_unsigned("cache_min_flush_age", p
->cache_min_flush_age
);
4648 case CACHE_MIN_EVICT_AGE
:
4649 f
->dump_unsigned("cache_min_evict_age", p
->cache_min_evict_age
);
4651 case ERASURE_CODE_PROFILE
:
4652 f
->dump_string("erasure_code_profile", p
->erasure_code_profile
);
4654 case MIN_READ_RECENCY_FOR_PROMOTE
:
4655 f
->dump_int("min_read_recency_for_promote",
4656 p
->min_read_recency_for_promote
);
4658 case MIN_WRITE_RECENCY_FOR_PROMOTE
:
4659 f
->dump_int("min_write_recency_for_promote",
4660 p
->min_write_recency_for_promote
);
4663 f
->dump_int("fast_read", p
->fast_read
);
4665 case HIT_SET_GRADE_DECAY_RATE
:
4666 f
->dump_int("hit_set_grade_decay_rate",
4667 p
->hit_set_grade_decay_rate
);
4669 case HIT_SET_SEARCH_LAST_N
:
4670 f
->dump_int("hit_set_search_last_n",
4671 p
->hit_set_search_last_n
);
4673 case SCRUB_MIN_INTERVAL
:
4674 case SCRUB_MAX_INTERVAL
:
4675 case DEEP_SCRUB_INTERVAL
:
4676 case RECOVERY_PRIORITY
:
4677 case RECOVERY_OP_PRIORITY
:
4678 case SCRUB_PRIORITY
:
4679 case COMPRESSION_MODE
:
4680 case COMPRESSION_ALGORITHM
:
4681 case COMPRESSION_REQUIRED_RATIO
:
4682 case COMPRESSION_MAX_BLOB_SIZE
:
4683 case COMPRESSION_MIN_BLOB_SIZE
:
4685 case CSUM_MAX_BLOCK
:
4686 case CSUM_MIN_BLOCK
:
4687 pool_opts_t::key_t key
= pool_opts_t::get_opt_desc(i
->first
).key
;
4688 if (p
->opts
.is_set(key
)) {
4689 f
->open_object_section("pool");
4690 f
->dump_string("pool", poolstr
);
4691 f
->dump_int("pool_id", pool
);
4692 if(*it
== CSUM_TYPE
) {
4694 p
->opts
.get(pool_opts_t::CSUM_TYPE
, &val
);
4695 f
->dump_string(i
->first
.c_str(), Checksummer::get_csum_type_string(val
));
4697 p
->opts
.dump(i
->first
, f
.get());
4711 for(choices_set_t::const_iterator it
= selected_choices
.begin();
4712 it
!= selected_choices
.end(); ++it
) {
4713 choices_map_t::const_iterator i
;
4716 ss
<< "pg_num: " << p
->get_pg_num() << "\n";
4719 ss
<< "pgp_num: " << p
->get_pgp_num() << "\n";
4722 ss
<< "auid: " << p
->get_auid() << "\n";
4725 ss
<< "size: " << p
->get_size() << "\n";
4728 ss
<< "min_size: " << p
->get_min_size() << "\n";
4730 case CRASH_REPLAY_INTERVAL
:
4731 ss
<< "crash_replay_interval: " <<
4732 p
->get_crash_replay_interval() << "\n";
4735 if (osdmap
.crush
->rule_exists(p
->get_crush_rule())) {
4736 ss
<< "crush_rule: " << osdmap
.crush
->get_rule_name(
4737 p
->get_crush_rule()) << "\n";
4739 ss
<< "crush_rule: " << p
->get_crush_rule() << "\n";
4742 case HIT_SET_PERIOD
:
4743 ss
<< "hit_set_period: " << p
->hit_set_period
<< "\n";
4746 ss
<< "hit_set_count: " << p
->hit_set_count
<< "\n";
4749 ss
<< "hit_set_type: " <<
4750 HitSet::get_type_name(p
->hit_set_params
.get_type()) << "\n";
4754 if (p
->hit_set_params
.get_type() == HitSet::TYPE_BLOOM
) {
4755 BloomHitSet::Params
*bloomp
=
4756 static_cast<BloomHitSet::Params
*>(p
->hit_set_params
.impl
.get());
4757 ss
<< "hit_set_fpp: " << bloomp
->get_fpp() << "\n";
4758 } else if(var
!= "all") {
4759 ss
<< "hit set is not of type Bloom; " <<
4760 "invalid to get a false positive rate!";
4766 case USE_GMT_HITSET
:
4767 ss
<< "use_gmt_hitset: " << p
->use_gmt_hitset
<< "\n";
4769 case TARGET_MAX_OBJECTS
:
4770 ss
<< "target_max_objects: " << p
->target_max_objects
<< "\n";
4772 case TARGET_MAX_BYTES
:
4773 ss
<< "target_max_bytes: " << p
->target_max_bytes
<< "\n";
4775 case CACHE_TARGET_DIRTY_RATIO
:
4776 ss
<< "cache_target_dirty_ratio: "
4777 << ((float)p
->cache_target_dirty_ratio_micro
/1000000) << "\n";
4779 case CACHE_TARGET_DIRTY_HIGH_RATIO
:
4780 ss
<< "cache_target_dirty_high_ratio: "
4781 << ((float)p
->cache_target_dirty_high_ratio_micro
/1000000) << "\n";
4783 case CACHE_TARGET_FULL_RATIO
:
4784 ss
<< "cache_target_full_ratio: "
4785 << ((float)p
->cache_target_full_ratio_micro
/1000000) << "\n";
4787 case CACHE_MIN_FLUSH_AGE
:
4788 ss
<< "cache_min_flush_age: " << p
->cache_min_flush_age
<< "\n";
4790 case CACHE_MIN_EVICT_AGE
:
4791 ss
<< "cache_min_evict_age: " << p
->cache_min_evict_age
<< "\n";
4793 case ERASURE_CODE_PROFILE
:
4794 ss
<< "erasure_code_profile: " << p
->erasure_code_profile
<< "\n";
4796 case MIN_READ_RECENCY_FOR_PROMOTE
:
4797 ss
<< "min_read_recency_for_promote: " <<
4798 p
->min_read_recency_for_promote
<< "\n";
4800 case HIT_SET_GRADE_DECAY_RATE
:
4801 ss
<< "hit_set_grade_decay_rate: " <<
4802 p
->hit_set_grade_decay_rate
<< "\n";
4804 case HIT_SET_SEARCH_LAST_N
:
4805 ss
<< "hit_set_search_last_n: " <<
4806 p
->hit_set_search_last_n
<< "\n";
4812 case WRITE_FADVISE_DONTNEED
:
4815 for (i
= ALL_CHOICES
.begin(); i
!= ALL_CHOICES
.end(); ++i
) {
4816 if (i
->second
== *it
)
4819 assert(i
!= ALL_CHOICES
.end());
4820 ss
<< i
->first
<< ": " <<
4821 (p
->has_flag(pg_pool_t::get_flag_by_name(i
->first
)) ?
4822 "true" : "false") << "\n";
4824 case MIN_WRITE_RECENCY_FOR_PROMOTE
:
4825 ss
<< "min_write_recency_for_promote: " <<
4826 p
->min_write_recency_for_promote
<< "\n";
4829 ss
<< "fast_read: " << p
->fast_read
<< "\n";
4831 case SCRUB_MIN_INTERVAL
:
4832 case SCRUB_MAX_INTERVAL
:
4833 case DEEP_SCRUB_INTERVAL
:
4834 case RECOVERY_PRIORITY
:
4835 case RECOVERY_OP_PRIORITY
:
4836 case SCRUB_PRIORITY
:
4837 case COMPRESSION_MODE
:
4838 case COMPRESSION_ALGORITHM
:
4839 case COMPRESSION_REQUIRED_RATIO
:
4840 case COMPRESSION_MAX_BLOB_SIZE
:
4841 case COMPRESSION_MIN_BLOB_SIZE
:
4843 case CSUM_MAX_BLOCK
:
4844 case CSUM_MIN_BLOCK
:
4845 for (i
= ALL_CHOICES
.begin(); i
!= ALL_CHOICES
.end(); ++i
) {
4846 if (i
->second
== *it
)
4849 assert(i
!= ALL_CHOICES
.end());
4851 pool_opts_t::key_t key
= pool_opts_t::get_opt_desc(i
->first
).key
;
4852 if (p
->opts
.is_set(key
)) {
4853 if(key
== pool_opts_t::CSUM_TYPE
) {
4855 p
->opts
.get(key
, &val
);
4856 ss
<< i
->first
<< ": " << Checksummer::get_csum_type_string(val
) << "\n";
4858 ss
<< i
->first
<< ": " << p
->opts
.get(key
) << "\n";
4864 rdata
.append(ss
.str());
4869 } else if (prefix
== "osd pool stats") {
4870 r
= mon
->pgservice
->process_pg_command(prefix
, cmdmap
,
4871 osdmap
, f
.get(), &ss
, &rdata
);
4872 } else if (prefix
== "osd pool get-quota") {
4874 cmd_getval(g_ceph_context
, cmdmap
, "pool", pool_name
);
4876 int64_t poolid
= osdmap
.lookup_pg_pool_name(pool_name
);
4878 assert(poolid
== -ENOENT
);
4879 ss
<< "unrecognized pool '" << pool_name
<< "'";
4883 const pg_pool_t
*p
= osdmap
.get_pg_pool(poolid
);
4886 f
->open_object_section("pool_quotas");
4887 f
->dump_string("pool_name", pool_name
);
4888 f
->dump_unsigned("pool_id", poolid
);
4889 f
->dump_unsigned("quota_max_objects", p
->quota_max_objects
);
4890 f
->dump_unsigned("quota_max_bytes", p
->quota_max_bytes
);
4895 rs
<< "quotas for pool '" << pool_name
<< "':\n"
4896 << " max objects: ";
4897 if (p
->quota_max_objects
== 0)
4900 rs
<< si_t(p
->quota_max_objects
) << " objects";
4903 if (p
->quota_max_bytes
== 0)
4906 rs
<< si_t(p
->quota_max_bytes
) << "B";
4907 rdata
.append(rs
.str());
4911 } else if (prefix
== "osd crush rule list" ||
4912 prefix
== "osd crush rule ls") {
4914 f
->open_array_section("rules");
4915 osdmap
.crush
->list_rules(f
.get());
4920 osdmap
.crush
->list_rules(&ss
);
4921 rdata
.append(ss
.str());
4923 } else if (prefix
== "osd crush rule dump") {
4925 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
4927 cmd_getval(g_ceph_context
, cmdmap
, "format", format
);
4928 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json-pretty"));
4930 f
->open_array_section("rules");
4931 osdmap
.crush
->dump_rules(f
.get());
4934 int ruleno
= osdmap
.crush
->get_rule_id(name
);
4936 ss
<< "unknown crush rule '" << name
<< "'";
4940 osdmap
.crush
->dump_rule(ruleno
, f
.get());
4945 rdata
.append(rs
.str());
4946 } else if (prefix
== "osd crush dump") {
4948 cmd_getval(g_ceph_context
, cmdmap
, "format", format
);
4949 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json-pretty"));
4950 f
->open_object_section("crush_map");
4951 osdmap
.crush
->dump(f
.get());
4956 rdata
.append(rs
.str());
4957 } else if (prefix
== "osd crush show-tunables") {
4959 cmd_getval(g_ceph_context
, cmdmap
, "format", format
);
4960 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json-pretty"));
4961 f
->open_object_section("crush_map_tunables");
4962 osdmap
.crush
->dump_tunables(f
.get());
4967 rdata
.append(rs
.str());
4968 } else if (prefix
== "osd crush tree") {
4970 cmd_getval(g_ceph_context
, cmdmap
, "shadow", shadow
);
4971 bool show_shadow
= shadow
== "--show-shadow";
4972 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
));
4974 osdmap
.crush
->dump_tree(nullptr,
4976 osdmap
.get_pool_names(),
4981 osdmap
.crush
->dump_tree(&ss
,
4983 osdmap
.get_pool_names(),
4985 rdata
.append(ss
.str());
4987 } else if (prefix
== "osd crush ls") {
4989 if (!cmd_getval(g_ceph_context
, cmdmap
, "node", name
)) {
4990 ss
<< "no node specified";
4994 if (!osdmap
.crush
->name_exists(name
)) {
4995 ss
<< "node '" << name
<< "' does not exist";
4999 int id
= osdmap
.crush
->get_item_id(name
);
5002 result
.push_back(id
);
5004 int num
= osdmap
.crush
->get_bucket_size(id
);
5005 for (int i
= 0; i
< num
; ++i
) {
5006 result
.push_back(osdmap
.crush
->get_bucket_item(id
, i
));
5010 f
->open_array_section("items");
5011 for (auto i
: result
) {
5012 f
->dump_string("item", osdmap
.crush
->get_item_name(i
));
5018 for (auto i
: result
) {
5019 ss
<< osdmap
.crush
->get_item_name(i
) << "\n";
5021 rdata
.append(ss
.str());
5024 } else if (prefix
== "osd crush class ls") {
5025 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json-pretty"));
5026 f
->open_array_section("crush_classes");
5027 for (auto i
: osdmap
.crush
->class_name
)
5028 f
->dump_string("class", i
.second
);
5031 } else if (prefix
== "osd crush class ls-osd") {
5033 cmd_getval(g_ceph_context
, cmdmap
, "class", name
);
5034 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty", "json-pretty"));
5036 osdmap
.crush
->get_devices_by_class(name
, &osds
);
5037 f
->open_array_section("osds");
5038 for (auto& osd
: osds
)
5039 f
->dump_int("osd", osd
);
5042 } else if (prefix
== "osd erasure-code-profile ls") {
5043 const auto &profiles
= osdmap
.get_erasure_code_profiles();
5045 f
->open_array_section("erasure-code-profiles");
5046 for (auto i
= profiles
.begin(); i
!= profiles
.end(); ++i
) {
5048 f
->dump_string("profile", i
->first
.c_str());
5050 rdata
.append(i
->first
+ "\n");
5057 rdata
.append(rs
.str());
5059 } else if (prefix
== "osd crush weight-set ls") {
5060 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
));
5062 f
->open_array_section("weight_sets");
5063 if (osdmap
.crush
->have_choose_args(CrushWrapper::DEFAULT_CHOOSE_ARGS
)) {
5064 f
->dump_string("pool", "(compat)");
5066 for (auto& i
: osdmap
.crush
->choose_args
) {
5068 f
->dump_string("pool", osdmap
.get_pool_name(i
.first
));
5075 if (osdmap
.crush
->have_choose_args(CrushWrapper::DEFAULT_CHOOSE_ARGS
)) {
5078 for (auto& i
: osdmap
.crush
->choose_args
) {
5080 rs
<< osdmap
.get_pool_name(i
.first
) << "\n";
5083 rdata
.append(rs
.str());
5085 } else if (prefix
== "osd crush weight-set dump") {
5086 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
, "json-pretty",
5088 osdmap
.crush
->dump_choose_args(f
.get());
5090 } else if (prefix
== "osd erasure-code-profile get") {
5092 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
5093 if (!osdmap
.has_erasure_code_profile(name
)) {
5094 ss
<< "unknown erasure code profile '" << name
<< "'";
5098 const map
<string
,string
> &profile
= osdmap
.get_erasure_code_profile(name
);
5100 f
->open_object_section("profile");
5101 for (map
<string
,string
>::const_iterator i
= profile
.begin();
5105 f
->dump_string(i
->first
.c_str(), i
->second
.c_str());
5107 rdata
.append(i
->first
+ "=" + i
->second
+ "\n");
5114 rdata
.append(rs
.str());
5117 // try prepare update
5124 mon
->reply_command(op
, r
, rs
, rdata
, get_last_committed());
5128 void OSDMonitor::update_pool_flags(int64_t pool_id
, uint64_t flags
)
5130 const pg_pool_t
*pool
= osdmap
.get_pg_pool(pool_id
);
5131 pending_inc
.get_new_pool(pool_id
, pool
)->flags
= flags
;
5134 bool OSDMonitor::update_pools_status()
5136 if (!mon
->pgservice
->is_readable())
5141 auto& pools
= osdmap
.get_pools();
5142 for (auto it
= pools
.begin(); it
!= pools
.end(); ++it
) {
5143 const pool_stat_t
*pstat
= mon
->pgservice
->get_pool_stat(it
->first
);
5146 const object_stat_sum_t
& sum
= pstat
->stats
.sum
;
5147 const pg_pool_t
&pool
= it
->second
;
5148 const string
& pool_name
= osdmap
.get_pool_name(it
->first
);
5151 (pool
.quota_max_bytes
> 0 && (uint64_t)sum
.num_bytes
>= pool
.quota_max_bytes
) ||
5152 (pool
.quota_max_objects
> 0 && (uint64_t)sum
.num_objects
>= pool
.quota_max_objects
);
5154 if (pool
.has_flag(pg_pool_t::FLAG_FULL
)) {
5158 mon
->clog
->info() << "pool '" << pool_name
5159 << "' no longer full; removing FULL flag";
5161 update_pool_flags(it
->first
, pool
.get_flags() & ~pg_pool_t::FLAG_FULL
);
5167 if (pool
.quota_max_bytes
> 0 &&
5168 (uint64_t)sum
.num_bytes
>= pool
.quota_max_bytes
) {
5169 mon
->clog
->warn() << "pool '" << pool_name
<< "' is full"
5170 << " (reached quota's max_bytes: "
5171 << si_t(pool
.quota_max_bytes
) << ")";
5173 if (pool
.quota_max_objects
> 0 &&
5174 (uint64_t)sum
.num_objects
>= pool
.quota_max_objects
) {
5175 mon
->clog
->warn() << "pool '" << pool_name
<< "' is full"
5176 << " (reached quota's max_objects: "
5177 << pool
.quota_max_objects
<< ")";
5179 update_pool_flags(it
->first
, pool
.get_flags() | pg_pool_t::FLAG_FULL
);
5186 int OSDMonitor::prepare_new_pool(MonOpRequestRef op
)
5188 op
->mark_osdmon_event(__func__
);
5189 MPoolOp
*m
= static_cast<MPoolOp
*>(op
->get_req());
5190 dout(10) << "prepare_new_pool from " << m
->get_connection() << dendl
;
5191 MonSession
*session
= m
->get_session();
5194 string erasure_code_profile
;
5198 return prepare_new_pool(m
->name
, m
->auid
, m
->crush_rule
, rule_name
,
5200 erasure_code_profile
,
5201 pg_pool_t::TYPE_REPLICATED
, 0, FAST_READ_OFF
, &ss
);
5203 return prepare_new_pool(m
->name
, session
->auid
, m
->crush_rule
, rule_name
,
5205 erasure_code_profile
,
5206 pg_pool_t::TYPE_REPLICATED
, 0, FAST_READ_OFF
, &ss
);
5209 int OSDMonitor::crush_rename_bucket(const string
& srcname
,
5210 const string
& dstname
,
5215 // Avoid creating a pending crush if it does not already exists and
5216 // the rename would fail.
5218 if (!_have_pending_crush()) {
5219 ret
= _get_stable_crush().can_rename_bucket(srcname
,
5226 CrushWrapper newcrush
;
5227 _get_pending_crush(newcrush
);
5229 ret
= newcrush
.rename_bucket(srcname
,
5235 pending_inc
.crush
.clear();
5236 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
5237 *ss
<< "renamed bucket " << srcname
<< " into " << dstname
;
5241 void OSDMonitor::check_legacy_ec_plugin(const string
& plugin
, const string
& profile
) const
5243 string replacement
= "";
5245 if (plugin
== "jerasure_generic" ||
5246 plugin
== "jerasure_sse3" ||
5247 plugin
== "jerasure_sse4" ||
5248 plugin
== "jerasure_neon") {
5249 replacement
= "jerasure";
5250 } else if (plugin
== "shec_generic" ||
5251 plugin
== "shec_sse3" ||
5252 plugin
== "shec_sse4" ||
5253 plugin
== "shec_neon") {
5254 replacement
= "shec";
5257 if (replacement
!= "") {
5258 dout(0) << "WARNING: erasure coding profile " << profile
<< " uses plugin "
5259 << plugin
<< " that has been deprecated. Please use "
5260 << replacement
<< " instead." << dendl
;
5264 int OSDMonitor::normalize_profile(const string
& profilename
,
5265 ErasureCodeProfile
&profile
,
5269 ErasureCodeInterfaceRef erasure_code
;
5270 ErasureCodePluginRegistry
&instance
= ErasureCodePluginRegistry::instance();
5271 ErasureCodeProfile::const_iterator plugin
= profile
.find("plugin");
5272 check_legacy_ec_plugin(plugin
->second
, profilename
);
5273 int err
= instance
.factory(plugin
->second
,
5274 g_conf
->get_val
<std::string
>("erasure_code_dir"),
5275 profile
, &erasure_code
, ss
);
5280 err
= erasure_code
->init(profile
, ss
);
5285 auto it
= profile
.find("stripe_unit");
5286 if (it
!= profile
.end()) {
5288 uint32_t stripe_unit
= strict_si_cast
<uint32_t>(it
->second
.c_str(), &err_str
);
5289 if (!err_str
.empty()) {
5290 *ss
<< "could not parse stripe_unit '" << it
->second
5291 << "': " << err_str
<< std::endl
;
5294 uint32_t data_chunks
= erasure_code
->get_data_chunk_count();
5295 uint32_t chunk_size
= erasure_code
->get_chunk_size(stripe_unit
* data_chunks
);
5296 if (chunk_size
!= stripe_unit
) {
5297 *ss
<< "stripe_unit " << stripe_unit
<< " does not match ec profile "
5298 << "alignment. Would be padded to " << chunk_size
5302 if ((stripe_unit
% 4096) != 0 && !force
) {
5303 *ss
<< "stripe_unit should be a multiple of 4096 bytes for best performance."
5304 << "use --force to override this check" << std::endl
;
5311 int OSDMonitor::crush_rule_create_erasure(const string
&name
,
5312 const string
&profile
,
5316 int ruleid
= osdmap
.crush
->get_rule_id(name
);
5317 if (ruleid
!= -ENOENT
) {
5318 *rule
= osdmap
.crush
->get_rule_mask_ruleset(ruleid
);
5322 CrushWrapper newcrush
;
5323 _get_pending_crush(newcrush
);
5325 ruleid
= newcrush
.get_rule_id(name
);
5326 if (ruleid
!= -ENOENT
) {
5327 *rule
= newcrush
.get_rule_mask_ruleset(ruleid
);
5330 ErasureCodeInterfaceRef erasure_code
;
5331 int err
= get_erasure_code(profile
, &erasure_code
, ss
);
5333 *ss
<< "failed to load plugin using profile " << profile
<< std::endl
;
5337 err
= erasure_code
->create_rule(name
, newcrush
, ss
);
5338 erasure_code
.reset();
5342 pending_inc
.crush
.clear();
5343 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
5348 int OSDMonitor::get_erasure_code(const string
&erasure_code_profile
,
5349 ErasureCodeInterfaceRef
*erasure_code
,
5352 if (pending_inc
.has_erasure_code_profile(erasure_code_profile
))
5354 ErasureCodeProfile profile
=
5355 osdmap
.get_erasure_code_profile(erasure_code_profile
);
5356 ErasureCodeProfile::const_iterator plugin
=
5357 profile
.find("plugin");
5358 if (plugin
== profile
.end()) {
5359 *ss
<< "cannot determine the erasure code plugin"
5360 << " because there is no 'plugin' entry in the erasure_code_profile "
5361 << profile
<< std::endl
;
5364 check_legacy_ec_plugin(plugin
->second
, erasure_code_profile
);
5365 ErasureCodePluginRegistry
&instance
= ErasureCodePluginRegistry::instance();
5366 return instance
.factory(plugin
->second
,
5367 g_conf
->get_val
<std::string
>("erasure_code_dir"),
5368 profile
, erasure_code
, ss
);
5371 int OSDMonitor::check_cluster_features(uint64_t features
,
5374 stringstream unsupported_ss
;
5375 int unsupported_count
= 0;
5376 if ((mon
->get_quorum_con_features() & features
) != features
) {
5377 unsupported_ss
<< "the monitor cluster";
5378 ++unsupported_count
;
5381 set
<int32_t> up_osds
;
5382 osdmap
.get_up_osds(up_osds
);
5383 for (set
<int32_t>::iterator it
= up_osds
.begin();
5384 it
!= up_osds
.end(); ++it
) {
5385 const osd_xinfo_t
&xi
= osdmap
.get_xinfo(*it
);
5386 if ((xi
.features
& features
) != features
) {
5387 if (unsupported_count
> 0)
5388 unsupported_ss
<< ", ";
5389 unsupported_ss
<< "osd." << *it
;
5390 unsupported_count
++;
5394 if (unsupported_count
> 0) {
5395 ss
<< "features " << features
<< " unsupported by: "
5396 << unsupported_ss
.str();
5400 // check pending osd state, too!
5401 for (map
<int32_t,osd_xinfo_t
>::const_iterator p
=
5402 pending_inc
.new_xinfo
.begin();
5403 p
!= pending_inc
.new_xinfo
.end(); ++p
) {
5404 const osd_xinfo_t
&xi
= p
->second
;
5405 if ((xi
.features
& features
) != features
) {
5406 dout(10) << __func__
<< " pending osd." << p
->first
5407 << " features are insufficient; retry" << dendl
;
5415 bool OSDMonitor::validate_crush_against_features(const CrushWrapper
*newcrush
,
5418 OSDMap::Incremental new_pending
= pending_inc
;
5419 ::encode(*newcrush
, new_pending
.crush
, mon
->get_quorum_con_features());
5421 newmap
.deepish_copy_from(osdmap
);
5422 newmap
.apply_incremental(new_pending
);
5425 if (newmap
.require_min_compat_client
> 0) {
5426 auto mv
= newmap
.get_min_compat_client();
5427 if (mv
> newmap
.require_min_compat_client
) {
5428 ss
<< "new crush map requires client version " << ceph_release_name(mv
)
5429 << " but require_min_compat_client is "
5430 << ceph_release_name(newmap
.require_min_compat_client
);
5437 newmap
.get_features(CEPH_ENTITY_TYPE_MON
, NULL
) |
5438 newmap
.get_features(CEPH_ENTITY_TYPE_OSD
, NULL
);
5439 stringstream features_ss
;
5440 int r
= check_cluster_features(features
, features_ss
);
5442 ss
<< "Could not change CRUSH: " << features_ss
.str();
5449 bool OSDMonitor::erasure_code_profile_in_use(
5450 const mempool::osdmap::map
<int64_t, pg_pool_t
> &pools
,
5451 const string
&profile
,
5455 for (map
<int64_t, pg_pool_t
>::const_iterator p
= pools
.begin();
5458 if (p
->second
.erasure_code_profile
== profile
) {
5459 *ss
<< osdmap
.pool_name
[p
->first
] << " ";
5464 *ss
<< "pool(s) are using the erasure code profile '" << profile
<< "'";
5469 int OSDMonitor::parse_erasure_code_profile(const vector
<string
> &erasure_code_profile
,
5470 map
<string
,string
> *erasure_code_profile_map
,
5473 int r
= get_json_str_map(g_conf
->osd_pool_default_erasure_code_profile
,
5475 erasure_code_profile_map
);
5478 assert((*erasure_code_profile_map
).count("plugin"));
5479 string default_plugin
= (*erasure_code_profile_map
)["plugin"];
5480 map
<string
,string
> user_map
;
5481 for (vector
<string
>::const_iterator i
= erasure_code_profile
.begin();
5482 i
!= erasure_code_profile
.end();
5484 size_t equal
= i
->find('=');
5485 if (equal
== string::npos
) {
5486 user_map
[*i
] = string();
5487 (*erasure_code_profile_map
)[*i
] = string();
5489 const string key
= i
->substr(0, equal
);
5491 const string value
= i
->substr(equal
);
5492 user_map
[key
] = value
;
5493 (*erasure_code_profile_map
)[key
] = value
;
5497 if (user_map
.count("plugin") && user_map
["plugin"] != default_plugin
)
5498 (*erasure_code_profile_map
) = user_map
;
5503 int OSDMonitor::prepare_pool_size(const unsigned pool_type
,
5504 const string
&erasure_code_profile
,
5505 unsigned *size
, unsigned *min_size
,
5509 switch (pool_type
) {
5510 case pg_pool_t::TYPE_REPLICATED
:
5511 *size
= g_conf
->osd_pool_default_size
;
5512 *min_size
= g_conf
->get_osd_pool_default_min_size();
5514 case pg_pool_t::TYPE_ERASURE
:
5516 ErasureCodeInterfaceRef erasure_code
;
5517 err
= get_erasure_code(erasure_code_profile
, &erasure_code
, ss
);
5519 *size
= erasure_code
->get_chunk_count();
5520 *min_size
= MIN(erasure_code
->get_data_chunk_count() + 1, *size
);
5525 *ss
<< "prepare_pool_size: " << pool_type
<< " is not a known pool type";
5532 int OSDMonitor::prepare_pool_stripe_width(const unsigned pool_type
,
5533 const string
&erasure_code_profile
,
5534 uint32_t *stripe_width
,
5538 switch (pool_type
) {
5539 case pg_pool_t::TYPE_REPLICATED
:
5542 case pg_pool_t::TYPE_ERASURE
:
5544 ErasureCodeProfile profile
=
5545 osdmap
.get_erasure_code_profile(erasure_code_profile
);
5546 ErasureCodeInterfaceRef erasure_code
;
5547 err
= get_erasure_code(erasure_code_profile
, &erasure_code
, ss
);
5550 uint32_t data_chunks
= erasure_code
->get_data_chunk_count();
5551 uint32_t stripe_unit
= g_conf
->osd_pool_erasure_code_stripe_unit
;
5552 auto it
= profile
.find("stripe_unit");
5553 if (it
!= profile
.end()) {
5555 stripe_unit
= strict_si_cast
<uint32_t>(it
->second
.c_str(), &err_str
);
5556 assert(err_str
.empty());
5558 *stripe_width
= data_chunks
*
5559 erasure_code
->get_chunk_size(stripe_unit
* data_chunks
);
5563 *ss
<< "prepare_pool_stripe_width: "
5564 << pool_type
<< " is not a known pool type";
5571 int OSDMonitor::prepare_pool_crush_rule(const unsigned pool_type
,
5572 const string
&erasure_code_profile
,
5573 const string
&rule_name
,
5578 if (*crush_rule
< 0) {
5579 switch (pool_type
) {
5580 case pg_pool_t::TYPE_REPLICATED
:
5582 if (rule_name
== "") {
5584 *crush_rule
= osdmap
.crush
->get_osd_pool_default_crush_replicated_ruleset(g_ceph_context
);
5585 if (*crush_rule
< 0) {
5586 // Errors may happen e.g. if no valid rule is available
5587 *ss
<< "No suitable CRUSH rule exists, check "
5588 << "'osd pool default crush *' config options";
5592 return get_crush_rule(rule_name
, crush_rule
, ss
);
5596 case pg_pool_t::TYPE_ERASURE
:
5598 int err
= crush_rule_create_erasure(rule_name
,
5599 erasure_code_profile
,
5603 dout(20) << "prepare_pool_crush_rule: rule "
5604 << rule_name
<< " try again" << dendl
;
5607 // need to wait for the crush rule to be proposed before proceeding
5618 *ss
<< "prepare_pool_crush_rule: " << pool_type
5619 << " is not a known pool type";
5624 if (!osdmap
.crush
->ruleset_exists(*crush_rule
)) {
5625 *ss
<< "CRUSH rule " << *crush_rule
<< " not found";
5633 int OSDMonitor::get_crush_rule(const string
&rule_name
,
5638 ret
= osdmap
.crush
->get_rule_id(rule_name
);
5639 if (ret
!= -ENOENT
) {
5643 CrushWrapper newcrush
;
5644 _get_pending_crush(newcrush
);
5646 ret
= newcrush
.get_rule_id(rule_name
);
5647 if (ret
!= -ENOENT
) {
5648 // found it, wait for it to be proposed
5649 dout(20) << __func__
<< ": rule " << rule_name
5650 << " try again" << dendl
;
5653 // Cannot find it , return error
5654 *ss
<< "specified rule " << rule_name
<< " doesn't exist";
5662 * @param name The name of the new pool
5663 * @param auid The auid of the pool owner. Can be -1
5664 * @param crush_rule The crush rule to use. If <0, will use the system default
5665 * @param crush_rule_name The crush rule to use, if crush_rulset <0
5666 * @param pg_num The pg_num to use. If set to 0, will use the system default
5667 * @param pgp_num The pgp_num to use. If set to 0, will use the system default
5668 * @param erasure_code_profile The profile name in OSDMap to be used for erasure code
5669 * @param pool_type TYPE_ERASURE, or TYPE_REP
5670 * @param expected_num_objects expected number of objects on the pool
5671 * @param fast_read fast read type.
5672 * @param ss human readable error message, if any.
5674 * @return 0 on success, negative errno on failure.
5676 int OSDMonitor::prepare_new_pool(string
& name
, uint64_t auid
,
5678 const string
&crush_rule_name
,
5679 unsigned pg_num
, unsigned pgp_num
,
5680 const string
&erasure_code_profile
,
5681 const unsigned pool_type
,
5682 const uint64_t expected_num_objects
,
5683 FastReadType fast_read
,
5686 if (name
.length() == 0)
5689 pg_num
= g_conf
->osd_pool_default_pg_num
;
5691 pgp_num
= g_conf
->osd_pool_default_pgp_num
;
5692 if (pg_num
> (unsigned)g_conf
->mon_max_pool_pg_num
) {
5693 *ss
<< "'pg_num' must be greater than 0 and less than or equal to "
5694 << g_conf
->mon_max_pool_pg_num
5695 << " (you may adjust 'mon max pool pg num' for higher values)";
5698 if (pgp_num
> pg_num
) {
5699 *ss
<< "'pgp_num' must be greater than 0 and lower or equal than 'pg_num'"
5700 << ", which in this case is " << pg_num
;
5703 if (pool_type
== pg_pool_t::TYPE_REPLICATED
&& fast_read
== FAST_READ_ON
) {
5704 *ss
<< "'fast_read' can only apply to erasure coding pool";
5708 r
= prepare_pool_crush_rule(pool_type
, erasure_code_profile
,
5709 crush_rule_name
, &crush_rule
, ss
);
5711 dout(10) << " prepare_pool_crush_rule returns " << r
<< dendl
;
5714 if (g_conf
->mon_osd_crush_smoke_test
) {
5715 CrushWrapper newcrush
;
5716 _get_pending_crush(newcrush
);
5718 CrushTester
tester(newcrush
, err
);
5719 tester
.set_max_x(50);
5720 tester
.set_rule(crush_rule
);
5721 r
= tester
.test_with_fork(g_conf
->mon_lease
);
5723 dout(10) << " tester.test_with_fork returns " << r
5724 << ": " << err
.str() << dendl
;
5725 *ss
<< "crush test failed with " << r
<< ": " << err
.str();
5729 unsigned size
, min_size
;
5730 r
= prepare_pool_size(pool_type
, erasure_code_profile
, &size
, &min_size
, ss
);
5732 dout(10) << " prepare_pool_size returns " << r
<< dendl
;
5736 if (!osdmap
.crush
->check_crush_rule(crush_rule
, pool_type
, size
, *ss
)) {
5740 uint32_t stripe_width
= 0;
5741 r
= prepare_pool_stripe_width(pool_type
, erasure_code_profile
, &stripe_width
, ss
);
5743 dout(10) << " prepare_pool_stripe_width returns " << r
<< dendl
;
5748 if (pool_type
== pg_pool_t::TYPE_ERASURE
) {
5749 switch (fast_read
) {
5756 case FAST_READ_DEFAULT
:
5757 fread
= g_conf
->mon_osd_pool_ec_fast_read
;
5760 *ss
<< "invalid fast_read setting: " << fast_read
;
5765 for (map
<int64_t,string
>::iterator p
= pending_inc
.new_pool_names
.begin();
5766 p
!= pending_inc
.new_pool_names
.end();
5768 if (p
->second
== name
)
5772 if (-1 == pending_inc
.new_pool_max
)
5773 pending_inc
.new_pool_max
= osdmap
.pool_max
;
5774 int64_t pool
= ++pending_inc
.new_pool_max
;
5776 pg_pool_t
*pi
= pending_inc
.get_new_pool(pool
, &empty
);
5777 pi
->type
= pool_type
;
5778 pi
->fast_read
= fread
;
5779 pi
->flags
= g_conf
->osd_pool_default_flags
;
5780 if (g_conf
->osd_pool_default_flag_hashpspool
)
5781 pi
->set_flag(pg_pool_t::FLAG_HASHPSPOOL
);
5782 if (g_conf
->osd_pool_default_flag_nodelete
)
5783 pi
->set_flag(pg_pool_t::FLAG_NODELETE
);
5784 if (g_conf
->osd_pool_default_flag_nopgchange
)
5785 pi
->set_flag(pg_pool_t::FLAG_NOPGCHANGE
);
5786 if (g_conf
->osd_pool_default_flag_nosizechange
)
5787 pi
->set_flag(pg_pool_t::FLAG_NOSIZECHANGE
);
5788 if (g_conf
->osd_pool_use_gmt_hitset
&&
5789 (osdmap
.get_up_osd_features() & CEPH_FEATURE_OSD_HITSET_GMT
))
5790 pi
->use_gmt_hitset
= true;
5792 pi
->use_gmt_hitset
= false;
5795 pi
->min_size
= min_size
;
5796 pi
->crush_rule
= crush_rule
;
5797 pi
->expected_num_objects
= expected_num_objects
;
5798 pi
->object_hash
= CEPH_STR_HASH_RJENKINS
;
5799 pi
->set_pg_num(pg_num
);
5800 pi
->set_pgp_num(pgp_num
);
5801 pi
->last_change
= pending_inc
.epoch
;
5803 pi
->erasure_code_profile
= erasure_code_profile
;
5804 pi
->stripe_width
= stripe_width
;
5805 pi
->cache_target_dirty_ratio_micro
=
5806 g_conf
->osd_pool_default_cache_target_dirty_ratio
* 1000000;
5807 pi
->cache_target_dirty_high_ratio_micro
=
5808 g_conf
->osd_pool_default_cache_target_dirty_high_ratio
* 1000000;
5809 pi
->cache_target_full_ratio_micro
=
5810 g_conf
->osd_pool_default_cache_target_full_ratio
* 1000000;
5811 pi
->cache_min_flush_age
= g_conf
->osd_pool_default_cache_min_flush_age
;
5812 pi
->cache_min_evict_age
= g_conf
->osd_pool_default_cache_min_evict_age
;
5813 pending_inc
.new_pool_names
[pool
] = name
;
5817 bool OSDMonitor::prepare_set_flag(MonOpRequestRef op
, int flag
)
5819 op
->mark_osdmon_event(__func__
);
5821 if (pending_inc
.new_flags
< 0)
5822 pending_inc
.new_flags
= osdmap
.get_flags();
5823 pending_inc
.new_flags
|= flag
;
5824 ss
<< OSDMap::get_flag_string(flag
) << " is set";
5825 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, ss
.str(),
5826 get_last_committed() + 1));
5830 bool OSDMonitor::prepare_unset_flag(MonOpRequestRef op
, int flag
)
5832 op
->mark_osdmon_event(__func__
);
5834 if (pending_inc
.new_flags
< 0)
5835 pending_inc
.new_flags
= osdmap
.get_flags();
5836 pending_inc
.new_flags
&= ~flag
;
5837 ss
<< OSDMap::get_flag_string(flag
) << " is unset";
5838 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, ss
.str(),
5839 get_last_committed() + 1));
5843 int OSDMonitor::prepare_command_pool_set(map
<string
,cmd_vartype
> &cmdmap
,
5847 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
5848 int64_t pool
= osdmap
.lookup_pg_pool_name(poolstr
.c_str());
5850 ss
<< "unrecognized pool '" << poolstr
<< "'";
5854 cmd_getval(g_ceph_context
, cmdmap
, "var", var
);
5856 pg_pool_t p
= *osdmap
.get_pg_pool(pool
);
5857 if (pending_inc
.new_pools
.count(pool
))
5858 p
= pending_inc
.new_pools
[pool
];
5860 // accept val as a json string in the normal case (current
5861 // generation monitor). parse out int or float values from the
5862 // string as needed. however, if it is not a string, try to pull
5863 // out an int, in case an older monitor with an older json schema is
5864 // forwarding a request.
5866 string interr
, floaterr
;
5869 int64_t uf
= 0; // micro-f
5870 if (!cmd_getval(g_ceph_context
, cmdmap
, "val", val
)) {
5871 // wasn't a string; maybe an older mon forwarded json with an int?
5872 if (!cmd_getval(g_ceph_context
, cmdmap
, "val", n
))
5873 return -EINVAL
; // no value!
5875 // we got a string. see if it contains an int.
5876 n
= strict_strtoll(val
.c_str(), 10, &interr
);
5878 f
= strict_strtod(val
.c_str(), &floaterr
);
5879 uf
= llrintl(f
* (double)1000000.0);
5883 (var
== "hit_set_type" || var
== "hit_set_period" ||
5884 var
== "hit_set_count" || var
== "hit_set_fpp" ||
5885 var
== "target_max_objects" || var
== "target_max_bytes" ||
5886 var
== "cache_target_full_ratio" || var
== "cache_target_dirty_ratio" ||
5887 var
== "cache_target_dirty_high_ratio" || var
== "use_gmt_hitset" ||
5888 var
== "cache_min_flush_age" || var
== "cache_min_evict_age" ||
5889 var
== "hit_set_grade_decay_rate" || var
== "hit_set_search_last_n" ||
5890 var
== "min_read_recency_for_promote" || var
== "min_write_recency_for_promote")) {
5894 if (var
== "size") {
5895 if (p
.has_flag(pg_pool_t::FLAG_NOSIZECHANGE
)) {
5896 ss
<< "pool size change is disabled; you must unset nosizechange flag for the pool first";
5899 if (p
.type
== pg_pool_t::TYPE_ERASURE
) {
5900 ss
<< "can not change the size of an erasure-coded pool";
5903 if (interr
.length()) {
5904 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
5907 if (n
<= 0 || n
> 10) {
5908 ss
<< "pool size must be between 1 and 10";
5914 } else if (var
== "min_size") {
5915 if (p
.has_flag(pg_pool_t::FLAG_NOSIZECHANGE
)) {
5916 ss
<< "pool min size change is disabled; you must unset nosizechange flag for the pool first";
5919 if (interr
.length()) {
5920 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
5924 if (p
.type
!= pg_pool_t::TYPE_ERASURE
) {
5925 if (n
< 1 || n
> p
.size
) {
5926 ss
<< "pool min_size must be between 1 and " << (int)p
.size
;
5930 ErasureCodeInterfaceRef erasure_code
;
5933 int err
= get_erasure_code(p
.erasure_code_profile
, &erasure_code
, &tmp
);
5935 k
= erasure_code
->get_data_chunk_count();
5937 ss
<< __func__
<< " get_erasure_code failed: " << tmp
.rdbuf();
5941 if (n
< k
|| n
> p
.size
) {
5942 ss
<< "pool min_size must be between " << k
<< " and " << (int)p
.size
;
5947 } else if (var
== "auid") {
5948 if (interr
.length()) {
5949 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
5953 } else if (var
== "crash_replay_interval") {
5954 if (interr
.length()) {
5955 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
5958 p
.crash_replay_interval
= n
;
5959 } else if (var
== "pg_num") {
5960 if (p
.has_flag(pg_pool_t::FLAG_NOPGCHANGE
)) {
5961 ss
<< "pool pg_num change is disabled; you must unset nopgchange flag for the pool first";
5964 if (interr
.length()) {
5965 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
5968 if (n
<= (int)p
.get_pg_num()) {
5969 ss
<< "specified pg_num " << n
<< " <= current " << p
.get_pg_num();
5970 if (n
< (int)p
.get_pg_num())
5974 if (n
> (unsigned)g_conf
->mon_max_pool_pg_num
) {
5975 ss
<< "'pg_num' must be greater than 0 and less than or equal to "
5976 << g_conf
->mon_max_pool_pg_num
5977 << " (you may adjust 'mon max pool pg num' for higher values)";
5981 cmd_getval(g_ceph_context
,cmdmap
, "force", force
);
5982 if (p
.cache_mode
!= pg_pool_t::CACHEMODE_NONE
&&
5983 force
!= "--yes-i-really-mean-it") {
5984 ss
<< "splits in cache pools must be followed by scrubs and leave sufficient free space to avoid overfilling. use --yes-i-really-mean-it to force.";
5987 int expected_osds
= MIN(p
.get_pg_num(), osdmap
.get_num_osds());
5988 int64_t new_pgs
= n
- p
.get_pg_num();
5989 if (new_pgs
> g_conf
->mon_osd_max_split_count
* expected_osds
) {
5990 ss
<< "specified pg_num " << n
<< " is too large (creating "
5991 << new_pgs
<< " new PGs on ~" << expected_osds
5992 << " OSDs exceeds per-OSD max of " << g_conf
->mon_osd_max_split_count
5997 // force pre-luminous clients to resend their ops, since they
5998 // don't understand that split PGs now form a new interval.
5999 p
.last_force_op_resend_preluminous
= pending_inc
.epoch
;
6000 } else if (var
== "pgp_num") {
6001 if (p
.has_flag(pg_pool_t::FLAG_NOPGCHANGE
)) {
6002 ss
<< "pool pgp_num change is disabled; you must unset nopgchange flag for the pool first";
6005 if (interr
.length()) {
6006 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
6010 ss
<< "specified pgp_num must > 0, but you set to " << n
;
6013 if (n
> (int)p
.get_pg_num()) {
6014 ss
<< "specified pgp_num " << n
<< " > pg_num " << p
.get_pg_num();
6018 } else if (var
== "crush_rule") {
6019 int id
= osdmap
.crush
->get_rule_id(val
);
6020 if (id
== -ENOENT
) {
6021 ss
<< "crush rule " << val
<< " does not exist";
6025 ss
<< cpp_strerror(id
);
6028 if (!osdmap
.crush
->check_crush_rule(id
, p
.get_type(), p
.get_size(), ss
)) {
6032 } else if (var
== "nodelete" || var
== "nopgchange" ||
6033 var
== "nosizechange" || var
== "write_fadvise_dontneed" ||
6034 var
== "noscrub" || var
== "nodeep-scrub") {
6035 uint64_t flag
= pg_pool_t::get_flag_by_name(var
);
6036 // make sure we only compare against 'n' if we didn't receive a string
6037 if (val
== "true" || (interr
.empty() && n
== 1)) {
6039 } else if (val
== "false" || (interr
.empty() && n
== 0)) {
6042 ss
<< "expecting value 'true', 'false', '0', or '1'";
6045 } else if (var
== "hashpspool") {
6046 uint64_t flag
= pg_pool_t::get_flag_by_name(var
);
6048 cmd_getval(g_ceph_context
, cmdmap
, "force", force
);
6049 if (force
!= "--yes-i-really-mean-it") {
6050 ss
<< "are you SURE? this will remap all placement groups in this pool,"
6051 " this triggers large data movement,"
6052 " pass --yes-i-really-mean-it if you really do.";
6055 // make sure we only compare against 'n' if we didn't receive a string
6056 if (val
== "true" || (interr
.empty() && n
== 1)) {
6058 } else if (val
== "false" || (interr
.empty() && n
== 0)) {
6061 ss
<< "expecting value 'true', 'false', '0', or '1'";
6064 } else if (var
== "hit_set_type") {
6066 p
.hit_set_params
= HitSet::Params();
6068 int err
= check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL
, ss
);
6071 if (val
== "bloom") {
6072 BloomHitSet::Params
*bsp
= new BloomHitSet::Params
;
6073 bsp
->set_fpp(g_conf
->osd_pool_default_hit_set_bloom_fpp
);
6074 p
.hit_set_params
= HitSet::Params(bsp
);
6075 } else if (val
== "explicit_hash")
6076 p
.hit_set_params
= HitSet::Params(new ExplicitHashHitSet::Params
);
6077 else if (val
== "explicit_object")
6078 p
.hit_set_params
= HitSet::Params(new ExplicitObjectHitSet::Params
);
6080 ss
<< "unrecognized hit_set type '" << val
<< "'";
6084 } else if (var
== "hit_set_period") {
6085 if (interr
.length()) {
6086 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
6089 p
.hit_set_period
= n
;
6090 } else if (var
== "hit_set_count") {
6091 if (interr
.length()) {
6092 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
6095 p
.hit_set_count
= n
;
6096 } else if (var
== "hit_set_fpp") {
6097 if (floaterr
.length()) {
6098 ss
<< "error parsing floating point value '" << val
<< "': " << floaterr
;
6101 if (p
.hit_set_params
.get_type() != HitSet::TYPE_BLOOM
) {
6102 ss
<< "hit set is not of type Bloom; invalid to set a false positive rate!";
6105 BloomHitSet::Params
*bloomp
= static_cast<BloomHitSet::Params
*>(p
.hit_set_params
.impl
.get());
6107 } else if (var
== "use_gmt_hitset") {
6108 if (val
== "true" || (interr
.empty() && n
== 1)) {
6109 if (!(osdmap
.get_up_osd_features() & CEPH_FEATURE_OSD_HITSET_GMT
)) {
6110 ss
<< "not all OSDs support GMT hit set.";
6113 p
.use_gmt_hitset
= true;
6115 ss
<< "expecting value 'true' or '1'";
6118 } else if (var
== "allow_ec_overwrites") {
6119 if (!p
.is_erasure()) {
6120 ss
<< "ec overwrites can only be enabled for an erasure coded pool";
6124 if (!g_conf
->mon_debug_no_require_bluestore_for_ec_overwrites
&&
6125 !is_pool_currently_all_bluestore(pool
, p
, &err
)) {
6126 ss
<< "pool must only be stored on bluestore for scrubbing to work: " << err
.str();
6129 if (val
== "true" || (interr
.empty() && n
== 1)) {
6130 p
.flags
|= pg_pool_t::FLAG_EC_OVERWRITES
;
6131 } else if (val
== "false" || (interr
.empty() && n
== 0)) {
6132 ss
<< "ec overwrites cannot be disabled once enabled";
6135 ss
<< "expecting value 'true', 'false', '0', or '1'";
6138 } else if (var
== "target_max_objects") {
6139 if (interr
.length()) {
6140 ss
<< "error parsing int '" << val
<< "': " << interr
;
6143 p
.target_max_objects
= n
;
6144 } else if (var
== "target_max_bytes") {
6145 if (interr
.length()) {
6146 ss
<< "error parsing int '" << val
<< "': " << interr
;
6149 p
.target_max_bytes
= n
;
6150 } else if (var
== "cache_target_dirty_ratio") {
6151 if (floaterr
.length()) {
6152 ss
<< "error parsing float '" << val
<< "': " << floaterr
;
6155 if (f
< 0 || f
> 1.0) {
6156 ss
<< "value must be in the range 0..1";
6159 p
.cache_target_dirty_ratio_micro
= uf
;
6160 } else if (var
== "cache_target_dirty_high_ratio") {
6161 if (floaterr
.length()) {
6162 ss
<< "error parsing float '" << val
<< "': " << floaterr
;
6165 if (f
< 0 || f
> 1.0) {
6166 ss
<< "value must be in the range 0..1";
6169 p
.cache_target_dirty_high_ratio_micro
= uf
;
6170 } else if (var
== "cache_target_full_ratio") {
6171 if (floaterr
.length()) {
6172 ss
<< "error parsing float '" << val
<< "': " << floaterr
;
6175 if (f
< 0 || f
> 1.0) {
6176 ss
<< "value must be in the range 0..1";
6179 p
.cache_target_full_ratio_micro
= uf
;
6180 } else if (var
== "cache_min_flush_age") {
6181 if (interr
.length()) {
6182 ss
<< "error parsing int '" << val
<< "': " << interr
;
6185 p
.cache_min_flush_age
= n
;
6186 } else if (var
== "cache_min_evict_age") {
6187 if (interr
.length()) {
6188 ss
<< "error parsing int '" << val
<< "': " << interr
;
6191 p
.cache_min_evict_age
= n
;
6192 } else if (var
== "min_read_recency_for_promote") {
6193 if (interr
.length()) {
6194 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
6197 p
.min_read_recency_for_promote
= n
;
6198 } else if (var
== "hit_set_grade_decay_rate") {
6199 if (interr
.length()) {
6200 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
6203 if (n
> 100 || n
< 0) {
6204 ss
<< "value out of range,valid range is 0 - 100";
6207 p
.hit_set_grade_decay_rate
= n
;
6208 } else if (var
== "hit_set_search_last_n") {
6209 if (interr
.length()) {
6210 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
6213 if (n
> p
.hit_set_count
|| n
< 0) {
6214 ss
<< "value out of range,valid range is 0 - hit_set_count";
6217 p
.hit_set_search_last_n
= n
;
6218 } else if (var
== "min_write_recency_for_promote") {
6219 if (interr
.length()) {
6220 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
6223 p
.min_write_recency_for_promote
= n
;
6224 } else if (var
== "fast_read") {
6225 if (p
.is_replicated()) {
6226 ss
<< "fast read is not supported in replication pool";
6229 if (val
== "true" || (interr
.empty() && n
== 1)) {
6231 } else if (val
== "false" || (interr
.empty() && n
== 0)) {
6232 p
.fast_read
= false;
6234 ss
<< "expecting value 'true', 'false', '0', or '1'";
6237 } else if (pool_opts_t::is_opt_name(var
)) {
6238 bool unset
= val
== "unset";
6239 if (var
== "compression_mode") {
6241 auto cmode
= Compressor::get_comp_mode_type(val
);
6243 ss
<< "unrecognized compression mode '" << val
<< "'";
6247 } else if (var
== "compression_algorithm") {
6249 auto alg
= Compressor::get_comp_alg_type(val
);
6251 ss
<< "unrecognized compression_algorithm '" << val
<< "'";
6255 } else if (var
== "compression_required_ratio") {
6256 if (floaterr
.length()) {
6257 ss
<< "error parsing float value '" << val
<< "': " << floaterr
;
6260 if (f
< 0 || f
> 1) {
6261 ss
<< "compression_required_ratio is out of range (0-1): '" << val
<< "'";
6264 } else if (var
== "csum_type") {
6265 auto t
= unset
? 0 : Checksummer::get_csum_string_type(val
);
6267 ss
<< "unrecognized csum_type '" << val
<< "'";
6270 //preserve csum_type numeric value
6273 } else if (var
== "compression_max_blob_size" ||
6274 var
== "compression_min_blob_size" ||
6275 var
== "csum_max_block" ||
6276 var
== "csum_min_block") {
6277 if (interr
.length()) {
6278 ss
<< "error parsing int value '" << val
<< "': " << interr
;
6283 pool_opts_t::opt_desc_t desc
= pool_opts_t::get_opt_desc(var
);
6284 switch (desc
.type
) {
6285 case pool_opts_t::STR
:
6287 p
.opts
.unset(desc
.key
);
6289 p
.opts
.set(desc
.key
, static_cast<std::string
>(val
));
6292 case pool_opts_t::INT
:
6293 if (interr
.length()) {
6294 ss
<< "error parsing integer value '" << val
<< "': " << interr
;
6298 p
.opts
.unset(desc
.key
);
6300 p
.opts
.set(desc
.key
, static_cast<int>(n
));
6303 case pool_opts_t::DOUBLE
:
6304 if (floaterr
.length()) {
6305 ss
<< "error parsing floating point value '" << val
<< "': " << floaterr
;
6309 p
.opts
.unset(desc
.key
);
6311 p
.opts
.set(desc
.key
, static_cast<double>(f
));
6315 assert(!"unknown type");
6318 ss
<< "unrecognized variable '" << var
<< "'";
6321 if (val
!= "unset") {
6322 ss
<< "set pool " << pool
<< " " << var
<< " to " << val
;
6324 ss
<< "unset pool " << pool
<< " " << var
;
6326 p
.last_change
= pending_inc
.epoch
;
6327 pending_inc
.new_pools
[pool
] = p
;
6331 int OSDMonitor::prepare_command_pool_application(const string
&prefix
,
6332 map
<string
,cmd_vartype
> &cmdmap
,
6336 cmd_getval(g_ceph_context
, cmdmap
, "pool", pool_name
);
6337 int64_t pool
= osdmap
.lookup_pg_pool_name(pool_name
.c_str());
6339 ss
<< "unrecognized pool '" << pool_name
<< "'";
6343 pg_pool_t p
= *osdmap
.get_pg_pool(pool
);
6344 if (pending_inc
.new_pools
.count(pool
)) {
6345 p
= pending_inc
.new_pools
[pool
];
6349 cmd_getval(g_ceph_context
, cmdmap
, "app", app
);
6350 bool app_exists
= (p
.application_metadata
.count(app
) > 0);
6352 if (boost::algorithm::ends_with(prefix
, "enable")) {
6354 ss
<< "application name must be provided";
6359 ss
<< "application must be enabled on base tier";
6364 cmd_getval(g_ceph_context
, cmdmap
, "force", force
);
6366 if (!app_exists
&& !p
.application_metadata
.empty() &&
6367 force
!= "--yes-i-really-mean-it") {
6368 ss
<< "Are you SURE? Pool '" << pool_name
<< "' already has an enabled "
6369 << "application; pass --yes-i-really-mean-it to proceed anyway";
6373 if (!app_exists
&& p
.application_metadata
.size() >= MAX_POOL_APPLICATIONS
) {
6374 ss
<< "too many enabled applications on pool '" << pool_name
<< "'; "
6375 << "max " << MAX_POOL_APPLICATIONS
;
6379 if (app
.length() > MAX_POOL_APPLICATION_LENGTH
) {
6380 ss
<< "application name '" << app
<< "' too long; max length "
6381 << MAX_POOL_APPLICATION_LENGTH
;
6386 p
.application_metadata
[app
] = {};
6388 ss
<< "enabled application '" << app
<< "' on pool '" << pool_name
<< "'";
6390 } else if (boost::algorithm::ends_with(prefix
, "disable")) {
6392 cmd_getval(g_ceph_context
, cmdmap
, "force", force
);
6394 if (force
!= "--yes-i-really-mean-it") {
6395 ss
<< "Are you SURE? Disabling an application within a pool might result "
6396 << "in loss of application functionality; pass "
6397 << "--yes-i-really-mean-it to proceed anyway";
6402 ss
<< "application '" << app
<< "' is not enabled on pool '" << pool_name
6404 return 0; // idempotent
6407 p
.application_metadata
.erase(app
);
6408 ss
<< "disable application '" << app
<< "' on pool '" << pool_name
<< "'";
6410 } else if (boost::algorithm::ends_with(prefix
, "set")) {
6412 ss
<< "application metadata must be set on base tier";
6417 ss
<< "application '" << app
<< "' is not enabled on pool '" << pool_name
6423 cmd_getval(g_ceph_context
, cmdmap
, "key", key
);
6426 ss
<< "key must be provided";
6430 auto &app_keys
= p
.application_metadata
[app
];
6431 if (app_keys
.count(key
) == 0 &&
6432 app_keys
.size() >= MAX_POOL_APPLICATION_KEYS
) {
6433 ss
<< "too many keys set for application '" << app
<< "' on pool '"
6434 << pool_name
<< "'; max " << MAX_POOL_APPLICATION_KEYS
;
6438 if (key
.length() > MAX_POOL_APPLICATION_LENGTH
) {
6439 ss
<< "key '" << app
<< "' too long; max length "
6440 << MAX_POOL_APPLICATION_LENGTH
;
6445 cmd_getval(g_ceph_context
, cmdmap
, "value", value
);
6446 if (value
.length() > MAX_POOL_APPLICATION_LENGTH
) {
6447 ss
<< "value '" << value
<< "' too long; max length "
6448 << MAX_POOL_APPLICATION_LENGTH
;
6452 p
.application_metadata
[app
][key
] = value
;
6453 ss
<< "set application '" << app
<< "' key '" << key
<< "' to '"
6454 << value
<< "' on pool '" << pool_name
<< "'";
6455 } else if (boost::algorithm::ends_with(prefix
, "rm")) {
6457 ss
<< "application '" << app
<< "' is not enabled on pool '" << pool_name
6463 cmd_getval(g_ceph_context
, cmdmap
, "key", key
);
6464 auto it
= p
.application_metadata
[app
].find(key
);
6465 if (it
== p
.application_metadata
[app
].end()) {
6466 ss
<< "application '" << app
<< "' on pool '" << pool_name
6467 << "' does not have key '" << key
<< "'";
6468 return 0; // idempotent
6471 p
.application_metadata
[app
].erase(it
);
6472 ss
<< "removed application '" << app
<< "' key '" << key
<< "' on pool '"
6473 << pool_name
<< "'";
6478 p
.last_change
= pending_inc
.epoch
;
6479 pending_inc
.new_pools
[pool
] = p
;
6483 int OSDMonitor::_prepare_command_osd_crush_remove(
6484 CrushWrapper
&newcrush
,
6493 err
= newcrush
.remove_item_under(g_ceph_context
, id
, ancestor
,
6496 err
= newcrush
.remove_item(g_ceph_context
, id
, unlink_only
);
6501 void OSDMonitor::do_osd_crush_remove(CrushWrapper
& newcrush
)
6503 pending_inc
.crush
.clear();
6504 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
6507 int OSDMonitor::prepare_command_osd_crush_remove(
6508 CrushWrapper
&newcrush
,
6514 int err
= _prepare_command_osd_crush_remove(
6515 newcrush
, id
, ancestor
,
6516 has_ancestor
, unlink_only
);
6522 do_osd_crush_remove(newcrush
);
6527 int OSDMonitor::prepare_command_osd_remove(int32_t id
)
6529 if (osdmap
.is_up(id
)) {
6533 pending_inc
.new_state
[id
] = osdmap
.get_state(id
);
6534 pending_inc
.new_uuid
[id
] = uuid_d();
6535 pending_metadata_rm
.insert(id
);
6536 pending_metadata
.erase(id
);
6541 int32_t OSDMonitor::_allocate_osd_id(int32_t* existing_id
)
6543 assert(existing_id
);
6546 for (int32_t i
= 0; i
< osdmap
.get_max_osd(); ++i
) {
6547 if (!osdmap
.exists(i
) &&
6548 pending_inc
.new_up_client
.count(i
) == 0 &&
6549 (pending_inc
.new_state
.count(i
) == 0 ||
6550 (pending_inc
.new_state
[i
] & CEPH_OSD_EXISTS
) == 0)) {
6556 if (pending_inc
.new_max_osd
< 0) {
6557 return osdmap
.get_max_osd();
6559 return pending_inc
.new_max_osd
;
6562 void OSDMonitor::do_osd_create(
6567 dout(10) << __func__
<< " uuid " << uuid
<< dendl
;
6570 // We presume validation has been performed prior to calling this
6571 // function. We assert with prejudice.
6573 int32_t allocated_id
= -1; // declare here so we can jump
6574 int32_t existing_id
= -1;
6575 if (!uuid
.is_zero()) {
6576 existing_id
= osdmap
.identify_osd(uuid
);
6577 if (existing_id
>= 0) {
6578 assert(id
< 0 || id
== existing_id
);
6579 *new_id
= existing_id
;
6581 } else if (id
>= 0) {
6582 // uuid does not exist, and id has been provided, so just create
6589 // allocate a new id
6590 allocated_id
= _allocate_osd_id(&existing_id
);
6591 dout(10) << __func__
<< " allocated id " << allocated_id
6592 << " existing id " << existing_id
<< dendl
;
6593 if (existing_id
>= 0) {
6594 assert(existing_id
< osdmap
.get_max_osd());
6595 assert(allocated_id
< 0);
6596 pending_inc
.new_weight
[existing_id
] = CEPH_OSD_OUT
;
6597 *new_id
= existing_id
;
6599 } else if (allocated_id
>= 0) {
6600 assert(existing_id
< 0);
6602 if (pending_inc
.new_max_osd
< 0) {
6603 pending_inc
.new_max_osd
= osdmap
.get_max_osd() + 1;
6605 ++pending_inc
.new_max_osd
;
6607 *new_id
= pending_inc
.new_max_osd
- 1;
6608 assert(*new_id
== allocated_id
);
6610 assert(0 == "unexpected condition");
6614 dout(10) << __func__
<< " using id " << *new_id
<< dendl
;
6615 if (osdmap
.get_max_osd() <= *new_id
&& pending_inc
.new_max_osd
<= *new_id
) {
6616 pending_inc
.new_max_osd
= *new_id
+ 1;
6619 pending_inc
.new_state
[*new_id
] |= CEPH_OSD_EXISTS
| CEPH_OSD_NEW
;
6620 if (!uuid
.is_zero())
6621 pending_inc
.new_uuid
[*new_id
] = uuid
;
6624 int OSDMonitor::validate_osd_create(
6627 const bool check_osd_exists
,
6628 int32_t* existing_id
,
6632 dout(10) << __func__
<< " id " << id
<< " uuid " << uuid
6633 << " check_osd_exists " << check_osd_exists
<< dendl
;
6635 assert(existing_id
);
6637 if (id
< 0 && uuid
.is_zero()) {
6638 // we have nothing to validate
6641 } else if (uuid
.is_zero()) {
6642 // we have an id but we will ignore it - because that's what
6643 // `osd create` does.
6648 * This function will be used to validate whether we are able to
6649 * create a new osd when the `uuid` is specified.
6651 * It will be used by both `osd create` and `osd new`, as the checks
6652 * are basically the same when it pertains to osd id and uuid validation.
6653 * However, `osd create` presumes an `uuid` is optional, for legacy
6654 * reasons, while `osd new` requires the `uuid` to be provided. This
6655 * means that `osd create` will not be idempotent if an `uuid` is not
6656 * provided, but we will always guarantee the idempotency of `osd new`.
6659 assert(!uuid
.is_zero());
6660 if (pending_inc
.identify_osd(uuid
) >= 0) {
6661 // osd is about to exist
6665 int32_t i
= osdmap
.identify_osd(uuid
);
6667 // osd already exists
6668 if (id
>= 0 && i
!= id
) {
6669 ss
<< "uuid " << uuid
<< " already in use for different id " << i
;
6672 // return a positive errno to distinguish between a blocking error
6673 // and an error we consider to not be a problem (i.e., this would be
6674 // an idempotent operation).
6680 if (pending_inc
.new_state
.count(id
)) {
6681 // osd is about to exist
6684 // we may not care if an osd exists if we are recreating a previously
6686 if (check_osd_exists
&& osdmap
.exists(id
)) {
6687 ss
<< "id " << id
<< " already in use and does not match uuid "
6695 int OSDMonitor::prepare_command_osd_create(
6698 int32_t* existing_id
,
6701 dout(10) << __func__
<< " id " << id
<< " uuid " << uuid
<< dendl
;
6702 assert(existing_id
);
6704 if (uuid
.is_zero()) {
6705 dout(10) << __func__
<< " no uuid; assuming legacy `osd create`" << dendl
;
6708 return validate_osd_create(id
, uuid
, true, existing_id
, ss
);
6711 int OSDMonitor::prepare_command_osd_new(
6713 const map
<string
,cmd_vartype
>& cmdmap
,
6714 const map
<string
,string
>& secrets
,
6722 assert(paxos
->is_plugged());
6724 dout(10) << __func__
<< " " << op
<< dendl
;
6726 /* validate command. abort now if something's wrong. */
6728 /* `osd new` will expect a `uuid` to be supplied; `id` is optional.
6730 * If `id` is not specified, we will identify any existing osd based
6731 * on `uuid`. Operation will be idempotent iff secrets match.
6733 * If `id` is specified, we will identify any existing osd based on
6734 * `uuid` and match against `id`. If they match, operation will be
6735 * idempotent iff secrets match.
6737 * `-i secrets.json` will be optional. If supplied, will be used
6738 * to check for idempotency when `id` and `uuid` match.
6740 * If `id` is not specified, and `uuid` does not exist, an id will
6741 * be found or allocated for the osd.
6743 * If `id` is specified, and the osd has been previously marked
6744 * as destroyed, then the `id` will be reused.
6746 if (!cmd_getval(g_ceph_context
, cmdmap
, "uuid", uuidstr
)) {
6747 ss
<< "requires the OSD's UUID to be specified.";
6749 } else if (!uuid
.parse(uuidstr
.c_str())) {
6750 ss
<< "invalid UUID value '" << uuidstr
<< "'.";
6754 if (cmd_getval(g_ceph_context
, cmdmap
, "id", id
) &&
6756 ss
<< "invalid OSD id; must be greater or equal than zero.";
6760 // are we running an `osd create`-like command, or recreating
6761 // a previously destroyed osd?
6763 bool is_recreate_destroyed
= (id
>= 0 && osdmap
.is_destroyed(id
));
6765 // we will care about `id` to assess whether osd is `destroyed`, or
6766 // to create a new osd.
6767 // we will need an `id` by the time we reach auth.
6769 int32_t existing_id
= -1;
6770 int err
= validate_osd_create(id
, uuid
, !is_recreate_destroyed
,
6773 bool may_be_idempotent
= false;
6774 if (err
== EEXIST
) {
6775 // this is idempotent from the osdmon's point-of-view
6776 may_be_idempotent
= true;
6777 assert(existing_id
>= 0);
6779 } else if (err
< 0) {
6783 if (!may_be_idempotent
) {
6784 // idempotency is out of the window. We are either creating a new
6785 // osd or recreating a destroyed osd.
6787 // We now need to figure out if we have an `id` (and if it's valid),
6788 // of find an `id` if we don't have one.
6790 // NOTE: we need to consider the case where the `id` is specified for
6791 // `osd create`, and we must honor it. So this means checking if
6792 // the `id` is destroyed, and if so assume the destroy; otherwise,
6793 // check if it `exists` - in which case we complain about not being
6794 // `destroyed`. In the end, if nothing fails, we must allow the
6795 // creation, so that we are compatible with `create`.
6796 if (id
>= 0 && osdmap
.exists(id
) && !osdmap
.is_destroyed(id
)) {
6797 dout(10) << __func__
<< " osd." << id
<< " isn't destroyed" << dendl
;
6798 ss
<< "OSD " << id
<< " has not yet been destroyed";
6800 } else if (id
< 0) {
6802 id
= _allocate_osd_id(&existing_id
);
6804 assert(existing_id
>= 0);
6807 dout(10) << __func__
<< " found id " << id
<< " to use" << dendl
;
6808 } else if (id
>= 0 && osdmap
.is_destroyed(id
)) {
6809 dout(10) << __func__
<< " recreating osd." << id
<< dendl
;
6811 dout(10) << __func__
<< " creating new osd." << id
<< dendl
;
6815 assert(osdmap
.exists(id
));
6818 // we are now able to either create a brand new osd or reuse an existing
6819 // osd that has been previously destroyed.
6821 dout(10) << __func__
<< " id " << id
<< " uuid " << uuid
<< dendl
;
6823 if (may_be_idempotent
&& secrets
.empty()) {
6824 // nothing to do, really.
6825 dout(10) << __func__
<< " idempotent and no secrets -- no op." << dendl
;
6828 f
->open_object_section("created_osd");
6829 f
->dump_int("osdid", id
);
6837 string cephx_secret
, lockbox_secret
, dmcrypt_key
;
6838 bool has_lockbox
= false;
6839 bool has_secrets
= (!secrets
.empty());
6841 ConfigKeyService
*svc
= nullptr;
6842 AuthMonitor::auth_entity_t cephx_entity
, lockbox_entity
;
6845 if (secrets
.count("cephx_secret") == 0) {
6846 ss
<< "requires a cephx secret.";
6849 cephx_secret
= secrets
.at("cephx_secret");
6851 bool has_lockbox_secret
= (secrets
.count("cephx_lockbox_secret") > 0);
6852 bool has_dmcrypt_key
= (secrets
.count("dmcrypt_key") > 0);
6854 dout(10) << __func__
<< " has lockbox " << has_lockbox_secret
6855 << " dmcrypt " << has_dmcrypt_key
<< dendl
;
6857 if (has_lockbox_secret
&& has_dmcrypt_key
) {
6859 lockbox_secret
= secrets
.at("cephx_lockbox_secret");
6860 dmcrypt_key
= secrets
.at("dmcrypt_key");
6861 } else if (!has_lockbox_secret
!= !has_dmcrypt_key
) {
6862 ss
<< "requires both a cephx lockbox secret and a dm-crypt key.";
6866 dout(10) << __func__
<< " validate secrets using osd id " << id
<< dendl
;
6868 err
= mon
->authmon()->validate_osd_new(id
, uuid
,
6876 } else if (may_be_idempotent
&& err
!= EEXIST
) {
6877 // for this to be idempotent, `id` should already be >= 0; no need
6878 // to use validate_id.
6880 ss
<< "osd." << id
<< " exists but secrets do not match";
6885 svc
= (ConfigKeyService
*)mon
->config_key_service
;
6886 err
= svc
->validate_osd_new(uuid
, dmcrypt_key
, ss
);
6889 } else if (may_be_idempotent
&& err
!= EEXIST
) {
6891 ss
<< "osd." << id
<< " exists but dm-crypt key does not match.";
6896 assert(!has_secrets
|| !cephx_secret
.empty());
6897 assert(!has_lockbox
|| !lockbox_secret
.empty());
6899 if (may_be_idempotent
) {
6900 // we have nothing to do for either the osdmon or the authmon,
6901 // and we have no lockbox - so the config key service will not be
6902 // touched. This is therefore an idempotent operation, and we can
6903 // just return right away.
6904 dout(10) << __func__
<< " idempotent -- no op." << dendl
;
6907 f
->open_object_section("created_osd");
6908 f
->dump_int("osdid", id
);
6915 assert(!may_be_idempotent
);
6919 assert(!cephx_secret
.empty());
6920 assert((lockbox_secret
.empty() && dmcrypt_key
.empty()) ||
6921 (!lockbox_secret
.empty() && !dmcrypt_key
.empty()));
6923 err
= mon
->authmon()->do_osd_new(cephx_entity
,
6929 assert(nullptr != svc
);
6930 svc
->do_osd_new(uuid
, dmcrypt_key
);
6934 if (is_recreate_destroyed
) {
6936 assert(osdmap
.is_destroyed(id
));
6937 pending_inc
.new_weight
[id
] = CEPH_OSD_OUT
;
6938 pending_inc
.new_state
[id
] |= CEPH_OSD_DESTROYED
| CEPH_OSD_NEW
;
6939 if (osdmap
.get_state(id
) & CEPH_OSD_UP
) {
6940 // due to http://tracker.ceph.com/issues/20751 some clusters may
6941 // have UP set for non-existent OSDs; make sure it is cleared
6942 // for a newly created osd.
6943 pending_inc
.new_state
[id
] |= CEPH_OSD_UP
;
6945 pending_inc
.new_uuid
[id
] = uuid
;
6948 int32_t new_id
= -1;
6949 do_osd_create(id
, uuid
, &new_id
);
6950 assert(new_id
>= 0);
6951 assert(id
== new_id
);
6955 f
->open_object_section("created_osd");
6956 f
->dump_int("osdid", id
);
6965 bool OSDMonitor::prepare_command(MonOpRequestRef op
)
6967 op
->mark_osdmon_event(__func__
);
6968 MMonCommand
*m
= static_cast<MMonCommand
*>(op
->get_req());
6970 map
<string
, cmd_vartype
> cmdmap
;
6971 if (!cmdmap_from_json(m
->cmd
, &cmdmap
, ss
)) {
6972 string rs
= ss
.str();
6973 mon
->reply_command(op
, -EINVAL
, rs
, get_last_committed());
6977 MonSession
*session
= m
->get_session();
6979 mon
->reply_command(op
, -EACCES
, "access denied", get_last_committed());
6983 return prepare_command_impl(op
, cmdmap
);
6986 static int parse_reweights(CephContext
*cct
,
6987 const map
<string
,cmd_vartype
> &cmdmap
,
6988 const OSDMap
& osdmap
,
6989 map
<int32_t, uint32_t>* weights
)
6992 if (!cmd_getval(g_ceph_context
, cmdmap
, "weights", weights_str
)) {
6995 std::replace(begin(weights_str
), end(weights_str
), '\'', '"');
6996 json_spirit::mValue json_value
;
6997 if (!json_spirit::read(weights_str
, json_value
)) {
7000 if (json_value
.type() != json_spirit::obj_type
) {
7003 const auto obj
= json_value
.get_obj();
7005 for (auto& osd_weight
: obj
) {
7006 auto osd_id
= std::stoi(osd_weight
.first
);
7007 if (!osdmap
.exists(osd_id
)) {
7010 if (osd_weight
.second
.type() != json_spirit::str_type
) {
7013 auto weight
= std::stoul(osd_weight
.second
.get_str());
7014 weights
->insert({osd_id
, weight
});
7016 } catch (const std::logic_error
& e
) {
7022 int OSDMonitor::prepare_command_osd_destroy(
7026 assert(paxos
->is_plugged());
7028 // we check if the osd exists for the benefit of `osd purge`, which may
7029 // have previously removed the osd. If the osd does not exist, return
7030 // -ENOENT to convey this, and let the caller deal with it.
7032 // we presume that all auth secrets and config keys were removed prior
7033 // to this command being called. if they exist by now, we also assume
7034 // they must have been created by some other command and do not pertain
7035 // to this non-existent osd.
7036 if (!osdmap
.exists(id
)) {
7037 dout(10) << __func__
<< " osd." << id
<< " does not exist." << dendl
;
7041 uuid_d uuid
= osdmap
.get_uuid(id
);
7042 dout(10) << __func__
<< " destroying osd." << id
7043 << " uuid " << uuid
<< dendl
;
7045 // if it has been destroyed, we assume our work here is done.
7046 if (osdmap
.is_destroyed(id
)) {
7047 ss
<< "destroyed osd." << id
;
7051 EntityName cephx_entity
, lockbox_entity
;
7052 bool idempotent_auth
= false, idempotent_cks
= false;
7054 int err
= mon
->authmon()->validate_osd_destroy(id
, uuid
,
7059 if (err
== -ENOENT
) {
7060 idempotent_auth
= true;
7066 ConfigKeyService
*svc
= (ConfigKeyService
*)mon
->config_key_service
;
7067 err
= svc
->validate_osd_destroy(id
, uuid
);
7069 assert(err
== -ENOENT
);
7071 idempotent_cks
= true;
7074 if (!idempotent_auth
) {
7075 err
= mon
->authmon()->do_osd_destroy(cephx_entity
, lockbox_entity
);
7079 if (!idempotent_cks
) {
7080 svc
->do_osd_destroy(id
, uuid
);
7083 pending_inc
.new_state
[id
] = CEPH_OSD_DESTROYED
;
7084 pending_inc
.new_uuid
[id
] = uuid_d();
7086 // we can only propose_pending() once per service, otherwise we'll be
7087 // defying PaxosService and all laws of nature. Therefore, as we may
7088 // be used during 'osd purge', let's keep the caller responsible for
7094 int OSDMonitor::prepare_command_osd_purge(
7098 assert(paxos
->is_plugged());
7099 dout(10) << __func__
<< " purging osd." << id
<< dendl
;
7101 assert(!osdmap
.is_up(id
));
7104 * This may look a bit weird, but this is what's going to happen:
7106 * 1. we make sure that removing from crush works
7107 * 2. we call `prepare_command_osd_destroy()`. If it returns an
7108 * error, then we abort the whole operation, as no updates
7109 * have been made. However, we this function will have
7110 * side-effects, thus we need to make sure that all operations
7111 * performed henceforth will *always* succeed.
7112 * 3. we call `prepare_command_osd_remove()`. Although this
7113 * function can return an error, it currently only checks if the
7114 * osd is up - and we have made sure that it is not so, so there
7115 * is no conflict, and it is effectively an update.
7116 * 4. finally, we call `do_osd_crush_remove()`, which will perform
7117 * the crush update we delayed from before.
7120 CrushWrapper newcrush
;
7121 _get_pending_crush(newcrush
);
7123 bool may_be_idempotent
= false;
7125 int err
= _prepare_command_osd_crush_remove(newcrush
, id
, 0, false, false);
7126 if (err
== -ENOENT
) {
7128 may_be_idempotent
= true;
7129 } else if (err
< 0) {
7130 ss
<< "error removing osd." << id
<< " from crush";
7134 // no point destroying the osd again if it has already been marked destroyed
7135 if (!osdmap
.is_destroyed(id
)) {
7136 err
= prepare_command_osd_destroy(id
, ss
);
7138 if (err
== -ENOENT
) {
7144 may_be_idempotent
= false;
7149 if (may_be_idempotent
&& !osdmap
.exists(id
)) {
7150 dout(10) << __func__
<< " osd." << id
<< " does not exist and "
7151 << "we are idempotent." << dendl
;
7155 err
= prepare_command_osd_remove(id
);
7156 // we should not be busy, as we should have made sure this id is not up.
7159 do_osd_crush_remove(newcrush
);
7163 bool OSDMonitor::prepare_command_impl(MonOpRequestRef op
,
7164 map
<string
,cmd_vartype
> &cmdmap
)
7166 op
->mark_osdmon_event(__func__
);
7167 MMonCommand
*m
= static_cast<MMonCommand
*>(op
->get_req());
7175 cmd_getval(g_ceph_context
, cmdmap
, "format", format
, string("plain"));
7176 boost::scoped_ptr
<Formatter
> f(Formatter::create(format
));
7179 cmd_getval(g_ceph_context
, cmdmap
, "prefix", prefix
);
7183 bool osdid_present
= cmd_getval(g_ceph_context
, cmdmap
, "id", osdid
);
7184 if (osdid_present
) {
7186 oss
<< "osd." << osdid
;
7190 // Even if there's a pending state with changes that could affect
7191 // a command, considering that said state isn't yet committed, we
7192 // just don't care about those changes if the command currently being
7193 // handled acts as a no-op against the current committed state.
7194 // In a nutshell, we assume this command happens *before*.
7196 // Let me make this clearer:
7198 // - If we have only one client, and that client issues some
7199 // operation that would conflict with this operation but is
7200 // still on the pending state, then we would be sure that said
7201 // operation wouldn't have returned yet, so the client wouldn't
7202 // issue this operation (unless the client didn't wait for the
7203 // operation to finish, and that would be the client's own fault).
7205 // - If we have more than one client, each client will observe
7206 // whatever is the state at the moment of the commit. So, if we
7207 // have two clients, one issuing an unlink and another issuing a
7208 // link, and if the link happens while the unlink is still on the
7209 // pending state, from the link's point-of-view this is a no-op.
7210 // If different clients are issuing conflicting operations and
7211 // they care about that, then the clients should make sure they
7212 // enforce some kind of concurrency mechanism -- from our
7213 // perspective that's what Douglas Adams would call an SEP.
7215 // This should be used as a general guideline for most commands handled
7216 // in this function. Adapt as you see fit, but please bear in mind that
7217 // this is the expected behavior.
7220 if (prefix
== "osd setcrushmap" ||
7221 (prefix
== "osd crush set" && !osdid_present
)) {
7222 if (pending_inc
.crush
.length()) {
7223 dout(10) << __func__
<< " waiting for pending crush update " << dendl
;
7224 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
7227 dout(10) << "prepare_command setting new crush map" << dendl
;
7228 bufferlist
data(m
->get_data());
7231 bufferlist::iterator
bl(data
.begin());
7234 catch (const std::exception
&e
) {
7236 ss
<< "Failed to parse crushmap: " << e
.what();
7240 int64_t prior_version
= 0;
7241 if (cmd_getval(g_ceph_context
, cmdmap
, "prior_version", prior_version
)) {
7242 if (prior_version
== osdmap
.get_crush_version() - 1) {
7243 // see if we are a resend of the last update. this is imperfect
7244 // (multiple racing updaters may not both get reliable success)
7245 // but we expect crush updaters (via this interface) to be rare-ish.
7246 bufferlist current
, proposed
;
7247 osdmap
.crush
->encode(current
, mon
->get_quorum_con_features());
7248 crush
.encode(proposed
, mon
->get_quorum_con_features());
7249 if (current
.contents_equal(proposed
)) {
7250 dout(10) << __func__
7251 << " proposed matches current and version equals previous"
7254 ss
<< osdmap
.get_crush_version();
7258 if (prior_version
!= osdmap
.get_crush_version()) {
7260 ss
<< "prior_version " << prior_version
<< " != crush version "
7261 << osdmap
.get_crush_version();
7266 if (crush
.has_legacy_rulesets()) {
7268 ss
<< "crush maps with ruleset != ruleid are no longer allowed";
7271 if (!validate_crush_against_features(&crush
, ss
)) {
7276 const auto& osdmap_pools
= osdmap
.get_pools();
7277 for (auto pit
= osdmap_pools
.begin(); pit
!= osdmap_pools
.end(); ++pit
) {
7278 const int64_t pool_id
= pit
->first
;
7279 const pg_pool_t
&pool
= pit
->second
;
7280 int ruleno
= pool
.get_crush_rule();
7281 if (!crush
.rule_exists(ruleno
)) {
7282 ss
<< " the crush rule no "<< ruleno
<< " for pool id " << pool_id
<< " is in use";
7288 if (g_conf
->mon_osd_crush_smoke_test
) {
7289 // sanity check: test some inputs to make sure this map isn't
7291 dout(10) << " testing map" << dendl
;
7293 CrushTester
tester(crush
, ess
);
7294 tester
.set_max_x(50);
7295 int r
= tester
.test_with_fork(g_conf
->mon_lease
);
7297 dout(10) << " tester.test_with_fork returns " << r
7298 << ": " << ess
.str() << dendl
;
7299 ss
<< "crush smoke test failed with " << r
<< ": " << ess
.str();
7303 dout(10) << " crush test result " << ess
.str() << dendl
;
7306 pending_inc
.crush
= data
;
7307 ss
<< osdmap
.get_crush_version() + 1;
7310 } else if (prefix
== "osd crush set-device-class") {
7311 if (osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
7312 ss
<< "you must complete the upgrade and 'ceph osd require-osd-release "
7313 << "luminous' before using crush device classes";
7318 string device_class
;
7319 if (!cmd_getval(g_ceph_context
, cmdmap
, "class", device_class
)) {
7320 err
= -EINVAL
; // no value!
7325 vector
<string
> idvec
;
7326 cmd_getval(g_ceph_context
, cmdmap
, "ids", idvec
);
7327 CrushWrapper newcrush
;
7328 _get_pending_crush(newcrush
);
7330 for (unsigned j
= 0; j
< idvec
.size() && !stop
; j
++) {
7334 (idvec
[0] == "any" || idvec
[0] == "all" || idvec
[0] == "*")) {
7335 osdmap
.get_all_osds(osds
);
7338 // try traditional single osd way
7339 long osd
= parse_osd_id(idvec
[j
].c_str(), &ss
);
7341 // ss has reason for failure
7342 ss
<< ", unable to parse osd id:\"" << idvec
[j
] << "\". ";
7349 for (auto &osd
: osds
) {
7350 if (!osdmap
.exists(osd
)) {
7351 ss
<< "osd." << osd
<< " does not exist. ";
7356 oss
<< "osd." << osd
;
7357 string name
= oss
.str();
7360 if (newcrush
.item_exists(osd
)) {
7361 action
= "updating";
7363 action
= "creating";
7364 newcrush
.set_item_name(osd
, name
);
7367 dout(5) << action
<< " crush item id " << osd
<< " name '" << name
7368 << "' device_class '" << device_class
<< "'"
7370 err
= newcrush
.update_device_class(osd
, device_class
, name
, &ss
);
7374 if (err
== 0 && !_have_pending_crush()) {
7376 // for single osd only, wildcard makes too much noise
7377 ss
<< "set-device-class item id " << osd
<< " name '" << name
7378 << "' device_class '" << device_class
<< "': no change";
7381 updated
.insert(osd
);
7386 if (!updated
.empty()) {
7387 pending_inc
.crush
.clear();
7388 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7389 ss
<< "set osd(s) " << updated
<< " to class '" << device_class
<< "'";
7391 wait_for_finished_proposal(op
,
7392 new Monitor::C_Command(mon
,op
, 0, rs
, get_last_committed() + 1));
7396 } else if (prefix
== "osd crush rm-device-class") {
7398 vector
<string
> idvec
;
7399 cmd_getval(g_ceph_context
, cmdmap
, "ids", idvec
);
7400 CrushWrapper newcrush
;
7401 _get_pending_crush(newcrush
);
7404 for (unsigned j
= 0; j
< idvec
.size() && !stop
; j
++) {
7409 (idvec
[0] == "any" || idvec
[0] == "all" || idvec
[0] == "*")) {
7410 osdmap
.get_all_osds(osds
);
7413 // try traditional single osd way
7414 long osd
= parse_osd_id(idvec
[j
].c_str(), &ss
);
7416 // ss has reason for failure
7417 ss
<< ", unable to parse osd id:\"" << idvec
[j
] << "\". ";
7424 for (auto &osd
: osds
) {
7425 if (!osdmap
.exists(osd
)) {
7426 ss
<< "osd." << osd
<< " does not exist. ";
7430 auto class_name
= newcrush
.get_item_class(osd
);
7432 ss
<< "osd." << osd
<< " belongs to no class, ";
7435 // note that we do not verify if class_is_in_use here
7436 // in case the device is misclassified and user wants
7437 // to overridely reset...
7439 err
= newcrush
.remove_device_class(g_ceph_context
, osd
, &ss
);
7441 // ss has reason for failure
7444 updated
.insert(osd
);
7448 if (!updated
.empty()) {
7449 pending_inc
.crush
.clear();
7450 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7451 ss
<< "done removing class of osd(s): " << updated
;
7453 wait_for_finished_proposal(op
,
7454 new Monitor::C_Command(mon
,op
, 0, rs
, get_last_committed() + 1));
7458 } else if (prefix
== "osd crush add-bucket") {
7459 // os crush add-bucket <name> <type>
7460 string name
, typestr
;
7461 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
7462 cmd_getval(g_ceph_context
, cmdmap
, "type", typestr
);
7464 if (!_have_pending_crush() &&
7465 _get_stable_crush().name_exists(name
)) {
7466 ss
<< "bucket '" << name
<< "' already exists";
7470 CrushWrapper newcrush
;
7471 _get_pending_crush(newcrush
);
7473 if (newcrush
.name_exists(name
)) {
7474 ss
<< "bucket '" << name
<< "' already exists";
7477 int type
= newcrush
.get_type_id(typestr
);
7479 ss
<< "type '" << typestr
<< "' does not exist";
7484 ss
<< "type '" << typestr
<< "' is for devices, not buckets";
7489 err
= newcrush
.add_bucket(0, 0,
7490 CRUSH_HASH_DEFAULT
, type
, 0, NULL
,
7493 ss
<< "add_bucket error: '" << cpp_strerror(err
) << "'";
7496 err
= newcrush
.set_item_name(bucketno
, name
);
7498 ss
<< "error setting bucket name to '" << name
<< "'";
7502 pending_inc
.crush
.clear();
7503 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7504 ss
<< "added bucket " << name
<< " type " << typestr
7507 } else if (prefix
== "osd crush rename-bucket") {
7508 string srcname
, dstname
;
7509 cmd_getval(g_ceph_context
, cmdmap
, "srcname", srcname
);
7510 cmd_getval(g_ceph_context
, cmdmap
, "dstname", dstname
);
7512 err
= crush_rename_bucket(srcname
, dstname
, &ss
);
7513 if (err
== -EALREADY
) // equivalent to success for idempotency
7519 } else if (prefix
== "osd crush weight-set create" ||
7520 prefix
== "osd crush weight-set create-compat") {
7521 CrushWrapper newcrush
;
7522 _get_pending_crush(newcrush
);
7525 if (newcrush
.has_non_straw2_buckets()) {
7526 ss
<< "crush map contains one or more bucket(s) that are not straw2";
7530 if (prefix
== "osd crush weight-set create") {
7531 if (osdmap
.require_min_compat_client
> 0 &&
7532 osdmap
.require_min_compat_client
< CEPH_RELEASE_LUMINOUS
) {
7533 ss
<< "require_min_compat_client "
7534 << ceph_release_name(osdmap
.require_min_compat_client
)
7535 << " < luminous, which is required for per-pool weight-sets. "
7536 << "Try 'ceph osd set-require-min-compat-client luminous' "
7537 << "before using the new interface";
7541 string poolname
, mode
;
7542 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolname
);
7543 pool
= osdmap
.lookup_pg_pool_name(poolname
.c_str());
7545 ss
<< "pool '" << poolname
<< "' not found";
7549 cmd_getval(g_ceph_context
, cmdmap
, "mode", mode
);
7550 if (mode
!= "flat" && mode
!= "positional") {
7551 ss
<< "unrecognized weight-set mode '" << mode
<< "'";
7555 positions
= mode
== "flat" ? 1 : osdmap
.get_pg_pool(pool
)->get_size();
7557 pool
= CrushWrapper::DEFAULT_CHOOSE_ARGS
;
7560 newcrush
.create_choose_args(pool
, positions
);
7561 pending_inc
.crush
.clear();
7562 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7565 } else if (prefix
== "osd crush weight-set rm" ||
7566 prefix
== "osd crush weight-set rm-compat") {
7567 CrushWrapper newcrush
;
7568 _get_pending_crush(newcrush
);
7570 if (prefix
== "osd crush weight-set rm") {
7572 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolname
);
7573 pool
= osdmap
.lookup_pg_pool_name(poolname
.c_str());
7575 ss
<< "pool '" << poolname
<< "' not found";
7580 pool
= CrushWrapper::DEFAULT_CHOOSE_ARGS
;
7582 newcrush
.rm_choose_args(pool
);
7583 pending_inc
.crush
.clear();
7584 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7587 } else if (prefix
== "osd crush weight-set reweight" ||
7588 prefix
== "osd crush weight-set reweight-compat") {
7589 string poolname
, item
;
7590 vector
<double> weight
;
7591 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolname
);
7592 cmd_getval(g_ceph_context
, cmdmap
, "item", item
);
7593 cmd_getval(g_ceph_context
, cmdmap
, "weight", weight
);
7594 CrushWrapper newcrush
;
7595 _get_pending_crush(newcrush
);
7597 if (prefix
== "osd crush weight-set reweight") {
7598 pool
= osdmap
.lookup_pg_pool_name(poolname
.c_str());
7600 ss
<< "pool '" << poolname
<< "' not found";
7604 if (!newcrush
.have_choose_args(pool
)) {
7605 ss
<< "no weight-set for pool '" << poolname
<< "'";
7609 auto arg_map
= newcrush
.choose_args_get(pool
);
7610 int positions
= newcrush
.get_choose_args_positions(arg_map
);
7611 if (weight
.size() != (size_t)positions
) {
7612 ss
<< "must specify exact " << positions
<< " weight values";
7617 pool
= CrushWrapper::DEFAULT_CHOOSE_ARGS
;
7618 if (!newcrush
.have_choose_args(pool
)) {
7619 ss
<< "no backward-compatible weight-set";
7624 if (!newcrush
.name_exists(item
)) {
7625 ss
<< "item '" << item
<< "' does not exist";
7629 err
= newcrush
.choose_args_adjust_item_weightf(
7631 newcrush
.choose_args_get(pool
),
7632 newcrush
.get_item_id(item
),
7639 pending_inc
.crush
.clear();
7640 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7642 } else if (osdid_present
&&
7643 (prefix
== "osd crush set" || prefix
== "osd crush add")) {
7644 // <OsdName> is 'osd.<id>' or '<id>', passed as int64_t id
7645 // osd crush set <OsdName> <weight> <loc1> [<loc2> ...]
7646 // osd crush add <OsdName> <weight> <loc1> [<loc2> ...]
7648 if (!osdmap
.exists(osdid
)) {
7650 ss
<< name
<< " does not exist. Create it before updating the crush map";
7655 if (!cmd_getval(g_ceph_context
, cmdmap
, "weight", weight
)) {
7656 ss
<< "unable to parse weight value '"
7657 << cmd_vartype_stringify(cmdmap
["weight"]) << "'";
7663 vector
<string
> argvec
;
7664 cmd_getval(g_ceph_context
, cmdmap
, "args", argvec
);
7665 map
<string
,string
> loc
;
7666 CrushWrapper::parse_loc_map(argvec
, &loc
);
7668 if (prefix
== "osd crush set"
7669 && !_get_stable_crush().item_exists(osdid
)) {
7671 ss
<< "unable to set item id " << osdid
<< " name '" << name
7672 << "' weight " << weight
<< " at location " << loc
7673 << ": does not exist";
7677 dout(5) << "adding/updating crush item id " << osdid
<< " name '"
7678 << name
<< "' weight " << weight
<< " at location "
7680 CrushWrapper newcrush
;
7681 _get_pending_crush(newcrush
);
7684 if (prefix
== "osd crush set" ||
7685 newcrush
.check_item_loc(g_ceph_context
, osdid
, loc
, (int *)NULL
)) {
7687 err
= newcrush
.update_item(g_ceph_context
, osdid
, weight
, name
, loc
);
7690 err
= newcrush
.insert_item(g_ceph_context
, osdid
, weight
, name
, loc
);
7698 if (err
== 0 && !_have_pending_crush()) {
7699 ss
<< action
<< " item id " << osdid
<< " name '" << name
<< "' weight "
7700 << weight
<< " at location " << loc
<< ": no change";
7704 pending_inc
.crush
.clear();
7705 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7706 ss
<< action
<< " item id " << osdid
<< " name '" << name
<< "' weight "
7707 << weight
<< " at location " << loc
<< " to crush map";
7709 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
7710 get_last_committed() + 1));
7713 } else if (prefix
== "osd crush create-or-move") {
7715 // osd crush create-or-move <OsdName> <initial_weight> <loc1> [<loc2> ...]
7716 if (!osdmap
.exists(osdid
)) {
7718 ss
<< name
<< " does not exist. create it before updating the crush map";
7723 if (!cmd_getval(g_ceph_context
, cmdmap
, "weight", weight
)) {
7724 ss
<< "unable to parse weight value '"
7725 << cmd_vartype_stringify(cmdmap
["weight"]) << "'";
7731 vector
<string
> argvec
;
7732 cmd_getval(g_ceph_context
, cmdmap
, "args", argvec
);
7733 map
<string
,string
> loc
;
7734 CrushWrapper::parse_loc_map(argvec
, &loc
);
7736 dout(0) << "create-or-move crush item name '" << name
<< "' initial_weight " << weight
7737 << " at location " << loc
<< dendl
;
7739 CrushWrapper newcrush
;
7740 _get_pending_crush(newcrush
);
7742 err
= newcrush
.create_or_move_item(g_ceph_context
, osdid
, weight
, name
, loc
);
7744 ss
<< "create-or-move updated item name '" << name
<< "' weight " << weight
7745 << " at location " << loc
<< " to crush map";
7749 pending_inc
.crush
.clear();
7750 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7751 ss
<< "create-or-move updating item name '" << name
<< "' weight " << weight
7752 << " at location " << loc
<< " to crush map";
7754 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
7755 get_last_committed() + 1));
7760 } else if (prefix
== "osd crush move") {
7762 // osd crush move <name> <loc1> [<loc2> ...]
7765 vector
<string
> argvec
;
7766 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
7767 cmd_getval(g_ceph_context
, cmdmap
, "args", argvec
);
7768 map
<string
,string
> loc
;
7769 CrushWrapper::parse_loc_map(argvec
, &loc
);
7771 dout(0) << "moving crush item name '" << name
<< "' to location " << loc
<< dendl
;
7772 CrushWrapper newcrush
;
7773 _get_pending_crush(newcrush
);
7775 if (!newcrush
.name_exists(name
)) {
7777 ss
<< "item " << name
<< " does not exist";
7780 int id
= newcrush
.get_item_id(name
);
7782 if (!newcrush
.check_item_loc(g_ceph_context
, id
, loc
, (int *)NULL
)) {
7784 err
= newcrush
.create_or_move_item(g_ceph_context
, id
, 0, name
, loc
);
7786 err
= newcrush
.move_bucket(g_ceph_context
, id
, loc
);
7789 ss
<< "moved item id " << id
<< " name '" << name
<< "' to location " << loc
<< " in crush map";
7790 pending_inc
.crush
.clear();
7791 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7793 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
7794 get_last_committed() + 1));
7798 ss
<< "no need to move item id " << id
<< " name '" << name
<< "' to location " << loc
<< " in crush map";
7802 } else if (prefix
== "osd crush swap-bucket") {
7803 string source
, dest
, force
;
7804 cmd_getval(g_ceph_context
, cmdmap
, "source", source
);
7805 cmd_getval(g_ceph_context
, cmdmap
, "dest", dest
);
7806 cmd_getval(g_ceph_context
, cmdmap
, "force", force
);
7807 CrushWrapper newcrush
;
7808 _get_pending_crush(newcrush
);
7809 if (!newcrush
.name_exists(source
)) {
7810 ss
<< "source item " << source
<< " does not exist";
7814 if (!newcrush
.name_exists(dest
)) {
7815 ss
<< "dest item " << dest
<< " does not exist";
7819 int sid
= newcrush
.get_item_id(source
);
7820 int did
= newcrush
.get_item_id(dest
);
7822 if (newcrush
.get_immediate_parent_id(sid
, &sparent
) == 0 &&
7823 force
!= "--yes-i-really-mean-it") {
7824 ss
<< "source item " << source
<< " is not an orphan bucket; pass --yes-i-really-mean-it to proceed anyway";
7828 if (newcrush
.get_bucket_alg(sid
) != newcrush
.get_bucket_alg(did
) &&
7829 force
!= "--yes-i-really-mean-it") {
7830 ss
<< "source bucket alg " << crush_alg_name(newcrush
.get_bucket_alg(sid
)) << " != "
7831 << "dest bucket alg " << crush_alg_name(newcrush
.get_bucket_alg(did
))
7832 << "; pass --yes-i-really-mean-it to proceed anyway";
7836 int r
= newcrush
.swap_bucket(g_ceph_context
, sid
, did
);
7838 ss
<< "failed to swap bucket contents: " << cpp_strerror(r
);
7842 ss
<< "swapped bucket of " << source
<< " to " << dest
;
7843 pending_inc
.crush
.clear();
7844 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7845 wait_for_finished_proposal(op
,
7846 new Monitor::C_Command(mon
, op
, err
, ss
.str(),
7847 get_last_committed() + 1));
7849 } else if (prefix
== "osd crush link") {
7850 // osd crush link <name> <loc1> [<loc2> ...]
7852 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
7853 vector
<string
> argvec
;
7854 cmd_getval(g_ceph_context
, cmdmap
, "args", argvec
);
7855 map
<string
,string
> loc
;
7856 CrushWrapper::parse_loc_map(argvec
, &loc
);
7858 // Need an explicit check for name_exists because get_item_id returns
7860 int id
= osdmap
.crush
->get_item_id(name
);
7861 if (!osdmap
.crush
->name_exists(name
)) {
7863 ss
<< "item " << name
<< " does not exist";
7866 dout(5) << "resolved crush name '" << name
<< "' to id " << id
<< dendl
;
7868 if (osdmap
.crush
->check_item_loc(g_ceph_context
, id
, loc
, (int*) NULL
)) {
7869 ss
<< "no need to move item id " << id
<< " name '" << name
7870 << "' to location " << loc
<< " in crush map";
7875 dout(5) << "linking crush item name '" << name
<< "' at location " << loc
<< dendl
;
7876 CrushWrapper newcrush
;
7877 _get_pending_crush(newcrush
);
7879 if (!newcrush
.name_exists(name
)) {
7881 ss
<< "item " << name
<< " does not exist";
7884 int id
= newcrush
.get_item_id(name
);
7885 if (!newcrush
.check_item_loc(g_ceph_context
, id
, loc
, (int *)NULL
)) {
7886 err
= newcrush
.link_bucket(g_ceph_context
, id
, loc
);
7888 ss
<< "linked item id " << id
<< " name '" << name
7889 << "' to location " << loc
<< " in crush map";
7890 pending_inc
.crush
.clear();
7891 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7893 ss
<< "cannot link item id " << id
<< " name '" << name
7894 << "' to location " << loc
;
7898 ss
<< "no need to move item id " << id
<< " name '" << name
7899 << "' to location " << loc
<< " in crush map";
7903 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, err
, ss
.str(),
7904 get_last_committed() + 1));
7906 } else if (prefix
== "osd crush rm" ||
7907 prefix
== "osd crush remove" ||
7908 prefix
== "osd crush unlink") {
7910 // osd crush rm <id> [ancestor]
7911 CrushWrapper newcrush
;
7912 _get_pending_crush(newcrush
);
7915 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
7917 if (!osdmap
.crush
->name_exists(name
)) {
7919 ss
<< "device '" << name
<< "' does not appear in the crush map";
7922 if (!newcrush
.name_exists(name
)) {
7924 ss
<< "device '" << name
<< "' does not appear in the crush map";
7926 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
7927 get_last_committed() + 1));
7930 int id
= newcrush
.get_item_id(name
);
7933 bool unlink_only
= prefix
== "osd crush unlink";
7934 string ancestor_str
;
7935 if (cmd_getval(g_ceph_context
, cmdmap
, "ancestor", ancestor_str
)) {
7936 if (!newcrush
.name_exists(ancestor_str
)) {
7938 ss
<< "ancestor item '" << ancestor_str
7939 << "' does not appear in the crush map";
7942 ancestor
= newcrush
.get_item_id(ancestor_str
);
7945 err
= prepare_command_osd_crush_remove(
7948 (ancestor
< 0), unlink_only
);
7950 if (err
== -ENOENT
) {
7951 ss
<< "item " << id
<< " does not appear in that position";
7956 ss
<< "removed item id " << id
<< " name '" << name
<< "' from crush map";
7958 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
7959 get_last_committed() + 1));
7964 } else if (prefix
== "osd crush reweight-all") {
7965 CrushWrapper newcrush
;
7966 _get_pending_crush(newcrush
);
7968 newcrush
.reweight(g_ceph_context
);
7969 pending_inc
.crush
.clear();
7970 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
7971 ss
<< "reweighted crush hierarchy";
7973 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
7974 get_last_committed() + 1));
7976 } else if (prefix
== "osd crush reweight") {
7977 // osd crush reweight <name> <weight>
7978 CrushWrapper newcrush
;
7979 _get_pending_crush(newcrush
);
7982 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
7983 if (!newcrush
.name_exists(name
)) {
7985 ss
<< "device '" << name
<< "' does not appear in the crush map";
7989 int id
= newcrush
.get_item_id(name
);
7991 ss
<< "device '" << name
<< "' is not a leaf in the crush map";
7996 if (!cmd_getval(g_ceph_context
, cmdmap
, "weight", w
)) {
7997 ss
<< "unable to parse weight value '"
7998 << cmd_vartype_stringify(cmdmap
["weight"]) << "'";
8003 err
= newcrush
.adjust_item_weightf(g_ceph_context
, id
, w
);
8006 pending_inc
.crush
.clear();
8007 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
8008 ss
<< "reweighted item id " << id
<< " name '" << name
<< "' to " << w
8011 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8012 get_last_committed() + 1));
8014 } else if (prefix
== "osd crush reweight-subtree") {
8015 // osd crush reweight <name> <weight>
8016 CrushWrapper newcrush
;
8017 _get_pending_crush(newcrush
);
8020 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
8021 if (!newcrush
.name_exists(name
)) {
8023 ss
<< "device '" << name
<< "' does not appear in the crush map";
8027 int id
= newcrush
.get_item_id(name
);
8029 ss
<< "device '" << name
<< "' is not a subtree in the crush map";
8034 if (!cmd_getval(g_ceph_context
, cmdmap
, "weight", w
)) {
8035 ss
<< "unable to parse weight value '"
8036 << cmd_vartype_stringify(cmdmap
["weight"]) << "'";
8041 err
= newcrush
.adjust_subtree_weightf(g_ceph_context
, id
, w
);
8044 pending_inc
.crush
.clear();
8045 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
8046 ss
<< "reweighted subtree id " << id
<< " name '" << name
<< "' to " << w
8049 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8050 get_last_committed() + 1));
8052 } else if (prefix
== "osd crush tunables") {
8053 CrushWrapper newcrush
;
8054 _get_pending_crush(newcrush
);
8058 cmd_getval(g_ceph_context
, cmdmap
, "profile", profile
);
8059 if (profile
== "legacy" || profile
== "argonaut") {
8060 newcrush
.set_tunables_legacy();
8061 } else if (profile
== "bobtail") {
8062 newcrush
.set_tunables_bobtail();
8063 } else if (profile
== "firefly") {
8064 newcrush
.set_tunables_firefly();
8065 } else if (profile
== "hammer") {
8066 newcrush
.set_tunables_hammer();
8067 } else if (profile
== "jewel") {
8068 newcrush
.set_tunables_jewel();
8069 } else if (profile
== "optimal") {
8070 newcrush
.set_tunables_optimal();
8071 } else if (profile
== "default") {
8072 newcrush
.set_tunables_default();
8074 ss
<< "unrecognized profile '" << profile
<< "'";
8079 if (!validate_crush_against_features(&newcrush
, ss
)) {
8084 pending_inc
.crush
.clear();
8085 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
8086 ss
<< "adjusted tunables profile to " << profile
;
8088 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8089 get_last_committed() + 1));
8091 } else if (prefix
== "osd crush set-tunable") {
8092 CrushWrapper newcrush
;
8093 _get_pending_crush(newcrush
);
8097 cmd_getval(g_ceph_context
, cmdmap
, "tunable", tunable
);
8100 if (!cmd_getval(g_ceph_context
, cmdmap
, "value", value
)) {
8102 ss
<< "failed to parse integer value " << cmd_vartype_stringify(cmdmap
["value"]);
8106 if (tunable
== "straw_calc_version") {
8107 if (value
!= 0 && value
!= 1) {
8108 ss
<< "value must be 0 or 1; got " << value
;
8112 newcrush
.set_straw_calc_version(value
);
8114 ss
<< "unrecognized tunable '" << tunable
<< "'";
8119 if (!validate_crush_against_features(&newcrush
, ss
)) {
8124 pending_inc
.crush
.clear();
8125 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
8126 ss
<< "adjusted tunable " << tunable
<< " to " << value
;
8128 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8129 get_last_committed() + 1));
8132 } else if (prefix
== "osd crush rule create-simple") {
8133 string name
, root
, type
, mode
;
8134 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
8135 cmd_getval(g_ceph_context
, cmdmap
, "root", root
);
8136 cmd_getval(g_ceph_context
, cmdmap
, "type", type
);
8137 cmd_getval(g_ceph_context
, cmdmap
, "mode", mode
);
8141 if (osdmap
.crush
->rule_exists(name
)) {
8142 // The name is uniquely associated to a ruleid and the rule it contains
8143 // From the user point of view, the rule is more meaningfull.
8144 ss
<< "rule " << name
<< " already exists";
8149 CrushWrapper newcrush
;
8150 _get_pending_crush(newcrush
);
8152 if (newcrush
.rule_exists(name
)) {
8153 // The name is uniquely associated to a ruleid and the rule it contains
8154 // From the user point of view, the rule is more meaningfull.
8155 ss
<< "rule " << name
<< " already exists";
8158 int ruleno
= newcrush
.add_simple_rule(name
, root
, type
, "", mode
,
8159 pg_pool_t::TYPE_REPLICATED
, &ss
);
8165 pending_inc
.crush
.clear();
8166 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
8169 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8170 get_last_committed() + 1));
8173 } else if (prefix
== "osd crush rule create-replicated") {
8174 string name
, root
, type
, device_class
;
8175 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
8176 cmd_getval(g_ceph_context
, cmdmap
, "root", root
);
8177 cmd_getval(g_ceph_context
, cmdmap
, "type", type
);
8178 cmd_getval(g_ceph_context
, cmdmap
, "class", device_class
);
8180 if (!device_class
.empty()) {
8181 if (osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
8182 ss
<< "you must complete the upgrade and 'ceph osd require-osd-release "
8183 << "luminous' before using crush device classes";
8189 if (osdmap
.crush
->rule_exists(name
)) {
8190 // The name is uniquely associated to a ruleid and the rule it contains
8191 // From the user point of view, the rule is more meaningfull.
8192 ss
<< "rule " << name
<< " already exists";
8197 CrushWrapper newcrush
;
8198 _get_pending_crush(newcrush
);
8200 if (newcrush
.rule_exists(name
)) {
8201 // The name is uniquely associated to a ruleid and the rule it contains
8202 // From the user point of view, the rule is more meaningfull.
8203 ss
<< "rule " << name
<< " already exists";
8206 int ruleno
= newcrush
.add_simple_rule(
8207 name
, root
, type
, device_class
,
8208 "firstn", pg_pool_t::TYPE_REPLICATED
, &ss
);
8214 pending_inc
.crush
.clear();
8215 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
8218 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8219 get_last_committed() + 1));
8222 } else if (prefix
== "osd erasure-code-profile rm") {
8224 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
8226 if (erasure_code_profile_in_use(pending_inc
.new_pools
, name
, &ss
))
8229 if (erasure_code_profile_in_use(osdmap
.pools
, name
, &ss
)) {
8234 if (osdmap
.has_erasure_code_profile(name
) ||
8235 pending_inc
.new_erasure_code_profiles
.count(name
)) {
8236 if (osdmap
.has_erasure_code_profile(name
)) {
8237 pending_inc
.old_erasure_code_profiles
.push_back(name
);
8239 dout(20) << "erasure code profile rm " << name
<< ": creation canceled" << dendl
;
8240 pending_inc
.new_erasure_code_profiles
.erase(name
);
8244 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8245 get_last_committed() + 1));
8248 ss
<< "erasure-code-profile " << name
<< " does not exist";
8253 } else if (prefix
== "osd erasure-code-profile set") {
8255 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
8256 vector
<string
> profile
;
8257 cmd_getval(g_ceph_context
, cmdmap
, "profile", profile
);
8259 if (profile
.size() > 0 && profile
.back() == "--force") {
8265 map
<string
,string
> profile_map
;
8266 err
= parse_erasure_code_profile(profile
, &profile_map
, &ss
);
8269 if (profile_map
.find("plugin") == profile_map
.end()) {
8270 ss
<< "erasure-code-profile " << profile_map
8271 << " must contain a plugin entry" << std::endl
;
8275 string plugin
= profile_map
["plugin"];
8277 if (pending_inc
.has_erasure_code_profile(name
)) {
8278 dout(20) << "erasure code profile " << name
<< " try again" << dendl
;
8281 if (plugin
== "isa" || plugin
== "lrc") {
8282 err
= check_cluster_features(CEPH_FEATURE_ERASURE_CODE_PLUGINS_V2
, ss
);
8287 } else if (plugin
== "shec") {
8288 err
= check_cluster_features(CEPH_FEATURE_ERASURE_CODE_PLUGINS_V3
, ss
);
8294 err
= normalize_profile(name
, profile_map
, force
, &ss
);
8298 if (osdmap
.has_erasure_code_profile(name
)) {
8299 ErasureCodeProfile existing_profile_map
=
8300 osdmap
.get_erasure_code_profile(name
);
8301 err
= normalize_profile(name
, existing_profile_map
, force
, &ss
);
8305 if (existing_profile_map
== profile_map
) {
8311 ss
<< "will not override erasure code profile " << name
8312 << " because the existing profile "
8313 << existing_profile_map
8314 << " is different from the proposed profile "
8320 dout(20) << "erasure code profile set " << name
<< "="
8321 << profile_map
<< dendl
;
8322 pending_inc
.set_erasure_code_profile(name
, profile_map
);
8326 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8327 get_last_committed() + 1));
8330 } else if (prefix
== "osd crush rule create-erasure") {
8331 err
= check_cluster_features(CEPH_FEATURE_CRUSH_V2
, ss
);
8336 string name
, poolstr
;
8337 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
8339 cmd_getval(g_ceph_context
, cmdmap
, "profile", profile
);
8341 profile
= "default";
8342 if (profile
== "default") {
8343 if (!osdmap
.has_erasure_code_profile(profile
)) {
8344 if (pending_inc
.has_erasure_code_profile(profile
)) {
8345 dout(20) << "erasure code profile " << profile
<< " already pending" << dendl
;
8349 map
<string
,string
> profile_map
;
8350 err
= osdmap
.get_erasure_code_profile_default(g_ceph_context
,
8355 err
= normalize_profile(name
, profile_map
, true, &ss
);
8358 dout(20) << "erasure code profile set " << profile
<< "="
8359 << profile_map
<< dendl
;
8360 pending_inc
.set_erasure_code_profile(profile
, profile_map
);
8366 err
= crush_rule_create_erasure(name
, profile
, &rule
, &ss
);
8369 case -EEXIST
: // return immediately
8370 ss
<< "rule " << name
<< " already exists";
8374 case -EALREADY
: // wait for pending to be proposed
8375 ss
<< "rule " << name
<< " already exists";
8378 default: // non recoverable error
8383 ss
<< "created rule " << name
<< " at " << rule
;
8387 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8388 get_last_committed() + 1));
8391 } else if (prefix
== "osd crush rule rm") {
8393 cmd_getval(g_ceph_context
, cmdmap
, "name", name
);
8395 if (!osdmap
.crush
->rule_exists(name
)) {
8396 ss
<< "rule " << name
<< " does not exist";
8401 CrushWrapper newcrush
;
8402 _get_pending_crush(newcrush
);
8404 if (!newcrush
.rule_exists(name
)) {
8405 ss
<< "rule " << name
<< " does not exist";
8408 int ruleno
= newcrush
.get_rule_id(name
);
8409 assert(ruleno
>= 0);
8411 // make sure it is not in use.
8412 // FIXME: this is ok in some situations, but let's not bother with that
8414 int ruleset
= newcrush
.get_rule_mask_ruleset(ruleno
);
8415 if (osdmap
.crush_ruleset_in_use(ruleset
)) {
8416 ss
<< "crush ruleset " << name
<< " " << ruleset
<< " is in use";
8421 err
= newcrush
.remove_rule(ruleno
);
8426 pending_inc
.crush
.clear();
8427 newcrush
.encode(pending_inc
.crush
, mon
->get_quorum_con_features());
8430 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8431 get_last_committed() + 1));
8434 } else if (prefix
== "osd setmaxosd") {
8436 if (!cmd_getval(g_ceph_context
, cmdmap
, "newmax", newmax
)) {
8437 ss
<< "unable to parse 'newmax' value '"
8438 << cmd_vartype_stringify(cmdmap
["newmax"]) << "'";
8443 if (newmax
> g_conf
->mon_max_osd
) {
8445 ss
<< "cannot set max_osd to " << newmax
<< " which is > conf.mon_max_osd ("
8446 << g_conf
->mon_max_osd
<< ")";
8450 // Don't allow shrinking OSD number as this will cause data loss
8451 // and may cause kernel crashes.
8452 // Note: setmaxosd sets the maximum OSD number and not the number of OSDs
8453 if (newmax
< osdmap
.get_max_osd()) {
8454 // Check if the OSDs exist between current max and new value.
8455 // If there are any OSDs exist, then don't allow shrinking number
8457 for (int i
= newmax
; i
< osdmap
.get_max_osd(); i
++) {
8458 if (osdmap
.exists(i
)) {
8460 ss
<< "cannot shrink max_osd to " << newmax
8461 << " because osd." << i
<< " (and possibly others) still in use";
8467 pending_inc
.new_max_osd
= newmax
;
8468 ss
<< "set new max_osd = " << pending_inc
.new_max_osd
;
8470 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8471 get_last_committed() + 1));
8474 } else if (prefix
== "osd set-full-ratio" ||
8475 prefix
== "osd set-backfillfull-ratio" ||
8476 prefix
== "osd set-nearfull-ratio") {
8477 if (osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
8478 ss
<< "you must complete the upgrade and 'ceph osd require-osd-release "
8479 << "luminous' before using the new interface";
8484 if (!cmd_getval(g_ceph_context
, cmdmap
, "ratio", n
)) {
8485 ss
<< "unable to parse 'ratio' value '"
8486 << cmd_vartype_stringify(cmdmap
["ratio"]) << "'";
8490 if (prefix
== "osd set-full-ratio")
8491 pending_inc
.new_full_ratio
= n
;
8492 else if (prefix
== "osd set-backfillfull-ratio")
8493 pending_inc
.new_backfillfull_ratio
= n
;
8494 else if (prefix
== "osd set-nearfull-ratio")
8495 pending_inc
.new_nearfull_ratio
= n
;
8496 ss
<< prefix
<< " " << n
;
8498 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8499 get_last_committed() + 1));
8501 } else if (prefix
== "osd set-require-min-compat-client") {
8502 if (osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
8503 ss
<< "you must complete the upgrade and 'ceph osd require-osd-release "
8504 << "luminous' before using the new interface";
8509 cmd_getval(g_ceph_context
, cmdmap
, "version", v
);
8510 int vno
= ceph_release_from_name(v
.c_str());
8512 ss
<< "version " << v
<< " is not recognized";
8517 newmap
.deepish_copy_from(osdmap
);
8518 newmap
.apply_incremental(pending_inc
);
8519 newmap
.require_min_compat_client
= vno
;
8520 auto mvno
= newmap
.get_min_compat_client();
8522 ss
<< "osdmap current utilizes features that require "
8523 << ceph_release_name(mvno
)
8524 << "; cannot set require_min_compat_client below that to "
8525 << ceph_release_name(vno
);
8530 cmd_getval(g_ceph_context
, cmdmap
, "sure", sure
);
8531 if (sure
!= "--yes-i-really-mean-it") {
8533 mon
->get_combined_feature_map(&m
);
8534 uint64_t features
= ceph_release_features(vno
);
8538 CEPH_ENTITY_TYPE_CLIENT
,
8539 CEPH_ENTITY_TYPE_MDS
,
8540 CEPH_ENTITY_TYPE_MGR
}) {
8541 auto p
= m
.m
.find(type
);
8542 if (p
== m
.m
.end()) {
8545 for (auto& q
: p
->second
) {
8546 uint64_t missing
= ~q
.first
& features
;
8549 ss
<< "cannot set require_min_compat_client to " << v
<< ": ";
8554 ss
<< q
.second
<< " connected " << ceph_entity_type_name(type
)
8555 << "(s) look like " << ceph_release_name(
8556 ceph_release_from_features(q
.first
))
8557 << " (missing 0x" << std::hex
<< missing
<< std::dec
<< ")";
8563 ss
<< "; add --yes-i-really-mean-it to do it anyway";
8568 ss
<< "set require_min_compat_client to " << ceph_release_name(vno
);
8569 pending_inc
.new_require_min_compat_client
= vno
;
8571 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
8572 get_last_committed() + 1));
8574 } else if (prefix
== "osd pause") {
8575 return prepare_set_flag(op
, CEPH_OSDMAP_PAUSERD
| CEPH_OSDMAP_PAUSEWR
);
8577 } else if (prefix
== "osd unpause") {
8578 return prepare_unset_flag(op
, CEPH_OSDMAP_PAUSERD
| CEPH_OSDMAP_PAUSEWR
);
8580 } else if (prefix
== "osd set") {
8582 cmd_getval(g_ceph_context
, cmdmap
, "key", key
);
8584 return prepare_set_flag(op
, CEPH_OSDMAP_FULL
);
8585 else if (key
== "pause")
8586 return prepare_set_flag(op
, CEPH_OSDMAP_PAUSERD
| CEPH_OSDMAP_PAUSEWR
);
8587 else if (key
== "noup")
8588 return prepare_set_flag(op
, CEPH_OSDMAP_NOUP
);
8589 else if (key
== "nodown")
8590 return prepare_set_flag(op
, CEPH_OSDMAP_NODOWN
);
8591 else if (key
== "noout")
8592 return prepare_set_flag(op
, CEPH_OSDMAP_NOOUT
);
8593 else if (key
== "noin")
8594 return prepare_set_flag(op
, CEPH_OSDMAP_NOIN
);
8595 else if (key
== "nobackfill")
8596 return prepare_set_flag(op
, CEPH_OSDMAP_NOBACKFILL
);
8597 else if (key
== "norebalance")
8598 return prepare_set_flag(op
, CEPH_OSDMAP_NOREBALANCE
);
8599 else if (key
== "norecover")
8600 return prepare_set_flag(op
, CEPH_OSDMAP_NORECOVER
);
8601 else if (key
== "noscrub")
8602 return prepare_set_flag(op
, CEPH_OSDMAP_NOSCRUB
);
8603 else if (key
== "nodeep-scrub")
8604 return prepare_set_flag(op
, CEPH_OSDMAP_NODEEP_SCRUB
);
8605 else if (key
== "notieragent")
8606 return prepare_set_flag(op
, CEPH_OSDMAP_NOTIERAGENT
);
8607 else if (key
== "sortbitwise") {
8608 if (osdmap
.get_up_osd_features() & CEPH_FEATURE_OSD_BITWISE_HOBJ_SORT
) {
8609 return prepare_set_flag(op
, CEPH_OSDMAP_SORTBITWISE
);
8611 ss
<< "not all up OSDs have OSD_BITWISE_HOBJ_SORT feature";
8615 } else if (key
== "recovery_deletes") {
8616 if (HAVE_FEATURE(osdmap
.get_up_osd_features(), OSD_RECOVERY_DELETES
)) {
8617 return prepare_set_flag(op
, CEPH_OSDMAP_RECOVERY_DELETES
);
8619 ss
<< "not all up OSDs have OSD_RECOVERY_DELETES feature";
8623 } else if (key
== "require_jewel_osds") {
8624 if (!osdmap
.test_flag(CEPH_OSDMAP_SORTBITWISE
)) {
8625 ss
<< "the sortbitwise flag must be set before require_jewel_osds";
8628 } else if (osdmap
.require_osd_release
>= CEPH_RELEASE_JEWEL
) {
8629 ss
<< "require_osd_release is already >= jewel";
8632 } else if (HAVE_FEATURE(osdmap
.get_up_osd_features(), SERVER_JEWEL
)) {
8633 return prepare_set_flag(op
, CEPH_OSDMAP_REQUIRE_JEWEL
);
8635 ss
<< "not all up OSDs have CEPH_FEATURE_SERVER_JEWEL feature";
8638 } else if (key
== "require_kraken_osds") {
8639 if (!osdmap
.test_flag(CEPH_OSDMAP_SORTBITWISE
)) {
8640 ss
<< "the sortbitwise flag must be set before require_kraken_osds";
8643 } else if (osdmap
.require_osd_release
>= CEPH_RELEASE_KRAKEN
) {
8644 ss
<< "require_osd_release is already >= kraken";
8647 } else if (HAVE_FEATURE(osdmap
.get_up_osd_features(), SERVER_KRAKEN
)) {
8648 bool r
= prepare_set_flag(op
, CEPH_OSDMAP_REQUIRE_KRAKEN
);
8649 // ensure JEWEL is also set
8650 pending_inc
.new_flags
|= CEPH_OSDMAP_REQUIRE_JEWEL
;
8653 ss
<< "not all up OSDs have CEPH_FEATURE_SERVER_KRAKEN feature";
8657 ss
<< "unrecognized flag '" << key
<< "'";
8661 } else if (prefix
== "osd unset") {
8663 cmd_getval(g_ceph_context
, cmdmap
, "key", key
);
8665 return prepare_unset_flag(op
, CEPH_OSDMAP_FULL
);
8666 else if (key
== "pause")
8667 return prepare_unset_flag(op
, CEPH_OSDMAP_PAUSERD
| CEPH_OSDMAP_PAUSEWR
);
8668 else if (key
== "noup")
8669 return prepare_unset_flag(op
, CEPH_OSDMAP_NOUP
);
8670 else if (key
== "nodown")
8671 return prepare_unset_flag(op
, CEPH_OSDMAP_NODOWN
);
8672 else if (key
== "noout")
8673 return prepare_unset_flag(op
, CEPH_OSDMAP_NOOUT
);
8674 else if (key
== "noin")
8675 return prepare_unset_flag(op
, CEPH_OSDMAP_NOIN
);
8676 else if (key
== "nobackfill")
8677 return prepare_unset_flag(op
, CEPH_OSDMAP_NOBACKFILL
);
8678 else if (key
== "norebalance")
8679 return prepare_unset_flag(op
, CEPH_OSDMAP_NOREBALANCE
);
8680 else if (key
== "norecover")
8681 return prepare_unset_flag(op
, CEPH_OSDMAP_NORECOVER
);
8682 else if (key
== "noscrub")
8683 return prepare_unset_flag(op
, CEPH_OSDMAP_NOSCRUB
);
8684 else if (key
== "nodeep-scrub")
8685 return prepare_unset_flag(op
, CEPH_OSDMAP_NODEEP_SCRUB
);
8686 else if (key
== "notieragent")
8687 return prepare_unset_flag(op
, CEPH_OSDMAP_NOTIERAGENT
);
8689 ss
<< "unrecognized flag '" << key
<< "'";
8693 } else if (prefix
== "osd require-osd-release") {
8695 cmd_getval(g_ceph_context
, cmdmap
, "release", release
);
8696 if (!osdmap
.test_flag(CEPH_OSDMAP_SORTBITWISE
)) {
8697 ss
<< "the sortbitwise flag must be set first";
8701 int rel
= ceph_release_from_name(release
.c_str());
8703 ss
<< "unrecognized release " << release
;
8707 if (rel
< CEPH_RELEASE_LUMINOUS
) {
8708 ss
<< "use this command only for luminous and later";
8712 if (rel
== osdmap
.require_osd_release
) {
8717 if (rel
== CEPH_RELEASE_LUMINOUS
) {
8718 if (!HAVE_FEATURE(osdmap
.get_up_osd_features(), SERVER_LUMINOUS
)) {
8719 ss
<< "not all up OSDs have CEPH_FEATURE_SERVER_LUMINOUS feature";
8724 ss
<< "not supported for this release yet";
8728 if (rel
< osdmap
.require_osd_release
) {
8729 ss
<< "require_osd_release cannot be lowered once it has been set";
8733 pending_inc
.new_require_osd_release
= rel
;
8734 if (rel
>= CEPH_RELEASE_LUMINOUS
&&
8735 !osdmap
.test_flag(CEPH_OSDMAP_RECOVERY_DELETES
)) {
8736 return prepare_set_flag(op
, CEPH_OSDMAP_RECOVERY_DELETES
);
8739 } else if (prefix
== "osd cluster_snap") {
8740 // ** DISABLE THIS FOR NOW **
8741 ss
<< "cluster snapshot currently disabled (broken implementation)";
8742 // ** DISABLE THIS FOR NOW **
8744 } else if (prefix
== "osd down" ||
8745 prefix
== "osd out" ||
8746 prefix
== "osd in" ||
8747 prefix
== "osd rm") {
8751 bool verbose
= true;
8753 vector
<string
> idvec
;
8754 cmd_getval(g_ceph_context
, cmdmap
, "ids", idvec
);
8755 for (unsigned j
= 0; j
< idvec
.size() && !stop
; j
++) {
8760 (idvec
[0] == "any" || idvec
[0] == "all" || idvec
[0] == "*")) {
8761 if (prefix
== "osd in") {
8762 // touch out osds only
8763 osdmap
.get_out_osds(osds
);
8765 osdmap
.get_all_osds(osds
);
8768 verbose
= false; // so the output is less noisy.
8770 long osd
= parse_osd_id(idvec
[j
].c_str(), &ss
);
8772 ss
<< "invalid osd id" << osd
;
8775 } else if (!osdmap
.exists(osd
)) {
8776 ss
<< "osd." << osd
<< " does not exist. ";
8783 for (auto &osd
: osds
) {
8784 if (prefix
== "osd down") {
8785 if (osdmap
.is_down(osd
)) {
8787 ss
<< "osd." << osd
<< " is already down. ";
8789 pending_inc
.pending_osd_state_set(osd
, CEPH_OSD_UP
);
8790 ss
<< "marked down osd." << osd
<< ". ";
8793 } else if (prefix
== "osd out") {
8794 if (osdmap
.is_out(osd
)) {
8796 ss
<< "osd." << osd
<< " is already out. ";
8798 pending_inc
.new_weight
[osd
] = CEPH_OSD_OUT
;
8799 if (osdmap
.osd_weight
[osd
]) {
8800 if (pending_inc
.new_xinfo
.count(osd
) == 0) {
8801 pending_inc
.new_xinfo
[osd
] = osdmap
.osd_xinfo
[osd
];
8803 pending_inc
.new_xinfo
[osd
].old_weight
= osdmap
.osd_weight
[osd
];
8805 ss
<< "marked out osd." << osd
<< ". ";
8806 std::ostringstream msg
;
8807 msg
<< "Client " << op
->get_session()->entity_name
8808 << " marked osd." << osd
<< " out";
8809 if (osdmap
.is_up(osd
)) {
8810 msg
<< ", while it was still marked up";
8812 msg
<< ", after it was down for " << int(down_pending_out
[osd
].sec())
8816 mon
->clog
->info() << msg
.str();
8819 } else if (prefix
== "osd in") {
8820 if (osdmap
.is_in(osd
)) {
8822 ss
<< "osd." << osd
<< " is already in. ";
8824 if (osdmap
.osd_xinfo
[osd
].old_weight
> 0) {
8825 pending_inc
.new_weight
[osd
] = osdmap
.osd_xinfo
[osd
].old_weight
;
8826 if (pending_inc
.new_xinfo
.count(osd
) == 0) {
8827 pending_inc
.new_xinfo
[osd
] = osdmap
.osd_xinfo
[osd
];
8829 pending_inc
.new_xinfo
[osd
].old_weight
= 0;
8831 pending_inc
.new_weight
[osd
] = CEPH_OSD_IN
;
8833 ss
<< "marked in osd." << osd
<< ". ";
8836 } else if (prefix
== "osd rm") {
8837 err
= prepare_command_osd_remove(osd
);
8839 if (err
== -EBUSY
) {
8842 ss
<< "osd." << osd
<< " is still up; must be down before removal. ";
8846 ss
<< ", osd." << osd
;
8848 ss
<< "removed osd." << osd
;
8857 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, err
, rs
,
8858 get_last_committed() + 1));
8861 } else if (prefix
== "osd add-noup" ||
8862 prefix
== "osd add-nodown" ||
8863 prefix
== "osd add-noin" ||
8864 prefix
== "osd add-noout") {
8873 if (prefix
== "osd add-noup") {
8875 } else if (prefix
== "osd add-nodown") {
8877 } else if (prefix
== "osd add-noin") {
8886 vector
<string
> idvec
;
8887 cmd_getval(g_ceph_context
, cmdmap
, "ids", idvec
);
8888 for (unsigned j
= 0; j
< idvec
.size() && !stop
; j
++) {
8894 (idvec
[0] == "any" || idvec
[0] == "all" || idvec
[0] == "*")) {
8895 osdmap
.get_all_osds(osds
);
8898 // try traditional single osd way
8900 long osd
= parse_osd_id(idvec
[j
].c_str(), &ss
);
8902 // ss has reason for failure
8903 ss
<< ", unable to parse osd id:\"" << idvec
[j
] << "\". ";
8911 for (auto &osd
: osds
) {
8913 if (!osdmap
.exists(osd
)) {
8914 ss
<< "osd." << osd
<< " does not exist. ";
8920 if (osdmap
.is_up(osd
)) {
8921 ss
<< "osd." << osd
<< " is already up. ";
8925 if (osdmap
.is_noup(osd
)) {
8926 if (pending_inc
.pending_osd_state_clear(osd
, CEPH_OSD_NOUP
))
8929 pending_inc
.pending_osd_state_set(osd
, CEPH_OSD_NOUP
);
8936 if (osdmap
.is_down(osd
)) {
8937 ss
<< "osd." << osd
<< " is already down. ";
8941 if (osdmap
.is_nodown(osd
)) {
8942 if (pending_inc
.pending_osd_state_clear(osd
, CEPH_OSD_NODOWN
))
8945 pending_inc
.pending_osd_state_set(osd
, CEPH_OSD_NODOWN
);
8952 if (osdmap
.is_in(osd
)) {
8953 ss
<< "osd." << osd
<< " is already in. ";
8957 if (osdmap
.is_noin(osd
)) {
8958 if (pending_inc
.pending_osd_state_clear(osd
, CEPH_OSD_NOIN
))
8961 pending_inc
.pending_osd_state_set(osd
, CEPH_OSD_NOIN
);
8968 if (osdmap
.is_out(osd
)) {
8969 ss
<< "osd." << osd
<< " is already out. ";
8973 if (osdmap
.is_noout(osd
)) {
8974 if (pending_inc
.pending_osd_state_clear(osd
, CEPH_OSD_NOOUT
))
8977 pending_inc
.pending_osd_state_set(osd
, CEPH_OSD_NOOUT
);
8984 assert(0 == "invalid option");
8991 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, err
, rs
,
8992 get_last_committed() + 1));
8995 } else if (prefix
== "osd rm-noup" ||
8996 prefix
== "osd rm-nodown" ||
8997 prefix
== "osd rm-noin" ||
8998 prefix
== "osd rm-noout") {
9007 if (prefix
== "osd rm-noup") {
9009 } else if (prefix
== "osd rm-nodown") {
9011 } else if (prefix
== "osd rm-noin") {
9020 vector
<string
> idvec
;
9021 cmd_getval(g_ceph_context
, cmdmap
, "ids", idvec
);
9023 for (unsigned j
= 0; j
< idvec
.size() && !stop
; j
++) {
9029 (idvec
[0] == "any" || idvec
[0] == "all" || idvec
[0] == "*")) {
9031 // touch previous noup/nodown/noin/noout osds only
9034 osdmap
.get_noup_osds(&osds
);
9037 osdmap
.get_nodown_osds(&osds
);
9040 osdmap
.get_noin_osds(&osds
);
9043 osdmap
.get_noout_osds(&osds
);
9046 assert(0 == "invalid option");
9049 // cancel any pending noup/nodown/noin/noout requests too
9050 vector
<int> pending_state_osds
;
9051 (void) pending_inc
.get_pending_state_osds(&pending_state_osds
);
9052 for (auto &p
: pending_state_osds
) {
9056 if (!osdmap
.is_noup(p
) &&
9057 pending_inc
.pending_osd_state_clear(p
, CEPH_OSD_NOUP
)) {
9063 if (!osdmap
.is_nodown(p
) &&
9064 pending_inc
.pending_osd_state_clear(p
, CEPH_OSD_NODOWN
)) {
9070 if (!osdmap
.is_noin(p
) &&
9071 pending_inc
.pending_osd_state_clear(p
, CEPH_OSD_NOIN
)) {
9077 if (!osdmap
.is_noout(p
) &&
9078 pending_inc
.pending_osd_state_clear(p
, CEPH_OSD_NOOUT
)) {
9084 assert(0 == "invalid option");
9090 // try traditional single osd way
9092 long osd
= parse_osd_id(idvec
[j
].c_str(), &ss
);
9094 // ss has reason for failure
9095 ss
<< ", unable to parse osd id:\"" << idvec
[j
] << "\". ";
9100 osds
.push_back(osd
);
9103 for (auto &osd
: osds
) {
9105 if (!osdmap
.exists(osd
)) {
9106 ss
<< "osd." << osd
<< " does not exist. ";
9112 if (osdmap
.is_noup(osd
)) {
9113 pending_inc
.pending_osd_state_set(osd
, CEPH_OSD_NOUP
);
9115 } else if (pending_inc
.pending_osd_state_clear(
9116 osd
, CEPH_OSD_NOUP
)) {
9122 if (osdmap
.is_nodown(osd
)) {
9123 pending_inc
.pending_osd_state_set(osd
, CEPH_OSD_NODOWN
);
9125 } else if (pending_inc
.pending_osd_state_clear(
9126 osd
, CEPH_OSD_NODOWN
)) {
9132 if (osdmap
.is_noin(osd
)) {
9133 pending_inc
.pending_osd_state_set(osd
, CEPH_OSD_NOIN
);
9135 } else if (pending_inc
.pending_osd_state_clear(
9136 osd
, CEPH_OSD_NOIN
)) {
9142 if (osdmap
.is_noout(osd
)) {
9143 pending_inc
.pending_osd_state_set(osd
, CEPH_OSD_NOOUT
);
9145 } else if (pending_inc
.pending_osd_state_clear(
9146 osd
, CEPH_OSD_NOOUT
)) {
9152 assert(0 == "invalid option");
9159 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, err
, rs
,
9160 get_last_committed() + 1));
9163 } else if (prefix
== "osd pg-temp") {
9165 if (!cmd_getval(g_ceph_context
, cmdmap
, "pgid", pgidstr
)) {
9166 ss
<< "unable to parse 'pgid' value '"
9167 << cmd_vartype_stringify(cmdmap
["pgid"]) << "'";
9172 if (!pgid
.parse(pgidstr
.c_str())) {
9173 ss
<< "invalid pgid '" << pgidstr
<< "'";
9177 if (!osdmap
.pg_exists(pgid
)) {
9178 ss
<< "pg " << pgid
<< " does not exist";
9182 if (pending_inc
.new_pg_temp
.count(pgid
)) {
9183 dout(10) << __func__
<< " waiting for pending update on " << pgid
<< dendl
;
9184 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
9188 vector
<int64_t> id_vec
;
9189 vector
<int32_t> new_pg_temp
;
9190 if (!cmd_getval(g_ceph_context
, cmdmap
, "id", id_vec
)) {
9191 ss
<< "unable to parse 'id' value(s) '"
9192 << cmd_vartype_stringify(cmdmap
["id"]) << "'";
9196 for (auto osd
: id_vec
) {
9197 if (!osdmap
.exists(osd
)) {
9198 ss
<< "osd." << osd
<< " does not exist";
9202 new_pg_temp
.push_back(osd
);
9205 int pool_min_size
= osdmap
.get_pg_pool_min_size(pgid
);
9206 if ((int)new_pg_temp
.size() < pool_min_size
) {
9207 ss
<< "num of osds (" << new_pg_temp
.size() <<") < pool min size ("
9208 << pool_min_size
<< ")";
9213 int pool_size
= osdmap
.get_pg_pool_size(pgid
);
9214 if ((int)new_pg_temp
.size() > pool_size
) {
9215 ss
<< "num of osds (" << new_pg_temp
.size() <<") > pool size ("
9216 << pool_size
<< ")";
9221 pending_inc
.new_pg_temp
[pgid
] = mempool::osdmap::vector
<int>(
9222 new_pg_temp
.begin(), new_pg_temp
.end());
9223 ss
<< "set " << pgid
<< " pg_temp mapping to " << new_pg_temp
;
9225 } else if (prefix
== "osd primary-temp") {
9227 if (!cmd_getval(g_ceph_context
, cmdmap
, "pgid", pgidstr
)) {
9228 ss
<< "unable to parse 'pgid' value '"
9229 << cmd_vartype_stringify(cmdmap
["pgid"]) << "'";
9234 if (!pgid
.parse(pgidstr
.c_str())) {
9235 ss
<< "invalid pgid '" << pgidstr
<< "'";
9239 if (!osdmap
.pg_exists(pgid
)) {
9240 ss
<< "pg " << pgid
<< " does not exist";
9246 if (!cmd_getval(g_ceph_context
, cmdmap
, "id", osd
)) {
9247 ss
<< "unable to parse 'id' value '"
9248 << cmd_vartype_stringify(cmdmap
["id"]) << "'";
9252 if (osd
!= -1 && !osdmap
.exists(osd
)) {
9253 ss
<< "osd." << osd
<< " does not exist";
9258 if (osdmap
.require_min_compat_client
> 0 &&
9259 osdmap
.require_min_compat_client
< CEPH_RELEASE_FIREFLY
) {
9260 ss
<< "require_min_compat_client "
9261 << ceph_release_name(osdmap
.require_min_compat_client
)
9262 << " < firefly, which is required for primary-temp";
9265 } else if (!g_conf
->mon_osd_allow_primary_temp
) {
9266 ss
<< "you must enable 'mon osd allow primary temp = true' on the mons before you can set primary_temp mappings. note that this is for developers only: older clients/OSDs will break and there is no feature bit infrastructure in place.";
9271 pending_inc
.new_primary_temp
[pgid
] = osd
;
9272 ss
<< "set " << pgid
<< " primary_temp mapping to " << osd
;
9274 } else if (prefix
== "osd pg-upmap" ||
9275 prefix
== "osd rm-pg-upmap" ||
9276 prefix
== "osd pg-upmap-items" ||
9277 prefix
== "osd rm-pg-upmap-items") {
9278 if (osdmap
.require_osd_release
< CEPH_RELEASE_LUMINOUS
) {
9279 ss
<< "you must complete the upgrade and 'ceph osd require-osd-release "
9280 << "luminous' before using the new interface";
9284 if (osdmap
.require_min_compat_client
< CEPH_RELEASE_LUMINOUS
) {
9285 ss
<< "min_compat_client "
9286 << ceph_release_name(osdmap
.require_min_compat_client
)
9287 << " < luminous, which is required for pg-upmap. "
9288 << "Try 'ceph osd set-require-min-compat-client luminous' "
9289 << "before using the new interface";
9293 err
= check_cluster_features(CEPH_FEATUREMASK_OSDMAP_PG_UPMAP
, ss
);
9299 if (!cmd_getval(g_ceph_context
, cmdmap
, "pgid", pgidstr
)) {
9300 ss
<< "unable to parse 'pgid' value '"
9301 << cmd_vartype_stringify(cmdmap
["pgid"]) << "'";
9306 if (!pgid
.parse(pgidstr
.c_str())) {
9307 ss
<< "invalid pgid '" << pgidstr
<< "'";
9311 if (!osdmap
.pg_exists(pgid
)) {
9312 ss
<< "pg " << pgid
<< " does not exist";
9321 OP_RM_PG_UPMAP_ITEMS
,
9324 if (prefix
== "osd pg-upmap") {
9325 option
= OP_PG_UPMAP
;
9326 } else if (prefix
== "osd rm-pg-upmap") {
9327 option
= OP_RM_PG_UPMAP
;
9328 } else if (prefix
== "osd pg-upmap-items") {
9329 option
= OP_PG_UPMAP_ITEMS
;
9331 option
= OP_RM_PG_UPMAP_ITEMS
;
9334 // check pending upmap changes
9336 case OP_PG_UPMAP
: // fall through
9337 case OP_RM_PG_UPMAP
:
9338 if (pending_inc
.new_pg_upmap
.count(pgid
) ||
9339 pending_inc
.old_pg_upmap
.count(pgid
)) {
9340 dout(10) << __func__
<< " waiting for pending update on "
9342 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
9347 case OP_PG_UPMAP_ITEMS
: // fall through
9348 case OP_RM_PG_UPMAP_ITEMS
:
9349 if (pending_inc
.new_pg_upmap_items
.count(pgid
) ||
9350 pending_inc
.old_pg_upmap_items
.count(pgid
)) {
9351 dout(10) << __func__
<< " waiting for pending update on "
9353 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
9359 assert(0 == "invalid option");
9365 vector
<int64_t> id_vec
;
9366 if (!cmd_getval(g_ceph_context
, cmdmap
, "id", id_vec
)) {
9367 ss
<< "unable to parse 'id' value(s) '"
9368 << cmd_vartype_stringify(cmdmap
["id"]) << "'";
9373 int pool_min_size
= osdmap
.get_pg_pool_min_size(pgid
);
9374 if ((int)id_vec
.size() < pool_min_size
) {
9375 ss
<< "num of osds (" << id_vec
.size() <<") < pool min size ("
9376 << pool_min_size
<< ")";
9381 int pool_size
= osdmap
.get_pg_pool_size(pgid
);
9382 if ((int)id_vec
.size() > pool_size
) {
9383 ss
<< "num of osds (" << id_vec
.size() <<") > pool size ("
9384 << pool_size
<< ")";
9389 vector
<int32_t> new_pg_upmap
;
9390 for (auto osd
: id_vec
) {
9391 if (osd
!= CRUSH_ITEM_NONE
&& !osdmap
.exists(osd
)) {
9392 ss
<< "osd." << osd
<< " does not exist";
9396 auto it
= std::find(new_pg_upmap
.begin(), new_pg_upmap
.end(), osd
);
9397 if (it
!= new_pg_upmap
.end()) {
9398 ss
<< "osd." << osd
<< " already exists, ";
9401 new_pg_upmap
.push_back(osd
);
9404 if (new_pg_upmap
.empty()) {
9405 ss
<< "no valid upmap items(pairs) is specified";
9410 pending_inc
.new_pg_upmap
[pgid
] = mempool::osdmap::vector
<int32_t>(
9411 new_pg_upmap
.begin(), new_pg_upmap
.end());
9412 ss
<< "set " << pgid
<< " pg_upmap mapping to " << new_pg_upmap
;
9416 case OP_RM_PG_UPMAP
:
9418 pending_inc
.old_pg_upmap
.insert(pgid
);
9419 ss
<< "clear " << pgid
<< " pg_upmap mapping";
9423 case OP_PG_UPMAP_ITEMS
:
9425 vector
<int64_t> id_vec
;
9426 if (!cmd_getval(g_ceph_context
, cmdmap
, "id", id_vec
)) {
9427 ss
<< "unable to parse 'id' value(s) '"
9428 << cmd_vartype_stringify(cmdmap
["id"]) << "'";
9433 if (id_vec
.size() % 2) {
9434 ss
<< "you must specify pairs of osd ids to be remapped";
9439 int pool_size
= osdmap
.get_pg_pool_size(pgid
);
9440 if ((int)(id_vec
.size() / 2) > pool_size
) {
9441 ss
<< "num of osd pairs (" << id_vec
.size() / 2 <<") > pool size ("
9442 << pool_size
<< ")";
9447 vector
<pair
<int32_t,int32_t>> new_pg_upmap_items
;
9448 ostringstream items
;
9450 for (auto p
= id_vec
.begin(); p
!= id_vec
.end(); ++p
) {
9454 ss
<< "from osd." << from
<< " == to osd." << to
<< ", ";
9457 if (!osdmap
.exists(from
)) {
9458 ss
<< "osd." << from
<< " does not exist";
9462 if (to
!= CRUSH_ITEM_NONE
&& !osdmap
.exists(to
)) {
9463 ss
<< "osd." << to
<< " does not exist";
9467 pair
<int32_t,int32_t> entry
= make_pair(from
, to
);
9468 auto it
= std::find(new_pg_upmap_items
.begin(),
9469 new_pg_upmap_items
.end(), entry
);
9470 if (it
!= new_pg_upmap_items
.end()) {
9471 ss
<< "osd." << from
<< " -> osd." << to
<< " already exists, ";
9474 new_pg_upmap_items
.push_back(entry
);
9475 items
<< from
<< "->" << to
<< ",";
9477 string
out(items
.str());
9478 out
.resize(out
.size() - 1); // drop last ','
9481 if (new_pg_upmap_items
.empty()) {
9482 ss
<< "no valid upmap items(pairs) is specified";
9487 pending_inc
.new_pg_upmap_items
[pgid
] =
9488 mempool::osdmap::vector
<pair
<int32_t,int32_t>>(
9489 new_pg_upmap_items
.begin(), new_pg_upmap_items
.end());
9490 ss
<< "set " << pgid
<< " pg_upmap_items mapping to " << out
;
9494 case OP_RM_PG_UPMAP_ITEMS
:
9496 pending_inc
.old_pg_upmap_items
.insert(pgid
);
9497 ss
<< "clear " << pgid
<< " pg_upmap_items mapping";
9502 assert(0 == "invalid option");
9506 } else if (prefix
== "osd primary-affinity") {
9508 if (!cmd_getval(g_ceph_context
, cmdmap
, "id", id
)) {
9509 ss
<< "invalid osd id value '"
9510 << cmd_vartype_stringify(cmdmap
["id"]) << "'";
9515 if (!cmd_getval(g_ceph_context
, cmdmap
, "weight", w
)) {
9516 ss
<< "unable to parse 'weight' value '"
9517 << cmd_vartype_stringify(cmdmap
["weight"]) << "'";
9521 long ww
= (int)((double)CEPH_OSD_MAX_PRIMARY_AFFINITY
*w
);
9523 ss
<< "weight must be >= 0";
9527 if (osdmap
.require_min_compat_client
> 0 &&
9528 osdmap
.require_min_compat_client
< CEPH_RELEASE_FIREFLY
) {
9529 ss
<< "require_min_compat_client "
9530 << ceph_release_name(osdmap
.require_min_compat_client
)
9531 << " < firefly, which is required for primary-affinity";
9534 } else if (!g_conf
->mon_osd_allow_primary_affinity
) {
9535 ss
<< "you must enable 'mon osd allow primary affinity = true' on the mons before you can adjust primary-affinity. note that older clients will no longer be able to communicate with the cluster.";
9539 err
= check_cluster_features(CEPH_FEATURE_OSD_PRIMARY_AFFINITY
, ss
);
9544 if (osdmap
.exists(id
)) {
9545 pending_inc
.new_primary_affinity
[id
] = ww
;
9546 ss
<< "set osd." << id
<< " primary-affinity to " << w
<< " (" << ios::hex
<< ww
<< ios::dec
<< ")";
9548 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
9549 get_last_committed() + 1));
9552 ss
<< "osd." << id
<< " does not exist";
9556 } else if (prefix
== "osd reweight") {
9558 if (!cmd_getval(g_ceph_context
, cmdmap
, "id", id
)) {
9559 ss
<< "unable to parse osd id value '"
9560 << cmd_vartype_stringify(cmdmap
["id"]) << "'";
9565 if (!cmd_getval(g_ceph_context
, cmdmap
, "weight", w
)) {
9566 ss
<< "unable to parse weight value '"
9567 << cmd_vartype_stringify(cmdmap
["weight"]) << "'";
9571 long ww
= (int)((double)CEPH_OSD_IN
*w
);
9573 ss
<< "weight must be >= 0";
9577 if (osdmap
.exists(id
)) {
9578 pending_inc
.new_weight
[id
] = ww
;
9579 ss
<< "reweighted osd." << id
<< " to " << w
<< " (" << std::hex
<< ww
<< std::dec
<< ")";
9581 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
9582 get_last_committed() + 1));
9585 ss
<< "osd." << id
<< " does not exist";
9589 } else if (prefix
== "osd reweightn") {
9590 map
<int32_t, uint32_t> weights
;
9591 err
= parse_reweights(g_ceph_context
, cmdmap
, osdmap
, &weights
);
9593 ss
<< "unable to parse 'weights' value '"
9594 << cmd_vartype_stringify(cmdmap
["weights"]) << "'";
9597 pending_inc
.new_weight
.insert(weights
.begin(), weights
.end());
9598 wait_for_finished_proposal(
9600 new Monitor::C_Command(mon
, op
, 0, rs
, rdata
, get_last_committed() + 1));
9602 } else if (prefix
== "osd lost") {
9604 if (!cmd_getval(g_ceph_context
, cmdmap
, "id", id
)) {
9605 ss
<< "unable to parse osd id value '"
9606 << cmd_vartype_stringify(cmdmap
["id"]) << "'";
9611 if (!cmd_getval(g_ceph_context
, cmdmap
, "sure", sure
) || sure
!= "--yes-i-really-mean-it") {
9612 ss
<< "are you SURE? this might mean real, permanent data loss. pass "
9613 "--yes-i-really-mean-it if you really do.";
9616 } else if (!osdmap
.exists(id
)) {
9617 ss
<< "osd." << id
<< " does not exist";
9620 } else if (!osdmap
.is_down(id
)) {
9621 ss
<< "osd." << id
<< " is not down";
9625 epoch_t e
= osdmap
.get_info(id
).down_at
;
9626 pending_inc
.new_lost
[id
] = e
;
9627 ss
<< "marked osd lost in epoch " << e
;
9629 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
9630 get_last_committed() + 1));
9634 } else if (prefix
== "osd destroy" || prefix
== "osd purge") {
9635 /* Destroying an OSD means that we don't expect to further make use of
9636 * the OSDs data (which may even become unreadable after this operation),
9637 * and that we are okay with scrubbing all its cephx keys and config-key
9638 * data (which may include lockbox keys, thus rendering the osd's data
9641 * The OSD will not be removed. Instead, we will mark it as destroyed,
9642 * such that a subsequent call to `create` will not reuse the osd id.
9643 * This will play into being able to recreate the OSD, at the same
9644 * crush location, with minimal data movement.
9647 // make sure authmon is writeable.
9648 if (!mon
->authmon()->is_writeable()) {
9649 dout(10) << __func__
<< " waiting for auth mon to be writeable for "
9650 << "osd destroy" << dendl
;
9651 mon
->authmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
9656 if (!cmd_getval(g_ceph_context
, cmdmap
, "id", id
)) {
9657 ss
<< "unable to parse osd id value '"
9658 << cmd_vartype_stringify(cmdmap
["id"]) << "";
9663 bool is_destroy
= (prefix
== "osd destroy");
9665 assert("osd purge" == prefix
);
9669 if (!cmd_getval(g_ceph_context
, cmdmap
, "sure", sure
) ||
9670 sure
!= "--yes-i-really-mean-it") {
9671 ss
<< "Are you SURE? This will mean real, permanent data loss, as well "
9672 << "as cephx and lockbox keys. Pass --yes-i-really-mean-it if you "
9676 } else if (!osdmap
.exists(id
)) {
9677 ss
<< "osd." << id
<< " does not exist";
9678 err
= 0; // idempotent
9680 } else if (osdmap
.is_up(id
)) {
9681 ss
<< "osd." << id
<< " is not `down`.";
9684 } else if (is_destroy
&& osdmap
.is_destroyed(id
)) {
9685 ss
<< "destroyed osd." << id
;
9690 bool goto_reply
= false;
9694 err
= prepare_command_osd_destroy(id
, ss
);
9695 // we checked above that it should exist.
9696 assert(err
!= -ENOENT
);
9698 err
= prepare_command_osd_purge(id
, ss
);
9699 if (err
== -ENOENT
) {
9701 ss
<< "osd." << id
<< " does not exist.";
9707 if (err
< 0 || goto_reply
) {
9712 ss
<< "destroyed osd." << id
;
9714 ss
<< "purged osd." << id
;
9718 wait_for_finished_proposal(op
,
9719 new Monitor::C_Command(mon
, op
, 0, rs
, get_last_committed() + 1));
9720 force_immediate_propose();
9723 } else if (prefix
== "osd new") {
9725 // make sure authmon is writeable.
9726 if (!mon
->authmon()->is_writeable()) {
9727 dout(10) << __func__
<< " waiting for auth mon to be writeable for "
9728 << "osd new" << dendl
;
9729 mon
->authmon()->wait_for_writeable(op
, new C_RetryMessage(this, op
));
9733 map
<string
,string
> secrets_map
;
9735 bufferlist bl
= m
->get_data();
9736 string secrets_json
= bl
.to_str();
9737 dout(20) << __func__
<< " osd new json = " << secrets_json
<< dendl
;
9739 err
= get_json_str_map(secrets_json
, ss
, &secrets_map
);
9743 dout(20) << __func__
<< " osd new secrets " << secrets_map
<< dendl
;
9746 err
= prepare_command_osd_new(op
, cmdmap
, secrets_map
, ss
, f
.get());
9759 if (err
== EEXIST
) {
9760 // idempotent operation
9765 wait_for_finished_proposal(op
,
9766 new Monitor::C_Command(mon
, op
, 0, rs
, rdata
,
9767 get_last_committed() + 1));
9768 force_immediate_propose();
9771 } else if (prefix
== "osd create") {
9773 // optional id provided?
9774 int64_t id
= -1, cmd_id
= -1;
9775 if (cmd_getval(g_ceph_context
, cmdmap
, "id", cmd_id
)) {
9777 ss
<< "invalid osd id value '" << cmd_id
<< "'";
9781 dout(10) << " osd create got id " << cmd_id
<< dendl
;
9786 if (cmd_getval(g_ceph_context
, cmdmap
, "uuid", uuidstr
)) {
9787 if (!uuid
.parse(uuidstr
.c_str())) {
9788 ss
<< "invalid uuid value '" << uuidstr
<< "'";
9792 // we only care about the id if we also have the uuid, to
9793 // ensure the operation's idempotency.
9797 int32_t new_id
= -1;
9798 err
= prepare_command_osd_create(id
, uuid
, &new_id
, ss
);
9800 if (err
== -EAGAIN
) {
9801 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
9804 // a check has failed; reply to the user.
9807 } else if (err
== EEXIST
) {
9808 // this is an idempotent operation; we can go ahead and reply.
9810 f
->open_object_section("created_osd");
9811 f
->dump_int("osdid", new_id
);
9822 do_osd_create(id
, uuid
, &new_id
);
9825 f
->open_object_section("created_osd");
9826 f
->dump_int("osdid", new_id
);
9833 wait_for_finished_proposal(op
,
9834 new Monitor::C_Command(mon
, op
, 0, rs
, rdata
,
9835 get_last_committed() + 1));
9838 } else if (prefix
== "osd blacklist clear") {
9839 pending_inc
.new_blacklist
.clear();
9840 std::list
<std::pair
<entity_addr_t
,utime_t
> > blacklist
;
9841 osdmap
.get_blacklist(&blacklist
);
9842 for (const auto &entry
: blacklist
) {
9843 pending_inc
.old_blacklist
.push_back(entry
.first
);
9845 ss
<< " removed all blacklist entries";
9847 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
9848 get_last_committed() + 1));
9850 } else if (prefix
== "osd blacklist") {
9852 cmd_getval(g_ceph_context
, cmdmap
, "addr", addrstr
);
9854 if (!addr
.parse(addrstr
.c_str(), 0)) {
9855 ss
<< "unable to parse address " << addrstr
;
9861 cmd_getval(g_ceph_context
, cmdmap
, "blacklistop", blacklistop
);
9862 if (blacklistop
== "add") {
9863 utime_t expires
= ceph_clock_now();
9866 cmd_getval(g_ceph_context
, cmdmap
, "expire", d
,
9867 g_conf
->mon_osd_blacklist_default_expire
);
9870 pending_inc
.new_blacklist
[addr
] = expires
;
9873 // cancel any pending un-blacklisting request too
9874 auto it
= std::find(pending_inc
.old_blacklist
.begin(),
9875 pending_inc
.old_blacklist
.end(), addr
);
9876 if (it
!= pending_inc
.old_blacklist
.end()) {
9877 pending_inc
.old_blacklist
.erase(it
);
9881 ss
<< "blacklisting " << addr
<< " until " << expires
<< " (" << d
<< " sec)";
9883 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
9884 get_last_committed() + 1));
9886 } else if (blacklistop
== "rm") {
9887 if (osdmap
.is_blacklisted(addr
) ||
9888 pending_inc
.new_blacklist
.count(addr
)) {
9889 if (osdmap
.is_blacklisted(addr
))
9890 pending_inc
.old_blacklist
.push_back(addr
);
9892 pending_inc
.new_blacklist
.erase(addr
);
9893 ss
<< "un-blacklisting " << addr
;
9895 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
9896 get_last_committed() + 1));
9899 ss
<< addr
<< " isn't blacklisted";
9904 } else if (prefix
== "osd pool mksnap") {
9906 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
9907 int64_t pool
= osdmap
.lookup_pg_pool_name(poolstr
.c_str());
9909 ss
<< "unrecognized pool '" << poolstr
<< "'";
9914 cmd_getval(g_ceph_context
, cmdmap
, "snap", snapname
);
9915 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool
);
9916 if (p
->is_unmanaged_snaps_mode()) {
9917 ss
<< "pool " << poolstr
<< " is in unmanaged snaps mode";
9920 } else if (p
->snap_exists(snapname
.c_str())) {
9921 ss
<< "pool " << poolstr
<< " snap " << snapname
<< " already exists";
9924 } else if (p
->is_tier()) {
9925 ss
<< "pool " << poolstr
<< " is a cache tier";
9930 if (pending_inc
.new_pools
.count(pool
))
9931 pp
= &pending_inc
.new_pools
[pool
];
9933 pp
= &pending_inc
.new_pools
[pool
];
9936 if (pp
->snap_exists(snapname
.c_str())) {
9937 ss
<< "pool " << poolstr
<< " snap " << snapname
<< " already exists";
9939 pp
->add_snap(snapname
.c_str(), ceph_clock_now());
9940 pp
->set_snap_epoch(pending_inc
.epoch
);
9941 ss
<< "created pool " << poolstr
<< " snap " << snapname
;
9944 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
9945 get_last_committed() + 1));
9947 } else if (prefix
== "osd pool rmsnap") {
9949 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
9950 int64_t pool
= osdmap
.lookup_pg_pool_name(poolstr
.c_str());
9952 ss
<< "unrecognized pool '" << poolstr
<< "'";
9957 cmd_getval(g_ceph_context
, cmdmap
, "snap", snapname
);
9958 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool
);
9959 if (p
->is_unmanaged_snaps_mode()) {
9960 ss
<< "pool " << poolstr
<< " is in unmanaged snaps mode";
9963 } else if (!p
->snap_exists(snapname
.c_str())) {
9964 ss
<< "pool " << poolstr
<< " snap " << snapname
<< " does not exist";
9969 if (pending_inc
.new_pools
.count(pool
))
9970 pp
= &pending_inc
.new_pools
[pool
];
9972 pp
= &pending_inc
.new_pools
[pool
];
9975 snapid_t sn
= pp
->snap_exists(snapname
.c_str());
9977 pp
->remove_snap(sn
);
9978 pp
->set_snap_epoch(pending_inc
.epoch
);
9979 ss
<< "removed pool " << poolstr
<< " snap " << snapname
;
9981 ss
<< "already removed pool " << poolstr
<< " snap " << snapname
;
9984 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
9985 get_last_committed() + 1));
9987 } else if (prefix
== "osd pool create") {
9990 cmd_getval(g_ceph_context
, cmdmap
, "pg_num", pg_num
, int64_t(0));
9991 cmd_getval(g_ceph_context
, cmdmap
, "pgp_num", pgp_num
, pg_num
);
9993 string pool_type_str
;
9994 cmd_getval(g_ceph_context
, cmdmap
, "pool_type", pool_type_str
);
9995 if (pool_type_str
.empty())
9996 pool_type_str
= g_conf
->osd_pool_default_type
;
9999 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
10000 int64_t pool_id
= osdmap
.lookup_pg_pool_name(poolstr
);
10001 if (pool_id
>= 0) {
10002 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool_id
);
10003 if (pool_type_str
!= p
->get_type_name()) {
10004 ss
<< "pool '" << poolstr
<< "' cannot change to type " << pool_type_str
;
10007 ss
<< "pool '" << poolstr
<< "' already exists";
10014 if (pool_type_str
== "replicated") {
10015 pool_type
= pg_pool_t::TYPE_REPLICATED
;
10016 } else if (pool_type_str
== "erasure") {
10017 err
= check_cluster_features(CEPH_FEATURE_CRUSH_V2
|
10018 CEPH_FEATURE_OSD_ERASURE_CODES
,
10020 if (err
== -EAGAIN
)
10024 pool_type
= pg_pool_t::TYPE_ERASURE
;
10026 ss
<< "unknown pool type '" << pool_type_str
<< "'";
10031 bool implicit_rule_creation
= false;
10033 cmd_getval(g_ceph_context
, cmdmap
, "rule", rule_name
);
10034 string erasure_code_profile
;
10035 cmd_getval(g_ceph_context
, cmdmap
, "erasure_code_profile", erasure_code_profile
);
10037 if (pool_type
== pg_pool_t::TYPE_ERASURE
) {
10038 if (erasure_code_profile
== "")
10039 erasure_code_profile
= "default";
10040 //handle the erasure code profile
10041 if (erasure_code_profile
== "default") {
10042 if (!osdmap
.has_erasure_code_profile(erasure_code_profile
)) {
10043 if (pending_inc
.has_erasure_code_profile(erasure_code_profile
)) {
10044 dout(20) << "erasure code profile " << erasure_code_profile
<< " already pending" << dendl
;
10048 map
<string
,string
> profile_map
;
10049 err
= osdmap
.get_erasure_code_profile_default(g_ceph_context
,
10054 dout(20) << "erasure code profile " << erasure_code_profile
<< " set" << dendl
;
10055 pending_inc
.set_erasure_code_profile(erasure_code_profile
, profile_map
);
10059 if (rule_name
== "") {
10060 implicit_rule_creation
= true;
10061 if (erasure_code_profile
== "default") {
10062 rule_name
= "erasure-code";
10064 dout(1) << "implicitly use rule named after the pool: "
10065 << poolstr
<< dendl
;
10066 rule_name
= poolstr
;
10070 //NOTE:for replicated pool,cmd_map will put rule_name to erasure_code_profile field
10071 rule_name
= erasure_code_profile
;
10074 if (!implicit_rule_creation
&& rule_name
!= "") {
10076 err
= get_crush_rule(rule_name
, &rule
, &ss
);
10077 if (err
== -EAGAIN
) {
10078 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
10085 int64_t expected_num_objects
;
10086 cmd_getval(g_ceph_context
, cmdmap
, "expected_num_objects", expected_num_objects
, int64_t(0));
10087 if (expected_num_objects
< 0) {
10088 ss
<< "'expected_num_objects' must be non-negative";
10093 int64_t fast_read_param
;
10094 cmd_getval(g_ceph_context
, cmdmap
, "fast_read", fast_read_param
, int64_t(-1));
10095 FastReadType fast_read
= FAST_READ_DEFAULT
;
10096 if (fast_read_param
== 0)
10097 fast_read
= FAST_READ_OFF
;
10098 else if (fast_read_param
> 0)
10099 fast_read
= FAST_READ_ON
;
10101 err
= prepare_new_pool(poolstr
, 0, // auid=0 for admin created pool
10102 -1, // default crush rule
10105 erasure_code_profile
, pool_type
,
10106 (uint64_t)expected_num_objects
,
10112 ss
<< "pool '" << poolstr
<< "' already exists";
10115 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
10124 ss
<< "pool '" << poolstr
<< "' created";
10127 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
10128 get_last_committed() + 1));
10131 } else if (prefix
== "osd pool delete" ||
10132 prefix
== "osd pool rm") {
10133 // osd pool delete/rm <poolname> <poolname again> --yes-i-really-really-mean-it
10134 string poolstr
, poolstr2
, sure
;
10135 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
10136 cmd_getval(g_ceph_context
, cmdmap
, "pool2", poolstr2
);
10137 cmd_getval(g_ceph_context
, cmdmap
, "sure", sure
);
10138 int64_t pool
= osdmap
.lookup_pg_pool_name(poolstr
.c_str());
10140 ss
<< "pool '" << poolstr
<< "' does not exist";
10145 bool force_no_fake
= sure
== "--yes-i-really-really-mean-it-not-faking";
10146 if (poolstr2
!= poolstr
||
10147 (sure
!= "--yes-i-really-really-mean-it" && !force_no_fake
)) {
10148 ss
<< "WARNING: this will *PERMANENTLY DESTROY* all data stored in pool " << poolstr
10149 << ". If you are *ABSOLUTELY CERTAIN* that is what you want, pass the pool name *twice*, "
10150 << "followed by --yes-i-really-really-mean-it.";
10154 err
= _prepare_remove_pool(pool
, &ss
, force_no_fake
);
10155 if (err
== -EAGAIN
) {
10156 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
10162 } else if (prefix
== "osd pool rename") {
10163 string srcpoolstr
, destpoolstr
;
10164 cmd_getval(g_ceph_context
, cmdmap
, "srcpool", srcpoolstr
);
10165 cmd_getval(g_ceph_context
, cmdmap
, "destpool", destpoolstr
);
10166 int64_t pool_src
= osdmap
.lookup_pg_pool_name(srcpoolstr
.c_str());
10167 int64_t pool_dst
= osdmap
.lookup_pg_pool_name(destpoolstr
.c_str());
10169 if (pool_src
< 0) {
10170 if (pool_dst
>= 0) {
10171 // src pool doesn't exist, dst pool does exist: to ensure idempotency
10172 // of operations, assume this rename succeeded, as it is not changing
10173 // the current state. Make sure we output something understandable
10174 // for whoever is issuing the command, if they are paying attention,
10175 // in case it was not intentional; or to avoid a "wtf?" and a bug
10176 // report in case it was intentional, while expecting a failure.
10177 ss
<< "pool '" << srcpoolstr
<< "' does not exist; pool '"
10178 << destpoolstr
<< "' does -- assuming successful rename";
10181 ss
<< "unrecognized pool '" << srcpoolstr
<< "'";
10185 } else if (pool_dst
>= 0) {
10186 // source pool exists and so does the destination pool
10187 ss
<< "pool '" << destpoolstr
<< "' already exists";
10192 int ret
= _prepare_rename_pool(pool_src
, destpoolstr
);
10194 ss
<< "pool '" << srcpoolstr
<< "' renamed to '" << destpoolstr
<< "'";
10196 ss
<< "failed to rename pool '" << srcpoolstr
<< "' to '" << destpoolstr
<< "': "
10197 << cpp_strerror(ret
);
10200 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, ret
, rs
,
10201 get_last_committed() + 1));
10204 } else if (prefix
== "osd pool set") {
10205 err
= prepare_command_pool_set(cmdmap
, ss
);
10206 if (err
== -EAGAIN
)
10212 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
10213 get_last_committed() + 1));
10215 } else if (prefix
== "osd tier add") {
10216 err
= check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL
, ss
);
10217 if (err
== -EAGAIN
)
10222 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
10223 int64_t pool_id
= osdmap
.lookup_pg_pool_name(poolstr
);
10225 ss
<< "unrecognized pool '" << poolstr
<< "'";
10229 string tierpoolstr
;
10230 cmd_getval(g_ceph_context
, cmdmap
, "tierpool", tierpoolstr
);
10231 int64_t tierpool_id
= osdmap
.lookup_pg_pool_name(tierpoolstr
);
10232 if (tierpool_id
< 0) {
10233 ss
<< "unrecognized pool '" << tierpoolstr
<< "'";
10237 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool_id
);
10239 const pg_pool_t
*tp
= osdmap
.get_pg_pool(tierpool_id
);
10242 if (!_check_become_tier(tierpool_id
, tp
, pool_id
, p
, &err
, &ss
)) {
10246 // make sure new tier is empty
10247 string force_nonempty
;
10248 cmd_getval(g_ceph_context
, cmdmap
, "force_nonempty", force_nonempty
);
10249 const pool_stat_t
*pstats
= mon
->pgservice
->get_pool_stat(tierpool_id
);
10250 if (pstats
&& pstats
->stats
.sum
.num_objects
!= 0 &&
10251 force_nonempty
!= "--force-nonempty") {
10252 ss
<< "tier pool '" << tierpoolstr
<< "' is not empty; --force-nonempty to force";
10256 if (tp
->ec_pool()) {
10257 ss
<< "tier pool '" << tierpoolstr
10258 << "' is an ec pool, which cannot be a tier";
10262 if ((!tp
->removed_snaps
.empty() || !tp
->snaps
.empty()) &&
10263 ((force_nonempty
!= "--force-nonempty") ||
10264 (!g_conf
->mon_debug_unsafe_allow_tier_with_nonempty_snaps
))) {
10265 ss
<< "tier pool '" << tierpoolstr
<< "' has snapshot state; it cannot be added as a tier without breaking the pool";
10270 pg_pool_t
*np
= pending_inc
.get_new_pool(pool_id
, p
);
10271 pg_pool_t
*ntp
= pending_inc
.get_new_pool(tierpool_id
, tp
);
10272 if (np
->tiers
.count(tierpool_id
) || ntp
->is_tier()) {
10273 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
10276 np
->tiers
.insert(tierpool_id
);
10277 np
->set_snap_epoch(pending_inc
.epoch
); // tier will update to our snap info
10278 ntp
->tier_of
= pool_id
;
10279 ss
<< "pool '" << tierpoolstr
<< "' is now (or already was) a tier of '" << poolstr
<< "'";
10280 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, ss
.str(),
10281 get_last_committed() + 1));
10283 } else if (prefix
== "osd tier remove" ||
10284 prefix
== "osd tier rm") {
10286 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
10287 int64_t pool_id
= osdmap
.lookup_pg_pool_name(poolstr
);
10289 ss
<< "unrecognized pool '" << poolstr
<< "'";
10293 string tierpoolstr
;
10294 cmd_getval(g_ceph_context
, cmdmap
, "tierpool", tierpoolstr
);
10295 int64_t tierpool_id
= osdmap
.lookup_pg_pool_name(tierpoolstr
);
10296 if (tierpool_id
< 0) {
10297 ss
<< "unrecognized pool '" << tierpoolstr
<< "'";
10301 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool_id
);
10303 const pg_pool_t
*tp
= osdmap
.get_pg_pool(tierpool_id
);
10306 if (!_check_remove_tier(pool_id
, p
, tp
, &err
, &ss
)) {
10310 if (p
->tiers
.count(tierpool_id
) == 0) {
10311 ss
<< "pool '" << tierpoolstr
<< "' is now (or already was) not a tier of '" << poolstr
<< "'";
10315 if (tp
->tier_of
!= pool_id
) {
10316 ss
<< "tier pool '" << tierpoolstr
<< "' is a tier of '"
10317 << osdmap
.get_pool_name(tp
->tier_of
) << "': "
10318 // be scary about it; this is an inconsistency and bells must go off
10319 << "THIS SHOULD NOT HAVE HAPPENED AT ALL";
10323 if (p
->read_tier
== tierpool_id
) {
10324 ss
<< "tier pool '" << tierpoolstr
<< "' is the overlay for '" << poolstr
<< "'; please remove-overlay first";
10329 pg_pool_t
*np
= pending_inc
.get_new_pool(pool_id
, p
);
10330 pg_pool_t
*ntp
= pending_inc
.get_new_pool(tierpool_id
, tp
);
10331 if (np
->tiers
.count(tierpool_id
) == 0 ||
10332 ntp
->tier_of
!= pool_id
||
10333 np
->read_tier
== tierpool_id
) {
10334 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
10337 np
->tiers
.erase(tierpool_id
);
10339 ss
<< "pool '" << tierpoolstr
<< "' is now (or already was) not a tier of '" << poolstr
<< "'";
10340 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, ss
.str(),
10341 get_last_committed() + 1));
10343 } else if (prefix
== "osd tier set-overlay") {
10344 err
= check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL
, ss
);
10345 if (err
== -EAGAIN
)
10350 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
10351 int64_t pool_id
= osdmap
.lookup_pg_pool_name(poolstr
);
10353 ss
<< "unrecognized pool '" << poolstr
<< "'";
10357 string overlaypoolstr
;
10358 cmd_getval(g_ceph_context
, cmdmap
, "overlaypool", overlaypoolstr
);
10359 int64_t overlaypool_id
= osdmap
.lookup_pg_pool_name(overlaypoolstr
);
10360 if (overlaypool_id
< 0) {
10361 ss
<< "unrecognized pool '" << overlaypoolstr
<< "'";
10365 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool_id
);
10367 const pg_pool_t
*overlay_p
= osdmap
.get_pg_pool(overlaypool_id
);
10369 if (p
->tiers
.count(overlaypool_id
) == 0) {
10370 ss
<< "tier pool '" << overlaypoolstr
<< "' is not a tier of '" << poolstr
<< "'";
10374 if (p
->read_tier
== overlaypool_id
) {
10376 ss
<< "overlay for '" << poolstr
<< "' is now (or already was) '" << overlaypoolstr
<< "'";
10379 if (p
->has_read_tier()) {
10380 ss
<< "pool '" << poolstr
<< "' has overlay '"
10381 << osdmap
.get_pool_name(p
->read_tier
)
10382 << "'; please remove-overlay first";
10388 pg_pool_t
*np
= pending_inc
.get_new_pool(pool_id
, p
);
10389 np
->read_tier
= overlaypool_id
;
10390 np
->write_tier
= overlaypool_id
;
10391 np
->set_last_force_op_resend(pending_inc
.epoch
);
10392 pg_pool_t
*noverlay_p
= pending_inc
.get_new_pool(overlaypool_id
, overlay_p
);
10393 noverlay_p
->set_last_force_op_resend(pending_inc
.epoch
);
10394 ss
<< "overlay for '" << poolstr
<< "' is now (or already was) '" << overlaypoolstr
<< "'";
10395 if (overlay_p
->cache_mode
== pg_pool_t::CACHEMODE_NONE
)
10396 ss
<<" (WARNING: overlay pool cache_mode is still NONE)";
10397 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, ss
.str(),
10398 get_last_committed() + 1));
10400 } else if (prefix
== "osd tier remove-overlay" ||
10401 prefix
== "osd tier rm-overlay") {
10403 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
10404 int64_t pool_id
= osdmap
.lookup_pg_pool_name(poolstr
);
10406 ss
<< "unrecognized pool '" << poolstr
<< "'";
10410 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool_id
);
10412 if (!p
->has_read_tier()) {
10414 ss
<< "there is now (or already was) no overlay for '" << poolstr
<< "'";
10418 if (!_check_remove_tier(pool_id
, p
, NULL
, &err
, &ss
)) {
10423 pg_pool_t
*np
= pending_inc
.get_new_pool(pool_id
, p
);
10424 if (np
->has_read_tier()) {
10425 const pg_pool_t
*op
= osdmap
.get_pg_pool(np
->read_tier
);
10426 pg_pool_t
*nop
= pending_inc
.get_new_pool(np
->read_tier
,op
);
10427 nop
->set_last_force_op_resend(pending_inc
.epoch
);
10429 if (np
->has_write_tier()) {
10430 const pg_pool_t
*op
= osdmap
.get_pg_pool(np
->write_tier
);
10431 pg_pool_t
*nop
= pending_inc
.get_new_pool(np
->write_tier
, op
);
10432 nop
->set_last_force_op_resend(pending_inc
.epoch
);
10434 np
->clear_read_tier();
10435 np
->clear_write_tier();
10436 np
->set_last_force_op_resend(pending_inc
.epoch
);
10437 ss
<< "there is now (or already was) no overlay for '" << poolstr
<< "'";
10438 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, ss
.str(),
10439 get_last_committed() + 1));
10441 } else if (prefix
== "osd tier cache-mode") {
10442 err
= check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL
, ss
);
10443 if (err
== -EAGAIN
)
10448 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
10449 int64_t pool_id
= osdmap
.lookup_pg_pool_name(poolstr
);
10451 ss
<< "unrecognized pool '" << poolstr
<< "'";
10455 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool_id
);
10457 if (!p
->is_tier()) {
10458 ss
<< "pool '" << poolstr
<< "' is not a tier";
10463 cmd_getval(g_ceph_context
, cmdmap
, "mode", modestr
);
10464 pg_pool_t::cache_mode_t mode
= pg_pool_t::get_cache_mode_from_str(modestr
);
10466 ss
<< "'" << modestr
<< "' is not a valid cache mode";
10472 cmd_getval(g_ceph_context
, cmdmap
, "sure", sure
);
10473 if ((mode
!= pg_pool_t::CACHEMODE_WRITEBACK
&&
10474 mode
!= pg_pool_t::CACHEMODE_NONE
&&
10475 mode
!= pg_pool_t::CACHEMODE_PROXY
&&
10476 mode
!= pg_pool_t::CACHEMODE_READPROXY
) &&
10477 sure
!= "--yes-i-really-mean-it") {
10478 ss
<< "'" << modestr
<< "' is not a well-supported cache mode and may "
10479 << "corrupt your data. pass --yes-i-really-mean-it to force.";
10484 // pool already has this cache-mode set and there are no pending changes
10485 if (p
->cache_mode
== mode
&&
10486 (pending_inc
.new_pools
.count(pool_id
) == 0 ||
10487 pending_inc
.new_pools
[pool_id
].cache_mode
== p
->cache_mode
)) {
10488 ss
<< "set cache-mode for pool '" << poolstr
<< "'"
10489 << " to " << pg_pool_t::get_cache_mode_name(mode
);
10494 /* Mode description:
10496 * none: No cache-mode defined
10497 * forward: Forward all reads and writes to base pool
10498 * writeback: Cache writes, promote reads from base pool
10499 * readonly: Forward writes to base pool
10500 * readforward: Writes are in writeback mode, Reads are in forward mode
10501 * proxy: Proxy all reads and writes to base pool
10502 * readproxy: Writes are in writeback mode, Reads are in proxy mode
10504 * Hence, these are the allowed transitions:
10507 * forward -> proxy || readforward || readproxy || writeback || any IF num_objects_dirty == 0
10508 * proxy -> forward || readforward || readproxy || writeback || any IF num_objects_dirty == 0
10509 * readforward -> forward || proxy || readproxy || writeback || any IF num_objects_dirty == 0
10510 * readproxy -> forward || proxy || readforward || writeback || any IF num_objects_dirty == 0
10511 * writeback -> readforward || readproxy || forward || proxy
10515 // We check if the transition is valid against the current pool mode, as
10516 // it is the only committed state thus far. We will blantly squash
10517 // whatever mode is on the pending state.
10519 if (p
->cache_mode
== pg_pool_t::CACHEMODE_WRITEBACK
&&
10520 (mode
!= pg_pool_t::CACHEMODE_FORWARD
&&
10521 mode
!= pg_pool_t::CACHEMODE_PROXY
&&
10522 mode
!= pg_pool_t::CACHEMODE_READFORWARD
&&
10523 mode
!= pg_pool_t::CACHEMODE_READPROXY
)) {
10524 ss
<< "unable to set cache-mode '" << pg_pool_t::get_cache_mode_name(mode
)
10525 << "' on a '" << pg_pool_t::get_cache_mode_name(p
->cache_mode
)
10526 << "' pool; only '"
10527 << pg_pool_t::get_cache_mode_name(pg_pool_t::CACHEMODE_FORWARD
)
10529 << pg_pool_t::get_cache_mode_name(pg_pool_t::CACHEMODE_PROXY
)
10531 << pg_pool_t::get_cache_mode_name(pg_pool_t::CACHEMODE_READFORWARD
)
10533 << pg_pool_t::get_cache_mode_name(pg_pool_t::CACHEMODE_READPROXY
)
10538 if ((p
->cache_mode
== pg_pool_t::CACHEMODE_READFORWARD
&&
10539 (mode
!= pg_pool_t::CACHEMODE_WRITEBACK
&&
10540 mode
!= pg_pool_t::CACHEMODE_FORWARD
&&
10541 mode
!= pg_pool_t::CACHEMODE_PROXY
&&
10542 mode
!= pg_pool_t::CACHEMODE_READPROXY
)) ||
10544 (p
->cache_mode
== pg_pool_t::CACHEMODE_READPROXY
&&
10545 (mode
!= pg_pool_t::CACHEMODE_WRITEBACK
&&
10546 mode
!= pg_pool_t::CACHEMODE_FORWARD
&&
10547 mode
!= pg_pool_t::CACHEMODE_READFORWARD
&&
10548 mode
!= pg_pool_t::CACHEMODE_PROXY
)) ||
10550 (p
->cache_mode
== pg_pool_t::CACHEMODE_PROXY
&&
10551 (mode
!= pg_pool_t::CACHEMODE_WRITEBACK
&&
10552 mode
!= pg_pool_t::CACHEMODE_FORWARD
&&
10553 mode
!= pg_pool_t::CACHEMODE_READFORWARD
&&
10554 mode
!= pg_pool_t::CACHEMODE_READPROXY
)) ||
10556 (p
->cache_mode
== pg_pool_t::CACHEMODE_FORWARD
&&
10557 (mode
!= pg_pool_t::CACHEMODE_WRITEBACK
&&
10558 mode
!= pg_pool_t::CACHEMODE_READFORWARD
&&
10559 mode
!= pg_pool_t::CACHEMODE_PROXY
&&
10560 mode
!= pg_pool_t::CACHEMODE_READPROXY
))) {
10562 const pool_stat_t
* pstats
=
10563 mon
->pgservice
->get_pool_stat(pool_id
);
10565 if (pstats
&& pstats
->stats
.sum
.num_objects_dirty
> 0) {
10566 ss
<< "unable to set cache-mode '"
10567 << pg_pool_t::get_cache_mode_name(mode
) << "' on pool '" << poolstr
10568 << "': dirty objects found";
10574 pg_pool_t
*np
= pending_inc
.get_new_pool(pool_id
, p
);
10575 np
->cache_mode
= mode
;
10576 // set this both when moving to and from cache_mode NONE. this is to
10577 // capture legacy pools that were set up before this flag existed.
10578 np
->flags
|= pg_pool_t::FLAG_INCOMPLETE_CLONES
;
10579 ss
<< "set cache-mode for pool '" << poolstr
10580 << "' to " << pg_pool_t::get_cache_mode_name(mode
);
10581 if (mode
== pg_pool_t::CACHEMODE_NONE
) {
10582 const pg_pool_t
*base_pool
= osdmap
.get_pg_pool(np
->tier_of
);
10584 if (base_pool
->read_tier
== pool_id
||
10585 base_pool
->write_tier
== pool_id
)
10586 ss
<<" (WARNING: pool is still configured as read or write tier)";
10588 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, ss
.str(),
10589 get_last_committed() + 1));
10591 } else if (prefix
== "osd tier add-cache") {
10592 err
= check_cluster_features(CEPH_FEATURE_OSD_CACHEPOOL
, ss
);
10593 if (err
== -EAGAIN
)
10598 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
10599 int64_t pool_id
= osdmap
.lookup_pg_pool_name(poolstr
);
10601 ss
<< "unrecognized pool '" << poolstr
<< "'";
10605 string tierpoolstr
;
10606 cmd_getval(g_ceph_context
, cmdmap
, "tierpool", tierpoolstr
);
10607 int64_t tierpool_id
= osdmap
.lookup_pg_pool_name(tierpoolstr
);
10608 if (tierpool_id
< 0) {
10609 ss
<< "unrecognized pool '" << tierpoolstr
<< "'";
10613 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool_id
);
10615 const pg_pool_t
*tp
= osdmap
.get_pg_pool(tierpool_id
);
10618 if (!_check_become_tier(tierpool_id
, tp
, pool_id
, p
, &err
, &ss
)) {
10623 if (!cmd_getval(g_ceph_context
, cmdmap
, "size", size
)) {
10624 ss
<< "unable to parse 'size' value '"
10625 << cmd_vartype_stringify(cmdmap
["size"]) << "'";
10629 // make sure new tier is empty
10630 const pool_stat_t
*pstats
=
10631 mon
->pgservice
->get_pool_stat(tierpool_id
);
10632 if (pstats
&& pstats
->stats
.sum
.num_objects
!= 0) {
10633 ss
<< "tier pool '" << tierpoolstr
<< "' is not empty";
10637 string modestr
= g_conf
->osd_tier_default_cache_mode
;
10638 pg_pool_t::cache_mode_t mode
= pg_pool_t::get_cache_mode_from_str(modestr
);
10640 ss
<< "osd tier cache default mode '" << modestr
<< "' is not a valid cache mode";
10644 HitSet::Params hsp
;
10645 if (g_conf
->osd_tier_default_cache_hit_set_type
== "bloom") {
10646 BloomHitSet::Params
*bsp
= new BloomHitSet::Params
;
10647 bsp
->set_fpp(g_conf
->osd_pool_default_hit_set_bloom_fpp
);
10648 hsp
= HitSet::Params(bsp
);
10649 } else if (g_conf
->osd_tier_default_cache_hit_set_type
== "explicit_hash") {
10650 hsp
= HitSet::Params(new ExplicitHashHitSet::Params
);
10652 else if (g_conf
->osd_tier_default_cache_hit_set_type
== "explicit_object") {
10653 hsp
= HitSet::Params(new ExplicitObjectHitSet::Params
);
10655 ss
<< "osd tier cache default hit set type '" <<
10656 g_conf
->osd_tier_default_cache_hit_set_type
<< "' is not a known type";
10661 pg_pool_t
*np
= pending_inc
.get_new_pool(pool_id
, p
);
10662 pg_pool_t
*ntp
= pending_inc
.get_new_pool(tierpool_id
, tp
);
10663 if (np
->tiers
.count(tierpool_id
) || ntp
->is_tier()) {
10664 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
10667 np
->tiers
.insert(tierpool_id
);
10668 np
->read_tier
= np
->write_tier
= tierpool_id
;
10669 np
->set_snap_epoch(pending_inc
.epoch
); // tier will update to our snap info
10670 np
->set_last_force_op_resend(pending_inc
.epoch
);
10671 ntp
->set_last_force_op_resend(pending_inc
.epoch
);
10672 ntp
->tier_of
= pool_id
;
10673 ntp
->cache_mode
= mode
;
10674 ntp
->hit_set_count
= g_conf
->osd_tier_default_cache_hit_set_count
;
10675 ntp
->hit_set_period
= g_conf
->osd_tier_default_cache_hit_set_period
;
10676 ntp
->min_read_recency_for_promote
= g_conf
->osd_tier_default_cache_min_read_recency_for_promote
;
10677 ntp
->min_write_recency_for_promote
= g_conf
->osd_tier_default_cache_min_write_recency_for_promote
;
10678 ntp
->hit_set_grade_decay_rate
= g_conf
->osd_tier_default_cache_hit_set_grade_decay_rate
;
10679 ntp
->hit_set_search_last_n
= g_conf
->osd_tier_default_cache_hit_set_search_last_n
;
10680 ntp
->hit_set_params
= hsp
;
10681 ntp
->target_max_bytes
= size
;
10682 ss
<< "pool '" << tierpoolstr
<< "' is now (or already was) a cache tier of '" << poolstr
<< "'";
10683 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, ss
.str(),
10684 get_last_committed() + 1));
10686 } else if (prefix
== "osd pool set-quota") {
10688 cmd_getval(g_ceph_context
, cmdmap
, "pool", poolstr
);
10689 int64_t pool_id
= osdmap
.lookup_pg_pool_name(poolstr
);
10691 ss
<< "unrecognized pool '" << poolstr
<< "'";
10697 cmd_getval(g_ceph_context
, cmdmap
, "field", field
);
10698 if (field
!= "max_objects" && field
!= "max_bytes") {
10699 ss
<< "unrecognized field '" << field
<< "'; should be 'max_bytes' or 'max_objects'";
10704 // val could contain unit designations, so we treat as a string
10706 cmd_getval(g_ceph_context
, cmdmap
, "val", val
);
10708 int64_t value
= unit_to_bytesize(val
, &tss
);
10710 ss
<< "error parsing value '" << value
<< "': " << tss
.str();
10715 pg_pool_t
*pi
= pending_inc
.get_new_pool(pool_id
, osdmap
.get_pg_pool(pool_id
));
10716 if (field
== "max_objects") {
10717 pi
->quota_max_objects
= value
;
10718 } else if (field
== "max_bytes") {
10719 pi
->quota_max_bytes
= value
;
10721 assert(0 == "unrecognized option");
10723 ss
<< "set-quota " << field
<< " = " << value
<< " for pool " << poolstr
;
10725 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
10726 get_last_committed() + 1));
10728 } else if (prefix
== "osd pool application enable" ||
10729 prefix
== "osd pool application disable" ||
10730 prefix
== "osd pool application set" ||
10731 prefix
== "osd pool application rm") {
10732 err
= prepare_command_pool_application(prefix
, cmdmap
, ss
);
10733 if (err
== -EAGAIN
)
10739 wait_for_finished_proposal(
10740 op
, new Monitor::C_Command(mon
, op
, 0, rs
, get_last_committed() + 1));
10742 } else if (prefix
== "osd reweight-by-pg" ||
10743 prefix
== "osd reweight-by-utilization" ||
10744 prefix
== "osd test-reweight-by-pg" ||
10745 prefix
== "osd test-reweight-by-utilization") {
10747 prefix
== "osd reweight-by-pg" || prefix
== "osd test-reweight-by-pg";
10749 prefix
== "osd test-reweight-by-pg" ||
10750 prefix
== "osd test-reweight-by-utilization";
10752 cmd_getval(g_ceph_context
, cmdmap
, "oload", oload
, int64_t(120));
10753 set
<int64_t> pools
;
10754 vector
<string
> poolnamevec
;
10755 cmd_getval(g_ceph_context
, cmdmap
, "pools", poolnamevec
);
10756 for (unsigned j
= 0; j
< poolnamevec
.size(); j
++) {
10757 int64_t pool
= osdmap
.lookup_pg_pool_name(poolnamevec
[j
]);
10759 ss
<< "pool '" << poolnamevec
[j
] << "' does not exist";
10763 pools
.insert(pool
);
10765 double max_change
= g_conf
->mon_reweight_max_change
;
10766 cmd_getval(g_ceph_context
, cmdmap
, "max_change", max_change
);
10767 if (max_change
<= 0.0) {
10768 ss
<< "max_change " << max_change
<< " must be positive";
10772 int64_t max_osds
= g_conf
->mon_reweight_max_osds
;
10773 cmd_getval(g_ceph_context
, cmdmap
, "max_osds", max_osds
);
10774 if (max_osds
<= 0) {
10775 ss
<< "max_osds " << max_osds
<< " must be positive";
10779 string no_increasing
;
10780 cmd_getval(g_ceph_context
, cmdmap
, "no_increasing", no_increasing
);
10782 mempool::osdmap::map
<int32_t, uint32_t> new_weights
;
10783 err
= mon
->pgservice
->reweight_by_utilization(osdmap
,
10788 pools
.empty() ? NULL
: &pools
,
10789 no_increasing
== "--no-increasing",
10791 &ss
, &out_str
, f
.get());
10793 dout(10) << "reweight::by_utilization: finished with " << out_str
<< dendl
;
10798 rdata
.append(out_str
);
10800 ss
<< "FAILED reweight-by-pg";
10801 } else if (err
== 0 || dry_run
) {
10804 ss
<< "SUCCESSFUL reweight-by-pg";
10805 pending_inc
.new_weight
= std::move(new_weights
);
10806 wait_for_finished_proposal(
10808 new Monitor::C_Command(mon
, op
, 0, rs
, rdata
, get_last_committed() + 1));
10811 } else if (prefix
== "osd force-create-pg") {
10814 cmd_getval(g_ceph_context
, cmdmap
, "pgid", pgidstr
);
10815 if (!pgid
.parse(pgidstr
.c_str())) {
10816 ss
<< "invalid pgid '" << pgidstr
<< "'";
10822 std::lock_guard
<std::mutex
> l(creating_pgs_lock
);
10823 auto emplaced
= creating_pgs
.pgs
.emplace(pgid
,
10824 make_pair(osdmap
.get_epoch(),
10825 ceph_clock_now()));
10826 creating_now
= emplaced
.second
;
10828 if (creating_now
) {
10829 ss
<< "pg " << pgidstr
<< " now creating, ok";
10833 ss
<< "pg " << pgid
<< " already creating";
10843 if (err
< 0 && rs
.length() == 0)
10844 rs
= cpp_strerror(err
);
10845 mon
->reply_command(op
, err
, rs
, rdata
, get_last_committed());
10850 wait_for_finished_proposal(op
, new Monitor::C_Command(mon
, op
, 0, rs
,
10851 get_last_committed() + 1));
10855 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
10859 bool OSDMonitor::preprocess_pool_op(MonOpRequestRef op
)
10861 op
->mark_osdmon_event(__func__
);
10862 MPoolOp
*m
= static_cast<MPoolOp
*>(op
->get_req());
10864 if (m
->fsid
!= mon
->monmap
->fsid
) {
10865 dout(0) << __func__
<< " drop message on fsid " << m
->fsid
10866 << " != " << mon
->monmap
->fsid
<< " for " << *m
<< dendl
;
10867 _pool_op_reply(op
, -EINVAL
, osdmap
.get_epoch());
10871 if (m
->op
== POOL_OP_CREATE
)
10872 return preprocess_pool_op_create(op
);
10874 if (!osdmap
.get_pg_pool(m
->pool
)) {
10875 dout(10) << "attempt to operate on non-existent pool id " << m
->pool
<< dendl
;
10876 _pool_op_reply(op
, 0, osdmap
.get_epoch());
10880 // check if the snap and snapname exist
10881 bool snap_exists
= false;
10882 const pg_pool_t
*p
= osdmap
.get_pg_pool(m
->pool
);
10883 if (p
->snap_exists(m
->name
.c_str()))
10884 snap_exists
= true;
10887 case POOL_OP_CREATE_SNAP
:
10888 if (p
->is_unmanaged_snaps_mode() || p
->is_tier()) {
10889 _pool_op_reply(op
, -EINVAL
, osdmap
.get_epoch());
10893 _pool_op_reply(op
, 0, osdmap
.get_epoch());
10897 case POOL_OP_CREATE_UNMANAGED_SNAP
:
10898 if (p
->is_pool_snaps_mode()) {
10899 _pool_op_reply(op
, -EINVAL
, osdmap
.get_epoch());
10903 case POOL_OP_DELETE_SNAP
:
10904 if (p
->is_unmanaged_snaps_mode()) {
10905 _pool_op_reply(op
, -EINVAL
, osdmap
.get_epoch());
10908 if (!snap_exists
) {
10909 _pool_op_reply(op
, 0, osdmap
.get_epoch());
10913 case POOL_OP_DELETE_UNMANAGED_SNAP
:
10914 if (p
->is_pool_snaps_mode()) {
10915 _pool_op_reply(op
, -EINVAL
, osdmap
.get_epoch());
10918 if (p
->is_removed_snap(m
->snapid
)) {
10919 _pool_op_reply(op
, 0, osdmap
.get_epoch());
10923 case POOL_OP_DELETE
:
10924 if (osdmap
.lookup_pg_pool_name(m
->name
.c_str()) >= 0) {
10925 _pool_op_reply(op
, 0, osdmap
.get_epoch());
10929 case POOL_OP_AUID_CHANGE
:
10939 bool OSDMonitor::preprocess_pool_op_create(MonOpRequestRef op
)
10941 op
->mark_osdmon_event(__func__
);
10942 MPoolOp
*m
= static_cast<MPoolOp
*>(op
->get_req());
10943 MonSession
*session
= m
->get_session();
10945 _pool_op_reply(op
, -EPERM
, osdmap
.get_epoch());
10948 if (!session
->is_capable("osd", MON_CAP_W
)) {
10949 dout(5) << "attempt to create new pool without sufficient auid privileges!"
10950 << "message: " << *m
<< std::endl
10951 << "caps: " << session
->caps
<< dendl
;
10952 _pool_op_reply(op
, -EPERM
, osdmap
.get_epoch());
10956 int64_t pool
= osdmap
.lookup_pg_pool_name(m
->name
.c_str());
10958 _pool_op_reply(op
, 0, osdmap
.get_epoch());
10965 bool OSDMonitor::prepare_pool_op(MonOpRequestRef op
)
10967 op
->mark_osdmon_event(__func__
);
10968 MPoolOp
*m
= static_cast<MPoolOp
*>(op
->get_req());
10969 dout(10) << "prepare_pool_op " << *m
<< dendl
;
10970 if (m
->op
== POOL_OP_CREATE
) {
10971 return prepare_pool_op_create(op
);
10972 } else if (m
->op
== POOL_OP_DELETE
) {
10973 return prepare_pool_op_delete(op
);
10977 bool changed
= false;
10979 if (!osdmap
.have_pg_pool(m
->pool
)) {
10980 _pool_op_reply(op
, -ENOENT
, osdmap
.get_epoch());
10984 const pg_pool_t
*pool
= osdmap
.get_pg_pool(m
->pool
);
10987 case POOL_OP_CREATE_SNAP
:
10988 if (pool
->is_tier()) {
10990 _pool_op_reply(op
, ret
, osdmap
.get_epoch());
10992 } // else, fall through
10993 case POOL_OP_DELETE_SNAP
:
10994 if (!pool
->is_unmanaged_snaps_mode()) {
10995 bool snap_exists
= pool
->snap_exists(m
->name
.c_str());
10996 if ((m
->op
== POOL_OP_CREATE_SNAP
&& snap_exists
)
10997 || (m
->op
== POOL_OP_DELETE_SNAP
&& !snap_exists
)) {
11005 _pool_op_reply(op
, ret
, osdmap
.get_epoch());
11008 case POOL_OP_DELETE_UNMANAGED_SNAP
:
11009 // we won't allow removal of an unmanaged snapshot from a pool
11010 // not in unmanaged snaps mode.
11011 if (!pool
->is_unmanaged_snaps_mode()) {
11012 _pool_op_reply(op
, -ENOTSUP
, osdmap
.get_epoch());
11016 case POOL_OP_CREATE_UNMANAGED_SNAP
:
11017 // but we will allow creating an unmanaged snapshot on any pool
11018 // as long as it is not in 'pool' snaps mode.
11019 if (pool
->is_pool_snaps_mode()) {
11020 _pool_op_reply(op
, -EINVAL
, osdmap
.get_epoch());
11025 // projected pool info
11027 if (pending_inc
.new_pools
.count(m
->pool
))
11028 pp
= pending_inc
.new_pools
[m
->pool
];
11030 pp
= *osdmap
.get_pg_pool(m
->pool
);
11032 bufferlist reply_data
;
11034 // pool snaps vs unmanaged snaps are mutually exclusive
11036 case POOL_OP_CREATE_SNAP
:
11037 case POOL_OP_DELETE_SNAP
:
11038 if (pp
.is_unmanaged_snaps_mode()) {
11044 case POOL_OP_CREATE_UNMANAGED_SNAP
:
11045 case POOL_OP_DELETE_UNMANAGED_SNAP
:
11046 if (pp
.is_pool_snaps_mode()) {
11053 case POOL_OP_CREATE_SNAP
:
11054 if (!pp
.snap_exists(m
->name
.c_str())) {
11055 pp
.add_snap(m
->name
.c_str(), ceph_clock_now());
11056 dout(10) << "create snap in pool " << m
->pool
<< " " << m
->name
<< " seq " << pp
.get_snap_epoch() << dendl
;
11061 case POOL_OP_DELETE_SNAP
:
11063 snapid_t s
= pp
.snap_exists(m
->name
.c_str());
11071 case POOL_OP_CREATE_UNMANAGED_SNAP
:
11074 pp
.add_unmanaged_snap(snapid
);
11075 ::encode(snapid
, reply_data
);
11080 case POOL_OP_DELETE_UNMANAGED_SNAP
:
11081 if (!pp
.is_removed_snap(m
->snapid
)) {
11082 pp
.remove_unmanaged_snap(m
->snapid
);
11087 case POOL_OP_AUID_CHANGE
:
11088 if (pp
.auid
!= m
->auid
) {
11100 pp
.set_snap_epoch(pending_inc
.epoch
);
11101 pending_inc
.new_pools
[m
->pool
] = pp
;
11105 wait_for_finished_proposal(op
, new OSDMonitor::C_PoolOp(this, op
, ret
, pending_inc
.epoch
, &reply_data
));
11109 bool OSDMonitor::prepare_pool_op_create(MonOpRequestRef op
)
11111 op
->mark_osdmon_event(__func__
);
11112 int err
= prepare_new_pool(op
);
11113 wait_for_finished_proposal(op
, new OSDMonitor::C_PoolOp(this, op
, err
, pending_inc
.epoch
));
11117 int OSDMonitor::_check_remove_pool(int64_t pool_id
, const pg_pool_t
& pool
,
11120 const string
& poolstr
= osdmap
.get_pool_name(pool_id
);
11122 // If the Pool is in use by CephFS, refuse to delete it
11123 FSMap
const &pending_fsmap
= mon
->mdsmon()->get_pending();
11124 if (pending_fsmap
.pool_in_use(pool_id
)) {
11125 *ss
<< "pool '" << poolstr
<< "' is in use by CephFS";
11129 if (pool
.tier_of
>= 0) {
11130 *ss
<< "pool '" << poolstr
<< "' is a tier of '"
11131 << osdmap
.get_pool_name(pool
.tier_of
) << "'";
11134 if (!pool
.tiers
.empty()) {
11135 *ss
<< "pool '" << poolstr
<< "' has tiers";
11136 for(auto tier
: pool
.tiers
) {
11137 *ss
<< " " << osdmap
.get_pool_name(tier
);
11142 if (!g_conf
->mon_allow_pool_delete
) {
11143 *ss
<< "pool deletion is disabled; you must first set the mon_allow_pool_delete config option to true before you can destroy a pool";
11147 if (pool
.has_flag(pg_pool_t::FLAG_NODELETE
)) {
11148 *ss
<< "pool deletion is disabled; you must unset nodelete flag for the pool first";
11152 *ss
<< "pool '" << poolstr
<< "' removed";
11157 * Check if it is safe to add a tier to a base pool
11160 * True if the operation should proceed, false if we should abort here
11161 * (abort doesn't necessarily mean error, could be idempotency)
11163 bool OSDMonitor::_check_become_tier(
11164 const int64_t tier_pool_id
, const pg_pool_t
*tier_pool
,
11165 const int64_t base_pool_id
, const pg_pool_t
*base_pool
,
11169 const std::string
&tier_pool_name
= osdmap
.get_pool_name(tier_pool_id
);
11170 const std::string
&base_pool_name
= osdmap
.get_pool_name(base_pool_id
);
11172 const FSMap
&pending_fsmap
= mon
->mdsmon()->get_pending();
11173 if (pending_fsmap
.pool_in_use(tier_pool_id
)) {
11174 *ss
<< "pool '" << tier_pool_name
<< "' is in use by CephFS";
11179 if (base_pool
->tiers
.count(tier_pool_id
)) {
11180 assert(tier_pool
->tier_of
== base_pool_id
);
11182 *ss
<< "pool '" << tier_pool_name
<< "' is now (or already was) a tier of '"
11183 << base_pool_name
<< "'";
11187 if (base_pool
->is_tier()) {
11188 *ss
<< "pool '" << base_pool_name
<< "' is already a tier of '"
11189 << osdmap
.get_pool_name(base_pool
->tier_of
) << "', "
11190 << "multiple tiers are not yet supported.";
11195 if (tier_pool
->has_tiers()) {
11196 *ss
<< "pool '" << tier_pool_name
<< "' has following tier(s) already:";
11197 for (set
<uint64_t>::iterator it
= tier_pool
->tiers
.begin();
11198 it
!= tier_pool
->tiers
.end(); ++it
)
11199 *ss
<< "'" << osdmap
.get_pool_name(*it
) << "',";
11200 *ss
<< " multiple tiers are not yet supported.";
11205 if (tier_pool
->is_tier()) {
11206 *ss
<< "tier pool '" << tier_pool_name
<< "' is already a tier of '"
11207 << osdmap
.get_pool_name(tier_pool
->tier_of
) << "'";
11218 * Check if it is safe to remove a tier from this base pool
11221 * True if the operation should proceed, false if we should abort here
11222 * (abort doesn't necessarily mean error, could be idempotency)
11224 bool OSDMonitor::_check_remove_tier(
11225 const int64_t base_pool_id
, const pg_pool_t
*base_pool
,
11226 const pg_pool_t
*tier_pool
,
11227 int *err
, ostream
*ss
) const
11229 const std::string
&base_pool_name
= osdmap
.get_pool_name(base_pool_id
);
11231 // Apply CephFS-specific checks
11232 const FSMap
&pending_fsmap
= mon
->mdsmon()->get_pending();
11233 if (pending_fsmap
.pool_in_use(base_pool_id
)) {
11234 if (base_pool
->type
!= pg_pool_t::TYPE_REPLICATED
) {
11235 // If the underlying pool is erasure coded, we can't permit the
11236 // removal of the replicated tier that CephFS relies on to access it
11237 *ss
<< "pool '" << base_pool_name
<< "' is in use by CephFS via its tier";
11242 if (tier_pool
&& tier_pool
->cache_mode
== pg_pool_t::CACHEMODE_WRITEBACK
) {
11243 *ss
<< "pool '" << base_pool_name
<< "' is in use by CephFS, and this "
11244 "tier is still in use as a writeback cache. Change the cache "
11245 "mode and flush the cache before removing it";
11255 int OSDMonitor::_prepare_remove_pool(
11256 int64_t pool
, ostream
*ss
, bool no_fake
)
11258 dout(10) << __func__
<< " " << pool
<< dendl
;
11259 const pg_pool_t
*p
= osdmap
.get_pg_pool(pool
);
11260 int r
= _check_remove_pool(pool
, *p
, ss
);
11264 auto new_pool
= pending_inc
.new_pools
.find(pool
);
11265 if (new_pool
!= pending_inc
.new_pools
.end()) {
11266 // if there is a problem with the pending info, wait and retry
11268 const auto& p
= new_pool
->second
;
11269 int r
= _check_remove_pool(pool
, p
, ss
);
11274 if (pending_inc
.old_pools
.count(pool
)) {
11275 dout(10) << __func__
<< " " << pool
<< " already pending removal"
11280 if (g_conf
->mon_fake_pool_delete
&& !no_fake
) {
11281 string old_name
= osdmap
.get_pool_name(pool
);
11282 string new_name
= old_name
+ "." + stringify(pool
) + ".DELETED";
11283 dout(1) << __func__
<< " faking pool deletion: renaming " << pool
<< " "
11284 << old_name
<< " -> " << new_name
<< dendl
;
11285 pending_inc
.new_pool_names
[pool
] = new_name
;
11290 pending_inc
.old_pools
.insert(pool
);
11292 // remove any pg_temp mappings for this pool
11293 for (auto p
= osdmap
.pg_temp
->begin();
11294 p
!= osdmap
.pg_temp
->end();
11296 if (p
->first
.pool() == (uint64_t)pool
) {
11297 dout(10) << __func__
<< " " << pool
<< " removing obsolete pg_temp "
11298 << p
->first
<< dendl
;
11299 pending_inc
.new_pg_temp
[p
->first
].clear();
11302 // remove any primary_temp mappings for this pool
11303 for (auto p
= osdmap
.primary_temp
->begin();
11304 p
!= osdmap
.primary_temp
->end();
11306 if (p
->first
.pool() == (uint64_t)pool
) {
11307 dout(10) << __func__
<< " " << pool
11308 << " removing obsolete primary_temp" << p
->first
<< dendl
;
11309 pending_inc
.new_primary_temp
[p
->first
] = -1;
11312 // remove any pg_upmap mappings for this pool
11313 for (auto& p
: osdmap
.pg_upmap
) {
11314 if (p
.first
.pool() == (uint64_t)pool
) {
11315 dout(10) << __func__
<< " " << pool
11316 << " removing obsolete pg_upmap "
11317 << p
.first
<< dendl
;
11318 pending_inc
.old_pg_upmap
.insert(p
.first
);
11321 // remove any pg_upmap_items mappings for this pool
11322 for (auto& p
: osdmap
.pg_upmap_items
) {
11323 if (p
.first
.pool() == (uint64_t)pool
) {
11324 dout(10) << __func__
<< " " << pool
11325 << " removing obsolete pg_upmap_items " << p
.first
11327 pending_inc
.old_pg_upmap_items
.insert(p
.first
);
11333 int OSDMonitor::_prepare_rename_pool(int64_t pool
, string newname
)
11335 dout(10) << "_prepare_rename_pool " << pool
<< dendl
;
11336 if (pending_inc
.old_pools
.count(pool
)) {
11337 dout(10) << "_prepare_rename_pool " << pool
<< " pending removal" << dendl
;
11340 for (map
<int64_t,string
>::iterator p
= pending_inc
.new_pool_names
.begin();
11341 p
!= pending_inc
.new_pool_names
.end();
11343 if (p
->second
== newname
&& p
->first
!= pool
) {
11348 pending_inc
.new_pool_names
[pool
] = newname
;
11352 bool OSDMonitor::prepare_pool_op_delete(MonOpRequestRef op
)
11354 op
->mark_osdmon_event(__func__
);
11355 MPoolOp
*m
= static_cast<MPoolOp
*>(op
->get_req());
11357 int ret
= _prepare_remove_pool(m
->pool
, &ss
, false);
11358 if (ret
== -EAGAIN
) {
11359 wait_for_finished_proposal(op
, new C_RetryMessage(this, op
));
11363 dout(10) << __func__
<< " got " << ret
<< " " << ss
.str() << dendl
;
11364 wait_for_finished_proposal(op
, new OSDMonitor::C_PoolOp(this, op
, ret
,
11365 pending_inc
.epoch
));
11369 void OSDMonitor::_pool_op_reply(MonOpRequestRef op
,
11370 int ret
, epoch_t epoch
, bufferlist
*blp
)
11372 op
->mark_osdmon_event(__func__
);
11373 MPoolOp
*m
= static_cast<MPoolOp
*>(op
->get_req());
11374 dout(20) << "_pool_op_reply " << ret
<< dendl
;
11375 MPoolOpReply
*reply
= new MPoolOpReply(m
->fsid
, m
->get_tid(),
11376 ret
, epoch
, get_last_committed(), blp
);
11377 mon
->send_reply(op
, reply
);