From patchwork Fri Mar 8 15:24:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 2238791 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id 32D5EE0338 for ; Fri, 8 Mar 2013 15:24:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759593Ab3CHPYr (ORCPT ); Fri, 8 Mar 2013 10:24:47 -0500 Received: from aserp1040.oracle.com ([141.146.126.69]:51077 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758746Ab3CHPYo (ORCPT ); Fri, 8 Mar 2013 10:24:44 -0500 Received: from acsinet21.oracle.com (acsinet21.oracle.com [141.146.126.237]) by aserp1040.oracle.com (Sentrion-MTA-4.3.1/Sentrion-MTA-4.3.1) with ESMTP id r28FOhot019527 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 8 Mar 2013 15:24:44 GMT Received: from acsmt358.oracle.com (acsmt358.oracle.com [141.146.40.158]) by acsinet21.oracle.com (8.14.4+Sun/8.14.4) with ESMTP id r28FOhfN009001 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 8 Mar 2013 15:24:43 GMT Received: from abhmt114.oracle.com (abhmt114.oracle.com [141.146.116.66]) by acsmt358.oracle.com (8.12.11.20060308/8.12.11) with ESMTP id r28FOh08023284 for ; Fri, 8 Mar 2013 09:24:43 -0600 Received: from wish.sg.oracle.com (/10.186.101.18) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 08 Mar 2013 07:24:42 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/3] btrfs-progs: Introduce flag BTRFS_SCAN_BACKUP_SB for btrfs_read_dev_super Date: Fri, 8 Mar 2013 23:24:59 +0800 Message-Id: <1362756300-30212-3-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 1.8.1.164.g2d0029e In-Reply-To: <1362756300-30212-1-git-send-email-anand.jain@oracle.com> References: <5127022B.6070200@oracle.com> <1362756300-30212-1-git-send-email-anand.jain@oracle.com> X-Source-IP: acsinet21.oracle.com [141.146.126.237] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org 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 --- 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 5197456..33e7e78 100644 --- a/disk-io.c +++ b/disk-io.c @@ -877,7 +877,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; @@ -1100,7 +1101,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; @@ -1109,6 +1111,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); @@ -1123,7 +1126,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..38c6b4f 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 234daf4..c76de2b 100644 --- a/find-root.c +++ b/find-root.c @@ -150,7 +150,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 c4d0d00..4641ce3 100644 --- a/utils.h +++ b/utils.h @@ -23,6 +23,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 ca1b402..b6e3f29 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; @@ -225,7 +226,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;