]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/config: extract get_conffile_paths() out
authorKefu Chai <kchai@redhat.com>
Wed, 29 Jul 2020 09:24:59 +0000 (17:24 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 1 Aug 2020 16:01:47 +0000 (00:01 +0800)
md_config_t::parse_config_files() performs blocked i/o, and it might be
detected by the stall detector of seastar, and it spills out warning
messages when it sees the hang.

so i plan to implement an asynchronized parse_config_files() for
crimson, and reuse the synchronized part from the blocking
implementation of parse_config_files(). this is the first step.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/common/config.cc
src/common/config.h

index 925a572cd55388e13c0b7d064b79765918e65417..3f7fe25181e172a9355d046606caab61a9c813e6 100644 (file)
@@ -350,57 +350,31 @@ int md_config_t::parse_config_files(ConfigValues& values,
   if (safe_to_start_threads)
     return -ENOSYS;
 
-  if (!values.cluster.size() && !conf_files_str) {
+  if (values.cluster.empty() && !conf_files_str) {
     /*
      * set the cluster name to 'ceph' when neither cluster name nor
      * configuration file are specified.
      */
     values.cluster = "ceph";
   }
-
-  if (!conf_files_str) {
-    const char *c = getenv("CEPH_CONF");
-    if (c) {
-      conf_files_str = c;
-    }
-    else {
-      if (flags & CINIT_FLAG_NO_DEFAULT_CONFIG_FILE)
-       return 0;
-      conf_files_str = CEPH_CONF_FILE_DEFAULT;
-    }
-  }
-
-  std::list<std::string> conf_files;
-  get_str_list(conf_files_str, conf_files);
-  auto p = conf_files.begin();
-  while (p != conf_files.end()) {
-    string &s = *p;
-    if (s.find("$data_dir") != string::npos &&
-       data_dir_option.empty()) {
-      // useless $data_dir item, skip
-      p = conf_files.erase(p);
-    } else {
-      early_expand_meta(values, s, warnings);
-      ++p;
-    }
-  }
-
   // open new conf
-  list<string>::const_iterator c;
-  for (c = conf_files.begin(); c != conf_files.end(); ++c) {
-    cf.clear();
-    string fn = *c;
+  string conffile;
+  for (auto& fn : get_conffile_paths(values, conf_files_str, warnings, flags)) {
     ostringstream oss;
     int ret = cf.parse_file(fn.c_str(), &oss);
-    parse_error = oss.str();
     if (ret == 0) {
+      parse_error.clear();
+      conffile = fn;
       break;
+    } else {
+      parse_error = oss.str();
+      if (ret != -ENOENT) {
+       return ret;
+      }
     }
-    if (ret != -ENOENT)
-      return ret;
   }
   // it must have been all ENOENTs, that's the only way we got here
-  if (c == conf_files.end())
+  if (conffile.empty())
     return -ENOENT;
 
   if (values.cluster.size() == 0) {
@@ -408,9 +382,9 @@ int md_config_t::parse_config_files(ConfigValues& values,
      * If cluster name is not set yet, use the prefix of the
      * basename of configuration file as cluster name.
      */
-    auto start = c->rfind('/') + 1;
-    auto end = c->find(".conf", start);
-    if (end == c->npos) {
+    auto start = conffile.rfind('/') + 1;
+    auto end = conffile.find(".conf", start);
+    if (end == conffile.npos) {
         /*
          * If the configuration file does not follow $cluster.conf
          * convention, we do the last try and assign the cluster to
@@ -418,7 +392,7 @@ int md_config_t::parse_config_files(ConfigValues& values,
          */
         values.cluster = "ceph";
     } else {
-      values.cluster = c->substr(start, end - start);
+      values.cluster = conffile.substr(start, end - start);
     }
   }
 
@@ -467,6 +441,39 @@ int md_config_t::parse_config_files(ConfigValues& values,
   return 0;
 }
 
+std::list<std::string>
+md_config_t::get_conffile_paths(const ConfigValues& values,
+                               const char *conf_files_str,
+                               std::ostream *warnings,
+                               int flags) const
+{
+  if (!conf_files_str) {
+    const char *c = getenv("CEPH_CONF");
+    if (c) {
+      conf_files_str = c;
+    } else {
+      if (flags & CINIT_FLAG_NO_DEFAULT_CONFIG_FILE)
+       return {};
+      conf_files_str = CEPH_CONF_FILE_DEFAULT;
+    }
+  }
+
+  std::list<std::string> paths;
+  get_str_list(conf_files_str, paths);
+  for (auto i = paths.begin(); i != paths.end(); ) {
+    string& path = *i;
+    if (path.find("$data_dir") != path.npos &&
+       data_dir_option.empty()) {
+      // useless $data_dir item, skip
+      i = paths.erase(i);
+    } else {
+      early_expand_meta(values, path, warnings);
+      ++i;
+    }
+  }
+  return paths;
+}
+
 void md_config_t::parse_env(unsigned entity_type,
                            ConfigValues& values,
                            const ConfigTracker& tracker,
index 06c4c0be5ec36fc47653193a35c52477ccb5f5d8..d1f3dac2d42f7faf842c7fdb48a483b7dd8e1534 100644 (file)
@@ -317,6 +317,11 @@ public:  // for global_init
   bool finalize_reexpand_meta(ConfigValues& values,
                              const ConfigTracker& tracker);
 private:
+  std::list<std::string> get_conffile_paths(const ConfigValues& values,
+                                           const char *conf_files,
+                                           std::ostream *warnings,
+                                           int flags) const;
+
   // The configuration file we read, or NULL if we haven't read one.
   ConfFile cf;
 public: