}
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;
}
}