* [PATCH 1/5] qga: implement 'guest-get-vcpus' for FreeBSD
2026-11-22 9:05 [PATCH 0/5] qga: implement more APIs for FreeBSD Roman Bogorodskiy
@ 2026-11-22 9:05 ` Roman Bogorodskiy
2026-11-22 9:05 ` [PATCH 2/5] qga: implement 'guest-get-cpustats' " Roman Bogorodskiy
` (4 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Roman Bogorodskiy @ 2026-11-22 9:05 UTC (permalink / raw)
To: qemu-devel
Cc: Roman Bogorodskiy, Michael Roth, Kostiantyn Kostiuk, Eric Blake,
Markus Armbruster
Use cpuset_getaffinity() to get vCPUs. This function is specific
to FreeBSD, and other BSDs use other mechanisms, so just
put that under #ifdef __FreeBSD__.
FreeBSD does not support offline CPUs, so reported vCPUs
are always online.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
qga/commands-bsd.c | 32 ++++++++++++++++++++++++++++++++
qga/qapi-schema.json | 4 ++--
tests/unit/test-qga.c | 4 ++++
3 files changed, 38 insertions(+), 2 deletions(-)
diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c
index 830ad08ac0..99657b6796 100644
--- a/qga/commands-bsd.c
+++ b/qga/commands-bsd.c
@@ -23,6 +23,7 @@
#include <net/if_dl.h>
#include <sys/statvfs.h>
#if defined(__FreeBSD__)
+#include <sys/cpuset.h>
#include <sys/sysctl.h>
#include <net/route.h>
#include <net/if.h>
@@ -526,4 +527,35 @@ GuestNetworkRouteList *qmp_guest_network_get_route(Error **errp)
return head;
}
+
+GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
+{
+ cpuset_t mask;
+ GuestLogicalProcessorList *head, **tail;
+ int bit;
+
+ head = NULL;
+ tail = &head;
+
+ if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_CPUSET, 0,
+ sizeof(mask), &mask) != 0) {
+ error_setg_errno(errp, errno, "getaffinity");
+ return NULL;
+ }
+
+ for (bit = 0; bit < CPU_SETSIZE; bit++) {
+ if (CPU_ISSET(bit, &mask)) {
+ GuestLogicalProcessor *vcpu;
+ vcpu = g_new0(GuestLogicalProcessor, 1);
+ vcpu->logical_id = bit;
+ vcpu->online = true;
+ vcpu->has_can_offline = true;
+ vcpu->can_offline = false;
+ QAPI_LIST_APPEND(tail, vcpu);
+ }
+ }
+
+ return head;
+}
+
#endif /* __FreeBSD__ */
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index de42dfe77d..d74b94dc8a 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -735,7 +735,7 @@
'data': {'logical-id': 'int',
'online': 'bool',
'*can-offline': 'bool'},
- 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] } }
+ 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32', 'CONFIG_FREEBSD'] } }
##
# @guest-get-vcpus:
@@ -748,7 +748,7 @@
##
{ 'command': 'guest-get-vcpus',
'returns': ['GuestLogicalProcessor'],
- 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32'] } }
+ 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_WIN32', 'CONFIG_FREEBSD'] } }
##
# @guest-set-vcpus:
diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index b1c84c188b..a8387bd8e8 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -1117,9 +1117,13 @@ int main(int argc, char **argv)
g_test_add_data_func("/qga/info", &fix, test_qga_info);
g_test_add_data_func("/qga/network-get-interfaces", &fix,
test_qga_network_get_interfaces);
+#if defined(CONFIG_LINUX)
if (!access("/sys/devices/system/cpu/cpu0", F_OK)) {
g_test_add_data_func("/qga/get-vcpus", &fix, test_qga_get_vcpus);
}
+#elif defined(CONFIG_FREEBSD)
+ g_test_add_data_func("/qga/get-vcpus", &fix, test_qga_get_vcpus);
+#endif
g_test_add_data_func("/qga/get-fsinfo", &fix, test_qga_get_fsinfo);
g_test_add_data_func("/qga/get-load", &fix, test_qga_get_load);
g_test_add_data_func("/qga/get-memory-block-info", &fix,
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 2/5] qga: implement 'guest-get-cpustats' for FreeBSD
2026-11-22 9:05 [PATCH 0/5] qga: implement more APIs for FreeBSD Roman Bogorodskiy
2026-11-22 9:05 ` [PATCH 1/5] qga: implement 'guest-get-vcpus' " Roman Bogorodskiy
@ 2026-11-22 9:05 ` Roman Bogorodskiy
2026-11-22 9:05 ` [PATCH 3/5] qga: implement 'guest-get-disks' " Roman Bogorodskiy
` (3 subsequent siblings)
5 siblings, 0 replies; 10+ messages in thread
From: Roman Bogorodskiy @ 2026-11-22 9:05 UTC (permalink / raw)
To: qemu-devel
Cc: Roman Bogorodskiy, Michael Roth, Kostiantyn Kostiuk, Eric Blake,
Markus Armbruster
Currently, 'guest-get-cpustats' is implemented for Linux and uses
a Linux-specific GuestLinuxCpuStats. Introduce a BSD specific
type 'GuestBsdCpuStats'. Current implementation adds FreeBSD support,
but it's expected that the type could be shared for other BSD
implementations.
This implementation is built on top of the "kern.cp_times" sysctl.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
qga/commands-bsd.c | 62 ++++++++++++++++++++++++++++++++++++++++++++
qga/qapi-schema.json | 44 +++++++++++++++++++++++++++----
2 files changed, 101 insertions(+), 5 deletions(-)
diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c
index 99657b6796..0f97427d8b 100644
--- a/qga/commands-bsd.c
+++ b/qga/commands-bsd.c
@@ -558,4 +558,66 @@ GuestLogicalProcessorList *qmp_guest_get_vcpus(Error **errp)
return head;
}
+GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
+{
+ GuestCpuStatsList *head = NULL, **tail = &head;
+ int maxcpu;
+ int maxid;
+ g_autofree long *times = NULL;
+ size_t size;
+ int i, j, empty;
+ struct clockinfo clockrate;
+ int hz;
+
+ size = sizeof(clockrate);
+ if (sysctlbyname("kern.clockrate", &clockrate, &size, NULL, 0) == -1) {
+ error_setg_errno(errp, errno, "sysctlbyname(kern.clockrate)");
+ return NULL;
+ }
+ hz = clockrate.stathz ? clockrate.stathz : clockrate.hz;
+
+ size = sizeof(maxcpu);
+ if (sysctlbyname("kern.smp.maxcpus", &maxcpu, &size, NULL, 0) == -1) {
+ error_setg_errno(errp, errno, "sysctlbyname(kern.smp.maxcpus)");
+ return NULL;
+ }
+ times = g_new0(long, maxcpu * CPUSTATES);
+ size = sizeof(long) * maxcpu * CPUSTATES;
+ if (sysctlbyname("kern.cp_times", times, &size, NULL, 0) == -1) {
+ error_setg_errno(errp, errno, "sysctlbyname(kern.cp_times)");
+ return NULL;
+ }
+
+ maxid = MIN(size / CPUSTATES / sizeof(long) - 1, CPU_SETSIZE - 1);
+ for (i = 0; i <= maxid; i++) {
+ GuestCpuStats *cpustat = NULL;
+ GuestBsdCpuStats *bsdcpustat;
+
+ empty = 1;
+ for (j = 0; empty && j < CPUSTATES; j++) {
+ if (times[i * CPUSTATES + j] != 0) {
+ empty = 0;
+ }
+ }
+ if (empty) {
+ continue;
+ }
+
+ cpustat = g_new0(GuestCpuStats, 1);
+ cpustat->type = GUEST_CPU_STATS_TYPE_BSD;
+
+ bsdcpustat = &cpustat->u.bsd;
+ bsdcpustat->cpu = i;
+#define TO_MS(X) ((uint64_t)(unsigned long)(X) * 1000 / hz)
+ bsdcpustat->user = TO_MS(times[i * CPUSTATES + CP_USER]);
+ bsdcpustat->nice = TO_MS(times[i * CPUSTATES + CP_NICE]);
+ bsdcpustat->system = TO_MS(times[i * CPUSTATES + CP_SYS]);
+ bsdcpustat->idle = TO_MS(times[i * CPUSTATES + CP_IDLE]);
+ bsdcpustat->irq = TO_MS(times[i * CPUSTATES + CP_INTR]);
+#undef TO_MS
+
+ QAPI_LIST_APPEND(tail, cpustat);
+ }
+ return head;
+}
#endif /* __FreeBSD__ */
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index d74b94dc8a..4856a549a6 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -1700,12 +1700,14 @@
# Guest operating systems supporting CPU statistics
#
# @linux: Linux
+# @bsd: FreeBSD (Since 12.0)
#
# Since: 7.1
##
{ 'enum': 'GuestCpuStatsType',
- 'data': [ 'linux' ],
- 'if': 'CONFIG_LINUX' }
+ 'data': [ 'linux', 'bsd' ],
+ 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_FREEBSD'] }
+}
##
# @GuestLinuxCpuStats:
@@ -1751,6 +1753,34 @@
},
'if': 'CONFIG_LINUX' }
+##
+# @GuestBsdCpuStats:
+# CPU statistics of BSD
+#
+# @cpu: CPU index in guest OS
+#
+# @user: Time spent in user mode
+#
+# @nice: Time spent in user mode with low priority (nice)
+#
+# @system: Time spent in system mode
+#
+# @idle: Time spent in the idle task
+#
+# @irq: Time servicing interrupts
+#
+# Since: 12.0
+##
+{ 'struct': 'GuestBsdCpuStats',
+ 'data': {'cpu': 'int',
+ 'user': 'uint64',
+ 'nice': 'uint64',
+ 'system': 'uint64',
+ 'idle': 'uint64',
+ 'irq': 'uint64'
+ },
+ 'if': 'CONFIG_FREEBSD' }
+
##
# @GuestCpuStats:
# Get statistics of each CPU in millisecond.
@@ -1762,8 +1792,12 @@
{ 'union': 'GuestCpuStats',
'base': { 'type': 'GuestCpuStatsType' },
'discriminator': 'type',
- 'data': { 'linux': 'GuestLinuxCpuStats' },
- 'if': 'CONFIG_LINUX' }
+ 'data': {
+ 'linux': { 'type': 'GuestLinuxCpuStats', 'if': 'CONFIG_LINUX'},
+ 'bsd': { 'type': 'GuestBsdCpuStats', 'if': 'CONFIG_FREEBSD' }
+ },
+ 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_FREEBSD'] }
+}
##
# @guest-get-cpustats:
@@ -1775,7 +1809,7 @@
##
{ 'command': 'guest-get-cpustats',
'returns': ['GuestCpuStats'],
- 'if': 'CONFIG_LINUX'
+ 'if': { 'any': ['CONFIG_LINUX', 'CONFIG_FREEBSD'] }
}
##
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 3/5] qga: implement 'guest-get-disks' for FreeBSD
2026-11-22 9:05 [PATCH 0/5] qga: implement more APIs for FreeBSD Roman Bogorodskiy
2026-11-22 9:05 ` [PATCH 1/5] qga: implement 'guest-get-vcpus' " Roman Bogorodskiy
2026-11-22 9:05 ` [PATCH 2/5] qga: implement 'guest-get-cpustats' " Roman Bogorodskiy
@ 2026-11-22 9:05 ` Roman Bogorodskiy
2026-11-24 10:43 ` Markus Armbruster
2026-11-22 9:05 ` [PATCH 4/5] tests/unit/test-qga: test 'guest-get-disks' Roman Bogorodskiy
` (2 subsequent siblings)
5 siblings, 1 reply; 10+ messages in thread
From: Roman Bogorodskiy @ 2026-11-22 9:05 UTC (permalink / raw)
To: qemu-devel
Cc: Roman Bogorodskiy, Michael Roth, Kostiantyn Kostiuk, Eric Blake,
Markus Armbruster
The implementation uses the "kern.geom.conftxt" sysctl.
It resides under the "#ifdef __FreeBSD__" block as
other BSDs do not have GEOM.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
qga/commands-bsd.c | 77 ++++++++++++++++++++++++++++++++++++++++++++
qga/qapi-schema.json | 13 ++++----
2 files changed, 84 insertions(+), 6 deletions(-)
diff --git a/qga/commands-bsd.c b/qga/commands-bsd.c
index 0f97427d8b..f8b4ffd175 100644
--- a/qga/commands-bsd.c
+++ b/qga/commands-bsd.c
@@ -13,6 +13,7 @@
#include "qemu/osdep.h"
#include "qga-qapi-commands.h"
#include "qapi/error.h"
+#include "qemu/cutils.h"
#include "qemu/queue.h"
#include "block/block-common.h"
#include "commands-common.h"
@@ -620,4 +621,80 @@ GuestCpuStatsList *qmp_guest_get_cpustats(Error **errp)
}
return head;
}
+
+GuestDiskInfoList *qmp_guest_get_disks(Error **errp)
+{
+ GuestDiskInfoList *ret = NULL;
+ GuestDiskInfo *disk;
+ g_autofree char *buf = NULL;
+ g_auto(GStrv) lines = NULL;
+ g_autoptr(GHashTable) providers = NULL;
+ size_t len;
+ int i;
+
+ if (sysctlbyname("kern.geom.conftxt", NULL, &len, NULL, 0) == -1) {
+ error_setg_errno(errp, errno, "sysctlbyname(kern.geom.conftxt)");
+ return NULL;
+ }
+
+ buf = g_malloc0(len);
+
+ if (sysctlbyname("kern.geom.conftxt", buf, &len, NULL, 0) == -1) {
+ error_setg_errno(errp, errno, "sysctlbyname(kern.geom.conftxt)");
+ return NULL;
+ }
+
+ providers = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
+ lines = g_strsplit(buf, "\n", -1);
+ for (i = 0; lines[i] != NULL; ++i) {
+ g_auto(GStrv) tokens = NULL;
+ bool is_part = false;
+ uint64_t mediasize;
+
+ if (strlen(lines[i]) == 0) {
+ continue;
+ }
+
+ tokens = g_strsplit(lines[i], " ", -1);
+
+ /*
+ * kern.geom.conftxt format:
+ *
+ * 0 DISK ada0 8001563222016 512 hd 16 sc 63
+ * 1 PART ada0p1 8001563181056 512 i 1 o 20480 ty freebsd-ufs xs GPT xt <uuid>
+ */
+ if (g_strv_length(tokens) < 5) {
+ continue;
+ }
+
+ if (g_str_equal(tokens[1], "DISK")) {
+ /* nada */
+ } else if (g_str_equal(tokens[1], "PART")) {
+ is_part = true;
+ } else {
+ continue;
+ }
+
+ if (qemu_strtou64(tokens[3], NULL, 10, &mediasize) < 0 ||
+ mediasize == 0) {
+ continue;
+ }
+
+ /* Filter out duplicate providers, for example for mirrors */
+ if (g_hash_table_contains(providers, tokens[2])) {
+ continue;
+ } else {
+ g_hash_table_add(providers, g_strdup(tokens[2]));
+ }
+
+ disk = g_new0(GuestDiskInfo, 1);
+ disk->name = g_strdup_printf("/dev/%s", tokens[2]);
+ disk->partition = is_part;
+
+ QAPI_LIST_PREPEND(ret, disk);
+ }
+
+ return ret;
+}
+
#endif /* __FreeBSD__ */
diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
index 4856a549a6..35aaa040cf 100644
--- a/qga/qapi-schema.json
+++ b/qga/qapi-schema.json
@@ -947,7 +947,7 @@
'media-errors-hi': 'uint64',
'number-of-error-log-entries-lo': 'uint64',
'number-of-error-log-entries-hi': 'uint64' },
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
##
# @GuestDiskSmart:
@@ -961,12 +961,12 @@
'base': { 'type': 'GuestDiskBusType' },
'discriminator': 'type',
'data': { 'nvme': 'GuestNVMeSmart' },
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
##
# @GuestDiskInfo:
#
-# @name: device node (Linux) or device UNC (Windows)
+# @name: device node (Linux, FreeBSD) or device UNC (Windows)
#
# @partition: whether this is a partition or disk
#
@@ -987,7 +987,7 @@
'data': {'name': 'str', 'partition': 'bool', '*dependencies': ['str'],
'*address': 'GuestDiskAddress', '*alias': 'str',
'*smart': 'GuestDiskSmart'},
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
##
# @guest-get-disks:
@@ -995,13 +995,14 @@
# Returns: The list of disks in the guest. For Windows these are only
# the physical disks. On Linux these are all root block devices
# of non-zero size including e.g. removable devices, loop devices,
-# NBD, etc.
+# NBD, etc. On FreeBSD these are nonzero-size GEOM DISK and PART
+# providers (since 12.0).
#
# Since: 5.2
##
{ 'command': 'guest-get-disks',
'returns': ['GuestDiskInfo'],
- 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
+ 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
##
# @GuestFilesystemInfo:
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 3/5] qga: implement 'guest-get-disks' for FreeBSD
2026-11-22 9:05 ` [PATCH 3/5] qga: implement 'guest-get-disks' " Roman Bogorodskiy
@ 2026-11-24 10:43 ` Markus Armbruster
2026-11-24 18:22 ` Roman Bogorodskiy
0 siblings, 1 reply; 10+ messages in thread
From: Markus Armbruster @ 2026-11-24 10:43 UTC (permalink / raw)
To: Roman Bogorodskiy
Cc: qemu-devel, Michael Roth, Kostiantyn Kostiuk, Eric Blake
Roman Bogorodskiy <bogorodskiy@gmail.com> writes:
> The implementation uses the "kern.geom.conftxt" sysctl.
> It resides under the "#ifdef __FreeBSD__" block as
> other BSDs do not have GEOM.
>
> Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
[...]
> diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> index 4856a549a6..35aaa040cf 100644
> --- a/qga/qapi-schema.json
> +++ b/qga/qapi-schema.json
> @@ -947,7 +947,7 @@
> 'media-errors-hi': 'uint64',
> 'number-of-error-log-entries-lo': 'uint64',
> 'number-of-error-log-entries-hi': 'uint64' },
> - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
> + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
>
> ##
> # @GuestDiskSmart:
> @@ -961,12 +961,12 @@
> 'base': { 'type': 'GuestDiskBusType' },
> 'discriminator': 'type',
> 'data': { 'nvme': 'GuestNVMeSmart' },
> - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
> + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
>
> ##
> # @GuestDiskInfo:
> #
> -# @name: device node (Linux) or device UNC (Windows)
> +# @name: device node (Linux, FreeBSD) or device UNC (Windows)
> #
> # @partition: whether this is a partition or disk
> #
> @@ -987,7 +987,7 @@
> 'data': {'name': 'str', 'partition': 'bool', '*dependencies': ['str'],
> '*address': 'GuestDiskAddress', '*alias': 'str',
> '*smart': 'GuestDiskSmart'},
> - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
> + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
>
> ##
> # @guest-get-disks:
> @@ -995,13 +995,14 @@
> # Returns: The list of disks in the guest. For Windows these are only
> # the physical disks. On Linux these are all root block devices
> # of non-zero size including e.g. removable devices, loop devices,
> -# NBD, etc.
> +# NBD, etc. On FreeBSD these are nonzero-size GEOM DISK and PART
> +# providers (since 12.0).
The (since 12.0) applies just to the sentence about FreeBSD. Rather
subtle.
Elsewhere in this series, you don't add (since 12.0) when you implement
something for FreeBSD. How useful is it here?
> #
> # Since: 5.2
> ##
> { 'command': 'guest-get-disks',
> 'returns': ['GuestDiskInfo'],
> - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
> + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
>
> ##
> # @GuestFilesystemInfo:
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 3/5] qga: implement 'guest-get-disks' for FreeBSD
2026-11-24 10:43 ` Markus Armbruster
@ 2026-11-24 18:22 ` Roman Bogorodskiy
2026-11-27 13:00 ` Markus Armbruster
0 siblings, 1 reply; 10+ messages in thread
From: Roman Bogorodskiy @ 2026-11-24 18:22 UTC (permalink / raw)
To: Markus Armbruster
Cc: qemu-devel, Michael Roth, Kostiantyn Kostiuk, Eric Blake
Markus Armbruster wrote:
> Roman Bogorodskiy <bogorodskiy@gmail.com> writes:
>
> > The implementation uses the "kern.geom.conftxt" sysctl.
> > It resides under the "#ifdef __FreeBSD__" block as
> > other BSDs do not have GEOM.
> >
> > Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
>
> [...]
>
> > diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
> > index 4856a549a6..35aaa040cf 100644
> > --- a/qga/qapi-schema.json
> > +++ b/qga/qapi-schema.json
> > @@ -947,7 +947,7 @@
> > 'media-errors-hi': 'uint64',
> > 'number-of-error-log-entries-lo': 'uint64',
> > 'number-of-error-log-entries-hi': 'uint64' },
> > - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
> > + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
> >
> > ##
> > # @GuestDiskSmart:
> > @@ -961,12 +961,12 @@
> > 'base': { 'type': 'GuestDiskBusType' },
> > 'discriminator': 'type',
> > 'data': { 'nvme': 'GuestNVMeSmart' },
> > - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
> > + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
> >
> > ##
> > # @GuestDiskInfo:
> > #
> > -# @name: device node (Linux) or device UNC (Windows)
> > +# @name: device node (Linux, FreeBSD) or device UNC (Windows)
> > #
> > # @partition: whether this is a partition or disk
> > #
> > @@ -987,7 +987,7 @@
> > 'data': {'name': 'str', 'partition': 'bool', '*dependencies': ['str'],
> > '*address': 'GuestDiskAddress', '*alias': 'str',
> > '*smart': 'GuestDiskSmart'},
> > - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
> > + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
> >
> > ##
> > # @guest-get-disks:
> > @@ -995,13 +995,14 @@
> > # Returns: The list of disks in the guest. For Windows these are only
> > # the physical disks. On Linux these are all root block devices
> > # of non-zero size including e.g. removable devices, loop devices,
> > -# NBD, etc.
> > +# NBD, etc. On FreeBSD these are nonzero-size GEOM DISK and PART
> > +# providers (since 12.0).
>
> The (since 12.0) applies just to the sentence about FreeBSD. Rather
> subtle.
>
> Elsewhere in this series, you don't add (since 12.0) when you implement
> something for FreeBSD. How useful is it here?
Yes, I have to admit that I was having a hard time deciding where to put
that.
This series actually adds "@bsd: FreeBSD (Since 12.0)" to
"@GuestCpuStatsType" but that was an easy one as it's definitely useful
to know that the new type has appeared.
For the rest of the entries I'm not really sure. The example you're
referring too can be confusing indeed.
Should I use something like:
# Since 5.2 (Linux only); 12.0 (FreeBSD)
or omit these completely?
> > #
> > # Since: 5.2
> > ##
> > { 'command': 'guest-get-disks',
> > 'returns': ['GuestDiskInfo'],
> > - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
> > + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
> >
> > ##
> > # @GuestFilesystemInfo:
^ permalink raw reply [flat|nested] 10+ messages in thread* Re: [PATCH 3/5] qga: implement 'guest-get-disks' for FreeBSD
2026-11-24 18:22 ` Roman Bogorodskiy
@ 2026-11-27 13:00 ` Markus Armbruster
0 siblings, 0 replies; 10+ messages in thread
From: Markus Armbruster @ 2026-11-27 13:00 UTC (permalink / raw)
To: Roman Bogorodskiy
Cc: qemu-devel, Michael Roth, Kostiantyn Kostiuk, Eric Blake
Roman Bogorodskiy <bogorodskiy@gmail.com> writes:
> Markus Armbruster wrote:
>
>> Roman Bogorodskiy <bogorodskiy@gmail.com> writes:
>>
>> > The implementation uses the "kern.geom.conftxt" sysctl.
>> > It resides under the "#ifdef __FreeBSD__" block as
>> > other BSDs do not have GEOM.
>> >
>> > Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
>>
>> [...]
>>
>> > diff --git a/qga/qapi-schema.json b/qga/qapi-schema.json
>> > index 4856a549a6..35aaa040cf 100644
>> > --- a/qga/qapi-schema.json
>> > +++ b/qga/qapi-schema.json
>> > @@ -947,7 +947,7 @@
>> > 'media-errors-hi': 'uint64',
>> > 'number-of-error-log-entries-lo': 'uint64',
>> > 'number-of-error-log-entries-hi': 'uint64' },
>> > - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
>> > + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
>> >
>> > ##
>> > # @GuestDiskSmart:
>> > @@ -961,12 +961,12 @@
>> > 'base': { 'type': 'GuestDiskBusType' },
>> > 'discriminator': 'type',
>> > 'data': { 'nvme': 'GuestNVMeSmart' },
>> > - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
>> > + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
>> >
>> > ##
>> > # @GuestDiskInfo:
>> > #
>> > -# @name: device node (Linux) or device UNC (Windows)
>> > +# @name: device node (Linux, FreeBSD) or device UNC (Windows)
>> > #
>> > # @partition: whether this is a partition or disk
>> > #
>> > @@ -987,7 +987,7 @@
>> > 'data': {'name': 'str', 'partition': 'bool', '*dependencies': ['str'],
>> > '*address': 'GuestDiskAddress', '*alias': 'str',
>> > '*smart': 'GuestDiskSmart'},
>> > - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
>> > + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
>> >
>> > ##
>> > # @guest-get-disks:
>> > @@ -995,13 +995,14 @@
>> > # Returns: The list of disks in the guest. For Windows these are only
>> > # the physical disks. On Linux these are all root block devices
>> > # of non-zero size including e.g. removable devices, loop devices,
>> > -# NBD, etc.
>> > +# NBD, etc. On FreeBSD these are nonzero-size GEOM DISK and PART
>> > +# providers (since 12.0).
>>
>> The (since 12.0) applies just to the sentence about FreeBSD. Rather
>> subtle.
>>
>> Elsewhere in this series, you don't add (since 12.0) when you implement
>> something for FreeBSD. How useful is it here?
>
> Yes, I have to admit that I was having a hard time deciding where to put
> that.
>
> This series actually adds "@bsd: FreeBSD (Since 12.0)" to
> "@GuestCpuStatsType" but that was an easy one as it's definitely useful
> to know that the new type has appeared.
>
> For the rest of the entries I'm not really sure. The example you're
> referring too can be confusing indeed.
>
> Should I use something like:
>
> # Since 5.2 (Linux only); 12.0 (FreeBSD)
For better or worse, that's what you did in commit 0ae3840f612b (qga:
implement 'guest-network-get-route' for FreeBSD) following precedence of
Elizabeth's commit 595a77289d07 (qga: implement guest-network-get-route
for Windows). So let's do that again.
> or omit these completely?
>
>> > #
>> > # Since: 5.2
>> > ##
>> > { 'command': 'guest-get-disks',
>> > 'returns': ['GuestDiskInfo'],
>> > - 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV' ] } }
>> > + 'if': { 'any': [ 'CONFIG_WIN32', 'CONFIG_LIBUDEV', 'CONFIG_FREEBSD' ] } }
>> >
>> > ##
>> > # @GuestFilesystemInfo:
^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 4/5] tests/unit/test-qga: test 'guest-get-disks'
2026-11-22 9:05 [PATCH 0/5] qga: implement more APIs for FreeBSD Roman Bogorodskiy
` (2 preceding siblings ...)
2026-11-22 9:05 ` [PATCH 3/5] qga: implement 'guest-get-disks' " Roman Bogorodskiy
@ 2026-11-22 9:05 ` Roman Bogorodskiy
2026-11-22 9:05 ` [PATCH 5/5] tests/unit/test-qga: test 'guest-get-cpustats' Roman Bogorodskiy
2026-11-27 13:02 ` [PATCH 0/5] qga: implement more APIs for FreeBSD Markus Armbruster
5 siblings, 0 replies; 10+ messages in thread
From: Roman Bogorodskiy @ 2026-11-22 9:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Roman Bogorodskiy, Michael Roth, Kostiantyn Kostiuk
Add a test for the 'guest-get-disks' command.
As it's implemented only for CONFIG_WIN32, CONFIG_LIBUDEV,
and CONFIG_FREEBSD, guard the test similarly.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
tests/unit/test-qga.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index a8387bd8e8..a8ef6b0e21 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -1095,6 +1095,30 @@ static void test_qga_guest_get_osinfo(gconstpointer data)
fixture_tear_down(&fixture, NULL);
}
+#if defined(CONFIG_WIN32) || defined(CONFIG_LIBUDEV) || defined(CONFIG_FREEBSD)
+static void test_qga_get_disks(gconstpointer fix)
+{
+ const TestFixture *fixture = fix;
+ g_autoptr(QDict) ret = NULL;
+ QList *list;
+ const QListEntry *entry;
+
+ ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-disks'}");
+ g_assert_nonnull(ret);
+ qmp_assert_no_error(ret);
+
+ list = qdict_get_qlist(ret, "return");
+ QLIST_FOREACH_ENTRY(list, entry) {
+ QDict *qdict;
+
+ qdict = qobject_to(QDict, entry->value);
+ g_assert(qdict);
+ g_assert_cmpuint(strlen(qdict_get_str(qdict, "name")), >, 0);
+ g_assert_nonnull(qobject_to(QBool, qdict_get(qdict, "partition")));
+ }
+}
+#endif
+
int main(int argc, char **argv)
{
TestFixture fix;
@@ -1158,6 +1182,9 @@ int main(int argc, char **argv)
test_qga_guest_get_timezone);
g_test_add_data_func("/qga/guest-get-users", &fix,
test_qga_guest_get_users);
+#if defined(CONFIG_WIN32) || defined(CONFIG_LIBUDEV) || defined(CONFIG_FREEBSD)
+ g_test_add_data_func("/qga/get-disks", &fix, test_qga_get_disks);
+#endif
ret = g_test_run();
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* [PATCH 5/5] tests/unit/test-qga: test 'guest-get-cpustats'
2026-11-22 9:05 [PATCH 0/5] qga: implement more APIs for FreeBSD Roman Bogorodskiy
` (3 preceding siblings ...)
2026-11-22 9:05 ` [PATCH 4/5] tests/unit/test-qga: test 'guest-get-disks' Roman Bogorodskiy
@ 2026-11-22 9:05 ` Roman Bogorodskiy
2026-11-27 13:02 ` [PATCH 0/5] qga: implement more APIs for FreeBSD Markus Armbruster
5 siblings, 0 replies; 10+ messages in thread
From: Roman Bogorodskiy @ 2026-11-22 9:05 UTC (permalink / raw)
To: qemu-devel; +Cc: Roman Bogorodskiy, Michael Roth, Kostiantyn Kostiuk
Add a test for 'guest-get-cpustats'. As it works only
on Linux and FreeBSD, guard the test accordingly.
Validate that the result is not empty and all the required
fields are present.
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
---
tests/unit/test-qga.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/tests/unit/test-qga.c b/tests/unit/test-qga.c
index a8ef6b0e21..530bf97fd1 100644
--- a/tests/unit/test-qga.c
+++ b/tests/unit/test-qga.c
@@ -1119,6 +1119,38 @@ static void test_qga_get_disks(gconstpointer fix)
}
#endif
+static void test_qga_get_cpustats(gconstpointer fix)
+{
+ const TestFixture *fixture = fix;
+ g_autoptr(QDict) ret = NULL;
+ QList *list;
+ const QListEntry *entry;
+
+ ret = qmp_fd(fixture->fd, "{'execute': 'guest-get-cpustats'}");
+ g_assert_nonnull(ret);
+ qmp_assert_no_error(ret);
+
+ list = qdict_get_qlist(ret, "return");
+ g_assert(!qlist_empty(list));
+ QLIST_FOREACH_ENTRY(list, entry) {
+ QDict *qdict;
+
+ qdict = qobject_to(QDict, entry->value);
+ g_assert(qdict);
+#if defined(CONFIG_LINUX)
+ g_assert_cmpstr(qdict_get_str(qdict, "type"), ==, "linux");
+#else
+ g_assert_cmpstr(qdict_get_str(qdict, "type"), ==, "bsd");
+ g_assert(qdict_haskey(qdict, "irq"));
+#endif
+ g_assert(qdict_haskey(qdict, "cpu"));
+ g_assert(qdict_haskey(qdict, "user"));
+ g_assert(qdict_haskey(qdict, "nice"));
+ g_assert(qdict_haskey(qdict, "system"));
+ g_assert(qdict_haskey(qdict, "idle"));
+ }
+}
+
int main(int argc, char **argv)
{
TestFixture fix;
@@ -1185,6 +1217,9 @@ int main(int argc, char **argv)
#if defined(CONFIG_WIN32) || defined(CONFIG_LIBUDEV) || defined(CONFIG_FREEBSD)
g_test_add_data_func("/qga/get-disks", &fix, test_qga_get_disks);
#endif
+#if defined(CONFIG_LINUX) || defined(CONFIG_FREEBSD)
+ g_test_add_data_func("/qga/get-cpustats", &fix, test_qga_get_cpustats);
+#endif
ret = g_test_run();
--
2.56.0
^ permalink raw reply related [flat|nested] 10+ messages in thread* Re: [PATCH 0/5] qga: implement more APIs for FreeBSD
2026-11-22 9:05 [PATCH 0/5] qga: implement more APIs for FreeBSD Roman Bogorodskiy
` (4 preceding siblings ...)
2026-11-22 9:05 ` [PATCH 5/5] tests/unit/test-qga: test 'guest-get-cpustats' Roman Bogorodskiy
@ 2026-11-27 13:02 ` Markus Armbruster
5 siblings, 0 replies; 10+ messages in thread
From: Markus Armbruster @ 2026-11-27 13:02 UTC (permalink / raw)
To: Roman Bogorodskiy; +Cc: qemu-devel
Roman Bogorodskiy <bogorodskiy@gmail.com> writes:
> This series adds FreeBSD implementation for:
>
> - guest-get-vcpus
> - guest-get-cpustats
> - guest-get-disks
>
> It also adds new test-qga tests for 'guest-get-disks'
> and 'guest-get-cpustats'.
>
> Tested locally on FreeBSD -CURRENT amd64.
> Tested with libvirt/QEMU Linux host and FreeBSD -CURRENT amd64 guest.
> Compile tested on OpenBSD 7.9 and NetBSD 11.0.
With less confusing since information in PATCH 3, QAPI schema
Acked-by: Markus Armbruster <armbru@redhat.com>
^ permalink raw reply [flat|nested] 10+ messages in thread