From: "Tomáš Golembiovský" <tgolembi@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: QEMU <qemu-devel@nongnu.org>, Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: Re: [Qemu-devel] [PATCH] qga: report disk size and free space
Date: Tue, 3 Jul 2018 12:36:10 +0200 [thread overview]
Message-ID: <20180703123610.75b498f1@fiorina> (raw)
In-Reply-To: <CAJ+F1CJeui7YXrH35ObNBbasoduRKeJW8W=O+nW3P2rEHLAdPg@mail.gmail.com>
On Tue, 3 Jul 2018 12:01:55 +0200
Marc-André Lureau <marcandre.lureau@gmail.com> wrote:
> Hi
>
> On Tue, Jul 3, 2018 at 10:31 AM, Tomáš Golembiovský <tgolembi@redhat.com> wrote:
> > Report total file system size and free space in output of command
> > "guest-get-fsinfo". Values are optional and it is not an error if they cannot
> > be retrieved for some reason.
> >
>
> I am afraid this will miss 3.0, since it's a new feature
I kind of expected this.
> > Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
> > ---
> > qga/commands-posix.c | 18 ++++++++++++++++++
> > qga/commands-win32.c | 16 ++++++++++++++++
> > qga/qapi-schema.json | 5 ++++-
> > 3 files changed, 38 insertions(+), 1 deletion(-)
> >
> > diff --git a/qga/commands-posix.c b/qga/commands-posix.c
> > index eae817191b..1f2fb25b91 100644
> > --- a/qga/commands-posix.c
> > +++ b/qga/commands-posix.c
> > @@ -13,6 +13,7 @@
> >
> > #include "qemu/osdep.h"
> > #include <sys/ioctl.h>
> > +#include <sys/statvfs.h>
> > #include <sys/utsname.h>
> > #include <sys/wait.h>
> > #include <dirent.h>
> > @@ -1074,11 +1075,28 @@ static GuestFilesystemInfo *build_guest_fsinfo(struct FsMount *mount,
> > GuestFilesystemInfo *fs = g_malloc0(sizeof(*fs));
> > char *devpath = g_strdup_printf("/sys/dev/block/%u:%u",
> > mount->devmajor, mount->devminor);
> > + struct statvfs vfs_stats;
> >
> > fs->mountpoint = g_strdup(mount->dirname);
> > fs->type = g_strdup(mount->devtype);
> > build_guest_fsinfo_for_device(devpath, fs, errp);
> >
> > + g_debug(" get filesystem statistics for '%s'", mount->dirname);
> > + if (statvfs(mount->dirname, &vfs_stats) != 0) {
> > + /* This is not fatal, just log this incident */
> > + Error *local_err = NULL;
> > + error_setg_errno(&local_err, errno, "statfs(\"%s\")",
>
> statvfs()
>
> > + mount->dirname);
> > + slog("failed to stat filesystem: %s",
> > + error_get_pretty(local_err));
> > + error_free(local_err);
>
> The usage of Error is a bit overkill, perhaps you may juste use slog()
> / strerror() directly.
>
> > + } else {
> > + fs->size = vfs_stats.f_frsize * vfs_stats.f_blocks;
> > + fs->has_size = true;
> > + fs->free = vfs_stats.f_frsize * vfs_stats.f_bfree;
> > + fs->has_free = true;
> > + }
> > +
> > g_free(devpath);
> > return fs;
> > }
> > diff --git a/qga/commands-win32.c b/qga/commands-win32.c
> > index 70ee5379f6..6d6ca05281 100644
> > --- a/qga/commands-win32.c
> > +++ b/qga/commands-win32.c
> > @@ -706,6 +706,22 @@ static GuestFilesystemInfo *build_guest_fsinfo(char *guid, Error **errp)
> > }
> > fs->type = g_strdup(fs_name);
> > fs->disk = build_guest_disk_info(guid, errp);
> > +
> > + if (len > 0) {
> > + if (GetDiskFreeSpaceEx(mnt_point, 0, (PULARGE_INTEGER)&fs->size,
> > + (PULARGE_INTEGER)&fs->free) != 0) {
>
> I would rather use some local ULARGE_INTEGER and access the QuadPart
> to avoid the cast, but it should work.
I tried that, but the returned values were nonsensical. Maybe I did
something wrong along the way. I'll give it one more try.
Thanks for quick response,
Tomas
>
> > + /* This is not fatal, just log this incident */
> > + Error *local_err = NULL;
> > + error_setg_win32(&local_err, GetLastError(),
> > + "failed to get free space on volume \"%s\"", mnt_point);
> > + slog("%s", error_get_pretty(local_err));
> > + error_free(local_err);
> > + } else {
> > + fs->has_size = true;
> > + fs->has_free = true;
> > + }
> > + }
> > +
> > free:
> > g_free(mnt_point);
> > return fs;
> > diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> > index 17884c7c70..28a32444d3 100644
> > --- a/qga/qapi-schema.json
> > +++ b/qga/qapi-schema.json
> > @@ -848,12 +848,15 @@
> > # @type: file system type string
> > # @disk: an array of disk hardware information that the volume lies on,
> > # which may be empty if the disk type is not supported
> > +# @size: total number of bytes on the file system (Since 2.13)
> > +# @free: number of bytes available on the file system (Since 2.13)
>
> "Since 3.1", most probably
>
> > #
> > # Since: 2.2
> > ##
> > { 'struct': 'GuestFilesystemInfo',
> > 'data': {'name': 'str', 'mountpoint': 'str', 'type': 'str',
> > - 'disk': ['GuestDiskAddress']} }
> > + 'disk': ['GuestDiskAddress'], '*size': 'uint64',
> > + '*free': 'uint64'} }
> >
> > ##
> > # @guest-get-fsinfo:
> > --
> > 2.17.1
> >
> >
>
>
>
> --
> Marc-André Lureau
--
Tomáš Golembiovský <tgolembi@redhat.com>
next prev parent reply other threads:[~2018-07-03 10:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-03 8:31 [Qemu-devel] [PATCH] qga: report disk size and free space Tomáš Golembiovský
2018-07-03 10:01 ` Marc-André Lureau
2018-07-03 10:36 ` Tomáš Golembiovský [this message]
2018-07-03 10:54 ` Tomáš Golembiovský
2018-07-03 16:26 ` Eric Blake
2018-07-03 11:39 ` no-reply
2018-07-03 16:24 ` Eric Blake
2018-07-10 17:58 ` Tomáš Golembiovský
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=20180703123610.75b498f1@fiorina \
--to=tgolembi@redhat.com \
--cc=marcandre.lureau@gmail.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).