using librbd::util::create_context_callback;
using librbd::util::create_rados_callback;
+template <typename I>
+CreatePrimaryRequest<I>::CreatePrimaryRequest(I *image_ctx, bool demoted,
+ bool force, uint64_t *snap_id,
+ Context *on_finish)
+ : m_image_ctx(image_ctx), m_demoted(demoted), m_force(force),
+ 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("");
+}
+
template <typename I>
void CreatePrimaryRequest<I>::send() {
refresh_image();
librados::AioCompletion *comp = create_rados_callback<
CreatePrimaryRequest<I>, &CreatePrimaryRequest<I>::handle_get_mirror_peers>(this);
m_out_bl.clear();
- int r = m_image_ctx->md_ctx.aio_operate(RBD_MIRRORING, comp, &op, &m_out_bl);
+ int r = m_default_ns_ctx.aio_operate(RBD_MIRRORING, comp, &op, &m_out_bl);
ceph_assert(r == 0);
comp->release();
}
#define CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_PRIMARY_REQUEST_H
#include "include/buffer.h"
+#include "include/rados/librados.hpp"
#include "cls/rbd/cls_rbd_types.h"
#include <string>
}
CreatePrimaryRequest(ImageCtxT *image_ctx, bool demoted, bool force,
- uint64_t *snap_id, Context *on_finish)
- : m_image_ctx(image_ctx), m_demoted(demoted), m_force(force),
- m_snap_id(snap_id), m_on_finish(on_finish) {
- }
+ uint64_t *snap_id, Context *on_finish);
void send();
uint64_t *m_snap_id;
Context *m_on_finish;
+ librados::IoCtx m_default_ns_ctx;
std::set<std::string> m_mirror_peer_uuids;
std::string m_snap_name;
SnapInfo{snap_name, ns, 0, {}, 0, 0, {}}}).second);
}
+ void expect_clone_md_ctx(MockTestImageCtx &mock_image_ctx) {
+ EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx), clone())
+ .WillOnce(Invoke([&mock_image_ctx]() {
+ get_mock_io_ctx(mock_image_ctx.md_ctx).get();
+ return &get_mock_io_ctx(mock_image_ctx.md_ctx);
+ }));
+ }
+
void expect_refresh_image(MockTestImageCtx &mock_image_ctx,
bool refresh_required, int r) {
EXPECT_CALL(*mock_image_ctx.state, is_refresh_required())
InSequence seq;
+ expect_clone_md_ctx(mock_image_ctx);
expect_refresh_image(mock_image_ctx, true, 0);
expect_get_mirror_image(
mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
InSequence seq;
+ expect_clone_md_ctx(mock_image_ctx);
expect_refresh_image(mock_image_ctx, true, -EINVAL);
C_SaferCond ctx;
InSequence seq;
+ expect_clone_md_ctx(mock_image_ctx);
expect_refresh_image(mock_image_ctx, false, 0);
expect_get_mirror_image(
mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
InSequence seq;
+ expect_clone_md_ctx(mock_image_ctx);
expect_refresh_image(mock_image_ctx, true, 0);
expect_get_mirror_image(
mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
InSequence seq;
+ expect_clone_md_ctx(mock_image_ctx);
expect_refresh_image(mock_image_ctx, true, 0);
expect_get_mirror_image(
mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
InSequence seq;
+ expect_clone_md_ctx(mock_image_ctx);
expect_refresh_image(mock_image_ctx, true, 0);
expect_get_mirror_image(
mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
InSequence seq;
+ expect_clone_md_ctx(mock_image_ctx);
expect_refresh_image(mock_image_ctx, true, 0);
expect_get_mirror_image(
mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",