virQEMUCapsProbeHVF: Factor out setting of the capability

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@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-03-08 18:14:03 +01:00
parent 111cfc5532
commit 6af47df5ac
3 changed files with 12 additions and 14 deletions

View File

@ -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;
return false;
if (hv_support)
virQEMUCapsSet(qemuCaps, QEMU_CAPS_HVF);
return 0;
return !!hv_support;
}
#else
int
bool
virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps G_GNUC_UNUSED)
{
return 0;
return false;
}
#endif
@ -5626,8 +5623,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);

View File

@ -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);

View File

@ -52,10 +52,10 @@ virQEMUCapsGetKVMSupportsSecureGuest(virQEMUCaps *qemuCaps)
return real_virQEMUCapsGetKVMSupportsSecureGuest(qemuCaps);
}
int
bool
virQEMUCapsProbeHVF(virQEMUCaps *qemuCaps G_GNUC_UNUSED)
{
return 0;
return false;
}
#endif