* [PATCH 1/3] btrfs: rename btrfs_ordered_extent::list to csum_list
2026-02-10 3:24 [PATCH 0/3] btrfs: ordered extent csum list related cleanup Qu Wenruo
@ 2026-02-10 3:24 ` Qu Wenruo
2026-02-10 3:24 ` [PATCH 2/3] btrfs: make add_pending_csums() to take an ordered extent as parameter Qu Wenruo
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2026-02-10 3:24 UTC (permalink / raw)
To: linux-btrfs
That list head records all pending checksums for that ordered
extent. And unlike other lists, we just use the name "list", which can
be very confusing for readers.
Rename it to "csum_list" which follows the remaining lists, showing the
purpose of the list.
And since we're here, remove a comment inside
btrfs_finish_ordered_zoned() where we have
"ASSERT(!list_empty(&ordered->csum_list))" to make sure the OE has
pending csums.
That comment is only here to make sure we do not call list_first_entry()
before checking BTRFS_ORDERED_PREALLOC.
But since we already have that bit checked and even have a dedicated
ASSERT(), there is no need for that comment anymore.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/inode.c | 6 +++---
fs/btrfs/ordered-data.c | 10 +++++-----
fs/btrfs/ordered-data.h | 2 +-
fs/btrfs/tree-log.c | 2 +-
fs/btrfs/zoned.c | 7 +++----
5 files changed, 13 insertions(+), 14 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 826809977df5..73c193a38b80 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3258,8 +3258,8 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) {
/* Logic error */
- ASSERT(list_empty(&ordered_extent->list));
- if (unlikely(!list_empty(&ordered_extent->list))) {
+ ASSERT(list_empty(&ordered_extent->csum_list));
+ if (unlikely(!list_empty(&ordered_extent->csum_list))) {
ret = -EINVAL;
btrfs_abort_transaction(trans, ret);
goto out;
@@ -3308,7 +3308,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
goto out;
}
- ret = add_pending_csums(trans, &ordered_extent->list);
+ ret = add_pending_csums(trans, &ordered_extent->csum_list);
if (unlikely(ret)) {
btrfs_abort_transaction(trans, ret);
goto out;
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 5df02c707aee..a17f18673bed 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -197,7 +197,7 @@ static struct btrfs_ordered_extent *alloc_ordered_extent(
entry->flags = flags;
refcount_set(&entry->refs, 1);
init_waitqueue_head(&entry->wait);
- INIT_LIST_HEAD(&entry->list);
+ INIT_LIST_HEAD(&entry->csum_list);
INIT_LIST_HEAD(&entry->log_list);
INIT_LIST_HEAD(&entry->root_extent_list);
INIT_LIST_HEAD(&entry->work_list);
@@ -329,7 +329,7 @@ void btrfs_add_ordered_sum(struct btrfs_ordered_extent *entry,
struct btrfs_inode *inode = entry->inode;
spin_lock(&inode->ordered_tree_lock);
- list_add_tail(&sum->list, &entry->list);
+ list_add_tail(&sum->list, &entry->csum_list);
spin_unlock(&inode->ordered_tree_lock);
}
@@ -628,7 +628,7 @@ void btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry)
ASSERT(list_empty(&entry->log_list));
ASSERT(RB_EMPTY_NODE(&entry->rb_node));
btrfs_add_delayed_iput(entry->inode);
- list_for_each_entry_safe(sum, tmp, &entry->list, list)
+ list_for_each_entry_safe(sum, tmp, &entry->csum_list, list)
kvfree(sum);
kmem_cache_free(btrfs_ordered_extent_cache, entry);
}
@@ -1323,10 +1323,10 @@ struct btrfs_ordered_extent *btrfs_split_ordered_extent(
}
}
- list_for_each_entry_safe(sum, tmpsum, &ordered->list, list) {
+ list_for_each_entry_safe(sum, tmpsum, &ordered->csum_list, list) {
if (offset == len)
break;
- list_move_tail(&sum->list, &new->list);
+ list_move_tail(&sum->list, &new->csum_list);
offset += sum->len;
}
diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h
index 1e6b0b182b29..e178d4a489af 100644
--- a/fs/btrfs/ordered-data.h
+++ b/fs/btrfs/ordered-data.h
@@ -134,7 +134,7 @@ struct btrfs_ordered_extent {
struct btrfs_inode *inode;
/* list of checksums for insertion when the extent io is done */
- struct list_head list;
+ struct list_head csum_list;
/* used for fast fsyncs */
struct list_head log_list;
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index e2806ca410f6..6ff1fe284ee9 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -5063,7 +5063,7 @@ static int log_extent_csums(struct btrfs_trans_handle *trans,
if (test_and_set_bit(BTRFS_ORDERED_LOGGED_CSUM, &ordered->flags))
continue;
- list_for_each_entry(sums, &ordered->list, list) {
+ list_for_each_entry(sums, &ordered->csum_list, list) {
ret = log_csums(trans, inode, log_root, sums);
if (ret)
return ret;
diff --git a/fs/btrfs/zoned.c b/fs/btrfs/zoned.c
index ae6f61bcefca..f3049890368c 100644
--- a/fs/btrfs/zoned.c
+++ b/fs/btrfs/zoned.c
@@ -2114,9 +2114,8 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered)
if (test_bit(BTRFS_ORDERED_PREALLOC, &ordered->flags))
return;
- ASSERT(!list_empty(&ordered->list));
- /* The ordered->list can be empty in the above pre-alloc case. */
- sum = list_first_entry(&ordered->list, struct btrfs_ordered_sum, list);
+ ASSERT(!list_empty(&ordered->csum_list));
+ sum = list_first_entry(&ordered->csum_list, struct btrfs_ordered_sum, list);
logical = sum->logical;
len = sum->len;
@@ -2147,7 +2146,7 @@ void btrfs_finish_ordered_zoned(struct btrfs_ordered_extent *ordered)
*/
if ((inode->flags & BTRFS_INODE_NODATASUM) ||
test_bit(BTRFS_FS_STATE_NO_DATA_CSUMS, &fs_info->fs_state)) {
- while ((sum = list_first_entry_or_null(&ordered->list,
+ while ((sum = list_first_entry_or_null(&ordered->csum_list,
typeof(*sum), list))) {
list_del(&sum->list);
kfree(sum);
--
2.52.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/3] btrfs: make add_pending_csums() to take an ordered extent as parameter
2026-02-10 3:24 [PATCH 0/3] btrfs: ordered extent csum list related cleanup Qu Wenruo
2026-02-10 3:24 ` [PATCH 1/3] btrfs: rename btrfs_ordered_extent::list to csum_list Qu Wenruo
@ 2026-02-10 3:24 ` Qu Wenruo
2026-02-10 3:24 ` [PATCH 3/3] btrfs: rename btrfs_csum_file_blocks() to btrfs_insert_data_csums() Qu Wenruo
2026-02-10 12:47 ` [PATCH 0/3] btrfs: ordered extent csum list related cleanup Filipe Manana
3 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2026-02-10 3:24 UTC (permalink / raw)
To: linux-btrfs
The structure btrfs_ordered_extent has a lot of list heads for different
purposes, passing a random list_head pointer is never a good idea as if
the wrong list is passed in, the type casting along with the fs will be
screwed up.
Instead pass the btrfs_ordered_extent pointer, and grab the csum_list
inside add_pending_csums() to make it a little safer.
Since we're here, also update the comments to follow the current style.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/inode.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 73c193a38b80..6c7fe7c87bc3 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2739,17 +2739,19 @@ void btrfs_clear_delalloc_extent(struct btrfs_inode *inode,
}
/*
- * given a list of ordered sums record them in the inode. This happens
- * at IO completion time based on sums calculated at bio submission time.
+ * Given an ordered extent and insert all its checksums into the csum tree.
+ *
+ * This happens at IO completion time based on sums calculated at bio
+ * submission time.
*/
static int add_pending_csums(struct btrfs_trans_handle *trans,
- struct list_head *list)
+ struct btrfs_ordered_extent *oe)
{
struct btrfs_ordered_sum *sum;
struct btrfs_root *csum_root = NULL;
int ret;
- list_for_each_entry(sum, list, list) {
+ list_for_each_entry(sum, &oe->csum_list, list) {
trans->adding_csums = true;
if (!csum_root)
csum_root = btrfs_csum_root(trans->fs_info,
@@ -3308,7 +3310,7 @@ int btrfs_finish_one_ordered(struct btrfs_ordered_extent *ordered_extent)
goto out;
}
- ret = add_pending_csums(trans, &ordered_extent->csum_list);
+ ret = add_pending_csums(trans, ordered_extent);
if (unlikely(ret)) {
btrfs_abort_transaction(trans, ret);
goto out;
--
2.52.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 3/3] btrfs: rename btrfs_csum_file_blocks() to btrfs_insert_data_csums()
2026-02-10 3:24 [PATCH 0/3] btrfs: ordered extent csum list related cleanup Qu Wenruo
2026-02-10 3:24 ` [PATCH 1/3] btrfs: rename btrfs_ordered_extent::list to csum_list Qu Wenruo
2026-02-10 3:24 ` [PATCH 2/3] btrfs: make add_pending_csums() to take an ordered extent as parameter Qu Wenruo
@ 2026-02-10 3:24 ` Qu Wenruo
2026-02-10 12:47 ` [PATCH 0/3] btrfs: ordered extent csum list related cleanup Filipe Manana
3 siblings, 0 replies; 5+ messages in thread
From: Qu Wenruo @ 2026-02-10 3:24 UTC (permalink / raw)
To: linux-btrfs
The function btrfs_csum_file_blocks() is a little confusing, unlike
btrfs_csum_one_bio(), it is not calculating the checksum of some file
blocks.
Instead it's just inserting the already calculated checksums into a given
root (can be a csum root or a log tree).
So rename it to btrfs_insert_data_csums() to reflect its behavior better.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
fs/btrfs/file-item.c | 6 +++---
fs/btrfs/file-item.h | 6 +++---
fs/btrfs/inode.c | 2 +-
fs/btrfs/tree-log.c | 6 +++---
4 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c
index 7bd715442f3e..27d971b12ce7 100644
--- a/fs/btrfs/file-item.c
+++ b/fs/btrfs/file-item.c
@@ -1090,9 +1090,9 @@ static int find_next_csum_offset(struct btrfs_root *root,
return 0;
}
-int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
- struct btrfs_root *root,
- struct btrfs_ordered_sum *sums)
+int btrfs_insert_data_csums(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root,
+ struct btrfs_ordered_sum *sums)
{
struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_key file_key;
diff --git a/fs/btrfs/file-item.h b/fs/btrfs/file-item.h
index 5645c5e3abdb..6c678787c770 100644
--- a/fs/btrfs/file-item.h
+++ b/fs/btrfs/file-item.h
@@ -61,9 +61,9 @@ int btrfs_lookup_file_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path, u64 objectid,
u64 bytenr, int mod);
-int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
- struct btrfs_root *root,
- struct btrfs_ordered_sum *sums);
+int btrfs_insert_data_csums(struct btrfs_trans_handle *trans,
+ struct btrfs_root *root,
+ struct btrfs_ordered_sum *sums);
int btrfs_csum_one_bio(struct btrfs_bio *bbio, bool async);
int btrfs_alloc_dummy_sum(struct btrfs_bio *bbio);
int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 6c7fe7c87bc3..4256c8056428 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2756,7 +2756,7 @@ static int add_pending_csums(struct btrfs_trans_handle *trans,
if (!csum_root)
csum_root = btrfs_csum_root(trans->fs_info,
sum->logical);
- ret = btrfs_csum_file_blocks(trans, csum_root, sum);
+ ret = btrfs_insert_data_csums(trans, csum_root, sum);
trans->adding_csums = false;
if (ret)
return ret;
diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 6ff1fe284ee9..b5f8e1399758 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -996,7 +996,7 @@ static noinline int replay_one_extent(struct walk_control *wc)
btrfs_root_id(root));
}
if (!ret) {
- ret = btrfs_csum_file_blocks(trans, csum_root, sums);
+ ret = btrfs_insert_data_csums(trans, csum_root, sums);
if (ret)
btrfs_abort_log_replay(wc, ret,
"failed to add csums for range [%llu, %llu) inode %llu root %llu",
@@ -4722,7 +4722,7 @@ static int log_csums(struct btrfs_trans_handle *trans,
* worry about logging checksum items with overlapping ranges.
*/
if (inode->last_reflink_trans < trans->transid)
- return btrfs_csum_file_blocks(trans, log_root, sums);
+ return btrfs_insert_data_csums(trans, log_root, sums);
/*
* Serialize logging for checksums. This is to avoid racing with the
@@ -4745,7 +4745,7 @@ static int log_csums(struct btrfs_trans_handle *trans,
*/
ret = btrfs_del_csums(trans, log_root, sums->logical, sums->len);
if (!ret)
- ret = btrfs_csum_file_blocks(trans, log_root, sums);
+ ret = btrfs_insert_data_csums(trans, log_root, sums);
btrfs_unlock_extent(&log_root->log_csum_range, sums->logical, lock_end,
&cached_state);
--
2.52.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH 0/3] btrfs: ordered extent csum list related cleanup
2026-02-10 3:24 [PATCH 0/3] btrfs: ordered extent csum list related cleanup Qu Wenruo
` (2 preceding siblings ...)
2026-02-10 3:24 ` [PATCH 3/3] btrfs: rename btrfs_csum_file_blocks() to btrfs_insert_data_csums() Qu Wenruo
@ 2026-02-10 12:47 ` Filipe Manana
3 siblings, 0 replies; 5+ messages in thread
From: Filipe Manana @ 2026-02-10 12:47 UTC (permalink / raw)
To: Qu Wenruo; +Cc: linux-btrfs
On Tue, Feb 10, 2026 at 3:24 AM Qu Wenruo <wqu@suse.com> wrote:
>
> Trivial changes, please refer to the commit message of each patch.
>
> Qu Wenruo (3):
> btrfs: rename btrfs_ordered_extent::list to csum_list
> btrfs: make add_pending_csums() to take an ordered extent as parameter
> btrfs: rename btrfs_csum_file_blocks() to btrfs_insert_data_csums()
Reviewed-by: Filipe Manana <fdmanana@suse.com>
Looks good, thanks.
>
> fs/btrfs/file-item.c | 6 +++---
> fs/btrfs/file-item.h | 6 +++---
> fs/btrfs/inode.c | 18 ++++++++++--------
> fs/btrfs/ordered-data.c | 10 +++++-----
> fs/btrfs/ordered-data.h | 2 +-
> fs/btrfs/tree-log.c | 8 ++++----
> fs/btrfs/zoned.c | 7 +++----
> 7 files changed, 29 insertions(+), 28 deletions(-)
>
> --
> 2.52.0
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread