From 67361c10ea8ed5642ee6c9f09d5fad20749dda08 Mon Sep 17 00:00:00 2001 From: Josh Durgin Date: Mon, 9 Jul 2012 17:24:19 -0700 Subject: [PATCH] librbd: return an error when removing a non-existent image Try treating the image as new format if it's not in the old-style directory, which is the last step in old-style removal. Then if the image is not found in the new-style directory, -ENOENT will be returned, preserving the semantics that existed prior to 6f096b6cdc66bb92762aa92e51e5e448039cf3e3. Signed-off-by: Josh Durgin --- src/librbd.cc | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/librbd.cc b/src/librbd.cc index 62819a62077..3711ada7fc3 100644 --- a/src/librbd.cc +++ b/src/librbd.cc @@ -1285,15 +1285,14 @@ int remove(IoCtx& io_ctx, const char *imgname, ProgressContext& prog_ctx) if (old_format || unknown_format) { ldout(cct, 2) << "removing rbd image from directory..." << dendl; r = tmap_rm(io_ctx, imgname); - if (r == 0) - old_format = true; + old_format = (r == 0); if (r < 0 && !unknown_format) { lderr(cct) << "error removing img from old-style directory: " << cpp_strerror(-r) << dendl; return r; } } - if (!old_format || unknown_format) { + if (!old_format) { ldout(cct, 2) << "removing id object..." << dendl; r = io_ctx.remove(id_obj_name(imgname)); if (r < 0 && r != -ENOENT) { @@ -1301,17 +1300,15 @@ int remove(IoCtx& io_ctx, const char *imgname, ProgressContext& prog_ctx) return r; } - if (unknown_format) { - 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; - } + 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; } ldout(cct, 2) << "removing rbd image from directory..." << dendl; r = cls_client::dir_remove_image(&io_ctx, RBD_DIRECTORY, imgname, id); - if (r < 0 && !unknown_format) { + if (r < 0) { lderr(cct) << "error removing img from new-style directory: " << cpp_strerror(-r) << dendl; return r;