From: Jason Dillaman Date: Fri, 24 Jun 2016 14:52:16 +0000 (-0400) Subject: librbd: removal of partially deleted image needs id lookup X-Git-Tag: v11.0.0~12^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F9923%2Fhead;p=ceph.git librbd: removal of partially deleted image needs id lookup Several operations depend on the image id but if the image cannot be opened to retrieve the id, these cleanup operations cannot be executed. Fixes: http://tracker.ceph.com/issues/16471 Signed-off-by: Jason Dillaman --- diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index edcec0f11056..2506d42388f2 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -2127,58 +2127,66 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force, } if (old_format || unknown_format) { - ldout(cct, 2) << "removing rbd image from directory..." << dendl; + ldout(cct, 2) << "removing rbd image from v1 directory..." << dendl; r = tmap_rm(io_ctx, imgname); old_format = (r == 0); if (r < 0 && !unknown_format) { if (r != -ENOENT) { - lderr(cct) << "error removing img from old-style directory: " - << cpp_strerror(-r) << dendl; + lderr(cct) << "error removing image from v1 directory: " + << cpp_strerror(-r) << dendl; } return r; } } if (!old_format) { - r = Journal<>::remove(io_ctx, id); - if (r < 0 && r != -ENOENT) { - lderr(cct) << "error removing image journal" << dendl; - return r; + if (id.empty()) { + ldout(cct, 5) << "attempting to determine image id" << dendl; + r = cls_client::dir_get_id(&io_ctx, RBD_DIRECTORY, imgname, &id); + if (r < 0 && r != -ENOENT) { + lderr(cct) << "error getting id of image" << dendl; + return r; + } } + if (!id.empty()) { + ldout(cct, 10) << "removing journal..." << dendl; + r = Journal<>::remove(io_ctx, id); + if (r < 0 && r != -ENOENT) { + lderr(cct) << "error removing image journal" << dendl; + return r; + } - r = ObjectMap::remove(io_ctx, id); - if (r < 0 && r != -ENOENT) { - lderr(cct) << "error removing image object map" << dendl; - return r; + ldout(cct, 10) << "removing object map..." << dendl; + r = ObjectMap::remove(io_ctx, id); + if (r < 0 && r != -ENOENT) { + lderr(cct) << "error removing image object map" << dendl; + return r; + } + + ldout(cct, 10) << "removing image from rbd_mirroring object..." + << dendl; + r = cls_client::mirror_image_remove(&io_ctx, id); + if (r < 0 && r != -ENOENT && r != -EOPNOTSUPP) { + lderr(cct) << "failed to remove image from mirroring directory: " + << cpp_strerror(r) << dendl; + return r; + } } ldout(cct, 2) << "removing id object..." << dendl; r = io_ctx.remove(util::id_obj_name(imgname)); if (r < 0 && r != -ENOENT) { - lderr(cct) << "error removing id object: " << cpp_strerror(r) << dendl; - return r; - } - - r = cls_client::dir_get_id(&io_ctx, RBD_DIRECTORY, imgname, &id); - if (r < 0 && r != -ENOENT) { - lderr(cct) << "error getting id of image" << dendl; + lderr(cct) << "error removing id object: " << cpp_strerror(r) + << dendl; return r; } - ldout(cct, 2) << "removing rbd image from directory..." << dendl; + ldout(cct, 2) << "removing rbd image from v2 directory..." << dendl; r = cls_client::dir_remove_image(&io_ctx, RBD_DIRECTORY, imgname, id); if (r < 0) { if (r != -ENOENT) { - lderr(cct) << "error removing img from new-style directory: " - << cpp_strerror(-r) << dendl; + lderr(cct) << "error removing image from v2 directory: " + << cpp_strerror(-r) << dendl; } - return r; - } - - ldout(cct, 2) << "removing image from rbd_mirroring object..." << dendl; - r = cls_client::mirror_image_remove(&io_ctx, id); - if (r < 0 && r != -ENOENT && r != -EOPNOTSUPP) { - lderr(cct) << "failed to remove image from mirroring directory: " - << cpp_strerror(r) << dendl; return r; } }