From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH v2 2/3] btrfs: remove __TRANS_FREEZABLE
Date: Thu, 24 Sep 2026 15:28:15 +0930 [thread overview]
Message-ID: <0eae09fa05791ff4079a10f778c02cc0da0653b0.1790229298.git.wqu@suse.com> (raw)
In-Reply-To: <cover.1790229298.git.wqu@suse.com>
Inside transaction.c most TRANS_* flags are just a single bit, but there
are 2 exceptions:
- TRANS_START
Which is (__TRANS_START | __TRANS_FREEZABLE)
- TRANS_JOIN
Which is (__TRANS_JOIN | __TRANS_FREEZABLE)
The extra __TRANS_FREEZABLE flag indicates that those operations need
to acquire sb intwrite lock to handle fs freezing.
However since there are only two operations requiring sb intwrite lock,
there is no need to introduce a dedicated flag for it, we can introduce
a new TRANS_SB_INTWRITER_MASK to cover the only two cases, then use that
new mask to determine whether the type requires sb intwrite lock.
This makes all TRANS_* flags a single bit.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/transaction.c | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 4181f3897a30..d73c8723ed70 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -39,7 +39,6 @@
static struct kmem_cache *btrfs_trans_handle_cachep;
enum {
- ENUM_BIT(__TRANS_FREEZABLE),
ENUM_BIT(__TRANS_START),
ENUM_BIT(__TRANS_ATTACH),
ENUM_BIT(__TRANS_JOIN),
@@ -50,12 +49,15 @@ enum {
ENUM_BIT(__TRANS_JOIN_NOSTART),
};
-#define TRANS_START (__TRANS_START | __TRANS_FREEZABLE)
+#define TRANS_START (__TRANS_START)
#define TRANS_ATTACH (__TRANS_ATTACH)
-#define TRANS_JOIN (__TRANS_JOIN | __TRANS_FREEZABLE)
+#define TRANS_JOIN (__TRANS_JOIN)
#define TRANS_JOIN_NOLOCK (__TRANS_JOIN_NOLOCK)
#define TRANS_JOIN_NOSTART (__TRANS_JOIN_NOSTART)
+/* Those types need to hold sb intwrite lock. */
+#define TRANS_SB_INTWRITER_MASK (__TRANS_START | __TRANS_JOIN)
+
#define TRANS_EXTWRITERS (__TRANS_START | __TRANS_ATTACH)
/*
@@ -746,6 +748,8 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
}
/*
+ * Only TRANS_START and TRANS_JOIN require sb intwrite lock.
+ *
* If we are JOIN_NOLOCK we're already committing a transaction and
* waiting on this guy, so we don't need to do the sb_start_intwrite
* because we're already holding a ref. We need this because we could
@@ -755,7 +759,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
* If we are ATTACH, it means we just want to catch the current
* transaction and commit it, so we needn't do sb_start_intwrite().
*/
- if (type & __TRANS_FREEZABLE)
+ if (type & TRANS_SB_INTWRITER_MASK)
sb_start_intwrite(fs_info->sb);
if (may_wait_transaction(fs_info, type))
@@ -857,7 +861,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
return h;
join_fail:
- if (type & __TRANS_FREEZABLE)
+ if (type & TRANS_SB_INTWRITER_MASK)
sb_end_intwrite(fs_info->sb);
kmem_cache_free(btrfs_trans_handle_cachep, h);
alloc_fail:
@@ -1138,7 +1142,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
btrfs_trans_release_chunk_metadata(trans);
- if (trans->type & __TRANS_FREEZABLE)
+ if (trans->type & TRANS_SB_INTWRITER_MASK)
sb_end_intwrite(info->sb);
/*
@@ -2150,7 +2154,7 @@ static void cleanup_transaction(struct btrfs_trans_handle *trans, int err)
fs_info->running_transaction = NULL;
spin_unlock(&fs_info->trans_lock);
- if (trans->type & __TRANS_FREEZABLE)
+ if (trans->type & TRANS_SB_INTWRITER_MASK)
sb_end_intwrite(fs_info->sb);
btrfs_put_transaction(cur_trans);
btrfs_put_transaction(cur_trans);
@@ -2682,7 +2686,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
btrfs_put_transaction(cur_trans);
btrfs_put_transaction(cur_trans);
- if (trans->type & __TRANS_FREEZABLE)
+ if (trans->type & TRANS_SB_INTWRITER_MASK)
sb_end_intwrite(fs_info->sb);
btrfs_scrub_continue(fs_info);
--
2.55.0
next prev parent reply other threads:[~2026-09-24 5:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-24 5:58 [PATCH v2 0/3] btrfs: __TRANS_* flags cleanup Qu Wenruo
2026-09-24 5:58 ` [PATCH v2 1/3] btrfs: move __TRANS_* and TRANS_* flags out of transaction.h Qu Wenruo
2026-09-28 18:27 ` Filipe Manana
2026-09-28 21:59 ` Qu Wenruo
2026-09-24 5:58 ` Qu Wenruo [this message]
2026-09-28 18:32 ` [PATCH v2 2/3] btrfs: remove __TRANS_FREEZABLE Filipe Manana
2026-09-24 5:58 ` [PATCH v2 3/3] btrfs: remove __TRANS_* flags Qu Wenruo
2026-09-28 18:34 ` Filipe Manana
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0eae09fa05791ff4079a10f778c02cc0da0653b0.1790229298.git.wqu@suse.com \
--to=wqu@suse.com \
--cc=linux-btrfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox