]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: remove image in error handling of importing
authorDongsheng Yang <dongsheng.yang@easystack.cn>
Thu, 28 Jul 2016 22:05:11 +0000 (18:05 -0400)
committerDongsheng Yang <dongsheng.yang@easystack.cn>
Sun, 19 Feb 2017 12:41:28 +0000 (20:41 +0800)
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
src/tools/rbd/action/Import.cc

index 49ccf0b9fcf8ddbb4daa84cdb2d136a22bb99661..5b99e77d507ac61d917ed12a29e87a65adeb461d 100644 (file)
@@ -141,7 +141,7 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
   r = rbd.open(io_ctx, image, imgname);
   if (r < 0) {
     std::cerr << "rbd: failed to open image" << std::endl;
-    goto done;
+    goto err;
   }
 
   // loop body handles 0 return, as we may have a block to flush
@@ -167,7 +167,7 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
       r = image.resize(size);
       if (r < 0) {
         std::cerr << "rbd: can't resize image during import" << std::endl;
-        goto done;
+        goto close;
       }
     }
 
@@ -188,19 +188,22 @@ static int do_import(librbd::RBD &rbd, librados::IoCtx& io_ctx,
   }
   r = throttle->wait_for_ret();
   if (r < 0) {
-    goto done;
+    goto close;
   }
 
   if (from_stdin) {
     r = image.resize(image_pos);
     if (r < 0) {
       std::cerr << "rbd: final image resize failed" << std::endl;
-      goto done;
+      goto close;
     }
   }
 
+close:
   r = image.close();
-
+err:
+  if (r < 0)
+    rbd.remove(io_ctx, imgname);
 done:
   if (!from_stdin) {
     if (r < 0)