]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd:remove the local file when rbd export-diff fail 5587/head
authorcaibo <cai.bo@h3c.com>
Thu, 20 Aug 2015 09:40:29 +0000 (17:40 +0800)
committercaibo <cai.bo@h3c.com>
Thu, 20 Aug 2015 09:40:41 +0000 (17:40 +0800)
Signed-off-by: Bo Cai <cai.bo@h3c.com>
src/rbd.cc

index f8eedb02ff357a4e49d22a40ace59b740569dc5f..72f81df7e631743c22e9bf53913bbe97a1cdb9a3 100755 (executable)
@@ -1357,6 +1357,13 @@ static int do_export_diff(librbd::Image& image, const char *fromsnapname,
   if (fd < 0)
     return -errno;
 
+  BOOST_SCOPE_EXIT(&r, &fd, &path) {
+    close(fd);
+    if (r < 0 && fd != 1) {
+      remove(path);
+    }
+  } BOOST_SCOPE_EXIT_END
+
   {
     // header
     bufferlist bl;
@@ -1384,7 +1391,6 @@ static int do_export_diff(librbd::Image& image, const char *fromsnapname,
 
     r = bl.write_fd(fd);
     if (r < 0) {
-      close(fd);
       return r;
     }
   }
@@ -1410,7 +1416,6 @@ static int do_export_diff(librbd::Image& image, const char *fromsnapname,
   }
 
  out:
-  close(fd);
   if (r < 0)
     ec.pc.fail();
   else