]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: moved object name helpers to librbd::util namespace
authorJason Dillaman <dillaman@redhat.com>
Tue, 17 Nov 2015 15:42:34 +0000 (10:42 -0500)
committerJason Dillaman <dillaman@redhat.com>
Tue, 15 Dec 2015 01:30:50 +0000 (20:30 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/CMakeLists.txt
src/librbd/AsyncObjectThrottle.cc
src/librbd/ImageCtx.cc
src/librbd/ImageWatcher.cc
src/librbd/Makefile.am
src/librbd/Utils.cc [new file with mode: 0644]
src/librbd/Utils.h
src/librbd/internal.cc
src/librbd/internal.h
src/librbd/operation/RenameRequest.cc

index 1a2f1db554d955c06a256577e72934251ce60a4a..5950d64d24865c207640e9906752cd8fe8ac3c4c 100644 (file)
@@ -888,6 +888,7 @@ if(${WITH_RBD})
     librbd/LibrbdAdminSocketHook.cc
     librbd/LibrbdWriteback.cc
     librbd/ObjectMap.cc
+    librbd/Utils.cc
     librbd/object_map/InvalidateRequest.cc
     librbd/object_map/Request.cc
     librbd/object_map/ResizeRequest.cc
index e4b07faf364d226390e0adc77e5a13c15ab20a9a..3bf195c9c449a8ff830cb9e73e683a5ca1469358 100644 (file)
@@ -7,6 +7,7 @@
 #include "librbd/AsyncRequest.h"
 #include "librbd/ImageCtx.h"
 #include "librbd/internal.h"
+#include "librbd/Utils.h"
 
 namespace librbd
 {
@@ -16,7 +17,7 @@ AsyncObjectThrottle<T>::AsyncObjectThrottle(
     const AsyncRequest<T>* async_request, T &image_ctx,
     const ContextFactory& context_factory, Context *ctx,
     ProgressContext *prog_ctx, uint64_t object_no, uint64_t end_object_no)
-  : m_lock(unique_lock_name("librbd::AsyncThrottle::m_lock", this)),
+  : m_lock(util::unique_lock_name("librbd::AsyncThrottle::m_lock", this)),
     m_async_request(async_request), m_image_ctx(image_ctx),
     m_context_factory(context_factory), m_ctx(ctx), m_prog_ctx(prog_ctx),
     m_object_no(object_no), m_end_object_no(end_object_no), m_current_ops(0),
index 5faad48cf5392f900e61b1d17dedbeacc21710ac..6ad3415dd7132209a26e29990cc12075c26b4c59 100644 (file)
@@ -21,6 +21,7 @@
 #include "librbd/LibrbdAdminSocketHook.h"
 #include "librbd/ObjectMap.h"
 #include "librbd/operation/ResizeRequest.h"
+#include "librbd/Utils.h"
 
 #include <boost/bind.hpp>
 
@@ -131,16 +132,16 @@ struct C_InvalidateCache : public Context {
       journal(NULL),
       refresh_seq(0),
       last_refresh(0),
-      owner_lock(unique_lock_name("librbd::ImageCtx::owner_lock", this)),
-      md_lock(unique_lock_name("librbd::ImageCtx::md_lock", this)),
-      cache_lock(unique_lock_name("librbd::ImageCtx::cache_lock", this)),
-      snap_lock(unique_lock_name("librbd::ImageCtx::snap_lock", this)),
-      parent_lock(unique_lock_name("librbd::ImageCtx::parent_lock", this)),
-      refresh_lock(unique_lock_name("librbd::ImageCtx::refresh_lock", this)),
-      object_map_lock(unique_lock_name("librbd::ImageCtx::object_map_lock", this)),
-      async_ops_lock(unique_lock_name("librbd::ImageCtx::async_ops_lock", this)),
-      copyup_list_lock(unique_lock_name("librbd::ImageCtx::copyup_list_lock", this)),
-      completed_reqs_lock(unique_lock_name("librbd::ImageCtx::completed_reqs_lock", this)),
+      owner_lock(util::unique_lock_name("librbd::ImageCtx::owner_lock", this)),
+      md_lock(util::unique_lock_name("librbd::ImageCtx::md_lock", this)),
+      cache_lock(util::unique_lock_name("librbd::ImageCtx::cache_lock", this)),
+      snap_lock(util::unique_lock_name("librbd::ImageCtx::snap_lock", this)),
+      parent_lock(util::unique_lock_name("librbd::ImageCtx::parent_lock", this)),
+      refresh_lock(util::unique_lock_name("librbd::ImageCtx::refresh_lock", this)),
+      object_map_lock(util::unique_lock_name("librbd::ImageCtx::object_map_lock", this)),
+      async_ops_lock(util::unique_lock_name("librbd::ImageCtx::async_ops_lock", this)),
+      copyup_list_lock(util::unique_lock_name("librbd::ImageCtx::copyup_list_lock", this)),
+      completed_reqs_lock(util::unique_lock_name("librbd::ImageCtx::completed_reqs_lock", this)),
       extra_read_flags(0),
       old_format(true),
       order(0), size(0), features(0),
@@ -216,7 +217,7 @@ struct C_InvalidateCache : public Context {
 
     if (!old_format) {
       if (!id.length()) {
-       r = cls_client::get_id(&md_ctx, id_obj_name(name), &id);
+       r = cls_client::get_id(&md_ctx, util::id_obj_name(name), &id);
        if (r < 0) {
          lderr(cct) << "error reading image id: " << cpp_strerror(r)
                     << dendl;
@@ -224,7 +225,7 @@ struct C_InvalidateCache : public Context {
        }
       }
 
-      header_oid = header_name(id);
+      header_oid = util::header_name(id);
       apply_metadata_confs();
       r = cls_client::get_immutable_metadata(&md_ctx, header_oid,
                                             &object_prefix, &order);
@@ -245,7 +246,7 @@ struct C_InvalidateCache : public Context {
       init_layout();
     } else {
       apply_metadata_confs();
-      header_oid = old_header_name(name);
+      header_oid = util::old_header_name(name);
     }
 
     string pname = string("librbd-") + id + string("-") +
index f06856e22014f0eb06450bedb8461c3b5c6ff21b..8ffd751930f891c5bd03a9907ae3173dcf9edfa4 100644 (file)
@@ -6,6 +6,7 @@
 #include "librbd/internal.h"
 #include "librbd/ObjectMap.h"
 #include "librbd/TaskFinisher.h"
+#include "librbd/Utils.h"
 #include "cls/lock/cls_lock_client.h"
 #include "cls/lock/cls_lock_types.h"
 #include "include/encoding.h"
@@ -32,17 +33,16 @@ static const double RETRY_DELAY_SECONDS = 1.0;
 
 ImageWatcher::ImageWatcher(ImageCtx &image_ctx)
   : m_image_ctx(image_ctx),
-    m_watch_lock(unique_lock_name("librbd::ImageWatcher::m_watch_lock", this)),
+    m_watch_lock(util::unique_lock_name("librbd::ImageWatcher::m_watch_lock", this)),
     m_watch_ctx(*this), m_watch_handle(0),
     m_watch_state(WATCH_STATE_UNREGISTERED),
-    m_refresh_lock(unique_lock_name("librbd::ImageWatcher::m_refresh_lock",
-                                    this)),
+    m_refresh_lock(util::unique_lock_name("librbd::ImageWatcher::m_refresh_lock", this)),
     m_lock_supported(false), m_lock_owner_state(LOCK_OWNER_STATE_NOT_LOCKED),
-    m_listeners_lock(unique_lock_name("librbd::ImageWatcher::m_listeners_lock", this)),
+    m_listeners_lock(util::unique_lock_name("librbd::ImageWatcher::m_listeners_lock", this)),
     m_listeners_in_use(false),
     m_task_finisher(new TaskFinisher<Task>(*m_image_ctx.cct)),
-    m_async_request_lock(unique_lock_name("librbd::ImageWatcher::m_async_request_lock", this)),
-    m_owner_client_id_lock(unique_lock_name("librbd::ImageWatcher::m_owner_client_id_lock", this))
+    m_async_request_lock(util::unique_lock_name("librbd::ImageWatcher::m_async_request_lock", this)),
+    m_owner_client_id_lock(util::unique_lock_name("librbd::ImageWatcher::m_owner_client_id_lock", this))
 {
 }
 
index 5a3bd9462f9e94853d744c9520316b7f2cafbd38..a21bb0a4a2fb644cb3b5126116aa7539c4371b41 100644 (file)
@@ -25,6 +25,7 @@ librbd_internal_la_SOURCES = \
        librbd/LibrbdAdminSocketHook.cc \
        librbd/LibrbdWriteback.cc \
        librbd/ObjectMap.cc \
+       librbd/Utils.cc \
        librbd/object_map/InvalidateRequest.cc \
        librbd/object_map/Request.cc \
        librbd/object_map/ResizeRequest.cc \
diff --git a/src/librbd/Utils.cc b/src/librbd/Utils.cc
new file mode 100644 (file)
index 0000000..d89418f
--- /dev/null
@@ -0,0 +1,31 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "librbd/Utils.h"
+#include "include/rbd_types.h"
+#include "include/stringify.h"
+
+namespace librbd {
+namespace util {
+
+const std::string id_obj_name(const std::string &name)
+{
+  return RBD_ID_PREFIX + name;
+}
+
+const std::string header_name(const std::string &image_id)
+{
+  return RBD_HEADER_PREFIX + image_id;
+}
+
+const std::string old_header_name(const std::string &image_name)
+{
+  return image_name + RBD_SUFFIX;
+}
+
+std::string unique_lock_name(const std::string &name, void *address) {
+  return name + " (" + stringify(address) + ")";
+}
+
+} // namespace util
+} // namespace librbd
index bbb30b1ecd043f147946e88b225ff1afd95620e2..0986f060b981df8dcd82c2ab1bb00684cdbd1b4b 100644 (file)
@@ -86,6 +86,11 @@ struct C_AsyncCallback : public Context {
 
 } // namespace detail
 
+const std::string id_obj_name(const std::string &name);
+const std::string header_name(const std::string &image_id);
+const std::string old_header_name(const std::string &image_name);
+std::string unique_lock_name(const std::string &name, void *address);
+
 template <typename T>
 librados::AioCompletion *create_rados_ack_callback(T *obj) {
   return librados::Rados::aio_create_completion(
index 8ee94a5af290b9e95037c0e08a9eb1295b796f69..24150d94d58fd2b279afe59783886e1cdb889885 100644 (file)
@@ -260,36 +260,17 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
 
 } // anonymous namespace
 
-  const string id_obj_name(const string &name)
-  {
-    return RBD_ID_PREFIX + name;
-  }
-
-  const string header_name(const string &image_id)
-  {
-    return RBD_HEADER_PREFIX + image_id;
-  }
-
-  const string old_header_name(const string &image_name)
-  {
-    return image_name + RBD_SUFFIX;
-  }
-
-  std::string unique_lock_name(const std::string &name, void *address) {
-    return name + " (" + stringify(address) + ")";
-  }
-
   int detect_format(IoCtx &io_ctx, const string &name,
                    bool *old_format, uint64_t *size)
   {
     CephContext *cct = (CephContext *)io_ctx.cct();
     if (old_format)
       *old_format = true;
-    int r = io_ctx.stat(old_header_name(name), size, NULL);
+    int r = io_ctx.stat(util::old_header_name(name), size, NULL);
     if (r == -ENOENT) {
       if (old_format)
        *old_format = false;
-      r = io_ctx.stat(id_obj_name(name), size, NULL);
+      r = io_ctx.stat(util::id_obj_name(name), size, NULL);
       if (r < 0)
        return r;
     } else if (r < 0) {
@@ -1199,7 +1180,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
     bufferlist bl;
     bl.append((const char *)&header, sizeof(header));
 
-    string header_oid = old_header_name(imgname);
+    string header_oid = util::old_header_name(imgname);
     r = io_ctx.write(header_oid, bl, bl.length(), 0);
     if (r < 0) {
       lderr(cct) << "Error writing image header: " << cpp_strerror(r)
@@ -1237,7 +1218,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
       return r;
     }
 
-    id_obj = id_obj_name(imgname);
+    id_obj = util::id_obj_name(imgname);
 
     r = io_ctx.create(id_obj, true);
     if (r < 0) {
@@ -1264,7 +1245,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
     }
 
     oss << RBD_DATA_PREFIX << id;
-    header_oid = header_name(id);
+    header_oid = util::header_name(id);
     r = cls_client::create_image(&io_ctx, header_oid, size, order,
                                 features, oss.str());
     if (r < 0) {
@@ -2251,7 +2232,7 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) {
       }
 
       ldout(cct, 2) << "removing id object..." << dendl;
-      r = io_ctx.remove(id_obj_name(imgname));
+      r = io_ctx.remove(util::id_obj_name(imgname));
       if (r < 0 && r != -ENOENT) {
        lderr(cct) << "error removing id object: " << cpp_strerror(r) << dendl;
        return r;
index a672b52a3eb07dd9ff1dbc43a9caba5ee1ddbe69..042ba01634d4dff9effad8910dc4da4d14dbd61b 100644 (file)
@@ -68,11 +68,6 @@ namespace librbd {
     }
   };
 
-  const std::string id_obj_name(const std::string &name);
-  const std::string header_name(const std::string &image_id);
-  const std::string old_header_name(const std::string &image_name);
-  std::string unique_lock_name(const std::string &name, void *address);
-
   int detect_format(librados::IoCtx &io_ctx, const std::string &name,
                    bool *old_format, uint64_t *size);
 
index 316229c66c7dc11df031726fbca45fbaa9a4bcbb..aa5e09fa155f8fdf97374ee3e54df8eb434afee1 100644 (file)
@@ -7,6 +7,7 @@
 #include "include/rados/librados.hpp"
 #include "librbd/ImageCtx.h"
 #include "librbd/internal.h"
+#include "librbd/Utils.h"
 
 #define dout_subsys ceph_subsys_rbd
 #undef dout_prefix
@@ -46,10 +47,10 @@ template <typename I>
 RenameRequest<I>::RenameRequest(I &image_ctx, Context *on_finish,
                                const std::string &dest_name)
   : Request<I>(image_ctx, on_finish), m_dest_name(dest_name),
-    m_source_oid(image_ctx.old_format ? old_header_name(image_ctx.name) :
-                                        id_obj_name(image_ctx.name)),
-    m_dest_oid(image_ctx.old_format ? old_header_name(dest_name) :
-                                      id_obj_name(dest_name)) {
+    m_source_oid(image_ctx.old_format ? util::old_header_name(image_ctx.name) :
+                                        util::id_obj_name(image_ctx.name)),
+    m_dest_oid(image_ctx.old_format ? util::old_header_name(dest_name) :
+                                      util::id_obj_name(dest_name)) {
 }
 
 template <typename I>