linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Cc: sandeen@redhat.com, dsterba@suse.cz
Subject: [PATCH 3/5 v5] btrfs-progs: Introduce flag BTRFS_SCAN_BACKUP_SB for btrfs_read_dev_super
Date: Wed, 27 Mar 2013 18:07:34 +0800	[thread overview]
Message-ID: <1364378856-21053-4-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1364378856-21053-1-git-send-email-anand.jain@oracle.com>

As of now btrfs_read_dev_super() reads the backup super block
by default and calling function has no control. However in the
following patch we would see that is undesirable.
So with the flag BTRFS_SCAN_BACKUP_SB the calling function
can now indicate if btrfs_read_dev_super should scan for
the backup SB when primary SB fails.

This patch just provides the frame-work, keeping all the logic
in the code same with or without this patch.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
 disk-io.c   | 10 +++++++---
 disk-io.h   |  3 ++-
 find-root.c |  3 ++-
 utils.h     |  1 +
 volumes.c   |  4 +++-
 5 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/disk-io.c b/disk-io.c
index 6a03e9c..8d68c2e 100644
--- a/disk-io.c
+++ b/disk-io.c
@@ -880,7 +880,8 @@ static struct btrfs_fs_info *__open_ctree_fd(int fp, const char *path,
 	fs_info->super_bytenr = sb_bytenr;
 	disk_super = fs_info->super_copy;
 	ret = btrfs_read_dev_super(fs_devices->latest_bdev,
-				   disk_super, sb_bytenr);
+				   disk_super, sb_bytenr,
+				   BTRFS_SCAN_BACKUP_SB);
 	if (ret) {
 		printk("No valid btrfs found\n");
 		goto out_devices;
@@ -1103,7 +1104,8 @@ struct btrfs_root *open_ctree_fd(int fp, const char *path, u64 sb_bytenr,
 	return info->fs_root;
 }
 
-int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
+int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
+			u64 flags)
 {
 	u8 fsid[BTRFS_FSID_SIZE];
 	int fsid_is_initialized = 0;
@@ -1112,6 +1114,7 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
 	int ret;
 	u64 transid = 0;
 	u64 bytenr;
+	int max;
 
 	if (sb_bytenr != BTRFS_SUPER_INFO_OFFSET) {
 		ret = pread64(fd, &buf, sizeof(buf), sb_bytenr);
@@ -1126,7 +1129,8 @@ int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr)
 		return 0;
 	}
 
