]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/test/librbd/test_fixture.cc
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / test / librbd / test_fixture.cc
index 4e9d2b6497f9fd5f0982791a5a9b65b8cec98bb3..9ddebec482ef6722fb683fcb1ecfc6497910a432 100644 (file)
@@ -1,13 +1,15 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
+#include "common/Cond.h"
 #include "test/librbd/test_fixture.h"
 #include "test/librbd/test_support.h"
 #include "include/stringify.h"
 #include "librbd/ExclusiveLock.h"
 #include "librbd/ImageState.h"
 #include "librbd/ImageWatcher.h"
+#include "librbd/io/ImageDispatchSpec.h"
 #include "librbd/Operations.h"
-#include "librbd/io/ImageRequestWQ.h"
+#include "librbd/api/Io.h"
 #include "cls/lock/cls_lock_client.h"
 #include "cls/lock/cls_lock_types.h"
 #include "cls/rbd/cls_rbd_types.h"
@@ -59,6 +61,8 @@ std::string TestFixture::get_temp_image_name() {
 void TestFixture::SetUp() {
   ASSERT_EQ(0, _rados.ioctx_create(_pool_name.c_str(), m_ioctx));
   m_cct = reinterpret_cast<CephContext*>(m_ioctx.cct());
+  librados::Rados rados(m_ioctx);
+  rados.conf_set("rbd_persistent_cache_path", ".");
 
   m_image_name = get_temp_image_name();
   m_image_size = 2 << 20;
@@ -71,7 +75,6 @@ void TestFixture::TearDown() {
        iter != m_ictxs.end(); ++iter) {
     (*iter)->state->close();
   }
-
   m_ioctx.close();
 }
 
@@ -85,8 +88,9 @@ int TestFixture::open_image(const std::string &image_name,
 
 int TestFixture::snap_create(librbd::ImageCtx &ictx,
                              const std::string &snap_name) {
+  librbd::NoOpProgressContext prog_ctx;
   return ictx.operations->snap_create(cls::rbd::UserSnapshotNamespace(),
-                                     snap_name.c_str());
+                                     snap_name.c_str(), 0, prog_ctx);
 }
 
 int TestFixture::snap_protect(librbd::ImageCtx &ictx,
@@ -134,7 +138,7 @@ int TestFixture::unlock_image() {
 }
 
 int TestFixture::acquire_exclusive_lock(librbd::ImageCtx &ictx) {
-  int r = ictx.io_work_queue->write(0, 0, {}, 0);
+  int r = librbd::api::Io<>::write(ictx, 0, 0, {}, 0);
   if (r != 0) {
     return r;
   }
@@ -143,3 +147,19 @@ int TestFixture::acquire_exclusive_lock(librbd::ImageCtx &ictx) {
   ceph_assert(ictx.exclusive_lock != nullptr);
   return ictx.exclusive_lock->is_lock_owner() ? 0 : -EINVAL;
 }
+
+int TestFixture::flush_writeback_cache(librbd::ImageCtx *image_ctx) {
+  if (image_ctx->test_features(RBD_FEATURE_DIRTY_CACHE)) {
+    // cache exists. Close to flush data
+    C_SaferCond ctx;
+    auto aio_comp = librbd::io::AioCompletion::create_and_start(
+      &ctx, image_ctx, librbd::io::AIO_TYPE_FLUSH);
+    auto req = librbd::io::ImageDispatchSpec::create_flush(
+      *image_ctx, librbd::io::IMAGE_DISPATCH_LAYER_INTERNAL_START, aio_comp,
+      librbd::io::FLUSH_SOURCE_INTERNAL, {});
+    req->send();
+    return ctx.wait();
+  } else {
+    return librbd::api::Io<>::flush(*image_ctx);
+  }
+}