btrfs: btrfs_dec_test_*_ordered_extent() refactor
v2 cover btrfs: btrfs_dec_test_*_ordered_extent() refactor
This small patchset is btrfs_dec_test_*_ordered_extent() refactor during subpage RW support development.
This is mostly to make btrfs_dev_test_* functions more human readable and prepare it for calling btrfs_dec_test_first_ordered_extent() in btrfs_writepage_endio_finish_ordered() where we can have one or more ordered extents for one bvec.
The first patch is a very safe width reduction, where there is only one assginment. Thus it should be very safe and won't be involved in other call sites.
Changelog:
v2:
- Remove the width reduction in the 2nd patch
The u64->u32 width reduction has too many parts involved, it's really hard to do it cleanly just in one patch.
Remove the width reduction and focus on the existing refactors.
Qu Wenruo (2):
btrfs: make btrfs_dio_private::bytes to be u32
btrfs: refactor btrfs_dec_test_* functions for ordered extents
fs/btrfs/btrfs_inode.h | 2 +- fs/btrfs/inode.c | 5 +-- fs/btrfs/ordered-data.c | 99 ++++++++++++++++++++++------------------- fs/btrfs/ordered-data.h | 10 ++--- 4 files changed, 60 insertions(+), 56 deletions(-)
Signature · 1 line
2.29.2
PATCH v2 1/2 btrfs: make btrfs_dio_private::bytes to be u32
btrfs_dio_private::bytes is only assigned from bio::bi_iter::bi_size, which is no larger than U32.
--- fs/btrfs/btrfs_inode.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/btrfs_inode.h +1 -1
@@ -325,7 +325,7 @@ struct btrfs_dio_private {struct inode *inode;u64 logical_offset;u64 disk_bytenr; -u64 bytes; +u32 bytes;/* * References to this structure. There is one reference per in-flight
Signature · 1 line
2.29.2
PATCH v2 2/2 btrfs: refactor btrfs_dec_test_* functions for ordered extents
In reply to Qu WenruoThe refactors involves the following modifications:
- Return bool instead of int
- Parameter update for @cached of btrfs_dec_test_first_ordered_pending() For btrfs_dec_test_first_ordered_pending(), @cached is only used to return the finished ordered extent.
Rename it to @finished_ret.
- Comments update
* Change one stale comment
Which still refers to btrfs_dec_test_ordered_pending(), but the context is calling btrfs_dec_test_first_ordered_pending().
* Follow the common comment style for both functions
Add more detailed descriptions for parameters and the return value
* Move the reason why test_and_set_bit() is used into the call sites
- Change how the return value is calculated The most anti-human part of the return value is:
if (...)
ret = 1;
...
return ret == 0;This means, when we set ret to 1, the function returns 0. Change the local variable name to @finished, and directly return the value of it.
--- fs/btrfs/inode.c | 5 +-- fs/btrfs/ordered-data.c | 99 ++++++++++++++++++++++------------------- fs/btrfs/ordered-data.h | 10 ++--- 3 files changed, 59 insertions(+), 55 deletions(-)
fs/btrfs/inode.c +1 -4
@@ -7793,10 +7793,7 @@ static void __endio_write_update_ordered(struct btrfs_inode *inode, NULL);btrfs_queue_work (wq, &ordered->work); } -/* -* If btrfs_dec_test_ordered_pending does not find any ordered -* extent in the range, we can exit. -*/ +/* No ordered extent found in the range, exit. */ if (ordered_offset == last_offset)return ;/*
fs/btrfs/ordered-data.c +53 -46
175 lines not on this page · raw message
fs/btrfs/ordered-data.h +5 -5
@@ -152,11 +152,11 @@ btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t)void btrfs_put_ordered_extent (struct btrfs_ordered_extent *entry);void btrfs_remove_ordered_extent (struct btrfs_inode *btrfs_inode,struct btrfs_ordered_extent *entry); -int btrfs_dec_test_ordered_pending (struct btrfs_inode *inode, -struct btrfs_ordered_extent **cached, -u64 file_offset,u64 io_size,int uptodate); -int btrfs_dec_test_first_ordered_pending (struct btrfs_inode *inode, -struct btrfs_ordered_extent **cached, +bool btrfs_dec_test_ordered_pending (struct btrfs_inode *inode, +struct btrfs_ordered_extent **cached, +u64 file_offset,u64 io_size,int uptodate); +bool btrfs_dec_test_first_ordered_pending (struct btrfs_inode *inode, +struct btrfs_ordered_extent **finished_ret,u64 *file_offset,u64 io_size,int uptodate); int btrfs_add_ordered_extent(struct btrfs_inode *inode, u64 file_offset,
Signature · 1 line
2.29.2
Quoted 11 lines · Qu Wenruo
This small patchset is btrfs_dec_test_*_ordered_extent() refactor during subpage RW support development.
This is mostly to make btrfs_dev_test_* functions more human readable and prepare it for calling
btrfs_dec_test_first_ordered_extent()inbtrfs_writepage_endio_finish_ordered()where we can have one or more ordered extents for one bvec.The first patch is a very safe width reduction, where there is only one assginment. Thus it should be very safe and won't be involved in other call sites.
I've added a comment to the 'bytes' and reworded some comments in the 2nd patch, now added to misc-next, thanks.