btrfs: ordered extent csum list related cleanup
cover btrfs: ordered extent csum list related cleanup
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()
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(-)
Signature · 1 line
2.52.0
PATCH 1/3 btrfs: rename btrfs_ordered_extent::list to csum_list
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.
--- 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(-)
fs/btrfs/inode.c +3 -3
@@ -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;
fs/btrfs/ordered-data.c +5 -5
@@ -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; }
fs/btrfs/ordered-data.h +1 -1
@@ -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;
fs/btrfs/tree-log.c +1 -1
@@ -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;
fs/btrfs/zoned.c +3 -4
@@ -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);
Signature · 1 line
2.52.0
PATCH 2/3 btrfs: make add_pending_csums() to take an ordered extent as parameter
In reply to Qu WenruoThe 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.
--- fs/btrfs/inode.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
fs/btrfs/inode.c +7 -5
@@ -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;
Signature · 1 line
2.52.0
PATCH 3/3 btrfs: rename btrfs_csum_file_blocks() to btrfs_insert_data_csums()
In reply to Qu WenruoThe 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.
--- 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(-)
fs/btrfs/file-item.c +3 -3
@@ -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;
fs/btrfs/file-item.h +3 -3
@@ -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,
fs/btrfs/inode.c +1 -1
@@ -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;
fs/btrfs/tree-log.c +3 -3
@@ -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);
Signature · 1 line
2.52.0
Quoted 7 lines · Qu Wenruo
Trivial changes, please refer to the commit message of each patch.
Qu Wenruo (3):
btrfs: renamebtrfs_ordered_extent::listtocsum_list
btrfs: makeadd_pending_csums()to take an ordered extent as parameter
btrfs: renamebtrfs_csum_file_blocks()tobtrfs_insert_data_csums()
Looks good, thanks.
Quoted 14 lines
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