From nobody Tue Nov 4 15:30:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15306068148081012.4282578638642; Tue, 3 Jul 2018 01:33:34 -0700 (PDT) Received: from localhost ([::1]:38843 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faGkg-0003EM-5R for importer@patchew.org; Tue, 03 Jul 2018 04:33:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faGid-0002Iv-Kg for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:31:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faGia-0002cw-BY for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:31:27 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:37989) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1faGia-0002cB-52 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:31:24 -0400 Received: by mail-wm0-f67.google.com with SMTP id 69-v6so1287508wmf.3 for ; Tue, 03 Jul 2018 01:31:23 -0700 (PDT) Received: from localhost.localdomain (ip-94-112-73-67.net.upcbroadband.cz. [94.112.73.67]) by smtp.gmail.com with ESMTPSA id w24-v6sm805640wmc.15.2018.07.03.01.31.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Jul 2018 01:31:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=OsI5F9a1rR7G7o/M9OmfuDa+lIOq3Lueq02oZU8x0YI=; b=ASc0nqTuA76G6/7eS8JZUH3FeaJ+lAiivhqnpAJgLHEO02OTf+6UREr9Dl2rEOzVuH E6DzmQLXmmOXsSnNvoNsiW/8YuIlbJpKADghxpcjq9XzaOTgs1ZtWC+031qGOXEfRGC5 Et8KsfAuvuwNnPldHtYVwwhUYMGlBJgJTNRwNegQG/5jMXquNVdM9yyrzGTzFMDDcut5 tEqpWQeP0Qmvdr3mxPtjJFLPNpIR7rSLadTuLrO2ChlHRPqChoPEoozx6OmalrntB2dx N3NzJA9wHemGijhZjI/4eRJmPUL6GkpId/3eixI8PALSxobQ/az9Ajdql8NLoHSFvARw FUuQ== X-Gm-Message-State: APt69E1smDY3DnHvKk9sm9gT18a3gArJYrLLm259xMc/pWNW3BQnh32w DqeS8n3aywhza8LQSLbruhKa/j+xl/Y= X-Google-Smtp-Source: AAOMgpfs8HpqM4Mgn7jL8mZeh9TlEz/LXCcuQSL9E79ftjuN0pZvIdD/1lSD339vu2KBilK0Ix3D2g== X-Received: by 2002:a1c:b208:: with SMTP id b8-v6mr5385653wmf.131.1530606682380; Tue, 03 Jul 2018 01:31:22 -0700 (PDT) From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= To: qemu-devel@nongnu.org Date: Tue, 3 Jul 2018 10:31:20 +0200 Message-Id: <0b2c142da5d44a4b645dee47b7c50dae87a90a05.1530606672.git.tgolembi@redhat.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 74.125.82.67 Subject: [Qemu-devel] [PATCH] qga: report disk size and free space X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Tom=C3=A1=C5=A1=20Golembiovsk=C3=BD?= , Michael Roth Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 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 cann= ot be retrieved for some reason. Signed-off-by: Tom=C3=A1=C5=A1 Golembiovsk=C3=BD --- 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 @@ =20 #include "qemu/osdep.h" #include +#include #include #include #include @@ -1074,11 +1075,28 @@ static GuestFilesystemInfo *build_guest_fsinfo(stru= ct FsMount *mount, GuestFilesystemInfo *fs =3D g_malloc0(sizeof(*fs)); char *devpath =3D g_strdup_printf("/sys/dev/block/%u:%u", mount->devmajor, mount->devminor); + struct statvfs vfs_stats; =20 fs->mountpoint =3D g_strdup(mount->dirname); fs->type =3D g_strdup(mount->devtype); build_guest_fsinfo_for_device(devpath, fs, errp); =20 + g_debug(" get filesystem statistics for '%s'", mount->dirname); + if (statvfs(mount->dirname, &vfs_stats) !=3D 0) { + /* This is not fatal, just log this incident */ + Error *local_err =3D NULL; + error_setg_errno(&local_err, errno, "statfs(\"%s\")", + mount->dirname); + slog("failed to stat filesystem: %s", + error_get_pretty(local_err)); + error_free(local_err); + } else { + fs->size =3D vfs_stats.f_frsize * vfs_stats.f_blocks; + fs->has_size =3D true; + fs->free =3D vfs_stats.f_frsize * vfs_stats.f_bfree; + fs->has_free =3D 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 *g= uid, Error **errp) } fs->type =3D g_strdup(fs_name); fs->disk =3D build_guest_disk_info(guid, errp); + + if (len > 0) { + if (GetDiskFreeSpaceEx(mnt_point, 0, (PULARGE_INTEGER)&fs->size, + (PULARGE_INTEGER)&fs->free) !=3D 0) { + /* This is not fatal, just log this incident */ + Error *local_err =3D 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 =3D true; + fs->has_free =3D 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: 2.2 ## { 'struct': 'GuestFilesystemInfo', 'data': {'name': 'str', 'mountpoint': 'str', 'type': 'str', - 'disk': ['GuestDiskAddress']} } + 'disk': ['GuestDiskAddress'], '*size': 'uint64', + '*free': 'uint64'} } =20 ## # @guest-get-fsinfo: --=20 2.17.1