]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: use pool config overrides for create state machine
authorJason Dillaman <dillaman@redhat.com>
Mon, 8 Oct 2018 17:23:06 +0000 (13:23 -0400)
committerJason Dillaman <dillaman@redhat.com>
Mon, 8 Oct 2018 18:03:28 +0000 (14:03 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/api/Migration.cc
src/librbd/image/CloneRequest.cc
src/librbd/image/CreateRequest.cc
src/librbd/image/CreateRequest.h
src/librbd/internal.cc
src/test/librbd/image/test_mock_CloneRequest.cc
src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc
src/tools/rbd_mirror/image_replayer/CreateImageRequest.cc

index 3bd62048ed3f4eb9d66cafdf317dbe8f29278d65..eb8a2914c2bedd05abdc945b54067074721e7497 100644 (file)
@@ -1147,13 +1147,17 @@ int Migration<I>::create_dst_image() {
   ContextWQ *op_work_queue;
   ImageCtx::get_thread_pool_instance(m_cct, &thread_pool, &op_work_queue);
 
+  ConfigProxy config{m_cct->_conf};
+  api::Config<I>::apply_pool_overrides(m_dst_io_ctx, &config);
+
   int r;
   C_SaferCond on_create;
   librados::IoCtx parent_io_ctx;
   if (parent_spec.pool_id == -1) {
     auto *req = image::CreateRequest<I>::create(
-      m_dst_io_ctx, m_dst_image_name, m_dst_image_id, size, m_image_options,
-      "", "", true /* skip_mirror_enable */, op_work_queue, &on_create);
+      config, m_dst_io_ctx, m_dst_image_name, m_dst_image_id, size,
+      m_image_options, "", "", true /* skip_mirror_enable */, op_work_queue,
+      &on_create);
     req->send();
   } else {
     r = util::create_ioctx(m_src_image_ctx->md_ctx, "destination image",
@@ -1163,9 +1167,6 @@ int Migration<I>::create_dst_image() {
       return r;
     }
 
-    ConfigProxy config{m_cct->_conf};
-    api::Config<I>::apply_pool_overrides(m_dst_io_ctx, &config);
-
     auto *req = image::CloneRequest<I>::create(
       config, parent_io_ctx, parent_spec.image_id, "", parent_spec.snap_id,
       m_dst_io_ctx, m_dst_image_name, m_dst_image_id, m_image_options, "", "",
index c1962649e955eb5f593749d0f9df51aa8732c969..b89f077764b2141b0d43e054723cacf64bb68cd0 100644 (file)
@@ -277,8 +277,9 @@ void CloneRequest<I>::create_child() {
 
   RWLock::RLocker snap_locker(m_parent_image_ctx->snap_lock);
   CreateRequest<I> *req = CreateRequest<I>::create(
-    m_ioctx, m_name, m_id, m_size, m_opts, m_non_primary_global_image_id,
-    m_primary_mirror_uuid, true, m_op_work_queue, ctx);
+    m_config, m_ioctx, m_name, m_id, m_size, m_opts,
+    m_non_primary_global_image_id, m_primary_mirror_uuid, true,
+    m_op_work_queue, ctx);
   req->send();
 }
 
index 77823d2bb6a6d33fa987e1e4cc5fc8b9a219b2c5..14f4c3e83a3fc3185fd4790964ca740e92ce4a34 100644 (file)
@@ -1,8 +1,6 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 
-#include <boost/algorithm/string/predicate.hpp>
-
 #include "librbd/image/CreateRequest.h"
 #include "common/dout.h"
 #include "common/errno.h"
@@ -33,8 +31,6 @@ using util::create_context_callback;
 
 namespace {
 
-const uint64_t MAX_METADATA_ITEMS = 128;
-
 int validate_features(CephContext *cct, uint64_t features,
                        bool force_non_primary) {
   if (features & ~RBD_FEATURES_ALL) {
@@ -119,16 +115,16 @@ int CreateRequest<I>::validate_order(CephContext *cct, uint8_t order) {
                            << __func__ << ": "
 
 template<typename I>
-CreateRequest<I>::CreateRequest(IoCtx &ioctx, const std::string &image_name,
+CreateRequest<I>::CreateRequest(const ConfigProxy& config, IoCtx &ioctx,
+                                const std::string &image_name,
                                 const std::string &image_id, uint64_t size,
                                 const ImageOptions &image_options,
                                 const std::string &non_primary_global_image_id,
                                 const std::string &primary_mirror_uuid,
                                 bool skip_mirror_enable,
                                 ContextWQ *op_work_queue, Context *on_finish)
-  : m_image_name(image_name), m_image_id(image_id), m_size(size),
-    m_image_options(image_options),
-    m_non_primary_global_image_id(non_primary_global_image_id),
+  : m_config(config), m_image_name(image_name), m_image_id(image_id),
+    m_size(size), m_non_primary_global_image_id(non_primary_global_image_id),
     m_primary_mirror_uuid(primary_mirror_uuid),
     m_skip_mirror_enable(skip_mirror_enable),
     m_op_work_queue(op_work_queue), m_on_finish(on_finish) {
@@ -140,83 +136,17 @@ CreateRequest<I>::CreateRequest(IoCtx &ioctx, const std::string &image_name,
   m_header_obj = util::header_name(m_image_id);
   m_objmap_name = ObjectMap<>::object_map_name(m_image_id, CEPH_NOSNAP);
   m_force_non_primary = !non_primary_global_image_id.empty();
-}
-
-template<typename I>
-void CreateRequest<I>::send() {
-  ldout(m_cct, 20) << dendl;
-
-  get_pool_metadata();
-}
-
-template <typename I>
-void CreateRequest<I>::get_pool_metadata() {
-  ldout(m_cct, 20) << "start_key=" << m_last_metadata_key << dendl;
-
-  librados::ObjectReadOperation op;
-  cls_client::metadata_list_start(&op, m_last_metadata_key, MAX_METADATA_ITEMS);
-
-  using klass = CreateRequest<I>;
-  librados::AioCompletion *comp =
-    create_rados_callback<klass, &klass::handle_get_pool_metadata>(this);
-  m_outbl.clear();
-  m_io_ctx.aio_operate(RBD_INFO, comp, &op, &m_outbl);
-  comp->release();
-}
-
-template <typename I>
-void CreateRequest<I>::handle_get_pool_metadata(int r) {
-  ldout(m_cct, 20) << "r=" << r << dendl;
-
-  std::map<std::string, bufferlist> metadata;
-  if (r == 0) {
-    auto it = m_outbl.cbegin();
-    r = cls_client::metadata_list_finish(&it, &metadata);
-  }
-
-  if (r == -EOPNOTSUPP || r == -ENOENT) {
-    ldout(m_cct, 10) << "pool metadata not supported by OSD" << dendl;
-  } else if (r < 0) {
-    lderr(m_cct) << "failed to retrieve pool metadata: " << cpp_strerror(r)
-                 << dendl;
-    complete(r);
-    return;
-  }
-
-  if (!metadata.empty()) {
-    m_metadata.insert(metadata.begin(), metadata.end());
-    m_last_metadata_key = metadata.rbegin()->first;
-    if (boost::starts_with(m_last_metadata_key,
-                           ImageCtx::METADATA_CONF_PREFIX)) {
-      get_pool_metadata();
-      return;
-    }
-  }
 
-  ConfigProxy config(m_cct->_conf);
-  for (auto &it : m_metadata) {
-    std::string key;
-    if (!util::is_metadata_config_override(it.first, &key)) {
-      continue;
-    }
-    std::string value(it.second.c_str(), it.second.length());
-    r = config.set_val(key.c_str(), value);
-    if (r != 0) {
-      lderr(m_cct) << " failed to set config " << key << " with value "
-                   << it.second << ": " << cpp_strerror(r) << dendl;
-    }
-  }
-
-  if (m_image_options.get(RBD_IMAGE_OPTION_FEATURES, &m_features) != 0) {
+  if (image_options.get(RBD_IMAGE_OPTION_FEATURES, &m_features) != 0) {
     m_features = librbd::rbd_features_from_string(
-      config.get_val<std::string>("rbd_default_features"), nullptr);
+      m_config.get_val<std::string>("rbd_default_features"), nullptr);
     m_negotiate_features = true;
   }
 
   uint64_t features_clear = 0;
   uint64_t features_set = 0;
-  m_image_options.get(RBD_IMAGE_OPTION_FEATURES_CLEAR, &features_clear);
-  m_image_options.get(RBD_IMAGE_OPTION_FEATURES_SET, &features_set);
+  image_options.get(RBD_IMAGE_OPTION_FEATURES_CLEAR, &features_clear);
+  image_options.get(RBD_IMAGE_OPTION_FEATURES_SET, &features_set);
 
   uint64_t features_conflict = features_clear & features_set;
   features_clear &= ~features_conflict;
@@ -228,32 +158,32 @@ void CreateRequest<I>::handle_get_pool_metadata(int r) {
       m_features |= RBD_FEATURE_FAST_DIFF;
   }
 
-  if (m_image_options.get(RBD_IMAGE_OPTION_STRIPE_UNIT, &m_stripe_unit) != 0 ||
+  if (image_options.get(RBD_IMAGE_OPTION_STRIPE_UNIT, &m_stripe_unit) != 0 ||
       m_stripe_unit == 0) {
-    m_stripe_unit = config.get_val<Option::size_t>("rbd_default_stripe_unit");
+    m_stripe_unit = m_config.get_val<Option::size_t>("rbd_default_stripe_unit");
   }
-  if (m_image_options.get(RBD_IMAGE_OPTION_STRIPE_COUNT,
-                          &m_stripe_count) != 0 || m_stripe_count == 0) {
-    m_stripe_count = config.get_val<uint64_t>("rbd_default_stripe_count");
+  if (image_options.get(RBD_IMAGE_OPTION_STRIPE_COUNT, &m_stripe_count) != 0 ||
+      m_stripe_count == 0) {
+    m_stripe_count = m_config.get_val<uint64_t>("rbd_default_stripe_count");
   }
-  if (get_image_option(m_image_options, RBD_IMAGE_OPTION_ORDER,
-                       &m_order) != 0 || m_order == 0) {
+  if (get_image_option(image_options, RBD_IMAGE_OPTION_ORDER, &m_order) != 0 ||
+      m_order == 0) {
     m_order = config.get_val<uint64_t>("rbd_default_order");
   }
-  if (get_image_option(m_image_options, RBD_IMAGE_OPTION_JOURNAL_ORDER,
-                       &m_journal_order) != 0) {
-    m_journal_order = config.get_val<uint64_t>("rbd_journal_order");
+  if (get_image_option(image_options, RBD_IMAGE_OPTION_JOURNAL_ORDER,
+      &m_journal_order) != 0) {
+    m_journal_order = m_config.get_val<uint64_t>("rbd_journal_order");
   }
-  if (get_image_option(m_image_options, RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH,
+  if (get_image_option(image_options, RBD_IMAGE_OPTION_JOURNAL_SPLAY_WIDTH,
                        &m_journal_splay_width) != 0) {
-    m_journal_splay_width = config.get_val<uint64_t>("rbd_journal_splay_width");
+    m_journal_splay_width = m_config.get_val<uint64_t>(
+      "rbd_journal_splay_width");
   }
-  if (m_image_options.get(RBD_IMAGE_OPTION_JOURNAL_POOL,
-                          &m_journal_pool) != 0) {
-    m_journal_pool = config.get_val<std::string>("rbd_journal_pool");
+  if (image_options.get(RBD_IMAGE_OPTION_JOURNAL_POOL, &m_journal_pool) != 0) {
+    m_journal_pool = m_config.get_val<std::string>("rbd_journal_pool");
   }
-  if (m_image_options.get(RBD_IMAGE_OPTION_DATA_POOL, &m_data_pool) != 0) {
-    m_data_pool = config.get_val<std::string>("rbd_default_data_pool");
+  if (image_options.get(RBD_IMAGE_OPTION_DATA_POOL, &m_data_pool) != 0) {
+    m_data_pool = m_config.get_val<std::string>("rbd_default_data_pool");
   }
 
   m_layout.object_size = 1ull << m_order;
@@ -265,7 +195,7 @@ void CreateRequest<I>::handle_get_pool_metadata(int r) {
     m_layout.stripe_count = m_stripe_count;
   }
 
-  if (!m_data_pool.empty() && m_data_pool != m_io_ctx.get_pool_name()) {
+  if (!m_data_pool.empty() && m_data_pool != ioctx.get_pool_name()) {
     m_features |= RBD_FEATURE_DATA_POOL;
   } else {
     m_data_pool.clear();
@@ -291,8 +221,13 @@ void CreateRequest<I>::handle_get_pool_metadata(int r) {
                    << (uint64_t)m_journal_splay_width << ", "
                    << "journal_pool=" << m_journal_pool << ", "
                    << "data_pool=" << m_data_pool << dendl;
+}
 
-  r = validate_features(m_cct, m_features, m_force_non_primary);
+template<typename I>
+void CreateRequest<I>::send() {
+  ldout(m_cct, 20) << dendl;
+
+  int r = validate_features(m_cct, m_features, m_force_non_primary);
   if (r < 0) {
     complete(r);
     return;
@@ -316,6 +251,11 @@ void CreateRequest<I>::handle_get_pool_metadata(int r) {
     return;
   }
 
+  validate_data_pool();
+}
+
+template <typename I>
+void CreateRequest<I>::validate_data_pool() {
   m_data_io_ctx = m_io_ctx;
   if ((m_features & RBD_FEATURE_DATA_POOL) != 0) {
     librados::Rados rados(m_io_ctx);
@@ -329,16 +269,11 @@ void CreateRequest<I>::handle_get_pool_metadata(int r) {
     m_data_io_ctx.set_namespace(m_io_ctx.get_namespace());
   }
 
-  if (!config.get_val<bool>("rbd_validate_pool")) {
+  if (!m_config.get_val<bool>("rbd_validate_pool")) {
     add_image_to_directory();
     return;
   }
 
-  validate_data_pool();
-}
-
-template <typename I>
-void CreateRequest<I>::validate_data_pool() {
   ldout(m_cct, 15) << dendl;
 
   using klass = CreateRequest<I>;
index 98f950cf9e86101161fab16efaac9f5b18b253ed..120686ed45316e1e869e7ce5c3c155c976bdde8e 100644 (file)
@@ -16,6 +16,7 @@
 #include "common/Timer.h"
 #include "librbd/journal/TypeTraits.h"
 
+class ConfigProxy;
 class Context;
 
 using librados::IoCtx;
@@ -30,17 +31,18 @@ namespace image {
 template <typename ImageCtxT = ImageCtx>
 class CreateRequest {
 public:
-  static CreateRequest *create(IoCtx &ioctx, const std::string &image_name,
+  static CreateRequest *create(const ConfigProxy& config, IoCtx &ioctx,
+                               const std::string &image_name,
                                const std::string &image_id, uint64_t size,
                                const ImageOptions &image_options,
                                const std::string &non_primary_global_image_id,
                                const std::string &primary_mirror_uuid,
                                bool skip_mirror_enable,
                                ContextWQ *op_work_queue, Context *on_finish) {
-    return new CreateRequest(ioctx, image_name, image_id, size, image_options,
-                             non_primary_global_image_id, primary_mirror_uuid,
-                             skip_mirror_enable, op_work_queue,
-                             on_finish);
+    return new CreateRequest(config, ioctx, image_name, image_id, size,
+                             image_options, non_primary_global_image_id,
+                             primary_mirror_uuid, skip_mirror_enable,
+                             op_work_queue, on_finish);
   }
 
   static int validate_order(CephContext *cct, uint8_t order);
@@ -51,15 +53,12 @@ private:
   /**
    * @verbatim
    *
-   *                                  <start>
-   *                                     |
-   *                                     v
-   *                               GET POOL METADATA
-   *                                     |
-   *                                     v
-   *                               VALIDATE DATA POOL . . . . . .
-   *                                     |                      . (pool validation
-   *                                     v                      .  disabled)
+   *                                  <start> . . . . > . . . . .
+   *                                     |                      .
+   *                                     v                      .
+   *                               VALIDATE DATA POOL           v (pool validation
+   *                                     |                      .  disabled)
+   *                                     v                      .
    * (error: bottom up)         ADD IMAGE TO DIRECTORY  < . . . .
    *  _______<_______                    |
    * |               |                   v
@@ -93,7 +92,8 @@ private:
    * @endverbatim
    */
 
-  CreateRequest(IoCtx &ioctx, const std::string &image_name,
+  CreateRequest(const ConfigProxy& config, IoCtx &ioctx,
+                const std::string &image_name,
                 const std::string &image_id, uint64_t size,
                 const ImageOptions &image_options,
                 const std::string &non_primary_global_image_id,
@@ -101,12 +101,12 @@ private:
                 bool skip_mirror_enable,
                 ContextWQ *op_work_queue, Context *on_finish);
 
+  const ConfigProxy& m_config;
   IoCtx m_io_ctx;
   IoCtx m_data_io_ctx;
   std::string m_image_name;
   std::string m_image_id;
   uint64_t m_size;
-  ImageOptions m_image_options;
   uint8_t m_order = 0;
   uint64_t m_features = 0;
   uint64_t m_stripe_unit = 0;
@@ -134,12 +134,6 @@ private:
   rbd_mirror_mode_t m_mirror_mode = RBD_MIRROR_MODE_DISABLED;
   cls::rbd::MirrorImage m_mirror_image_internal;
 
-  std::string m_last_metadata_key;
-  std::map<std::string, bufferlist> m_metadata;
-
-  void get_pool_metadata();
-  void handle_get_pool_metadata(int r);
-
   void validate_data_pool();
   void handle_validate_data_pool(int r);
 
index a3499b493190693a74341aae269d1ea3dfd252d1..81d1765e050dbb0892d35d6501fb727224599911 100644 (file)
@@ -914,9 +914,12 @@ bool compare_by_name(const child_info_t& c1, const child_info_t& c2)
       ContextWQ *op_work_queue;
       ImageCtx::get_thread_pool_instance(cct, &thread_pool, &op_work_queue);
 
+      ConfigProxy config{cct->_conf};
+      api::Config<>::apply_pool_overrides(io_ctx, &config);
+
       C_SaferCond cond;
       image::CreateRequest<> *req = image::CreateRequest<>::create(
-        io_ctx, image_name, id, size, opts, non_primary_global_image_id,
+        config, io_ctx, image_name, id, size, opts, non_primary_global_image_id,
         primary_mirror_uuid, skip_mirror_enable, op_work_queue, &cond);
       req->send();
 
index 59a7b69ce17b99766bc39fb1844651ed4ec2ccfe..1333b70af004c3b52c8ca0dcee0766db30b2d852 100644 (file)
@@ -75,7 +75,8 @@ template <>
 struct CreateRequest<MockTestImageCtx> {
   Context* on_finish = nullptr;
   static CreateRequest* s_instance;
-  static CreateRequest* create(IoCtx &ioctx, const std::string &image_name,
+  static CreateRequest* create(const ConfigProxy& config, IoCtx &ioctx,
+                               const std::string &image_name,
                                const std::string &image_id, uint64_t size,
                                const ImageOptions &image_options,
                                const std::string &non_primary_global_image_id,
index cb34938f6300a953d11d9361116530dd9734eac1..8e13e8b37efff1775814c4afdbafdbe6fad49a98 100644 (file)
@@ -36,7 +36,8 @@ struct CreateRequest<librbd::MockTestImageCtx> {
   static CreateRequest *s_instance;
   Context *on_finish = nullptr;
 
-  static CreateRequest *create(IoCtx &ioctx, const std::string &imgname,
+  static CreateRequest *create(const ConfigProxy& config, IoCtx &ioctx,
+                               const std::string &imgname,
                                const std::string &imageid, uint64_t size,
                                const librbd::ImageOptions &image_options,
                                const std::string &non_primary_global_image_id,
index 4df226f02f89cf625a4ec9ec4cf6c314b34ab4c2..db934f50586f821979c0acf89d2571cc1c6ffae3 100644 (file)
@@ -75,11 +75,14 @@ void CreateImageRequest<I>::create_image() {
 
   RWLock::RLocker snap_locker(m_remote_image_ctx->snap_lock);
 
+  auto& config{
+    reinterpret_cast<CephContext*>(m_local_io_ctx.cct())->_conf};
+
   librbd::ImageOptions image_options;
   populate_image_options(&image_options);
 
   auto req = librbd::image::CreateRequest<I>::create(
-    m_local_io_ctx, m_local_image_name, m_local_image_id,
+    config, m_local_io_ctx, m_local_image_name, m_local_image_id,
     m_remote_image_ctx->size, image_options, m_global_image_id,
     m_remote_mirror_uuid, false, m_remote_image_ctx->op_work_queue, ctx);
   req->send();