From: Dongsheng Yang Date: Tue, 11 Oct 2016 11:02:02 +0000 (-0400) Subject: rbd: refactor do_export_diff to accept fd X-Git-Tag: v12.0.1~342^2~16 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=bc80b147ace869cbb218fb302bd3b8540bac3679;p=ceph.git rbd: refactor do_export_diff to accept fd Signed-off-by: Dongsheng Yang --- diff --git a/src/tools/rbd/action/Export.cc b/src/tools/rbd/action/Export.cc index d55936ba6759a..bffeb22611b35 100644 --- a/src/tools/rbd/action/Export.cc +++ b/src/tools/rbd/action/Export.cc @@ -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);