From 365e55635d574ab989bd2aab5f7f12b3ddca72ba Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Tue, 20 Jun 2017 12:13:42 -0400 Subject: [PATCH] mon: auto-enable CephFS on pools when using "fs new"/"fs add_data_pool" Signed-off-by: Jason Dillaman --- src/mon/FSCommands.cc | 72 +++++++++++++++++++++++++++++++++---------- src/mon/FSCommands.h | 7 ++++- src/mon/MDSMonitor.cc | 14 ++++++++- src/mon/OSDMonitor.cc | 21 +++++++++++++ src/mon/OSDMonitor.h | 2 ++ 5 files changed, 97 insertions(+), 19 deletions(-) diff --git a/src/mon/FSCommands.cc b/src/mon/FSCommands.cc index 4f9806bb7c3f6..4b0445fb1347e 100644 --- a/src/mon/FSCommands.cc +++ b/src/mon/FSCommands.cc @@ -80,11 +80,15 @@ class FlagSetHandler : public FileSystemCommandHandler class FsNewHandler : public FileSystemCommandHandler { public: - FsNewHandler() - : FileSystemCommandHandler("fs new") + FsNewHandler(Paxos *paxos) + : FileSystemCommandHandler("fs new"), m_paxos(paxos) { } + bool batched_propose() override { + return true; + } + int handle( Monitor *mon, FSMap &fsmap, @@ -92,6 +96,8 @@ class FsNewHandler : public FileSystemCommandHandler map &cmdmap, std::stringstream &ss) override { + assert(m_paxos->is_plugged()); + string metadata_name; cmd_getval(g_ceph_context, cmdmap, "metadata", metadata_name); int64_t metadata = mon->osdmon()->osdmap.lookup_pg_pool_name(metadata_name); @@ -100,12 +106,13 @@ class FsNewHandler : public FileSystemCommandHandler return -ENOENT; } - string force; - cmd_getval(g_ceph_context,cmdmap, "force", force); + string force_str; + cmd_getval(g_ceph_context,cmdmap, "force", force_str); + bool force = (force_str == "--force"); const pool_stat_t *stat = mon->pgservice->get_pool_stat(metadata); if (stat) { int64_t metadata_num_objects = stat->stats.sum.num_objects; - if (force != "--force" && metadata_num_objects > 0) { + if (!force && metadata_num_objects > 0) { ss << "pool '" << metadata_name << "' already contains some objects. Use an empty pool instead."; return -EINVAL; @@ -123,7 +130,7 @@ class FsNewHandler : public FileSystemCommandHandler 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."; return -EINVAL; } - + string fs_name; cmd_getval(g_ceph_context, cmdmap, "fs_name", fs_name); if (fs_name.empty()) { @@ -177,22 +184,30 @@ class FsNewHandler : public FileSystemCommandHandler // we believe we must. bailing out *after* we request the proposal is // bad business as we could have changed the osdmon's state and ending up // returning an error to the user. - int r = _check_pool(mon->osdmon()->osdmap, data, false, &ss); + int r = _check_pool(mon->osdmon()->osdmap, data, false, force, &ss); if (r < 0) { return r; } - r = _check_pool(mon->osdmon()->osdmap, metadata, true, &ss); + r = _check_pool(mon->osdmon()->osdmap, metadata, true, force, &ss); if (r < 0) { return r; } + mon->osdmon()->do_application_enable(data, + pg_pool_t::APPLICATION_NAME_CEPHFS); + mon->osdmon()->do_application_enable(metadata, + pg_pool_t::APPLICATION_NAME_CEPHFS); + // All checks passed, go ahead and create. fsmap.create_filesystem(fs_name, metadata, data, mon->get_quorum_con_features()); ss << "new fs with metadata pool " << metadata << " and data pool " << data; return 0; } + +private: + Paxos *m_paxos; }; class SetHandler : public FileSystemCommandHandler @@ -447,10 +462,14 @@ public: class AddDataPoolHandler : public FileSystemCommandHandler { public: - AddDataPoolHandler() - : FileSystemCommandHandler("fs add_data_pool") + AddDataPoolHandler(Paxos *paxos) + : FileSystemCommandHandler("fs add_data_pool"), m_paxos(paxos) {} + bool batched_propose() override { + return true; + } + int handle( Monitor *mon, FSMap &fsmap, @@ -458,6 +477,8 @@ class AddDataPoolHandler : public FileSystemCommandHandler map &cmdmap, std::stringstream &ss) override { + assert(m_paxos->is_plugged()); + string poolname; cmd_getval(g_ceph_context, cmdmap, "pool", poolname); @@ -484,7 +505,7 @@ class AddDataPoolHandler : public FileSystemCommandHandler } } - int r = _check_pool(mon->osdmon()->osdmap, poolid, false, &ss); + int r = _check_pool(mon->osdmon()->osdmap, poolid, false, false, &ss); if (r != 0) { return r; } @@ -495,6 +516,9 @@ class AddDataPoolHandler : public FileSystemCommandHandler return 0; } + mon->osdmon()->do_application_enable(poolid, + pg_pool_t::APPLICATION_NAME_CEPHFS); + fsmap.modify_filesystem( fs->fscid, [poolid](std::shared_ptr fs) @@ -506,6 +530,9 @@ class AddDataPoolHandler : public FileSystemCommandHandler return 0; } + +private: + Paxos *m_paxos; }; class SetDefaultHandler : public FileSystemCommandHandler @@ -730,8 +757,9 @@ class LegacyHandler : public T std::string legacy_prefix; public: - LegacyHandler(const std::string &new_prefix) - : T() + template + LegacyHandler(const std::string &new_prefix, Args&&... args) + : T(std::forward(args)...) { legacy_prefix = new_prefix; } @@ -785,22 +813,23 @@ class AliasHandler : public T }; -std::list > FileSystemCommandHandler::load() +std::list > +FileSystemCommandHandler::load(Paxos *paxos) { std::list > handlers; handlers.push_back(std::make_shared()); handlers.push_back(std::make_shared >("mds set")); handlers.push_back(std::make_shared()); - handlers.push_back(std::make_shared()); + handlers.push_back(std::make_shared(paxos)); handlers.push_back(std::make_shared >( - "mds add_data_pool")); + "mds add_data_pool", paxos)); handlers.push_back(std::make_shared()); handlers.push_back(std::make_shared >( "mds remove_data_pool")); handlers.push_back(std::make_shared >( "mds rm_data_pool")); - handlers.push_back(std::make_shared()); + handlers.push_back(std::make_shared(paxos)); handlers.push_back(std::make_shared()); handlers.push_back(std::make_shared()); @@ -839,6 +868,7 @@ int FileSystemCommandHandler::_check_pool( OSDMap &osd_map, const int64_t pool_id, bool metadata, + bool force, std::stringstream *ss) const { assert(ss != NULL); @@ -886,6 +916,14 @@ int FileSystemCommandHandler::_check_pool( return -EINVAL; } + if (!force && !pool->application_metadata.empty() && + pool->application_metadata.count( + pg_pool_t::APPLICATION_NAME_CEPHFS) == 0) { + *ss << " pool '" << pool_name << "' (id '" << pool_id + << "') has a non-CephFS application enabled."; + return -EINVAL; + } + // Nothing special about this pool, so it is permissible return 0; } diff --git a/src/mon/FSCommands.h b/src/mon/FSCommands.h index 5c3079159f3b5..b6b029a17d3f0 100644 --- a/src/mon/FSCommands.h +++ b/src/mon/FSCommands.h @@ -52,6 +52,7 @@ protected: OSDMap &osd_map, const int64_t pool_id, bool metadata, + bool force, std::stringstream *ss) const; virtual std::string const &get_prefix() {return prefix;} @@ -69,7 +70,11 @@ public: return get_prefix() == prefix_; } - static std::list > load(); + static std::list > load(Paxos *paxos); + + virtual bool batched_propose() { + return false; + } virtual int handle( Monitor *mon, diff --git a/src/mon/MDSMonitor.cc b/src/mon/MDSMonitor.cc index d5a350efb37b7..690e20571a480 100644 --- a/src/mon/MDSMonitor.cc +++ b/src/mon/MDSMonitor.cc @@ -1284,9 +1284,18 @@ bool MDSMonitor::prepare_command(MonOpRequestRef op) return true; } + bool batched_propose = false; for (auto h : handlers) { if (h->can_handle(prefix)) { + batched_propose = h->batched_propose(); + if (batched_propose) { + paxos->plug(); + } r = h->handle(mon, pending_fsmap, op, cmdmap, ss); + if (batched_propose) { + paxos->unplug(); + } + if (r == -EAGAIN) { // message has been enqueued for retry; return. dout(4) << __func__ << " enqueue for retry by prepare_command" << dendl; @@ -1340,6 +1349,9 @@ out: // success.. delay reply wait_for_finished_proposal(op, new Monitor::C_Command(mon, op, r, rs, get_last_committed() + 1)); + if (batched_propose) { + force_immediate_propose(); + } return true; } else { // reply immediately @@ -2271,7 +2283,7 @@ bool MDSMonitor::try_standby_replay( MDSMonitor::MDSMonitor(Monitor *mn, Paxos *p, string service_name) : PaxosService(mn, p, service_name) { - handlers = FileSystemCommandHandler::load(); + handlers = FileSystemCommandHandler::load(p); } void MDSMonitor::on_restart() diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 1c0caa7bfcbab..71a3b92c30e70 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -3115,6 +3115,27 @@ void OSDMonitor::check_pg_creates_sub(Subscription *sub) } } +void OSDMonitor::do_application_enable(int64_t pool_id, + const std::string &app_name) +{ + assert(paxos->is_plugged()); + + dout(20) << __func__ << ": pool_id=" << pool_id << ", app_name=" << app_name + << dendl; + + auto pp = osdmap.get_pg_pool(pool_id); + assert(pp != nullptr); + + pg_pool_t p = *pp; + if (pending_inc.new_pools.count(pool_id)) { + p = pending_inc.new_pools[pool_id]; + } + + p.application_metadata.insert({app_name, {}}); + p.last_change = pending_inc.epoch; + pending_inc.new_pools[pool_id] = p; +} + unsigned OSDMonitor::scan_for_creating_pgs( const mempool::osdmap::map& pools, const mempool::osdmap::set& removed_pools, diff --git a/src/mon/OSDMonitor.h b/src/mon/OSDMonitor.h index e7a4c9f68365c..ccc123188e72c 100644 --- a/src/mon/OSDMonitor.h +++ b/src/mon/OSDMonitor.h @@ -539,6 +539,8 @@ public: void check_osdmap_sub(Subscription *sub); void check_pg_creates_sub(Subscription *sub); + void do_application_enable(int64_t pool_id, const std::string &app_name); + void add_flag(int flag) { if (!(osdmap.flags & flag)) { if (pending_inc.new_flags < 0) -- 2.39.5