]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_copy: flush target devices before exiting
authorDarrick J. Wong <darrick.wong@oracle.com>
Wed, 15 Jul 2020 19:40:53 +0000 (15:40 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Wed, 15 Jul 2020 19:40:53 +0000 (15:40 -0400)
Flush the devices we're copying to before exiting, so that we can report
any write errors.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
copy/xfs_copy.c

index 2d087f716e898fb602d6d7e114ff851af6451fb6..38a20d37a015f8bb2f1a4c583027547b688b8090 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdarg.h>
 #include "xfs_copy.h"
 #include "libxlog.h"
+#include "libfrog/platform.h"
 
 #define        rounddown(x, y) (((x)/(y))*(y))
 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
@@ -138,6 +139,14 @@ check_errors(void)
        int     i, first_error = 0;
 
        for (i = 0; i < num_targets; i++)  {
+               if (target[i].state != INACTIVE) {
+                       if (platform_flush_device(target[i].fd, 0)) {
+                               target[i].error = errno;
+                               target[i].state = INACTIVE;
+                               target[i].err_type = 2;
+                       }
+               }
+
                if (target[i].state == INACTIVE)  {
                        if (first_error == 0)  {
                                first_error++;
@@ -145,10 +154,21 @@ check_errors(void)
                                _("THE FOLLOWING COPIES FAILED TO COMPLETE\n"));
                        }
                        do_log("    %s -- ", target[i].name);
-                       if (target[i].err_type == 0)
+                       switch (target[i].err_type) {
+                       case 0:
                                do_log(_("write error"));
-                       else
+                               break;
+                       case 1:
                                do_log(_("lseek error"));
+                               break;
+                       case 2:
+                               do_log(_("flush error"));
+                               break;
+                       default:
+                               do_log(_("unknown error type %d"),
+                                               target[i].err_type);
+                               break;
+                       }
                        do_log(_(" at offset %lld\n"), target[i].position);
                }
        }