Cleanups for later btrfs_alloc_chunk() rework
cover Cleanups for later btrfs_alloc_chunk() rework
Just small cleanups for incoming btrfs_alloc_chunk() rework, which is designed to allow btrfs_alloc_chunk() to be able to alloc meta chunk, even current meta chunks are already full.
The cleanups are quite small, most of them are just removing unnecessary parameters, and make some function static.
Qu Wenruo (5):
btrfs-progs: Use bool parameter to determine if we're allocating data
extent
btrfs-progs: volumes: Make find_free_dev_extent_start static
btrfs-progs: volumes: Remove unnecessary trans parameter
btrfs-progs: volumes: Remove unnecessary parameters when allocating
device extent
btrfs-progs: Remove unnecessary parameter for btrfs_add_block_group
cmds-check.c | 4 ++-- convert/main.c | 4 +--- ctree.h | 7 +++---- extent-tree.c | 31 ++++++++++++++++--------------- mkfs/main.c | 14 ++++---------- volumes.c | 35 ++++++++++++++--------------------- 6 files changed, 40 insertions(+), 55 deletions(-)
Signature · 1 line
2.15.1
PATCH 1/5 btrfs-progs: Use bool parameter to determine if we're allocating data extent
btrfs_reserve_extent() uses int @data to determine if we're allocating data extent, while reuse the parameter later to pass it as profile (data/meta/sys).
It's a little confusing, this patch will follow kernel parameter to use bool @is_data to replace it.
And in btrfs_reserve_extent(), use dedicated u64 @profile.
--- ctree.h | 2 +- extent-tree.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-)
ctree.h +1 -1
@@ -2435,7 +2435,7 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans,struct btrfs_root *root, u64 num_bytes, u64 empty_size, u64 hint_byte, u64 search_end, - struct btrfs_key *ins, int data); + struct btrfs_key *ins, bool is_data);int btrfs_fix_block_accounting (struct btrfs_trans_handle *trans,struct btrfs_root *root);void btrfs_pin_extent (struct btrfs_fs_info *fs_info,u64 bytenr,u64 num_bytes);
extent-tree.c +9 -8
@@ -2652,36 +2652,37 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans,struct btrfs_root *root, u64 num_bytes, u64 empty_size, u64 hint_byte, u64 search_end, - struct btrfs_key *ins, int data) + struct btrfs_key *ins, bool is_data) { int ret;u64 search_start =0 ;u64 alloc_profile; +u64 profile;struct btrfs_fs_info *info = root->fs_info; -if (data) { +if (is_data) { alloc_profile = info->avail_data_alloc_bits & info->data_alloc_profile; - data =BTRFS_BLOCK_GROUP_DATA | alloc_profile; + profile =BTRFS_BLOCK_GROUP_DATA | alloc_profile; }else if (info->system_allocs ==1 || root == info->chunk_root) { alloc_profile = info->avail_system_alloc_bits & info->system_alloc_profile; - data =BTRFS_BLOCK_GROUP_SYSTEM | alloc_profile; + profile =BTRFS_BLOCK_GROUP_SYSTEM | alloc_profile; }else { alloc_profile = info->avail_metadata_alloc_bits & info->metadata_alloc_profile; - data =BTRFS_BLOCK_GROUP_METADATA | alloc_profile; + profile =BTRFS_BLOCK_GROUP_METADATA | alloc_profile; }if (root->ref_cows) { -if (!(data &BTRFS_BLOCK_GROUP_METADATA )) { +if (!(profile &BTRFS_BLOCK_GROUP_METADATA )) { ret =do_chunk_alloc (trans, info, num_bytes,BTRFS_BLOCK_GROUP_METADATA );BUG_ON (ret); } ret =do_chunk_alloc (trans, info, - num_bytes +SZ_2M , data); + num_bytes +SZ_2M , profile);BUG_ON (ret); }
@@ -2689,7 +2690,7 @@ int btrfs_reserve_extent(struct btrfs_trans_handle *trans, ret =find_free_extent (trans, root, num_bytes, empty_size, search_start, search_end, hint_byte, ins, trans->alloc_exclude_start, - trans->alloc_exclude_nr, data); + trans->alloc_exclude_nr, profile);if (ret <0 )return ret; clear_extent_dirty(&info->free_space_cache,
Signature · 1 line
2.15.1
PATCH 2/5 btrfs-progs: volumes: Make find_free_dev_extent_start static
In reply to Qu WenruoThe function is not used by anyone else outside of volumes.c, make it static.
--- volumes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
volumes.c +1 -1
@@ -457,7 +457,7 @@ out:return ret; } -int find_free_dev_extent (struct btrfs_trans_handle *trans, +static int find_free_dev_extent (struct btrfs_trans_handle *trans,struct btrfs_device *device,u64 num_bytes,u64 *start) {
Signature · 1 line
2.15.1
PATCH 3/5 btrfs-progs: volumes: Remove unnecessary trans parameter
In reply to Qu WenruoRemove @trans parameter for find_free_dev_extent_start() and its callers.
The function itself is doing read-only tree search, no use of transaction.
--- volumes.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
volumes.c +7 -10
@@ -316,9 +316,9 @@ int btrfs_scan_one_device(int fd, const char *path,* But if we don't find suitable free space, it is used to store the size of * the max free space. */ -static int find_free_dev_extent_start (struct btrfs_trans_handle *trans, -struct btrfs_device *device,u64 num_bytes, -u64 search_start,u64 *start,u64 *len) +static int find_free_dev_extent_start (struct btrfs_device *device, +u64 num_bytes,u64 search_start, +u64 *start,u64 *len) {struct btrfs_key key;struct btrfs_root *root = device->dev_root;
@@ -457,13 +457,11 @@ out:return ret; } -static int find_free_dev_extent (struct btrfs_trans_handle *trans, -struct btrfs_device *device,u64 num_bytes, -u64 *start) +static int find_free_dev_extent (struct btrfs_device *device,u64 num_bytes, +u64 *start) {/* FIXME use last free of some kind */ -return find_free_dev_extent_start (trans, device, - num_bytes,0 , start,NULL ); +return find_free_dev_extent_start (device, num_bytes,0 , start,NULL ); } static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,
@@ -488,8 +486,7 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans,* is responsible to make sure it's free. */ if (!convert) { - ret =find_free_dev_extent (trans, device, num_bytes, - start); + ret =find_free_dev_extent (device, num_bytes, start);if (ret) goto err; }
Signature · 1 line
2.15.1
PATCH 4/5 btrfs-progs: volumes: Remove unnecessary parameters when allocating device extent
In reply to Qu Wenruo@chunk_tree and @chunk_objectid of device extent is fixed to BTRFS_CHUNK_TREE_OBJECTID and BTRFS_FIRST_CHUNK_TREE_OBJECTID respectively.
There is no need to pass them as parameter explicitly.
--- volumes.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
volumes.c +7 -11
@@ -466,9 +466,8 @@ static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,static int btrfs_alloc_dev_extent (struct btrfs_trans_handle *trans,struct btrfs_device *device, -u64 chunk_tree,u64 chunk_objectid, -u64 chunk_offset, -u64 num_bytes,u64 *start,int convert) +u64 chunk_offset,u64 num_bytes,u64 *start, +int convert) {int ret;struct btrfs_path *path;
@@ -501,8 +500,9 @@ static int btrfs_alloc_dev_extent(struct btrfs_trans_handle *trans, leaf = path->nodes[0 ]; extent =btrfs_item_ptr (leaf, path->slots[0 ], struct btrfs_dev_extent); -btrfs_set_dev_extent_chunk_tree (leaf, extent, chunk_tree); -btrfs_set_dev_extent_chunk_objectid (leaf, extent, chunk_objectid); +btrfs_set_dev_extent_chunk_tree (leaf, extent,BTRFS_CHUNK_TREE_OBJECTID ); +btrfs_set_dev_extent_chunk_objectid (leaf, extent, +BTRFS_FIRST_CHUNK_TREE_OBJECTID );btrfs_set_dev_extent_chunk_offset (leaf, extent, chunk_offset); write_extent_buffer(leaf, root->fs_info->chunk_tree_uuid,
@@ -1039,9 +1039,7 @@ again: (index == num_stripes - 1))list_move_tail (&device->dev_list, dev_list); - ret =btrfs_alloc_dev_extent (trans, device, - info->chunk_root->root_key.objectid, -BTRFS_FIRST_CHUNK_TREE_OBJECTID , key.offset, + ret =btrfs_alloc_dev_extent (trans, device, key.offset, calc_size, &dev_offset,0 );if (ret <0 ) goto out_chunk_map;
@@ -1176,9 +1174,7 @@ 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, - info->chunk_root->root_key.objectid, -BTRFS_FIRST_CHUNK_TREE_OBJECTID , key.offset, + ret =btrfs_alloc_dev_extent (trans, device, key.offset, calc_size, &dev_offset, convert);BUG_ON (ret);
Signature · 1 line
2.15.1
PATCH 5/5 btrfs-progs: Remove unnecessary parameter for btrfs_add_block_group
In reply to Qu Wenruo@chunk_objectid of btrfs_make_block_group() function is always fixed to BTRFS_FIRST_FREE_OBJECTID, so there is no need to pass it as parameter explicitly.
--- cmds-check.c | 4 ++-- convert/main.c | 4 +--- ctree.h | 5 ++--- extent-tree.c | 14 +++++++------- mkfs/main.c | 14 ++++---------- 5 files changed, 16 insertions(+), 25 deletions(-)
cmds-check.c +2 -2
@@ -13036,7 +13036,7 @@ static int repair_chunk_item(struct btrfs_trans_handle *trans,if (err &REFERENCER_MISSING ) { ret =btrfs_make_block_group (trans, chunk_root->fs_info,0 , - type, chunk_key.objectid, chunk_key.offset, length); + type, chunk_key.offset, length);if (ret) {error ("fail to add block group item[%llu %llu]" , chunk_key.offset, length);
@@ -13637,7 +13637,7 @@ static int reset_block_groups(struct btrfs_fs_info *fs_info) chunk = btrfs_item_ptr(leaf, path.slots[0], struct btrfs_chunk);btrfs_add_block_group (fs_info,0 ,btrfs_chunk_type (leaf, chunk), - key.objectid, key.offset, + key.offset,btrfs_chunk_length (leaf, chunk));set_extent_dirty (&fs_info->free_space_cache, key.offset, key.offset +btrfs_chunk_length (leaf, chunk));
convert/main.c +1 -3
@@ -916,9 +916,7 @@ static int make_convert_data_block_groups(struct btrfs_trans_handle *trans,if (ret <0 )break ; ret =btrfs_make_block_group (trans, fs_info,0 , -BTRFS_BLOCK_GROUP_DATA , -BTRFS_FIRST_CHUNK_TREE_OBJECTID , - cur, len); +BTRFS_BLOCK_GROUP_DATA , cur, len);if (ret <0 )break ; cur += len;
ctree.h +2 -3
@@ -2497,11 +2497,10 @@ int btrfs_free_block_groups(struct btrfs_fs_info *info);int btrfs_read_block_groups (struct btrfs_root *root);struct btrfs_block_group_cache *btrfs_add_block_group (struct btrfs_fs_info *fs_info,u64 bytes_used,u64 type, -u64 chunk_objectid,u64 chunk_offset,u64 size); +u64 chunk_offset,u64 size);int btrfs_make_block_group (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,u64 bytes_used, -u64 type,u64 chunk_objectid,u64 chunk_offset, -u64 size); +u64 type,u64 chunk_offset,u64 size);int btrfs_make_block_groups (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info); int btrfs_update_block_group(struct btrfs_trans_handle *trans,
extent-tree.c +7 -7
@@ -1916,7 +1916,7 @@ static int do_chunk_alloc(struct btrfs_trans_handle *trans,BUG_ON (ret); ret =btrfs_make_block_group (trans, fs_info,0 , space_info->flags, -BTRFS_FIRST_CHUNK_TREE_OBJECTID , start, num_bytes); + start, num_bytes);BUG_ON (ret);return 0 ; }
@@ -3312,7 +3312,7 @@ error:struct btrfs_block_group_cache *btrfs_add_block_group (struct btrfs_fs_info *fs_info,u64 bytes_used,u64 type, -u64 chunk_objectid,u64 chunk_offset,u64 size) +u64 chunk_offset,u64 size) {int ret;int bit =0 ;
@@ -3328,7 +3328,8 @@ btrfs_add_block_group(struct btrfs_fs_info *fs_info, u64 bytes_used, u64 type, cache->key.type =BTRFS_BLOCK_GROUP_ITEM_KEY ;btrfs_set_block_group_used (&cache->item, bytes_used); -btrfs_set_block_group_chunk_objectid (&cache->item, chunk_objectid); +btrfs_set_block_group_chunk_objectid (&cache->item, +BTRFS_FIRST_CHUNK_TREE_OBJECTID ); cache->flags = type;btrfs_set_block_group_flags (&cache->item, type);
@@ -3353,15 +3354,14 @@ btrfs_add_block_group(struct btrfs_fs_info *fs_info, u64 bytes_used, u64 type,int btrfs_make_block_group (struct btrfs_trans_handle *trans,struct btrfs_fs_info *fs_info,u64 bytes_used, -u64 type,u64 chunk_objectid,u64 chunk_offset, -u64 size) +u64 type,u64 chunk_offset,u64 size) {int ret;struct btrfs_root *extent_root = fs_info->extent_root;struct btrfs_block_group_cache *cache; - cache =btrfs_add_block_group (fs_info, bytes_used, type, - chunk_objectid, chunk_offset, size); + cache =btrfs_add_block_group (fs_info, bytes_used, type, chunk_offset, + size); ret =btrfs_insert_item (trans, extent_root, &cache->key, &cache->item,sizeof (cache->item));BUG_ON (ret);
mkfs/main.c +4 -10
@@ -83,7 +83,6 @@ static int create_metadata_block_groups(struct btrfs_root *root, int mixed, root->fs_info->system_allocs =1 ; ret =btrfs_make_block_group (trans, fs_info, bytes_used,BTRFS_BLOCK_GROUP_SYSTEM , -BTRFS_FIRST_CHUNK_TREE_OBJECTID ,0 ,BTRFS_MKFS_SYSTEM_GROUP_SIZE ); allocation->system +=BTRFS_MKFS_SYSTEM_GROUP_SIZE ;if (ret)
@@ -103,7 +102,6 @@ static int create_metadata_block_groups(struct btrfs_root *root, int mixed, ret =btrfs_make_block_group (trans, fs_info,0 ,BTRFS_BLOCK_GROUP_METADATA |BTRFS_BLOCK_GROUP_DATA , -BTRFS_FIRST_CHUNK_TREE_OBJECTID , chunk_start, chunk_size);if (ret)return ret;
@@ -120,7 +118,6 @@ static int create_metadata_block_groups(struct btrfs_root *root, int mixed,return ret; ret =btrfs_make_block_group (trans, fs_info,0 ,BTRFS_BLOCK_GROUP_METADATA , -BTRFS_FIRST_CHUNK_TREE_OBJECTID , chunk_start, chunk_size); allocation->metadata += chunk_size;if (ret)
@@ -155,7 +152,6 @@ static int create_data_block_groups(struct btrfs_trans_handle *trans,return ret; ret =btrfs_make_block_group (trans, fs_info,0 ,BTRFS_BLOCK_GROUP_DATA , -BTRFS_FIRST_CHUNK_TREE_OBJECTID , chunk_start, chunk_size); allocation->data += chunk_size;if (ret)
@@ -264,8 +260,7 @@ static int create_one_raid_group(struct btrfs_trans_handle *trans,return ret; ret =btrfs_make_block_group (trans, fs_info,0 , - type,BTRFS_FIRST_CHUNK_TREE_OBJECTID , - chunk_start, chunk_size); + type, chunk_start, chunk_size); type &=BTRFS_BLOCK_GROUP_TYPE_MASK ;if (type ==BTRFS_BLOCK_GROUP_DATA ) {
@@ -1012,8 +1007,8 @@ static int create_chunks(struct btrfs_trans_handle *trans,if (ret)return ret; ret =btrfs_make_block_group (trans, fs_info,0 , - meta_type,BTRFS_FIRST_CHUNK_TREE_OBJECTID , - chunk_start, chunk_size); + meta_type, chunk_start, + chunk_size); allocation->metadata += chunk_size;if (ret)return ret;
@@ -1029,8 +1024,7 @@ static int create_chunks(struct btrfs_trans_handle *trans,if (ret)return ret; ret =btrfs_make_block_group (trans, fs_info,0 , - data_type,BTRFS_FIRST_CHUNK_TREE_OBJECTID , - chunk_start, size_of_data); + data_type, chunk_start, size_of_data); allocation->data += size_of_data;if (ret)return ret;
Signature · 1 line
2.15.1
Re: [PATCH 5/5] btrfs-progs: Remove unnecessary parameter for btrfs_add_block_group
Quoted 5 lines · Qu Wenruo
@chunk_objectid of
btrfs_make_block_group()function is always fixed toBTRFS_FIRST_FREE_OBJECTID, so there is no need to pass it as parameter explicitly.Signed-off-by Qu Wenruo <[email protected]>
Can you please refresh this patch on top of current devel? There were some merge conflicts due to other patches, the rest has been applied. Thanks.
Quoted 7 lines · Qu Wenruo
Just small cleanups for incoming
btrfs_alloc_chunk()rework, which is designed to allowbtrfs_alloc_chunk()to be able to alloc meta chunk, even current meta chunks are already full.The cleanups are quite small, most of them are just removing unnecessary parameters, and make some function static.
Quoted 9 lines
Qu Wenruo (5):
btrfs-progs: Use bool parameter to determine if we're allocating data
extent
btrfs-progs: volumes: Makefind_free_dev_extent_startstatic
btrfs-progs: volumes: Remove unnecessary trans parameter
btrfs-progs: volumes: Remove unnecessary parameters when allocating
device extent
btrfs-progs: Remove unnecessary parameter forbtrfs_add_block_group
The series looks good to me.
Quoted 8 lines
cmds-check.c | 4 ++-- convert/main.c | 4 +--- ctree.h | 7 +++---- extent-tree.c | 31 ++++++++++++++++--------------- mkfs/main.c | 14 ++++---------- volumes.c | 35 ++++++++++++++--------------------- 6 files changed, 40 insertions(+), 55 deletions(-)
Quoted 7 lines · Qu Wenruo
Just small cleanups for incoming
btrfs_alloc_chunk()rework, which is designed to allowbtrfs_alloc_chunk()to be able to alloc meta chunk, even current meta chunks are already full.The cleanups are quite small, most of them are just removing unnecessary parameters, and make some function static.
Quoted 9 lines
Qu Wenruo (5):
btrfs-progs: Use bool parameter to determine if we're allocating data
extent
btrfs-progs: volumes: Makefind_free_dev_extent_startstatic
btrfs-progs: volumes: Remove unnecessary trans parameter
btrfs-progs: volumes: Remove unnecessary parameters when allocating
device extent
btrfs-progs: Remove unnecessary parameter forbtrfs_add_block_group
For the whole series:
Quoted 8 lines
cmds-check.c | 4 ++-- convert/main.c | 4 +--- ctree.h | 7 +++---- extent-tree.c | 31 ++++++++++++++++--------------- mkfs/main.c | 14 ++++---------- volumes.c | 35 ++++++++++++++--------------------- 6 files changed, 40 insertions(+), 55 deletions(-)