]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: return an error when removing a non-existent image
authorJosh Durgin <josh.durgin@inktank.com>
Tue, 10 Jul 2012 00:24:19 +0000 (17:24 -0700)
committerJosh Durgin <josh.durgin@inktank.com>
Tue, 10 Jul 2012 00:27:42 +0000 (17:27 -0700)
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 <josh.durgin@inktank.com>
src/librbd.cc

index 62819a620776319c167083b9748d88a909a906bb..3711ada7fc3bbbc41231984294fe61fe0ba35e07 100644 (file)
@@ -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;