-	for (i = 0; i < BTRFS_SUPER_MIRROR_MAX; i++) {
+	max = flags & BTRFS_SCAN_BACKUP_SB ? BTRFS_SUPER_MIRROR_MAX : 1;
+	for (i = 0; i < max; i++) {
 		bytenr = btrfs_sb_offset(i);
 		ret = pread64(fd, &buf, sizeof(buf), bytenr);
 		if (ret < sizeof(buf))
diff --git a/disk-io.h b/disk-io.h
index ff87958..40b7222 100644
--- a/disk-io.h
+++ b/disk-io.h
@@ -59,7 +59,8 @@ int close_ctree(struct btrfs_root *root);
 int write_all_supers(struct btrfs_root *root);
 int write_ctree_super(struct btrfs_trans_handle *trans,
 		      struct btrfs_root *root);
-int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr);
+int btrfs_read_dev_super(int fd, struct btrfs_super_block *sb, u64 sb_bytenr,
+			u64 flags);
 int btrfs_map_bh_to_logical(struct btrfs_root *root, struct extent_buffer *bh,
 			    u64 logical);
 struct extent_buffer *btrfs_find_tree_block(struct btrfs_root *root,
diff --git a/find-root.c b/find-root.c
index 16920ed..0b08358 100644
--- a/find-root.c
+++ b/find-root.c
@@ -151,7 +151,8 @@ static struct btrfs_root *open_ctree_broken(int fd, const char *device)
 	fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET;
 	disk_super = fs_info->super_copy;
 	ret = btrfs_read_dev_super(fs_devices->latest_bdev,
-				   disk_super, BTRFS_SUPER_INFO_OFFSET);
+				   disk_super, BTRFS_SUPER_INFO_OFFSET,
+				   BTRFS_SCAN_BACKUP_SB);
 	if (ret) {
 		printk("No valid btrfs found\n");
 		goto out_devices;
diff --git a/utils.h b/utils.h
index 1de5143..ab22b02 100644
--- a/utils.h
+++ b/utils.h
@@ -24,6 +24,7 @@
 
 #define BTRFS_MKFS_SYSTEM_GROUP_SIZE (4 * 1024 * 1024)
 #define BTRFS_SCAN_REGISTER	(1ULL << 1)
+#define BTRFS_SCAN_BACKUP_SB	(1ULL << 2)
 
 int make_btrfs(int fd, const char *device, const char *label,
 	       u64 blocks[6], u64 num_bytes, u32 nodesize,
diff --git a/volumes.c b/volumes.c
index 3e52d06..1113cb5 100644
--- a/volumes.c
+++ b/volumes.c
@@ -29,6 +29,7 @@
 #include "transaction.h"
 #include "print-tree.h"
 #include "volumes.h"
+#include "utils.h"
 
 struct stripe {
 	struct btrfs_device *dev;
@@ -226,7 +227,8 @@ int btrfs_scan_one_device(int fd, const char *path,
 		goto error;
 	}
 	disk_super = (struct btrfs_super_block *)buf;
-	ret = btrfs_read_dev_super(fd, disk_super, super_offset);
+	ret = btrfs_read_dev_super(fd, disk_super, super_offset,
+			BTRFS_SCAN_BACKUP_SB);
 	if (ret < 0) {
 		ret = -EIO;
 		goto error_brelse;
-- 
1.8.1.227.g44fe835


  parent reply	other threads:[~2013-03-27 10:07 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-22  5:29 [bug] mkfs.btrfs reports device busy for ext4 mounted disk Anand Jain
2013-02-22 19:03 ` Zach Brown
2013-02-22 22:30   ` David Sterba
2013-03-01 10:18     ` Anand Jain
2013-03-01 10:13 ` [PATCH] btrfs-progs: traverse to backup super-block only when indicated Anand Jain
2013-03-01 17:37   ` Eric Sandeen
2013-03-04  5:20     ` Anand Jain
2013-03-01 18:27   ` Zach Brown
2013-03-27 10:07   ` [PATCH 0/5 v5] access to backup-sb and btrfs' multipath aware Anand Jain
2013-03-27 10:07     ` [PATCH 1/5 v5] btrfs-progs: make btrfs dev scan multi path aware Anand Jain
2013-04-11  9:57       ` [obsoleted] " Anand Jain
2013-03-27 10:07     ` [PATCH 2/5 v5] btrfs-progs: Introduce flag BTRFS_SCAN_REGISTER to replace run_ioctl Anand Jain
2013-03-27 10:07     ` Anand Jain [this message]
2013-03-27 10:07     ` [PATCH 4/5 v5] btrfs-progs: introduce passing flags to btrfs_scan_one_device Anand Jain
2013-03-27 10:07     ` [PATCH 5/5 v5] btrfs-progs: disable using backup superblock by default Anand Jain
2013-03-27 23:17     ` [PATCH 0/5 v5] access to backup-sb and btrfs' multipath aware anand jain
2013-04-05  5:54 ` v6: access to backup superblock Anand Jain
2013-04-05  5:54   ` [PATCH 1/5] btrfs-progs: Introduce flag BTRFS_SCAN_REGISTER to replace run_ioctl Anand Jain
2013-04-05  5:54   ` [PATCH 2/5] btrfs-progs: Introduce flag BTRFS_SCAN_BACKUP_SB for btrfs_read_dev_super Anand Jain
2013-04-05  5:54   ` [PATCH 3/5] btrfs-progs: introduce passing flags to btrfs_scan_one_device Anand Jain
2013-04-05  5:54   ` [PATCH 4/5] btrfs-progs: disable using backup superblock by default Anand Jain
2013-04-05  5:54   ` [PATCH 5/5] btrfs-progs: btrfs-find-root should scan backup-sb Anand Jain

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=1364378856-21053-4-git-send-email-anand.jain@oracle.com \
    --to=anand.jain@oracle.com \
    --cc=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=sandeen@redhat.com \
    /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;
as well as URLs for NNTP newsgroup(s).