Skip to content

Commit

Permalink
Btrfs: ioctl, don't re-lock extent range when not necessary
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
fdmanana authored and masoncl committed Jun 10, 2014
1 parent 2c46382 commit ff5df9b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions fs/btrfs/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2700,10 +2700,15 @@ static inline void lock_extent_range(struct inode *inode, u64 off, u64 len)
lock_extent(&BTRFS_I(inode)->io_tree, off, off + len - 1);
ordered = btrfs_lookup_first_ordered_extent(inode,
off + len - 1);
if (!ordered &&
if ((!ordered ||
ordered->file_offset + ordered->len <= off ||
ordered->file_offset >= off + len) &&
!test_range_bit(&BTRFS_I(inode)->io_tree, off,
off + len - 1, EXTENT_DELALLOC, 0, NULL))
off + len - 1, EXTENT_DELALLOC, 0, NULL)) {
if (ordered)
btrfs_put_ordered_extent(ordered);
break;
}
unlock_extent(&BTRFS_I(inode)->io_tree, off, off + len - 1);
if (ordered)
btrfs_put_ordered_extent(ordered);
Expand Down

0 comments on commit ff5df9b

Please sign in to comment.