From 89dcd8b6287da7d97af0e7cad45ee023a5a39811 Mon Sep 17 00:00:00 2001 From: John Spray Date: Fri, 13 Jan 2017 00:30:28 +0000 Subject: [PATCH] client: populate metadata during mount This way we avoid having to over-write the "root" metadata during mount, and any user-set overrides (such as bad values injected by tests) will survive. Because Client instances may also open sessions without mounting to send commands, add a call into populate_metadata from mds_command as well. Fixes: http://tracker.ceph.com/issues/18361 Signed-off-by: John Spray (cherry picked from commit 1dbff09ad553f9ff07f4f4217ba7ece6c2cdc5d2) --- src/client/Client.cc | 17 ++++++++++++----- src/client/Client.h | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/client/Client.cc b/src/client/Client.cc index c09af04b0c3a2..777ca9d1cc9c8 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -568,8 +568,6 @@ int Client::init() << cpp_strerror(-ret) << dendl; } - populate_metadata(); - client_lock.Lock(); initialized = true; client_lock.Unlock(); @@ -1934,7 +1932,7 @@ MetaSession *Client::_get_or_open_mds_session(mds_rank_t mds) * Populate a map of strings with client-identifying metadata, * such as the hostname. Call this once at initialization. */ -void Client::populate_metadata() +void Client::populate_metadata(const std::string &mount_root) { // Hostname struct utsname u; @@ -1950,7 +1948,9 @@ void Client::populate_metadata() metadata["entity_id"] = cct->_conf->name.get_id(); // Our mount position - metadata["root"] = cct->_conf->client_mountpoint; + if (!mount_root.empty()) { + metadata["root"] = mount_root; + } // Ceph version metadata["ceph_version"] = pretty_version_to_str(); @@ -5449,6 +5449,12 @@ int Client::mds_command( return -ENOENT; } + if (metadata.empty()) { + // We are called on an unmounted client, so metadata + // won't be initialized yet. + populate_metadata(""); + } + // Send commands to targets C_GatherBuilder gather(cct, onfinish); for (const auto target_gid : non_laggy) { @@ -5553,9 +5559,10 @@ int Client::mount(const std::string &mount_root, bool require_mds) } } + populate_metadata(mount_root.empty() ? "/" : mount_root); + filepath fp(CEPH_INO_ROOT); if (!mount_root.empty()) { - metadata["root"] = mount_root.c_str(); fp = filepath(mount_root.c_str()); } while (true) { diff --git a/src/client/Client.h b/src/client/Client.h index 7129cab15ca2b..51376c0e51eee 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -439,7 +439,7 @@ protected: // Optional extra metadata about me to send to the MDS std::map metadata; - void populate_metadata(); + void populate_metadata(const std::string &mount_root); /* async block write barrier support */ -- 2.39.5