diff options
author | Stefan Roesch <shr@fb.com> | 2022-09-12 22:27:48 +0300 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2022-09-29 18:08:28 +0300 |
commit | 2fcab928ccc2bac0c22e3b3b04f5acf0dc8de96b (patch) | |
tree | 35728187a6114ba995bf624c036848abe9ad967f /fs/btrfs/file.c | |
parent | fc2260001232766c1836d5a6053913194ce23f88 (diff) | |
download | linux-2fcab928ccc2bac0c22e3b3b04f5acf0dc8de96b.tar.xz |
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 <fdmanana@suse.com>
Signed-off-by: Stefan Roesch <shr@fb.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/file.c')
-rw-r--r-- | fs/btrfs/file.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c index 2181b549df4e..5113e3d60f78 100644 --- a/fs/btrfs/file.c +++ b/fs/btrfs/file.c @@ -1439,7 +1439,7 @@ static noinline int lock_and_cleanup_extent_if_need(struct btrfs_inode *inode, struct page **pages, size_t num_pages, loff_t pos, size_t write_bytes, - u64 *lockstart, u64 *lockend, + u64 *lockstart, u64 *lockend, bool nowait, struct extent_state **cached_state) { 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, if (start_pos < inode->vfs_inode.i_size) { struct btrfs_ordered_extent *ordered; - lock_extent(&inode->io_tree, start_pos, last_pos, cached_state); + if (nowait) { + if (!try_lock_extent(&inode->io_tree, start_pos, last_pos)) { + for (i = 0; i < num_pages; i++) { + unlock_page(pages[i]); + put_page(pages[i]); + pages[i] = NULL; + } + + return -EAGAIN; + } + } else { + lock_extent(&inode->io_tree, start_pos, last_pos, cached_state); + } + ordered = btrfs_lookup_ordered_range(inode, start_pos, last_pos - start_pos + 1); if (ordered && @@ -1752,7 +1765,7 @@ again: extents_locked = lock_and_cleanup_extent_if_need( BTRFS_I(inode), pages, num_pages, pos, write_bytes, &lockstart, - &lockend, &cached_state); + &lockend, false, &cached_state); if (extents_locked < 0) { if (extents_locked == -EAGAIN) goto again; |