From 1dbff09ad553f9ff07f4f4217ba7ece6c2cdc5d2 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 --- 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 12fc2fa9cdd4a..2d7bd1548a6a8 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -544,8 +544,6 @@ int Client::init() << cpp_strerror(-ret) << dendl; } - populate_metadata(); - client_lock.Lock(); initialized = true; client_lock.Unlock(); @@ -1925,7 +1923,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; @@ -1943,7 +1941,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(); @@ -5496,6 +5496,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) { @@ -5618,9 +5624,10 @@ int Client::mount(const std::string &mount_root, const UserPerm& perms, } } + 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 6ceee71d02900..baa79ab948106 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -433,7 +433,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