Btrfs: change ordered data tree search to use start and length.
PATCH v3 16/18 Btrfs: change ordered data tree search to use start and length.
Users of btrfs_lookup_first_ordered_extent() want to detect only a real overlap, so searching for the range instead of just an address prevents taking references on entries we don't want. This also simplifies the code.
Signed-off-by jim owens <[email protected]>
--- fs/btrfs/file.c | 10 +- fs/btrfs/inode.c | 32 ++--- fs/btrfs/ioctl.c | 2 +- fs/btrfs/ordered-data.c | 289 +++++++++++++++-------------------------------- fs/btrfs/ordered-data.h | 7 +- 5 files changed, 112 insertions(+), 228 deletions(-)
fs/btrfs/file.c +3 -7
@@ -786,11 +786,9 @@ again:lock_extent_bits (&BTRFS_I (inode)->io_tree, start_pos, last_pos -1 ,0 , &cached_state,GFP_NOFS ); - ordered =btrfs_lookup_first_ordered_extent (inode, - last_pos -1 ); -if (ordered && - ordered->file_offset + ordered->len > start_pos && - ordered->file_offset < last_pos) { + ordered =btrfs_lookup_first_ordered_extent (inode, start_pos, + last_pos - start_pos); +if (ordered) {btrfs_put_ordered_extent (ordered); unlock_extent_cached(&BTRFS_I(inode)->io_tree, start_pos, last_pos - 1,
@@ -803,8 +801,6 @@ again: last_pos - start_pos); goto again; } -if (ordered) -btrfs_put_ordered_extent (ordered); clear_extent_bit(&BTRFS_I(inode)->io_tree, start_pos, last_pos - 1, EXTENT_DIRTY | EXTENT_DELALLOC |
fs/btrfs/inode.c +13 -19
@@ -5331,7 +5331,7 @@ void btrfs_destroy_inode(struct inode *inode)spin_unlock (&root->list_lock);while (1 ) { - ordered =btrfs_lookup_first_ordered_extent (inode, (u64)-1 ); + ordered =btrfs_lookup_first_ordered_extent (inode,0 , (u64)-1 );if (!ordered)break ;else {
@@ -5869,25 +5869,19 @@ static long btrfs_fallocate(struct inode *inode, int mode,lock_extent_bits (&BTRFS_I (inode)->io_tree, alloc_start, locked_end,0 , &cached_state,GFP_NOFS ); ordered =btrfs_lookup_first_ordered_extent (inode, - alloc_end -1 ); -if (ordered && - ordered->file_offset + ordered->len > alloc_start && - ordered->file_offset < alloc_end) { -btrfs_put_ordered_extent (ordered); -unlock_extent_cached (&BTRFS_I (inode)->io_tree, - alloc_start, locked_end, - &cached_state,GFP_NOFS ); -/* -* we can't wait on the range with the transaction -* running or with the extent lock held -*/ -btrfs_wait_ordered_range (inode, alloc_start, - alloc_end - alloc_start); - }else { -if (ordered) -btrfs_put_ordered_extent (ordered); + alloc_start, alloc_end - alloc_start); +if (!ordered)break ; - } + +btrfs_put_ordered_extent (ordered); +unlock_extent_cached (&BTRFS_I (inode)->io_tree, alloc_start, + locked_end, &cached_state,GFP_NOFS ); +/* +* we can't wait on the range with the transaction +* running or with the extent lock held +*/ +btrfs_wait_ordered_range (inode, alloc_start, + alloc_end - alloc_start); } cur_offset = alloc_start;
fs/btrfs/ioctl.c +1 -1
@@ -1532,7 +1532,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,while (1 ) {struct btrfs_ordered_extent *ordered;lock_extent (&BTRFS_I (src)->io_tree, off, off+len,GFP_NOFS ); - ordered =btrfs_lookup_first_ordered_extent (inode, off+len); + ordered =btrfs_lookup_first_ordered_extent (inode, off, len);if (BTRFS_I (src)->delalloc_bytes ==0 && !ordered)break ;unlock_extent (&BTRFS_I (src)->io_tree, off, off+len,GFP_NOFS );
fs/btrfs/ordered-data.c +91 -198
399 lines not on this page · raw message
fs/btrfs/ordered-data.h +4 -3
@@ -149,11 +149,12 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode,void btrfs_start_ordered_extent (struct inode *inode,struct btrfs_ordered_extent *entry,int wait);int btrfs_wait_ordered_range (struct inode *inode,u64 start,u64 len); -struct btrfs_ordered_extent * -btrfs_lookup_first_ordered_extent (struct inode * inode,u64 file_offset); +struct btrfs_ordered_extent *btrfs_lookup_first_ordered_extent ( +struct inode *inode,u64 file_offset,u64 len);int btrfs_ordered_update_i_size (struct inode *inode,u64 offset,struct btrfs_ordered_extent *ordered); -int btrfs_find_ordered_sum (struct inode *inode,u64 offset,u64 disk_bytenr,u32 *sum); +int btrfs_find_ordered_sum (struct inode *inode,u64 offset,u64 disk_bytenr, +u32 *sum);int btrfs_run_ordered_operations (struct btrfs_root *root,int wait); int btrfs_add_ordered_operation(struct btrfs_trans_handle *trans, struct btrfs_root *root,
Signature · 1 line
1.6.3.3