mirror of
https://github.com/ceph/ceph
synced 2025-01-04 02:02:36 +00:00
Merge pull request #11260 from runsisi/wip-fix-mirror-image-disable
librbd: fix rollback if failed to disable mirroring for image Reviewed-by: Jason Dillaman <dillaman@redhat.com>
This commit is contained in:
commit
297f21d88b
@ -2392,10 +2392,9 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force,
|
|||||||
return r;
|
return r;
|
||||||
} else {
|
} else {
|
||||||
bool rollback = false;
|
bool rollback = false;
|
||||||
BOOST_SCOPE_EXIT_ALL(ictx, rollback) {
|
BOOST_SCOPE_EXIT_ALL(ictx, &mirror_image_internal, &rollback) {
|
||||||
if (rollback) {
|
if (rollback) {
|
||||||
CephContext *cct = ictx->cct;
|
CephContext *cct = ictx->cct;
|
||||||
cls::rbd::MirrorImage mirror_image_internal;
|
|
||||||
mirror_image_internal.state = cls::rbd::MIRROR_IMAGE_STATE_ENABLED;
|
mirror_image_internal.state = cls::rbd::MIRROR_IMAGE_STATE_ENABLED;
|
||||||
int r = cls_client::mirror_image_set(&ictx->md_ctx, ictx->id, mirror_image_internal);
|
int r = cls_client::mirror_image_set(&ictx->md_ctx, ictx->id, mirror_image_internal);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
@ -2405,46 +2404,50 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force,
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RWLock::RLocker l(ictx->snap_lock);
|
{
|
||||||
map<librados::snap_t, SnapInfo> snap_info = ictx->snap_info;
|
RWLock::RLocker l(ictx->snap_lock);
|
||||||
for (auto &info : snap_info) {
|
map<librados::snap_t, SnapInfo> snap_info = ictx->snap_info;
|
||||||
librbd::parent_spec parent_spec(ictx->md_ctx.get_id(), ictx->id, info.first);
|
for (auto &info : snap_info) {
|
||||||
map< pair<int64_t, string>, set<string> > image_info;
|
librbd::parent_spec parent_spec(ictx->md_ctx.get_id(), ictx->id, info.first);
|
||||||
|
map< pair<int64_t, string>, set<string> > image_info;
|
||||||
|
|
||||||
r = list_children_info(ictx, parent_spec, image_info);
|
r = list_children_info(ictx, parent_spec, image_info);
|
||||||
if (r < 0) {
|
|
||||||
rollback = true;
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
if (image_info.empty())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Rados rados(ictx->md_ctx);
|
|
||||||
for (auto &info: image_info) {
|
|
||||||
IoCtx ioctx;
|
|
||||||
r = rados.ioctx_create2(info.first.first, ioctx);
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
rollback = true;
|
rollback = true;
|
||||||
lderr(cct) << "Error accessing child image pool " << info.first.second << dendl;
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
for (auto &id_it : info.second) {
|
if (image_info.empty())
|
||||||
cls::rbd::MirrorImage mirror_image_internal;
|
continue;
|
||||||
r = cls_client::mirror_image_get(&ioctx, id_it, &mirror_image_internal);
|
|
||||||
if (r != -ENOENT) {
|
Rados rados(ictx->md_ctx);
|
||||||
|
for (auto &info: image_info) {
|
||||||
|
IoCtx ioctx;
|
||||||
|
r = rados.ioctx_create2(info.first.first, ioctx);
|
||||||
|
if (r < 0) {
|
||||||
rollback = true;
|
rollback = true;
|
||||||
lderr(cct) << "mirroring is enabled on one or more children " << dendl;
|
lderr(cct) << "Error accessing child image pool " << info.first.second << dendl;
|
||||||
return -EBUSY;
|
return r;
|
||||||
|
}
|
||||||
|
for (auto &id_it : info.second) {
|
||||||
|
cls::rbd::MirrorImage mirror_image_internal;
|
||||||
|
r = cls_client::mirror_image_get(&ioctx, id_it, &mirror_image_internal);
|
||||||
|
if (r != -ENOENT) {
|
||||||
|
rollback = true;
|
||||||
|
lderr(cct) << "mirroring is enabled on one or more children " << dendl;
|
||||||
|
return -EBUSY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r = mirror_image_disable_internal(ictx, force);
|
||||||
|
if (r < 0) {
|
||||||
|
rollback = true;
|
||||||
|
return r;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r = mirror_image_disable_internal(ictx, force);
|
|
||||||
if (r < 0) {
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user