summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/inode.c
diff options
context:
space:
mode:
authorJosef Bacik <josef@toxicpanda.com>2024-02-12 16:10:44 -0500
committerDavid Sterba <dsterba@suse.com>2024-05-07 21:31:09 +0200
commitc0707c9e1e36d56cef7b3c8de5c5fdcb14f34aa5 (patch)
tree5c4c98e54a05ff26b8b3578c5bfc0321cfb26d78 /fs/btrfs/inode.c
parent7034674b8a070361b3149fdae377f5b80d5f860f (diff)
downloadlinux-c0707c9e1e36d56cef7b3c8de5c5fdcb14f34aa5.tar.gz
linux-c0707c9e1e36d56cef7b3c8de5c5fdcb14f34aa5.tar.bz2
linux-c0707c9e1e36d56cef7b3c8de5c5fdcb14f34aa5.zip
btrfs: push the extent lock into btrfs_run_delalloc_range
We want to limit the scope of the extent lock to be around operations that can change in flight. Currently we hold the extent lock through the entire writepage operation, which isn't really necessary. We want to protect to make sure nobody has updated DELALLOC. In find_lock_delalloc_range we must lock the range in order to validate the contents of our io_tree. However once we've done that we're safe to unlock the range and continue, as we have the page lock already held for the range. We are protected from all operations at this point. * mmap() - we're holding the page lock, thus are protected. * buffered writes - again, we're protected because we take the page lock for the first and last page in our range for buffered writes so we won't create new delalloc ranges in this area. * direct IO - we invalidate pagecache before attempting to write a new area, which requires the page lock, so again are protected once we're holding the page lock on this range. Additionally this behavior actually already exists for compressed, we unlock the range as soon as we start to process the async extents, and re-lock it during compression. So this is completely safe, and makes the locking more consistent. Make this simple by just pushing the extent lock into btrfs_run_delalloc_range. From there followup patches will push the lock further down into its users. Reviewed-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Signed-off-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/inode.c')
-rw-r--r--fs/btrfs/inode.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index d82c453ae9d7..347de4e3a331 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -2250,6 +2250,11 @@ int btrfs_run_delalloc_range(struct btrfs_inode *inode, struct page *locked_page
int ret;
/*
+ * We're unlocked by the different fill functions below.
+ */
+ lock_extent(&inode->io_tree, start, end, NULL);
+
+ /*
* The range must cover part of the @locked_page, or a return of 1
* can confuse the caller.
*/