btrfs-progs: receiv: fail on first -ENODATA only
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 29 Apr 2017 21:54:05 +0000 (23:54 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 15 May 2017 14:23:14 +0000 (16:23 +0200)
Returning -ENODATA is only considered invalid on the first run of the
loop where we would detect entirely empty stream.

The enhanced test misc-tests/018-recv-end-of-stream now passes.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=195597
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-receive.c

index b59f00e..72e9c8f 100644 (file)
@@ -1091,6 +1091,7 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
        char *dest_dir_full_path;
        char root_subvol_path[PATH_MAX];
        int end = 0;
        char *dest_dir_full_path;
        char root_subvol_path[PATH_MAX];
        int end = 0;
+       int iterations = 0;
 
        dest_dir_full_path = realpath(tomnt, NULL);
        if (!dest_dir_full_path) {
 
        dest_dir_full_path = realpath(tomnt, NULL);
        if (!dest_dir_full_path) {
@@ -1198,13 +1199,18 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
                                                         rctx,
                                                         rctx->honor_end_cmd,
                                                         max_errors);
                                                         rctx,
                                                         rctx->honor_end_cmd,
                                                         max_errors);
-               if (ret < 0 && ret == -ENODATA) {
+               if (ret < 0) {
+                       if (ret != -ENODATA)
+                               goto out;
+
                        /* Empty stream is invalid */
                        /* Empty stream is invalid */
-                       error("empty stream is not considered valid");
-                       ret = -EINVAL;
-                       goto out;
-               } else if (ret < 0) {
-                       goto out;
+                       if (iterations == 0) {
+                               error("empty stream is not considered valid");
+                               ret = -EINVAL;
+                               goto out;
+                       }
+
+                       ret = 1;
                }
                if (ret > 0)
                        end = 1;
                }
                if (ret > 0)
                        end = 1;
@@ -1213,6 +1219,8 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
                ret = finish_subvol(rctx);
                if (ret < 0)
                        goto out;
                ret = finish_subvol(rctx);
                if (ret < 0)
                        goto out;
+
+               iterations++;
        }
        ret = 0;
 
        }
        ret = 0;