#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"
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'));
}
RWLock::RLocker owner_locker(image_ctx->owner_lock);
- ASSERT_EQ(0, image_ctx->flush());
+ ASSERT_EQ(0, flush(image_ctx));
}
} // anonymous namespace
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));
}
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));
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;
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);
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);