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) 2017 Red Hat Ltd
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
16 #include "OSDMonitor.h"
18 #include "FSCommands.h"
19 #include "MDSMonitor.h"
20 #include "MgrStatMonitor.h"
21 #include "mds/cephfs_features.h"
23 using TOPNSPC::common::cmd_getval
;
31 using std::ostringstream
;
35 using std::stringstream
;
39 using ceph::bufferlist
;
42 using ceph::ErasureCodeInterfaceRef
;
43 using ceph::ErasureCodeProfile
;
44 using ceph::Formatter
;
45 using ceph::JSONFormatter
;
46 using ceph::make_message
;
47 using ceph::mono_clock
;
48 using ceph::mono_time
;
50 class FlagSetHandler
: public FileSystemCommandHandler
54 : FileSystemCommandHandler("fs flag set")
62 const cmdmap_t
& cmdmap
,
63 std::stringstream
&ss
) override
66 cmd_getval(cmdmap
, "flag_name", flag_name
);
69 cmd_getval(cmdmap
, "val", flag_val
);
72 cmd_getval(cmdmap
, "yes_i_really_mean_it", sure
);
74 if (flag_name
== "enable_multiple") {
75 bool flag_bool
= false;
76 int r
= parse_bool(flag_val
, &flag_bool
, ss
);
78 ss
<< "Invalid boolean value '" << flag_val
<< "'";
82 fsmap
.set_enable_multiple(flag_bool
);
85 ss
<< "Unknown flag '" << flag_name
<< "'";
91 class FailHandler
: public FileSystemCommandHandler
95 : FileSystemCommandHandler("fs fail")
103 const cmdmap_t
& cmdmap
,
104 std::stringstream
& ss
) override
106 if (!mon
->osdmon()->is_writeable()) {
107 // not allowed to write yet, so retry when we can
108 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
113 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
114 ss
<< "Missing filesystem name";
118 auto fs
= fsmap
.get_filesystem(fs_name
);
120 auto f
= [](auto fs
) {
121 fs
->mds_map
.set_flag(CEPH_MDSMAP_NOT_JOINABLE
);
123 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
125 std::vector
<mds_gid_t
> to_fail
;
126 for (const auto& p
: fs
->mds_map
.get_mds_info()) {
127 to_fail
.push_back(p
.first
);
130 for (const auto& gid
: to_fail
) {
131 mon
->mdsmon()->fail_mds_gid(fsmap
, gid
);
133 if (!to_fail
.empty()) {
134 mon
->osdmon()->propose_pending();
138 ss
<< " marked not joinable; MDS cannot join the cluster. All MDS ranks marked failed.";
144 class FsNewHandler
: public FileSystemCommandHandler
147 explicit FsNewHandler(Paxos
*paxos
)
148 : FileSystemCommandHandler("fs new"), m_paxos(paxos
)
152 bool batched_propose() override
{
160 const cmdmap_t
& cmdmap
,
161 std::stringstream
&ss
) override
163 ceph_assert(m_paxos
->is_plugged());
165 string metadata_name
;
166 cmd_getval(cmdmap
, "metadata", metadata_name
);
167 int64_t metadata
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(metadata_name
);
169 ss
<< "pool '" << metadata_name
<< "' does not exist";
174 cmd_getval(cmdmap
, "data", data_name
);
175 int64_t data
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(data_name
);
177 ss
<< "pool '" << data_name
<< "' does not exist";
181 ss
<< "pool '" << data_name
<< "' has id 0, which CephFS does not allow. Use another pool or recreate it to get a non-zero pool id.";
186 cmd_getval(cmdmap
, "fs_name", fs_name
);
187 if (fs_name
.empty()) {
188 // Ensure fs name is not empty so that we can implement
189 // commmands that refer to FS by name in future.
190 ss
<< "Filesystem name may not be empty";
194 if (fsmap
.get_filesystem(fs_name
)) {
195 auto fs
= fsmap
.get_filesystem(fs_name
);
196 if (*(fs
->mds_map
.get_data_pools().begin()) == data
197 && fs
->mds_map
.get_metadata_pool() == metadata
) {
198 // Identical FS created already, this is a no-op
199 ss
<< "filesystem '" << fs_name
<< "' already exists";
202 ss
<< "filesystem already exists with name '" << fs_name
<< "'";
208 cmd_getval(cmdmap
, "force", force
);
210 const pool_stat_t
*stat
= mon
->mgrstatmon()->get_pool_stat(metadata
);
212 int64_t metadata_num_objects
= stat
->stats
.sum
.num_objects
;
213 if (!force
&& metadata_num_objects
> 0) {
214 ss
<< "pool '" << metadata_name
215 << "' already contains some objects. Use an empty pool instead.";
220 if (fsmap
.filesystem_count() > 0
221 && !fsmap
.get_enable_multiple()) {
222 ss
<< "Creation of multiple filesystems is disabled. To enable "
223 "this experimental feature, use 'ceph fs flag set enable_multiple "
228 for (auto& fs
: fsmap
.get_filesystems()) {
229 const std::vector
<int64_t> &data_pools
= fs
->mds_map
.get_data_pools();
233 "allow_dangerous_metadata_overlay", sure
);
235 if ((std::find(data_pools
.begin(), data_pools
.end(), data
) != data_pools
.end()
236 || fs
->mds_map
.get_metadata_pool() == metadata
)
238 ss
<< "Filesystem '" << fs_name
239 << "' is already using one of the specified RADOS pools. This should ONLY be done in emergencies and after careful reading of the documentation. Pass --allow-dangerous-metadata-overlay to permit this.";
244 pg_pool_t
const *data_pool
= mon
->osdmon()->osdmap
.get_pg_pool(data
);
245 ceph_assert(data_pool
!= NULL
); // Checked it existed above
246 pg_pool_t
const *metadata_pool
= mon
->osdmon()->osdmap
.get_pg_pool(metadata
);
247 ceph_assert(metadata_pool
!= NULL
); // Checked it existed above
249 int r
= _check_pool(mon
->osdmon()->osdmap
, data
, POOL_DATA_DEFAULT
, force
, &ss
);
254 r
= _check_pool(mon
->osdmon()->osdmap
, metadata
, POOL_METADATA
, force
, &ss
);
259 if (!mon
->osdmon()->is_writeable()) {
260 // not allowed to write yet, so retry when we can
261 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
264 mon
->osdmon()->do_application_enable(data
,
265 pg_pool_t::APPLICATION_NAME_CEPHFS
,
266 "data", fs_name
, true);
267 mon
->osdmon()->do_application_enable(metadata
,
268 pg_pool_t::APPLICATION_NAME_CEPHFS
,
269 "metadata", fs_name
, true);
270 mon
->osdmon()->do_set_pool_opt(metadata
,
271 pool_opts_t::RECOVERY_PRIORITY
,
272 static_cast<int64_t>(5));
273 mon
->osdmon()->do_set_pool_opt(metadata
,
274 pool_opts_t::PG_NUM_MIN
,
275 static_cast<int64_t>(16));
276 mon
->osdmon()->do_set_pool_opt(metadata
,
277 pool_opts_t::PG_AUTOSCALE_BIAS
,
278 static_cast<double>(4.0));
279 mon
->osdmon()->propose_pending();
281 // All checks passed, go ahead and create.
282 auto&& fs
= fsmap
.create_filesystem(fs_name
, metadata
, data
,
283 mon
->get_quorum_con_features());
285 ss
<< "new fs with metadata pool " << metadata
<< " and data pool " << data
;
287 // assign a standby to rank 0 to avoid health warnings
288 auto info
= fsmap
.find_replacement_for({fs
->fscid
, 0});
291 mon
->clog
->info() << info
->human_name() << " assigned to filesystem "
292 << fs_name
<< " as rank 0";
293 fsmap
.promote(info
->global_id
, *fs
, 0);
303 class SetHandler
: public FileSystemCommandHandler
307 : FileSystemCommandHandler("fs set")
314 const cmdmap_t
& cmdmap
,
315 std::stringstream
&ss
) override
318 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
319 ss
<< "Missing filesystem name";
323 auto fs
= fsmap
.get_filesystem(fs_name
);
325 if (!cmd_getval(cmdmap
, "var", var
) || var
.empty()) {
326 ss
<< "Invalid variable";
332 if (!cmd_getval(cmdmap
, "val", val
)) {
335 // we got a string. see if it contains an int.
336 n
= strict_strtoll(val
.c_str(), 10, &interr
);
337 if (var
== "max_mds") {
338 // NOTE: see also "mds set_max_mds", which can modify the same field.
339 if (interr
.length()) {
345 ss
<< "You must specify at least one MDS";
349 if (n
> 1 && n
> fs
->mds_map
.get_max_mds()) {
350 if (fs
->mds_map
.was_snaps_ever_allowed() &&
351 !fs
->mds_map
.allows_multimds_snaps()) {
352 ss
<< "multi-active MDS is not allowed while there are snapshots possibly created by pre-mimic MDS";
357 ss
<< "may not have more than " << MAX_MDS
<< " MDS ranks";
361 fsmap
.modify_filesystem(
363 [n
](std::shared_ptr
<Filesystem
> fs
)
365 fs
->mds_map
.clear_flag(CEPH_MDSMAP_NOT_JOINABLE
);
366 fs
->mds_map
.set_max_mds(n
);
368 } else if (var
== "inline_data") {
369 bool enable_inline
= false;
370 int r
= parse_bool(val
, &enable_inline
, ss
);
376 bool confirm
= false;
377 cmd_getval(cmdmap
, "yes_i_really_really_mean_it", confirm
);
379 ss
<< "Inline data support is deprecated and will be removed in a future release. "
380 << "Add --yes-i-really-really-mean-it if you are certain you want this enabled.";
383 ss
<< "inline data enabled";
385 fsmap
.modify_filesystem(
387 [](std::shared_ptr
<Filesystem
> fs
)
389 fs
->mds_map
.set_inline_data_enabled(true);
393 CompatSet c
= fsmap
.get_compat();
394 c
.incompat
.insert(MDS_FEATURE_INCOMPAT_INLINE
);
395 fsmap
.update_compat(c
);
397 ss
<< "inline data disabled";
398 fsmap
.modify_filesystem(
400 [](std::shared_ptr
<Filesystem
> fs
)
402 fs
->mds_map
.set_inline_data_enabled(false);
405 } else if (var
== "balancer") {
407 ss
<< "unsetting the metadata load balancer";
409 ss
<< "setting the metadata load balancer to " << val
;
411 fsmap
.modify_filesystem(
413 [val
](std::shared_ptr
<Filesystem
> fs
)
415 fs
->mds_map
.set_balancer(val
);
418 } else if (var
== "max_file_size") {
419 if (interr
.length()) {
420 ss
<< var
<< " requires an integer value";
423 if (n
< CEPH_MIN_STRIPE_UNIT
) {
424 ss
<< var
<< " must at least " << CEPH_MIN_STRIPE_UNIT
;
427 fsmap
.modify_filesystem(
429 [n
](std::shared_ptr
<Filesystem
> fs
)
431 fs
->mds_map
.set_max_filesize(n
);
433 } else if (var
== "allow_new_snaps") {
434 bool enable_snaps
= false;
435 int r
= parse_bool(val
, &enable_snaps
, ss
);
441 fsmap
.modify_filesystem(
443 [](std::shared_ptr
<Filesystem
> fs
)
445 fs
->mds_map
.clear_snaps_allowed();
447 ss
<< "disabled new snapshots";
449 fsmap
.modify_filesystem(
451 [](std::shared_ptr
<Filesystem
> fs
)
453 fs
->mds_map
.set_snaps_allowed();
455 ss
<< "enabled new snapshots";
457 } else if (var
== "allow_multimds") {
458 ss
<< "Multiple MDS is always enabled. Use the max_mds"
459 << " parameter to control the number of active MDSs"
460 << " allowed. This command is DEPRECATED and will be"
461 << " REMOVED from future releases.";
462 } else if (var
== "allow_multimds_snaps") {
464 int r
= parse_bool(val
, &enable
, ss
);
470 if (!cmd_getval(cmdmap
, "confirm", confirm
) ||
471 confirm
!= "--yes-i-am-really-a-mds") {
472 ss
<< "Warning! This command is for MDS only. Do not run it manually";
477 ss
<< "enabled multimds with snapshot";
478 fsmap
.modify_filesystem(
480 [](std::shared_ptr
<Filesystem
> fs
)
482 fs
->mds_map
.set_multimds_snaps_allowed();
485 ss
<< "disabled multimds with snapshot";
486 fsmap
.modify_filesystem(
488 [](std::shared_ptr
<Filesystem
> fs
)
490 fs
->mds_map
.clear_multimds_snaps_allowed();
493 } else if (var
== "allow_dirfrags") {
494 ss
<< "Directory fragmentation is now permanently enabled."
495 << " This command is DEPRECATED and will be REMOVED from future releases.";
496 } else if (var
== "down") {
497 bool is_down
= false;
498 int r
= parse_bool(val
, &is_down
, ss
);
503 ss
<< fs
->mds_map
.get_fs_name();
505 fsmap
.modify_filesystem(
507 [is_down
](std::shared_ptr
<Filesystem
> fs
)
510 if (fs
->mds_map
.get_max_mds() > 0) {
511 fs
->mds_map
.set_old_max_mds();
512 fs
->mds_map
.set_max_mds(0);
513 } /* else already down! */
515 mds_rank_t oldmax
= fs
->mds_map
.get_old_max_mds();
516 fs
->mds_map
.set_max_mds(oldmax
? oldmax
: 1);
521 ss
<< " marked down. ";
523 ss
<< " marked up, max_mds = " << fs
->mds_map
.get_max_mds();
525 } else if (var
== "cluster_down" || var
== "joinable") {
526 bool joinable
= true;
527 int r
= parse_bool(val
, &joinable
, ss
);
531 if (var
== "cluster_down") {
532 joinable
= !joinable
;
535 ss
<< fs
->mds_map
.get_fs_name();
537 fsmap
.modify_filesystem(
539 [joinable
](std::shared_ptr
<Filesystem
> fs
)
542 fs
->mds_map
.clear_flag(CEPH_MDSMAP_NOT_JOINABLE
);
544 fs
->mds_map
.set_flag(CEPH_MDSMAP_NOT_JOINABLE
);
549 ss
<< " marked joinable; MDS may join as newly active.";
551 ss
<< " marked not joinable; MDS cannot join as newly active.";
554 if (var
== "cluster_down") {
555 ss
<< " WARNING: cluster_down flag is deprecated and will be"
556 << " removed in a future version. Please use \"joinable\".";
558 } else if (var
== "standby_count_wanted") {
559 if (interr
.length()) {
560 ss
<< var
<< " requires an integer value";
564 ss
<< var
<< " must be non-negative";
567 fsmap
.modify_filesystem(
569 [n
](std::shared_ptr
<Filesystem
> fs
)
571 fs
->mds_map
.set_standby_count_wanted(n
);
573 } else if (var
== "session_timeout") {
574 if (interr
.length()) {
575 ss
<< var
<< " requires an integer value";
579 ss
<< var
<< " must be at least 30s";
582 fsmap
.modify_filesystem(
584 [n
](std::shared_ptr
<Filesystem
> fs
)
586 fs
->mds_map
.set_session_timeout((uint32_t)n
);
588 } else if (var
== "session_autoclose") {
589 if (interr
.length()) {
590 ss
<< var
<< " requires an integer value";
594 ss
<< var
<< " must be at least 30s";
597 fsmap
.modify_filesystem(
599 [n
](std::shared_ptr
<Filesystem
> fs
)
601 fs
->mds_map
.set_session_autoclose((uint32_t)n
);
603 } else if (var
== "allow_standby_replay") {
605 int r
= parse_bool(val
, &allow
, ss
);
611 if (!mon
->osdmon()->is_writeable()) {
612 // not allowed to write yet, so retry when we can
613 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
616 std::vector
<mds_gid_t
> to_fail
;
617 for (const auto& [gid
, info
]: fs
->mds_map
.get_mds_info()) {
618 if (info
.state
== MDSMap::STATE_STANDBY_REPLAY
) {
619 to_fail
.push_back(gid
);
623 for (const auto& gid
: to_fail
) {
624 mon
->mdsmon()->fail_mds_gid(fsmap
, gid
);
626 if (!to_fail
.empty()) {
627 mon
->osdmon()->propose_pending();
631 auto f
= [allow
](auto& fs
) {
633 fs
->mds_map
.set_standby_replay_allowed();
635 fs
->mds_map
.clear_standby_replay_allowed();
638 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
639 } else if (var
== "min_compat_client") {
640 auto vno
= ceph_release_from_name(val
.c_str());
642 ss
<< "version " << val
<< " is not recognized";
645 ss
<< "WARNING: setting min_compat_client is deprecated"
646 " and may not do what you want.\n"
647 "The oldest release to set is octopus.\n"
648 "Please migrate to `ceph fs required_client_features ...`.";
649 auto f
= [vno
](auto&& fs
) {
650 fs
->mds_map
.set_min_compat_client(vno
);
652 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
654 ss
<< "unknown variable " << var
;
662 class RequiredClientFeaturesHandler
: public FileSystemCommandHandler
665 RequiredClientFeaturesHandler()
666 : FileSystemCommandHandler("fs required_client_features")
674 const cmdmap_t
& cmdmap
,
675 std::stringstream
&ss
) override
678 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
679 ss
<< "Missing filesystem name";
682 auto fs
= fsmap
.get_filesystem(fs_name
);
684 ss
<< "Not found: '" << fs_name
<< "'";
688 if (!cmd_getval(cmdmap
, "subop", subop
) ||
689 (subop
!= "add" && subop
!= "rm")) {
690 ss
<< "Must either add or rm a feature; " << subop
<< " is not recognized";
694 if (!cmd_getval(cmdmap
, "val", val
) || val
.empty()) {
695 ss
<< "Missing feature id/name";
699 int feature
= cephfs_feature_from_name(val
);
702 feature
= strict_strtol(val
.c_str(), 10, &err
);
704 ss
<< "Invalid feature name: " << val
;
707 if (feature
< 0 || feature
> CEPHFS_FEATURE_MAX
) {
708 ss
<< "Invalid feature id: " << feature
;
713 if (subop
== "add") {
715 fsmap
.modify_filesystem(
717 [feature
, &ret
](auto&& fs
)
719 if (fs
->mds_map
.get_required_client_features().test(feature
))
721 fs
->mds_map
.add_required_client_feature(feature
);
725 ss
<< "added feature '" << cephfs_feature_name(feature
) << "' to required_client_features";
727 ss
<< "feature '" << cephfs_feature_name(feature
) << "' is already set";
731 fsmap
.modify_filesystem(
733 [feature
, &ret
](auto&& fs
)
735 if (!fs
->mds_map
.get_required_client_features().test(feature
))
737 fs
->mds_map
.remove_required_client_feature(feature
);
741 ss
<< "removed feature '" << cephfs_feature_name(feature
) << "' from required_client_features";
743 ss
<< "feature '" << cephfs_feature_name(feature
) << "' is already unset";
751 class AddDataPoolHandler
: public FileSystemCommandHandler
754 explicit AddDataPoolHandler(Paxos
*paxos
)
755 : FileSystemCommandHandler("fs add_data_pool"), m_paxos(paxos
)
758 bool batched_propose() override
{
766 const cmdmap_t
& cmdmap
,
767 std::stringstream
&ss
) override
769 ceph_assert(m_paxos
->is_plugged());
772 cmd_getval(cmdmap
, "pool", poolname
);
775 if (!cmd_getval(cmdmap
, "fs_name", fs_name
)
776 || fs_name
.empty()) {
777 ss
<< "Missing filesystem name";
781 int64_t poolid
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(poolname
);
784 poolid
= strict_strtol(poolname
.c_str(), 10, &err
);
786 ss
<< "pool '" << poolname
<< "' does not exist";
791 int r
= _check_pool(mon
->osdmon()->osdmap
, poolid
, POOL_DATA_EXTRA
, false, &ss
);
796 auto fs
= fsmap
.get_filesystem(fs_name
);
797 // no-op when the data_pool already on fs
798 if (fs
->mds_map
.is_data_pool(poolid
)) {
799 ss
<< "data pool " << poolid
<< " is already on fs " << fs_name
;
803 if (!mon
->osdmon()->is_writeable()) {
804 // not allowed to write yet, so retry when we can
805 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
808 mon
->osdmon()->do_application_enable(poolid
,
809 pg_pool_t::APPLICATION_NAME_CEPHFS
,
810 "data", fs_name
, true);
811 mon
->osdmon()->propose_pending();
813 fsmap
.modify_filesystem(
815 [poolid
](std::shared_ptr
<Filesystem
> fs
)
817 fs
->mds_map
.add_data_pool(poolid
);
820 ss
<< "added data pool " << poolid
<< " to fsmap";
829 class SetDefaultHandler
: public FileSystemCommandHandler
833 : FileSystemCommandHandler("fs set-default")
840 const cmdmap_t
& cmdmap
,
841 std::stringstream
&ss
) override
844 cmd_getval(cmdmap
, "fs_name", fs_name
);
845 auto fs
= fsmap
.get_filesystem(fs_name
);
847 ss
<< "filesystem '" << fs_name
<< "' does not exist";
851 fsmap
.set_legacy_client_fscid(fs
->fscid
);
856 class RemoveFilesystemHandler
: public FileSystemCommandHandler
859 RemoveFilesystemHandler()
860 : FileSystemCommandHandler("fs rm")
867 const cmdmap_t
& cmdmap
,
868 std::stringstream
&ss
) override
870 /* We may need to blocklist ranks. */
871 if (!mon
->osdmon()->is_writeable()) {
872 // not allowed to write yet, so retry when we can
873 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
877 // Check caller has correctly named the FS to delete
878 // (redundant while there is only one FS, but command
879 // syntax should apply to multi-FS future)
881 cmd_getval(cmdmap
, "fs_name", fs_name
);
882 auto fs
= fsmap
.get_filesystem(fs_name
);
884 // Consider absence success to make deletes idempotent
885 ss
<< "filesystem '" << fs_name
<< "' does not exist";
889 // Check that no MDS daemons are active
890 if (fs
->mds_map
.get_num_up_mds() > 0) {
891 ss
<< "all MDS daemons must be inactive/failed before removing filesystem. See `ceph fs fail`.";
895 // Check for confirmation flag
897 cmd_getval(cmdmap
, "yes_i_really_mean_it", sure
);
899 ss
<< "this is a DESTRUCTIVE operation and will make data in your filesystem permanently" \
900 " inaccessible. Add --yes-i-really-mean-it if you are sure you wish to continue.";
904 if (fsmap
.get_legacy_client_fscid() == fs
->fscid
) {
905 fsmap
.set_legacy_client_fscid(FS_CLUSTER_ID_NONE
);
908 std::vector
<mds_gid_t
> to_fail
;
909 // There may be standby_replay daemons left here
910 for (const auto &i
: fs
->mds_map
.get_mds_info()) {
911 ceph_assert(i
.second
.state
== MDSMap::STATE_STANDBY_REPLAY
);
912 to_fail
.push_back(i
.first
);
915 for (const auto &gid
: to_fail
) {
916 // Standby replays don't write, so it isn't important to
917 // wait for an osdmap propose here: ignore return value.
918 mon
->mdsmon()->fail_mds_gid(fsmap
, gid
);
920 if (!to_fail
.empty()) {
921 mon
->osdmon()->propose_pending(); /* maybe new blocklists */
924 fsmap
.erase_filesystem(fs
->fscid
);
930 class ResetFilesystemHandler
: public FileSystemCommandHandler
933 ResetFilesystemHandler()
934 : FileSystemCommandHandler("fs reset")
941 const cmdmap_t
& cmdmap
,
942 std::stringstream
&ss
) override
945 cmd_getval(cmdmap
, "fs_name", fs_name
);
946 auto fs
= fsmap
.get_filesystem(fs_name
);
948 ss
<< "filesystem '" << fs_name
<< "' does not exist";
949 // Unlike fs rm, we consider this case an error
953 // Check that no MDS daemons are active
954 if (fs
->mds_map
.get_num_up_mds() > 0) {
955 ss
<< "all MDS daemons must be inactive before resetting filesystem: set the cluster_down flag"
956 " and use `ceph mds fail` to make this so";
960 // Check for confirmation flag
962 cmd_getval(cmdmap
, "yes_i_really_mean_it", sure
);
964 ss
<< "this is a potentially destructive operation, only for use by experts in disaster recovery. "
965 "Add --yes-i-really-mean-it if you are sure you wish to continue.";
969 fsmap
.reset_filesystem(fs
->fscid
);
975 class RemoveDataPoolHandler
: public FileSystemCommandHandler
978 RemoveDataPoolHandler()
979 : FileSystemCommandHandler("fs rm_data_pool")
986 const cmdmap_t
& cmdmap
,
987 std::stringstream
&ss
) override
990 cmd_getval(cmdmap
, "pool", poolname
);
993 if (!cmd_getval(cmdmap
, "fs_name", fs_name
)
994 || fs_name
.empty()) {
995 ss
<< "Missing filesystem name";
999 int64_t poolid
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(poolname
);
1002 poolid
= strict_strtol(poolname
.c_str(), 10, &err
);
1004 ss
<< "pool '" << poolname
<< "' does not exist";
1006 } else if (poolid
< 0) {
1007 ss
<< "invalid pool id '" << poolid
<< "'";
1012 ceph_assert(poolid
>= 0); // Checked by parsing code above
1014 auto fs
= fsmap
.get_filesystem(fs_name
);
1015 if (fs
->mds_map
.get_first_data_pool() == poolid
) {
1016 ss
<< "cannot remove default data pool";
1021 fsmap
.modify_filesystem(fs
->fscid
,
1022 [&r
, poolid
](std::shared_ptr
<Filesystem
> fs
)
1024 r
= fs
->mds_map
.remove_data_pool(poolid
);
1027 // It was already removed, succeed in silence
1029 } else if (r
== 0) {
1030 // We removed it, succeed
1031 ss
<< "removed data pool " << poolid
<< " from fsmap";
1034 // Unexpected error, bubble up
1041 * For commands with an alternative prefix
1043 template<typename T
>
1044 class AliasHandler
: public T
1046 std::string alias_prefix
;
1049 explicit AliasHandler(const std::string
&new_prefix
)
1052 alias_prefix
= new_prefix
;
1055 std::string
const &get_prefix() const override
{return alias_prefix
;}
1061 const cmdmap_t
& cmdmap
,
1062 std::stringstream
&ss
) override
1064 return T::handle(mon
, fsmap
, op
, cmdmap
, ss
);
1068 class MirrorHandlerEnable
: public FileSystemCommandHandler
1071 MirrorHandlerEnable()
1072 : FileSystemCommandHandler("fs mirror enable")
1075 int handle(Monitor
*mon
,
1076 FSMap
&fsmap
, MonOpRequestRef op
,
1077 const cmdmap_t
& cmdmap
, std::stringstream
&ss
) override
{
1078 std::string fs_name
;
1079 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
1080 ss
<< "Missing filesystem name";
1084 auto fs
= fsmap
.get_filesystem(fs_name
);
1085 if (fs
== nullptr) {
1086 ss
<< "Filesystem '" << fs_name
<< "' not found";
1090 if (fs
->mirror_info
.is_mirrored()) {
1094 auto f
= [](auto &&fs
) {
1095 fs
->mirror_info
.enable_mirroring();
1097 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
1103 class MirrorHandlerDisable
: public FileSystemCommandHandler
1106 MirrorHandlerDisable()
1107 : FileSystemCommandHandler("fs mirror disable")
1110 int handle(Monitor
*mon
,
1111 FSMap
&fsmap
, MonOpRequestRef op
,
1112 const cmdmap_t
& cmdmap
, std::stringstream
&ss
) override
{
1113 std::string fs_name
;
1114 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
1115 ss
<< "Missing filesystem name";
1119 auto fs
= fsmap
.get_filesystem(fs_name
);
1120 if (fs
== nullptr) {
1121 ss
<< "Filesystem '" << fs_name
<< "' not found";
1125 if (!fs
->mirror_info
.is_mirrored()) {
1129 auto f
= [](auto &&fs
) {
1130 fs
->mirror_info
.disable_mirroring();
1132 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
1138 class MirrorHandlerAddPeer
: public FileSystemCommandHandler
1141 MirrorHandlerAddPeer()
1142 : FileSystemCommandHandler("fs mirror peer_add")
1145 boost::optional
<std::pair
<string
, string
>>
1146 extract_remote_cluster_conf(const std::string
&spec
) {
1147 auto pos
= spec
.find("@");
1148 if (pos
== std::string_view::npos
) {
1149 return boost::optional
<std::pair
<string
, string
>>();
1152 auto client
= spec
.substr(0, pos
);
1153 auto cluster
= spec
.substr(pos
+1);
1155 return std::make_pair(client
, cluster
);
1158 bool peer_add(FSMap
&fsmap
, Filesystem::const_ref
&&fs
,
1159 const cmdmap_t
&cmdmap
, std::stringstream
&ss
) {
1162 string remote_fs_name
;
1163 cmd_getval(cmdmap
, "uuid", peer_uuid
);
1164 cmd_getval(cmdmap
, "remote_cluster_spec", remote_spec
);
1165 cmd_getval(cmdmap
, "remote_fs_name", remote_fs_name
);
1167 // verify (and extract) remote cluster specification
1168 auto remote_conf
= extract_remote_cluster_conf(remote_spec
);
1170 ss
<< "invalid remote cluster spec -- should be <client>@<cluster>";
1174 if (fs
->mirror_info
.has_peer(peer_uuid
)) {
1175 ss
<< "peer already exists";
1178 if (fs
->mirror_info
.has_peer((*remote_conf
).first
, (*remote_conf
).second
,
1180 ss
<< "peer already exists";
1184 auto f
= [peer_uuid
, remote_conf
, remote_fs_name
](auto &&fs
) {
1185 fs
->mirror_info
.peer_add(peer_uuid
, (*remote_conf
).first
,
1186 (*remote_conf
).second
, remote_fs_name
);
1188 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
1192 int handle(Monitor
*mon
,
1193 FSMap
&fsmap
, MonOpRequestRef op
,
1194 const cmdmap_t
& cmdmap
, std::stringstream
&ss
) override
{
1195 std::string fs_name
;
1196 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
1197 ss
<< "Missing filesystem name";
1201 auto fs
= fsmap
.get_filesystem(fs_name
);
1202 if (fs
== nullptr) {
1203 ss
<< "Filesystem '" << fs_name
<< "' not found";
1207 if (!fs
->mirror_info
.is_mirrored()) {
1208 ss
<< "Mirroring not enabled for filesystem '" << fs_name
<< "'";
1212 auto res
= peer_add(fsmap
, std::move(fs
), cmdmap
, ss
);
1221 class MirrorHandlerRemovePeer
: public FileSystemCommandHandler
1224 MirrorHandlerRemovePeer()
1225 : FileSystemCommandHandler("fs mirror peer_remove")
1228 bool peer_remove(FSMap
&fsmap
, Filesystem::const_ref
&&fs
,
1229 const cmdmap_t
&cmdmap
, std::stringstream
&ss
) {
1231 cmd_getval(cmdmap
, "uuid", peer_uuid
);
1233 if (!fs
->mirror_info
.has_peer(peer_uuid
)) {
1234 ss
<< "cannot find peer with uuid: " << peer_uuid
;
1238 auto f
= [peer_uuid
](auto &&fs
) {
1239 fs
->mirror_info
.peer_remove(peer_uuid
);
1241 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
1245 int handle(Monitor
*mon
,
1246 FSMap
&fsmap
, MonOpRequestRef op
,
1247 const cmdmap_t
& cmdmap
, std::stringstream
&ss
) override
{
1248 std::string fs_name
;
1249 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
1250 ss
<< "Missing filesystem name";
1254 auto fs
= fsmap
.get_filesystem(fs_name
);
1255 if (fs
== nullptr) {
1256 ss
<< "Filesystem '" << fs_name
<< "' not found";
1260 if (!fs
->mirror_info
.is_mirrored()) {
1261 ss
<< "Mirroring not enabled for filesystem '" << fs_name
<< "'";
1265 auto res
= peer_remove(fsmap
, std::move(fs
), cmdmap
, ss
);
1274 std::list
<std::shared_ptr
<FileSystemCommandHandler
> >
1275 FileSystemCommandHandler::load(Paxos
*paxos
)
1277 std::list
<std::shared_ptr
<FileSystemCommandHandler
> > handlers
;
1279 handlers
.push_back(std::make_shared
<SetHandler
>());
1280 handlers
.push_back(std::make_shared
<FailHandler
>());
1281 handlers
.push_back(std::make_shared
<FlagSetHandler
>());
1282 handlers
.push_back(std::make_shared
<RequiredClientFeaturesHandler
>());
1283 handlers
.push_back(std::make_shared
<AddDataPoolHandler
>(paxos
));
1284 handlers
.push_back(std::make_shared
<RemoveDataPoolHandler
>());
1285 handlers
.push_back(std::make_shared
<FsNewHandler
>(paxos
));
1286 handlers
.push_back(std::make_shared
<RemoveFilesystemHandler
>());
1287 handlers
.push_back(std::make_shared
<ResetFilesystemHandler
>());
1289 handlers
.push_back(std::make_shared
<SetDefaultHandler
>());
1290 handlers
.push_back(std::make_shared
<AliasHandler
<SetDefaultHandler
> >(
1292 handlers
.push_back(std::make_shared
<MirrorHandlerEnable
>());
1293 handlers
.push_back(std::make_shared
<MirrorHandlerDisable
>());
1294 handlers
.push_back(std::make_shared
<MirrorHandlerAddPeer
>());
1295 handlers
.push_back(std::make_shared
<MirrorHandlerRemovePeer
>());
1300 int FileSystemCommandHandler::_check_pool(
1302 const int64_t pool_id
,
1305 std::stringstream
*ss
) const
1307 ceph_assert(ss
!= NULL
);
1309 const pg_pool_t
*pool
= osd_map
.get_pg_pool(pool_id
);
1311 *ss
<< "pool id '" << pool_id
<< "' does not exist";
1315 const string
& pool_name
= osd_map
.get_pool_name(pool_id
);
1317 if (pool
->is_erasure()) {
1318 if (type
== POOL_METADATA
) {
1319 *ss
<< "pool '" << pool_name
<< "' (id '" << pool_id
<< "')"
1320 << " is an erasure-coded pool. Use of erasure-coded pools"
1321 << " for CephFS metadata is not permitted";
1323 } else if (type
== POOL_DATA_DEFAULT
&& !force
) {
1324 *ss
<< "pool '" << pool_name
<< "' (id '" << pool_id
<< "')"
1325 " is an erasure-coded pool."
1326 " Use of an EC pool for the default data pool is discouraged;"
1327 " see the online CephFS documentation for more information."
1328 " Use --force to override.";
1330 } else if (!pool
->allows_ecoverwrites()) {
1331 // non-overwriteable EC pools are only acceptable with a cache tier overlay
1332 if (!pool
->has_tiers() || !pool
->has_read_tier() || !pool
->has_write_tier()) {
1333 *ss
<< "pool '" << pool_name
<< "' (id '" << pool_id
<< "')"
1334 << " is an erasure-coded pool, with no overwrite support";
1338 // That cache tier overlay must be writeback, not readonly (it's the
1339 // write operations like modify+truncate we care about support for)
1340 const pg_pool_t
*write_tier
= osd_map
.get_pg_pool(
1342 ceph_assert(write_tier
!= NULL
); // OSDMonitor shouldn't allow DNE tier
1343 if (write_tier
->cache_mode
== pg_pool_t::CACHEMODE_FORWARD
1344 || write_tier
->cache_mode
== pg_pool_t::CACHEMODE_READONLY
) {
1345 *ss
<< "EC pool '" << pool_name
<< "' has a write tier ("
1346 << osd_map
.get_pool_name(pool
->write_tier
)
1347 << ") that is configured "
1348 "to forward writes. Use a cache mode such as 'writeback' for "
1355 if (pool
->is_tier()) {
1356 *ss
<< " pool '" << pool_name
<< "' (id '" << pool_id
1357 << "') is already in use as a cache tier.";
1361 if (!force
&& !pool
->application_metadata
.empty() &&
1362 pool
->application_metadata
.count(
1363 pg_pool_t::APPLICATION_NAME_CEPHFS
) == 0) {
1364 *ss
<< " pool '" << pool_name
<< "' (id '" << pool_id
1365 << "') has a non-CephFS application enabled.";
1369 // Nothing special about this pool, so it is permissible
1373 int FileSystemCommandHandler::is_op_allowed(
1374 const MonOpRequestRef
& op
, const FSMap
& fsmap
, const cmdmap_t
& cmdmap
,
1375 std::stringstream
&ss
) const
1378 cmd_getval(cmdmap
, "fs_name", fs_name
);
1380 // so that fsmap can filtered and the original copy is untouched.
1381 FSMap fsmap_copy
= fsmap
;
1382 fsmap_copy
.filter(op
->get_session()->get_allowed_fs_names());
1384 auto fs
= fsmap_copy
.get_filesystem(fs_name
);
1385 if (fs
== nullptr) {
1386 /* let "fs rm" handle idempotent case where file system does not exist */
1387 if (!(get_prefix() == "fs rm" && fsmap
.get_filesystem(fs_name
) == nullptr)) {
1388 ss
<< "Filesystem not found: '" << fs_name
<< "'";
1393 if (!op
->get_session()->fs_name_capable(fs_name
, MON_CAP_W
)) {
1394 ss
<< "Permission denied: '" << fs_name
<< "'";