diff mbox

[2/3] btrfs-progs: fi usage: change to output more info without root privilege

Message ID dbdf04aa-3969-8249-a507-d7d16f3d1e5d@jp.fujitsu.com (mailing list archive)
State New, archived
Headers show

Commit Message

Misono Tomohiro Nov. 30, 2017, 7:52 a.m. UTC
Although per device usage cannot be shown without root privilege,
per profile usage can be shown.

To achieve this, we just basically need to remove the check of nullness
of chunkinfo in print_filesystem_usage_by_chunk(), because other
functions except print_unused() properly handles chunkinfo by
chunkcount, which is 0 if chunkinfo is null.

As a result, "fi usage" always includes the infomation of "fi df".

Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>
---
 cmds-fi-usage.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

Comments

Qu Wenruo Nov. 30, 2017, 8:13 a.m. UTC | #1
On 2017年11月30日 15:52, Misono, Tomohiro wrote:
> Although per device usage cannot be shown without root privilege,
> per profile usage can be shown.
> 
> To achieve this, we just basically need to remove the check of nullness
> of chunkinfo in print_filesystem_usage_by_chunk(), because other
> functions except print_unused() properly handles chunkinfo by
> chunkcount, which is 0 if chunkinfo is null.
> 
> As a result, "fi usage" always includes the infomation of "fi df".
> 
> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com>

Looks good.

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

Thanks,
Qu

> ---
>  cmds-fi-usage.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
> index 299c2dae..7bbc9896 100644
> --- a/cmds-fi-usage.c
> +++ b/cmds-fi-usage.c
> @@ -885,9 +885,11 @@ static void _cmd_filesystem_usage_linear(unsigned unit_mode,
>  		printf("\n");
>  	}
>  
> -	printf("Unallocated:\n");
> -	print_unused(info_ptr, info_count, device_info_ptr, device_info_count,
> -			unit_mode | UNITS_NEGATIVE);
> +	if (info_count) {
> +		printf("Unallocated:\n");
> +		print_unused(info_ptr, info_count, device_info_ptr,
> +				device_info_count, unit_mode | UNITS_NEGATIVE);
> +	}
>  }
>  
>  static int print_filesystem_usage_by_chunk(int fd,
> @@ -898,9 +900,6 @@ static int print_filesystem_usage_by_chunk(int fd,
>  	struct btrfs_ioctl_space_args *sargs;
>  	int ret = 0;
>  
> -	if (!chunkinfo)
> -		return 0;
> -
>  	sargs = load_space_info(fd, path);
>  	if (!sargs) {
>  		ret = 1;
>
diff mbox

Patch

diff --git a/cmds-fi-usage.c b/cmds-fi-usage.c
index 299c2dae..7bbc9896 100644
--- a/cmds-fi-usage.c
+++ b/cmds-fi-usage.c
@@ -885,9 +885,11 @@  static void _cmd_filesystem_usage_linear(unsigned unit_mode,
 		printf("\n");
 	}
 
-	printf("Unallocated:\n");
-	print_unused(info_ptr, info_count, device_info_ptr, device_info_count,
-			unit_mode | UNITS_NEGATIVE);
+	if (info_count) {
+		printf("Unallocated:\n");
+		print_unused(info_ptr, info_count, device_info_ptr,
+				device_info_count, unit_mode | UNITS_NEGATIVE);
+	}
 }
 
 static int print_filesystem_usage_by_chunk(int fd,
@@ -898,9 +900,6 @@  static int print_filesystem_usage_by_chunk(int fd,
 	struct btrfs_ioctl_space_args *sargs;
 	int ret = 0;
 
-	if (!chunkinfo)
-		return 0;
-
 	sargs = load_space_info(fd, path);
 	if (!sargs) {
 		ret = 1;