]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common: do not dup the options when reexpanding 38830/head
authorXiubo Li <xiubli@redhat.com>
Mon, 23 Nov 2020 12:55:01 +0000 (20:55 +0800)
committerNathan Cutler <ncutler@suse.com>
Wed, 27 Jan 2021 20:45:20 +0000 (21:45 +0100)
The old code will store all the options, which has `$pid` in them,
in may_reexpand_meta map. And when reexpanding later, the reexpand
code will dup them with a higher priority(CONF_OVERRIDE).

This will be a problem, if the default value has `$pid` and be
stored in the may_reexpand_meta map, and then the code set a new
different value, which may have no `$pid`, from CLI or config file.
The reexpand will override it with the default value always.

This will do not duplicate the options with CONF_OVERRIDE priority
when reexpanding, just refresh them and call the observers. And the
finalize_reexpand_meta() will always be called after the fork() is
done in child processes.

Fixes: https://tracker.ceph.com/issues/48240
Signed-off-by: Xiubo Li <xiubli@redhat.com>
(cherry picked from commit 56ca87ae3b3c341a78a8df8f95d3bf31828c9108)

src/common/config.cc
src/common/config.h

index 14646cd71c3f7cbec130295d27951815bdb4f1ef..863525efe78a08cf73ea4afd2729e02a8aec21d6 100644 (file)
@@ -1110,17 +1110,19 @@ void md_config_t::early_expand_meta(
 bool md_config_t::finalize_reexpand_meta(ConfigValues& values,
                                         const ConfigTracker& tracker)
 {
-  for (auto& [name, value] : may_reexpand_meta) {
-    set_val(values, tracker, name, value);
-  }
-  
-  if (!may_reexpand_meta.empty()) {
-    // meta expands could have modified anything.  Copy it all out again.
-    update_legacy_vals(values);
-    return true;
-  } else {
-    return false;
+  std::vector<std::string> reexpands;
+  reexpands.swap(may_reexpand_meta);
+  for (auto& name : reexpands) {
+    // always refresh the options if they are in the may_reexpand_meta
+    // map, because the options may have already been expanded with old
+    // meta.
+    const auto &opt_iter = schema.find(name);
+    ceph_assert(opt_iter != schema.end());
+    const Option &opt = opt_iter->second;
+    _refresh(values, opt);
   }
+
+  return !may_reexpand_meta.empty();
 }
 
 Option::value_t md_config_t::_expand_meta(
@@ -1204,7 +1206,7 @@ Option::value_t md_config_t::_expand_meta(
       } else if (var == "pid") {
        out += stringify(getpid());
         if (o) {
-          may_reexpand_meta[o->name] = *str;
+          may_reexpand_meta.push_back(o->name);
         }
       } else if (var == "cctid") {
        out += stringify((unsigned long long)this);
index 527f6904e967cbc1b5ea235a93fc59b81259bfe6..a432a3ae82b3ef8317e1e5152101eefdefb38b3a 100644 (file)
@@ -101,7 +101,7 @@ public:
   std::map<std::string,std::string> ignored_mon_values;
 
   /// original raw values saved that may need to re-expand at certain time
-  mutable std::map<std::string, std::string> may_reexpand_meta;
+  mutable std::vector<std::string> may_reexpand_meta;
 
   /// encoded, cached copy of of values + ignored_mon_values
   bufferlist values_bl;