]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
rbd-mirror: moved image asok/perf counter name helper to utils
authorJason Dillaman <dillaman@redhat.com>
Fri, 13 Dec 2019 01:46:14 +0000 (20:46 -0500)
committerJason Dillaman <dillaman@redhat.com>
Mon, 16 Dec 2019 01:08:10 +0000 (20:08 -0500)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/tools/rbd_mirror/ImageReplayer.cc
src/tools/rbd_mirror/ImageReplayer.h
src/tools/rbd_mirror/image_replayer/Utils.cc
src/tools/rbd_mirror/image_replayer/Utils.h

index 42ef95606184df62dd453b414153334f40e3466e..8bed3fc28be48ea41955a0c351efafc6e6e3501f 100644 (file)
@@ -29,6 +29,7 @@
 #include "tools/rbd_mirror/image_replayer/CloseImageRequest.h"
 #include "tools/rbd_mirror/image_replayer/PrepareLocalImageRequest.h"
 #include "tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h"
+#include "tools/rbd_mirror/image_replayer/Utils.h"
 #include "tools/rbd_mirror/image_replayer/journal/EventPreprocessor.h"
 #include "tools/rbd_mirror/image_replayer/journal/ReplayStatusFormatter.h"
 
@@ -273,7 +274,8 @@ ImageReplayer<I>::ImageReplayer(
   // name.  When the image name becomes known on start the asok commands will be
   // re-registered using "remote_pool_name/remote_image_name" name.
 
-  m_name = admin_socket_hook_name(global_image_id);
+  m_image_spec = image_replayer::util::compute_image_spec(
+    local_io_ctx, global_image_id);
   register_admin_socket_hook();
 }
 
@@ -974,7 +976,7 @@ void ImageReplayer<I>::print_status(Formatter *f)
   std::lock_guard l{m_lock};
 
   f->open_object_section("image_replayer");
-  f->dump_string("name", m_name);
+  f->dump_string("name", m_image_spec);
   f->dump_string("state", to_string(m_state));
   f->close_section();
 }
