diff mbox

[1/1] btrfs-progs: send: fail on first -ENODATA only

Message ID 20170429215405.1123-2-christian.brauner@ubuntu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Christian Brauner April 29, 2017, 9:54 p.m. UTC
Returning -ENODATA is only considered invalid on the first run of the loop.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
---
 cmds-receive.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

Comments

Christian Brauner May 1, 2017, 1:09 p.m. UTC | #1
Hi,

The original bug-reporter verified that my patch fixes the bug. See

https://bugzilla.kernel.org/show_bug.cgi?id=195597

Christian

On Sat, Apr 29, 2017 at 11:54:05PM +0200, Christian Brauner wrote:
> Returning -ENODATA is only considered invalid on the first run of the loop.
> 
> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
> ---
>  cmds-receive.c | 20 ++++++++++++++------
>  1 file changed, 14 insertions(+), 6 deletions(-)
> 
> diff --git a/cmds-receive.c b/cmds-receive.c
> index b59f00e4..72e9c8f3 100644
> --- a/cmds-receive.c
> +++ b/cmds-receive.c
> @@ -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;
> +	int iterations = 0;
>  
>  	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);
> -		if (ret < 0 && ret == -ENODATA) {
> +		if (ret < 0) {
> +			if (ret != -ENODATA)
> +				goto out;
> +
>  			/* 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;
> @@ -1213,6 +1219,8 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
>  		ret = finish_subvol(rctx);
>  		if (ret < 0)
>  			goto out;
> +
> +		iterations++;
>  	}
>  	ret = 0;
>  
> -- 
> 2.11.0
> 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Lakshmipathi.G May 1, 2017, 6:16 p.m. UTC | #2
Hi Christian, thanks for fixing it quickly :) I don't have permission
to change the bug state to fixed, if you or Nazar have those rights, i
think this bug can be closed.
----
Cheers,
Lakshmipathi.G
http://www.giis.co.in http://www.webminal.org


On Mon, May 1, 2017 at 6:39 PM, Christian Brauner
<christian.brauner@canonical.com> wrote:
> Hi,
>
> The original bug-reporter verified that my patch fixes the bug. See
>
> https://bugzilla.kernel.org/show_bug.cgi?id=195597
>
> Christian
>
> On Sat, Apr 29, 2017 at 11:54:05PM +0200, Christian Brauner wrote:
>> Returning -ENODATA is only considered invalid on the first run of the loop.
>>
>> Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
>> ---
>>  cmds-receive.c | 20 ++++++++++++++------
>>  1 file changed, 14 insertions(+), 6 deletions(-)
>>
>> diff --git a/cmds-receive.c b/cmds-receive.c
>> index b59f00e4..72e9c8f3 100644
>> --- a/cmds-receive.c
>> +++ b/cmds-receive.c
>> @@ -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;
>> +     int iterations = 0;
>>
>>       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);
>> -             if (ret < 0 && ret == -ENODATA) {
>> +             if (ret < 0) {
>> +                     if (ret != -ENODATA)
>> +                             goto out;
>> +
>>                       /* 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;
>> @@ -1213,6 +1219,8 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
>>               ret = finish_subvol(rctx);
>>               if (ret < 0)
>>                       goto out;
>> +
>> +             iterations++;
>>       }
>>       ret = 0;
>>
>> --
>> 2.11.0
>>
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
David Sterba May 9, 2017, 6:09 p.m. UTC | #3
On Mon, May 01, 2017 at 03:09:41PM +0200, Christian Brauner wrote:
> The original bug-reporter verified that my patch fixes the bug. See
> 
> https://bugzilla.kernel.org/show_bug.cgi?id=195597

Thanks, patch applied. I'll add reference to the changelog. 
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/cmds-receive.c b/cmds-receive.c
index b59f00e4..72e9c8f3 100644
--- a/cmds-receive.c
+++ b/cmds-receive.c
@@ -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;
+	int iterations = 0;
 
 	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);
-		if (ret < 0 && ret == -ENODATA) {
+		if (ret < 0) {
+			if (ret != -ENODATA)
+				goto out;
+
 			/* 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;
@@ -1213,6 +1219,8 @@  static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
 		ret = finish_subvol(rctx);
 		if (ret < 0)
 			goto out;
+
+		iterations++;
 	}
 	ret = 0;