summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ordered-data.c
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2019-05-07 10:19:24 +0300
committerDavid Sterba <dsterba@suse.com>2019-07-01 13:34:59 +0200
commitbd80d94efb83acd67d48f9f3f07483c8306085aa (patch)
tree5776fa204d2772616ca1f0fd083334314fe79a86 /fs/btrfs/ordered-data.c
parent23d31bd476d1d096d0f073483547872ec155ab34 (diff)
downloadlinux-bd80d94efb83acd67d48f9f3f07483c8306085aa.tar.bz2
btrfs: Always use a cached extent_state in btrfs_lock_and_flush_ordered_range
In case no cached_state argument is passed to btrfs_lock_and_flush_ordered_range use one locally in the function. This optimises the case when an ordered extent is found since the unlock function will be able to unlock that state directly without searching for it again. Reviewed-by: Josef Bacik <josef@toxicpanda.com> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/ordered-data.c')
-rw-r--r--fs/btrfs/ordered-data.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 37401cc04a6b..df02ed25b7db 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -982,14 +982,26 @@ void btrfs_lock_and_flush_ordered_range(struct extent_io_tree *tree,
struct extent_state **cached_state)
{
struct btrfs_ordered_extent *ordered;
+ struct extent_state *cachedp = NULL;
+
+ if (cached_state)
+ cachedp = *cached_state;
while (1) {
- lock_extent_bits(tree, start, end, cached_state);
+ lock_extent_bits(tree, start, end, &cachedp);
ordered = btrfs_lookup_ordered_range(inode, start,
end - start + 1);
- if (!ordered)
+ if (!ordered) {
+ /*
+ * If no external cached_state has been passed then
+ * decrement the extra ref taken for cachedp since we
+ * aren't exposing it outside of this function
+ */
+ if (!cached_state)
+ refcount_dec(&cachedp->refs);
break;
- unlock_extent_cached(tree, start, end, cached_state);
+ }
+ unlock_extent_cached(tree, start, end, &cachedp);
btrfs_start_ordered_extent(&inode->vfs_inode, ordered, 1);
btrfs_put_ordered_extent(ordered);
}