C_SaferCond on_finish;
auto req = mirror::snapshot::CreatePrimaryRequest<I>::create(
- ictx, false, false, snap_id, &on_finish);
+ ictx, 0U, snap_id, &on_finish);
req->send();
return on_finish.wait();
}
using librbd::util::create_rados_callback;
template <typename I>
-CreatePrimaryRequest<I>::CreatePrimaryRequest(I *image_ctx, bool demoted,
- bool force, uint64_t *snap_id,
+CreatePrimaryRequest<I>::CreatePrimaryRequest(I *image_ctx, uint32_t flags,
+ uint64_t *snap_id,
Context *on_finish)
- : m_image_ctx(image_ctx), m_demoted(demoted), m_force(force),
+ : m_image_ctx(image_ctx), m_flags(flags),
m_snap_id(snap_id), m_on_finish(on_finish) {
m_default_ns_ctx.dup(m_image_ctx->md_ctx);
m_default_ns_ctx.set_namespace("");
return;
}
- if (!util::can_create_primary_snapshot(m_image_ctx, m_demoted, m_force,
- nullptr)) {
+ if (!util::can_create_primary_snapshot(
+ m_image_ctx,
+ ((m_flags & CREATE_PRIMARY_FLAG_DEMOTED) != 0),
+ ((m_flags & CREATE_PRIMARY_FLAG_FORCE) != 0), nullptr)) {
finish(-EINVAL);
return;
}
m_mirror_peer_uuids.insert(peer.uuid);
}
- if (m_mirror_peer_uuids.empty()) {
+ if (m_mirror_peer_uuids.empty() &&
+ ((m_flags & CREATE_PRIMARY_FLAG_IGNORE_EMPTY_PEERS) == 0)) {
lderr(cct) << "no mirror tx peers configured for the pool" << dendl;
finish(-EINVAL);
return;
CephContext *cct = m_image_ctx->cct;
ldout(cct, 20) << dendl;
- cls::rbd::MirrorPrimarySnapshotNamespace ns{m_demoted, m_mirror_peer_uuids};
+ cls::rbd::MirrorPrimarySnapshotNamespace ns{
+ ((m_flags & CREATE_PRIMARY_FLAG_DEMOTED) != 0), m_mirror_peer_uuids};
auto ctx = create_context_callback<
CreatePrimaryRequest<I>,
&CreatePrimaryRequest<I>::handle_create_snapshot>(this);
if (m_snap_id != nullptr) {
std::shared_lock image_locker{m_image_ctx->image_lock};
- cls::rbd::MirrorPrimarySnapshotNamespace ns{m_demoted, m_mirror_peer_uuids};
+ cls::rbd::MirrorPrimarySnapshotNamespace ns{
+ ((m_flags & CREATE_PRIMARY_FLAG_DEMOTED) != 0), m_mirror_peer_uuids};
*m_snap_id = m_image_ctx->get_snap_id(ns, m_snap_name);
}
#include "include/buffer.h"
#include "include/rados/librados.hpp"
#include "cls/rbd/cls_rbd_types.h"
+#include "librbd/mirror/snapshot/Types.h"
#include <string>
#include <set>
template <typename ImageCtxT = librbd::ImageCtx>
class CreatePrimaryRequest {
public:
- static CreatePrimaryRequest *create(ImageCtxT *image_ctx, bool demoted,
- bool force, uint64_t *snap_id,
+ static CreatePrimaryRequest *create(ImageCtxT *image_ctx, uint32_t flags,
+ uint64_t *snap_id,
Context *on_finish) {
- return new CreatePrimaryRequest(image_ctx, demoted, force, snap_id,
- on_finish);
+ return new CreatePrimaryRequest(image_ctx, flags, snap_id, on_finish);
}
- CreatePrimaryRequest(ImageCtxT *image_ctx, bool demoted, bool force,
- uint64_t *snap_id, Context *on_finish);
+ CreatePrimaryRequest(ImageCtxT *image_ctx, uint32_t flags, uint64_t *snap_id,
+ Context *on_finish);
void send();
*/
ImageCtxT *m_image_ctx;
- const bool m_demoted;
- const bool m_force;
+ const uint32_t m_flags;
uint64_t *m_snap_id;
Context *m_on_finish;
auto ctx = create_context_callback<
DemoteRequest<I>, &DemoteRequest<I>::handle_create_snapshot>(this);
- auto req = CreatePrimaryRequest<I>::create(m_image_ctx, true, false, nullptr,
- ctx);
+ auto req = CreatePrimaryRequest<I>::create(
+ m_image_ctx,
+ (snapshot::CREATE_PRIMARY_FLAG_IGNORE_EMPTY_PEERS |
+ snapshot::CREATE_PRIMARY_FLAG_DEMOTED), nullptr, ctx);
req->send();
}
PromoteRequest<I>,
&PromoteRequest<I>::handle_create_promote_snapshot>(this);
- auto req = CreatePrimaryRequest<I>::create(m_image_ctx, false, true, nullptr,
- ctx);
+ auto req = CreatePrimaryRequest<I>::create(
+ m_image_ctx,
+ (snapshot::CREATE_PRIMARY_FLAG_IGNORE_EMPTY_PEERS |
+ snapshot::CREATE_PRIMARY_FLAG_FORCE), nullptr, ctx);
req->send();
}
namespace mirror {
namespace snapshot {
+enum CreatePrimaryFlags {
+ CREATE_PRIMARY_FLAG_IGNORE_EMPTY_PEERS = (1 << 0),
+ CREATE_PRIMARY_FLAG_DEMOTED = (1 << 1),
+ CREATE_PRIMARY_FLAG_FORCE = (1 << 2)
+};
+
struct ImageStateHeader {
uint32_t object_count = 0;
expect_create_snapshot(mock_image_ctx, 0);
C_SaferCond ctx;
- auto req = new MockCreatePrimaryRequest(&mock_image_ctx, false, false,
- nullptr, &ctx);
+ auto req = new MockCreatePrimaryRequest(&mock_image_ctx, 0U, nullptr, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
}
expect_refresh_image(mock_image_ctx, true, -EINVAL);
C_SaferCond ctx;
- auto req = new MockCreatePrimaryRequest(&mock_image_ctx, false, false,
- nullptr, &ctx);
+ auto req = new MockCreatePrimaryRequest(&mock_image_ctx, 0U, nullptr, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
}
cls::rbd::MIRROR_IMAGE_STATE_ENABLED}, -EINVAL);
C_SaferCond ctx;
- auto req = new MockCreatePrimaryRequest(&mock_image_ctx, false, false,
- nullptr, &ctx);
+ auto req = new MockCreatePrimaryRequest(&mock_image_ctx, 0U, nullptr, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
}
expect_can_create_primary_snapshot(mock_utils, false, false, false);
C_SaferCond ctx;
- auto req = new MockCreatePrimaryRequest(&mock_image_ctx, false, false,
- nullptr, &ctx);
+ auto req = new MockCreatePrimaryRequest(&mock_image_ctx, 0U, nullptr, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
}
"mirror", "fsid"}}, -EINVAL);
C_SaferCond ctx;
- auto req = new MockCreatePrimaryRequest(&mock_image_ctx, false, false,
- nullptr, &ctx);
+ auto req = new MockCreatePrimaryRequest(&mock_image_ctx, 0U, nullptr, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
}
expect_create_snapshot(mock_image_ctx, -EINVAL);
C_SaferCond ctx;
- auto req = new MockCreatePrimaryRequest(&mock_image_ctx, false, false,
- nullptr, &ctx);
+ auto req = new MockCreatePrimaryRequest(&mock_image_ctx, 0U, nullptr, &ctx);
req->send();
ASSERT_EQ(-EINVAL, ctx.wait());
}
expect_unlink_peer(mock_image_ctx, mock_unlink_peer_request, snap_id, "uuid",
0);
C_SaferCond ctx;
- auto req = new MockCreatePrimaryRequest(&mock_image_ctx, false, false,
- nullptr, &ctx);
+ auto req = new MockCreatePrimaryRequest(&mock_image_ctx, 0U, nullptr, &ctx);
req->send();
ASSERT_EQ(0, ctx.wait());
}
bool force = false;
Context* on_finish = nullptr;
static CreatePrimaryRequest* s_instance;
- static CreatePrimaryRequest *create(MockTestImageCtx *image_ctx, bool demoted,
- bool force, uint64_t *snap_id,
+ static CreatePrimaryRequest *create(MockTestImageCtx *image_ctx,
+ uint32_t flags, uint64_t *snap_id,
Context *on_finish) {
ceph_assert(s_instance != nullptr);
- s_instance->demoted = demoted;
- s_instance->force = force;
+ s_instance->demoted = ((flags & CREATE_PRIMARY_FLAG_DEMOTED) != 0);
+ s_instance->force = ((flags & CREATE_PRIMARY_FLAG_FORCE) != 0);
s_instance->on_finish = on_finish;
return s_instance;
}