]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Librbd: Don't affect global md_config_t
authorHaomai Wang <haomaiwang@gmail.com>
Fri, 10 Apr 2015 07:25:33 +0000 (15:25 +0800)
committerHaomai Wang <haomaiwang@gmail.com>
Fri, 10 Apr 2015 08:44:47 +0000 (16:44 +0800)
Signed-off-by: Haomai Wang <haomaiwang@gmail.com>
src/librbd/AioRequest.cc
src/librbd/AsyncFlattenRequest.cc
src/librbd/AsyncTrimRequest.cc
src/librbd/ImageCtx.cc
src/librbd/ImageCtx.h
src/librbd/ImageWatcher.cc
src/librbd/internal.cc
src/test/librbd/test_internal.cc

index 38e5db74b24d3bcaddfc5b2002c88dbe95232bc9..eca8896720e316643a0e7f9c94873b3af51519f2 100644 (file)
@@ -89,7 +89,7 @@ namespace librbd {
 
   static inline bool is_copy_on_read(ImageCtx *ictx, librados::snap_t snap_id) {
     assert(ictx->snap_lock.is_locked());
-    return (ictx->rbd_clone_copy_on_read) &&
+    return (ictx->clone_copy_on_read) &&
            (!ictx->read_only) && (snap_id == CEPH_NOSNAP);
   }
 
index 9c1b2b8c8fa6c64530c40b085bb8cfb2f84f4c7a..13037846bac6debe46d93b1a6da7af267bffbcff 100644 (file)
@@ -124,7 +124,7 @@ void AsyncFlattenRequest::send() {
   AsyncObjectThrottle *throttle = new AsyncObjectThrottle(
     *this, context_factory, create_callback_context(), m_prog_ctx, 0,
     m_overlap_objects);
-  throttle->start_ops(m_image_ctx.rbd_concurrent_management_ops);
+  throttle->start_ops(m_image_ctx.concurrent_management_ops);
 }
 
 bool AsyncFlattenRequest::send_update_header() {
index 211ceffa5664ebda7657ba72cd5415f19138475a..996857c78356b4d55edfa2b0fce5ae4225517f37 100644 (file)
@@ -150,7 +150,7 @@ void AsyncTrimRequest::send_remove_objects() {
       boost::lambda::_1, &m_image_ctx, boost::lambda::_2));
   AsyncObjectThrottle *throttle = new AsyncObjectThrottle(
     *this, context_factory, ctx, m_prog_ctx, m_delete_start, m_num_objects);
-  throttle->start_ops(m_image_ctx.rbd_concurrent_management_ops);
+  throttle->start_ops(m_image_ctx.concurrent_management_ops);
 }
 
 void AsyncTrimRequest::send_pre_remove() {
index 0dc032e00b566aaa5f51f14c62422c4556145b33..14b490f0b743b4e7adcfd792fed5d00f8768c086 100644 (file)
@@ -2,6 +2,7 @@
 // vim: ts=8 sw=2 smarttab
 #include <errno.h>
 #include <boost/assign/list_of.hpp>
+#include <stddef.h>
 
 #include "common/ceph_context.h"
 #include "common/dout.h"
@@ -151,42 +152,42 @@ namespace librbd {
       header_oid = old_header_name(name);
     }
 
-    if (rbd_cache) {
+    if (cache) {
       Mutex::Locker l(cache_lock);
       ldout(cct, 20) << "enabling caching..." << dendl;
       writeback_handler = new LibrbdWriteback(this, cache_lock);
 
-      uint64_t init_max_dirty = rbd_cache_max_dirty;
-      if (rbd_cache_writethrough_until_flush)
+      uint64_t init_max_dirty = cache_max_dirty;
+      if (cache_writethrough_until_flush)
        init_max_dirty = 0;
       ldout(cct, 20) << "Initial cache settings:"
-                    << " size=" << rbd_cache_size
+                    << " size=" << cache_size
                     << " num_objects=" << 10
                     << " max_dirty=" << init_max_dirty
-                    << " target_dirty=" << rbd_cache_target_dirty
+                    << " target_dirty=" << cache_target_dirty
                     << " max_dirty_age="
-                    << rbd_cache_max_dirty_age << dendl;
+                    << cache_max_dirty_age << dendl;
 
       object_cacher = new ObjectCacher(cct, pname, *writeback_handler, cache_lock,
                                       NULL, NULL,
-                                      rbd_cache_size,
+                                      cache_size,
                                       10,  /* reset this in init */
                                       init_max_dirty,
-                                      rbd_cache_target_dirty,
-                                      rbd_cache_max_dirty_age,
-                                      rbd_cache_block_writes_upfront);
+                                      cache_target_dirty,
+                                      cache_max_dirty_age,
+                                      cache_block_writes_upfront);
       object_set = new ObjectCacher::ObjectSet(NULL, data_ctx.get_id(), 0);
       object_set->return_enoent = true;
       object_cacher->start();
     }
 
-    if (rbd_clone_copy_on_read) {
+    if (clone_copy_on_read) {
       copyup_finisher = new Finisher(cct);
       copyup_finisher->start();
     }
 
-    readahead.set_trigger_requests(rbd_readahead_trigger_requests);
-    readahead.set_max_readahead_size(rbd_readahead_max_bytes);
+    readahead.set_trigger_requests(readahead_trigger_requests);
+    readahead.set_max_readahead_size(readahead_max_bytes);
 
     perf_start(pname);
     return 0;
@@ -222,12 +223,12 @@ namespace librbd {
 
     // size object cache appropriately
     if (object_cacher) {
-      uint64_t obj = rbd_cache_max_dirty_object;
+      uint64_t obj = cache_max_dirty_object;
       if (!obj) {
-        obj = rbd_cache_size / (1ull << order);
+        obj = cache_size / (1ull << order);
         obj = obj * 4 + 10;
       }
-      ldout(cct, 10) << " cache bytes " << rbd_cache_size << " order " << (int)order
+      ldout(cct, 10) << " cache bytes " << cache_size << " order " << (int)order
                     << " -> about " << obj << " objects" << dendl;
       object_cacher->set_max_objects(obj);
     }
@@ -291,9 +292,9 @@ namespace librbd {
     if (snap_id == LIBRADOS_SNAP_HEAD)
       return flags;
 
-    if (rbd_balance_snap_reads)
+    if (balance_snap_reads)
       flags |= librados::OPERATION_BALANCE_READS;
-    else if (rbd_localize_snap_reads)
+    else if (localize_snap_reads)
       flags |= librados::OPERATION_LOCALIZE_READS;
     return flags;
   }
@@ -613,12 +614,12 @@ namespace librbd {
   }
 
   void ImageCtx::user_flushed() {
-    if (object_cacher && rbd_cache_writethrough_until_flush) {
+    if (object_cacher && cache_writethrough_until_flush) {
       md_lock.get_read();
       bool flushed_before = flush_encountered;
       md_lock.put_read();
 
-      uint64_t max_dirty = rbd_cache_max_dirty;
+      uint64_t max_dirty = cache_max_dirty;
       if (!flushed_before && max_dirty > 0) {
        md_lock.get_write();
        flush_encountered = true;
@@ -810,7 +811,7 @@ namespace librbd {
     }
   }
 
-  bool ImageCtx::_filter_metadata_confs(const string &prefix, const vector<string> &configs,
+  bool ImageCtx::_filter_metadata_confs(const string &prefix, map<string, bool> &configs,
                                         map<string, bufferlist> &pairs, map<string, bufferlist> *res) {
     size_t conf_prefix_len = prefix.size();
 
@@ -820,9 +821,10 @@ namespace librbd {
         return false;
 
       string key = it->first.substr(conf_prefix_len, it->first.size() - conf_prefix_len);
-      for (std::vector<string>::const_iterator cit = configs.begin();
+      for (map<string, bool>::iterator cit = configs.begin();
            cit != configs.end(); ++cit) {
-        if (!key.compare(*cit)) {
+        if (!key.compare(cit->first)) {
+          cit->second = true;
           res->insert(make_pair(key, it->second));
           break;
         }
@@ -834,31 +836,32 @@ namespace librbd {
   void ImageCtx::apply_metadata_confs() {
     ldout(cct, 20) << __func__ << dendl;
     static uint64_t max_conf_items = 128;
-    const std::vector<string> configs = boost::assign::list_of(
-        "rbd_cache")(
-        "rbd_cache_writethrough_until_flush")(
-        "rbd_cache_size")(
-        "rbd_cache_max_dirty")(
-        "rbd_cache_target_dirty")(
-        "rbd_cache_max_dirty_age")(
-        "rbd_cache_max_dirty_object")(
-        "rbd_cache_block_writes_upfront")(
-        "rbd_concurrent_management_ops")(
-        "rbd_balance_snap_reads")(
-        "rbd_localize_snap_reads")(
-        "rbd_balance_parent_reads")(
-        "rbd_localize_parent_reads")(
-        "rbd_readahead_trigger_requests")(
-        "rbd_readahead_max_bytes")(
-        "rbd_readahead_disable_after_bytes")(
-        "rbd_clone_copy_on_read")(
-        "rbd_blacklist_on_break_lock")(
-        "rbd_blacklist_expire_seconds")(
-        "rbd_request_timed_out_seconds");
+    std::map<string, bool> configs = boost::assign::map_list_of(
+        "rbd_cache", false)(
+        "rbd_cache_writethrough_until_flush", false)(
+        "rbd_cache_size", false)(
+        "rbd_cache_max_dirty", false)(
+        "rbd_cache_target_dirty", false)(
+        "rbd_cache_max_dirty_age", false)(
+        "rbd_cache_max_dirty_object", false)(
+        "rbd_cache_block_writes_upfront", false)(
+        "rbd_concurrent_management_ops", false)(
+        "rbd_balance_snap_reads", false)(
+        "rbd_localize_snap_reads", false)(
+        "rbd_balance_parent_reads", false)(
+        "rbd_localize_parent_reads", false)(
+        "rbd_readahead_trigger_requests", false)(
+        "rbd_readahead_max_bytes", false)(
+        "rbd_readahead_disable_after_bytes", false)(
+        "rbd_clone_copy_on_read", false)(
+        "rbd_blacklist_on_break_lock", false)(
+        "rbd_blacklist_expire_seconds", false)(
+        "rbd_request_timed_out_seconds", false);
 
     string start = METADATA_CONF_PREFIX;
     int r = 0, j = 0;
     bool is_continue;
+    md_config_t local_config_t;
     do {
       map<string, bufferlist> pairs, res;
       r = cls_client::metadata_list(&md_ctx, header_oid, start, max_conf_items, &pairs);
@@ -871,7 +874,7 @@ namespace librbd {
       
       is_continue = _filter_metadata_confs(METADATA_CONF_PREFIX, configs, pairs, &res);
       for (map<string, bufferlist>::iterator it = res.begin(); it != res.end(); ++it) {
-        j = cct->_conf->set_val(it->first.c_str(), it->second.c_str());
+        j = local_config_t.set_val(it->first.c_str(), it->second.c_str());
         if (j < 0)
           lderr(cct) << __func__ << " failed to set config " << it->first << " with value "
                      << it->second.c_str() << ": " << j << dendl;
@@ -880,26 +883,33 @@ namespace librbd {
       start = pairs.rbegin()->first;
     } while (is_continue);
 
-    md_config_t *conf = cct->_conf;
-    rbd_cache = conf->rbd_cache;
-    rbd_cache_writethrough_until_flush = conf->rbd_cache_writethrough_until_flush;
-    rbd_cache_size = conf->rbd_cache_size;
-    rbd_cache_max_dirty = conf->rbd_cache_max_dirty;
-    rbd_cache_target_dirty = conf->rbd_cache_target_dirty;
-    rbd_cache_max_dirty_age = conf->rbd_cache_max_dirty_age;
-    rbd_cache_max_dirty_object = conf->rbd_cache_max_dirty_object;
-    rbd_cache_block_writes_upfront = conf->rbd_cache_block_writes_upfront;
-    rbd_concurrent_management_ops = conf->rbd_concurrent_management_ops;
-    rbd_balance_snap_reads = conf->rbd_balance_snap_reads;
-    rbd_localize_snap_reads = conf->rbd_localize_snap_reads;
-    rbd_balance_parent_reads = conf->rbd_balance_parent_reads;
-    rbd_localize_parent_reads = conf->rbd_localize_parent_reads;
-    rbd_readahead_trigger_requests = conf->rbd_readahead_trigger_requests;
-    rbd_readahead_max_bytes = conf->rbd_readahead_max_bytes;
-    rbd_readahead_disable_after_bytes = conf->rbd_readahead_disable_after_bytes;
-    rbd_clone_copy_on_read = conf->rbd_clone_copy_on_read;
-    rbd_blacklist_on_break_lock = conf->rbd_blacklist_on_break_lock;
-    rbd_blacklist_expire_seconds = conf->rbd_blacklist_expire_seconds;
-    rbd_request_timed_out_seconds = conf->rbd_request_timed_out_seconds;
+#define ASSIGN_OPTION(config)                                                      \
+    do {                                                                           \
+      if (configs[#config])                                                        \
+        config = local_config_t.rbd_##config;                                      \
+      else                                                                         \
+        config = cct->_conf->rbd_##config;                                         \
+    } while (0);
+
+    ASSIGN_OPTION(cache);
+    ASSIGN_OPTION(cache_writethrough_until_flush);
+    ASSIGN_OPTION(cache_size);
+    ASSIGN_OPTION(cache_max_dirty);
+    ASSIGN_OPTION(cache_target_dirty);
+    ASSIGN_OPTION(cache_max_dirty_age);
+    ASSIGN_OPTION(cache_max_dirty_object);
+    ASSIGN_OPTION(cache_block_writes_upfront);
+    ASSIGN_OPTION(concurrent_management_ops);
+    ASSIGN_OPTION(balance_snap_reads);
+    ASSIGN_OPTION(localize_snap_reads);
+    ASSIGN_OPTION(balance_parent_reads);
+    ASSIGN_OPTION(localize_parent_reads);
+    ASSIGN_OPTION(readahead_trigger_requests);
+    ASSIGN_OPTION(readahead_max_bytes);
+    ASSIGN_OPTION(readahead_disable_after_bytes);
+    ASSIGN_OPTION(clone_copy_on_read);
+    ASSIGN_OPTION(blacklist_on_break_lock);
+    ASSIGN_OPTION(blacklist_expire_seconds);
+    ASSIGN_OPTION(request_timed_out_seconds);
   }
 }
index 32cb6a785b4a19c23e1824462aaa5b82275a88fc..e82111cf917a5c18a66a41ef82bcf3b92ff77597 100644 (file)
@@ -132,27 +132,27 @@ namespace librbd {
 
     // Configuration
     static const string METADATA_CONF_PREFIX;
-    bool rbd_cache;
-    bool rbd_cache_writethrough_until_flush;
-    uint64_t rbd_cache_size;
-    uint64_t rbd_cache_max_dirty;
-    uint64_t rbd_cache_target_dirty;
-    double rbd_cache_max_dirty_age;
-    uint32_t rbd_cache_max_dirty_object;
-    bool rbd_cache_block_writes_upfront;
-    uint32_t rbd_concurrent_management_ops;
-    bool rbd_balance_snap_reads;
-    bool rbd_localize_snap_reads;
-    bool rbd_balance_parent_reads;
-    bool rbd_localize_parent_reads;
-    uint32_t rbd_readahead_trigger_requests;
-    uint64_t rbd_readahead_max_bytes;
-    uint64_t rbd_readahead_disable_after_bytes;
-    bool rbd_clone_copy_on_read;
-    bool rbd_blacklist_on_break_lock;
-    uint32_t rbd_blacklist_expire_seconds;
-    uint32_t rbd_request_timed_out_seconds;
-    static bool _filter_metadata_confs(const string &prefix, const std::vector<string> &configs,
+    bool cache;
+    bool cache_writethrough_until_flush;
+    uint64_t cache_size;
+    uint64_t cache_max_dirty;
+    uint64_t cache_target_dirty;
+    double cache_max_dirty_age;
+    uint32_t cache_max_dirty_object;
+    bool cache_block_writes_upfront;
+    uint32_t concurrent_management_ops;
+    bool balance_snap_reads;
+    bool localize_snap_reads;
+    bool balance_parent_reads;
+    bool localize_parent_reads;
+    uint32_t readahead_trigger_requests;
+    uint64_t readahead_max_bytes;
+    uint64_t readahead_disable_after_bytes;
+    bool clone_copy_on_read;
+    bool blacklist_on_break_lock;
+    uint32_t blacklist_expire_seconds;
+    uint32_t request_timed_out_seconds;
+    static bool _filter_metadata_confs(const string &prefix, std::map<string, bool> &configs,
                                        map<string, bufferlist> &pairs, map<string, bufferlist> *res);
 
     /**
index ed8bfcf50077c0430a493da8f68e93293e332076..df5706cf38bc1b8c8f66aa0cd4359933641af14c 100644 (file)
@@ -153,12 +153,12 @@ int ImageWatcher::try_lock() {
       }
     }
 
-    if (m_image_ctx.rbd_blacklist_on_break_lock) {
+    if (m_image_ctx.blacklist_on_break_lock) {
       ldout(m_image_ctx.cct, 1) << "blacklisting client: " << locker << "@"
                                << locker_address << dendl;
       librados::Rados rados(m_image_ctx.md_ctx);
       r = rados.blacklist_add(locker_address,
-                             m_image_ctx.rbd_blacklist_expire_seconds);
+                             m_image_ctx.blacklist_expire_seconds);
       if (r < 0) {
         lderr(m_image_ctx.cct) << "unable to blacklist client: "
                               << cpp_strerror(r) << dendl;
@@ -662,7 +662,7 @@ void ImageWatcher::schedule_async_request_timed_out(const AsyncRequestId &id) {
   Task task(TASK_CODE_ASYNC_REQUEST, id);
   m_task_finisher->cancel(task);
 
-  m_task_finisher->add_event_after(task, m_image_ctx.rbd_request_timed_out_seconds, ctx);
+  m_task_finisher->add_event_after(task, m_image_ctx.request_timed_out_seconds, ctx);
 }
 
 void ImageWatcher::async_request_timed_out(const AsyncRequestId &id) {
index 77d1e29ba15e5bae7e7a7c753e7b8f2848415e53..66fc735f181b1beadd996784687de15abad61ec4 100644 (file)
@@ -303,7 +303,7 @@ namespace librbd {
 
     int r;
     CephContext *cct = ictx->cct;
-    SimpleThrottle throttle(ictx->rbd_concurrent_management_ops, true);
+    SimpleThrottle throttle(ictx->concurrent_management_ops, true);
 
     for (uint64_t i = 0; i < numseg; i++) {
       string oid = ictx->get_object_name(i);
@@ -1395,9 +1395,9 @@ reprotect_and_return_err:
     ictx->parent = new ImageCtx("", parent_image_id, NULL, p_ioctx, true);
 
     // set rados flags for reading the parent image
-    if (ictx->rbd_balance_parent_reads)
+    if (ictx->balance_parent_reads)
       ictx->parent->set_read_flag(librados::OPERATION_BALANCE_READS);
-    else if (ictx->rbd_localize_parent_reads)
+    else if (ictx->localize_parent_reads)
       ictx->parent->set_read_flag(librados::OPERATION_LOCALIZE_READS);
 
     r = open_image(ictx->parent);
@@ -2316,7 +2316,7 @@ reprotect_and_return_err:
       return r;
     }
 
-    SimpleThrottle throttle(src->rbd_concurrent_management_ops, false);
+    SimpleThrottle throttle(src->concurrent_management_ops, false);
     uint64_t period = src->get_stripe_period();
     for (uint64_t offset = 0; offset < src_size; offset += period) {
       uint64_t len = min(period, src_size - offset);
@@ -2704,7 +2704,7 @@ reprotect_and_return_err:
       return -EINVAL;
     }
 
-    if (ictx->rbd_blacklist_on_break_lock) {
+    if (ictx->blacklist_on_break_lock) {
       typedef std::map<rados::cls::lock::locker_id_t,
                       rados::cls::lock::locker_info_t> Lockers;
       Lockers lockers;
@@ -2734,7 +2734,7 @@ reprotect_and_return_err:
       RWLock::RLocker locker(ictx->md_lock);
       librados::Rados rados(ictx->md_ctx);
       r = rados.blacklist_add(client_address,
-                             ictx->rbd_blacklist_expire_seconds);
+                             ictx->blacklist_expire_seconds);
       if (r < 0) {
         lderr(ictx->cct) << "unable to blacklist client: " << cpp_strerror(r)
                       << dendl;
@@ -3640,8 +3640,8 @@ reprotect_and_return_err:
       total_bytes += p->second;
     }
     ictx->md_lock.get_write();
-    bool abort = ictx->rbd_readahead_disable_after_bytes != 0 &&
-      ictx->total_bytes_read > ictx->rbd_readahead_disable_after_bytes;
+    bool abort = ictx->readahead_disable_after_bytes != 0 &&
+      ictx->total_bytes_read > ictx->readahead_disable_after_bytes;
     ictx->total_bytes_read += total_bytes;
     ictx->snap_lock.get_read();
     uint64_t image_size = ictx->get_image_size(ictx->snap_id);
@@ -3686,7 +3686,7 @@ reprotect_and_return_err:
     }
 
     // readahead
-    if (ictx->object_cacher && ictx->rbd_readahead_max_bytes > 0 &&
+    if (ictx->object_cacher && ictx->readahead_max_bytes > 0 &&
        !(op_flags & LIBRADOS_OP_FLAG_FADVISE_RANDOM)) {
       readahead(ictx, image_extents);
     }
index 7952c127165f52a5828f078f4ca4d62f1c131c59..e6f8907c389475370abac2c098b6ad39cab12461 100644 (file)
@@ -366,10 +366,11 @@ TEST_F(TestInternal, MultipleResize) {
 TEST_F(TestInternal, MetadatConfig) {
   REQUIRE_FEATURE(RBD_FEATURE_LAYERING);
 
-  const vector<string> test_confs = boost::assign::list_of(
-    "aaaaaaa")(
-    "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")(
-    "cccccccccccccc");
+  map<string, bool> test_confs = boost::assign::map_list_of(
+    "aaaaaaa", false)(
+    "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", false)(
+    "cccccccccccccc", false);
+  map<string, bool>::iterator it = test_confs.begin();
   const string prefix = "test_config_";
   bool is_continue;
   librbd::ImageCtx *ictx;
@@ -377,18 +378,26 @@ TEST_F(TestInternal, MetadatConfig) {
 
   librbd::Image image1;
   map<string, bufferlist> pairs, res;
-  pairs[prefix+test_confs[0]].append("value1");
-  pairs[prefix+test_confs[1]].append("value2");
-  pairs[prefix+test_confs[2]].append("value3");
+  pairs[prefix+it->first].append("value1");
+  it++;
+  pairs[prefix+it->first].append("value2");
+  it++;
+  pairs[prefix+it->first].append("value3");
   pairs[prefix+"asdfsdaf"].append("value6");
   pairs[prefix+"zxvzxcv123"].append("value5");
 
   is_continue = ictx->_filter_metadata_confs(prefix, test_confs, pairs, &res);
   ASSERT_TRUE(is_continue);
   ASSERT_TRUE(res.size() == 3U);
-  ASSERT_TRUE(res.count(test_confs[0]));
-  ASSERT_TRUE(res.count(test_confs[1]));
-  ASSERT_TRUE(res.count(test_confs[2]));
+  it = test_confs.begin();
+  ASSERT_TRUE(res.count(it->first));
+  ASSERT_TRUE(it->second);
+  it++;
+  ASSERT_TRUE(res.count(it->first));
+  ASSERT_TRUE(it->second);
+  it++;
+  ASSERT_TRUE(res.count(it->first));
+  ASSERT_TRUE(it->second);
   res.clear();
 
   pairs["zzzzzzzz"].append("value7");