Separate the architecture specific code to probe the support for HVF from the actual setting of the capability. In upcoming patches 'virQEMUCapsProbeHVF' will be mocked in the testsuite to provide testing for the HVF hypervisor. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/qemu/qemu_capabilities.c | 19 ++++++++----------- src/qemu/qemu_capabilities.h | 3 ++- tests/domaincapsmock.c | 4 ++-- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 9a310a0f2d..f37a81bfe7 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3339,7 +3339,7 @@ virQEMUCapsProbeQMPKVMState(virQEMUCaps *qemuCaps, } #ifdef __APPLE__ -int +bool virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps) { int hv_support = 0; @@ -3349,22 +3349,19 @@ virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps) /* Guest and host arch need to match for hardware acceleration * to be usable */ if (qemuCaps->arch != hostArch) - return 0; + return false; /* We need the OS to report Hypervisor.framework availability */ if (sysctlbyname("kern.hv_support", &hv_support, &len, NULL, 0) < 0) - return 0; - - if (hv_support) - virQEMUCapsSet(qemuCaps, QEMU_CAPS_HVF); + return false; - return 0; + return !!hv_support; } #else -int +bool virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps G_GNUC_UNUSED) { - return 0; + return false; } #endif @@ -5629,8 +5626,8 @@ virQEMUCapsInitQMPMonitor(virQEMUCaps *qemuCaps, if (virQEMUCapsProbeQMPKVMState(qemuCaps, mon) < 0) return -1; - if (virQEMUCapsProbeHVF(qemuCaps) < 0) - return -1; + if (virQEMUCapsProbeHVF(qemuCaps)) + virQEMUCapsSet(qemuCaps, QEMU_CAPS_HVF); type = virQEMUCapsGetVirtType(qemuCaps); accel = virQEMUCapsGetAccel(qemuCaps, type); diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index c4f1708639..15f0df5317 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -887,7 +887,8 @@ virQEMUCapsGetSGXCapabilities(virQEMUCaps *qemuCaps); bool virQEMUCapsGetKVMSupportsSecureGuest(virQEMUCaps *qemuCaps) G_NO_INLINE; -int virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps) G_NO_INLINE; +bool +virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps) G_NO_INLINE; virArch virQEMUCapsArchFromString(const char *arch); const char *virQEMUCapsArchToString(virArch arch); diff --git a/tests/domaincapsmock.c b/tests/domaincapsmock.c index 4d53e48c48..8f27eeb3a1 100644 --- a/tests/domaincapsmock.c +++ b/tests/domaincapsmock.c @@ -52,10 +52,10 @@ virQEMUCapsGetKVMSupportsSecureGuest(virQEMUCaps *qemuCaps) return real_virQEMUCapsGetKVMSupportsSecureGuest(qemuCaps); } -int +bool virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps G_GNUC_UNUSED) { - return 0; + return false; } #endif -- 2.39.2