public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Eric Sandeen <sandeen@sandeen.net>
Cc: linux-xfs <linux-xfs@vger.kernel.org>
Subject: Re: [PATCH V2] metadump/restore: don't use errno after fwrite/fread failures
Date: Thu, 22 Mar 2018 09:47:45 -0700	[thread overview]
Message-ID: <20180322164745.GV4818@magnolia> (raw)
In-Reply-To: <7e510e30-3922-98d7-75c9-19f8e90610d0@sandeen.net>

On Thu, Mar 22, 2018 at 09:41:43AM -0500, Eric Sandeen wrote:
> fread/fwrite don't set errno, so printing out strerror(errno)
> after a failure leads to incorrect and confusing messages:
> 
> # xfs_mdrestore pre_repair.meta pre_repair.img
> xfs_mdrestore: error reading from file: Success
> 
> Don't return unset errno from write_index, either.
> 
> Signed-off-by: Eric Sandeen <sandeen@redhat.com>

Looks ok,
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>

--D

> ---
> 
> V2: don't return errno, either.
> 
> diff --git a/db/metadump.c b/db/metadump.c
> index 9d62958..d33f901 100644
> --- a/db/metadump.c
> +++ b/db/metadump.c
> @@ -161,8 +161,8 @@ write_index(void)
>  	 */
>  	metablock->mb_count = cpu_to_be16(cur_index);
>  	if (fwrite(metablock, (cur_index + 1) << BBSHIFT, 1, outf) != 1) {
> -		print_warning("error writing to file: %s", strerror(errno));
> -		return -errno;
> +		print_warning("error writing to target file");
> +		return -1;
>  	}
>  
>  	memset(block_index, 0, num_indices * sizeof(__be64));
> diff --git a/mdrestore/xfs_mdrestore.c b/mdrestore/xfs_mdrestore.c
> index c9d4b0c..262a385 100644
> --- a/mdrestore/xfs_mdrestore.c
> +++ b/mdrestore/xfs_mdrestore.c
> @@ -93,15 +93,14 @@ perform_restore(
>  	block_buffer = (char *)metablock + block_size;
>  
>  	if (fread(block_index, block_size - sizeof(struct xfs_metablock), 1, src_f) != 1)
> -		fatal("error reading from file: %s\n", strerror(errno));
> +		fatal("error reading from metadump file\n");
>  
>  	if (block_index[0] != 0)
>  		fatal("first block is not the primary superblock\n");
>  
>  
> -	if (fread(block_buffer, mb_count << mbp->mb_blocklog,
> -			1, src_f) != 1)
> -		fatal("error reading from file: %s\n", strerror(errno));
> +	if (fread(block_buffer, mb_count << mbp->mb_blocklog, 1, src_f) != 1)
> +		fatal("error reading from metadump file\n");
>  
>  	libxfs_sb_from_disk(&sb, (xfs_dsb_t *)block_buffer);
>  
> @@ -157,7 +156,7 @@ perform_restore(
>  			break;
>  
>  		if (fread(metablock, block_size, 1, src_f) != 1)
> -			fatal("error reading from file: %s\n", strerror(errno));
> +			fatal("error reading from metadump file\n");
>  
>  		mb_count = be16_to_cpu(metablock->mb_count);
>  		if (mb_count == 0)
> @@ -167,7 +166,7 @@ perform_restore(
>  
>  		if (fread(block_buffer, mb_count << mbp->mb_blocklog,
>  								1, src_f) != 1)
> -			fatal("error reading from file: %s\n", strerror(errno));
> +			fatal("error reading from metadump file\n");
>  
>  		bytes_read += block_size + (mb_count << mbp->mb_blocklog);
>  	}
> @@ -253,7 +252,7 @@ main(
>  	}
>  
>  	if (fread(&mb, sizeof(mb), 1, src_f) != 1)
> -		fatal("error reading from file: %s\n", strerror(errno));
> +		fatal("error reading from metadump file\n");
>  	if (mb.mb_magic != cpu_to_be32(XFS_MD_MAGIC))
>  		fatal("specified file is not a metadata dump\n");
>  
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

      reply	other threads:[~2018-03-22 16:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-21 23:24 [PATCH] metadump/restore: don't use errno after fwrite/fread failures Eric Sandeen
2018-03-21 23:58 ` Darrick J. Wong
2018-03-22  2:15   ` Eric Sandeen
2018-03-22 14:41 ` [PATCH V2] " Eric Sandeen
2018-03-22 16:47   ` Darrick J. Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180322164745.GV4818@magnolia \
    --to=darrick.wong@oracle.com \
    --cc=linux-xfs@vger.kernel.org \
    --cc=sandeen@sandeen.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox