]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd: refactor do_export_diff to accept fd
authorDongsheng Yang <dongsheng.yang@easystack.cn>
Tue, 11 Oct 2016 11:02:02 +0000 (07:02 -0400)
committerDongsheng Yang <dongsheng.yang@easystack.cn>
Sun, 19 Feb 2017 12:42:03 +0000 (20:42 +0800)
Signed-off-by: Dongsheng Yang <dongsheng.yang@easystack.cn>
src/tools/rbd/action/Export.cc

index d55936ba6759a2b50bad1db72e8225a2b15a7e5a..bffeb22611b3505e504b4f7a6a24c2d5a787df52 100644 (file)
@@ -107,25 +107,18 @@ private:
   }
 };
 
-int do_export_diff(librbd::Image& image, const char *fromsnapname,
-                const char *endsnapname, bool whole_object,
-                const char *path, bool no_progress)
+
+int do_export_diff_fd(librbd::Image& image, const char *fromsnapname,
+                  const char *endsnapname, bool whole_object,
+                  int fd, bool no_progress)
 {
   int r;
   librbd::image_info_t info;
-  int fd;
 
   r = image.stat(info, sizeof(info));
   if (r < 0)
     return r;
 
-  if (strcmp(path, "-") == 0)
-    fd = 1;
-  else
-    fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
-  if (fd < 0)
-    return -errno;
-
   {
     // header
     bufferlist bl;
@@ -153,10 +146,6 @@ int do_export_diff(librbd::Image& image, const char *fromsnapname,
 
     r = bl.write_fd(fd);
     if (r < 0) {
-      close(fd);
-      if (fd != 1) {
-       remove(path);
-      }
       return r;
     }
   }
@@ -186,6 +175,25 @@ out:
   else
     edc.pc.finish();
 
+  return r;
+}
+
+int do_export_diff(librbd::Image& image, const char *fromsnapname,
+                const char *endsnapname, bool whole_object,
+                const char *path, bool no_progress)
+{
+  int r;
+  int fd;
+
+  if (strcmp(path, "-") == 0)
+    fd = 1;
+  else
+    fd = open(path, O_WRONLY | O_CREAT | O_EXCL, 0644);
+  if (fd < 0)
+    return -errno;
+
+  r = do_export_diff_fd(image, fromsnapname, endsnapname, whole_object, fd, no_progress);
+
   close(fd);
   if (r < 0 && fd != 1) {
     remove(path);