]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/rbd_mirror/test_ImageSync.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / test / rbd_mirror / test_ImageSync.cc
index 89b223fb591e06a8cdd7d823592f56fbe1b590fa..fbd3381116d280531640c2bed0e513e2cc3273c6 100644 (file)
@@ -11,6 +11,8 @@
 #include "librbd/ImageState.h"
 #include "librbd/internal.h"
 #include "librbd/Operations.h"
+#include "librbd/io/AioCompletion.h"
+#include "librbd/io/ImageDispatchSpec.h"
 #include "librbd/io/ImageRequestWQ.h"
 #include "librbd/io/ReadResult.h"
 #include "librbd/journal/Types.h"
@@ -26,15 +28,28 @@ namespace mirror {
 
 namespace {
 
-void scribble(librbd::ImageCtx *image_ctx, int num_ops, size_t max_size)
+int flush(librbd::ImageCtx *image_ctx) {
+  C_SaferCond ctx;
+  auto aio_comp = librbd::io::AioCompletion::create(
+    &ctx, image_ctx, librbd::io::AIO_TYPE_FLUSH);
+  auto req = librbd::io::ImageDispatchSpec<>::create_flush_request(
+    *image_ctx, aio_comp, librbd::io::FLUSH_SOURCE_INTERNAL, {});
+  req->send();
+  delete req;
+  return ctx.wait();
+}
+
+void scribble(librbd::ImageCtx *image_ctx, int num_ops, uint64_t max_size)
 {
-  max_size = MIN(image_ctx->size, max_size);
+  max_size = std::min<uint64_t>(image_ctx->size, max_size);
   for (int i=0; i<num_ops; i++) {
     uint64_t off = rand() % (image_ctx->size - max_size + 1);
     uint64_t len = 1 + rand() % max_size;
 
     if (rand() % 4 == 0) {
-      ASSERT_EQ((int)len, image_ctx->io_work_queue->discard(off, len, image_ctx->skip_partial_discard));
+      ASSERT_EQ((int)len,
+                image_ctx->io_work_queue->discard(
+                  off, len, image_ctx->discard_granularity_bytes));
     } else {
       bufferlist bl;
       bl.append(std::string(len, '1'));
@@ -44,7 +59,7 @@ void scribble(librbd::ImageCtx *image_ctx, int num_ops, size_t max_size)
   }
 
   RWLock::RLocker owner_locker(image_ctx->owner_lock);
-  ASSERT_EQ(0, image_ctx->flush());
+  ASSERT_EQ(0, flush(image_ctx));
 }
 
 } // anonymous namespace
@@ -68,7 +83,7 @@ public:
 
     librbd::journal::ClientData client_data(m_client_meta);
     bufferlist client_data_bl;
-    ::encode(client_data, client_data_bl);
+    encode(client_data, client_data_bl);
 
     ASSERT_EQ(0, m_remote_journaler->register_client(client_data_bl));
   }
@@ -164,7 +179,7 @@ TEST_F(TestImageSync, Resize) {
                                                                0));
   {
     RWLock::RLocker owner_locker(m_remote_image_ctx->owner_lock);
-    ASSERT_EQ(0, m_remote_image_ctx->flush());
+    ASSERT_EQ(0, flush(m_remote_image_ctx));
   }
 
   ASSERT_EQ(0, create_snap(m_remote_image_ctx, "snap", nullptr));
@@ -206,16 +221,17 @@ TEST_F(TestImageSync, Discard) {
                                                                0));
   {
     RWLock::RLocker owner_locker(m_remote_image_ctx->owner_lock);
-    ASSERT_EQ(0, m_remote_image_ctx->flush());
+    ASSERT_EQ(0, flush(m_remote_image_ctx));
   }
 
   ASSERT_EQ(0, create_snap(m_remote_image_ctx, "snap", nullptr));
 
-  ASSERT_EQ((int)len - 2, m_remote_image_ctx->io_work_queue->discard(off + 1,
-                                                                     len - 2, m_remote_image_ctx->skip_partial_discard));
+  ASSERT_EQ((int)len - 2,
+            m_remote_image_ctx->io_work_queue->discard(
+              off + 1, len - 2, m_remote_image_ctx->discard_granularity_bytes));
   {
     RWLock::RLocker owner_locker(m_remote_image_ctx->owner_lock);
-    ASSERT_EQ(0, m_remote_image_ctx->flush());
+    ASSERT_EQ(0, flush(m_remote_image_ctx));
   }
 
   C_SaferCond ctx;
@@ -271,12 +287,17 @@ TEST_F(TestImageSync, SnapshotStress) {
   read_local_bl.append(std::string(object_size, '1'));
 
   for (auto &snap_name : snap_names) {
+    uint64_t remote_snap_id;
+    {
+      RWLock::RLocker remote_snap_locker(m_remote_image_ctx->snap_lock);
+      remote_snap_id = m_remote_image_ctx->get_snap_id(
+        cls::rbd::UserSnapshotNamespace{}, snap_name);
+    }
+
     uint64_t remote_size;
     {
       C_SaferCond ctx;
-      m_remote_image_ctx->state->snap_set(cls::rbd::UserSnapshotNamespace(),
-                                         snap_name,
-                                         &ctx);
+      m_remote_image_ctx->state->snap_set(remote_snap_id, &ctx);
       ASSERT_EQ(0, ctx.wait());
 
       RWLock::RLocker remote_snap_locker(m_remote_image_ctx->snap_lock);
@@ -284,12 +305,17 @@ TEST_F(TestImageSync, SnapshotStress) {
         m_remote_image_ctx->snap_id);
     }
 
+    uint64_t local_snap_id;
+    {
+      RWLock::RLocker snap_locker(m_local_image_ctx->snap_lock);
+      local_snap_id = m_local_image_ctx->get_snap_id(
+        cls::rbd::UserSnapshotNamespace{}, snap_name);
+    }
+
     uint64_t local_size;
     {
       C_SaferCond ctx;
-      m_local_image_ctx->state->snap_set(cls::rbd::UserSnapshotNamespace(),
-                                        snap_name,
-                                        &ctx);
+      m_local_image_ctx->state->snap_set(local_snap_id, &ctx);
       ASSERT_EQ(0, ctx.wait());
 
       RWLock::RLocker snap_locker(m_local_image_ctx->snap_lock);