From 66f4ebbb905f097c20636858a1127b938c5e9833 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 8 Oct 2018 10:45:59 -0400 Subject: [PATCH] librbd: helper method to apply pool-level config overrides Signed-off-by: Jason Dillaman --- src/librbd/api/Config.cc | 24 ++++++++++++++++++++++++ src/librbd/api/Config.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/src/librbd/api/Config.cc b/src/librbd/api/Config.cc index 6b7061043e690..eec026f319110 100644 --- a/src/librbd/api/Config.cc +++ b/src/librbd/api/Config.cc @@ -207,6 +207,30 @@ int Config::list(I *image_ctx, std::vector *options) { return 0; } +template +void Config::apply_pool_overrides(librados::IoCtx& io_ctx, + ConfigProxy* config) { + CephContext *cct = reinterpret_cast(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 diff --git a/src/librbd/api/Config.h b/src/librbd/api/Config.h index 9f27000966dfd..13213728bd479 100644 --- a/src/librbd/api/Config.h +++ b/src/librbd/api/Config.h @@ -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 *options); + + static void apply_pool_overrides(librados::IoCtx& io_ctx, + ConfigProxy* config); }; } // namespace api -- 2.39.5