return 0;
}
+int mirror_image_enable_internal(ImageCtx *ictx) {
+ CephContext *cct = ictx->cct;
+
+ if ((ictx->features & RBD_FEATURE_JOURNALING) == 0) {
+ lderr(cct) << "cannot enable mirroring: journaling is not enabled"
+ << dendl;
+ return -EINVAL;
+ }
+
+ bool is_primary;
+ int r = Journal<>::is_tag_owner(ictx, &is_primary);
+ if (r < 0) {
+ lderr(cct) << "cannot enable mirroring: failed to check tag ownership: "
+ << cpp_strerror(r) << dendl;
+ return r;
+ }
+
+ if (!is_primary) {
+ lderr(cct) <<
+ "cannot enable mirroring: last journal tag not owned by local cluster"
+ << dendl;
+ return -EINVAL;
+ }
+
+ cls::rbd::MirrorImage mirror_image_internal;
+ r = cls_client::mirror_image_get(&ictx->md_ctx, ictx->id,
+ &mirror_image_internal);
+ if (r < 0 && r != -ENOENT) {
+ lderr(cct) << "cannot enable mirroring: " << cpp_strerror(r) << dendl;
+ return r;
+ }
+
+ if (mirror_image_internal.state ==
+ cls::rbd::MirrorImageState::MIRROR_IMAGE_STATE_ENABLED) {
+ // mirroring is already enabled
+ return 0;
+ }
+ else if (r != -ENOENT) {
+ lderr(cct) << "cannot enable mirroring: mirroring image is in "
+ "disabling state" << dendl;
+ return -EINVAL;
+ }
+
+ mirror_image_internal.state =
+ cls::rbd::MirrorImageState::MIRROR_IMAGE_STATE_ENABLED;
+
+ uuid_d uuid_gen;
+ uuid_gen.generate_random();
+ mirror_image_internal.global_image_id = uuid_gen.to_string();
+
+ r = cls_client::mirror_image_set(&ictx->md_ctx, ictx->id,
+ mirror_image_internal);
+ if (r < 0) {
+ lderr(cct) << "cannot enable mirroring: " << cpp_strerror(r) << dendl;
+ return r;
+ }
+
+ ldout(cct, 20) << "image mirroring is enabled: global_id=" <<
+ mirror_image_internal.global_image_id << dendl;
+
+ return 0;
+}
+
} // anonymous namespace
int detect_format(IoCtx &io_ctx, const string &name,
delete img_ctx;
goto err_remove_object_map;
}
- r = mirror_image_enable(img_ctx);
+ r = mirror_image_enable_internal(img_ctx);
if (r < 0) {
lderr(cct) << "error enabling mirroring: " << cpp_strerror(r)
<< dendl;
lderr(cct) << "error opening image: " << cpp_strerror(r) << dendl;
delete img_ctx;
} else {
- r = mirror_image_enable(img_ctx);
+ r = mirror_image_enable_internal(img_ctx);
if (r < 0) {
lderr(cct) << "error enabling mirroring: " << cpp_strerror(r)
<< dendl;
CephContext *cct = ictx->cct;
ldout(cct, 20) << "mirror_image_enable " << ictx << dendl;
- if ((ictx->features & RBD_FEATURE_JOURNALING) == 0) {
- lderr(cct) << "cannot enable mirroring: journaling is not enabled"
- << dendl;
- return -EINVAL;
- }
-
- bool is_primary;
- int r = Journal<>::is_tag_owner(ictx, &is_primary);
+ cls::rbd::MirrorMode mirror_mode;
+ int r = cls_client::mirror_mode_get(&ictx->md_ctx, &mirror_mode);
if (r < 0) {
- lderr(cct) << "cannot enable mirroring: failed to check tag ownership: "
+ lderr(cct) << "cannot enable mirroring: failed to retrieve mirror mode: "
<< cpp_strerror(r) << dendl;
return r;
}
- if (!is_primary) {
- lderr(cct) <<
- "cannot enable mirroring: last journal tag not owned by local cluster"
- << dendl;
+ if (mirror_mode != cls::rbd::MIRROR_MODE_IMAGE) {
+ lderr(cct) << "cannot enable mirroring in the current pool mirroring "
+ "mode" << dendl;
return -EINVAL;
}
- cls::rbd::MirrorImage mirror_image_internal;
- r = cls_client::mirror_image_get(&ictx->md_ctx, ictx->id,
- &mirror_image_internal);
- if (r < 0 && r != -ENOENT) {
- lderr(cct) << "cannot enable mirroring: " << cpp_strerror(r) << dendl;
- return r;
- }
-
- if (mirror_image_internal.state ==
- cls::rbd::MirrorImageState::MIRROR_IMAGE_STATE_ENABLED) {
- // mirroring is already enabled
- return 0;
- }
- else if (r != -ENOENT) {
- lderr(cct) << "cannot enable mirroring: mirroring image is in "
- "disabling state" << dendl;
- return -EINVAL;
- }
-
- mirror_image_internal.state =
- cls::rbd::MirrorImageState::MIRROR_IMAGE_STATE_ENABLED;
-
- uuid_d uuid_gen;
- uuid_gen.generate_random();
- mirror_image_internal.global_image_id = uuid_gen.to_string();
-
- r = cls_client::mirror_image_set(&ictx->md_ctx, ictx->id,
- mirror_image_internal);
- if (r < 0) {
- lderr(cct) << "cannot enable mirroring: " << cpp_strerror(r) << dendl;
- return r;
- }
-
- ldout(cct, 20) << "image mirroring is enabled: global_id=" <<
- mirror_image_internal.global_image_id << dendl;
-
- return 0;
+ return mirror_image_enable_internal(ictx);
}
int mirror_image_disable(ImageCtx *ictx, bool force) {