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"
22 using TOPNSPC::common::cmd_getval
;
24 static const string
EXPERIMENTAL_WARNING("Warning! This feature is experimental."
25 "It may cause problems up to and including data loss."
26 "Consult the documentation at ceph.com, and if unsure, do not proceed."
27 "Add --yes-i-really-mean-it if you are certain.");
31 class FlagSetHandler
: public FileSystemCommandHandler
35 : FileSystemCommandHandler("fs flag set")
43 const cmdmap_t
& cmdmap
,
44 std::stringstream
&ss
) override
47 cmd_getval(cmdmap
, "flag_name", flag_name
);
50 cmd_getval(cmdmap
, "val", flag_val
);
53 cmd_getval(cmdmap
, "yes_i_really_mean_it", sure
);
55 if (flag_name
== "enable_multiple") {
56 bool flag_bool
= false;
57 int r
= parse_bool(flag_val
, &flag_bool
, ss
);
59 ss
<< "Invalid boolean value '" << flag_val
<< "'";
64 ss
<< EXPERIMENTAL_WARNING
;
66 fsmap
.set_enable_multiple(flag_bool
);
69 ss
<< "Unknown flag '" << flag_name
<< "'";
75 class FailHandler
: public FileSystemCommandHandler
79 : FileSystemCommandHandler("fs fail")
87 const cmdmap_t
& cmdmap
,
88 std::stringstream
& ss
) override
90 if (!mon
->osdmon()->is_writeable()) {
91 // not allowed to write yet, so retry when we can
92 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
97 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
98 ss
<< "Missing filesystem name";
102 auto fs
= fsmap
.get_filesystem(fs_name
);
104 ss
<< "Not found: '" << fs_name
<< "'";
108 auto f
= [](auto fs
) {
109 fs
->mds_map
.set_flag(CEPH_MDSMAP_NOT_JOINABLE
);
111 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
113 std::vector
<mds_gid_t
> to_fail
;
114 for (const auto& p
: fs
->mds_map
.get_mds_info()) {
115 to_fail
.push_back(p
.first
);
118 for (const auto& gid
: to_fail
) {
119 mon
->mdsmon()->fail_mds_gid(fsmap
, gid
);
121 if (!to_fail
.empty()) {
122 mon
->osdmon()->propose_pending();
126 ss
<< " marked not joinable; MDS cannot join the cluster. All MDS ranks marked failed.";
132 class FsNewHandler
: public FileSystemCommandHandler
135 explicit FsNewHandler(Paxos
*paxos
)
136 : FileSystemCommandHandler("fs new"), m_paxos(paxos
)
140 bool batched_propose() override
{
148 const cmdmap_t
& cmdmap
,
149 std::stringstream
&ss
) override
151 ceph_assert(m_paxos
->is_plugged());
153 string metadata_name
;
154 cmd_getval(cmdmap
, "metadata", metadata_name
);
155 int64_t metadata
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(metadata_name
);
157 ss
<< "pool '" << metadata_name
<< "' does not exist";
162 cmd_getval(cmdmap
, "data", data_name
);
163 int64_t data
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(data_name
);
165 ss
<< "pool '" << data_name
<< "' does not exist";
169 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.";
174 cmd_getval(cmdmap
, "fs_name", fs_name
);
175 if (fs_name
.empty()) {
176 // Ensure fs name is not empty so that we can implement
177 // commmands that refer to FS by name in future.
178 ss
<< "Filesystem name may not be empty";
182 if (fsmap
.get_filesystem(fs_name
)) {
183 auto fs
= fsmap
.get_filesystem(fs_name
);
184 if (*(fs
->mds_map
.get_data_pools().begin()) == data
185 && fs
->mds_map
.get_metadata_pool() == metadata
) {
186 // Identical FS created already, this is a no-op
187 ss
<< "filesystem '" << fs_name
<< "' already exists";
190 ss
<< "filesystem already exists with name '" << fs_name
<< "'";
196 cmd_getval(cmdmap
, "force", force
);
198 const pool_stat_t
*stat
= mon
->mgrstatmon()->get_pool_stat(metadata
);
200 int64_t metadata_num_objects
= stat
->stats
.sum
.num_objects
;
201 if (!force
&& metadata_num_objects
> 0) {
202 ss
<< "pool '" << metadata_name
203 << "' already contains some objects. Use an empty pool instead.";
208 if (fsmap
.filesystem_count() > 0
209 && !fsmap
.get_enable_multiple()) {
210 ss
<< "Creation of multiple filesystems is disabled. To enable "
211 "this experimental feature, use 'ceph fs flag set enable_multiple "
216 for (auto& fs
: fsmap
.get_filesystems()) {
217 const std::vector
<int64_t> &data_pools
= fs
->mds_map
.get_data_pools();
221 "allow_dangerous_metadata_overlay", sure
);
223 if ((std::find(data_pools
.begin(), data_pools
.end(), data
) != data_pools
.end()
224 || fs
->mds_map
.get_metadata_pool() == metadata
)
226 ss
<< "Filesystem '" << fs_name
227 << "' 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.";
232 pg_pool_t
const *data_pool
= mon
->osdmon()->osdmap
.get_pg_pool(data
);
233 ceph_assert(data_pool
!= NULL
); // Checked it existed above
234 pg_pool_t
const *metadata_pool
= mon
->osdmon()->osdmap
.get_pg_pool(metadata
);
235 ceph_assert(metadata_pool
!= NULL
); // Checked it existed above
237 int r
= _check_pool(mon
->osdmon()->osdmap
, data
, POOL_DATA_DEFAULT
, force
, &ss
);
242 r
= _check_pool(mon
->osdmon()->osdmap
, metadata
, POOL_METADATA
, force
, &ss
);
247 if (!mon
->osdmon()->is_writeable()) {
248 // not allowed to write yet, so retry when we can
249 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
252 mon
->osdmon()->do_application_enable(data
,
253 pg_pool_t::APPLICATION_NAME_CEPHFS
,
254 "data", fs_name
, true);
255 mon
->osdmon()->do_application_enable(metadata
,
256 pg_pool_t::APPLICATION_NAME_CEPHFS
,
257 "metadata", fs_name
, true);
258 mon
->osdmon()->do_set_pool_opt(metadata
,
259 pool_opts_t::RECOVERY_PRIORITY
,
260 static_cast<int64_t>(5));
261 mon
->osdmon()->do_set_pool_opt(metadata
,
262 pool_opts_t::PG_NUM_MIN
,
263 static_cast<int64_t>(16));
264 mon
->osdmon()->do_set_pool_opt(metadata
,
265 pool_opts_t::PG_AUTOSCALE_BIAS
,
266 static_cast<double>(4.0));
267 mon
->osdmon()->propose_pending();
269 // All checks passed, go ahead and create.
270 auto&& fs
= fsmap
.create_filesystem(fs_name
, metadata
, data
,
271 mon
->get_quorum_con_features());
273 ss
<< "new fs with metadata pool " << metadata
<< " and data pool " << data
;
275 // assign a standby to rank 0 to avoid health warnings
276 auto info
= fsmap
.find_replacement_for({fs
->fscid
, 0});
279 mon
->clog
->info() << info
->human_name() << " assigned to filesystem "
280 << fs_name
<< " as rank 0";
281 fsmap
.promote(info
->global_id
, *fs
, 0);
291 class SetHandler
: public FileSystemCommandHandler
295 : FileSystemCommandHandler("fs set")
302 const cmdmap_t
& cmdmap
,
303 std::stringstream
&ss
) override
306 if (!cmd_getval(cmdmap
, "fs_name", fs_name
) || fs_name
.empty()) {
307 ss
<< "Missing filesystem name";
311 auto fs
= fsmap
.get_filesystem(fs_name
);
313 ss
<< "Not found: '" << fs_name
<< "'";
318 if (!cmd_getval(cmdmap
, "var", var
) || var
.empty()) {
319 ss
<< "Invalid variable";
325 if (!cmd_getval(cmdmap
, "val", val
)) {
328 // we got a string. see if it contains an int.
329 n
= strict_strtoll(val
.c_str(), 10, &interr
);
330 if (var
== "max_mds") {
331 // NOTE: see also "mds set_max_mds", which can modify the same field.
332 if (interr
.length()) {
338 ss
<< "You must specify at least one MDS";
341 if (n
> 1 && n
> fs
->mds_map
.get_max_mds()) {
342 if (fs
->mds_map
.was_snaps_ever_allowed() &&
343 !fs
->mds_map
.allows_multimds_snaps()) {
344 ss
<< "multi-active MDS is not allowed while there are snapshots possibly created by pre-mimic MDS";
349 ss
<< "may not have more than " << MAX_MDS
<< " MDS ranks";
353 fsmap
.modify_filesystem(
355 [n
](std::shared_ptr
<Filesystem
> fs
)
357 fs
->mds_map
.clear_flag(CEPH_MDSMAP_NOT_JOINABLE
);
358 fs
->mds_map
.set_max_mds(n
);
360 } else if (var
== "inline_data") {
361 bool enable_inline
= false;
362 int r
= parse_bool(val
, &enable_inline
, ss
);
368 bool confirm
= false;
369 cmd_getval(cmdmap
, "yes_i_really_really_mean_it", confirm
);
371 ss
<< "Inline data support is deprecated and will be removed in a future release. "
372 << "Add --yes-i-really-really-mean-it if you are certain you want this enabled.";
375 ss
<< "inline data enabled";
377 fsmap
.modify_filesystem(
379 [](std::shared_ptr
<Filesystem
> fs
)
381 fs
->mds_map
.set_inline_data_enabled(true);
385 CompatSet c
= fsmap
.get_compat();
386 c
.incompat
.insert(MDS_FEATURE_INCOMPAT_INLINE
);
387 fsmap
.update_compat(c
);
389 ss
<< "inline data disabled";
390 fsmap
.modify_filesystem(
392 [](std::shared_ptr
<Filesystem
> fs
)
394 fs
->mds_map
.set_inline_data_enabled(false);
397 } else if (var
== "balancer") {
399 ss
<< "unsetting the metadata load balancer";
401 ss
<< "setting the metadata load balancer to " << val
;
403 fsmap
.modify_filesystem(
405 [val
](std::shared_ptr
<Filesystem
> fs
)
407 fs
->mds_map
.set_balancer(val
);
410 } else if (var
== "max_file_size") {
411 if (interr
.length()) {
412 ss
<< var
<< " requires an integer value";
415 if (n
< CEPH_MIN_STRIPE_UNIT
) {
416 ss
<< var
<< " must at least " << CEPH_MIN_STRIPE_UNIT
;
419 fsmap
.modify_filesystem(
421 [n
](std::shared_ptr
<Filesystem
> fs
)
423 fs
->mds_map
.set_max_filesize(n
);
425 } else if (var
== "allow_new_snaps") {
426 bool enable_snaps
= false;
427 int r
= parse_bool(val
, &enable_snaps
, ss
);
433 fsmap
.modify_filesystem(
435 [](std::shared_ptr
<Filesystem
> fs
)
437 fs
->mds_map
.clear_snaps_allowed();
439 ss
<< "disabled new snapshots";
441 fsmap
.modify_filesystem(
443 [](std::shared_ptr
<Filesystem
> fs
)
445 fs
->mds_map
.set_snaps_allowed();
447 ss
<< "enabled new snapshots";
449 } else if (var
== "allow_multimds") {
450 ss
<< "Multiple MDS is always enabled. Use the max_mds"
451 << " parameter to control the number of active MDSs"
452 << " allowed. This command is DEPRECATED and will be"
453 << " REMOVED from future releases.";
454 } else if (var
== "allow_multimds_snaps") {
456 int r
= parse_bool(val
, &enable
, ss
);
462 if (!cmd_getval(cmdmap
, "confirm", confirm
) ||
463 confirm
!= "--yes-i-am-really-a-mds") {
464 ss
<< "Warning! This command is for MDS only. Do not run it manually";
469 ss
<< "enabled multimds with snapshot";
470 fsmap
.modify_filesystem(
472 [](std::shared_ptr
<Filesystem
> fs
)
474 fs
->mds_map
.set_multimds_snaps_allowed();
477 ss
<< "disabled multimds with snapshot";
478 fsmap
.modify_filesystem(
480 [](std::shared_ptr
<Filesystem
> fs
)
482 fs
->mds_map
.clear_multimds_snaps_allowed();
485 } else if (var
== "allow_dirfrags") {
486 ss
<< "Directory fragmentation is now permanently enabled."
487 << " This command is DEPRECATED and will be REMOVED from future releases.";
488 } else if (var
== "down") {
489 bool is_down
= false;
490 int r
= parse_bool(val
, &is_down
, ss
);
495 ss
<< fs
->mds_map
.get_fs_name();
497 fsmap
.modify_filesystem(
499 [is_down
](std::shared_ptr
<Filesystem
> fs
)
502 if (fs
->mds_map
.get_max_mds() > 0) {
503 fs
->mds_map
.set_old_max_mds();
504 fs
->mds_map
.set_max_mds(0);
505 } /* else already down! */
507 mds_rank_t oldmax
= fs
->mds_map
.get_old_max_mds();
508 fs
->mds_map
.set_max_mds(oldmax
? oldmax
: 1);
513 ss
<< " marked down. ";
515 ss
<< " marked up, max_mds = " << fs
->mds_map
.get_max_mds();
517 } else if (var
== "cluster_down" || var
== "joinable") {
518 bool joinable
= true;
519 int r
= parse_bool(val
, &joinable
, ss
);
523 if (var
== "cluster_down") {
524 joinable
= !joinable
;
527 ss
<< fs
->mds_map
.get_fs_name();
529 fsmap
.modify_filesystem(
531 [joinable
](std::shared_ptr
<Filesystem
> fs
)
534 fs
->mds_map
.clear_flag(CEPH_MDSMAP_NOT_JOINABLE
);
536 fs
->mds_map
.set_flag(CEPH_MDSMAP_NOT_JOINABLE
);
541 ss
<< " marked joinable; MDS may join as newly active.";
543 ss
<< " marked not joinable; MDS cannot join as newly active.";
546 if (var
== "cluster_down") {
547 ss
<< " WARNING: cluster_down flag is deprecated and will be"
548 << " removed in a future version. Please use \"joinable\".";
550 } else if (var
== "standby_count_wanted") {
551 if (interr
.length()) {
552 ss
<< var
<< " requires an integer value";
556 ss
<< var
<< " must be non-negative";
559 fsmap
.modify_filesystem(
561 [n
](std::shared_ptr
<Filesystem
> fs
)
563 fs
->mds_map
.set_standby_count_wanted(n
);
565 } else if (var
== "session_timeout") {
566 if (interr
.length()) {
567 ss
<< var
<< " requires an integer value";
571 ss
<< var
<< " must be at least 30s";
574 fsmap
.modify_filesystem(
576 [n
](std::shared_ptr
<Filesystem
> fs
)
578 fs
->mds_map
.set_session_timeout((uint32_t)n
);
580 } else if (var
== "session_autoclose") {
581 if (interr
.length()) {
582 ss
<< var
<< " requires an integer value";
586 ss
<< var
<< " must be at least 30s";
589 fsmap
.modify_filesystem(
591 [n
](std::shared_ptr
<Filesystem
> fs
)
593 fs
->mds_map
.set_session_autoclose((uint32_t)n
);
595 } else if (var
== "allow_standby_replay") {
597 int r
= parse_bool(val
, &allow
, ss
);
602 auto f
= [allow
](auto& fs
) {
604 fs
->mds_map
.set_standby_replay_allowed();
606 fs
->mds_map
.clear_standby_replay_allowed();
609 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
610 } else if (var
== "min_compat_client") {
611 auto vno
= ceph_release_from_name(val
.c_str());
613 ss
<< "version " << val
<< " is not recognized";
616 auto f
= [vno
](auto&& fs
) {
617 fs
->mds_map
.set_min_compat_client(vno
);
619 fsmap
.modify_filesystem(fs
->fscid
, std::move(f
));
621 ss
<< "unknown variable " << var
;
629 class AddDataPoolHandler
: public FileSystemCommandHandler
632 explicit AddDataPoolHandler(Paxos
*paxos
)
633 : FileSystemCommandHandler("fs add_data_pool"), m_paxos(paxos
)
636 bool batched_propose() override
{
644 const cmdmap_t
& cmdmap
,
645 std::stringstream
&ss
) override
647 ceph_assert(m_paxos
->is_plugged());
650 cmd_getval(cmdmap
, "pool", poolname
);
653 if (!cmd_getval(cmdmap
, "fs_name", fs_name
)
654 || fs_name
.empty()) {
655 ss
<< "Missing filesystem name";
659 auto fs
= fsmap
.get_filesystem(fs_name
);
661 ss
<< "Not found: '" << fs_name
<< "'";
665 int64_t poolid
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(poolname
);
668 poolid
= strict_strtol(poolname
.c_str(), 10, &err
);
670 ss
<< "pool '" << poolname
<< "' does not exist";
675 int r
= _check_pool(mon
->osdmon()->osdmap
, poolid
, POOL_DATA_EXTRA
, false, &ss
);
680 // no-op when the data_pool already on fs
681 if (fs
->mds_map
.is_data_pool(poolid
)) {
682 ss
<< "data pool " << poolid
<< " is already on fs " << fs_name
;
686 if (!mon
->osdmon()->is_writeable()) {
687 // not allowed to write yet, so retry when we can
688 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
691 mon
->osdmon()->do_application_enable(poolid
,
692 pg_pool_t::APPLICATION_NAME_CEPHFS
,
693 "data", fs_name
, true);
694 mon
->osdmon()->propose_pending();
696 fsmap
.modify_filesystem(
698 [poolid
](std::shared_ptr
<Filesystem
> fs
)
700 fs
->mds_map
.add_data_pool(poolid
);
703 ss
<< "added data pool " << poolid
<< " to fsmap";
712 class SetDefaultHandler
: public FileSystemCommandHandler
716 : FileSystemCommandHandler("fs set-default")
723 const cmdmap_t
& cmdmap
,
724 std::stringstream
&ss
) override
727 cmd_getval(cmdmap
, "fs_name", fs_name
);
728 auto fs
= fsmap
.get_filesystem(fs_name
);
730 ss
<< "filesystem '" << fs_name
<< "' does not exist";
734 fsmap
.set_legacy_client_fscid(fs
->fscid
);
739 class RemoveFilesystemHandler
: public FileSystemCommandHandler
742 RemoveFilesystemHandler()
743 : FileSystemCommandHandler("fs rm")
750 const cmdmap_t
& cmdmap
,
751 std::stringstream
&ss
) override
753 /* We may need to blacklist ranks. */
754 if (!mon
->osdmon()->is_writeable()) {
755 // not allowed to write yet, so retry when we can
756 mon
->osdmon()->wait_for_writeable(op
, new PaxosService::C_RetryMessage(mon
->mdsmon(), op
));
760 // Check caller has correctly named the FS to delete
761 // (redundant while there is only one FS, but command
762 // syntax should apply to multi-FS future)
764 cmd_getval(cmdmap
, "fs_name", fs_name
);
765 auto fs
= fsmap
.get_filesystem(fs_name
);
767 // Consider absence success to make deletes idempotent
768 ss
<< "filesystem '" << fs_name
<< "' does not exist";
772 // Check that no MDS daemons are active
773 if (fs
->mds_map
.get_num_up_mds() > 0) {
774 ss
<< "all MDS daemons must be inactive/failed before removing filesystem. See `ceph fs fail`.";
778 // Check for confirmation flag
780 cmd_getval(cmdmap
, "yes_i_really_mean_it", sure
);
782 ss
<< "this is a DESTRUCTIVE operation and will make data in your filesystem permanently" \
783 " inaccessible. Add --yes-i-really-mean-it if you are sure you wish to continue.";
787 if (fsmap
.get_legacy_client_fscid() == fs
->fscid
) {
788 fsmap
.set_legacy_client_fscid(FS_CLUSTER_ID_NONE
);
791 std::vector
<mds_gid_t
> to_fail
;
792 // There may be standby_replay daemons left here
793 for (const auto &i
: fs
->mds_map
.get_mds_info()) {
794 ceph_assert(i
.second
.state
== MDSMap::STATE_STANDBY_REPLAY
);
795 to_fail
.push_back(i
.first
);
798 for (const auto &gid
: to_fail
) {
799 // Standby replays don't write, so it isn't important to
800 // wait for an osdmap propose here: ignore return value.
801 mon
->mdsmon()->fail_mds_gid(fsmap
, gid
);
803 if (!to_fail
.empty()) {
804 mon
->osdmon()->propose_pending(); /* maybe new blacklists */
807 fsmap
.erase_filesystem(fs
->fscid
);
813 class ResetFilesystemHandler
: public FileSystemCommandHandler
816 ResetFilesystemHandler()
817 : FileSystemCommandHandler("fs reset")
824 const cmdmap_t
& cmdmap
,
825 std::stringstream
&ss
) override
828 cmd_getval(cmdmap
, "fs_name", fs_name
);
829 auto fs
= fsmap
.get_filesystem(fs_name
);
831 ss
<< "filesystem '" << fs_name
<< "' does not exist";
832 // Unlike fs rm, we consider this case an error
836 // Check that no MDS daemons are active
837 if (fs
->mds_map
.get_num_up_mds() > 0) {
838 ss
<< "all MDS daemons must be inactive before resetting filesystem: set the cluster_down flag"
839 " and use `ceph mds fail` to make this so";
843 // Check for confirmation flag
845 cmd_getval(cmdmap
, "yes_i_really_mean_it", sure
);
847 ss
<< "this is a potentially destructive operation, only for use by experts in disaster recovery. "
848 "Add --yes-i-really-mean-it if you are sure you wish to continue.";
852 fsmap
.reset_filesystem(fs
->fscid
);
858 class RemoveDataPoolHandler
: public FileSystemCommandHandler
861 RemoveDataPoolHandler()
862 : FileSystemCommandHandler("fs rm_data_pool")
869 const cmdmap_t
& cmdmap
,
870 std::stringstream
&ss
) override
873 cmd_getval(cmdmap
, "pool", poolname
);
876 if (!cmd_getval(cmdmap
, "fs_name", fs_name
)
877 || fs_name
.empty()) {
878 ss
<< "Missing filesystem name";
882 auto fs
= fsmap
.get_filesystem(fs_name
);
884 ss
<< "Not found: '" << fs_name
<< "'";
888 int64_t poolid
= mon
->osdmon()->osdmap
.lookup_pg_pool_name(poolname
);
891 poolid
= strict_strtol(poolname
.c_str(), 10, &err
);
893 ss
<< "pool '" << poolname
<< "' does not exist";
895 } else if (poolid
< 0) {
896 ss
<< "invalid pool id '" << poolid
<< "'";
901 ceph_assert(poolid
>= 0); // Checked by parsing code above
903 if (fs
->mds_map
.get_first_data_pool() == poolid
) {
904 ss
<< "cannot remove default data pool";
910 fsmap
.modify_filesystem(fs
->fscid
,
911 [&r
, poolid
](std::shared_ptr
<Filesystem
> fs
)
913 r
= fs
->mds_map
.remove_data_pool(poolid
);
916 // It was already removed, succeed in silence
919 // We removed it, succeed
920 ss
<< "removed data pool " << poolid
<< " from fsmap";
923 // Unexpected error, bubble up
930 * For commands with an alternative prefix
933 class AliasHandler
: public T
935 std::string alias_prefix
;
938 explicit AliasHandler(const std::string
&new_prefix
)
941 alias_prefix
= new_prefix
;
944 std::string
const &get_prefix() override
{return alias_prefix
;}
950 const cmdmap_t
& cmdmap
,
951 std::stringstream
&ss
) override
953 return T::handle(mon
, fsmap
, op
, cmdmap
, ss
);
958 std::list
<std::shared_ptr
<FileSystemCommandHandler
> >
959 FileSystemCommandHandler::load(Paxos
*paxos
)
961 std::list
<std::shared_ptr
<FileSystemCommandHandler
> > handlers
;
963 handlers
.push_back(std::make_shared
<SetHandler
>());
964 handlers
.push_back(std::make_shared
<FailHandler
>());
965 handlers
.push_back(std::make_shared
<FlagSetHandler
>());
966 handlers
.push_back(std::make_shared
<AddDataPoolHandler
>(paxos
));
967 handlers
.push_back(std::make_shared
<RemoveDataPoolHandler
>());
968 handlers
.push_back(std::make_shared
<FsNewHandler
>(paxos
));
969 handlers
.push_back(std::make_shared
<RemoveFilesystemHandler
>());
970 handlers
.push_back(std::make_shared
<ResetFilesystemHandler
>());
972 handlers
.push_back(std::make_shared
<SetDefaultHandler
>());
973 handlers
.push_back(std::make_shared
<AliasHandler
<SetDefaultHandler
> >(
979 int FileSystemCommandHandler::_check_pool(
981 const int64_t pool_id
,
984 std::stringstream
*ss
) const
986 ceph_assert(ss
!= NULL
);
988 const pg_pool_t
*pool
= osd_map
.get_pg_pool(pool_id
);
990 *ss
<< "pool id '" << pool_id
<< "' does not exist";
994 const string
& pool_name
= osd_map
.get_pool_name(pool_id
);
996 if (pool
->is_erasure()) {
997 if (type
== POOL_METADATA
) {
998 *ss
<< "pool '" << pool_name
<< "' (id '" << pool_id
<< "')"
999 << " is an erasure-coded pool. Use of erasure-coded pools"
1000 << " for CephFS metadata is not permitted";
1002 } else if (type
== POOL_DATA_DEFAULT
&& !force
) {
1003 *ss
<< "pool '" << pool_name
<< "' (id '" << pool_id
<< "')"
1004 " is an erasure-coded pool."
1005 " Use of an EC pool for the default data pool is discouraged;"
1006 " see the online CephFS documentation for more information."
1007 " Use --force to override.";
1009 } else if (!pool
->allows_ecoverwrites()) {
1010 // non-overwriteable EC pools are only acceptable with a cache tier overlay
1011 if (!pool
->has_tiers() || !pool
->has_read_tier() || !pool
->has_write_tier()) {
1012 *ss
<< "pool '" << pool_name
<< "' (id '" << pool_id
<< "')"
1013 << " is an erasure-coded pool, with no overwrite support";
1017 // That cache tier overlay must be writeback, not readonly (it's the
1018 // write operations like modify+truncate we care about support for)
1019 const pg_pool_t
*write_tier
= osd_map
.get_pg_pool(
1021 ceph_assert(write_tier
!= NULL
); // OSDMonitor shouldn't allow DNE tier
1022 if (write_tier
->cache_mode
== pg_pool_t::CACHEMODE_FORWARD
1023 || write_tier
->cache_mode
== pg_pool_t::CACHEMODE_READONLY
) {
1024 *ss
<< "EC pool '" << pool_name
<< "' has a write tier ("
1025 << osd_map
.get_pool_name(pool
->write_tier
)
1026 << ") that is configured "
1027 "to forward writes. Use a cache mode such as 'writeback' for "
1034 if (pool
->is_tier()) {
1035 *ss
<< " pool '" << pool_name
<< "' (id '" << pool_id
1036 << "') is already in use as a cache tier.";
1040 if (!force
&& !pool
->application_metadata
.empty() &&
1041 pool
->application_metadata
.count(
1042 pg_pool_t::APPLICATION_NAME_CEPHFS
) == 0) {
1043 *ss
<< " pool '" << pool_name
<< "' (id '" << pool_id
1044 << "') has a non-CephFS application enabled.";
1048 // Nothing special about this pool, so it is permissible