[04/10] btrfs-progs: return -EIO properly in restore_metadump()
diff mbox

Message ID 1445254680-11102-5-git-send-email-guaneryu@gmail.com
State New
Headers show

Commit Message

Eryu Guan Oct. 19, 2015, 11:37 a.m. UTC
Error number -EIO is assigned to ret but later ret is overwritten by
wait_for_worker().

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
---
 btrfs-image.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

David Sterba Oct. 19, 2015, 1:56 p.m. UTC | #1
On Mon, Oct 19, 2015 at 07:37:54PM +0800, Eryu Guan wrote:
> Error number -EIO is assigned to ret but later ret is overwritten by
> wait_for_worker().
> 
> Signed-off-by: Eryu Guan <guaneryu@gmail.com>
> ---
>  btrfs-image.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/btrfs-image.c b/btrfs-image.c
> index 82eed05..7d3a2f8 100644
> --- a/btrfs-image.c
> +++ b/btrfs-image.c
> @@ -2465,6 +2465,7 @@ static int restore_metadump(const char *input, FILE *out, int old_restore,
>  	u64 bytenr = 0;
>  	FILE *in = NULL;
>  	int ret = 0;
> +	int err = 0;
>  
>  	if (!strcmp(input, "-")) {
>  		in = stdin;
> @@ -2526,7 +2527,7 @@ static int restore_metadump(const char *input, FILE *out, int old_restore,
>  		if (le64_to_cpu(header->magic) != HEADER_MAGIC ||
>  		    le64_to_cpu(header->bytenr) != bytenr) {
>  			fprintf(stderr, "bad header in metadump image\n");
> -			ret = -EIO;
> +			err = -EIO;

Shouldn't we do 'goto out' instead? As this looks likes the metadump is
broken anyway so there's no point in continuing.
--
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

Patch
diff mbox

diff --git a/btrfs-image.c b/btrfs-image.c
index 82eed05..7d3a2f8 100644
--- a/btrfs-image.c
+++ b/btrfs-image.c
@@ -2465,6 +2465,7 @@  static int restore_metadump(const char *input, FILE *out, int old_restore,
 	u64 bytenr = 0;
 	FILE *in = NULL;
 	int ret = 0;
+	int err = 0;
 
 	if (!strcmp(input, "-")) {
 		in = stdin;
@@ -2526,7 +2527,7 @@  static int restore_metadump(const char *input, FILE *out, int old_restore,
 		if (le64_to_cpu(header->magic) != HEADER_MAGIC ||
 		    le64_to_cpu(header->bytenr) != bytenr) {
 			fprintf(stderr, "bad header in metadump image\n");
-			ret = -EIO;
+			err = -EIO;
 			break;
 		}
 		ret = add_cluster(cluster, &mdrestore, &bytenr);
@@ -2536,6 +2537,8 @@  static int restore_metadump(const char *input, FILE *out, int old_restore,
 		}
 	}
 	ret = wait_for_worker(&mdrestore);
+	if (!ret)
+		ret = err;
 
 	if (!ret && !multi_devices && !old_restore) {
 		struct btrfs_root *root;