Skip to content

Commit 2fcab92

Browse files
Stefan Roeschkdave
authored andcommitted
btrfs: make lock_and_cleanup_extent_if_need nowait compatible
Add the nowait parameter to lock_and_cleanup_extent_if_need(). If the nowait parameter is specified we try to lock the extent in nowait mode. Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Stefan Roesch <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent fc22600 commit 2fcab92

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

fs/btrfs/file.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,7 +1439,7 @@ static noinline int
14391439
lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages,
14401440
size_t num_pages, loff_t pos,
14411441
size_t write_bytes,
1442-
u64 *lockstart, u64 *lockend,
1442+
u64 *lockstart, u64 *lockend, bool nowait,
14431443
struct extent_state **cached_state)
14441444
{
14451445
struct btrfs_fs_info *fs_info = inode->root->fs_info;
@@ -1454,7 +1454,20 @@ lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages,
14541454
if (start_pos < inode->vfs_inode.i_size) {
14551455
struct btrfs_ordered_extent *ordered;
14561456

1457-
lock_extent(&inode->io_tree, start_pos, last_pos, cached_state);
1457+
if (nowait) {
1458+
if (!try_lock_extent(&inode->io_tree, start_pos, last_pos)) {
1459+
for (i = 0; i < num_pages; i++) {
1460+
unlock_page(pages[i]);
1461+
put_page(pages[i]);
1462+
pages[i] = NULL;
1463+
}
1464+
1465+
return -EAGAIN;
1466+
}
1467+
} else {
1468+
lock_extent(&inode->io_tree, start_pos, last_pos, cached_state);
1469+
}
1470+
14581471
ordered = btrfs_lookup_ordered_range(inode, start_pos,
14591472
last_pos - start_pos + 1);
14601473
if (ordered &&
@@ -1752,7 +1765,7 @@ static noinline ssize_t btrfs_buffered_write(struct kiocb *iocb,
17521765
extents_locked = lock_and_cleanup_extent_if_need(
17531766
BTRFS_I(inode), pages,
17541767
num_pages, pos, write_bytes, &lockstart,
1755-
&lockend, &cached_state);
1768+
&lockend, false, &cached_state);
17561769
if (extents_locked < 0) {
17571770
if (extents_locked == -EAGAIN)
17581771
goto again;

0 commit comments

Comments
 (0)