Received: by 2002:ab2:2997:0:b0:1ec:cbc4:63fb with SMTP id n23csp545235lqb; Thu, 29 Feb 2024 08:09:12 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUxQfABMmCQLP440k9JAeKVvjy94U9f9Y34hxJdtIeRaSvCgU7K9b3jAwN5lQvUdph/F+mWBP1fabzoeyTNH7PdDjWhoF1TLkeIignbiw== X-Google-Smtp-Source: AGHT+IGzEyqU3mwDq2ZLsyXd/PItvhKd5+G+lACYvJgGihaA1i7dO6dTMLhvn9EO+gOwIyPRT8Oz X-Received: by 2002:a17:906:f198:b0:a41:3492:5fed with SMTP id gs24-20020a170906f19800b00a4134925fedmr1973779ejb.61.1709222952370; Thu, 29 Feb 2024 08:09:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709222952; cv=pass; d=google.com; s=arc-20160816; b=yE0ujL0xDhEhCYIYP+xICxJuy/AV65K83JbFptRqY6HnE3X5+OJK5gv2R4XTBUzmEG JohapYhHCI8ZiMj6L+zWnVIgZpeqHwzpoLtxMqWC4Is4mtTn5HXJHG8dRHhvIM5jLQzs IdRuyiBrj8JzZYMZ8sHhDkVhow2m3A6orsOOh84GNP4N2SYZYdhW6Mb01y00Sj9/2Uh7 LJ+442giBYFSZZuCOL0KiQMFstLhwjDz2IcR7NFc48TXM+5h52FvSZHtBg7VaOuTu9XT sfs9JKdPpctZP11+PitPau0R4wcbW0XfXSRD6Jztmh94nIFxOzf7GIWvmJZngrvWw1Q0 /cPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=/dcFeQ1csezt4W5aHCSPj9JjY0oUDjUQc6lWi/dQeYY=; fh=pYGbdzVDINbImXGcsgeWS/y8C08a+RDDzhrmqeamK7g=; b=fIoZpeGqydMHDM42lO1KaDCkKy702oWgja2xlPiRgcG9WxKLugHX0J1ncuCWgOlp7L ENYOS3upF4VvIW0wnr8QURpgCvKCgIVgP4bLHEaOW2vUsUCcVCGfA6oNSJZWedMshNQo t0dxroOpXyTHpe3nFduRnjUF/tKq5gll95YJ/XEHHsvvYNhn+MW5d/vgfEpeq5IOdjtK +kT2972ykTViDv9RBjBD4x2MSM//Bf8ryzhckoONIswnDCre1mAiqpOGB/PbLQMWgeR3 XE7L73ma64tOKLx8aSOKkVkdUlmoMhI+loK4404tCQcO6cfszsCJf/6ZzrWxQ1Hy2O5q GJmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c3e2B6aV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-87016-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87016-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id f17-20020a170906139100b00a3ea034e5dasi690957ejc.57.2024.02.29.08.09.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 08:09:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-87016-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=c3e2B6aV; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-87016-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-87016-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 20FDD1F225B8 for ; Thu, 29 Feb 2024 16:09:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1E301154456; Thu, 29 Feb 2024 15:51:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="c3e2B6aV" 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 3A5A51547C0; Thu, 29 Feb 2024 15:51:15 +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=1709221875; cv=none; b=NLSwRKCESgmngxtHdYXCKwxnc4AiPnCjKgx7v+wx/SETRxykTA1zmS179vd6ULfHU6kiz3MCiG30nZHd0cAAjQ/J08/ebuZrgKivGiuEsmHl9puoY32GkYb1hJ5ZpMCOXunUA/LfHMkjFo6mg8HqSyUi/6F8MNndRvNR9KtwGAM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709221875; c=relaxed/simple; bh=W7EFPrddAiARLEIxEX/jN7SMYuIy9OT780TTtwsJlAg=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hc6tTDjsQTNIYBUU4r9/Fbnqk/EOznqPJqpoa7jOl4gA6XkIvAc3D687UNf5tjWvaOxxlQIU+js3e5300MG7FcSW1JbAVDkDecnSnCdOqpIDjFgS+ppFpWNQ0Rlsuv1XncnRJUIigNzxQMMz5gOxlx2X+aOCbpymkLJjIUZn4ws= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c3e2B6aV; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1ACEC433F1; Thu, 29 Feb 2024 15:51:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709221875; bh=W7EFPrddAiARLEIxEX/jN7SMYuIy9OT780TTtwsJlAg=; h=From:To:Cc:Subject:Date:From; b=c3e2B6aVmG4M15qM3q9olZ16c8xVfuNyJCKrGO/qpflYxRjyH8jZpV5UrTEy+hvhu M9qcvIxhDoIMASd4lWsLtucNjapXdkGAjnbiMq1zI1KoocqkuIR2EFqXLxTZATxHU7 aRBYVUVvoxR8x4HiamsFfVJdtLsEEuHqhxlYyZDs9AlgT8uMEGNzGx2DcfdhsRhK03 +TnlWT9iH4EKg9Z0EzGzB596zcph9o/f86jbFmLipKJLc4IT9ClI+sQFlY1uK6uAuv H3wYMCbQhXy8N5EKNc2XDuU2LwYgubsGhMPVTBJVIXtiXH1eQaFexd2Or/ybXO3mOm hgNjlxNUOgjjw== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Filipe Manana , Johannes Thumshirn , Josef Bacik , Boris Burkov , David Sterba , Sasha Levin , clm@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 5.10 1/7] btrfs: add and use helper to check if block group is used Date: Thu, 29 Feb 2024 10:51:05 -0500 Message-ID: <20240229155112.2851155-1-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.210 Content-Transfer-Encoding: 8bit From: Filipe Manana [ Upstream commit 1693d5442c458ae8d5b0d58463b873cd879569ed ] Add a helper function to determine if a block group is being used and make use of it at btrfs_delete_unused_bgs(). This helper will also be used in future code changes. Reviewed-by: Johannes Thumshirn Reviewed-by: Josef Bacik Reviewed-by: Boris Burkov Signed-off-by: Filipe Manana Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/block-group.c | 3 +-- fs/btrfs/block-group.h | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c index c4e3c1a5de059..9a7c7e0f7c233 100644 --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -1393,8 +1393,7 @@ void btrfs_delete_unused_bgs(struct btrfs_fs_info *fs_info) } spin_lock(&block_group->lock); - if (block_group->reserved || block_group->pinned || - block_group->used || block_group->ro || + if (btrfs_is_block_group_used(block_group) || block_group->ro || list_is_singular(&block_group->list)) { /* * We want to bail if we made new allocations or have diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h index 4c7614346f724..0d02b75f9e7e3 100644 --- a/fs/btrfs/block-group.h +++ b/fs/btrfs/block-group.h @@ -196,6 +196,13 @@ static inline u64 btrfs_block_group_end(struct btrfs_block_group *block_group) return (block_group->start + block_group->length); } +static inline bool btrfs_is_block_group_used(const struct btrfs_block_group *bg) +{ + lockdep_assert_held(&bg->lock); + + return (bg->used > 0 || bg->reserved > 0 || bg->pinned > 0); +} + static inline bool btrfs_is_block_group_data_only( struct btrfs_block_group *block_group) { -- 2.43.0