From 9a2596d7b07c51ae16ec37867e0757a322e04df0 Mon Sep 17 00:00:00 2001 From: Patrick Donnelly Date: Mon, 10 Oct 2016 17:06:52 -0400 Subject: [PATCH] mds: fully encapsulate filesystems map Signed-off-by: Patrick Donnelly (cherry picked from commit de6c36af022da9599b04b59e5300fbb6a3de938f) --- src/mds/FSMap.h | 12 +++--------- src/mon/MDSMonitor.cc | 5 ++--- src/mon/Monitor.cc | 2 +- src/tools/cephfs/DataScan.cc | 4 ++-- src/tools/cephfs/RoleSelector.cc | 4 ++-- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/src/mds/FSMap.h b/src/mds/FSMap.h index d14e365a652a8..46614f69809bd 100644 --- a/src/mds/FSMap.h +++ b/src/mds/FSMap.h @@ -375,21 +375,15 @@ public: }); } - const std::map > &get_filesystems() const - { - return filesystems; - } - bool any_filesystems() const {return !filesystems.empty(); } + size_t filesystem_count() const {return filesystems.size();} bool filesystem_exists(fs_cluster_id_t fscid) const {return filesystems.count(fscid) > 0;} epoch_t get_epoch() const { return epoch; } void inc_epoch() { epoch++; } - std::shared_ptr get_filesystem(fs_cluster_id_t fscid) const - { - return std::const_pointer_cast(filesystems.at(fscid)); - } + std::shared_ptr get_filesystem(fs_cluster_id_t fscid) const {return std::const_pointer_cast(filesystems.at(fscid));} + std::shared_ptr get_filesystem(void) const {return std::const_pointer_cast(filesystems.begin()->second);} int parse_filesystem( std::string const &ns_str, diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index b91e360e0f6d7..fc9c1d09b0853 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -1555,7 +1555,7 @@ int MDSMonitor::management_command( } } - if (pending_fsmap.any_filesystems() + if (pending_fsmap.filesystem_count() > 0 && !pending_fsmap.get_enable_multiple()) { ss << "Creation of multiple filesystems is disabled. To enable " "this experimental feature, use 'ceph fs flag set enable_multiple " @@ -2819,8 +2819,7 @@ bool MDSMonitor::maybe_promote_standby(std::shared_ptr fs) // that doesn't correspond to an existing filesystem, especially // if we loaded from a version with a bug (#17466) if (info.standby_for_fscid != FS_CLUSTER_ID_NONE - && pending_fsmap.get_filesystems().count( - info.standby_for_fscid) == 0) { + && !pending_fsmap.filesystem_exists(info.standby_for_fscid)) { derr << "gid " << gid << " has invalid standby_for_fscid " << info.standby_for_fscid << dendl; continue; diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index 404735149809e..a90949fd0cce8 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -2478,7 +2478,7 @@ void Monitor::get_cluster_status(stringstream &ss, Formatter *f) ss << " monmap " << *monmap << "\n"; ss << " election epoch " << get_epoch() << ", quorum " << get_quorum() << " " << get_quorum_names() << "\n"; - if (mdsmon()->fsmap.any_filesystems()) { + if (mdsmon()->fsmap.filesystem_count() > 0) { ss << " fsmap " << mdsmon()->fsmap << "\n"; } diff --git a/src/tools/cephfs/DataScan.cc b/src/tools/cephfs/DataScan.cc index bb0584a365da3..7dc60194ed48c 100644 --- a/src/tools/cephfs/DataScan.cc +++ b/src/tools/cephfs/DataScan.cc @@ -212,8 +212,8 @@ int DataScan::main(const std::vector &args) // If caller didn't specify a namespace, try to pick // one if only one exists if (fscid == FS_CLUSTER_ID_NONE) { - if (fsmap->get_filesystems().size() == 1) { - fscid = fsmap->get_filesystems().begin()->first; + if (fsmap->filesystem_count() == 1) { + fscid = fsmap->get_filesystem()->fscid; } else { std::cerr << "Specify a filesystem with --filesystem" << std::endl; return -EINVAL; diff --git a/src/tools/cephfs/RoleSelector.cc b/src/tools/cephfs/RoleSelector.cc index d51f011a47de1..3c7932a5eb9e6 100644 --- a/src/tools/cephfs/RoleSelector.cc +++ b/src/tools/cephfs/RoleSelector.cc @@ -35,8 +35,8 @@ int MDSRoleSelector::parse(const FSMap &fsmap, std::string const &str) if (colon_pos == std::string::npos) { // An unqualified rank. Only valid if there is only one // namespace. - if (fsmap.get_filesystems().size() == 1) { - fscid = fsmap.get_filesystems().begin()->first; + if (fsmap.filesystem_count() == 1) { + fscid = fsmap.get_filesystem()->fscid; return parse_rank(fsmap, str); } else { return -EINVAL; -- 2.39.5