btrfs-progs: fix btrfs send & receive with -e flag
authorChristian Brauner <christian.brauner@ubuntu.com>
Mon, 3 Apr 2017 20:21:07 +0000 (22:21 +0200)
committerDavid Sterba <dsterba@suse.com>
Fri, 7 Apr 2017 16:51:19 +0000 (18:51 +0200)
commit4b59093844b8ab68e3fb91d691b98e5a8e3fdba1
treee157cd622ccae415709892452da350243932ac2b
parent87861b38e6defdd5596167bee8242a06d38fd160
btrfs-progs: fix btrfs send & receive with -e flag

The old check here tried to ensure that empty streams are not considered valid.
The old check however, will always fail when only one run through the while(1)
loop is needed and honor_end_cmd is set. So this:

btrfs send /some/subvol | btrfs receive -e /some/

will consistently fail because -e causes honor_cmd_to be set and
btrfs_read_and_process_send_stream() to correctly return 1. So the command will
be successful but btrfs receive will error out because the send - receive
concluded in one run through the while(1) loop.

If we want to exclude empty streams we need a way to tell the difference between
btrfs_read_and_process_send_stream() returning 1 because read_buf() did not
detect any data and read_and_process_cmd() returning 1 because honor_end_cmd was
set. Without introducing too many changes the best way to me seems to have
btrfs_read_and_process_send_stream() return -ENODATA in the first case. The rest
stays the same. We can then check for -ENODATA in do_receive() and report a
proper error in this case. This should also be backwards compatible to previous
versions of btrfs receive. They will fail on empty streams because a negative
value is returned. The only thing that they will lack is a nice error message.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: David Sterba <dsterba@suse.com>
cmds-receive.c
send-stream.c