Skip to contentSkip to conversation

btrfs-progs: device: print num_stripes in usage command

PATCH In review Sidong Yang 2 participants 2 messages Jun 8, 2021 – Jun 17, 2021 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 btrfs-progs: device: print num_stripes in usage command

This patch prints num_stripes for striping profiles in device usage commands. It helps to see profiles easily. The output is like below.

/dev/vdc, ID: 1
Device size: 1.00GiB
Device slack: 0.00B
Data,RAID0/2: 912.62MiB
Metadata,RAID1: 102.38MiB
System,RAID1: 8.00MiB
Unallocated: 1.00MiB

---
v2:
- print stripes if striping raid
- use separator "/"

---
 cmds/filesystem-usage.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)
cmds/filesystem-usage.c +26 -5
index 107453d4..b92a4860 100644
@@ -1192,20 +1192,41 @@ void print_device_chunks(struct device_info *devinfo,
 		const char *r_mode;
 		u64 flags;
 		u64 size;
+		u64 num_stripes;
+		u64 profile;
 
 		if (chunks_info_ptr[i].devid != devinfo->devid)
 			continue;
 
 		flags = chunks_info_ptr[i].type;
+		profile = flags & BTRFS_BLOCK_GROUP_PROFILE_MASK;
 
 		description = btrfs_group_type_str(flags);
 		r_mode = btrfs_group_profile_str(flags);
 		size = calc_chunk_size(chunks_info_ptr+i);
-		printf("   %s,%s:%*s%10s\n",
-			description,
-			r_mode,
-			(int)(20 - strlen(description) - strlen(r_mode)), "",
-			pretty_size_mode(size, unit_mode));
+		num_stripes = chunks_info_ptr[i].num_stripes;
+
+		switch (profile) {
+		case BTRFS_BLOCK_GROUP_RAID0:
+		case BTRFS_BLOCK_GROUP_RAID5:
+		case BTRFS_BLOCK_GROUP_RAID6:
+		case BTRFS_BLOCK_GROUP_RAID10:			
+			printf("   %s,%s/%llu:%*s%10s\n",
+				   description,
+				   r_mode,
+				   num_stripes,
+				   (int)(20 - strlen(description) - strlen(r_mode)
+						 - count_digits(num_stripes) - 1), "",
+				   pretty_size_mode(size, unit_mode));
+			break;
+		default:
+			printf("   %s,%s:%*s%10s\n",
+				   description,
+				   r_mode,
+				   (int)(20 - strlen(description) - strlen(r_mode)), "",
+				   pretty_size_mode(size, unit_mode));
+			break;
+		}
 
 		allocated += size;
 
Signature · 1 line
2.25.1
#1 lore raw
Quoted 11 lines · Sidong Yang

This patch prints num_stripes for striping profiles in device usage commands. It helps to see profiles easily. The output is like below.

/dev/vdc, ID: 1
Device size: 1.00GiB
Device slack: 0.00B
Data,RAID0/2: 912.62MiB
Metadata,RAID1: 102.38MiB
System,RAID1: 8.00MiB
Unallocated: 1.00MiB

Quoted 1 line

Added to devel with minor fixups, thanks.