From patchwork Tue Jun 2 10:05:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11583513 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 023241667 for ; Tue, 2 Jun 2020 10:06:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5B692072F for ; Tue, 2 Jun 2020 10:06:20 +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="l6uj3ZS+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726750AbgFBKGU (ORCPT ); Tue, 2 Jun 2020 06:06:20 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:65297 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726420AbgFBKGT (ORCPT ); Tue, 2 Jun 2020 06:06:19 -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=1591092378; x=1622628378; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ek/aYutujYSTB63skhSjVpG2rGoDax5o6D4SSqxGcZg=; b=l6uj3ZS+WPUxF5ROynKAY0WLjPMLF+Ur7vOsuiH3pCmpfRpnAUKcfwQc vjgS19SMYGmBSqEaZDYNMRxj08hd6xSnzuF01RedX4qlmUoJQ+TNbE7v8 tjwGbA84vJr3Vl0K+wDkxjNNZ1VN2n5vn4VUIbeqmt82WbhM1oAOhmpQv Bb6MHZKv/DKMz+dNkYJw1m6d0ntRWPfv/d5tweKk9z2NnDsk96sA0tZCJ UUgZ9xRFDr0le2tB3OoOBSZOH1ooGN4C8Yb7CjYPko1Ys7D7apwj0xolx 41jO22WmZoK/9xNz8lGAk+bZwGrqjnErfJ6noZCRUErpeIQTJEZclJUCn Q==; IronPort-SDR: a0MtIyh6ys8W25DbltVCfCIUzkTopLB6FVVbkB5AmynNKptK59g8IUNUfNQDDrVAmrQgTrxvmV VpMkK4CF7jSI644afb1dMISpXJS3UNKOxAysYOeqwfuj6rWZXS1f2asVi7mAifuoGU7KE3QYSN wVewOTeMDdy8/pkPlVfqoNgJLxYlF6401IZEv3YW1DmGSxe2GPwgEvCR9q8AXrzGMOLVvkQeFd ypM/DAK9GwJArGhPbzo91gKhWVKQHXw7Uk0DvEcPQ+Uz9etmm8JVb4YpyYt0UayDb9VgdfUtNw PhM= X-IronPort-AV: E=Sophos;i="5.73,463,1583164800"; d="scan'208";a="248104354" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 02 Jun 2020 18:06:03 +0800 IronPort-SDR: rK6zvjaBaxxGuSZIxMh2V3JGC+VfK0nQQ1GSEaT8Rw2xe2a74gVrn9B2JHdLB/yegrwwA1hPom 6KvjJ7qEfEwHvWDJ5BD9K/VFjBasHFIok= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2020 02:55:10 -0700 IronPort-SDR: qTPD+BTPKhF5mnEexZw8L6Q8jb0vyBG9f1sUzrUKA+wg3VpDaZIUUKyHQO1pix0su+nWMw0RnQ 8mmiPN1aPWgw== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 02 Jun 2020 03:06:03 -0700 From: Johannes Thumshirn To: David Sterba Cc: Nikolay Borisov , linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH v3 1/2] btrfs: get mapping tree directly from fsinfo in find_first_block_group Date: Tue, 2 Jun 2020 19:05:56 +0900 Message-Id: <20200602100557.6938-2-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602100557.6938-1-johannes.thumshirn@wdc.com> References: <20200602100557.6938-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 176e8a292fd1..e5641b6a3097 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 Tue Jun 2 10:05:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 11583515 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 96DBB175A for ; Tue, 2 Jun 2020 10:06:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7FE6B2072F for ; Tue, 2 Jun 2020 10:06:21 +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="cGn6cAhu" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726728AbgFBKGU (ORCPT ); Tue, 2 Jun 2020 06:06:20 -0400 Received: from esa1.hgst.iphmx.com ([68.232.141.245]:65304 "EHLO esa1.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726580AbgFBKGT (ORCPT ); Tue, 2 Jun 2020 06:06:19 -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=1591092378; x=1622628378; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=j+G4hck7pggCHnnCWwM2KH5bU56FwbyHNxegkWWZrIY=; b=cGn6cAhunCSqGRaPLamP4vs97tbOAJjy9DdDg0Spdl3EWGSU+z+euvgs v1EZdrImY5XnBQnyrcnIZKo+703K4kOMbW+a7XpPh6Ef+RqZLcWZE8YnW kkT2al5SRfI9LpLa4meJbwwfrAZnBx8tJ6y/fFEsb6iBsz2MAw9rGVvJA ILU/+AUvIUUwJyX+F80Atoo+lmkD0Z457H7Gt0ptZ3AUnF34acOf/z6zJ MUnLR4Keh5J4Lr3ToNC4vjzeOn177wqaaio9hclH188V1jnWWNw/mX+YV Q8XVJNg+UhFJFo3+NQGpYlKFvFluGoQ1tyrOvu0fdm8sTbOI9tME97em7 w==; IronPort-SDR: 0SV/J8Rncsi5p7McDDHmFqKqh7OQyUQV7IK2bHpD/uer/7FKarS8G8KHdSOf0Fusa3pP8j82+/ KBK7gif1wxUNmwTz6bKn+GIsr1F7MSBFVhX28+k7Skuu1B/t2eE8vn0w4inJY7ocQLjhTB7I4b 6IH+Nsw3h7obxljJXoLn4BRv91+v9w0nzH+f4EYrpfAsI8PvuTeC1l/dWQuGdx15htbkHZzSWy zpnO5+6FM8QhJGhfw8U4eNei7HMTh+HEnZ/wJU2WvpaN39b2CSQwUgK+SM570Hn98V1A38dRJ9 DIY= X-IronPort-AV: E=Sophos;i="5.73,463,1583164800"; d="scan'208";a="248104355" Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 02 Jun 2020 18:06:04 +0800 IronPort-SDR: UOnWZJ3ILiynNDEC/THbbjKIfBlFxs9PtlrIk6cC1GHACpjKsKoG05BK+MQTSDBvw/gCR6dLvF DuBbgdHUdiDPCTtNoWNBClABlHAllq7l8= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2020 02:55:11 -0700 IronPort-SDR: zOoc/F5jIX1ejIHLLTeqQiy31oKv620lJMbaBP+3+X8HVSJmOk6P7+NGLma7rderJpYtU/4LG9 wPSx3+IUwpDQ== WDCIronportException: Internal Received: from unknown (HELO redsun60.ssa.fujisawa.hgst.com) ([10.149.66.36]) by uls-op-cesaip02.wdc.com with ESMTP; 02 Jun 2020 03:06:04 -0700 From: Johannes Thumshirn To: David Sterba Cc: Nikolay Borisov , linux-btrfs@vger.kernel.org, Johannes Thumshirn Subject: [PATCH v3 2/2] btrfs: factor out reading of bg from find_frist_block_group Date: Tue, 2 Jun 2020 19:05:57 +0900 Message-Id: <20200602100557.6938-3-johannes.thumshirn@wdc.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200602100557.6938-1-johannes.thumshirn@wdc.com> References: <20200602100557.6938-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. While we're at it, we can also just return early in find_first_block_group(), if the tree slot isn't found. Signed-off-by: Johannes Thumshirn --- fs/btrfs/block-group.c | 102 ++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 46 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index e5641b6a3097..95b9b170b460 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1522,21 +1522,70 @@ 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) { 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; - u64 flags; int slot; ret = btrfs_search_slot(NULL, root, key, path, 0, 0); if (ret < 0) - goto out; + return ret; while (1) { slot = path->slots[0]; @@ -1553,49 +1602,10 @@ static int find_first_block_group(struct btrfs_fs_info *fs_info, 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); - goto out; + ret = read_bg_from_eb(fs_info, &found_key, path); + break; } + path->slots[0]++; } out: