All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
To: linux-btrfs@vger.kernel.org
Cc: hawken@thehawken.org
Subject: [PATCH 1/2] btrfs-progs: Return more meaningful value for btrfs_read_dev_super
Date: Tue, 20 Sep 2016 10:19:01 +0800	[thread overview]
Message-ID: <20160920021902.818-1-quwenruo@cn.fujitsu.com> (raw)

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




             reply	other threads:[~2016-09-20  2:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-20  2:19 Qu Wenruo [this message]
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

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=20160920021902.818-1-quwenruo@cn.fujitsu.com \
    --to=quwenruo@cn.fujitsu.com \
    --cc=hawken@thehawken.org \
    --cc=linux-btrfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.