public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] metadump/restore: don't use errno after fwrite/fread failures
@ 2018-03-21 23:24 Eric Sandeen
  2018-03-21 23:58 ` Darrick J. Wong
  2018-03-22 14:41 ` [PATCH V2] " Eric Sandeen
  0 siblings, 2 replies; 5+ messages in thread
From: Eric Sandeen @ 2018-03-21 23:24 UTC (permalink / raw)
  To: linux-xfs

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

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---

diff --git a/db/metadump.c b/db/metadump.c
index 9d62958..231adc6 100644
--- a/db/metadump.c
+++ b/db/metadump.c
@@ -161,7 +161,7 @@ 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));
+		print_warning("error writing to target file");
 		return -errno;
 	}
 
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");
 


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-03-22 16:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox