From patchwork Thu May 18 03:38:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9732459 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A80A16020B for ; Thu, 18 May 2017 03:40:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 895A82881B for ; Thu, 18 May 2017 03:40:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E97A28813; Thu, 18 May 2017 03:40:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2031D2881C for ; Thu, 18 May 2017 03:40:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932071AbdERDjM (ORCPT ); Wed, 17 May 2017 23:39:12 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:22220 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755072AbdERDjJ (ORCPT ); Wed, 17 May 2017 23:39:09 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="18996741" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 18 May 2017 11:39:04 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 58AFE47C6542; Thu, 18 May 2017 11:39:02 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 18 May 2017 11:39:01 +0800 From: Qu Wenruo To: , Subject: [PATCH 04/32] btrfs-progs: Refactor block sizes users in btrfs-corrupt-block.c Date: Thu, 18 May 2017 11:38:29 +0800 Message-ID: <20170518033857.15002-5-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170518033857.15002-1-quwenruo@cn.fujitsu.com> References: <20170518033857.15002-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: 58AFE47C6542.AFF86 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Convert root->sectorsize/nodesize users in btrfs-corrupt-block. This provides the basis to further refactor incorrect btrfs_root parameter to btrfs_fs_info parameter. Signed-off-by: Qu Wenruo --- btrfs-corrupt-block.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index 71b4d771..20a4c1df 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -169,7 +169,7 @@ static int corrupt_keys_in_block(struct btrfs_root *root, u64 bytenr) { struct extent_buffer *eb; - eb = read_tree_block(root, bytenr, root->nodesize, 0); + eb = read_tree_block(root, bytenr, root->fs_info->nodesize, 0); if (!extent_buffer_uptodate(eb)) return -EIO;; @@ -297,7 +297,7 @@ static void btrfs_corrupt_extent_tree(struct btrfs_trans_handle *trans, struct extent_buffer *next; next = read_tree_block(root, btrfs_node_blockptr(eb, i), - root->nodesize, + root->fs_info->nodesize, btrfs_node_ptr_generation(eb, i)); if (!extent_buffer_uptodate(next)) continue; @@ -764,7 +764,7 @@ static int corrupt_metadata_block(struct btrfs_root *root, u64 block, return -EINVAL; } - eb = read_tree_block(root, block, root->nodesize, 0); + eb = read_tree_block(root, block, root->fs_info->nodesize, 0); if (!extent_buffer_uptodate(eb)) { fprintf(stderr, "Couldn't read in tree block %s\n", field); return -EINVAL; @@ -1352,10 +1352,9 @@ int main(int argc, char **argv) print_usage(1); if (bytes == 0) - bytes = root->sectorsize; + bytes = root->fs_info->sectorsize; - bytes = (bytes + root->sectorsize - 1) / root->sectorsize; - bytes *= root->sectorsize; + bytes = round_up(bytes, root->fs_info->sectorsize); while (bytes > 0) { if (corrupt_block_keys) { @@ -1364,7 +1363,7 @@ int main(int argc, char **argv) struct extent_buffer *eb; eb = btrfs_find_create_tree_block(root->fs_info, - logical, root->sectorsize); + logical, root->fs_info->sectorsize); if (!eb) { error( "not enough memory to allocate extent buffer for bytenr %llu", @@ -1373,12 +1372,12 @@ int main(int argc, char **argv) goto out_close; } - debug_corrupt_block(eb, root, logical, root->sectorsize, - copy); + debug_corrupt_block(eb, root, logical, + root->fs_info->sectorsize, copy); free_extent_buffer(eb); } - logical += root->sectorsize; - bytes -= root->sectorsize; + logical += root->fs_info->sectorsize; + bytes -= root->fs_info->sectorsize; } return ret; out_close: