From patchwork Wed Sep 3 13:36:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 4834721 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3974C9F314 for ; Wed, 3 Sep 2014 13:36:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 883A0200C6 for ; Wed, 3 Sep 2014 13:36:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C6A102020E for ; Wed, 3 Sep 2014 13:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932842AbaICNe7 (ORCPT ); Wed, 3 Sep 2014 09:34:59 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:60451 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S932644AbaICNex (ORCPT ); Wed, 3 Sep 2014 09:34:53 -0400 X-IronPort-AV: E=Sophos;i="5.04,457,1406563200"; d="scan'208";a="35461875" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 03 Sep 2014 21:31:55 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s83DYm5S006741 for ; Wed, 3 Sep 2014 21:34:48 +0800 Received: from miao.fnst.cn.fujitsu.com (10.167.226.169) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 3 Sep 2014 21:34:59 +0800 From: Miao Xie To: Subject: [PATCH 3/5] Btrfs: restructure btrfs_scan_one_device Date: Wed, 3 Sep 2014 21:36:31 +0800 Message-ID: <1409751393-5403-4-git-send-email-miaox@cn.fujitsu.com> X-Mailer: git-send-email 1.9.3 In-Reply-To: <1409751393-5403-1-git-send-email-miaox@cn.fujitsu.com> References: <1409751393-5403-1-git-send-email-miaox@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.169] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some code in btrfs_scan_one_device will be re-used by the other function later, so restructure btrfs_scan_one_device and pick up those code to make a new function. Signed-off-by: Miao Xie --- fs/btrfs/volumes.c | 57 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 740a4f9..bcb19d5 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -885,24 +885,18 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices, return ret; } -/* - * Look for a btrfs signature on a device. This may be called out of the mount path - * and we are not allowed to call set_blocksize during the scan. The superblock - * is read via pagecache - */ -int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, - struct btrfs_fs_devices **fs_devices_ret) +static int __scan_device(struct block_device *bdev, const char *path, + struct btrfs_fs_devices **fs_devices_ret) { struct btrfs_super_block *disk_super; - struct block_device *bdev; struct page *page; void *p; - int ret = -EINVAL; u64 devid; u64 transid; u64 total_devices; u64 bytenr; pgoff_t index; + int ret; /* * we would like to check all the supers, but that would make @@ -911,38 +905,30 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, * later supers, using BTRFS_SUPER_MIRROR_MAX instead */ bytenr = btrfs_sb_offset(0); - flags |= FMODE_EXCL; - mutex_lock(&uuid_mutex); - - bdev = blkdev_get_by_path(path, flags, holder); - - if (IS_ERR(bdev)) { - ret = PTR_ERR(bdev); - goto error; - } /* make sure our super fits in the device */ if (bytenr + PAGE_CACHE_SIZE >= i_size_read(bdev->bd_inode)) - goto error_bdev_put; + return -EINVAL; /* make sure our super fits in the page */ if (sizeof(*disk_super) > PAGE_CACHE_SIZE) - goto error_bdev_put; + return -EINVAL; /* make sure our super doesn't straddle pages on disk */ index = bytenr >> PAGE_CACHE_SHIFT; if ((bytenr + sizeof(*disk_super) - 1) >> PAGE_CACHE_SHIFT != index) - goto error_bdev_put; + return -EINVAL; /* pull in the page with our super */ page = read_cache_page_gfp(bdev->bd_inode->i_mapping, index, GFP_NOFS); if (IS_ERR_OR_NULL(page)) - goto error_bdev_put; + return -ENOMEM; - p = kmap(page); + ret = -EINVAL; + p = kmap(page); /* align our pointer to the offset of the super block */ disk_super = p + (bytenr & ~PAGE_CACHE_MASK); @@ -974,7 +960,30 @@ error_unmap: kunmap(page); page_cache_release(page); -error_bdev_put: + return ret; +} + +/* + * Look for a btrfs signature on a device. This may be called out of the mount path + * and we are not allowed to call set_blocksize during the scan. The superblock + * is read via pagecache + */ +int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, + struct btrfs_fs_devices **fs_devices_ret) +{ + struct block_device *bdev; + int ret; + + flags |= FMODE_EXCL; + + mutex_lock(&uuid_mutex); + bdev = blkdev_get_by_path(path, flags, holder); + if (IS_ERR(bdev)) { + ret = PTR_ERR(bdev); + goto error; + } + + ret = __scan_device(bdev, path, fs_devices_ret); blkdev_put(bdev, flags); error: mutex_unlock(&uuid_mutex);