diff mbox series

btrfs-progs: fix btrfs_group_profile_str regression

Message ID 20211030143658.39136-1-wangyugui@e16-tech.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: fix btrfs_group_profile_str regression | expand

Commit Message

Wang Yugui Oct. 30, 2021, 2:36 p.m. UTC
dad03fac3bb8 ("btrfs-progs: switch btrfs_group_profile_str to use raid table")
introduced a regression that raid profile of GlobalReserve will be output
as 'unknown'.

 $ btrfs filesystem df /mnt/test
 Data, single: total=5.02TiB, used=4.98TiB
 System, single: total=4.00MiB, used=624.00KiB
 Metadata, single: total=11.01GiB, used=6.94GiB
 GlobalReserve, unknown: total=512.00MiB, used=0.00B

fix it by
- add the process of BTRFS_BLOCK_GROUP_RESERVED
- fix the define of BTRFS_BLOCK_GROUP_RESERVED too.

Fixes: dad03fac3bb8 ("btrfs-progs: switch btrfs_group_profile_str to use raid table")
Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>

---
 common/utils.c        | 2 +-
 kernel-shared/ctree.h | 3 ++-
 2 files changed, 3 insertions(+), 2 deletions(-)

Comments

Qu Wenruo Nov. 2, 2021, 10:42 a.m. UTC | #1
On 2021/10/30 22:36, Wang Yugui wrote:
> dad03fac3bb8 ("btrfs-progs: switch btrfs_group_profile_str to use raid table")
> introduced a regression that raid profile of GlobalReserve will be output
> as 'unknown'.
>
>   $ btrfs filesystem df /mnt/test
>   Data, single: total=5.02TiB, used=4.98TiB
>   System, single: total=4.00MiB, used=624.00KiB
>   Metadata, single: total=11.01GiB, used=6.94GiB
>   GlobalReserve, unknown: total=512.00MiB, used=0.00B
>
> fix it by
> - add the process of BTRFS_BLOCK_GROUP_RESERVED
> - fix the define of BTRFS_BLOCK_GROUP_RESERVED too.

That also unified kernel uapi and progs headers' definition of
BTRFS_BLOCK_GROUP_RESERVED.

>
> Fixes: dad03fac3bb8 ("btrfs-progs: switch btrfs_group_profile_str to use raid table")
> Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>

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

Thanks,
Qu
>
> ---
>   common/utils.c        | 2 +-
>   kernel-shared/ctree.h | 3 ++-
>   2 files changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/common/utils.c b/common/utils.c
> index aee0eedc..e8744199 100644
> --- a/common/utils.c
> +++ b/common/utils.c
> @@ -1030,7 +1030,7 @@ const char* btrfs_group_profile_str(u64 flag)
>   {
>   	int index;
>
> -	flag &= ~BTRFS_BLOCK_GROUP_TYPE_MASK;
> +	flag &= ~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_RESERVED);
>   	if (flag & ~BTRFS_BLOCK_GROUP_PROFILE_MASK)
>   		return "unknown";
>
> diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
> index 563ea50b..99ebc3ad 100644
> --- a/kernel-shared/ctree.h
> +++ b/kernel-shared/ctree.h
> @@ -972,7 +972,8 @@ struct btrfs_csum_item {
>   #define BTRFS_BLOCK_GROUP_RAID6    	(1ULL << 8)
>   #define BTRFS_BLOCK_GROUP_RAID1C3    	(1ULL << 9)
>   #define BTRFS_BLOCK_GROUP_RAID1C4    	(1ULL << 10)
> -#define BTRFS_BLOCK_GROUP_RESERVED	BTRFS_AVAIL_ALLOC_BIT_SINGLE
> +#define BTRFS_BLOCK_GROUP_RESERVED	(BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
> +					 BTRFS_SPACE_INFO_GLOBAL_RSV)
>
>   enum btrfs_raid_types {
>   	BTRFS_RAID_RAID10,
>
David Sterba Nov. 2, 2021, 5:06 p.m. UTC | #2
On Sat, Oct 30, 2021 at 10:36:58PM +0800, Wang Yugui wrote:
> dad03fac3bb8 ("btrfs-progs: switch btrfs_group_profile_str to use raid table")
> introduced a regression that raid profile of GlobalReserve will be output
> as 'unknown'.
> 
>  $ btrfs filesystem df /mnt/test
>  Data, single: total=5.02TiB, used=4.98TiB
>  System, single: total=4.00MiB, used=624.00KiB
>  Metadata, single: total=11.01GiB, used=6.94GiB
>  GlobalReserve, unknown: total=512.00MiB, used=0.00B
> 
> fix it by
> - add the process of BTRFS_BLOCK_GROUP_RESERVED
> - fix the define of BTRFS_BLOCK_GROUP_RESERVED too.
> 
> Fixes: dad03fac3bb8 ("btrfs-progs: switch btrfs_group_profile_str to use raid table")
> Signed-off-by: Wang Yugui <wangyugui@e16-tech.com>

Added to devel, thanks.
diff mbox series

Patch

diff --git a/common/utils.c b/common/utils.c
index aee0eedc..e8744199 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -1030,7 +1030,7 @@  const char* btrfs_group_profile_str(u64 flag)
 {
 	int index;
 
-	flag &= ~BTRFS_BLOCK_GROUP_TYPE_MASK;
+	flag &= ~(BTRFS_BLOCK_GROUP_TYPE_MASK | BTRFS_BLOCK_GROUP_RESERVED);
 	if (flag & ~BTRFS_BLOCK_GROUP_PROFILE_MASK)
 		return "unknown";
 
diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
index 563ea50b..99ebc3ad 100644
--- a/kernel-shared/ctree.h
+++ b/kernel-shared/ctree.h
@@ -972,7 +972,8 @@  struct btrfs_csum_item {
 #define BTRFS_BLOCK_GROUP_RAID6    	(1ULL << 8)
 #define BTRFS_BLOCK_GROUP_RAID1C3    	(1ULL << 9)
 #define BTRFS_BLOCK_GROUP_RAID1C4    	(1ULL << 10)
-#define BTRFS_BLOCK_GROUP_RESERVED	BTRFS_AVAIL_ALLOC_BIT_SINGLE
+#define BTRFS_BLOCK_GROUP_RESERVED	(BTRFS_AVAIL_ALLOC_BIT_SINGLE | \
+					 BTRFS_SPACE_INFO_GLOBAL_RSV)
 
 enum btrfs_raid_types {
 	BTRFS_RAID_RAID10,