From patchwork Wed May 27 08:12:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11572245 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B109B912 for ; Wed, 27 May 2020 08:12:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 987C3215A4 for ; Wed, 27 May 2020 08:12:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="lVzKKT2s" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387811AbgE0IMm (ORCPT ); Wed, 27 May 2020 04:12:42 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:15289 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387775AbgE0IMd (ORCPT ); Wed, 27 May 2020 04:12:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590567153; x=1622103153; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RtXp2JkcAgZd33XjOKlvLt4nU9bdMxQXaBrp5ggLE9E=; b=lVzKKT2sqNU5jlykiMTq0k3BI/bK5F6pVhHNJ8u25XWCrfitYI7trAf6 e1zxNGj7r3jLHm0SLBSOJRVJQ9K0i5EUsWB1iZiJENN8HDoEqn7o8HakR exUQQ67q27jx5OPB96ouR7b6bje4k2SkKkRBqyIaA0m9UNMnYMBMXEuTh 8pEFPFlB0TtVKp9rTiR+8t3Q9auDRAs+XAy87OU16OUvHoZairh5Qubh+ KRvTswhz0qrzgSm/LpBRxpn2XjV6zvHve3MkhErZMWM1WL9e2sIPdDv/n i5EGg1MwKdmCe+4Q8h7xF2im4Ye7Zx3MS4FcWWggm6zX4Ij8D7iEaDkuB w==; IronPort-SDR: XQ7n+p5JUdxK+OkPqDTV0cN1gwfkwbyO1QRXZO03G5HYiAqnvEdwUrMkItfIQxOmpMKc5W0aj0 wAGrR9T9HY9qXaNjjlsjSokgJvm9Pyw1vAPmX7O20IvJMkFeSevVG3GsQqwMQG0rWnHb54LF1a 8EY7UfqBbv1Ogaf+vSOwi1ucqJZ1d2rN3R9iukvE6ryoITmg8K4zMS8H563F6KVQgDX0/xrVKe K2IGSDfVyNNlD3hENXEJuDvgfIzGl4JECuEP4+GaWMAw9JhAA/zPl/FDfREuy8kcU+tEMZB2v3 h7E= X-IronPort-AV: E=Sophos;i="5.73,440,1583164800"; d="scan'208";a="247648699" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2020 16:12:31 +0800 IronPort-SDR: p6uge7cMGTrRix/ZZdXmdIKDdadL0CyaOTYc+gqUFhnEICPwTI9UF52vWI8nsQBZecUE/lMBsG RdRyc44O0sAjJP3I+H6bczpHIOfBjk6OA= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 01:02:22 -0700 IronPort-SDR: 3pewpqWvWrc8AgA2uduCGgg+BnmPbltUgN74SOKWNNaLYAw3dwIbeYfPO2lE16SgA5J16kSf6U UfY/Z5X0WesQ== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 27 May 2020 01:12:31 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn , Nikolay Borisov Subject: [PATCH v2 1/3] btrfs: remove pointless out label in find_first_block_group Date: Wed, 27 May 2020 17:12:25 +0900 Message-Id: <20200527081227.3408-2-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200527081227.3408-1-johannes.thumshirn@wdc.com> References: <20200527081227.3408-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The 'out' label in find_first_block_group() does not do anything in terms of cleanup. It is better to directly return 'ret' instead of jumping to out to not confuse readers. Additionally there is no need to initialize ret with 0. Signed-off-by: Johannes Thumshirn Reviewed-by: Nikolay Borisov --- fs/btrfs/block-group.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index 176e8a292fd1..c5acd89c864c 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1527,7 +1527,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, struct btrfs_key *key) { struct btrfs_root *root = fs_info->extent_root; - int ret = 0; + int ret; struct btrfs_key found_key; struct extent_buffer *leaf; struct btrfs_block_group_item bg; @@ -1536,7 +1536,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, ret = btrfs_search_slot(NULL, root, key, path, 0, 0); if (ret < 0) - goto out; + return ret; while (1) { slot = path->slots[0]; @@ -1546,7 +1546,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, if (ret == 0) continue; if (ret < 0) - goto out; + return ret; break; } btrfs_item_key_to_cpu(leaf, &found_key, slot); @@ -1594,11 +1594,11 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, } } free_extent_map(em); - goto out; + return ret; } path->slots[0]++; } -out: + return ret; } From patchwork Wed May 27 08:12:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11572243 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60F4F739 for ; Wed, 27 May 2020 08:12:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 410FA21531 for ; Wed, 27 May 2020 08:12:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="JodKIjdh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387809AbgE0IMl (ORCPT ); Wed, 27 May 2020 04:12:41 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:15288 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387776AbgE0IMd (ORCPT ); Wed, 27 May 2020 04:12:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590567153; x=1622103153; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6MmVwvch6llO++wAjN1UzSvTgf+D9QAPaoHZXyV9F7U=; b=JodKIjdht1kGzjekaQa2iSppnQCgwkBgTKIwhfOHpIOtlbji5NVHjykD NYpeZpC4BKeezRqO2Y+t9xlrytfxmG2WOZxyszGIbJpKH1XH8sYc6LI/L jdB3w5AxTlyqdBXpAanhwTe3IjU09l4hgclf+deioYSlCB41PhPQZUL1l yRaJVO9AZSABr0p/nYZzacnHDw8LnWgMlVYEClBg1lUBMP2tpNxg8ABXq v2cVXgyjWBGwcTmyc8H3W6IMoaPYsVuR7XNNlvKFFbJ+UM2cqdeNE0hTD 8x0G8pSNa1DYDDf7Mv5cau+iVmL5C1Uc5Hmw6+ZDEbResAWmYE/q8rioG g==; IronPort-SDR: +z0bTf1f41xY9QdWBj39yOWARwC1O3iLopi69TE+G04st/TSJc6IUuEPCRzUy9HtAyIvaru5Pr 7ugq+6mNyWbccNi3ojHgQVNwWP5vcJnb+z6M3mVzlNT9kwAhHDKarxj3V/NHbou+xxnqKrXlD3 m7JeLuGAwwktnY44zXSXdXxSaETaXQjpUL+Wh3Q051VoTjpC9okFFA2Yo8bOu90/xLYyoO5PV3 AI1L28jrE6mb4k42bwSbK2oUgYSMdALCrESxu1eMNuTS8tk6GxB/tcHGHA3/2z/DBE9YN+u9KP dBI= X-IronPort-AV: E=Sophos;i="5.73,440,1583164800"; d="scan'208";a="247648700" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2020 16:12:32 +0800 IronPort-SDR: gKbTJ19VziSJzeb8kDxhlXagLKTu2eObbnfxIq60VhA7TwzXw2FdK6hSjOXmRpIbkjcepo+1Nv BpQUim+s9jj17n8BhKNIbIKjtxYJUPmIs= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 01:02:23 -0700 IronPort-SDR: doIUcgwtmXSOBCHiTuUxQ9eHH0W+hEHUmF0xtWHNKFZjVLnF+6oZ1aqLJIClBkPAN0DTORrZSA lK5RsjuNWgpQ== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 27 May 2020 01:12:32 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn , Nikolay Borisov Subject: [PATCH v2 2/3] btrfs: get mapping tree directly from fsinfo in find_first_block_group Date: Wed, 27 May 2020 17:12:26 +0900 Message-Id: <20200527081227.3408-3-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200527081227.3408-1-johannes.thumshirn@wdc.com> References: <20200527081227.3408-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We already have an fs_info in our function parameters, there's no need to do the maths again and get fs_info from the extent_root just to get the mapping_tree. Instead directly grab the mapping_tree from fs_info. Signed-off-by: Johannes Thumshirn Reviewed-by: Nikolay Borisov --- fs/btrfs/block-group.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index c5acd89c864c..c4462e4c8413 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1556,7 +1556,7 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, struct extent_map_tree *em_tree; struct extent_map *em; - em_tree = &root->fs_info->mapping_tree; + em_tree = &fs_info->mapping_tree; read_lock(&em_tree->lock); em = lookup_extent_mapping(em_tree, found_key.objectid, found_key.offset); From patchwork Wed May 27 08:12:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11572241 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A8DCE739 for ; Wed, 27 May 2020 08:12:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8B5222145D for ; Wed, 27 May 2020 08:12:39 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="dF0UQQ4T" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387807AbgE0IMh (ORCPT ); Wed, 27 May 2020 04:12:37 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:15290 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387790AbgE0IMf (ORCPT ); Wed, 27 May 2020 04:12:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1590567154; x=1622103154; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hz2nZDN3LgZDhZ28NuCnPUE00f5eAx3qaEFSJFPCpyo=; b=dF0UQQ4TW75zuQwQFCA+gMtV/q5KvenRiWyGJFOBQHHfJYKIL5jNY11T h7cQHmYgxrMGCnoEN4TH92+YX50WigSv7rJwEgKs24TgXMsXpI+qbQab+ TtKBqvUDAzy+/gOaj+Ugcr1NcjtvLhEqjFJZFwOOUTkCIMddkyMU7PW4M ZQ1TJvQfh8SAubF96Q4XwZ0M7DG6IxJv1aIiBT/oK44qlMc8dN2ziJCUA 2UTsN8rM4s3OI3B5CuFmFw2z3CBngx28rOLy7U8kwawleS3JBtu15Ezla rHvvofLPQV0wMaPpXjcWykj4LjRfjaA5I7pC0tTjl/wHQYq0nJf7j9xqv w==; IronPort-SDR: d5xGExDrURMDaqmYQqR68s7n/P3KiJCwoICckmTFBCxpv85WXT+z4TW4blaeluJ7Bu6dgTd9MW M850jHOC7wpdknUyDkVPcIR/hw3Nzt/+5weo4NSMmL4/wzdM9YBdm4PKZkwmNRPbpX0ysDhYmK a2tXfzq728vpYps+fuAYrH62STPvMaFgIzDIA5rbNGzn3ACQjt7y6YLWfPUik54rXSaqfDsYgn yh2rDP/euzSOdtHAvkwLZ1LjGe3bHuS0oNKa3L1GMrkJkRtT4pl2TCIq4zlR1G0q+amkYZGKwY Iow= X-IronPort-AV: E=Sophos;i="5.73,440,1583164800"; d="scan'208";a="247648701" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 May 2020 16:12:33 +0800 IronPort-SDR: 2UdEehNSbGXg6FG8YDyLqf1MVT2fc9CeaUK+RfuwpMlZEf/N/3nqUC9jkL13odVTGOYncgoJJw NNuJ/II9EZAL7fOXaMf1OWOvX5mJ+nvvs= Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2020 01:02:24 -0700 IronPort-SDR: lmgpyJi0nudcBOYzeTqzwxhTCcygrc3T4nNKNaV1xxs8YosKQyjU0gsoZADpzY+fsoXBSo6Liw eFlHc9K8V4Fw== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip01.wdc.com with ESMTP; 27 May 2020 01:12:33 -0700 From: Johannes Thumshirn To: David Sterba Cc: linux-btrfs@vger.kernel.org, Johannes Thumshirn , Nikolay Borisov Subject: [PATCH v2 3/3] btrfs: factor out reading of bg from find_frist_block_group Date: Wed, 27 May 2020 17:12:27 +0900 Message-Id: <20200527081227.3408-4-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200527081227.3408-1-johannes.thumshirn@wdc.com> References: <20200527081227.3408-1-johannes.thumshirn@wdc.com> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org When find_first_block_group() finds a block group item in the extent-tree, it does a lookup of the object in the extent mapping tree and does further checks on the item. Factor out this step from find_first_block_group() so we can further simplify the code. Signed-off-by: Johannes Thumshirn Reviewed-by: Nikolay Borisov --- fs/btrfs/block-group.c | 100 ++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 46 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index c4462e4c8413..c2cbdbca4d47 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1522,6 +1522,57 @@ void btrfs_mark_bg_unused(struct btrfs_block_group *bg) spin_unlock(&fs_info->unused_bgs_lock); } +static int read_bg_from_eb(struct btrfs_fs_info *fs_info, struct btrfs_key *key, + struct btrfs_path *path) +{ + struct extent_map_tree *em_tree; + struct extent_map *em; + struct btrfs_block_group_item bg; + struct extent_buffer *leaf; + int slot; + u64 flags; + int ret = 0; + + slot = path->slots[0]; + leaf = path->nodes[0]; + + em_tree = &fs_info->mapping_tree; + read_lock(&em_tree->lock); + em = lookup_extent_mapping(em_tree, key->objectid, key->offset); + read_unlock(&em_tree->lock); + if (!em) { + btrfs_err(fs_info, + "logical %llu len %llu found bg but no related chunk", + key->objectid, key->offset); + return -ENOENT; + } + + if (em->start != key->objectid || em->len != key->offset) { + btrfs_err(fs_info, + "block group %llu len %llu mismatch with chunk %llu len %llu", + key->objectid, key->offset, em->start, em->len); + ret = -EUCLEAN; + goto out_free_em; + } + + read_extent_buffer(leaf, &bg, btrfs_item_ptr_offset(leaf, slot), + sizeof(bg)); + flags = btrfs_stack_block_group_flags(&bg) & + BTRFS_BLOCK_GROUP_TYPE_MASK; + + if (flags != (em->map_lookup->type & BTRFS_BLOCK_GROUP_TYPE_MASK)) { + btrfs_err(fs_info, + "block group %llu len %llu type flags 0x%llx mismatch with chunk type flags 0x%llx", + key->objectid, key->offset, flags, + (BTRFS_BLOCK_GROUP_TYPE_MASK & em->map_lookup->type)); + ret = -EUCLEAN; + } + +out_free_em: + free_extent_map(em); + return ret; +} + static int find_first_block_group(struct btrfs_fs_info *fs_info, struct btrfs_path *path, struct btrfs_key *key) @@ -1530,8 +1581,6 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, int ret; struct btrfs_key found_key; struct extent_buffer *leaf; - struct btrfs_block_group_item bg; - u64 flags; int slot; ret = btrfs_search_slot(NULL, root, key, path, 0, 0); @@ -1552,50 +1601,9 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, btrfs_item_key_to_cpu(leaf, &found_key, slot); if (found_key.objectid >= key->objectid && - found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) { - struct extent_map_tree *em_tree; - struct extent_map *em; - - em_tree = &fs_info->mapping_tree; - read_lock(&em_tree->lock); - em = lookup_extent_mapping(em_tree, found_key.objectid, - found_key.offset); - read_unlock(&em_tree->lock); - if (!em) { - btrfs_err(fs_info, - "logical %llu len %llu found bg but no related chunk", - found_key.objectid, found_key.offset); - ret = -ENOENT; - } else if (em->start != found_key.objectid || - em->len != found_key.offset) { - btrfs_err(fs_info, - "block group %llu len %llu mismatch with chunk %llu len %llu", - found_key.objectid, found_key.offset, - em->start, em->len); - ret = -EUCLEAN; - } else { - read_extent_buffer(leaf, &bg, - btrfs_item_ptr_offset(leaf, slot), - sizeof(bg)); - flags = btrfs_stack_block_group_flags(&bg) & - BTRFS_BLOCK_GROUP_TYPE_MASK; - - if (flags != (em->map_lookup->type & - BTRFS_BLOCK_GROUP_TYPE_MASK)) { - btrfs_err(fs_info, -"block group %llu len %llu type flags 0x%llx mismatch with chunk type flags 0x%llx", - found_key.objectid, - found_key.offset, flags, - (BTRFS_BLOCK_GROUP_TYPE_MASK & - em->map_lookup->type)); - ret = -EUCLEAN; - } else { - ret = 0; - } - } - free_extent_map(em); - return ret; - } + found_key.type == BTRFS_BLOCK_GROUP_ITEM_KEY) + return read_bg_from_eb(fs_info, &found_key, path); + path->slots[0]++; }