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 v2] btrfs-progs: filesystem usage: add avail info from statfs()
Date: Tue, 1 Dec 2020 19:05:18 +0100	[thread overview]
Message-ID: <20201201180518.GP6430@twin.jikos.cz> (raw)
In-Reply-To: <20201110005221.9323-1-realwakka@gmail.com>

On Tue, Nov 10, 2020 at 12:52:21AM +0000, Sidong Yang wrote:
> dd available space information from statfs(). This can be different from
> 'Free (estimated)' in some cases. This patch provide more information
> about filesystem usage like below. and update document for this.
> 
> Overall:
>     Device size:                   5.00GiB
>     Device allocated:              1.02GiB
>     Device unallocated:            3.98GiB
>     Device missing:                  0.00B
>     Used:                         88.00KiB
>     Free (estimated):              4.48GiB      (min: 2.49GiB)
>     Avail:                         4.48GiB

My idea was to print

      Free (statfs, df):		...

'Avail' without context is useless.

>     Data ratio:                       1.00
>     Metadata ratio:                   2.00
>     Global reserve:              832.00KiB      (used: 0.00B)
>     Multiple profiles:                  no
> 
> Issue: #306
> Signed-off-by: Sidong Yang <realwakka@gmail.com>
> ---
>  Documentation/btrfs-filesystem.asciidoc |  3 +++
>  cmds/filesystem-usage.c                 | 10 ++++++++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/Documentation/btrfs-filesystem.asciidoc b/Documentation/btrfs-filesystem.asciidoc
> index 6a5561ed..18623afe 100644
> --- a/Documentation/btrfs-filesystem.asciidoc
> +++ b/Documentation/btrfs-filesystem.asciidoc
> @@ -276,6 +276,7 @@ Overall:
>      Device missing:                  0.00B
>      Used:                          1.14TiB
>      Free (estimated):            692.57GiB      (min: 692.57GiB)
> +    Avail:                       692.57GiB
>      Data ratio:                       1.00
>      Metadata ratio:                   1.00
>      Global reserve:              512.00MiB      (used: 0.00B)
> @@ -295,6 +296,8 @@ including the reserved space
>  data, including currently allocated space and estimating the usage of the
>  unallocated space based on the block group profiles, the 'min' is the lower bound
>  of the estimate in case multiple profiles are present
> +* 'Avail' -- the amount of space available for data. it's get by statfs() system
> +call that can be different from 'Free (estimated)' in some cases
>  * 'Data ratio' -- ratio of total space for data including redundancy or parity to
>  the effectively usable data space, eg. single is 1.0, RAID1 is 2.0 and for RAID5/6
>  it depends on the number of devices
> diff --git a/cmds/filesystem-usage.c b/cmds/filesystem-usage.c
> index ab60d769..ed743a61 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,12 @@ 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) {
> +		warning("cannot get space info with statfs() on '%s': %m", path);
> +		ret = 0;
> +	}

Yeah, that's better than hard failure.

With the text updated, patch added to devel, thanks.

      reply	other threads:[~2020-12-01 18:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-10  0:52 [PATCH v2] btrfs-progs: filesystem usage: add avail info from statfs() Sidong Yang
2020-12-01 18:05 ` 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=20201201180518.GP6430@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