Message ID | 5ba3b6e48c1e7433b1e38ae315713d7b31813730.1712933005.git.fdmanana@suse.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | btrfs: some speedup for NOCOW write path and cleanups | expand |
在 2024/4/13 00:33, fdmanana@kernel.org 写道: > From: Filipe Manana <fdmanana@suse.com> > > There's no need to use a temporary list to add the checksums, we can just > add them to input list and then on error delete and free any checksums > that were added. So simplify and remove the temporary list. > > Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Initially I'm not sure if this would bring a behavior change as csum tree search failure would free any existing csum items, but all the call sites pass an empty list into the function anyway, so it's completely fine. Thanks, Qu > --- > fs/btrfs/file-item.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c > index 0712a0aa2dd0..c2799325706f 100644 > --- a/fs/btrfs/file-item.c > +++ b/fs/btrfs/file-item.c > @@ -470,7 +470,6 @@ int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end, > struct extent_buffer *leaf; > struct btrfs_ordered_sum *sums; > struct btrfs_csum_item *item; > - LIST_HEAD(tmplist); > int ret; > > ASSERT(IS_ALIGNED(start, fs_info->sectorsize) && > @@ -572,18 +571,17 @@ int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end, > bytes_to_csum_size(fs_info, size)); > > start += size; > - list_add_tail(&sums->list, &tmplist); > + list_add_tail(&sums->list, list); > } > path->slots[0]++; > } > ret = 0; > fail: > - while (ret < 0 && !list_empty(&tmplist)) { > - sums = list_entry(tmplist.next, struct btrfs_ordered_sum, list); > + while (ret < 0 && !list_empty(list)) { > + sums = list_entry(list->next, struct btrfs_ordered_sum, list); > list_del(&sums->list); > kfree(sums); > } > - list_splice_tail(&tmplist, list); > > btrfs_free_path(path); > return ret;
diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 0712a0aa2dd0..c2799325706f 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -470,7 +470,6 @@ int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end, struct extent_buffer *leaf; struct btrfs_ordered_sum *sums; struct btrfs_csum_item *item; - LIST_HEAD(tmplist); int ret; ASSERT(IS_ALIGNED(start, fs_info->sectorsize) && @@ -572,18 +571,17 @@ int btrfs_lookup_csums_list(struct btrfs_root *root, u64 start, u64 end, bytes_to_csum_size(fs_info, size)); start += size; - list_add_tail(&sums->list, &tmplist); + list_add_tail(&sums->list, list); } path->slots[0]++; } ret = 0; fail: - while (ret < 0 && !list_empty(&tmplist)) { - sums = list_entry(tmplist.next, struct btrfs_ordered_sum, list); + while (ret < 0 && !list_empty(list)) { + sums = list_entry(list->next, struct btrfs_ordered_sum, list); list_del(&sums->list); kfree(sums); } - list_splice_tail(&tmplist, list); btrfs_free_path(path); return ret;