summaryrefslogtreecommitdiffstats
path: root/fs/btrfs/relocation.c
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2020-06-17 12:10:43 +0300
committerDavid Sterba <dsterba@suse.com>2020-07-27 12:55:27 +0200
commit214e61d07e1ab9e497c081d1bad78d05f7c33abf (patch)
tree60ce7dc7340c1bab1da90bcce4489a4d861d5101 /fs/btrfs/relocation.c
parentc171edd5c8e164bbcb46c61016ef4e88c8130edf (diff)
btrfs: perform data management operations outside of inode lock
btrfs_alloc_data_chunk_ondemand and btrfs_free_reserved_data_space_noquota don't really use the guts of the inodes being passed to them. This implies it's not required to call them under extent lock. Move code around in prealloc_file_extent_cluster to do the heavy, data alloc/free operations outside of the lock. This also makes the 'out' label unnecessary, so remove it. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'fs/btrfs/relocation.c')
-rw-r--r--fs/btrfs/relocation.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index ade45fb4c49a..f7feada38d19 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2584,17 +2584,15 @@ int prealloc_file_extent_cluster(struct inode *inode,
int ret = 0;
u64 prealloc_start = cluster->start - offset;
u64 prealloc_end = cluster->end - offset;
- u64 cur_offset;
+ u64 cur_offset = prealloc_start;
BUG_ON(cluster->start != cluster->boundary[0]);
- inode_lock(inode);
-
ret = btrfs_alloc_data_chunk_ondemand(BTRFS_I(inode),
prealloc_end + 1 - prealloc_start);
if (ret)
- goto out;
+ return ret;
- cur_offset = prealloc_start;
+ inode_lock(inode);
while (nr < cluster->nr) {
start = cluster->boundary[nr] - offset;
if (nr + 1 < cluster->nr)
@@ -2613,11 +2611,11 @@ int prealloc_file_extent_cluster(struct inode *inode,
break;
nr++;
}
+ inode_unlock(inode);
+
if (cur_offset < prealloc_end)
btrfs_free_reserved_data_space_noquota(inode,
prealloc_end + 1 - cur_offset);
-out:
- inode_unlock(inode);
return ret;
}