* [PATCH v3] qga: implement 'guest-get-fsinfo' for FreeBSD
@ 2026-07-14 16:57 Roman Bogorodskiy
2026-07-14 17:00 ` Daniel P. Berrangé
0 siblings, 1 reply; 2+ messages in thread
From: Roman Bogorodskiy @ 2026-07-14 16:57 UTC (permalink / raw)
To: qemu-devel
Cc: Daniel P. Berrangé, Roman Bogorodskiy, Markus Armbruster,
Kostiantyn Kostiuk, Michael Roth, Eric Blake
Implement the qmp_guest_get_fsinfo() API for FreeBSD.
To implement it, reuse build_fs_mount_list() which is already
implemented for FreeBSD. Extend the FsMount type to include
a string "fromname" attribute to store the disk the FS is mounted from.
Disk mapping info is not covered by this implementation.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
Acked-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
---
Changes since v1:
- Replace g_malloc0() with g_new0(.., 1) for GuestFilesystemInfo
Changes since v2:
- Drop the unused 'errp' argument to build_guest_fsinfo() and
clean up the related code.
- Fix leaking string through g_strdup() for a g_path_get_basename()
allocated string.
qga/commands-bsd.c | 53 ++++++++++++++++++++++++++++++++++++++++++-
qga/commands-common.h | 1 +
qga/commands-posix.c | 3 +++
qga/qapi-schema.json | 12 +++++-----
4 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c
index 94ff6fee6a..1c51d099eb 100644
--- a/qga/commands-bsd.c
+++ b/qga/commands-bsd.c
@@ -20,6 +20,7 @@
#include <sys/ucred.h>
#include <sys/mount.h>
#include <net/if_dl.h>
+#include <sys/statvfs.h>
#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <net/if_arp.h>
#include <netinet/if_ether.h>
@@ -28,7 +29,7 @@
#endif
#include <paths.h>
-#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM)
+#if defined(CONFIG_FSFREEZE) || defined(CONFIG_FSTRIM) || defined(__FreeBSD__)
bool build_fs_mount_list(FsMountList *mounts, Error **errp)
{
FsMount *mount;
@@ -55,6 +56,7 @@ bool build_fs_mount_list(FsMountList *mounts, Error **errp)
mount->dirname = g_strdup(mntp->f_mntonname);
mount->devtype = g_strdup(mntp->f_fstypename);
+ mount->fromname = g_strdup(mntp->f_mntfromname);
mount->devmajor = major(mount->dev);
mount->devminor = minor(mount->dev);
mount->fsid = mntp->f_fsid;
@@ -178,3 +180,52 @@ bool guest_get_hw_addr(struct ifaddrs *ifa, unsigned char *buf,
return true;
}
#endif /* HAVE_GETIFADDRS */
+
+#if defined(__FreeBSD__)
+static GuestFilesystemInfo *build_guest_fsinfo(struct FsMount *mount)
+{
+ GuestFilesystemInfo *fs = g_new0(GuestFilesystemInfo, 1);
+ struct statvfs buf;
+ unsigned long used, nonroot_total, fr_size;
+
+ fs->mountpoint = g_strdup(mount->dirname);
+ fs->type = g_strdup(mount->devtype);
+ fs->name = g_path_get_basename(mount->fromname);
+
+ if (statvfs(fs->mountpoint, &buf) == 0) {
+ fr_size = buf.f_frsize;
+ used = buf.f_blocks - buf.f_bfree;
+ nonroot_total = used + buf.f_bavail;
+ fs->used_bytes = used * fr_size;
+ fs->total_bytes = nonroot_total * fr_size;
+ fs->total_bytes_privileged = buf.f_blocks * fr_size;
+
+ fs->has_total_bytes = true;
+ fs->has_total_bytes_privileged = true;
+ fs->has_used_bytes = true;
+ }
+
+ return fs;
+}
+
+GuestFilesystemInfoList *qmp_guest_get_fsinfo(Error **errp)
+{
+ FsMountList mounts;
+ struct FsMount *mount;
+ GuestFilesystemInfoList *ret = NULL;
+
+ QTAILQ_INIT(&mounts);
+ if (!build_fs_mount_list(&mounts, errp)) {
+ return NULL;
+ }
+
+ QTAILQ_FOREACH(mount, &mounts, next) {
+ g_debug("Building guest fsinfo for '%s'", mount->dirname);
+
+ QAPI_LIST_PREPEND(ret, build_guest_fsinfo(mount));
+ }
+
+ free_fs_mount_list(&mounts);
+ return ret;
+}
+#endif /* __FreeBSD__ */
diff --git a/qga/commands-common.h b/qga/commands-common.h
index 263e7c0525..a07d0885f5 100644
--- a/qga/commands-common.h
+++ b/qga/commands-common.h
@@ -29,6 +29,7 @@ typedef struct FsMount {
#if defined(__FreeBSD__)
dev_t dev;
fsid_t fsid;
+ char *fromname;
#endif
QTAILQ_ENTRY(FsMount) next;
} FsMount;
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 837be51c40..837e285b6d 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -731,6 +731,9 @@ void free_fs_mount_list(FsMountList *mounts)
QTAILQ_REMOVE(mounts, mount, next);
g_free(mount->dirname);
g_free(mount->devtype);
+#if defined(__FreeBSD__)
+ g_free(mount->fromname);
+#endif
g_free(mount);
}
}
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index c57bc9a02f..8cd0ba048b 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -874,7 +874,7 @@
'data': [ 'ide', 'fdc', 'scsi', 'virtio', 'xen', 'usb', 'uml', 'sata',
'sd', 'unknown', 'ieee1394', 'ssa', 'fibre', 'raid', 'iscsi',
'sas', 'mmc', 'virtual', 'file-backed-virtual', 'nvme' ],
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
##
# @GuestPCIAddress:
@@ -892,7 +892,7 @@
{ 'struct': 'GuestPCIAddress',
'data': {'domain': 'int', 'bus': 'int',
'slot': 'int', 'function': 'int'},
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
##
# @GuestCCWAddress:
@@ -912,7 +912,7 @@
'ssid': 'int',
'subchno': 'int',
'devno': 'int'},
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
##
# @GuestDiskAddress:
@@ -942,7 +942,7 @@
'bus': 'int', 'target': 'int', 'unit': 'int',
'*serial': 'str', '*dev': 'str',
'*ccw-address': 'GuestCCWAddress'},
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
##
# @GuestNVMeSmart:
@@ -1063,7 +1063,7 @@
'data': {'name': 'str', 'mountpoint': 'str', 'type': 'str',
'*used-bytes': 'uint64', '*total-bytes': 'uint64',
'*total-bytes-privileged': 'uint64', 'disk': ['GuestDiskAddress']},
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
##
# @guest-get-fsinfo:
@@ -1077,7 +1077,7 @@
##
{ 'command': 'guest-get-fsinfo',
'returns': ['GuestFilesystemInfo'],
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LINUX', 'CONFIG_FREEBSD' ] } }
##
# @guest-set-user-password:
--
2.52.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v3] qga: implement 'guest-get-fsinfo' for FreeBSD
2026-07-14 16:57 [PATCH v3] qga: implement 'guest-get-fsinfo' for FreeBSD Roman Bogorodskiy
@ 2026-07-14 17:00 ` Daniel P. Berrangé
0 siblings, 0 replies; 2+ messages in thread
From: Daniel P. Berrangé @ 2026-07-14 17:00 UTC (permalink / raw)
To: Roman Bogorodskiy
Cc: qemu-devel, Markus Armbruster, Kostiantyn Kostiuk, Michael Roth,
Eric Blake
On Tue, Jul 14, 2026 at 06:57:59PM +0200, Roman Bogorodskiy wrote:
> Implement the qmp_guest_get_fsinfo() API for FreeBSD.
> To implement it, reuse build_fs_mount_list() which is already
> implemented for FreeBSD. Extend the FsMount type to include
> a string "fromname" attribute to store the disk the FS is mounted from.
>
> Disk mapping info is not covered by this implementation.
>
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
> Acked-by: Markus Armbruster <armbru@redhat.com>
> Reviewed-by: Kostiantyn Kostiuk <kkostiuk@redhat.com>
> ---
> Changes since v1:
>
> - Replace g_malloc0() with g_new0(.., 1) for GuestFilesystemInfo
>
> Changes since v2:
>
> - Drop the unused 'errp' argument to build_guest_fsinfo() and
> clean up the related code.
> - Fix leaking string through g_strdup() for a g_path_get_basename()
> allocated string.
>
> qga/commands-bsd.c | 53 ++++++++++++++++++++++++++++++++++++++++++-
> qga/commands-common.h | 1 +
> qga/commands-posix.c | 3 +++
> qga/qapi-schema.json | 12 +++++-----
> 4 files changed, 62 insertions(+), 7 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
With regards,
Daniel
--
|: https://berrange.com ~~ https://hachyderm.io/@berrange :|
|: https://libvirt.org ~~ https://entangle-photo.org :|
|: https://pixelfed.art/berrange ~~ https://fstop138.berrange.com :|
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-14 17:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-14 16:57 [PATCH v3] qga: implement 'guest-get-fsinfo' for FreeBSD Roman Bogorodskiy
2026-07-14 17:00 ` Daniel P. Berrangé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.