]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: moved local to remote snapshot lookup to common function
authorJason Dillaman <dillaman@redhat.com>
Thu, 20 Feb 2020 17:57:26 +0000 (12:57 -0500)
committerJason Dillaman <dillaman@redhat.com>
Mon, 24 Feb 2020 21:03:23 +0000 (16:03 -0500)
This will be needed by the status formatter to lookup the remote
snapshot timestamp since the associated local snapshot timestamp
will be the time the snapshot was created on the local side.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/tools/rbd_mirror/CMakeLists.txt
src/tools/rbd_mirror/image_replayer/snapshot/ApplyImageStateRequest.cc
src/tools/rbd_mirror/image_replayer/snapshot/Utils.cc [new file with mode: 0644]
src/tools/rbd_mirror/image_replayer/snapshot/Utils.h [new file with mode: 0644]

index 1c288c9cc5f8b75654b25da8a9d730c62e6019f5..edf4775fd96832c4d80b20298c94cf8dc800f2ca 100644 (file)
@@ -56,6 +56,7 @@ set(rbd_mirror_internal
   image_replayer/snapshot/PrepareReplayRequest.cc
   image_replayer/snapshot/Replayer.cc
   image_replayer/snapshot/StateBuilder.cc
+  image_replayer/snapshot/Utils.cc
   image_sync/SyncPointCreateRequest.cc
   image_sync/SyncPointPruneRequest.cc
   image_sync/Utils.cc
index 6bceded0c5071bd7f34fd5b68e60136baca40c3b..3d85a85fc46f8fcbba2d8e4e3a7a4785a32e2c34 100644 (file)
@@ -9,6 +9,7 @@
 #include "librbd/Operations.h"
 #include "librbd/Utils.h"
 #include "librbd/image/GetMetadataRequest.h"
+#include "tools/rbd_mirror/image_replayer/snapshot/Utils.h"
 
 #define dout_context g_ceph_context
 #define dout_subsys ceph_subsys_rbd_mirror
@@ -593,38 +594,17 @@ uint64_t ApplyImageStateRequest<I>::compute_remote_snap_id(
   // Search our local non-primary snapshots for a mapping to the remote
   // snapshot. The non-primary mirror snapshot with the mappings will always
   // come at or after the snapshot we are searching against
-  auto snap_it = m_local_image_ctx->snap_info.lower_bound(local_snap_id);
-  for (; snap_it != m_local_image_ctx->snap_info.end(); ++snap_it) {
-    auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>(
-      &snap_it->second.snap_namespace);
-    if (mirror_ns == nullptr || !mirror_ns->is_non_primary()) {
-      continue;
-    }
-
-    if (mirror_ns->primary_mirror_uuid != m_remote_mirror_uuid) {
-      dout(20) << "local snapshot " << snap_it->first << " not tied to remote"
-               << dendl;
-      continue;
-    } else if (local_snap_id == snap_it->first) {
-      dout(15) << "local snapshot " << local_snap_id << " maps to "
-               << "remote snapshot " << mirror_ns->primary_snap_id << dendl;
-      return mirror_ns->primary_snap_id;
-    }
-
-    const auto& snap_seqs = mirror_ns->snap_seqs;
-    for (auto [remote_snap_id_seq, local_snap_id_seq] : snap_seqs) {
-      if (local_snap_id_seq == local_snap_id) {
-        dout(15) << "local snapshot " << local_snap_id << " maps to "
-                 << "remote snapshot " << remote_snap_id_seq << dendl;
-        return remote_snap_id_seq;
-      }
-    }
+  auto remote_snap_id = util::compute_remote_snap_id(
+    m_local_image_ctx->image_lock, m_local_image_ctx->snap_info,
+    local_snap_id, m_remote_mirror_uuid);
+  if (remote_snap_id != CEPH_NOSNAP) {
+    return remote_snap_id;
   }
 
   // if we failed to find a match to a remote snapshot in our local non-primary
   // snapshots, check the remote image for non-primary snapshot mappings back
   // to our snapshot
-  for (snap_it = m_remote_image_ctx->snap_info.begin();
+  for (auto snap_it = m_remote_image_ctx->snap_info.begin();
        snap_it != m_remote_image_ctx->snap_info.end(); ++snap_it) {
     auto snap_id = snap_it->first;
     auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>(
diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Utils.cc b/src/tools/rbd_mirror/image_replayer/snapshot/Utils.cc
new file mode 100644 (file)
index 0000000..7c20410
--- /dev/null
@@ -0,0 +1,65 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include "Utils.h"
+#include "common/debug.h"
+#include "common/errno.h"
+#include "cls/rbd/cls_rbd_types.h"
+
+#define dout_context g_ceph_context
+#define dout_subsys ceph_subsys_rbd_mirror
+#undef dout_prefix
+#define dout_prefix *_dout << "rbd::mirror::image_replayer::snapshot::util::" \
+                           << __func__ << ": "
+
+namespace rbd {
+namespace mirror {
+namespace image_replayer {
+namespace snapshot {
+namespace util {
+
+uint64_t compute_remote_snap_id(
+    const ceph::shared_mutex& local_image_lock,
+    const std::map<librados::snap_t, librbd::SnapInfo>& local_snap_infos,
+    uint64_t local_snap_id, const std::string& remote_mirror_uuid) {
+  ceph_assert(ceph_mutex_is_locked(local_image_lock));
+
+  // Search our local non-primary snapshots for a mapping to the remote
+  // snapshot. The non-primary mirror snapshot with the mappings will always
+  // come at or after the snapshot we are searching against
+  for (auto snap_it = local_snap_infos.lower_bound(local_snap_id);
+       snap_it != local_snap_infos.end(); ++snap_it) {
+    auto mirror_ns = boost::get<cls::rbd::MirrorSnapshotNamespace>(
+      &snap_it->second.snap_namespace);
+    if (mirror_ns == nullptr || !mirror_ns->is_non_primary()) {
+      continue;
+    }
+
+    if (mirror_ns->primary_mirror_uuid != remote_mirror_uuid) {
+      dout(20) << "local snapshot " << snap_it->first << " not tied to remote"
+               << dendl;
+      continue;
+    } else if (local_snap_id == snap_it->first) {
+      dout(15) << "local snapshot " << local_snap_id << " maps to "
+               << "remote snapshot " << mirror_ns->primary_snap_id << dendl;
+      return mirror_ns->primary_snap_id;
+    }
+
+    const auto& snap_seqs = mirror_ns->snap_seqs;
+    for (auto [remote_snap_id_seq, local_snap_id_seq] : snap_seqs) {
+      if (local_snap_id_seq == local_snap_id) {
+        dout(15) << "local snapshot " << local_snap_id << " maps to "
+                 << "remote snapshot " << remote_snap_id_seq << dendl;
+        return remote_snap_id_seq;
+      }
+    }
+  }
+
+  return CEPH_NOSNAP;
+}
+
+} // namespace util
+} // namespace snapshot
+} // namespace image_replayer
+} // namespace mirror
+} // namespace rbd
diff --git a/src/tools/rbd_mirror/image_replayer/snapshot/Utils.h b/src/tools/rbd_mirror/image_replayer/snapshot/Utils.h
new file mode 100644 (file)
index 0000000..8efc586
--- /dev/null
@@ -0,0 +1,30 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#ifndef RBD_MIRROR_IMAGE_REPLAYER_SNAPSHOT_UTILS_H
+#define RBD_MIRROR_IMAGE_REPLAYER_SNAPSHOT_UTILS_H
+
+#include "include/int_types.h"
+#include "include/rados/librados.hpp"
+#include "common/ceph_mutex.h"
+#include "librbd/Types.h"
+#include <map>
+
+namespace rbd {
+namespace mirror {
+namespace image_replayer {
+namespace snapshot {
+namespace util {
+
+uint64_t compute_remote_snap_id(
+    const ceph::shared_mutex& local_image_lock,
+    const std::map<librados::snap_t, librbd::SnapInfo>& local_snap_infos,
+    uint64_t local_snap_id, const std::string& remote_mirror_uuid);
+
+} // namespace util
+} // namespace snapshot
+} // namespace image_replayer
+} // namespace mirror
+} // namespace rbd
+
+#endif // RBD_MIRROR_IMAGE_REPLAYER_SNAPSHOT_UTILS_H