From 36af48029378d7e73a57d4ceb1a22ddfd85ef841 Mon Sep 17 00:00:00 2001 From: Javen Wu Date: Tue, 26 Jan 2016 11:31:11 +0000 Subject: [PATCH] common: default cluster name to config file prefix Signed-off-by: Javen Wu --- src/ceph.in | 2 +- src/common/config.cc | 38 +++++++++++++++++++++++++++++++-- src/global/global_init.cc | 2 +- src/librados/librados.cc | 2 +- src/pybind/rados/rados.pyx | 2 +- src/test/common/test_context.cc | 4 ++++ 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/ceph.in b/src/ceph.in index 6368ad0d972..603440afd1a 100755 --- a/src/ceph.in +++ b/src/ceph.in @@ -676,7 +676,7 @@ def main(): else: injectargs = None - clustername = 'ceph' + clustername = None if parsed_args.cluster: clustername = parsed_args.cluster diff --git a/src/common/config.cc b/src/common/config.cc index d67a96bb3b2..28067b0607d 100644 --- a/src/common/config.cc +++ b/src/common/config.cc @@ -121,7 +121,7 @@ int ceph_resolve_file_search(const std::string& filename_list, } md_config_t::md_config_t() - : cluster("ceph"), + : cluster(""), #define OPTION_OPT_INT(name, def_val) name(def_val), #define OPTION_OPT_LONGLONG(name, def_val) name((1LL) * def_val), @@ -204,8 +204,18 @@ int md_config_t::parse_config_files(const char *conf_files, int flags) { Mutex::Locker l(lock); + if (internal_safe_to_start_threads) return -ENOSYS; + + if (!cluster.size() && !conf_files) { + /* + * set the cluster name to 'ceph' when neither cluster name nor + * configuration file are specified. + */ + cluster = "ceph"; + } + if (!conf_files) { const char *c = getenv("CEPH_CONF"); if (c) { @@ -260,6 +270,26 @@ int md_config_t::parse_config_files_impl(const std::list &conf_file if (c == conf_files.end()) return -EINVAL; + if (cluster.size() == 0) { + /* + * If cluster name is not set yet, use the prefix of the + * basename of configuration file as cluster name. + */ + const char *fn = c->c_str(); + std::string name(basename(fn)); + int pos = name.find(".conf"); + if (pos < 0) { + /* + * If the configuration file does not follow $cluster.conf + * convention, we do the last try and assign the cluster to + * 'ceph'. + */ + cluster = "ceph"; + } else { + cluster = name.substr(0, pos); + } + } + std::vector my_sections; _get_my_sections(my_sections); for (int i = 0; i < NUM_CONFIG_OPTIONS; i++) { @@ -580,7 +610,11 @@ int md_config_t::parse_injectargs(std::vector& args, void md_config_t::apply_changes(std::ostream *oss) { Mutex::Locker l(lock); - _apply_changes(oss); + /* + * apply changes until the cluster name is assigned + */ + if (cluster.size()) + _apply_changes(oss); } bool md_config_t::_internal_field(const string& s) diff --git a/src/global/global_init.cc b/src/global/global_init.cc index 7cbfbd0d575..630c10e78c0 100644 --- a/src/global/global_init.cc +++ b/src/global/global_init.cc @@ -68,7 +68,7 @@ void global_pre_init(std::vector < const char * > *alt_def_args, // You can only call global_init once. assert(!g_ceph_context); std::string conf_file_list; - std::string cluster = "ceph"; + std::string cluster = ""; CephInitParameters iparams = ceph_argparse_early_args(args, module_type, flags, &cluster, &conf_file_list); CephContext *cct = common_preinit(iparams, code_env, flags, data_dir_option); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index e66d17b638a..1db87c72d7a 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -2348,7 +2348,7 @@ extern "C" int rados_create(rados_t *pcluster, const char * const id) if (id) { iparams.name.set(CEPH_ENTITY_TYPE_CLIENT, id); } - CephContext *cct = rados_create_cct("ceph", &iparams); + CephContext *cct = rados_create_cct("", &iparams); tracepoint(librados, rados_create_enter, id); *pcluster = reinterpret_cast(new librados::RadosClient(cct)); diff --git a/src/pybind/rados/rados.pyx b/src/pybind/rados/rados.pyx index 81fd1dc21d2..a5e7816d851 100644 --- a/src/pybind/rados/rados.pyx +++ b/src/pybind/rados/rados.pyx @@ -542,7 +542,7 @@ cdef class Rados(object): elif name is None: name = 'client.admin' if clustername is None: - clustername = 'ceph' + clustername = '' name = cstr(name, 'name') clustername = cstr(clustername, 'clustername') diff --git a/src/test/common/test_context.cc b/src/test/common/test_context.cc index 921fc90ff5f..d976758c6b7 100644 --- a/src/test/common/test_context.cc +++ b/src/test/common/test_context.cc @@ -30,6 +30,8 @@ TEST(CephContext, do_command) { CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); + cct->_conf->cluster = "ceph"; + string key("key"); string value("value"); cct->_conf->set_val(key.c_str(), value.c_str(), false); @@ -57,6 +59,8 @@ TEST(CephContext, experimental_features) { CephContext *cct = (new CephContext(CEPH_ENTITY_TYPE_CLIENT))->get(); + cct->_conf->cluster = "ceph"; + ASSERT_FALSE(cct->check_experimental_feature_enabled("foo")); ASSERT_FALSE(cct->check_experimental_feature_enabled("bar")); ASSERT_FALSE(cct->check_experimental_feature_enabled("baz")); -- 2.47.3