From patchwork Tue Jun 18 15:14:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13702509 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 330513F8E4 for ; Tue, 18 Jun 2024 15:14:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718723683; cv=none; b=hnLx+CA/J6N+fTzG/VKmDVY9jzjU20Wpe4NIPHIxD9v9zP3U+SvlM8Uu09I/j88TmpvMgkSN2oLbYeht4dpbJYR0dUu+Wv0FEJ8ynGcwk7nG/Q44j4Iklw9ggSFyU2pDgpBgqIT8MI0CgzINyQkd4jd3IwgteeEaxwQFpC6hpO0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718723683; c=relaxed/simple; bh=WVP7STDYye0caFOln2uX+hBhFY9537nvKzmB0srZRF8=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WIIPEGz6T0DgM4ckgGd4aqmGFu7m+NKFWMsoI/jwxgMzma96FIQr9Z4f5IyJzy4E4hCRy8a/eqf3hHzfITscKRUBL6QWUrbA1/W8KXeq/2pb+D01D7NWewx30PCj5itKwXKyfvhqD+OsTv9irACj00iLcYJCvnlNOmG8xd0Wd+M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GNEjepbg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GNEjepbg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B2FFC4AF1D for ; Tue, 18 Jun 2024 15:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718723682; bh=WVP7STDYye0caFOln2uX+hBhFY9537nvKzmB0srZRF8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=GNEjepbgW/8TqjKTiUtvvcNP674Uwewrck9PxmPdA4+Bp7UZmysscYcOlRG2DRU/k QfDDKAWSdTgfnFNB1VvH/MU1IN8ck6MgDCT/J2ammo9gi5rlQfxZcgKFDgajj0ReL/ EOi795Ci+nO+eNQibXK0o9zfy/t+XpyJKO9NVfGP8EK3hSP8mJOFGaRYLy1gvi6pg/ xxGgahv+NQ0jpXe1a2CW3WtghFyRlGlf+NJj7ZgO/rOxuyzhP7TcWSjMAWjcbJLGP2 kwF6f0Jb4fItigqPAPGPYY+0j2bDrubv5B/4yRbZqoQBU2rqis2lGdHME5TiQPSFcj B/0NRorKA4C+A== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 1/2] btrfs: simplify setting the full backref flag at update_ref_for_cow() Date: Tue, 18 Jun 2024 16:14:37 +0100 Message-Id: <989cfd93dc17f4b3d6348c6ff13393b67d2d3b83.1718723053.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana We keep a "new_flags" variable only to keep track if we need to update the metadata extent's flags, and when we set BTRFS_BLOCK_FLAG_FULL_BACKREF in the variable, we do it in an inner scope. Then check in an outer scope if the variable is not 0 and if so call btrfs_set_disk_extent_flags(). The variable isn't used for anything else. This is somewhat confusing, so to make it more straightforward update the extent's flags where we are currently updating "new_flags" and remove the variable. Signed-off-by: Filipe Manana --- fs/btrfs/ctree.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 763b9a1da428..7b2f1de845e7 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -417,7 +417,6 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, u64 refs; u64 owner; u64 flags; - u64 new_flags = 0; int ret; /* @@ -481,7 +480,10 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, if (ret) return ret; } - new_flags |= BTRFS_BLOCK_FLAG_FULL_BACKREF; + ret = btrfs_set_disk_extent_flags(trans, buf, + BTRFS_BLOCK_FLAG_FULL_BACKREF); + if (ret) + return ret; } else { if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID) @@ -491,11 +493,6 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, if (ret) return ret; } - if (new_flags != 0) { - ret = btrfs_set_disk_extent_flags(trans, buf, new_flags); - if (ret) - return ret; - } } else { if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) { if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID) From patchwork Tue Jun 18 15:14:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 13702510 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1B5439AEC for ; Tue, 18 Jun 2024 15:14:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718723683; cv=none; b=iWSKLPUIzdiDQ15Z+9Sft/Jrna2H9p4gDjY8YJGrKeU2pCEb5MDCRl8NMXiHXa4hRP6a3LEgSr2z4r3Vt9BnSJv26aSP1fSv0jYyf1Y8QuXuwmPbMoJZerY+DUpmjEh0qZZSQGjoxxvRPANykkHxYTmF8h2HCMCSJY7Mwuz2hS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718723683; c=relaxed/simple; bh=EYQS0aS3FdVuFwhy3xw+vkGECb9lF8NVP2j9JsWVc9k=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gIYESsLXI8QmotAyUrUmRX/0iefqXVkUzkiD6nvV8LLA0nfEloVigvKKMmBxmfvmwHmeeM3dPhey0kbxDahXtTm8lRgx8L873OwwP9WVgcEueAyTi9d/BokaXlWhFZXgmNj7u+efoOJ64IWJKHmXxD0QhiMyrm2fiXNN7T9wkro= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b994Nl/q; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b994Nl/q" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2A354C4AF50 for ; Tue, 18 Jun 2024 15:14:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1718723683; bh=EYQS0aS3FdVuFwhy3xw+vkGECb9lF8NVP2j9JsWVc9k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=b994Nl/qQGI6yAWvsCOjTQy//wFytokfj9iiQ0e5kWMyBk6MKA5qRI9AxQMZMo4Bh dpmG5wiQRBLTzB/SRJjgw0P4KGSzJc72EGYH3u1YISk30aNCaMkcbAFB0PPY6pUqIE 0Yxku0XlkBF7Nff6MlrkSpkEcOzqFurQ96sivx1CkIqmZw62IWlxoFAbCEg8R1NfMr c5bCfJdadEg/E3xa/4Ui82Y+szm3yqlxCk3kdrXmzYP1nuMkC6sNZQ7mLwdgi5tzaX QdFOTf23KzMcJko1FtZN4mcPDSI5dHLCuRawNiT6weDC9Wy9mAgdo7tpCjSarpMsZD hD2LkEDRg2LIQ== From: fdmanana@kernel.org To: linux-btrfs@vger.kernel.org Subject: [PATCH 2/2] btrfs: replace BUG_ON() with error handling at update_ref_for_cow() Date: Tue, 18 Jun 2024 16:14:38 +0100 Message-Id: <0b85a09a22d9a36c6f1b0a93d84c7cc31e041adb.1718723053.git.fdmanana@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-btrfs@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Filipe Manana Instead of a BUG_ON() just return an error, log an error message and abort the transaction in case we find an extent buffer belonging to the relocation tree that doesn't have the full backref flag set. This is unexpected and should never happen (save for bugs or a potential bad memory). Signed-off-by: Filipe Manana --- fs/btrfs/ctree.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index 7b2f1de845e7..e33f9f5a228d 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c @@ -461,8 +461,16 @@ static noinline int update_ref_for_cow(struct btrfs_trans_handle *trans, } owner = btrfs_header_owner(buf); - BUG_ON(owner == BTRFS_TREE_RELOC_OBJECTID && - !(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF)); + if (unlikely(owner == BTRFS_TREE_RELOC_OBJECTID && + !(flags & BTRFS_BLOCK_FLAG_FULL_BACKREF))) { + btrfs_crit(fs_info, +"found tree block at bytenr %llu level %d root %llu refs %llu flags %llx without full backref flag set", + buf->start, btrfs_header_level(buf), + btrfs_root_id(root), refs, flags); + ret = -EUCLEAN; + btrfs_abort_transaction(trans, ret); + return ret; + } if (refs > 1) { if ((owner == btrfs_root_id(root) ||