Skip to content

Commit ff5df9b

Browse files
fdmananamasoncl
authored andcommitted
Btrfs: ioctl, don't re-lock extent range when not necessary
In ioctl.c:lock_extent_range(), after locking our target range, the ordered extent that btrfs_lookup_first_ordered_extent() returns us may not overlap our target range at all. In this case we would just unlock our target range, wait for any new ordered extents that overlap the range to complete, lock again the range and repeat all these steps until we don't get any ordered extent and the delalloc flag isn't set in the io tree for our target range. Therefore just stop if we get an ordered extent that doesn't overlap our target range and the dealalloc flag isn't set for the range in the inode's io tree. Signed-off-by: Filipe David Borba Manana <[email protected]> Signed-off-by: Chris Mason <[email protected]>
1 parent 2c46382 commit ff5df9b

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

fs/btrfs/ioctl.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,10 +2700,15 @@ static inline void lock_extent_range(struct inode *inode, u64 off, u64 len)
27002700
lock_extent(&BTRFS_I(inode)->io_tree, off, off + len - 1);
27012701
ordered = btrfs_lookup_first_ordered_extent(inode,
27022702
off + len - 1);
2703-
if (!ordered &&
2703+
if ((!ordered ||
2704+
ordered->file_offset + ordered->len <= off ||
2705+
ordered->file_offset >= off + len) &&
27042706
!test_range_bit(&BTRFS_I(inode)->io_tree, off,
2705-
off + len - 1, EXTENT_DELALLOC, 0, NULL))
2707+
off + len - 1, EXTENT_DELALLOC, 0, NULL)) {
2708+
if (ordered)
2709+
btrfs_put_ordered_extent(ordered);
27062710
break;
2711+
}
27072712
unlock_extent(&BTRFS_I(inode)->io_tree, off, off + len - 1);
27082713
if (ordered)
27092714
btrfs_put_ordered_extent(ordered);

0 commit comments

Comments
 (0)