mirror of
https://github.com/ceph/ceph
synced 2025-04-23 07:46:04 +00:00
librbd: remove snapshot mirror image-meta when disabling
Remove the snapshot-based mirroring image-meta key/value pair (if any) when disabling mirroring. Signed-off-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
parent
86d39fb9ee
commit
281a64acf9
@ -28,6 +28,7 @@
|
|||||||
#include "librbd/mirror/snapshot/CreatePrimaryRequest.h"
|
#include "librbd/mirror/snapshot/CreatePrimaryRequest.h"
|
||||||
#include "librbd/mirror/snapshot/ImageMeta.h"
|
#include "librbd/mirror/snapshot/ImageMeta.h"
|
||||||
#include "librbd/mirror/snapshot/UnlinkPeerRequest.h"
|
#include "librbd/mirror/snapshot/UnlinkPeerRequest.h"
|
||||||
|
#include "librbd/mirror/snapshot/Utils.h"
|
||||||
#include <boost/algorithm/string/trim.hpp>
|
#include <boost/algorithm/string/trim.hpp>
|
||||||
#include <boost/algorithm/string/replace.hpp>
|
#include <boost/algorithm/string/replace.hpp>
|
||||||
#include <boost/scope_exit.hpp>
|
#include <boost/scope_exit.hpp>
|
||||||
@ -474,7 +475,8 @@ int Mirror<I>::image_disable(I *ictx, bool force) {
|
|||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
lderr(cct) << "cannot disable mirroring: " << cpp_strerror(r) << dendl;
|
lderr(cct) << "cannot disable mirroring: " << cpp_strerror(r) << dendl;
|
||||||
return r;
|
return r;
|
||||||
} else {
|
}
|
||||||
|
|
||||||
bool rollback = false;
|
bool rollback = false;
|
||||||
BOOST_SCOPE_EXIT_ALL(ictx, &mirror_image_internal, &rollback) {
|
BOOST_SCOPE_EXIT_ALL(ictx, &mirror_image_internal, &rollback) {
|
||||||
if (rollback) {
|
if (rollback) {
|
||||||
@ -489,8 +491,7 @@ int Mirror<I>::image_disable(I *ictx, bool force) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
{
|
std::unique_lock image_locker{ictx->image_lock};
|
||||||
std::shared_lock l{ictx->image_lock};
|
|
||||||
map<librados::snap_t, SnapInfo> snap_info = ictx->snap_info;
|
map<librados::snap_t, SnapInfo> snap_info = ictx->snap_info;
|
||||||
for (auto &info : snap_info) {
|
for (auto &info : snap_info) {
|
||||||
cls::rbd::ParentImageSpec parent_spec{ictx->md_ctx.get_id(),
|
cls::rbd::ParentImageSpec parent_spec{ictx->md_ctx.get_id(),
|
||||||
@ -526,9 +527,9 @@ int Mirror<I>::image_disable(I *ictx, bool force) {
|
|||||||
child_pool_id = child_image.pool_id;
|
child_pool_id = child_image.pool_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
cls::rbd::MirrorImage mirror_image_internal;
|
cls::rbd::MirrorImage child_mirror_image_internal;
|
||||||
r = cls_client::mirror_image_get(&child_io_ctx, child_image.image_id,
|
r = cls_client::mirror_image_get(&child_io_ctx, child_image.image_id,
|
||||||
&mirror_image_internal);
|
&child_mirror_image_internal);
|
||||||
if (r != -ENOENT) {
|
if (r != -ENOENT) {
|
||||||
rollback = true;
|
rollback = true;
|
||||||
lderr(cct) << "mirroring is enabled on one or more children "
|
lderr(cct) << "mirroring is enabled on one or more children "
|
||||||
@ -537,6 +538,25 @@ int Mirror<I>::image_disable(I *ictx, bool force) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
image_locker.unlock();
|
||||||
|
|
||||||
|
if (mirror_image_internal.mode == cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT) {
|
||||||
|
// remove any snapshot-based mirroring image-meta from image
|
||||||
|
std::string mirror_uuid;
|
||||||
|
r = uuid_get(ictx->md_ctx, &mirror_uuid);
|
||||||
|
if (r < 0) {
|
||||||
|
rollback = true;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = ictx->operations->metadata_remove(
|
||||||
|
mirror::snapshot::util::get_image_meta_key(mirror_uuid));
|
||||||
|
if (r < 0 && r != -ENOENT) {
|
||||||
|
lderr(cct) << "cannot remove snapshot image-meta key: " << cpp_strerror(r)
|
||||||
|
<< dendl;
|
||||||
|
rollback = true;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
C_SaferCond ctx;
|
C_SaferCond ctx;
|
||||||
@ -558,7 +578,6 @@ int Mirror<I>::image_disable(I *ictx, bool force) {
|
|||||||
// not fatal
|
// not fatal
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user