From: Jason Dillaman Date: Thu, 25 Feb 2016 18:20:54 +0000 (-0500) Subject: librbd: allocate new uuid when enabling mirroring X-Git-Tag: v10.1.0~187^2~12 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=9892fd782c1a42027e900808d255f2f104b8f832;p=ceph.git librbd: allocate new uuid when enabling mirroring Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 06d84833c263b..1a2e26b6bc1fd 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -2332,13 +2332,12 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { CephContext *cct = reinterpret_cast(io_ctx.cct()); ldout(cct, 20) << __func__ << dendl; - cls::rbd::MirrorMode mirror_mode_internal; + cls::rbd::MirrorMode next_mirror_mode; switch (mirror_mode) { case RBD_MIRROR_MODE_DISABLED: case RBD_MIRROR_MODE_IMAGE: case RBD_MIRROR_MODE_POOL: - mirror_mode_internal = static_cast( - mirror_mode); + next_mirror_mode = static_cast(mirror_mode); break; default: lderr(cct) << "Unknown mirror mode (" @@ -2346,7 +2345,28 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { return -EINVAL; } - int r = cls_client::mirror_mode_set(&io_ctx, mirror_mode_internal); + cls::rbd::MirrorMode current_mirror_mode; + int r = cls_client::mirror_mode_get(&io_ctx, ¤t_mirror_mode); + if (r < 0) { + lderr(cct) << "Failed to retrieve mirror mode: " << cpp_strerror(r) + << dendl; + return r; + } + + if (current_mirror_mode == next_mirror_mode) { + return 0; + } else if (current_mirror_mode == cls::rbd::MIRROR_MODE_DISABLED) { + uuid_d uuid_gen; + uuid_gen.generate_random(); + r = cls_client::mirror_uuid_set(&io_ctx, uuid_gen.to_string()); + if (r < 0) { + lderr(cct) << "Failed to allocate mirroring uuid: " << cpp_strerror(r) + << dendl; + return r; + } + } + + r = cls_client::mirror_mode_set(&io_ctx, next_mirror_mode); if (r < 0) { lderr(cct) << "Failed to set mirror mode: " << cpp_strerror(r) << dendl; return r;