Skip to contentSkip to conversation

qga: implement 'guest-get-fsinfo' for FreeBSD

PATCH In review Roman Bogorodskiy 3 participants 7 messages Jul 14 – Sep 8

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 qga: implement 'guest-get-fsinfo' for FreeBSD

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.

---
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(-)
qga/commands-bsd.c +52 -1
index 94ff6fee6a..1c51d099eb 100644
@@ -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__ */
qga/commands-common.h +1 -0
index 263e7c0525..a07d0885f5 100644
@@ -29,6 +29,7 @@ typedef struct FsMount {
 #if defined(__FreeBSD__)
     dev_t dev;
     fsid_t fsid;
+    char *fromname;
 #endif
     QTAILQ_ENTRY(FsMount) next;
 } FsMount;
qga/commands-posix.c +3 -0
index 837be51c40..837e285b6d 100644
@@ -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);
      }
 }
qga/qapi-schema.json +6 -6
index c57bc9a02f..8cd0ba048b 100644
@@ -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:
Signature · 1 line
2.52.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 22 lines · Roman Bogorodskiy

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.

---
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.

Quoted 5 lines
 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(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#2 lore raw
In reply to Roman Bogorodskiy
Quoted 22 lines · Roman Bogorodskiy

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.

---
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.

Quoted 5 lines
 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(-)

ping

https://patchew.org/QEMU/[email protected]/

Reviewed-by
#3 lore raw

Will be merged after code freeze

Quoted 35 lines · Roman Bogorodskiy
Quoted 22 lines · Roman Bogorodskiy

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.

---
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.

Quoted 5 lines
 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(-)

ping

https://patchew.org/QEMU/[email protected]/

#4 lore raw
Quoted 3 lines · Kostiantyn Kostiuk

Will be merged after code freeze

NB there is no current code freeze, the tree is open.

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|
#5 lore raw
In reply to Kostiantyn Kostiuk
Quoted 3 lines · Kostiantyn Kostiuk

Will be merged after code freeze

Hi Kostiantyn,

Gentle ping on this one now that the code freeze should be over.

Quoted 38 lines
Quoted 35 lines · Roman Bogorodskiy
Quoted 22 lines · Roman Bogorodskiy

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.

---
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.

Quoted 5 lines
 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(-)

ping

https://patchew.org/QEMU/[email protected]/

#6 lore raw

I plan to merge this patch this week

Quoted 53 lines · Roman Bogorodskiy
Quoted 3 lines · Kostiantyn Kostiuk

Will be merged after code freeze

Hi Kostiantyn,

Gentle ping on this one now that the code freeze should be over.

Quoted 1 line

On Wed, Aug 12, 2026 at 12:43 PM Roman Bogorodskiy <

[email protected]>

Quoted 8 lines
Quoted 6 lines · wrote:
Quoted 4 lines · Roman Bogorodskiy

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.

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines

Disk mapping info is not covered by this implementation.

---
Changes since v1:

- Replace g_malloc0() with g_new0(.., 1) for GuestFilesystemInfo

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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

++++++++++++++++++++++++++++++++++++++++++-

Quoted 10 lines
Quoted 10 lines
Quoted 4 lines
 qga/commands-common.h |  1 +
 qga/commands-posix.c  |  3 +++
 qga/qapi-schema.json  | 12 +++++-----
 4 files changed, 62 insertions(+), 7 deletions(-)

ping

https://patchew.org/QEMU/[email protected]/