From patchwork Sat Apr 29 20:07:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227066 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 98C0DC77B7C for ; Sat, 29 Apr 2023 20:07:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229604AbjD2UHe (ORCPT ); Sat, 29 Apr 2023 16:07:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230346AbjD2UHc (ORCPT ); Sat, 29 Apr 2023 16:07:32 -0400 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A952B1 for ; Sat, 29 Apr 2023 13:07:31 -0700 (PDT) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-54fe25c2765so20037017b3.3 for ; Sat, 29 Apr 2023 13:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798850; x=1685390850; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=a/7el9dzDebHbMEYNB5E3CBrWi/19wcM8pDAIzADdvs=; b=pIDj80Xa+pdOfLO63TibdBrbcN8NGeCfsBN1IJtUl7utgwJj4O1NahDBMp5Pfua4xU ygzXu+JLPmOA7SEG91uLSJ4ip4yX6+WxQZhektDsDXn4aneVKdfuqRYH8zWw5+mI2iif gspkKXyuMfK1Hj6gGooMfHxbSOFdjMF7Imys70HYwUD+sXoIzM95zg9mCPNlLUX94i+a GJRgS1yhk2RUAH29MGg7+NaQHcwVBD7ACHkt453t92HyF1g5t9jq9l8CEJvLNi1u82dx fjQxLnVZRDjDkO+kUqT+AdDxAWolUhnhKpAEih2t5m3L5SMg9ghFMg4pMnZ3C2VKDkzc 9ULA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798850; x=1685390850; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=a/7el9dzDebHbMEYNB5E3CBrWi/19wcM8pDAIzADdvs=; b=be6DXU/y4VM8nJr6xNdL7DGrkEqt/4vIUrx1vUmxw55KiTFPBILEk3Q8q/A+AAg0FJ kqS1fHD9u3xXt2UqqxPlDgYBJbuxQVLBhTGY61x3OOEtWavwvhLV2aOSziTEL9MWFkYW hyuUhqu3dtZFlfBuTWL7bSZ1rfajyXG4DDzRwVtc3QdsNgfXZy7zf00I//JqoEPeWVVj ImN4y3Mmqfs5XB6rdnub6dSD8Pk+KCj1ncwGcRuW2UOvyuZiheJQavOa9zaiHAZfuPe9 90OhFbBQXEmKL1eQRlOHgRttqKMFv49KNUHzckmHql+GM+X2vbEyHc1HbIWN3kz3BRgT +4hw== X-Gm-Message-State: AC+VfDyELWBHhpXVAi+0s+ueVCXVfMGbXbyWo+M7iBzMf/z5NnmGmFpM OoLYGgaLbkG47+WdyrbZJnJdC6oZ0qXsbCIuiUt6EA== X-Google-Smtp-Source: ACHHUZ5eM7u+gswCwzm19A1I41E2HtwaaszkDBOHGTa7hb4b4vr5UZSV0unUfkqBmHDUSrbyC7cnBw== X-Received: by 2002:a81:d351:0:b0:556:1cbb:fa1d with SMTP id d17-20020a81d351000000b005561cbbfa1dmr7926236ywl.38.1682798850155; Sat, 29 Apr 2023 13:07:30 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id g143-20020a815295000000b00545a08184c1sm6280764ywb.81.2023.04.29.13.07.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:29 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 01/12] btrfs: move btrfs_check_trunc_cache_free_space into block-rsv.c Date: Sat, 29 Apr 2023 16:07:10 -0400 Message-Id: <2b127b68d0e4faf2e0950c16dcaf4d0d4542a232.1682798736.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is completely related to block rsv's, move it out of the free space cache code and into block-rsv.c. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/block-rsv.c | 19 +++++++++++++++++++ fs/btrfs/block-rsv.h | 2 ++ fs/btrfs/free-space-cache.c | 19 ------------------- fs/btrfs/free-space-cache.h | 2 -- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/fs/btrfs/block-rsv.c b/fs/btrfs/block-rsv.c index 3ab707e26fa2..156ddb557004 100644 --- a/fs/btrfs/block-rsv.c +++ b/fs/btrfs/block-rsv.c @@ -540,3 +540,22 @@ struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans, return ERR_PTR(ret); } + +int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, + struct btrfs_block_rsv *rsv) +{ + u64 needed_bytes; + int ret; + + /* 1 for slack space, 1 for updating the inode */ + needed_bytes = btrfs_calc_insert_metadata_size(fs_info, 1) + + btrfs_calc_metadata_size(fs_info, 1); + + spin_lock(&rsv->lock); + if (rsv->reserved < needed_bytes) + ret = -ENOSPC; + else + ret = 0; + spin_unlock(&rsv->lock); + return ret; +} diff --git a/fs/btrfs/block-rsv.h b/fs/btrfs/block-rsv.h index 6dc781709aca..b0bd12b8652f 100644 --- a/fs/btrfs/block-rsv.h +++ b/fs/btrfs/block-rsv.h @@ -82,6 +82,8 @@ void btrfs_release_global_block_rsv(struct btrfs_fs_info *fs_info); struct btrfs_block_rsv *btrfs_use_block_rsv(struct btrfs_trans_handle *trans, struct btrfs_root *root, u32 blocksize); +int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, + struct btrfs_block_rsv *rsv); static inline void btrfs_unuse_block_rsv(struct btrfs_fs_info *fs_info, struct btrfs_block_rsv *block_rsv, u32 blocksize) diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c index d84cef89cdff..5cef89162193 100644 --- a/fs/btrfs/free-space-cache.c +++ b/fs/btrfs/free-space-cache.c @@ -292,25 +292,6 @@ int btrfs_remove_free_space_inode(struct btrfs_trans_handle *trans, return ret; } -int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, - struct btrfs_block_rsv *rsv) -{ - u64 needed_bytes; - int ret; - - /* 1 for slack space, 1 for updating the inode */ - needed_bytes = btrfs_calc_insert_metadata_size(fs_info, 1) + - btrfs_calc_metadata_size(fs_info, 1); - - spin_lock(&rsv->lock); - if (rsv->reserved < needed_bytes) - ret = -ENOSPC; - else - ret = 0; - spin_unlock(&rsv->lock); - return ret; -} - int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, struct btrfs_block_group *block_group, struct inode *vfs_inode) diff --git a/fs/btrfs/free-space-cache.h b/fs/btrfs/free-space-cache.h index a855e0483e03..33b4da3271b1 100644 --- a/fs/btrfs/free-space-cache.h +++ b/fs/btrfs/free-space-cache.h @@ -101,8 +101,6 @@ int btrfs_remove_free_space_inode(struct btrfs_trans_handle *trans, struct inode *inode, struct btrfs_block_group *block_group); -int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, - struct btrfs_block_rsv *rsv); int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, struct btrfs_block_group *block_group, struct inode *inode); From patchwork Sat Apr 29 20:07:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227067 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 043CDC77B60 for ; Sat, 29 Apr 2023 20:07:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230437AbjD2UHf (ORCPT ); Sat, 29 Apr 2023 16:07:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbjD2UHe (ORCPT ); Sat, 29 Apr 2023 16:07:34 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CDE71A8 for ; Sat, 29 Apr 2023 13:07:32 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-559f1819c5dso6576517b3.0 for ; Sat, 29 Apr 2023 13:07:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798851; x=1685390851; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=5aSmFHZ4x981jc/aRz86iFY60O70iUdZ9L2e7nsJuh4=; b=wBsLgYwur74cSZ3YPWdHPYzxtKBAHE2WnrWSLUZKmMnyORwany2ak1VK184wrhgYUP ExC5k19d1/gKIOo7mxiSoR9JEcCPA8Wmwg70G60LZz6zDlX4hVQ0oVY3SXGQkvMbTuZU HhkeQaoj0fF96qQlu0b0fbeAZ0UelDcedhU8hrMEu5Ta2V88w0WQlvKTvyy3k3WrnD3s zLteljjN1uMCF6ir7RrMJ2NY7q9stfso+iOV2wQ6wKHHY7g6jEXghJ+phgrraVpbqNHa H4Gik1dbs1clqhK/zlMHHW3/25l3qPAUPXefrLK2hO334u/WcGn9ryHaygawQdOMTKlY rayA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798851; x=1685390851; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5aSmFHZ4x981jc/aRz86iFY60O70iUdZ9L2e7nsJuh4=; b=A4lqVrUBAW5lNmqWyoKtYfpfsu5pjNGBqzJyY8NTemof39B7wzGoChb3FKuVeFLoYc 0NbE1IrqMWZbSf0EUKFUSEeAJHJEiksLq21brf4sIfFgSEdSWcblzUQ5al37D79cgQt1 LzejC5m8hlqRjLjGTZXy8YZlN3THtbOUpBDjYJIFZkujBTb+kP2eOweW0bdEHl5jRr5g jpIXel4bUTy/gSnRFJAZiyOpp27AUKKf1fZwDLxZZ4SG4tZ+MUwmJRIOMIpiZfS7ojZb Zl/BzkOspNtDg5PgPRnW5VzK7iQg71kF7IpBdAKVna3HHuKWwV7j5i5Tp7rtV4vbGYDS Fqew== X-Gm-Message-State: AC+VfDzGWWstVuWSGcWx/C4PNALFXtIokA5KtQkWNrJGNbMDCQnP1J3N tkbP4CcDTRSCKrWaVtgTxDS6U91H/uDE2B9Xr/IZuQ== X-Google-Smtp-Source: ACHHUZ631mGwnAj072QM43gFwQTojXwY/ZzczuUF90F77rP++SqIwQtEe34hKMZ3PL9kgo8BkKZW+w== X-Received: by 2002:a81:4ed6:0:b0:54f:b112:7680 with SMTP id c205-20020a814ed6000000b0054fb1127680mr7677209ywb.41.1682798851389; Sat, 29 Apr 2023 13:07:31 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id h196-20020a816ccd000000b0055a00e6542asm212995ywc.9.2023.04.29.13.07.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:31 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 02/12] btrfs: remove level argument from btrfs_set_block_flags Date: Sat, 29 Apr 2023 16:07:11 -0400 Message-Id: <64d597ef424891ea0f3af9cdbc3284cd222302eb.1682798736.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We just pass in btrfs_header_level(eb) for the level, and we're passing in the eb already, so simply get the level from the eb inside of btrfs_set_block_flags. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/ctree.c | 5 +---- fs/btrfs/extent-tree.c | 7 +++---- fs/btrfs/extent-tree.h | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 2ff2961b1183..7071f90c23e3 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -464,10 +464,7 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, return ret; } if (new_flags != 0) { - int level = btrfs_header_level(buf); - - ret = btrfs_set_disk_extent_flags(trans, buf, - new_flags, level); + ret = btrfs_set_disk_extent_flags(trans, buf, new_flags); if (ret) return ret; } diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 5cd289de4e92..df8181ccb57b 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2155,10 +2155,10 @@ int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, } int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, - struct extent_buffer *eb, u64 flags, - int level) + struct extent_buffer *eb, u64 flags) { struct btrfs_delayed_extent_op *extent_op; + int level = btrfs_header_level(eb); int ret; extent_op = btrfs_alloc_delayed_extent_op(); @@ -5102,8 +5102,7 @@ static noinline int walk_down_proc(struct btrfs_trans_handle *trans, BUG_ON(ret); /* -ENOMEM */ ret = btrfs_dec_ref(trans, root, eb, 0); BUG_ON(ret); /* -ENOMEM */ - ret = btrfs_set_disk_extent_flags(trans, eb, flag, - btrfs_header_level(eb)); + ret = btrfs_set_disk_extent_flags(trans, eb, flag); BUG_ON(ret); /* -ENOMEM */ wc->flags[level] |= flag; } diff --git a/fs/btrfs/extent-tree.h b/fs/btrfs/extent-tree.h index 0c958fc1b3b8..429d5c570061 100644 --- a/fs/btrfs/extent-tree.h +++ b/fs/btrfs/extent-tree.h @@ -141,7 +141,7 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *buf, int full_backref); int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, - struct extent_buffer *eb, u64 flags, int level); + struct extent_buffer *eb, u64 flags); int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref); int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, From patchwork Sat Apr 29 20:07:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227068 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88CFAC77B7C for ; Sat, 29 Apr 2023 20:07:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230380AbjD2UHi (ORCPT ); Sat, 29 Apr 2023 16:07:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41448 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229894AbjD2UHe (ORCPT ); Sat, 29 Apr 2023 16:07:34 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB83D129 for ; Sat, 29 Apr 2023 13:07:33 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-b9a7c1b86e8so1608697276.2 for ; Sat, 29 Apr 2023 13:07:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798853; x=1685390853; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=4EECNVhGKyEANkFkS1xoovYgmElt6xF+Gn3So5gaq1o=; b=Zp+E5k4ZsPtlzjBQKPC0W3qPLDKekYn28IZowrQW1+Xg4AqG7MAeNXnecVg7mjR4M8 3WJNMFDW2gyOPfZDfcB4Jhy8dtkXp1SSGHqnbNPnR8gKjOclvL85xi8UGCfjLlwZpSYy 4JMFeFlKp1VdhtJ87T7tscYRkvemlG83biMqA52podbRecFMtI+ET+ZmblbeD8lohtXr WVqAAdK9MH3GhArnQ/ALPVOLNWb9g1QFRQS+pVBXnIge6dlXtnpOoYVj8ZoDW4OEIQcD p+UuuuFHSJR3Yx2uD2sBDW21e7t+VHIVQAbdowhqYaARyNFak8uKSbmQYdc+EaY0QAac yPcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798853; x=1685390853; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4EECNVhGKyEANkFkS1xoovYgmElt6xF+Gn3So5gaq1o=; b=HjCfcuz6/jk44d1GspP2n82oQ+7KemUKP/JE1aIYCQMhuveYJVBL/6cBp0xKWg71JU fzmvQ+7H0iQp2jqzL/mmSbItuSQtbHoYVglmDsmFpD+ZrOtPz1i0GrTAB+V9iBVbaUSC m1VQ11LzL1nND5wo16sVciDMWeBHHJHNFJ8hByKCoF7d4BsvGtaIpSv8hgcElb7aNslS 8c3IE/b71BX19Anp95v8eCdnizvp7yGtqiPOpCG3djkg18KZhiPz3oWl2m6zFj/3rQV0 eepgSlLNIsQDoJWQ+IK8HMW1klomH0sjy2h2KGJSoqiTZc+0aW/g0XMfuD4MFj0X5V4H BvwA== X-Gm-Message-State: AC+VfDxr/Sm5jgFn2gAyxaED6wYs66VmIn/BhjABxfCIAHRWbd7pIrhr Ec8uFBcePHbMRxYjg9aUauF2N5NSpaub86fEBx/YrA== X-Google-Smtp-Source: ACHHUZ6EZ52MpFA9aFoWtozypEzZiS3mJRw5+toeL9JQAtPDO80dlIbqDes/I66R3TLM/+G2go1GKw== X-Received: by 2002:a25:c590:0:b0:b99:1e51:19e0 with SMTP id v138-20020a25c590000000b00b991e5119e0mr8540307ybe.11.1682798852556; Sat, 29 Apr 2023 13:07:32 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id h204-20020a256cd5000000b00b7b0aba5cccsm5853509ybc.22.2023.04.29.13.07.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:32 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 03/12] btrfs: simplify btrfs_check_leaf_* helpers into a single helper Date: Sat, 29 Apr 2023 16:07:12 -0400 Message-Id: <3f41d6e2a62eacc4a31966dfaa8a3e0b8f64766b.1682798736.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have two helpers for checking leaves, because we have an extra check for debugging in btrfs_mark_buffer_dirty(), and at that stage we may have item data that isn't consistent yet. However we can handle this case internally in the helper, if BTRFS_HEADER_FLAG_WRITTEN is set we know the buffer should be internally consistent, otherwise we need to skip checking the item data. Simplify this helper down a single helper and handle the item data checking logic internally to the helper. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 12 +++++------- fs/btrfs/tree-checker.c | 19 +++++++------------ fs/btrfs/tree-checker.h | 13 +------------ 3 files changed, 13 insertions(+), 31 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 59ea049fe7ee..aea1ee834a80 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -325,7 +325,7 @@ static int csum_one_extent_buffer(struct extent_buffer *eb) if (btrfs_header_level(eb)) ret = btrfs_check_node(eb); else - ret = btrfs_check_leaf_full(eb); + ret = btrfs_check_leaf(eb); if (ret < 0) goto error; @@ -582,7 +582,7 @@ static int validate_extent_buffer(struct extent_buffer *eb, * that we don't try and read the other copies of this block, just * return -EIO. */ - if (found_level == 0 && btrfs_check_leaf_full(eb)) { + if (found_level == 0 && btrfs_check_leaf(eb)) { set_bit(EXTENT_BUFFER_CORRUPT, &eb->bflags); ret = -EIO; } @@ -4687,12 +4687,10 @@ void btrfs_mark_buffer_dirty(struct extent_buffer *buf) fs_info->dirty_metadata_batch); #ifdef CONFIG_BTRFS_FS_CHECK_INTEGRITY /* - * Since btrfs_mark_buffer_dirty() can be called with item pointer set - * but item data not updated. - * So here we should only check item pointers, not item data. + * btrfs_check_leaf() won't check item data if we don't have WRITTEN + * set, so this will only validate the basic structure of the items. */ - if (btrfs_header_level(buf) == 0 && - btrfs_check_leaf_relaxed(buf)) { + if (btrfs_header_level(buf) == 0 && btrfs_check_leaf(buf)) { btrfs_print_leaf(buf); ASSERT(0); } diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index e2b54793bf0c..f153ddc60ba1 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1674,7 +1674,7 @@ static int check_leaf_item(struct extent_buffer *leaf, return ret; } -static int check_leaf(struct extent_buffer *leaf, bool check_item_data) +int btrfs_check_leaf(struct extent_buffer *leaf) { struct btrfs_fs_info *fs_info = leaf->fs_info; /* No valid key type is 0, so all key should be larger than this key */ @@ -1682,6 +1682,7 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data) struct btrfs_key key; u32 nritems = btrfs_header_nritems(leaf); int slot; + bool check_item_data = btrfs_header_flag(leaf, BTRFS_HEADER_FLAG_WRITTEN); if (unlikely(btrfs_header_level(leaf) != 0)) { generic_err(leaf, 0, @@ -1807,6 +1808,10 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data) return -EUCLEAN; } + /* + * We only want to do this if WRITTEN is set, otherwise the leaf + * may be in some intermediate state and won't appear valid. + */ if (check_item_data) { /* * Check if the item size and content meet other @@ -1824,17 +1829,7 @@ static int check_leaf(struct extent_buffer *leaf, bool check_item_data) return 0; } - -int btrfs_check_leaf_full(struct extent_buffer *leaf) -{ - return check_leaf(leaf, true); -} -ALLOW_ERROR_INJECTION(btrfs_check_leaf_full, ERRNO); - -int btrfs_check_leaf_relaxed(struct extent_buffer *leaf) -{ - return check_leaf(leaf, false); -} +ALLOW_ERROR_INJECTION(btrfs_check_leaf, ERRNO); int btrfs_check_node(struct extent_buffer *node) { diff --git a/fs/btrfs/tree-checker.h b/fs/btrfs/tree-checker.h index bfb5efa4e01f..48321e8d91bb 100644 --- a/fs/btrfs/tree-checker.h +++ b/fs/btrfs/tree-checker.h @@ -40,18 +40,7 @@ struct btrfs_tree_parent_check { u8 level; }; -/* - * Comprehensive leaf checker. - * Will check not only the item pointers, but also every possible member - * in item data. - */ -int btrfs_check_leaf_full(struct extent_buffer *leaf); - -/* - * Less strict leaf checker. - * Will only check item pointers, not reading item data. - */ -int btrfs_check_leaf_relaxed(struct extent_buffer *leaf); +int btrfs_check_leaf(struct extent_buffer *leaf); int btrfs_check_node(struct extent_buffer *node); int btrfs_check_chunk_valid(struct extent_buffer *leaf, From patchwork Sat Apr 29 20:07:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227069 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58C8CC77B7F for ; Sat, 29 Apr 2023 20:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230264AbjD2UHk (ORCPT ); Sat, 29 Apr 2023 16:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230428AbjD2UHf (ORCPT ); Sat, 29 Apr 2023 16:07:35 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAF10F7 for ; Sat, 29 Apr 2023 13:07:34 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-b9a6869dd3cso1661373276.2 for ; Sat, 29 Apr 2023 13:07:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798854; x=1685390854; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=dZ8dPfa8SZadkp5O/gW+kS1g7e8Idqo0ltCe5k3dcd4=; b=gZsN4PVFapzZ7OP6hK/oFivsveGLx2JwBMxuCKMqAsOu6LvMZJnDc7cud8JYmM6t7l fZH0rOYRwKiIgaadZaGQHBZqjTxLU0ljs8L1B+uozaT31lfObEEcsWYpZlhtrodbxB+A dEX/qd3YrA4v7gkQ1mWtm0bCokvzMlcMt+oICDtOc6cLY+ectEPUzJBbWZzA/B+pJSE9 gHgsBOC2BELVyTz8su89DPPbdHrp9mODZBHLCNkLEa/r3zSFVm2ZrO9/ABjZmoRt40KL 3vWMtVCBYmn/6GbvTwXelFDs08AzYE0ETQ1+bE9GxwvHBP7dYGMByMXaFPpqQQMNdRz6 Y5sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798854; x=1685390854; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dZ8dPfa8SZadkp5O/gW+kS1g7e8Idqo0ltCe5k3dcd4=; b=fXIPbCyM0lOz2VGcR72wNcIbtNb2iXk043P9V8ZlaDTnsBWdB/0ntkjyvL67p9LFJ3 EMw2mYgLB06M9LQG26C/hiVnuv0YnZZLeggP8vAEiKGRiqz+uhtkAGPUH7S0nyx/De9U Lgyj/7oyDEWSDPsltuB4KltblTiWIYsYgHCDs50Sq7ZFbDVOV1zftNSYmEgUJ9q15QNK 2cJsJpvaSL9wOIce88CBmG+yFQ8cMJ0u3dP4kCuKk0MMpWFc9EU1px2ud741sfKuA/KI nRQkZmrts2nZbpZsCAdf1bJA4dW7AL3mVS53bYK+bAY2fh15OdMFUDXo+Z0BOnU5t5hj Nx9w== X-Gm-Message-State: AC+VfDwiQcGlVthnmC0Vs5ZFrOuf49YX7LSfsYNUoXVTPHiNUf+ahYP1 QzU0hBe2u8ai48g2MiygIe9vDUISgLotFQ3V6wk8zw== X-Google-Smtp-Source: ACHHUZ5xXjbHTeQzlJ5wYg9K3Qt+zyJdeCRBqwwFD4fPdnrFu5fnIJyvG7Fr0+2QLCPavURLnIxfpA== X-Received: by 2002:a25:6d4:0:b0:b92:2940:ac60 with SMTP id 203-20020a2506d4000000b00b922940ac60mr7154874ybg.25.1682798853787; Sat, 29 Apr 2023 13:07:33 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d15-20020a25eb0f000000b00b8f52b11de6sm5838935ybs.42.2023.04.29.13.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:33 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 04/12] btrfs: add btrfs_tree_block_status definitions to tree-checker.h Date: Sat, 29 Apr 2023 16:07:13 -0400 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We use this in btrfs-progs to determine if we can fix different types of corruptions. We don't care about this in the kernel, however it would be good to share this code between the kernel and btrfs-progs, so add the status definitions so we can start converting the tree-checker code over to using these status flags instead of blanket returning -EUCLEAN. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/tree-checker.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fs/btrfs/tree-checker.h b/fs/btrfs/tree-checker.h index 48321e8d91bb..5e06d9ad2862 100644 --- a/fs/btrfs/tree-checker.h +++ b/fs/btrfs/tree-checker.h @@ -40,6 +40,18 @@ struct btrfs_tree_parent_check { u8 level; }; +enum btrfs_tree_block_status { + BTRFS_TREE_BLOCK_CLEAN, + BTRFS_TREE_BLOCK_INVALID_NRITEMS, + BTRFS_TREE_BLOCK_INVALID_PARENT_KEY, + BTRFS_TREE_BLOCK_BAD_KEY_ORDER, + BTRFS_TREE_BLOCK_INVALID_LEVEL, + BTRFS_TREE_BLOCK_INVALID_FREE_SPACE, + BTRFS_TREE_BLOCK_INVALID_OFFSETS, + BTRFS_TREE_BLOCK_INVALID_BLOCKPTR, + BTRFS_TREE_BLOCK_INVALID_ITEM, +}; + int btrfs_check_leaf(struct extent_buffer *leaf); int btrfs_check_node(struct extent_buffer *node); From patchwork Sat Apr 29 20:07:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227070 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53EBAC7EE24 for ; Sat, 29 Apr 2023 20:07:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230307AbjD2UHl (ORCPT ); Sat, 29 Apr 2023 16:07:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbjD2UHh (ORCPT ); Sat, 29 Apr 2023 16:07:37 -0400 Received: from mail-yw1-x112a.google.com (mail-yw1-x112a.google.com [IPv6:2607:f8b0:4864:20::112a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 426B513A for ; Sat, 29 Apr 2023 13:07:36 -0700 (PDT) Received: by mail-yw1-x112a.google.com with SMTP id 00721157ae682-559e2051d05so10841427b3.3 for ; Sat, 29 Apr 2023 13:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798855; x=1685390855; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=e797+hOoZ44p0ltOywYResV5qPx6dkIgMp8/Q0Strag=; b=jqilcQXVrz1lLNtDXuCsF8dhQX23aP6Mg08a7cuRLVxzzXQZQSbW5vjf0qSmySDVEe R3KqizyiYGkzFIa9lck3c5By9C+BGMbHqqyqk5bSfsdkJd+GvfsBEMzbSNZMNf4yND4+ 8JZ+p2gtOlTjWTnoV6WruRpC2g2IBWFnYJOYJ9qWHU4wUlkw3n6zTYvQw+4LJFylfkOT /Id/nQUyjnSQYJpfqJM0M4pblCJZABMJP+L+/nD0EEXzVqLVo421VEg04PpDv+Hpb6iq X1TLTLxLt2cJn4VBPneBvqoHOJH18lTVKNVYERSyjg4Yuq7x03U6Wn83blzRe7Hj2+NQ kNTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798855; x=1685390855; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e797+hOoZ44p0ltOywYResV5qPx6dkIgMp8/Q0Strag=; b=OxhawgzLjEbwdH547Fv/oNtKpUwmZXlzFX9IH8flBc6Dqqn9/3qf+/pgAhDwqPp92x Wb9JPKocDsIsUYFqOAP+SytXYoccomifc7TbpACP905OFYVq5zczvHvYYD4t85FME6lU k74fNAFx8QdhCIrPWMHtl72afc/j79YQhoVJ5eBx2MuLviR9efJFxmwDj5G+80+J6Nl1 EDxNm2cEQDpa/0sTQyjzOq3R2Ns1naC7aEclqtCAA7s4R1R6vRbhUHkTKndlyxTOcAs2 kpnwl92cBUjx+CJXPKgvx+gbs3RkR5esXnC2CO9VuhKbyLA6K6mhvJbfAT1vyl7RKWlX UqCQ== X-Gm-Message-State: AC+VfDylwq3H4+sHO/nuXHTyZrFT320DiPz4kyqjWU59IS9zhlzbq58s oigm+OItOFhcE/Dcr38kp3yc7UaKZfHE15n/XVjF7w== X-Google-Smtp-Source: ACHHUZ738KNUfzLanyW7f6LORHrjxjNsNppIx6L4eqs41593y4ERiPqwJ6VvZ+VBm8SGqYuNjZfUcA== X-Received: by 2002:a81:c30d:0:b0:55a:7c7:7be1 with SMTP id r13-20020a81c30d000000b0055a07c77be1mr905762ywk.22.1682798855166; Sat, 29 Apr 2023 13:07:35 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id m66-20020a0de345000000b0054bfc94a10dsm6295708ywe.47.2023.04.29.13.07.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:34 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 05/12] btrfs: use btrfs_tree_block_status for leaf item errors Date: Sat, 29 Apr 2023 16:07:14 -0400 Message-Id: <6536e8136f3da8b002f00151c0a12822792e7d48.1682798736.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We have a variety of item specific errors that can occur. For now simply put these under the umbrella of BTRFS_TREE_BLOCK_INVALID_ITEM, this can be fleshed out as we need in the future. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/tree-checker.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index f153ddc60ba1..bfc1f65726f6 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1620,9 +1620,10 @@ static int check_inode_ref(struct extent_buffer *leaf, /* * Common point to switch the item-specific validation. */ -static int check_leaf_item(struct extent_buffer *leaf, - struct btrfs_key *key, int slot, - struct btrfs_key *prev_key) +static enum btrfs_tree_block_status check_leaf_item(struct extent_buffer *leaf, + struct btrfs_key *key, + int slot, + struct btrfs_key *prev_key) { int ret = 0; struct btrfs_chunk *chunk; @@ -1671,7 +1672,10 @@ static int check_leaf_item(struct extent_buffer *leaf, ret = check_extent_data_ref(leaf, key, slot); break; } - return ret; + + if (ret) + return BTRFS_TREE_BLOCK_INVALID_ITEM; + return BTRFS_TREE_BLOCK_CLEAN; } int btrfs_check_leaf(struct extent_buffer *leaf) @@ -1752,7 +1756,6 @@ int btrfs_check_leaf(struct extent_buffer *leaf) for (slot = 0; slot < nritems; slot++) { u32 item_end_expected; u64 item_data_end; - int ret; btrfs_item_key_to_cpu(leaf, &key, slot); @@ -1813,13 +1816,15 @@ int btrfs_check_leaf(struct extent_buffer *leaf) * may be in some intermediate state and won't appear valid. */ if (check_item_data) { + enum btrfs_tree_block_status ret; + /* * Check if the item size and content meet other * criteria */ ret = check_leaf_item(leaf, &key, slot, &prev_key); - if (unlikely(ret < 0)) - return ret; + if (unlikely(ret != BTRFS_TREE_BLOCK_CLEAN)) + return -EUCLEAN; } prev_key.objectid = key.objectid; From patchwork Sat Apr 29 20:07:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227071 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7128BC77B60 for ; Sat, 29 Apr 2023 20:07:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229534AbjD2UHp (ORCPT ); Sat, 29 Apr 2023 16:07:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbjD2UHj (ORCPT ); Sat, 29 Apr 2023 16:07:39 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6C53132 for ; Sat, 29 Apr 2023 13:07:37 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-b9a6eec8611so14214025276.0 for ; Sat, 29 Apr 2023 13:07:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798856; x=1685390856; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=PevR7miQK5UnzH5jlnRw4m1LP/X4BZ8smpVG6zFEeVI=; b=397rNiTH/OlCTQH4NijHcxAUML52NxhGavrihUfslpgPYJ/EeXZrDmb1VHIf+egzgg VTcYuZNVFWiwv6+VCzMW9Fe1avlLCTWIO9lysqm86ly6vTB3eaNlDqwToHIzL0IO+zga UHxSWKqg595MougFRgIEofxtEKnfh0SiqWz0gtbRH45x0y7Hi1/NyzZhEz1vNduO8D7X 78pw9oiT1L4lbsGhggA6UkknsbOgd9VRMCiEOpOIDiVrYqqjZihRfORcJVeLTo1GKzlB Sho/l/AsewPnC4KzEu6TKXYTWwoHx9FXlgIDZAtJeUYkwM4+NDNBFfZzoo/brMD6nqij F70Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798856; x=1685390856; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PevR7miQK5UnzH5jlnRw4m1LP/X4BZ8smpVG6zFEeVI=; b=U2zxpg33wPe3eki8rbq/hdtRXpU0UWO5tW1NlU9Lqi9C7J0FQop+7OOvAQKSP2YLJP P0AtffEIjFdtepTMy52Aat9C9uAvRJkz5W5UJ775Hx2M/H6j3368+JvkKdXczV3IdWUd GYBGnBtAvyst0NDpn6dCRubIT1RK6yy81eGSnmkWMACNGRXz46wBQ/WluMfZu1hSxKKj 7Q046D+S4Ukv12JT0eqRu14aRcQAeq2ldRZ34oTN5fZABC+TqeNAWezCY2f8Tb8ljUXA uPLql2Ym62emwDc1vXvMWGXUHTw04J6jHB1USwRffDAStmBBLsuSZJ0vpkx05vPolbUT mcvA== X-Gm-Message-State: AC+VfDwOhxL36nMsOKmKvwfSH/NeBLhCJCyJJdKJZwnyXhXv1fpnSZGD Y4xqsW9Fr6Iuh7r8LhbRe86+tIt6KeIR3GQshuea+g== X-Google-Smtp-Source: ACHHUZ5cXdYAs0cPIvzYhs4oOIaUUfQGK8gc63eDg7eX6GBMfg6lxWIKGIF5oOuka+iU7od9C0x7Mg== X-Received: by 2002:a25:e64c:0:b0:b9a:6507:978 with SMTP id d73-20020a25e64c000000b00b9a65070978mr9206111ybh.12.1682798856469; Sat, 29 Apr 2023 13:07:36 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id 190-20020a250ac7000000b00b7767ca749esm5874139ybk.59.2023.04.29.13.07.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:36 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 06/12] btrfs: extend btrfs_leaf_check to return btrfs_tree_block_status Date: Sat, 29 Apr 2023 16:07:15 -0400 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Instead of blanket returning -EUCLEAN for all the failures in btrfs_check_leaf, use btrfs_tree_block_status and return the appropriate status for each failure. Rename the helper to __btrfs_check_leaf and then make a wrapper of btrfs_check_leaf that will return -EUCLEAN to non-clean error codes. This will allow us to have the __btrfs_check_leaf variant in btrfs-progs while keeping the behavior in the kernel consistent. Signed-off-by: Josef Bacik --- fs/btrfs/tree-checker.c | 36 +++++++++++++++++++++++------------- fs/btrfs/tree-checker.h | 7 +++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index bfc1f65726f6..2c330e9d123a 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1678,7 +1678,7 @@ static enum btrfs_tree_block_status check_leaf_item(struct extent_buffer *leaf, return BTRFS_TREE_BLOCK_CLEAN; } -int btrfs_check_leaf(struct extent_buffer *leaf) +enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf) { struct btrfs_fs_info *fs_info = leaf->fs_info; /* No valid key type is 0, so all key should be larger than this key */ @@ -1692,7 +1692,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf) generic_err(leaf, 0, "invalid level for leaf, have %d expect 0", btrfs_header_level(leaf)); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_INVALID_LEVEL; } /* @@ -1715,32 +1715,32 @@ int btrfs_check_leaf(struct extent_buffer *leaf) generic_err(leaf, 0, "invalid root, root %llu must never be empty", owner); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_INVALID_NRITEMS; } /* Unknown tree */ if (unlikely(owner == 0)) { generic_err(leaf, 0, "invalid owner, root 0 is not defined"); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_INVALID_OWNER; } /* EXTENT_TREE_V2 can have empty extent trees. */ if (btrfs_fs_incompat(fs_info, EXTENT_TREE_V2)) - return 0; + return BTRFS_TREE_BLOCK_CLEAN; if (unlikely(owner == BTRFS_EXTENT_TREE_OBJECTID)) { generic_err(leaf, 0, "invalid root, root %llu must never be empty", owner); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_INVALID_NRITEMS; } - return 0; + return BTRFS_TREE_BLOCK_CLEAN; } if (unlikely(nritems == 0)) - return 0; + return BTRFS_TREE_BLOCK_CLEAN; /* * Check the following things to make sure this is a good leaf, and @@ -1766,7 +1766,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf) prev_key.objectid, prev_key.type, prev_key.offset, key.objectid, key.type, key.offset); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_BAD_KEY_ORDER; } item_data_end = (u64)btrfs_item_offset(leaf, slot) + @@ -1785,7 +1785,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf) generic_err(leaf, slot, "unexpected item end, have %llu expect %u", item_data_end, item_end_expected); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_INVALID_OFFSETS; } /* @@ -1797,7 +1797,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf) generic_err(leaf, slot, "slot end outside of leaf, have %llu expect range [0, %u]", item_data_end, BTRFS_LEAF_DATA_SIZE(fs_info)); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_INVALID_OFFSETS; } /* Also check if the item pointer overlaps with btrfs item. */ @@ -1808,7 +1808,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf) btrfs_item_nr_offset(leaf, slot) + sizeof(struct btrfs_item), btrfs_item_ptr_offset(leaf, slot)); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_INVALID_OFFSETS; } /* @@ -1824,7 +1824,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf) */ ret = check_leaf_item(leaf, &key, slot, &prev_key); if (unlikely(ret != BTRFS_TREE_BLOCK_CLEAN)) - return -EUCLEAN; + return ret; } prev_key.objectid = key.objectid; @@ -1832,6 +1832,16 @@ int btrfs_check_leaf(struct extent_buffer *leaf) prev_key.offset = key.offset; } + return BTRFS_TREE_BLOCK_CLEAN; +} + +int btrfs_check_leaf(struct extent_buffer *leaf) +{ + enum btrfs_tree_block_status ret; + + ret = __btrfs_check_leaf(leaf); + if (unlikely(ret != BTRFS_TREE_BLOCK_CLEAN)) + return -EUCLEAN; return 0; } ALLOW_ERROR_INJECTION(btrfs_check_leaf, ERRNO); diff --git a/fs/btrfs/tree-checker.h b/fs/btrfs/tree-checker.h index 5e06d9ad2862..3b8de6d36141 100644 --- a/fs/btrfs/tree-checker.h +++ b/fs/btrfs/tree-checker.h @@ -50,8 +50,15 @@ enum btrfs_tree_block_status { BTRFS_TREE_BLOCK_INVALID_OFFSETS, BTRFS_TREE_BLOCK_INVALID_BLOCKPTR, BTRFS_TREE_BLOCK_INVALID_ITEM, + BTRFS_TREE_BLOCK_INVALID_OWNER, }; +/* + * Exported simply for btrfs-progs which wants to have the + * btrfs_tree_block_status return codes. + */ +enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf); + int btrfs_check_leaf(struct extent_buffer *leaf); int btrfs_check_node(struct extent_buffer *node); From patchwork Sat Apr 29 20:07:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9AEB7C77B7C for ; Sat, 29 Apr 2023 20:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229907AbjD2UHr (ORCPT ); Sat, 29 Apr 2023 16:07:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41610 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230118AbjD2UHk (ORCPT ); Sat, 29 Apr 2023 16:07:40 -0400 Received: from mail-yw1-x112e.google.com (mail-yw1-x112e.google.com [IPv6:2607:f8b0:4864:20::112e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14EFD2710 for ; Sat, 29 Apr 2023 13:07:38 -0700 (PDT) Received: by mail-yw1-x112e.google.com with SMTP id 00721157ae682-552a6357d02so15983277b3.3 for ; Sat, 29 Apr 2023 13:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798858; x=1685390858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=ZPDkrsOcjeDNfOdNUYQnZkwQqkT1OBLvizahJeZC/q8=; b=4XJFfgGa2T5lcUEGLqvfeZ0CIRLLi8XxspLomxOG0F4FUxTdg5zm1utYiqr4aYK5bw btmr1gMA8zTBG8xZjjR1yU6pxgo9oWbkDgJyNx39ooc65axZH9LQa0tHFFZRtcKhmtVZ TF0KARWDTwUrMPN6CowrBkwNN3MY911Ug2K7DmG3ZpNIVSUnIB6tucb5plDSroHSqAep B3XlsAadNugLFiqWbhM/N6H1SyzCmhL3G6atjVs5LyFsYnjou4YE3InpXR7YD6U02Jct ytefOod24P0KDNVLhtKzKV+QjUmtz4EGL/SX48aL55yy5Rf/3RcpZHuybPYqlHJN/ISG ZIOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798858; x=1685390858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZPDkrsOcjeDNfOdNUYQnZkwQqkT1OBLvizahJeZC/q8=; b=h7N6IO0RbtLL0Yc2+QQC+aeaPCJjyHyuF3WJVQFXG/yatMl8VL8UqUKuVUMdtPrsUG ZQwi9Qtrq0S3I9aEkHkK5WPbR0WKI8NFAcJmIXis9J1O6YaIZWIhJU9sX7CGKnvS3Koh uYShvGtprTJVNNxVAv8/O1U0cYk22LxkecJ4Mgrge3lgpcCfIeFmU553WnA22flmvX8v 0eqJXAlA3NGWnZYbRnoRXfKWUWKe2Zfo4NQ5ossbEP4Ky+/gMmLyEZnve1XfN9h3QQHp XVVg2qXfzFnSs2AorGhyLd689PxBKIBaKTCwtSxQFK9ASBlNNW16jRcRkzxe7Fnxsf41 ZLtA== X-Gm-Message-State: AC+VfDz/T+VpvtD/xbcU8+Nohyn2DfI+SBTEWShMugO5NGPzWkwH8y9s kLguwUZBwa7gpZry4YoRP4vcxcxLxaAVvonLqUfStA== X-Google-Smtp-Source: ACHHUZ52bNvYVGxozYcq0u2e3GvuRgBgnzSlmTw7B1mom4UKWD6SF00Aa413g6bJxYFNxeHI/dhziQ== X-Received: by 2002:a0d:d4c8:0:b0:559:f50f:64f6 with SMTP id w191-20020a0dd4c8000000b00559f50f64f6mr1739762ywd.7.1682798857738; Sat, 29 Apr 2023 13:07:37 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id d144-20020a814f96000000b00559f1cb8444sm327219ywb.70.2023.04.29.13.07.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:37 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 07/12] btrfs: add __btrfs_check_node helper Date: Sat, 29 Apr 2023 16:07:16 -0400 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This helper returns a btrfs_tree_block_status for the various errors, and then btrfs_check_node() will return -EUCLEAN if it gets anything other than BTRFS_TREE_BLOCK_CLEAN which will be used by the kernel. In the future btrfs-progs will use this helper instead. Signed-off-by: Josef Bacik --- fs/btrfs/tree-checker.c | 29 +++++++++++++++++------------ fs/btrfs/tree-checker.h | 1 + 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index 2c330e9d123a..eb9ba48d92aa 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1846,7 +1846,7 @@ int btrfs_check_leaf(struct extent_buffer *leaf) } ALLOW_ERROR_INJECTION(btrfs_check_leaf, ERRNO); -int btrfs_check_node(struct extent_buffer *node) +enum btrfs_tree_block_status __btrfs_check_node(struct extent_buffer *node) { struct btrfs_fs_info *fs_info = node->fs_info; unsigned long nr = btrfs_header_nritems(node); @@ -1854,13 +1854,12 @@ int btrfs_check_node(struct extent_buffer *node) int slot; int level = btrfs_header_level(node); u64 bytenr; - int ret = 0; if (unlikely(level <= 0 || level >= BTRFS_MAX_LEVEL)) { generic_err(node, 0, "invalid level for node, have %d expect [1, %d]", level, BTRFS_MAX_LEVEL - 1); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_INVALID_LEVEL; } if (unlikely(nr == 0 || nr > BTRFS_NODEPTRS_PER_BLOCK(fs_info))) { btrfs_crit(fs_info, @@ -1868,7 +1867,7 @@ int btrfs_check_node(struct extent_buffer *node) btrfs_header_owner(node), node->start, nr == 0 ? "small" : "large", nr, BTRFS_NODEPTRS_PER_BLOCK(fs_info)); - return -EUCLEAN; + return BTRFS_TREE_BLOCK_INVALID_NRITEMS; } for (slot = 0; slot < nr - 1; slot++) { @@ -1879,15 +1878,13 @@ int btrfs_check_node(struct extent_buffer *node) if (unlikely(!bytenr)) { generic_err(node, slot, "invalid NULL node pointer"); - ret = -EUCLEAN; - goto out; + return BTRFS_TREE_BLOCK_INVALID_BLOCKPTR; } if (unlikely(!IS_ALIGNED(bytenr, fs_info->sectorsize))) { generic_err(node, slot, "unaligned pointer, have %llu should be aligned to %u", bytenr, fs_info->sectorsize); - ret = -EUCLEAN; - goto out; + return BTRFS_TREE_BLOCK_INVALID_BLOCKPTR; } if (unlikely(btrfs_comp_cpu_keys(&key, &next_key) >= 0)) { @@ -1896,12 +1893,20 @@ int btrfs_check_node(struct extent_buffer *node) key.objectid, key.type, key.offset, next_key.objectid, next_key.type, next_key.offset); - ret = -EUCLEAN; - goto out; + return BTRFS_TREE_BLOCK_BAD_KEY_ORDER; } } -out: - return ret; + return BTRFS_TREE_BLOCK_CLEAN; +} + +int btrfs_check_node(struct extent_buffer *node) +{ + enum btrfs_tree_block_status ret; + + ret = __btrfs_check_node(node); + if (unlikely(ret != BTRFS_TREE_BLOCK_CLEAN)) + return -EUCLEAN; + return 0; } ALLOW_ERROR_INJECTION(btrfs_check_node, ERRNO); diff --git a/fs/btrfs/tree-checker.h b/fs/btrfs/tree-checker.h index 3b8de6d36141..c0861ce1429b 100644 --- a/fs/btrfs/tree-checker.h +++ b/fs/btrfs/tree-checker.h @@ -58,6 +58,7 @@ enum btrfs_tree_block_status { * btrfs_tree_block_status return codes. */ enum btrfs_tree_block_status __btrfs_check_leaf(struct extent_buffer *leaf); +enum btrfs_tree_block_status __btrfs_check_node(struct extent_buffer *node); int btrfs_check_leaf(struct extent_buffer *leaf); int btrfs_check_node(struct extent_buffer *node); From patchwork Sat Apr 29 20:07:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227073 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B9A2EC77B7F for ; Sat, 29 Apr 2023 20:07:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229996AbjD2UHs (ORCPT ); Sat, 29 Apr 2023 16:07:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229788AbjD2UHn (ORCPT ); Sat, 29 Apr 2023 16:07:43 -0400 Received: from mail-yb1-xb30.google.com (mail-yb1-xb30.google.com [IPv6:2607:f8b0:4864:20::b30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFADA210A for ; Sat, 29 Apr 2023 13:07:39 -0700 (PDT) Received: by mail-yb1-xb30.google.com with SMTP id 3f1490d57ef6-b9a6eec8611so14214114276.0 for ; Sat, 29 Apr 2023 13:07:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798859; x=1685390859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=uC3+bynHUqSF92rBvWCVvjTD5QoqGnqyMiaUmIEAOug=; b=YzzzrC/EGgFJBgFAi01SarUTXBtXcW2ESTp3hp5V0Y3qWMgKstyxql1Fl7ksSd76gD ElE4pxnqWkuL0lgoeDy8re1zHovdvq4Vg3iIsp0z8bCP1qDOLP9AZO8W6KTTn3/E/zgu KLATYxjTIcRim5P0f0KzKeR9uuuysSml66I4DaH4G6IvN+F1hTN2KCQtQyOvNBdMh2Qv i4s8bCULSEKko1F/EBKeYBuBvWCUzqwetz+mRavyfaHXOxTGXoLBZ10dkmX1u89GSWQC 0u+sQ6wAnt+0793e+ZxXCcVZdDH4jLvM+BQCYCuveM2lv/bIDc4lWBUaiCqYBxwMrD3b LGsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798859; x=1685390859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uC3+bynHUqSF92rBvWCVvjTD5QoqGnqyMiaUmIEAOug=; b=Z1CJ7c12L4KZPnztIYLwz/fZQdK7qZf24OpB0F1QwOpKr7wm/K28HyWhj+yFIb0eh8 MzHoQrVKqcpyJYcvEQKPV1R/iAP1ftsoFCCAtHYo3Z4Zn3ZwEFa64IdxM7EphYX6GXWT djpM4pQ3EWPfdlwXBoQirOcxBz9hwACbrbzvUN18MXxil2HLtkLJlMHcV6E+R1UboEDB BqEkgHuFJDmiNHdQzdF7PZDBx+Fck79G0ojpJBes2EDYulGq2f2DDtQJaDejjqDQ3bFP apaW5CRMz6coqX9SU2xNRaniRdI9nVXuAElH+Midva67P+H+vUA/hLN9hTTCfVXiUGCR dnGw== X-Gm-Message-State: AC+VfDyNA8efprO30HEYlfsO9YZrvluPRXSIF+H/wXrSXzc36MQ99FWx RQ9qaspq3HAnEJX2wI661yB/BHUpqtbRci42ckqF4Q== X-Google-Smtp-Source: ACHHUZ7/DO0NvJMy3IJi5fydtSmgc+zzhtCSVk4836OHks3Yn3fR47TrmovY5bVauGDy9HabbdfV7w== X-Received: by 2002:a81:4bc9:0:b0:559:ed24:6bd9 with SMTP id y192-20020a814bc9000000b00559ed246bd9mr2238117ywa.1.1682798859034; Sat, 29 Apr 2023 13:07:39 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id j65-20020a816e44000000b00559be540b56sm1111219ywc.134.2023.04.29.13.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:38 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 08/12] btrfs: move btrfs_verify_level_key into tree-checker.c Date: Sat, 29 Apr 2023 16:07:17 -0400 Message-Id: X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is more a buffer validation helper, move it into the tree-checker files where it makes more sense. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/disk-io.c | 58 ----------------------------------------- fs/btrfs/disk-io.h | 2 -- fs/btrfs/tree-checker.c | 58 +++++++++++++++++++++++++++++++++++++++++ fs/btrfs/tree-checker.h | 2 ++ 4 files changed, 60 insertions(+), 60 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index aea1ee834a80..cd0e8f394420 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -180,64 +180,6 @@ int btrfs_check_super_csum(struct btrfs_fs_info *fs_info, return 0; } -int btrfs_verify_level_key(struct extent_buffer *eb, int level, - struct btrfs_key *first_key, u64 parent_transid) -{ - struct btrfs_fs_info *fs_info = eb->fs_info; - int found_level; - struct btrfs_key found_key; - int ret; - - found_level = btrfs_header_level(eb); - if (found_level != level) { - WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG), - KERN_ERR "BTRFS: tree level check failed\n"); - btrfs_err(fs_info, -"tree level mismatch detected, bytenr=%llu level expected=%u has=%u", - eb->start, level, found_level); - return -EIO; - } - - if (!first_key) - return 0; - - /* - * For live tree block (new tree blocks in current transaction), - * we need proper lock context to avoid race, which is impossible here. - * So we only checks tree blocks which is read from disk, whose - * generation <= fs_info->last_trans_committed. - */ - if (btrfs_header_generation(eb) > fs_info->last_trans_committed) - return 0; - - /* We have @first_key, so this @eb must have at least one item */ - if (btrfs_header_nritems(eb) == 0) { - btrfs_err(fs_info, - "invalid tree nritems, bytenr=%llu nritems=0 expect >0", - eb->start); - WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG)); - return -EUCLEAN; - } - - if (found_level) - btrfs_node_key_to_cpu(eb, &found_key, 0); - else - btrfs_item_key_to_cpu(eb, &found_key, 0); - ret = btrfs_comp_cpu_keys(first_key, &found_key); - - if (ret) { - WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG), - KERN_ERR "BTRFS: tree first key check failed\n"); - btrfs_err(fs_info, -"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)", - eb->start, parent_transid, first_key->objectid, - first_key->type, first_key->offset, - found_key.objectid, found_key.type, - found_key.offset); - } - return ret; -} - static int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num) { diff --git a/fs/btrfs/disk-io.h b/fs/btrfs/disk-io.h index 4d5772330110..a26ab3cbb449 100644 --- a/fs/btrfs/disk-io.h +++ b/fs/btrfs/disk-io.h @@ -31,8 +31,6 @@ struct btrfs_tree_parent_check; void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info); void btrfs_init_fs_info(struct btrfs_fs_info *fs_info); -int btrfs_verify_level_key(struct extent_buffer *eb, int level, - struct btrfs_key *first_key, u64 parent_transid); struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, struct btrfs_tree_parent_check *check); struct extent_buffer *btrfs_find_create_tree_block( diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index eb9ba48d92aa..a1038156d57d 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -1964,3 +1964,61 @@ int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner) } return 0; } + +int btrfs_verify_level_key(struct extent_buffer *eb, int level, + struct btrfs_key *first_key, u64 parent_transid) +{ + struct btrfs_fs_info *fs_info = eb->fs_info; + int found_level; + struct btrfs_key found_key; + int ret; + + found_level = btrfs_header_level(eb); + if (found_level != level) { + WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG), + KERN_ERR "BTRFS: tree level check failed\n"); + btrfs_err(fs_info, +"tree level mismatch detected, bytenr=%llu level expected=%u has=%u", + eb->start, level, found_level); + return -EIO; + } + + if (!first_key) + return 0; + + /* + * For live tree block (new tree blocks in current transaction), + * we need proper lock context to avoid race, which is impossible here. + * So we only checks tree blocks which is read from disk, whose + * generation <= fs_info->last_trans_committed. + */ + if (btrfs_header_generation(eb) > fs_info->last_trans_committed) + return 0; + + /* We have @first_key, so this @eb must have at least one item */ + if (btrfs_header_nritems(eb) == 0) { + btrfs_err(fs_info, + "invalid tree nritems, bytenr=%llu nritems=0 expect >0", + eb->start); + WARN_ON(IS_ENABLED(CONFIG_BTRFS_DEBUG)); + return -EUCLEAN; + } + + if (found_level) + btrfs_node_key_to_cpu(eb, &found_key, 0); + else + btrfs_item_key_to_cpu(eb, &found_key, 0); + ret = btrfs_comp_cpu_keys(first_key, &found_key); + + if (ret) { + WARN(IS_ENABLED(CONFIG_BTRFS_DEBUG), + KERN_ERR "BTRFS: tree first key check failed\n"); + btrfs_err(fs_info, +"tree first key mismatch detected, bytenr=%llu parent_transid=%llu key expected=(%llu,%u,%llu) has=(%llu,%u,%llu)", + eb->start, parent_transid, first_key->objectid, + first_key->type, first_key->offset, + found_key.objectid, found_key.type, + found_key.offset); + } + return ret; +} diff --git a/fs/btrfs/tree-checker.h b/fs/btrfs/tree-checker.h index c0861ce1429b..3c2a02a72f64 100644 --- a/fs/btrfs/tree-checker.h +++ b/fs/btrfs/tree-checker.h @@ -66,5 +66,7 @@ int btrfs_check_node(struct extent_buffer *node); int btrfs_check_chunk_valid(struct extent_buffer *leaf, struct btrfs_chunk *chunk, u64 logical); int btrfs_check_eb_owner(const struct extent_buffer *eb, u64 root_owner); +int btrfs_verify_level_key(struct extent_buffer *eb, int level, + struct btrfs_key *first_key, u64 parent_transid); #endif From patchwork Sat Apr 29 20:07:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227074 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A81DEC77B7C for ; Sat, 29 Apr 2023 20:07:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229578AbjD2UHu (ORCPT ); Sat, 29 Apr 2023 16:07:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbjD2UHp (ORCPT ); Sat, 29 Apr 2023 16:07:45 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9938126AD for ; Sat, 29 Apr 2023 13:07:41 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id 3f1490d57ef6-b9a6f17f2b6so14180033276.1 for ; Sat, 29 Apr 2023 13:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798860; x=1685390860; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Ifif1Z1yD2qw5ylIpKzZ/EvAQTj9EHFzqF9TLYsPJVs=; b=KDraS2za8zmEvIxrIsiB6fZ07wPBC9cx8Rt6UVwiwZDtF7+R6d4TXCmbRjafMHmMoa xyE3P2ptzkjkQttE6aNzRKeL2TbG+O7woXaEGRF2jL5373aOU0YQte0SJW6SiYthhN3j x//yvLorJp1d3Y6U10X3WOzeWk9dkWjkRDqfVAdKOY4EjYPjvE+CKzIrvdLPZdCaYIBw vFJn6eDXCOs4rpPL1zdxcsr89TUNBcKCFbpr9m9Y64Kd+1aZp3NFlSIhai0bf7reGNs4 +HExKgJzIZNjX5hnRpgzVI6MrBDyOaPO7RajjxTweBnZ8Vok4vE/JZLlDlI/PqNr1roU 3n4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798860; x=1685390860; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ifif1Z1yD2qw5ylIpKzZ/EvAQTj9EHFzqF9TLYsPJVs=; b=bJYjSg6nqVEH0YiPMCN+WtaqbrsNWoHHS/j3guI0FHYTkydNgAB+45S5ujDq5s/hgA uuuV+BI7UxcC51Oc3i8SqK4sFdQCM7zuadOcOOKm6seE5gOCeFY5GZ0zRnJolPuQiUvd B9BDjZA1cSqfi72K2Pcymp47/nbAJOWd9JE1UVfNbmBTeBsEJ19iY/4jGs+L7mN61aMl TrbT/cHoOR9FbCv0oHS4T9t6m5Wu7KJS+TdjY0CU/0PDPRSVQnfdddntjaphJz4xEmJU hCudUSszjuQEJpAsHmgnnXvYoq4LNj/BIKA296olofzt9hE59QlOm/224kr/2Eoml1WE ar3w== X-Gm-Message-State: AC+VfDxvkiXh48eu8jc+6TusDgymvTZ9j5S0Gsjo1d5KQzzCCntcp6ao tA6+p4WYtdz6flfdWmejea49mD9mgdbtZrrXcraRPQ== X-Google-Smtp-Source: ACHHUZ5Nao0BtfPeDT0617lCmUnTYDt1dN2VeRAOMOli4zBj9ua+ydvxr5Yi19eCWduahrN/Fzb0hQ== X-Received: by 2002:a0d:cb41:0:b0:550:4d9f:3a3a with SMTP id n62-20020a0dcb41000000b005504d9f3a3amr8135972ywd.19.1682798860268; Sat, 29 Apr 2023 13:07:40 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id i205-20020a0ddfd6000000b00545a08184a9sm6316974ywe.57.2023.04.29.13.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:39 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 09/12] btrfs: move split_flags/combine_flags helpers to inode-item.h Date: Sat, 29 Apr 2023 16:07:18 -0400 Message-Id: <5deb90b337e17e2236dc2349fdbf4fb216146551.1682798736.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org These are more related to the inode item flags on disk than the in-memory btrfs_inode, move the helpers to inode-item.h. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/btrfs_inode.h | 16 ---------------- fs/btrfs/inode-item.h | 16 ++++++++++++++++ fs/btrfs/tree-checker.c | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h index ec2ae4406c16..9e8038273cdc 100644 --- a/fs/btrfs/btrfs_inode.h +++ b/fs/btrfs/btrfs_inode.h @@ -407,22 +407,6 @@ static inline bool btrfs_inode_can_compress(const struct btrfs_inode *inode) return true; } -/* - * btrfs_inode_item stores flags in a u64, btrfs_inode stores them in two - * separate u32s. These two functions convert between the two representations. - */ -static inline u64 btrfs_inode_combine_flags(u32 flags, u32 ro_flags) -{ - return (flags | ((u64)ro_flags << 32)); -} - -static inline void btrfs_inode_split_flags(u64 inode_item_flags, - u32 *flags, u32 *ro_flags) -{ - *flags = (u32)inode_item_flags; - *ro_flags = (u32)(inode_item_flags >> 32); -} - /* Array of bytes with variable length, hexadecimal format 0x1234 */ #define CSUM_FMT "0x%*phN" #define CSUM_FMT_VALUE(size, bytes) size, bytes diff --git a/fs/btrfs/inode-item.h b/fs/btrfs/inode-item.h index b80aeb715701..ede43b6c6559 100644 --- a/fs/btrfs/inode-item.h +++ b/fs/btrfs/inode-item.h @@ -60,6 +60,22 @@ struct btrfs_truncate_control { bool clear_extent_range; }; +/* + * btrfs_inode_item stores flags in a u64, btrfs_inode stores them in two + * separate u32s. These two functions convert between the two representations. + */ +static inline u64 btrfs_inode_combine_flags(u32 flags, u32 ro_flags) +{ + return (flags | ((u64)ro_flags << 32)); +} + +static inline void btrfs_inode_split_flags(u64 inode_item_flags, + u32 *flags, u32 *ro_flags) +{ + *flags = (u32)inode_item_flags; + *ro_flags = (u32)(inode_item_flags >> 32); +} + int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct btrfs_truncate_control *control); diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c index a1038156d57d..d38f54efd443 100644 --- a/fs/btrfs/tree-checker.c +++ b/fs/btrfs/tree-checker.c @@ -25,10 +25,10 @@ #include "compression.h" #include "volumes.h" #include "misc.h" -#include "btrfs_inode.h" #include "fs.h" #include "accessors.h" #include "file-item.h" +#include "inode-item.h" /* * Error message should follow the following format: From patchwork Sat Apr 29 20:07:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227075 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B10EC77B60 for ; Sat, 29 Apr 2023 20:07:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229951AbjD2UHw (ORCPT ); Sat, 29 Apr 2023 16:07:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230289AbjD2UHs (ORCPT ); Sat, 29 Apr 2023 16:07:48 -0400 Received: from mail-yw1-x1135.google.com (mail-yw1-x1135.google.com [IPv6:2607:f8b0:4864:20::1135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CF642D76 for ; Sat, 29 Apr 2023 13:07:42 -0700 (PDT) Received: by mail-yw1-x1135.google.com with SMTP id 00721157ae682-559e53d1195so9484367b3.2 for ; Sat, 29 Apr 2023 13:07:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798861; x=1685390861; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=yqjrnZ1dA3CANgG328lrX4wRimOWh+0WQMQv3a3TsXI=; b=4LKhIwJ12223z4avC4n/G8RbAHPuewdr0jPPewFABpvv9A7p3IpNxA/TAK5CJjHTyZ sroLlCjWU9sS0OWNPpbPSORzHpfKUetFjEdmLJsuGIuU1Scy2KZb4+kJ0kF4n2xB/W2a FNwEdC4Wg85Wdml18Nj0CIUs+5ME90+WhaXclIeuxk27/hlZt3HRPCIM7FoZoW1CLhRw byOJAsHTifYHlrBGUD8rLjk0l9HPCMRMr4yldNnWmVD03KaN6jijnJiNe0WuUBiULnkC i9ilUuCOhvi8c5Sl4EgPOFTeAK5oWmIEY5fQWWTyCQXcq09RQWai7YYWHhX/XI2WjVI5 6l4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798861; x=1685390861; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yqjrnZ1dA3CANgG328lrX4wRimOWh+0WQMQv3a3TsXI=; b=fXwCuK+TafNCGKCh6dfQ6B24ThzN7ft2NrsLADmhLqzl/3dflWY32qqPqWWDEkd9Kb If1qYDccpU/CZC2ugLDn7tyDMWLqENJ+dSxKJWVI1PeNgEJ5p3N2fXxtuvpO75Im0v+t gfwV7h8k7DkC8nz0bXXourrEY9wFP/CagxXrgPCFhqSA4T40r5aljIkpZ/4cJSFN6JGE xRGDR1PPtNhHx4Aau+mvW/44QSxinphzBb3muDALyt9z+UJjBd61KbwtUHRkMsEtT2mP GydVcNLn1ZxOE6AjInNzUIsd2iOVUEjPgBe0h0khR7EDljCe5urimFA2F011isQQWc+y PMyA== X-Gm-Message-State: AC+VfDy1fW4p4uEzCrM0PVTxGqq8rqodu5Ad/ISD0TUaatyww3wap7N9 rA3v3UH9XrXqQGMU6lvZRC35IKwrehP4q2s3/HoG7g== X-Google-Smtp-Source: ACHHUZ4NpzoGEeYuzr1pJmqZXWEV7YcZR07mnsT3Oo25AMahh4vZ2AP1zJlPTfVRXBbR1wszYjlOyQ== X-Received: by 2002:a81:6543:0:b0:55a:c62:3a92 with SMTP id z64-20020a816543000000b0055a0c623a92mr567549ywb.29.1682798861520; Sat, 29 Apr 2023 13:07:41 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id e133-20020a81698b000000b00545a08184e9sm6259623ywc.121.2023.04.29.13.07.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:41 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 10/12] btrfs: add __KERNEL__ check for btrfs_no_printk Date: Sat, 29 Apr 2023 16:07:19 -0400 Message-Id: <284c95473545a5e08904a691b5a7de55a3c5263f.1682798736.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org We want to override this in btrfs-progs, so wrap this in the __KERNEL__ check so we can easily sync this to btrfs-progs and have our local version of btrfs_no_printk do the work. Signed-off-by: Josef Bacik Reviewed-by: Johannes Thumshirn --- fs/btrfs/messages.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/fs/btrfs/messages.h b/fs/btrfs/messages.h index ac2d1982ba3d..99143bbf78a5 100644 --- a/fs/btrfs/messages.h +++ b/fs/btrfs/messages.h @@ -7,11 +7,18 @@ struct btrfs_fs_info; +/* + * We want to be able to override this in btrfs-progs. + */ +#ifdef __KERNEL__ + static inline __printf(2, 3) __cold void btrfs_no_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) { } +#endif + #ifdef CONFIG_PRINTK #define btrfs_printk(fs_info, fmt, args...) \ From patchwork Sat Apr 29 20:07:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227076 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 63E4AC77B7C for ; Sat, 29 Apr 2023 20:07:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbjD2UHy (ORCPT ); Sat, 29 Apr 2023 16:07:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41892 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230339AbjD2UHt (ORCPT ); Sat, 29 Apr 2023 16:07:49 -0400 Received: from mail-yw1-x1134.google.com (mail-yw1-x1134.google.com [IPv6:2607:f8b0:4864:20::1134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194F32D4A for ; Sat, 29 Apr 2023 13:07:44 -0700 (PDT) Received: by mail-yw1-x1134.google.com with SMTP id 00721157ae682-54fae5e9ec7so16365147b3.1 for ; Sat, 29 Apr 2023 13:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798863; x=1685390863; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=KSVauplUhZYm8oUuM5vJbwvjgaLq98k2j6wOoRptDDc=; b=XsMAzZpoNBt9cs4zLIpuH1QPAN1x1/3y6+ZKi3h5MEv7j50vyhMdcMGkL14obSNK3y jNWbRBaeLfL2PSFkEdbwu5WWUUdRWblSqZTyIyKEYFPbdeHWz9zedRK7BrAoz8FCSdZE uUXB6VG7ksySMrvO1iSBSZ2vQUsMuXy0fVZDER1XH7rDJyhFMglG32Baash8JoCPHpjQ DcjTGh5zVqdyb4qp4g89eRDocHsety5OTl60N+PzZWXiELntSACUg1rcSfEO79Ff4tAc ze5g71e3zMCxNFWkYtnosFAGoAlHMezi5dR5ibdKQXrS//dvL7oJoJ9iaMui9jSsjOF8 wNxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798863; x=1685390863; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=KSVauplUhZYm8oUuM5vJbwvjgaLq98k2j6wOoRptDDc=; b=Hwn3wDMZu92fnsZuxUSWkyVAsfendb/YFqALzbM9FowDCB97iFOAeSqxFO1b7f2q+m DwTDVqxmE7/9dwqZA0BcS463nTTriB3hGrjKd4slijIF8qDXUztZs4fBXWasJAyuDL2t dxjB5KB8hxTwDKY9+v1Q74pj8kv2QdLUrKxP3aO1zA0cA45Gy0oIVi4xdU0BiVmzHffB 782AhKuBKaoE72PGigv7NgJDQf4MPQ2pTgFBHFjCFu8cTnbsb3nWeoVcQQCUC4m1l7+F CU8B8ekT4ci5HP7Ty58coeUPaBIamDccupFF23TB39wvjn3ohAYzCgUt9Jtisvwselew 95aQ== X-Gm-Message-State: AC+VfDz0hHnZoJD6UWno+LAmMEs+EqYKnABC9iL/6AgYtFeHnMGK2BAM uIKz5f6v+2q2OPOP6VIYdrPpJ308yO7Q3ADPAso8Tw== X-Google-Smtp-Source: ACHHUZ6vq/YvhHLybG9aeTKWntcjaCG5GINKZLgJzYmiLHZfT+I/OgzU0PT1zUKeH7bN1rr3IXSudQ== X-Received: by 2002:a81:75d4:0:b0:55a:10e9:2ce6 with SMTP id q203-20020a8175d4000000b0055a10e92ce6mr439369ywc.50.1682798862728; Sat, 29 Apr 2023 13:07:42 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id f5-20020a0dc305000000b00545c373f7c0sm6307857ywd.139.2023.04.29.13.07.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:42 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 11/12] btrfs: add a btrfs_csum_type_size helper Date: Sat, 29 Apr 2023 16:07:20 -0400 Message-Id: <2627fbc83e4c07215bf831d6625b193d6491a750.1682798736.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is needed in btrfs-progs for the tools that convert the checksum types for file systems and a few other things. We don't have it in the kernel as we just want to get the size for the super blocks type. However I don't want to have to manually add this every time we sync ctree.c into btrfs-progs, so add the helper in the kernel with a note so it doesn't get removed by a later cleanup. Signed-off-by: Josef Bacik --- fs/btrfs/ctree.c | 8 +++++++- fs/btrfs/ctree.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 7071f90c23e3..c95c62baef3e 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -150,13 +150,19 @@ static inline void copy_leaf_items(const struct extent_buffer *dst, nr_items * sizeof(struct btrfs_item)); } +/* This exists for btrfs-progs usages. */ +u16 btrfs_csum_type_size(u16 type) +{ + return btrfs_csums[type].size; +} + int btrfs_super_csum_size(const struct btrfs_super_block *s) { u16 t = btrfs_super_csum_type(s); /* * csum type is validated at mount time */ - return btrfs_csums[t].size; + return btrfs_csum_type_size(t); } const char *btrfs_super_csum_name(u16 csum_type) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 4c1986cd5bed..221e230787e3 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -702,6 +702,7 @@ static inline bool btrfs_is_data_reloc_root(const struct btrfs_root *root) return root->root_key.objectid == BTRFS_DATA_RELOC_TREE_OBJECTID; } +u16 btrfs_csum_type_size(u16 type); int btrfs_super_csum_size(const struct btrfs_super_block *s); const char *btrfs_super_csum_name(u16 csum_type); const char *btrfs_super_csum_driver(u16 csum_type); From patchwork Sat Apr 29 20:07:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 13227077 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D641C77B7F for ; Sat, 29 Apr 2023 20:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229663AbjD2UH4 (ORCPT ); Sat, 29 Apr 2023 16:07:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229471AbjD2UHx (ORCPT ); Sat, 29 Apr 2023 16:07:53 -0400 Received: from mail-yb1-xb33.google.com (mail-yb1-xb33.google.com [IPv6:2607:f8b0:4864:20::b33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3110826A2 for ; Sat, 29 Apr 2023 13:07:45 -0700 (PDT) Received: by mail-yb1-xb33.google.com with SMTP id 3f1490d57ef6-b9a6f17f2b6so14180163276.1 for ; Sat, 29 Apr 2023 13:07:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20221208.gappssmtp.com; s=20221208; t=1682798864; x=1685390864; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=xZAeofo2K+pYk8Er0WS21gWHrYXLDgN+I/eX2G11YDU=; b=0SHciu5B4GdydqABszMDaVfXbE/ES9fbxSQMfmXXI9pZc9JtH/t5VW2fFI/cW3aTAY 0Z/u8cm7/LOSRiTDH3Dj7Aj+u1Bad46x9BGBVK5VJkYLCczy0XWNke1gLwBvjH6BTRPk kQQoKQifvCFJPb7eymp/hfm8ANjDAizwP+maCXn4wSauoLgw906Td/6058qq9qJg+8Rc W/lIy51+iTTZKbEBdhLRcxhhg/JzkEoP8O+98BF2H7bd/8GQdKxtsHjGNi/5g2ZNHevm BF9DXgBXQmM7XFehXEuiSJVJXE+g9mfEC0KkZEZhKCt2CXMnQQqSQRl6cxAFFwiLrBLw BCBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682798864; x=1685390864; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xZAeofo2K+pYk8Er0WS21gWHrYXLDgN+I/eX2G11YDU=; b=M7Uqm2HJvQ+m0ndGe1E5IO2VcSNjtujgHN0HiH81C66YmWUFBZw2yLa3HqiCDZUEE9 yLTC3RtWrQy27POoQ/R0nkb6EYt/u8xFj05V2p7/DsnG97tQNCS9nefTnUtn6kwtVNft H0xV5lWEvz82n68w3HObAOg20b2P2Tgry3qoaqPwvolZRDzf9IM/oxTqBRkYsNvhF6mJ pmJBpC1bCaG5HzVB/KmA5f2PVim4ooewyLkB4YkLeqzAGFm5EJotWscAxpdtyaf5Npyp QrOcsGlRl0H5PKz8ub5bfyG6yXZWvlooa5P+MQCf29EfOFPtPaKdg6Vzp3Ji1IYEnO6g Tl+A== X-Gm-Message-State: AC+VfDwQWKZsugD9FBNY5PWiaq+TBOb2SYP4cEjZMTcba32+Dn9Ce9ft YWQDTE9pUpQkADhLaDvX8TcbEIu3Lu75F47HEsYNaQ== X-Google-Smtp-Source: ACHHUZ4DQuJUpbm5TLJq1DyjdSE8M42YnpvscHQBhdmf9klcI3Zo0QgEUQYbwpQ/UiMKmjdBxufmrw== X-Received: by 2002:a81:4f84:0:b0:55a:101e:aaf0 with SMTP id d126-20020a814f84000000b0055a101eaaf0mr483837ywb.16.1682798863938; Sat, 29 Apr 2023 13:07:43 -0700 (PDT) Received: from localhost (cpe-76-182-20-124.nc.res.rr.com. [76.182.20.124]) by smtp.gmail.com with ESMTPSA id j62-20020a0de041000000b0054eb6b21b9csm6199294ywe.84.2023.04.29.13.07.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 29 Apr 2023 13:07:43 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 12/12] btrfs: rename del_ptr -> btrfs_del_ptr and export it Date: Sat, 29 Apr 2023 16:07:21 -0400 Message-Id: <7d772d80cffccb4054b74abd90649e1c4350a361.1682798736.git.josef@toxicpanda.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This exists internal to ctree.c, however btrfs check needs to use it for some of its operations. I'd rather not duplicate that code inside of btrfs check as this is low level and I want to keep this code in one place, so rename the function to btrfs_del_ptr and export it so that it can be used inside of btrfs-progs safely. Add a comment to make sure this doesn't get removed by a future cleanup. Signed-off-by: Josef Bacik --- fs/btrfs/ctree.c | 16 ++++++++-------- fs/btrfs/ctree.h | 2 ++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index c95c62baef3e..198773503cfd 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -37,8 +37,6 @@ static int push_node_left(struct btrfs_trans_handle *trans, static int balance_node_right(struct btrfs_trans_handle *trans, struct extent_buffer *dst_buf, struct extent_buffer *src_buf); -static void del_ptr(struct btrfs_root *root, struct btrfs_path *path, - int level, int slot); static const struct btrfs_csums { u16 size; @@ -1122,7 +1120,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, if (btrfs_header_nritems(right) == 0) { btrfs_clear_buffer_dirty(trans, right); btrfs_tree_unlock(right); - del_ptr(root, path, level + 1, pslot + 1); + btrfs_del_ptr(root, path, level + 1, pslot + 1); root_sub_used(root, right->len); btrfs_free_tree_block(trans, btrfs_root_id(root), right, 0, 1); @@ -1168,7 +1166,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans, if (btrfs_header_nritems(mid) == 0) { btrfs_clear_buffer_dirty(trans, mid); btrfs_tree_unlock(mid); - del_ptr(root, path, level + 1, pslot); + btrfs_del_ptr(root, path, level + 1, pslot); root_sub_used(root, mid->len); btrfs_free_tree_block(trans, btrfs_root_id(root), mid, 0, 1); free_extent_buffer_stale(mid); @@ -4276,9 +4274,11 @@ int btrfs_duplicate_item(struct btrfs_trans_handle *trans, * * the tree should have been previously balanced so the deletion does not * empty a node. + * + * This is exported for use inside btrfs-progs, don't un-export it. */ -static void del_ptr(struct btrfs_root *root, struct btrfs_path *path, - int level, int slot) +void btrfs_del_ptr(struct btrfs_root *root, struct btrfs_path *path, int level, + int slot) { struct extent_buffer *parent = path->nodes[level]; u32 nritems; @@ -4333,7 +4333,7 @@ static noinline void btrfs_del_leaf(struct btrfs_trans_handle *trans, struct extent_buffer *leaf) { WARN_ON(btrfs_header_generation(leaf) != trans->transid); - del_ptr(root, path, 1, path->slots[1]); + btrfs_del_ptr(root, path, 1, path->slots[1]); /* * btrfs_free_extent is expensive, we want to make sure we @@ -4419,7 +4419,7 @@ int btrfs_del_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, /* push_leaf_left fixes the path. * make sure the path still points to our leaf - * for possible call to del_ptr below + * for possible call to btrfs_del_ptr below */ slot = path->slots[1]; atomic_inc(&leaf->refs); diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 221e230787e3..9dc9315c2bfa 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -541,6 +541,8 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, struct extent_buffer **cow_ret, u64 new_root_objectid); int btrfs_block_can_be_shared(struct btrfs_root *root, struct extent_buffer *buf); +void btrfs_del_ptr(struct btrfs_root *root, struct btrfs_path *path, int level, + int slot); void btrfs_extend_item(struct btrfs_path *path, u32 data_size); void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end); int btrfs_split_item(struct btrfs_trans_handle *trans,