qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Chen Hanxiao <chen_han_xiao@126.com>
Cc: qemu-devel@nongnu.org, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH v4] qga: add mountpoint usage to GuestFilesystemInfo
Date: Fri, 1 Jun 2018 13:19:56 +0100	[thread overview]
Message-ID: <20180601121956.GW3458@redhat.com> (raw)
In-Reply-To: <20180601061121.13161-1-chen_han_xiao@126.com>

On Fri, Jun 01, 2018 at 02:11:21PM +0800, Chen Hanxiao wrote:
> From: Chen Hanxiao <chenhanxiao@gmail.com>
> 
> This patch adds support for getting the usage of mounted
> filesystem.
> It's very useful when we try to monitor guest's filesystem.
> 
> Cc: Michael Roth <mdroth@linux.vnet.ibm.com>
> Cc: Eric Blake <eblake@redhat.com>
> Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
> 
> ---
> v2:
>    add description in qapi-schema and version numbers
> v3:
>    use float for usage to get more precision.
> v4:
>    make usage as a best-effort query and mark it as optional.
> 
>  qga/commands-posix.c | 17 +++++++++++++++++
>  qga/qapi-schema.json |  3 ++-
>  2 files changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> index 0dc219dbcf..4facc76953 100644
> --- a/qga/commands-posix.c
> +++ b/qga/commands-posix.c
> @@ -46,6 +46,7 @@ extern char **environ;
>  #include <arpa/inet.h>
>  #include <sys/socket.h>
>  #include <net/if.h>
> +#include <sys/statvfs.h>
>  
>  #ifdef FIFREEZE
>  #define CONFIG_FSFREEZE
> @@ -1072,6 +1073,9 @@ static GuestFilesystemInfo *build_guest_fsinfo(struct FsMount *mount,
>                                                 Error **errp)
>  {
>      GuestFilesystemInfo *fs = g_malloc0(sizeof(*fs));
> +    struct statvfs buf;
> +    unsigned long used, nonroot_total;
> +    double usage;
>      char *devpath = g_strdup_printf("/sys/dev/block/%u:%u",
>                                      mount->devmajor, mount->devminor);
>  
> @@ -1079,7 +1083,20 @@ static GuestFilesystemInfo *build_guest_fsinfo(struct FsMount *mount,
>      fs->type = g_strdup(mount->devtype);
>      build_guest_fsinfo_for_device(devpath, fs, errp);
>  
> +    if (statvfs(fs->mountpoint, &buf)) {
> +        fs->has_usage = false;
> +        fs->usage = -1;
> +    } else {
> +        used = buf.f_blocks - buf.f_bfree;
> +        nonroot_total = used + buf.f_bavail;
> +        usage = (double) used / nonroot_total;

Why calculate the usage here ?  IMHO it would make the command more useful
if we just reported two separate "used_bytes" and "total_bytes" values. The
app can convert to a percentage utilization value if they so desire, while
other apps can now get the raw values

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

  reply	other threads:[~2018-06-01 12:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-01  6:11 [Qemu-devel] [PATCH v4] qga: add mountpoint usage to GuestFilesystemInfo Chen Hanxiao
2018-06-01 12:19 ` Daniel P. Berrangé [this message]
2018-06-01 15:21   ` Chen Hanxiao

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=20180601121956.GW3458@redhat.com \
    --to=berrange@redhat.com \
    --cc=chen_han_xiao@126.com \
    --cc=mdroth@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).