]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: helper method to apply pool-level config overrides
authorJason Dillaman <dillaman@redhat.com>
Mon, 8 Oct 2018 14:45:59 +0000 (10:45 -0400)
committerJason Dillaman <dillaman@redhat.com>
Mon, 8 Oct 2018 17:56:58 +0000 (13:56 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/api/Config.cc
src/librbd/api/Config.h

index 6b7061043e6902683119f446a15f43abd6e4aa10..eec026f319110ee8b69dc5dcdc402aa1f3e8452d 100644 (file)
@@ -207,6 +207,30 @@ int Config<I>::list(I *image_ctx, std::vector<config_option_t> *options) {
   return 0;
 }
 
+template <typename I>
+void Config<I>::apply_pool_overrides(librados::IoCtx& io_ctx,
+                                     ConfigProxy* config) {
+  CephContext *cct = reinterpret_cast<CephContext *>(io_ctx.cct());
+
+  Options opts(io_ctx, false);
+  int r = opts.init();
+  if (r < 0) {
+    lderr(cct) << "failed to read pool config overrides: " << cpp_strerror(r)
+               << dendl;
+    return;
+  }
+
+  for (auto& pair : opts) {
+    if (pair.second.second == RBD_CONFIG_SOURCE_POOL) {
+      r = config->set_val(pair.first, pair.second.first);
+      if (r < 0) {
+        lderr(cct) << "failed to override pool config " << pair.first << "="
+                   << pair.second.first << ": " << cpp_strerror(r) << dendl;
+      }
+    }
+  }
+}
+
 } // namespace api
 } // namespace librbd
 
index 9f27000966dfdebafee970efd1615f089553da8c..13213728bd479e70d514d9ffe1997c051b9ecb04 100644 (file)
@@ -6,6 +6,8 @@
 
 #include "include/rbd/librbd.hpp"
 
+struct ConfigProxy;
+
 namespace librados {
 
 class IoCtx;
@@ -27,6 +29,9 @@ public:
 
   static bool is_option_name(ImageCtxT *image_ctx, const std::string &name);
   static int list(ImageCtxT *image_ctx, std::vector<config_option_t> *options);
+
+  static void apply_pool_overrides(librados::IoCtx& io_ctx,
+                                   ConfigProxy* config);
 };
 
 } // namespace api