]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: use ConfigProxy within ImageCtx to store overrides
authorJason Dillaman <dillaman@redhat.com>
Thu, 4 Oct 2018 16:48:47 +0000 (12:48 -0400)
committerJason Dillaman <dillaman@redhat.com>
Fri, 5 Oct 2018 13:54:53 +0000 (09:54 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/ImageCtx.cc
src/librbd/ImageCtx.h
src/test/librbd/mock/MockImageCtx.h

index 6ab0555fa4cf65090b03ca844a70b6ca825e15ac..12e2f99dcb3771d7c807b751d6de49a86590c3f3 100644 (file)
@@ -96,6 +96,7 @@ public:
   ImageCtx::ImageCtx(const string &image_name, const string &image_id,
                     const char *snap, IoCtx& p, bool ro)
     : cct((CephContext*)p.cct()),
+      config(cct->_conf),
       perfcounter(NULL),
       snap_id(CEPH_NOSNAP),
       snap_exists(true),
@@ -813,28 +814,35 @@ public:
        "rbd_qos_read_bps_limit", false)(
        "rbd_qos_write_bps_limit", false);
 
-    ConfigProxy local_config_t{false};
     std::map<std::string, bufferlist> res;
 
+    // reset settings back to global defaults
+    for (auto& key : config_overrides) {
+      std::string value;
+      int r = cct->_conf.get_val(key, &value);
+      ceph_assert(r == 0);
+
+      config.set_val(key, value);
+    }
+
+    config_overrides.clear();
     _filter_metadata_confs(METADATA_CONF_PREFIX, configs, meta, &res);
     for (auto it : res) {
       std::string val(it.second.c_str(), it.second.length());
-      int j = local_config_t.set_val(it.first.c_str(), val);
+      int j = config.set_val(it.first.c_str(), val);
       if (j < 0) {
         lderr(cct) << __func__ << " failed to set config " << it.first
                    << " with value " << it.second.c_str() << ": " << j
                    << dendl;
       }
+      config_overrides.insert(it.first);
     }
 
 #define ASSIGN_OPTION(config, type)                                            \
     do {                                                                       \
       string key = "rbd_";                                                    \
       key = key + #config;                                                    \
-      if (configs[key])                                                        \
-        config = local_config_t.get_val<type>("rbd_"#config);                  \
-      else                                                                     \
-        config = cct->_conf.get_val<type>("rbd_"#config);                      \
+      config = config.get_val<type>("rbd_"#config);                            \
     } while (0);
 
     ASSIGN_OPTION(non_blocking_aio, bool);
index 766793823201595cb00c97621f296ff2e88b5c5a..5d6f41c0280512bec50daecc76c19b62f3ce8cb0 100644 (file)
@@ -7,9 +7,11 @@
 
 #include <list>
 #include <map>
+#include <set>
 #include <string>
 #include <vector>
 
+#include "common/config_proxy.h"
 #include "common/event_socket.h"
 #include "common/Mutex.h"
 #include "common/Readahead.h"
@@ -62,6 +64,9 @@ namespace librbd {
 
   struct ImageCtx {
     CephContext *cct;
+    ConfigProxy config;
+    std::set<std::string> config_overrides;
+
     PerfCounters *perfcounter;
     struct rbd_obj_header_ondisk header;
     ::SnapContext snapc;
index 028f4fba41fb803bf2b8640c53d6c24100331729..d027d2dac4003ee425ad4be73814cc288a74aff9 100644 (file)
@@ -118,7 +118,8 @@ struct MockImageCtx {
       ignore_migrating(image_ctx.ignore_migrating),
       mtime_update_interval(image_ctx.mtime_update_interval),
       atime_update_interval(image_ctx.atime_update_interval),
-      cache(image_ctx.cache)
+      cache(image_ctx.cache),
+      config(image_ctx.config)
   {
     md_ctx.dup(image_ctx.md_ctx);
     data_ctx.dup(image_ctx.data_ctx);
@@ -339,6 +340,8 @@ struct MockImageCtx {
   uint64_t mtime_update_interval;
   uint64_t atime_update_interval;
   bool cache;
+
+  ConfigProxy config;
 };
 
 } // namespace librbd