linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] btrfs-progs: Return more meaningful value for btrfs_read_dev_super
@ 2016-09-20  2:19 Qu Wenruo
  2016-09-20  2:19 ` [PATCH 2/2] btrfs-progs: super-recover: Reuse btrfs_read_dev_super function Qu Wenruo
  2016-09-23 13:22 ` [PATCH 1/2] btrfs-progs: Return more meaningful value for btrfs_read_dev_super David Sterba
  0 siblings, 2 replies; 5+ messages in thread
From: Qu Wenruo @ 2016-09-20  2:19 UTC (permalink / raw)
  To: linux-btrfs; +Cc: hawken

btrfs_read_dev_super() only returns 0 or -1, which doesn't really help,
caller won't know if it's caused by bad superblock or superblock out of
range.

Change it to return -ENOENT for superblock which is out of range, and
return -EIO for bad superblocks.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 disk-io.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index 854c285..26852ee 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -1590,14 +1590,15 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
 
 	if (sb_bytenr != BTRFS_SUPER_INFO_OFFSET) {
 		ret = pread64(fd, buf, BTRFS_SUPER_INFO_SIZE, sb_bytenr);
+		/* Special return value for out of dev/file range */
 		if (ret < BTRFS_SUPER_INFO_SIZE)
-			return -1;
+			return -ENOENT;
 
 		if (btrfs_super_bytenr(buf) != sb_bytenr)
-			return -1;
+			return -EIO;
 
 		if (check_super(buf, sbflags))
-			return -1;
+			return -EIO;
 		memcpy(sb, buf, BTRFS_SUPER_INFO_SIZE);
 		return 0;
 	}
@@ -1641,7 +1642,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
 		}
 	}
 
-	return transid > 0 ? 0 : -1;
+	return transid > 0 ? 0 : -EIO;
 }
 
 static int write_dev_supers(struct btrfs_root *root,
-- 
2.10.0




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

end of thread, other threads:[~2016-09-26  3:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-20  2:19 [PATCH 1/2] btrfs-progs: Return more meaningful value for btrfs_read_dev_super Qu Wenruo
2016-09-20  2:19 ` [PATCH 2/2] btrfs-progs: super-recover: Reuse btrfs_read_dev_super function Qu Wenruo
2016-09-23 13:26   ` David Sterba
2016-09-26  3:05     ` Qu Wenruo
2016-09-23 13:22 ` [PATCH 1/2] btrfs-progs: Return more meaningful value for btrfs_read_dev_super David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).