Skip to content

Commit

Permalink
btrfs: perform data management operations outside of inode lock
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nikolay Borisov authored and David Sterba committed Jul 27, 2020
1 parent c171edd commit 214e61d
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions fs/btrfs/relocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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;
}

Expand Down

0 comments on commit 214e61d

Please sign in to comment.