Commit 60dfdf25 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: Remove 'trans' argument from find_free_dev_extent(_start)

Now that these functions no longer require a handle to transaction to
inspect pending/pinned chunks the argument can be removed. At the same
time also remove any surrounding code which acquired the handle.
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 1c11b63e
...@@ -9915,12 +9915,10 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group_cache *cache) ...@@ -9915,12 +9915,10 @@ void btrfs_dec_block_group_ro(struct btrfs_block_group_cache *cache)
*/ */
int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr) int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr)
{ {
struct btrfs_root *root = fs_info->extent_root;
struct btrfs_block_group_cache *block_group; struct btrfs_block_group_cache *block_group;
struct btrfs_space_info *space_info; struct btrfs_space_info *space_info;
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices; struct btrfs_fs_devices *fs_devices = fs_info->fs_devices;
struct btrfs_device *device; struct btrfs_device *device;
struct btrfs_trans_handle *trans;
u64 min_free; u64 min_free;
u64 dev_min = 1; u64 dev_min = 1;
u64 dev_nr = 0; u64 dev_nr = 0;
...@@ -10019,13 +10017,6 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr) ...@@ -10019,13 +10017,6 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr)
min_free = div64_u64(min_free, dev_min); min_free = div64_u64(min_free, dev_min);
} }
/* We need to do this so that we can look at pending chunks */
trans = btrfs_join_transaction(root);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
goto out;
}
mutex_lock(&fs_info->chunk_mutex); mutex_lock(&fs_info->chunk_mutex);
list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) { list_for_each_entry(device, &fs_devices->alloc_list, dev_alloc_list) {
u64 dev_offset; u64 dev_offset;
...@@ -10036,7 +10027,7 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr) ...@@ -10036,7 +10027,7 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr)
*/ */
if (device->total_bytes > device->bytes_used + min_free && if (device->total_bytes > device->bytes_used + min_free &&
!test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) { !test_bit(BTRFS_DEV_STATE_REPLACE_TGT, &device->dev_state)) {
ret = find_free_dev_extent(trans, device, min_free, ret = find_free_dev_extent(device, min_free,
&dev_offset, NULL); &dev_offset, NULL);
if (!ret) if (!ret)
dev_nr++; dev_nr++;
...@@ -10052,7 +10043,6 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr) ...@@ -10052,7 +10043,6 @@ int btrfs_can_relocate(struct btrfs_fs_info *fs_info, u64 bytenr)
"no space to allocate a new chunk for block group %llu", "no space to allocate a new chunk for block group %llu",
block_group->key.objectid); block_group->key.objectid);
mutex_unlock(&fs_info->chunk_mutex); mutex_unlock(&fs_info->chunk_mutex);
btrfs_end_transaction(trans);
out: out:
btrfs_put_block_group(block_group); btrfs_put_block_group(block_group);
return ret; return ret;
...@@ -11304,34 +11294,14 @@ static int btrfs_trim_free_extents(struct btrfs_device *device, ...@@ -11304,34 +11294,14 @@ static int btrfs_trim_free_extents(struct btrfs_device *device,
while (1) { while (1) {
struct btrfs_fs_info *fs_info = device->fs_info; struct btrfs_fs_info *fs_info = device->fs_info;
struct btrfs_transaction *trans;
u64 bytes; u64 bytes;
ret = mutex_lock_interruptible(&fs_info->chunk_mutex); ret = mutex_lock_interruptible(&fs_info->chunk_mutex);
if (ret) if (ret)
break; break;
ret = down_read_killable(&fs_info->commit_root_sem); ret = find_free_dev_extent_start(device, range->minlen, start,
if (ret) { &start, &len);
mutex_unlock(&fs_info->chunk_mutex);
break;
}
spin_lock(&fs_info->trans_lock);
trans = fs_info->running_transaction;
if (trans)
refcount_inc(&trans->use_count);
spin_unlock(&fs_info->trans_lock);
if (!trans)
up_read(&fs_info->commit_root_sem);
ret = find_free_dev_extent_start(trans, device, range->minlen,
start, &start, &len);
if (trans) {
up_read(&fs_info->commit_root_sem);
btrfs_put_transaction(trans);
}
if (ret) { if (ret) {
mutex_unlock(&fs_info->chunk_mutex); mutex_unlock(&fs_info->chunk_mutex);
......
...@@ -1549,8 +1549,7 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start, ...@@ -1549,8 +1549,7 @@ static bool contains_pending_extent(struct btrfs_device *device, u64 *start,
* But if we don't find suitable free space, it is used to store the size of * But if we don't find suitable free space, it is used to store the size of
* the max free space. * the max free space.
*/ */
int find_free_dev_extent_start(struct btrfs_transaction *transaction, int find_free_dev_extent_start(struct btrfs_device *device, u64 num_bytes,
struct btrfs_device *device, u64 num_bytes,
u64 search_start, u64 *start, u64 *len) u64 search_start, u64 *start, u64 *len)
{ {
struct btrfs_fs_info *fs_info = device->fs_info; struct btrfs_fs_info *fs_info = device->fs_info;
...@@ -1706,13 +1705,11 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction, ...@@ -1706,13 +1705,11 @@ int find_free_dev_extent_start(struct btrfs_transaction *transaction,
return ret; return ret;
} }
int find_free_dev_extent(struct btrfs_trans_handle *trans, int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
struct btrfs_device *device, u64 num_bytes,
u64 *start, u64 *len) u64 *start, u64 *len)
{ {
/* FIXME use last free of some kind */ /* FIXME use last free of some kind */
return find_free_dev_extent_start(trans->transaction, device, return find_free_dev_extent_start(device, num_bytes, 0, start, len);
num_bytes, 0, start, len);
} }
static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans, static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
...@@ -5025,7 +5022,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans, ...@@ -5025,7 +5022,7 @@ static int __btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
if (total_avail == 0) if (total_avail == 0)
continue; continue;
ret = find_free_dev_extent(trans, device, ret = find_free_dev_extent(device,
max_stripe_size * dev_stripes, max_stripe_size * dev_stripes,
&dev_offset, &max_avail); &dev_offset, &max_avail);
if (ret && ret != -ENOSPC) if (ret && ret != -ENOSPC)
......
...@@ -453,11 +453,9 @@ int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); ...@@ -453,11 +453,9 @@ int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info); int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info); int btrfs_check_uuid_tree(struct btrfs_fs_info *fs_info);
int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset); int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset);
int find_free_dev_extent_start(struct btrfs_transaction *transaction, int find_free_dev_extent_start(struct btrfs_device *device, u64 num_bytes,
struct btrfs_device *device, u64 num_bytes,
u64 search_start, u64 *start, u64 *max_avail); u64 search_start, u64 *start, u64 *max_avail);
int find_free_dev_extent(struct btrfs_trans_handle *trans, int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
struct btrfs_device *device, u64 num_bytes,
u64 *start, u64 *max_avail); u64 *start, u64 *max_avail);
void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index); void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info, int btrfs_get_dev_stats(struct btrfs_fs_info *fs_info,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment