Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: David Sterba <dsterba@suse.cz>
To: Sidong Yang <realwakka@gmail.com>
Cc: dsterba@suse.cz, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: filesystem usage: add avail info from statfs()
Date: Tue, 10 Nov 2020 00:16:42 +0100	[thread overview]
Message-ID: <20201109231642.GD6756@twin.jikos.cz> (raw)
In-Reply-To: <20201109145923.14167-1-realwakka@gmail.com>

On Mon, Nov 09, 2020 at 02:59:23PM +0000, Sidong Yang wrote:
> Add available space information from statfs(). This can be different from
> 'Free (estimated)' in some cases. This patch provide more information about
> filesystem usage.
> 
> Issue: #306
> Signed-off-by: Sidong Yang <realwakka@gmail.com>
> ---
>  cmds/filesystem-usage.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c
> index ab60d769..c17e26c3 100644
> --- a/cmds/filesystem-usage.c
> +++ b/cmds/filesystem-usage.c
> @@ -19,6 +19,7 @@
>  #include <string.h>
>  #include <unistd.h>
>  #include <sys/ioctl.h>
> +#include <sys/vfs.h>
>  #include <errno.h>
>  #include <stdarg.h>
>  #include <getopt.h>
> @@ -430,6 +431,7 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo,
>  	u64 free_min = 0;
>  	double max_data_ratio = 1.0;
>  	int mixed = 0;
> +	struct statfs statfs_buf;
>  
>  	sargs = load_space_info(fd, path);
>  	if (!sargs) {
> @@ -556,6 +558,13 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo,
>  	if (unit_mode != UNITS_HUMAN)
>  		width = 18;
>  
> +	ret = statfs(path, &statfs_buf);
> +	if (ret) {
> +		error("cannot get space info with statfs() on '%s': %m", path);

I wonder when statfs would not work and I don't think it should be a
hard error, maybe a warning or some stub that says the information was
not available.

> +		ret = 1;
> +		goto exit;
> +	}
> +
>  	printf("Overall:\n");
>  
>  	printf("    Device size:\t\t%*s\n", width,
> @@ -572,6 +581,8 @@ static int print_filesystem_usage_overall(int fd, struct chunk_info *chunkinfo,
>  		width,
>  		pretty_size_mode(free_estimated, unit_mode));
>  	printf("min: %s)\n", pretty_size_mode(free_min, unit_mode));
> +	printf("    Avail:\t\t\t%*s\n", width,
> +		pretty_size_mode(statfs_buf.f_bavail * statfs_buf.f_bsize, unit_mode));

It's good to paste sample output of the command to the changelog to have
a second thought on how it actually looks. A simple 'Avail' is without
context and I as a user have no idea what it means or how to interpret
the value. Please try again.

      reply	other threads:[~2020-11-09 23:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-09 14:59 [PATCH] btrfs-progs: filesystem usage: add avail info from statfs() Sidong Yang
2020-11-09 23:16 ` David Sterba [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201109231642.GD6756@twin.jikos.cz \
    --to=dsterba@suse.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=realwakka@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox