btrfs-progs: volumes: Refactor btrfs_alloc_dev_extent() into two functions
We have btrfs_alloc_dev_extent() accepting @convert flag to toggle special handling for convert. However the @convert flag only determines whether we call find_free_dev_extent(), and we may later need to insert dev extents without searching dev tree. So refactor btrfs_alloc_dev_extent() into 2 functions, - btrfs_alloc_dev_extent(), which will try to find free dev extent, and - btrfs_insert_dev_extent(), which will just inserts a dev extent For implementation, btrfs_alloc_dev_extent() will call btrfs_insert_dev_extent() anyway, so there's no duplicated code. This removes the need of @convert parameter, and make btrfs_insert_dev_extent() public for later usage. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
9a65b425bb
commit
e6c1fa297a
48
volumes.c
48
volumes.c
|
@ -530,10 +530,12 @@ static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
|
|||
return find_free_dev_extent_start(device, num_bytes, 0, start, len);
|
||||
}
|
||||
|
||||
static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_device *device,
|
||||
u64 chunk_offset, u64 num_bytes, u64 *start,
|
||||
int convert)
|
||||
/*
|
||||
* Insert one device extent into the fs.
|
||||
*/
|
||||
int btrfs_insert_dev_extent(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_device *device,
|
||||
u64 chunk_offset, u64 num_bytes, u64 start)
|
||||
{
|
||||
int ret;
|
||||
struct btrfs_path *path;
|
||||
|
@ -546,18 +548,8 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
|
|||
if (!path)
|
||||
return -ENOMEM;
|
||||
|
||||
/*
|
||||
* For convert case, just skip search free dev_extent, as caller
|
||||
* is responsible to make sure it's free.
|
||||
*/
|
||||
if (!convert) {
|
||||
ret = find_free_dev_extent(device, num_bytes, start, NULL);
|
||||
if (ret)
|
||||
goto err;
|
||||
}
|
||||
|
||||
key.objectid = device->devid;
|
||||
key.offset = *start;
|
||||
key.offset = start;
|
||||
key.type = BTRFS_DEV_EXTENT_KEY;
|
||||
ret = btrfs_insert_empty_item(trans, root, path, &key,
|
||||
sizeof(*extent));
|
||||
|
@ -583,6 +575,22 @@ err:
|
|||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate one free dev extent and insert it into the fs.
|
||||
*/
|
||||
static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_device *device,
|
||||
u64 chunk_offset, u64 num_bytes, u64 *start)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = find_free_dev_extent(device, num_bytes, start, NULL);
|
||||
if (ret)
|
||||
return ret;
|
||||
return btrfs_insert_dev_extent(trans, device, chunk_offset, num_bytes,
|
||||
*start);
|
||||
}
|
||||
|
||||
static int find_next_chunk(struct btrfs_fs_info *fs_info, u64 *offset)
|
||||
{
|
||||
struct btrfs_root *root = fs_info->chunk_root;
|
||||
|
@ -1107,7 +1115,7 @@ again:
|
|||
list_move_tail(&device->dev_list, dev_list);
|
||||
|
||||
ret = btrfs_alloc_dev_extent(trans, device, key.offset,
|
||||
calc_size, &dev_offset, 0);
|
||||
calc_size, &dev_offset);
|
||||
if (ret < 0)
|
||||
goto out_chunk_map;
|
||||
|
||||
|
@ -1241,8 +1249,12 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
|
|||
while (index < num_stripes) {
|
||||
struct btrfs_stripe *stripe;
|
||||
|
||||
ret = btrfs_alloc_dev_extent(trans, device, key.offset,
|
||||
calc_size, &dev_offset, convert);
|
||||
if (convert)
|
||||
ret = btrfs_insert_dev_extent(trans, device, key.offset,
|
||||
calc_size, dev_offset);
|
||||
else
|
||||
ret = btrfs_alloc_dev_extent(trans, device, key.offset,
|
||||
calc_size, &dev_offset);
|
||||
BUG_ON(ret);
|
||||
|
||||
device->bytes_used += calc_size;
|
||||
|
|
|
@ -268,6 +268,9 @@ int btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
|
|||
int flags);
|
||||
int btrfs_close_devices(struct btrfs_fs_devices *fs_devices);
|
||||
void btrfs_close_all_devices(void);
|
||||
int btrfs_insert_dev_extent(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_device *device,
|
||||
u64 chunk_offset, u64 num_bytes, u64 start);
|
||||
int btrfs_add_device(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_device *device);
|
||||
|
|
Loading…
Reference in New Issue