* [PATCH 1/5] btrfs-progs: Use bool parameter to determine if we're allocating data extent
2018-01-03 7:13 [PATCH 0/5] Cleanups for later btrfs_alloc_chunk() rework Qu Wenruo
@ 2018-01-03 7:13 ` Qu Wenruo
2018-01-03 7:13 ` [PATCH 2/5] btrfs-progs: volumes: Make find_free_dev_extent_start static Qu Wenruo
` (5 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Qu Wenruo @ 2018-01-03 7:13 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
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.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
ctree.h | 2 +-
extent-tree.c | 17 +++++++++--------
2 files changed, 10 insertions(+), 9 deletions(-)
diff --git a/ctree.h b/ctree.h
index b92df1c1a518..61d9f9fc9dff 100644
--- a/ctree.h
+++ b/ctree.h
@@ -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);
diff --git a/extent-tree.c b/extent-tree.c
index 055582c36da6..58b64a21d226 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -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,
--
2.15.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 3/5] btrfs-progs: volumes: Remove unnecessary trans parameter
2018-01-03 7:13 [PATCH 0/5] Cleanups for later btrfs_alloc_chunk() rework Qu Wenruo
2018-01-03 7:13 ` [PATCH 1/5] btrfs-progs: Use bool parameter to determine if we're allocating data extent Qu Wenruo
2018-01-03 7:13 ` [PATCH 2/5] btrfs-progs: volumes: Make find_free_dev_extent_start static Qu Wenruo
@ 2018-01-03 7:13 ` Qu Wenruo
2018-01-03 7:13 ` [PATCH 4/5] btrfs-progs: volumes: Remove unnecessary parameters when allocating device extent Qu Wenruo
` (3 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Qu Wenruo @ 2018-01-03 7:13 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
Remove @trans parameter for find_free_dev_extent_start() and its
callers.
The function itself is doing read-only tree search, no use of
transaction.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
volumes.c | 17 +++++++----------
1 file changed, 7 insertions(+), 10 deletions(-)
diff --git a/volumes.c b/volumes.c
index 0e50e1d5833e..f6c6447fe925 100644
--- a/volumes.c
+++ b/volumes.c
@@ -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;
}
--
2.15.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 4/5] btrfs-progs: volumes: Remove unnecessary parameters when allocating device extent
2018-01-03 7:13 [PATCH 0/5] Cleanups for later btrfs_alloc_chunk() rework Qu Wenruo
` (2 preceding siblings ...)
2018-01-03 7:13 ` [PATCH 3/5] btrfs-progs: volumes: Remove unnecessary trans parameter Qu Wenruo
@ 2018-01-03 7:13 ` Qu Wenruo
2018-01-03 7:13 ` [PATCH 5/5] btrfs-progs: Remove unnecessary parameter for btrfs_add_block_group Qu Wenruo
` (2 subsequent siblings)
6 siblings, 0 replies; 9+ messages in thread
From: Qu Wenruo @ 2018-01-03 7:13 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
@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.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
volumes.c | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/volumes.c b/volumes.c
index f6c6447fe925..fa3c6de023f9 100644
--- a/volumes.c
+++ b/volumes.c
@@ -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);
--
2.15.1
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 5/5] btrfs-progs: Remove unnecessary parameter for btrfs_add_block_group
2018-01-03 7:13 [PATCH 0/5] Cleanups for later btrfs_alloc_chunk() rework Qu Wenruo
` (3 preceding siblings ...)
2018-01-03 7:13 ` [PATCH 4/5] btrfs-progs: volumes: Remove unnecessary parameters when allocating device extent Qu Wenruo
@ 2018-01-03 7:13 ` Qu Wenruo
2018-01-23 18:31 ` David Sterba
2018-01-03 9:17 ` [PATCH 0/5] Cleanups for later btrfs_alloc_chunk() rework Su Yue
2018-01-04 13:54 ` Nikolay Borisov
6 siblings, 1 reply; 9+ messages in thread
From: Qu Wenruo @ 2018-01-03 7:13 UTC (permalink / raw)
To: linux-btrfs; +Cc: dsterba
@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.
Signed-off-by: Qu Wenruo <wqu@suse.com>
---
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(-)
diff --git a/cmds-check.c b/cmds-check.c
index a93ac2c88a38..635c1c44ff6f 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -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));
diff --git a/convert/main.c b/convert/main.c
index af2855316fee..4a510a786394 100644
--- a/convert/main.c
+++ b/convert/main.c
@@ -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;
diff --git a/ctree.h b/ctree.h
index 61d9f9fc9dff..5a04c0f1c912 100644
--- a/ctree.h
+++ b/ctree.h
@@ -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,
diff --git a/extent-tree.c b/extent-tree.c
index 58b64a21d226..db24da3a3a8c 100644
--- a/extent-tree.c
+++ b/extent-tree.c
@@ -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);
diff --git a/mkfs/main.c b/mkfs/main.c
index a69a699fa3fd..938025bfd32e 100644
--- a/mkfs/main.c
+++ b/mkfs/main.c
@@ -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;
--
2.15.1
^ permalink raw reply related [flat|nested] 9+ messages in thread