]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common: default cluster name to config file prefix 7364/head
authorJaven Wu <javen.wu@xtaotech.com>
Tue, 26 Jan 2016 11:31:11 +0000 (11:31 +0000)
committerJaven Wu <javen.wu@xtaotech.com>
Fri, 19 Feb 2016 06:55:09 +0000 (06:55 +0000)
Signed-off-by: Javen Wu <javen.wu@xtaotech.com>
src/ceph.in
src/common/config.cc
src/global/global_init.cc
src/librados/librados.cc
src/pybind/rados/rados.pyx
src/test/common/test_context.cc

index 6368ad0d972538136c10c5b670192b81da174c25..603440afd1a34d7ef5a62d2545b29cd53077d743 100755 (executable)
@@ -676,7 +676,7 @@ def main():
     else:
         injectargs = None
 
-    clustername = 'ceph'
+    clustername = None
     if parsed_args.cluster:
         clustername = parsed_args.cluster
 
index d67a96bb3b20cbcdf6cd502bce6d22ca8c93de4d..28067b0607df166aa42e077b8726d49e0b410496 100644 (file)
@@ -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<std::string> &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 <std::string> 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<const char*>& 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)
index 7cbfbd0d575a2d43e5bb8b2ba5580e0200c9bb4a..630c10e78c0b9f4be4e8a9f08a24696d844066b7 100644 (file)
@@ -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);
index e66d17b638aca3e91aeeeb236127be552810b9a6..1db87c72d7a43c8b0df92b6dccebe03eb4b33242 100644 (file)
@@ -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<rados_t>(new librados::RadosClient(cct));
index 81fd1dc21d2cca59a761e726e823e64d4d31009a..a5e7816d851837a2a391a51779106473ead63e2c 100644 (file)
@@ -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')
index 921fc90ff5fa6bcd3764fbc034ccc09a49b1d017..d976758c6b7c35edaf1a7d4c3783d9e1103be6e4 100644 (file)
@@ -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"));