From: Patrick Donnelly Date: Wed, 16 Jan 2019 15:00:45 +0000 (-0800) Subject: mds: alias reference type for Filesystem X-Git-Tag: v14.1.0~334^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=1cae6a5e69bc4a4b1398d655955a8c966497916b;p=ceph.git mds: alias reference type for Filesystem Signed-off-by: Patrick Donnelly --- diff --git a/src/mds/FSMap.cc b/src/mds/FSMap.cc index 69109d0524e1..89261f8d54c7 100644 --- a/src/mds/FSMap.cc +++ b/src/mds/FSMap.cc @@ -76,7 +76,7 @@ void FSMap::generate_test_instances(list& ls) int k = 20; for (auto i : mds_map_instances) { - auto fs = std::make_shared(); + auto fs = Filesystem::create(); fs->fscid = k++; fs->mds_map = *i; delete i; @@ -231,10 +231,10 @@ void FSMap::print_summary(Formatter *f, ostream *out) const } -std::shared_ptr FSMap::create_filesystem(std::string_view name, +Filesystem::ref FSMap::create_filesystem(std::string_view name, int64_t metadata_pool, int64_t data_pool, uint64_t features) { - auto fs = std::make_shared(); + auto fs = Filesystem::create(); fs->mds_map.epoch = epoch; fs->mds_map.fs_name = name; fs->mds_map.data_pools.push_back(data_pool); @@ -269,7 +269,7 @@ std::shared_ptr FSMap::create_filesystem(std::string_view name, void FSMap::reset_filesystem(fs_cluster_id_t fscid) { auto fs = get_filesystem(fscid); - auto new_fs = std::make_shared(); + auto new_fs = Filesystem::create(); // Populate rank 0 as existing (so don't go into CREATING) // but failed (so that next available MDS is assigned the rank) @@ -547,7 +547,7 @@ void FSMap::decode(bufferlist::const_iterator& p) // Synthesise a Filesystem from legacy_mds_map, if enabled if (legacy_mds_map.enabled) { // Construct a Filesystem from the legacy MDSMap - auto migrate_fs = std::make_shared(); + auto migrate_fs = Filesystem::create(); migrate_fs->fscid = FS_CLUSTER_ID_ANONYMOUS; migrate_fs->mds_map = legacy_mds_map; migrate_fs->mds_map.epoch = epoch; @@ -601,7 +601,7 @@ void FSMap::decode(bufferlist::const_iterator& p) decode(fs_list, p); filesystems.clear(); for (std::vector::const_iterator fs = fs_list.begin(); fs != fs_list.end(); ++fs) { - filesystems[fs->fscid] = std::make_shared(*fs); + filesystems[fs->fscid] = Filesystem::create(*fs); } decode(mds_roles, p); @@ -645,7 +645,7 @@ void Filesystem::decode(bufferlist::const_iterator& p) int FSMap::parse_filesystem( std::string_view ns_str, - std::shared_ptr *result + Filesystem::const_ref* result ) const { std::string ns_err; @@ -812,7 +812,7 @@ void FSMap::sanity() const void FSMap::promote( mds_gid_t standby_gid, - const std::shared_ptr &filesystem, + const Filesystem::ref& filesystem, mds_rank_t assigned_rank) { ceph_assert(gid_exists(standby_gid)); @@ -1003,7 +1003,7 @@ int FSMap::parse_role( { size_t colon_pos = role_str.find(":"); size_t rank_pos; - std::shared_ptr fs; + Filesystem::const_ref fs; if (colon_pos == std::string::npos) { if (legacy_client_fscid == FS_CLUSTER_ID_NONE) { ss << "No filesystem selected"; diff --git a/src/mds/FSMap.h b/src/mds/FSMap.h index 655b8af68c89..e955f8c422f2 100644 --- a/src/mds/FSMap.h +++ b/src/mds/FSMap.h @@ -45,6 +45,15 @@ class health_check_map_t; class Filesystem { public: + using ref = std::shared_ptr; + using const_ref = std::shared_ptr; + + template + static ref create(Args&&... args) + { + return std::make_shared(std::forward(args)...); + } + void encode(bufferlist& bl, uint64_t features) const; void decode(bufferlist::const_iterator& p); @@ -82,7 +91,7 @@ protected: bool enable_multiple = false; bool ever_enabled_multiple = false; // < the cluster had multiple MDSes enabled once - std::map > filesystems; + std::map filesystems; // Remember which Filesystem an MDS daemon's info is stored in // (or in standby_daemons for FS_CLUSTER_ID_NONE) @@ -256,7 +265,7 @@ public: */ void promote( mds_gid_t standby_gid, - const std::shared_ptr &filesystem, + const Filesystem::ref& filesystem, mds_rank_t assigned_rank); /** @@ -292,7 +301,7 @@ public: * Caller must already have validated all arguments vs. the existing * FSMap and OSDMap contents. */ - std::shared_ptr create_filesystem( + Filesystem::ref create_filesystem( std::string_view name, int64_t metadata_pool, int64_t data_pool, uint64_t features); @@ -318,7 +327,7 @@ public: */ void modify_filesystem( const fs_cluster_id_t fscid, - std::function )> fn) + std::function fn) { auto fs = filesystems.at(fscid); fn(fs); @@ -380,7 +389,7 @@ public: } } - std::shared_ptr get_legacy_filesystem() + Filesystem::const_ref get_legacy_filesystem() { if (legacy_client_fscid == FS_CLUSTER_ID_NONE) { return nullptr; @@ -395,7 +404,7 @@ public: void update_export_targets(mds_gid_t who, const std::set &targets) { auto fscid = mds_roles.at(who); - modify_filesystem(fscid, [who, &targets](std::shared_ptr fs) { + modify_filesystem(fscid, [who, &targets](auto fs) { fs->mds_map.mds_info.at(who).export_targets = targets; }); } @@ -405,30 +414,30 @@ public: size_t filesystem_count() const {return filesystems.size();} bool filesystem_exists(fs_cluster_id_t fscid) const {return filesystems.count(fscid) > 0;} - 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) {return filesystems.at(fscid);} - std::shared_ptr get_filesystem(void) const {return std::const_pointer_cast(filesystems.begin()->second);} - std::shared_ptr get_filesystem(std::string_view name) const + Filesystem::const_ref get_filesystem(fs_cluster_id_t fscid) const {return std::const_pointer_cast(filesystems.at(fscid));} + Filesystem::ref get_filesystem(fs_cluster_id_t fscid) {return filesystems.at(fscid);} + Filesystem::const_ref get_filesystem(void) const {return std::const_pointer_cast(filesystems.begin()->second);} + Filesystem::const_ref get_filesystem(std::string_view name) const { - for (const auto &i : filesystems) { - if (i.second->mds_map.fs_name == name) { - return std::const_pointer_cast(i.second); + for (const auto& p : filesystems) { + if (p.second->mds_map.fs_name == name) { + return p.second; } } return nullptr; } - std::list > get_filesystems(void) const - { - std::list > ret; - for (const auto &i : filesystems) { - ret.push_back(std::const_pointer_cast(i.second)); - } - return ret; + std::vector get_filesystems(void) const + { + std::vector ret; + for (const auto& p : filesystems) { + ret.push_back(p.second); } + return ret; + } int parse_filesystem( std::string_view ns_str, - std::shared_ptr *result + Filesystem::const_ref *result ) const; int parse_role( diff --git a/src/mon/FSCommands.cc b/src/mon/FSCommands.cc index f1fe9eab8ae6..666c16702643 100644 --- a/src/mon/FSCommands.cc +++ b/src/mon/FSCommands.cc @@ -160,7 +160,7 @@ class FsNewHandler : public FileSystemCommandHandler return -EINVAL; } - for (auto fs : fsmap.get_filesystems()) { + for (auto& fs : fsmap.get_filesystems()) { const std::vector &data_pools = fs->mds_map.get_data_pools(); bool sure = false;