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 auto f
= [vno
](auto&& fs
) {
646 fs
->mds_map
.set_min_compat_client(vno
);
648 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
650 ss
<< "unknown variable " << var
;
658 class RequiredClientFeaturesHandler
: public FileSystemCommandHandler
661 RequiredClientFeaturesHandler()
662 : FileSystemCommandHandler("fs required_client_features")
670 const cmdmap_t
& cmdmap
,
671 std::stringstream
&ss
) override
674 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
675 ss
<< "Missing filesystem name";
678 auto fs
= fsmap
.get_filesystem(fs_name
);
680 ss
<< "Not found: '" << fs_name
<< "'";
684 if (!cmd_getval(cmdmap
, "subop", subop
) ||
685 (subop
!= "add" && subop
!= "rm")) {
686 ss
<< "Must either add or rm a feature; " << subop
<< " is not recognized";
690 if (!cmd_getval(cmdmap
, "val", val
) || val
.empty()) {
691 ss
<< "Missing feature id/name";
695 int feature
= cephfs_feature_from_name(val
);
698 feature
= strict_strtol(val
.c_str(), 10, &err
);
700 ss
<< "Invalid feature name: " << val
;
703 if (feature
< 0 || feature
> CEPHFS_FEATURE_MAX
) {
704 ss
<< "Invalid feature id: " << feature
;
709 if (subop
== "add") {
711 fsmap
.modify_filesystem(
713 [feature
, &ret
](auto&& fs
)
715 if (fs
->mds_map
.get_required_client_features().test(feature
))
717 fs
->mds_map
.add_required_client_feature(feature
);
721 ss
<< "added feature '" << cephfs_feature_name(feature
) << "' to required_client_features";
723 ss
<< "feature '" << cephfs_feature_name(feature
) << "' is already set";
727 fsmap
.modify_filesystem(
729 [feature
, &ret
](auto&& fs
)
731 if (!fs
->mds_map
.get_required_client_features().test(feature
))
733 fs
->mds_map
.remove_required_client_feature(feature
);
737 ss
<< "removed feature '" << cephfs_feature_name(feature
) << "' from required_client_features";
739 ss
<< "feature '" << cephfs_feature_name(feature
) << "' is already unset";
747 class AddDataPoolHandler
: public FileSystemCommandHandler
750 explicit AddDataPoolHandler(Paxos
*paxos
)
751 : FileSystemCommandHandler("fs add_data_pool"), m_paxos(paxos
)
754 bool batched_propose() override
{
762 const cmdmap_t
& cmdmap
,
763 std::stringstream
&ss
) override
765 ceph_assert(m_paxos
->is_plugged());
768 cmd_getval(cmdmap
, "pool", poolname
);
771 if (!cmd_getval(cmdmap
, "fs_name", fs_name
)
772 || fs_name
.empty()) {
773 ss
<< "Missing filesystem name";
777 int64_t poolid
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(poolname
);
780 poolid
= strict_strtol(poolname
.c_str(), 10, &err
);
782 ss
<< "pool '" << poolname
<< "' does not exist";
787 int r
= _check_pool(mon
->osdmon()->osdmap
, poolid
, POOL_DATA_EXTRA
, false, &ss
);
792 auto fs
= fsmap
.get_filesystem(fs_name
);
793 // no-op when the data_pool already on fs
794 if (fs
->mds_map
.is_data_pool(poolid
)) {
795 ss
<< "data pool " << poolid
<< " is already on fs " << fs_name
;
799 if (!mon
->osdmon()->is_writeable()) {
800 // not allowed to write yet, so retry when we can
801 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
804 mon
->osdmon()->do_application_enable(poolid
,
805 pg_pool_t::APPLICATION_NAME_CEPHFS
,
806 "data", fs_name
, true);
807 mon
->osdmon()->propose_pending();
809 fsmap
.modify_filesystem(
811 [poolid
](std::shared_ptr
<Filesystem
> fs
)
813 fs
->mds_map
.add_data_pool(poolid
);
816 ss
<< "added data pool " << poolid
<< " to fsmap";
825 class SetDefaultHandler
: public FileSystemCommandHandler
829 : FileSystemCommandHandler("fs set-default")
836 const cmdmap_t
& cmdmap
,
837 std::stringstream
&ss
) override
840 cmd_getval(cmdmap
, "fs_name", fs_name
);
841 auto fs
= fsmap
.get_filesystem(fs_name
);
843 ss
<< "filesystem '" << fs_name
<< "' does not exist";
847 fsmap
.set_legacy_client_fscid(fs
->fscid
);
852 class RemoveFilesystemHandler
: public FileSystemCommandHandler
855 RemoveFilesystemHandler()
856 : FileSystemCommandHandler("fs rm")
863 const cmdmap_t
& cmdmap
,
864 std::stringstream
&ss
) override
866 /* We may need to blocklist ranks. */
867 if (!mon
->osdmon()->is_writeable()) {
868 // not allowed to write yet, so retry when we can
869 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
873 // Check caller has correctly named the FS to delete
874 // (redundant while there is only one FS, but command
875 // syntax should apply to multi-FS future)
877 cmd_getval(cmdmap
, "fs_name", fs_name
);
878 auto fs
= fsmap
.get_filesystem(fs_name
);
880 // Consider absence success to make deletes idempotent
881 ss
<< "filesystem '" << fs_name
<< "' does not exist";
885 // Check that no MDS daemons are active
886 if (fs
->mds_map
.get_num_up_mds() > 0) {
887 ss
<< "all MDS daemons must be inactive/failed before removing filesystem. See `ceph fs fail`.";
891 // Check for confirmation flag
893 cmd_getval(cmdmap
, "yes_i_really_mean_it", sure
);
895 ss
<< "this is a DESTRUCTIVE operation and will make data in your filesystem permanently" \
896 " inaccessible. Add --yes-i-really-mean-it if you are sure you wish to continue.";
900 if (fsmap
.get_legacy_client_fscid() == fs
->fscid
) {
901 fsmap
.set_legacy_client_fscid(FS_CLUSTER_ID_NONE
);
904 std::vector
<mds_gid_t
> to_fail
;
905 // There may be standby_replay daemons left here
906 for (const auto &i
: fs
->mds_map
.get_mds_info()) {
907 ceph_assert(i
.second
.state
== MDSMap::STATE_STANDBY_REPLAY
);
908 to_fail
.push_back(i
.first
);
911 for (const auto &gid
: to_fail
) {
912 // Standby replays don't write, so it isn't important to
913 // wait for an osdmap propose here: ignore return value.
914 mon
->mdsmon()->fail_mds_gid(fsmap
, gid
);
916 if (!to_fail
.empty()) {
917 mon
->osdmon()->propose_pending(); /* maybe new blocklists */
920 fsmap
.erase_filesystem(fs
->fscid
);
926 class ResetFilesystemHandler
: public FileSystemCommandHandler
929 ResetFilesystemHandler()
930 : FileSystemCommandHandler("fs reset")
937 const cmdmap_t
& cmdmap
,
938 std::stringstream
&ss
) override
941 cmd_getval(cmdmap
, "fs_name", fs_name
);
942 auto fs
= fsmap
.get_filesystem(fs_name
);
944 ss
<< "filesystem '" << fs_name
<< "' does not exist";
945 // Unlike fs rm, we consider this case an error
949 // Check that no MDS daemons are active
950 if (fs
->mds_map
.get_num_up_mds() > 0) {
951 ss
<< "all MDS daemons must be inactive before resetting filesystem: set the cluster_down flag"
952 " and use `ceph mds fail` to make this so";
956 // Check for confirmation flag
958 cmd_getval(cmdmap
, "yes_i_really_mean_it", sure
);
960 ss
<< "this is a potentially destructive operation, only for use by experts in disaster recovery. "
961 "Add --yes-i-really-mean-it if you are sure you wish to continue.";
965 fsmap
.reset_filesystem(fs
->fscid
);
971 class RemoveDataPoolHandler
: public FileSystemCommandHandler
974 RemoveDataPoolHandler()
975 : FileSystemCommandHandler("fs rm_data_pool")
982 const cmdmap_t
& cmdmap
,
983 std::stringstream
&ss
) override
986 cmd_getval(cmdmap
, "pool", poolname
);
989 if (!cmd_getval(cmdmap
, "fs_name", fs_name
)
990 || fs_name
.empty()) {
991 ss
<< "Missing filesystem name";
995 int64_t poolid
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(poolname
);
998 poolid
= strict_strtol(poolname
.c_str(), 10, &err
);
1000 ss
<< "pool '" << poolname
<< "' does not exist";
1002 } else if (poolid
< 0) {
1003 ss
<< "invalid pool id '" << poolid
<< "'";
1008 ceph_assert(poolid
>= 0); // Checked by parsing code above
1010 auto fs
= fsmap
.get_filesystem(fs_name
);
1011 if (fs
->mds_map
.get_first_data_pool() == poolid
) {
1012 ss
<< "cannot remove default data pool";
1017 fsmap
.modify_filesystem(fs
->fscid
,
1018 [&r
, poolid
](std::shared_ptr
<Filesystem
> fs
)
1020 r
= fs
->mds_map
.remove_data_pool(poolid
);
1023 // It was already removed, succeed in silence
1025 } else if (r
== 0) {
1026 // We removed it, succeed
1027 ss
<< "removed data pool " << poolid
<< " from fsmap";
1030 // Unexpected error, bubble up
1037 * For commands with an alternative prefix
1039 template<typename T
>
1040 class AliasHandler
: public T
1042 std::string alias_prefix
;
1045 explicit AliasHandler(const std::string
&new_prefix
)
1048 alias_prefix
= new_prefix
;
1051 std::string
const &get_prefix() const override
{return alias_prefix
;}
1057 const cmdmap_t
& cmdmap
,
1058 std::stringstream
&ss
) override
1060 return T::handle(mon
, fsmap
, op
, cmdmap
, ss
);
1064 class MirrorHandlerEnable
: public FileSystemCommandHandler
1067 MirrorHandlerEnable()
1068 : FileSystemCommandHandler("fs mirror enable")
1071 int handle(Monitor
*mon
,
1072 FSMap
&fsmap
, MonOpRequestRef op
,
1073 const cmdmap_t
& cmdmap
, std::stringstream
&ss
) override
{
1074 std::string fs_name
;
1075 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
1076 ss
<< "Missing filesystem name";
1080 auto fs
= fsmap
.get_filesystem(fs_name
);
1081 if (fs
== nullptr) {
1082 ss
<< "Filesystem '" << fs_name
<< "' not found";
1086 if (fs
->mirror_info
.is_mirrored()) {
1090 auto f
= [](auto &&fs
) {
1091 fs
->mirror_info
.enable_mirroring();
1093 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
1099 class MirrorHandlerDisable
: public FileSystemCommandHandler
1102 MirrorHandlerDisable()
1103 : FileSystemCommandHandler("fs mirror disable")
1106 int handle(Monitor
*mon
,
1107 FSMap
&fsmap
, MonOpRequestRef op
,
1108 const cmdmap_t
& cmdmap
, std::stringstream
&ss
) override
{
1109 std::string fs_name
;
1110 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
1111 ss
<< "Missing filesystem name";
1115 auto fs
= fsmap
.get_filesystem(fs_name
);
1116 if (fs
== nullptr) {
1117 ss
<< "Filesystem '" << fs_name
<< "' not found";
1121 if (!fs
->mirror_info
.is_mirrored()) {
1125 auto f
= [](auto &&fs
) {
1126 fs
->mirror_info
.disable_mirroring();
1128 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
1134 class MirrorHandlerAddPeer
: public FileSystemCommandHandler
1137 MirrorHandlerAddPeer()
1138 : FileSystemCommandHandler("fs mirror peer_add")
1141 boost::optional
<std::pair
<string
, string
>>
1142 extract_remote_cluster_conf(const std::string
&spec
) {
1143 auto pos
= spec
.find("@");
1144 if (pos
== std::string_view::npos
) {
1145 return boost::optional
<std::pair
<string
, string
>>();
1148 auto client
= spec
.substr(0, pos
);
1149 auto cluster
= spec
.substr(pos
+1);
1151 return std::make_pair(client
, cluster
);
1154 bool peer_add(FSMap
&fsmap
, Filesystem::const_ref
&&fs
,
1155 const cmdmap_t
&cmdmap
, std::stringstream
&ss
) {
1158 string remote_fs_name
;
1159 cmd_getval(cmdmap
, "uuid", peer_uuid
);
1160 cmd_getval(cmdmap
, "remote_cluster_spec", remote_spec
);
1161 cmd_getval(cmdmap
, "remote_fs_name", remote_fs_name
);
1163 // verify (and extract) remote cluster specification
1164 auto remote_conf
= extract_remote_cluster_conf(remote_spec
);
1166 ss
<< "invalid remote cluster spec -- should be <client>@<cluster>";
1170 if (fs
->mirror_info
.has_peer(peer_uuid
)) {
1171 ss
<< "peer already exists";
1174 if (fs
->mirror_info
.has_peer((*remote_conf
).first
, (*remote_conf
).second
,
1176 ss
<< "peer already exists";
1180 auto f
= [peer_uuid
, remote_conf
, remote_fs_name
](auto &&fs
) {
1181 fs
->mirror_info
.peer_add(peer_uuid
, (*remote_conf
).first
,
1182 (*remote_conf
).second
, remote_fs_name
);
1184 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
1188 int handle(Monitor
*mon
,
1189 FSMap
&fsmap
, MonOpRequestRef op
,
1190 const cmdmap_t
& cmdmap
, std::stringstream
&ss
) override
{
1191 std::string fs_name
;
1192 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
1193 ss
<< "Missing filesystem name";
1197 auto fs
= fsmap
.get_filesystem(fs_name
);
1198 if (fs
== nullptr) {
1199 ss
<< "Filesystem '" << fs_name
<< "' not found";
1203 if (!fs
->mirror_info
.is_mirrored()) {
1204 ss
<< "Mirroring not enabled for filesystem '" << fs_name
<< "'";
1208 auto res
= peer_add(fsmap
, std::move(fs
), cmdmap
, ss
);
1217 class MirrorHandlerRemovePeer
: public FileSystemCommandHandler
1220 MirrorHandlerRemovePeer()
1221 : FileSystemCommandHandler("fs mirror peer_remove")
1224 bool peer_remove(FSMap
&fsmap
, Filesystem::const_ref
&&fs
,
1225 const cmdmap_t
&cmdmap
, std::stringstream
&ss
) {
1227 cmd_getval(cmdmap
, "uuid", peer_uuid
);
1229 if (!fs
->mirror_info
.has_peer(peer_uuid
)) {
1230 ss
<< "cannot find peer with uuid: " << peer_uuid
;
1234 auto f
= [peer_uuid
](auto &&fs
) {
1235 fs
->mirror_info
.peer_remove(peer_uuid
);
1237 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
1241 int handle(Monitor
*mon
,
1242 FSMap
&fsmap
, MonOpRequestRef op
,
1243 const cmdmap_t
& cmdmap
, std::stringstream
&ss
) override
{
1244 std::string fs_name
;
1245 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
1246 ss
<< "Missing filesystem name";
1250 auto fs
= fsmap
.get_filesystem(fs_name
);
1251 if (fs
== nullptr) {
1252 ss
<< "Filesystem '" << fs_name
<< "' not found";
1256 if (!fs
->mirror_info
.is_mirrored()) {
1257 ss
<< "Mirroring not enabled for filesystem '" << fs_name
<< "'";
1261 auto res
= peer_remove(fsmap
, std::move(fs
), cmdmap
, ss
);
1270 std::list
<std::shared_ptr
<FileSystemCommandHandler
> >
1271 FileSystemCommandHandler::load(Paxos
*paxos
)
1273 std::list
<std::shared_ptr
<FileSystemCommandHandler
> > handlers
;
1275 handlers
.push_back(std::make_shared
<SetHandler
>());
1276 handlers
.push_back(std::make_shared
<FailHandler
>());
1277 handlers
.push_back(std::make_shared
<FlagSetHandler
>());
1278 handlers
.push_back(std::make_shared
<RequiredClientFeaturesHandler
>());
1279 handlers
.push_back(std::make_shared
<AddDataPoolHandler
>(paxos
));
1280 handlers
.push_back(std::make_shared
<RemoveDataPoolHandler
>());
1281 handlers
.push_back(std::make_shared
<FsNewHandler
>(paxos
));
1282 handlers
.push_back(std::make_shared
<RemoveFilesystemHandler
>());
1283 handlers
.push_back(std::make_shared
<ResetFilesystemHandler
>());
1285 handlers
.push_back(std::make_shared
<SetDefaultHandler
>());
1286 handlers
.push_back(std::make_shared
<AliasHandler
<SetDefaultHandler
> >(
1288 handlers
.push_back(std::make_shared
<MirrorHandlerEnable
>());
1289 handlers
.push_back(std::make_shared
<MirrorHandlerDisable
>());
1290 handlers
.push_back(std::make_shared
<MirrorHandlerAddPeer
>());
1291 handlers
.push_back(std::make_shared
<MirrorHandlerRemovePeer
>());
1296 int FileSystemCommandHandler::_check_pool(
1298 const int64_t pool_id
,
1301 std::stringstream
*ss
) const
1303 ceph_assert(ss
!= NULL
);
1305 const pg_pool_t
*pool
= osd_map
.get_pg_pool(pool_id
);
1307 *ss
<< "pool id '" << pool_id
<< "' does not exist";
1311 const string
& pool_name
= osd_map
.get_pool_name(pool_id
);
1313 if (pool
->is_erasure()) {
1314 if (type
== POOL_METADATA
) {
1315 *ss
<< "pool '" << pool_name
<< "' (id '" << pool_id
<< "')"
1316 << " is an erasure-coded pool. Use of erasure-coded pools"
1317 << " for CephFS metadata is not permitted";
1319 } else if (type
== POOL_DATA_DEFAULT
&& !force
) {
1320 *ss
<< "pool '" << pool_name
<< "' (id '" << pool_id
<< "')"
1321 " is an erasure-coded pool."
1322 " Use of an EC pool for the default data pool is discouraged;"
1323 " see the online CephFS documentation for more information."
1324 " Use --force to override.";
1326 } else if (!pool
->allows_ecoverwrites()) {
1327 // non-overwriteable EC pools are only acceptable with a cache tier overlay
1328 if (!pool
->has_tiers() || !pool
->has_read_tier() || !pool
->has_write_tier()) {
1329 *ss
<< "pool '" << pool_name
<< "' (id '" << pool_id
<< "')"
1330 << " is an erasure-coded pool, with no overwrite support";
1334 // That cache tier overlay must be writeback, not readonly (it's the
1335 // write operations like modify+truncate we care about support for)
1336 const pg_pool_t
*write_tier
= osd_map
.get_pg_pool(
1338 ceph_assert(write_tier
!= NULL
); // OSDMonitor shouldn't allow DNE tier
1339 if (write_tier
->cache_mode
== pg_pool_t::CACHEMODE_FORWARD
1340 || write_tier
->cache_mode
== pg_pool_t::CACHEMODE_READONLY
) {
1341 *ss
<< "EC pool '" << pool_name
<< "' has a write tier ("
1342 << osd_map
.get_pool_name(pool
->write_tier
)
1343 << ") that is configured "
1344 "to forward writes. Use a cache mode such as 'writeback' for "
1351 if (pool
->is_tier()) {
1352 *ss
<< " pool '" << pool_name
<< "' (id '" << pool_id
1353 << "') is already in use as a cache tier.";
1357 if (!force
&& !pool
->application_metadata
.empty() &&
1358 pool
->application_metadata
.count(
1359 pg_pool_t::APPLICATION_NAME_CEPHFS
) == 0) {
1360 *ss
<< " pool '" << pool_name
<< "' (id '" << pool_id
1361 << "') has a non-CephFS application enabled.";
1365 // Nothing special about this pool, so it is permissible
1369 int FileSystemCommandHandler::is_op_allowed(
1370 const MonOpRequestRef
& op
, const FSMap
& fsmap
, const cmdmap_t
& cmdmap
,
1371 std::stringstream
&ss
) const
1374 cmd_getval(cmdmap
, "fs_name", fs_name
);
1376 // so that fsmap can filtered and the original copy is untouched.
1377 FSMap fsmap_copy
= fsmap
;
1378 fsmap_copy
.filter(op
->get_session()->get_allowed_fs_names());
1380 auto fs
= fsmap_copy
.get_filesystem(fs_name
);
1381 if (fs
== nullptr) {
1382 /* let "fs rm" handle idempotent case where file system does not exist */
1383 if (!(get_prefix() == "fs rm" && fsmap
.get_filesystem(fs_name
) == nullptr)) {
1384 ss
<< "Filesystem not found: '" << fs_name
<< "'";
1389 if (!op
->get_session()->fs_name_capable(fs_name
, MON_CAP_W
)) {
1390 ss
<< "Permission denied: '" << fs_name
<< "'";