diff mbox series

[1/3] btrfs-progs: Initialize sub_stripes to 1 in btrfs_alloc_data_chunk

Message ID 20191030122227.28496-2-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series Misc btrfs-progs fixes | expand

Commit Message

Nikolay Borisov Oct. 30, 2019, 12:22 p.m. UTC
sub_stripe variables is by default initialized to 0 and it's overriden
only in case we have RAID10 mode. This leads to the following (minor)
artifacts on a freshly created filesystem:

item 3 key (FIRST_CHUNK_TREE CHUNK_ITEM 30408704) itemoff 15863 itemsize 112
		length 1073741824 owner 2 stripe_len 65536 type METADATA|RAID1
		io_align 65536 io_width 65536 sector_size 4096
		num_stripes 2 sub_stripes 0
			stripe 0 devid 2 offset 9437184
			dev_uuid a020fc2f-b526-4800-9278-156f2f431fe9
			stripe 1 devid 1 offset 30408704
			dev_uuid 0f78aa72-4626-4057-a8f2-285f46b2c664

After balance resulting chunk item is:

item 3 key (FIRST_CHUNK_TREE CHUNK_ITEM 3251634176) itemoff 15863 itemsize 112
		length 268435456 owner 2 stripe_len 65536 type METADATA|RAID1
		io_align 65536 io_width 65536 sector_size 4096
		num_stripes 2 sub_stripes 1
			stripe 0 devid 2 offset 3230662656
			dev_uuid a020fc2f-b526-4800-9278-156f2f431fe9
			stripe 1 devid 1 offset 3251634176
			dev_uuid 0f78aa72-4626-4057-a8f2-285f46b2c664

Kernel code usually initializes it to 1, since it takes the value from
the raid description table which has it set to 1 for all but RAID10 types.
In userspace it has be statically initialized by 1 since we don't have
btrfs_bg_flags_to_raid_index. Eventually the kernel/userspace needs
to be merged but for now it wouldn't bring much value if this function
is copied.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 volumes.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Qu Wenruo Oct. 30, 2019, 12:42 p.m. UTC | #1
On 2019/10/30 下午8:22, Nikolay Borisov wrote:
> sub_stripe variables is by default initialized to 0 and it's overriden
> only in case we have RAID10 mode. This leads to the following (minor)
> artifacts on a freshly created filesystem:
>
> item 3 key (FIRST_CHUNK_TREE CHUNK_ITEM 30408704) itemoff 15863 itemsize 112
> 		length 1073741824 owner 2 stripe_len 65536 type METADATA|RAID1
> 		io_align 65536 io_width 65536 sector_size 4096
> 		num_stripes 2 sub_stripes 0
> 			stripe 0 devid 2 offset 9437184
> 			dev_uuid a020fc2f-b526-4800-9278-156f2f431fe9
> 			stripe 1 devid 1 offset 30408704
> 			dev_uuid 0f78aa72-4626-4057-a8f2-285f46b2c664
>
> After balance resulting chunk item is:
>
> item 3 key (FIRST_CHUNK_TREE CHUNK_ITEM 3251634176) itemoff 15863 itemsize 112
> 		length 268435456 owner 2 stripe_len 65536 type METADATA|RAID1
> 		io_align 65536 io_width 65536 sector_size 4096
> 		num_stripes 2 sub_stripes 1
> 			stripe 0 devid 2 offset 3230662656
> 			dev_uuid a020fc2f-b526-4800-9278-156f2f431fe9
> 			stripe 1 devid 1 offset 3251634176
> 			dev_uuid 0f78aa72-4626-4057-a8f2-285f46b2c664
>
> Kernel code usually initializes it to 1, since it takes the value from
> the raid description table which has it set to 1 for all but RAID10 types.
> In userspace it has be statically initialized by 1 since we don't have
> btrfs_bg_flags_to_raid_index. Eventually the kernel/userspace needs
> to be merged but for now it wouldn't bring much value if this function
> is copied.
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

I guess the tree-checker skips this check except for RAID10 just to work
around this problem.

Thanks,
Qu
> ---
>  volumes.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/volumes.c b/volumes.c
> index fbbc22b5b1b3..1d088d93e788 100644
> --- a/volumes.c
> +++ b/volumes.c
> @@ -993,7 +993,7 @@ int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
>  	int num_stripes = 1;
>  	int max_stripes = 0;
>  	int min_stripes = 1;
> -	int sub_stripes = 0;
> +	int sub_stripes = 1;
>  	int looped = 0;
>  	int ret;
>  	int index;
> @@ -1258,7 +1258,7 @@ int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
>  	struct map_lookup *map;
>  	u64 calc_size = SZ_8M;
>  	int num_stripes = 1;
> -	int sub_stripes = 0;
> +	int sub_stripes = 1;
>  	int ret;
>  	int index;
>  	int stripe_len = BTRFS_STRIPE_LEN;
>
diff mbox series

Patch

diff --git a/volumes.c b/volumes.c
index fbbc22b5b1b3..1d088d93e788 100644
--- a/volumes.c
+++ b/volumes.c
@@ -993,7 +993,7 @@  int btrfs_alloc_chunk(struct btrfs_trans_handle *trans,
 	int num_stripes = 1;
 	int max_stripes = 0;
 	int min_stripes = 1;
-	int sub_stripes = 0;
+	int sub_stripes = 1;
 	int looped = 0;
 	int ret;
 	int index;
@@ -1258,7 +1258,7 @@  int btrfs_alloc_data_chunk(struct btrfs_trans_handle *trans,
 	struct map_lookup *map;
 	u64 calc_size = SZ_8M;
 	int num_stripes = 1;
-	int sub_stripes = 0;
+	int sub_stripes = 1;
 	int ret;
 	int index;
 	int stripe_len = BTRFS_STRIPE_LEN;