@@ -1734,16 +1736,18 @@ void ImageReplayer<I>::register_admin_socket_hook() {
 
     ceph_assert(m_perf_counters == nullptr);
 
-    dout(15) << "registered asok hook: " << m_name << dendl;
-    asok_hook = new ImageReplayerAdminSocketHook<I>(g_ceph_context, m_name,
-                                                    this);
+    dout(15) << "registered asok hook: " << m_image_spec << dendl;
+    asok_hook = new ImageReplayerAdminSocketHook<I>(
+      g_ceph_context, m_image_spec, this);
     int r = asok_hook->register_commands();
     if (r == 0) {
       m_asok_hook = asok_hook;
 
       CephContext *cct = static_cast<CephContext *>(m_local_io_ctx.cct());
-      auto prio = cct->_conf.get_val<int64_t>("rbd_mirror_image_perf_stats_prio");
-      PerfCountersBuilder plb(g_ceph_context, "rbd_mirror_image_" + m_name,
+      auto prio = cct->_conf.get_val<int64_t>(
+        "rbd_mirror_image_perf_stats_prio");
+      PerfCountersBuilder plb(g_ceph_context,
+                              "rbd_mirror_image_" + m_image_spec,
                               l_rbd_mirror_first, l_rbd_mirror_last);
       plb.add_u64_counter(l_rbd_mirror_replay, "replay", "Replays", "r", prio);
       plb.add_u64_counter(l_rbd_mirror_replay_bytes, "replay_bytes",
@@ -1783,27 +1787,17 @@ void ImageReplayer<I>::reregister_admin_socket_hook() {
   {
     std::lock_guard locker{m_lock};
 
-    auto name = admin_socket_hook_name(m_local_image_name);
-    if (m_asok_hook != nullptr && m_name == name) {
+    auto image_spec = image_replayer::util::compute_image_spec(
+      m_local_io_ctx, m_local_image_name);
+    if (m_asok_hook != nullptr && m_image_spec == image_spec) {
       return;
     }
-    m_name = name;
+    m_image_spec = image_spec;
   }
   unregister_admin_socket_hook();
   register_admin_socket_hook();
 }
 
-template <typename I>
-std::string ImageReplayer<I>::admin_socket_hook_name(
-    const std::string &image_name) const {
-  std::string name = m_local_io_ctx.get_namespace();
-  if (!name.empty()) {
-    name += "/";
-  }
-
-  return m_local_io_ctx.get_pool_name() + "/" + name + image_name;
-}
-
 template <typename I>
 std::ostream &operator<<(std::ostream &os, const ImageReplayer<I> &replayer)
 {
index f121f02e53efc7bf42f00d55ab611e28e37aae2d..03b200730abbab77f4db917bd4a42a0577bc7d48 100644 (file)
@@ -100,7 +100,7 @@ public:
   bool is_running() { std::lock_guard l{m_lock}; return is_running_(); }
   bool is_replaying() { std::lock_guard l{m_lock}; return is_replaying_(); }
 
-  std::string get_name() { std::lock_guard l{m_lock}; return m_name; };
+  std::string get_name() { std::lock_guard l{m_lock}; return m_image_spec; };
   void set_state_description(int r, const std::string &desc);
 
   // TODO temporary until policy handles release of image replayers
@@ -298,7 +298,7 @@ private:
 
   std::string m_local_image_id;
   std::string m_local_image_name;
-  std::string m_name;
+  std::string m_image_spec;
 
   mutable ceph::mutex m_lock;
   State m_state = STATE_STOPPED;
@@ -445,8 +445,6 @@ private:
   void register_admin_socket_hook();
   void unregister_admin_socket_hook();
   void reregister_admin_socket_hook();
-
-  std::string admin_socket_hook_name(const std::string &image_name) const;
 };
 
 } // namespace mirror
index eda0179f29d56f8356452219132ee3838e6cb735..55162a4e4b58df9e8b3682c04c5bc058ea7a23e6 100644 (file)
@@ -2,6 +2,7 @@
 // vim: ts=8 sw=2 smarttab
 
 #include "tools/rbd_mirror/image_replayer/Utils.h"
+#include "include/rados/librados.hpp"
 #include "common/debug.h"
 #include "common/errno.h"
 #include "cls/journal/cls_journal_types.h"
@@ -18,6 +19,16 @@ namespace mirror {
 namespace image_replayer {
 namespace util {
 
+std::string compute_image_spec(librados::IoCtx& io_ctx,
+                               const std::string& image_name) {
+  std::string name = io_ctx.get_namespace();
+  if (!name.empty()) {
+    name += "/";
+  }
+
+  return io_ctx.get_pool_name() + "/" + name + image_name;
+}
+
 bool decode_client_meta(const cls::journal::Client& client,
                         librbd::journal::MirrorPeerClientMeta* client_meta) {
   dout(15) << dendl;
index d42146d150f479a107f5ea2877400b8205b7c481..6c5352cd1513dcdbb054006673e6641d2b40c125 100644 (file)
@@ -4,6 +4,9 @@
 #ifndef RBD_MIRROR_IMAGE_REPLAYER_UTILS_H
 #define RBD_MIRROR_IMAGE_REPLAYER_UTILS_H
 
+#include "include/rados/librados_fwd.hpp"
+#include <string>
+
 namespace cls { namespace journal { struct Client; } }
 namespace librbd { namespace journal { struct MirrorPeerClientMeta; } }
 
@@ -12,6 +15,9 @@ namespace mirror {
 namespace image_replayer {
 namespace util {
 
+std::string compute_image_spec(librados::IoCtx& io_ctx,
+                               const std::string& image_name);
+
 bool decode_client_meta(const cls::journal::Client& client,
                         librbd::journal::MirrorPeerClientMeta* client_meta);