On Mon, Jan 17, 2022 at 11:52:48AM +0100, Andrea Bolognani wrote:
From: Roman Bolshakov <r.bolshakov(a)yadro.com>
This makes possible to add more accelerators by touching less code and
reduces code duplication.
Signed-off-by: Roman Bolshakov <r.bolshakov(a)yadro.com>
Signed-off-by: Andrea Bolognani <abologna(a)redhat.com>
Tested-by: Brad Laue <brad(a)brad-x.com>
---
src/qemu/qemu_capabilities.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
Reviewed-by: Daniel P. Berrangé <berrange(a)redhat.com>
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 401ffe89c9..8d3e8b3afb 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -793,6 +793,16 @@ const char *virQEMUCapsArchToString(virArch arch)
}
+static const char *
+virQEMUCapsAccelStr(virDomainVirtType type)
+{
+ if (type == VIR_DOMAIN_VIRT_QEMU)
+ return "tcg";
+
+ return virDomainVirtTypeToString(type);
+}
I don't like this use of virDomainVirtTypeToString since the
vast majority of values it returns are not valid QEMU accelerators.
I'd say we should just directly return the virt types we actually
expect to get - the invalid ones will have already been filtered
out. ie
virQEMUCapsAccelStr(virDomainVirtType type)
{
if (type == VIR_DOMAIN_VIRT_KVM)
return "kvm";
else
return "tcg";
}
that is still easily extended to add hvf and so on, without being
misleading about supporting any virt type
+
+
/* Checks whether a domain with @guest arch can run natively on @host.
*/
bool
@@ -4079,7 +4089,7 @@ virQEMUCapsLoadAccel(virQEMUCaps *qemuCaps,
virDomainVirtType type)
{
virQEMUCapsAccel *caps = virQEMUCapsGetAccel(qemuCaps, type);
- const char *typeStr = type == VIR_DOMAIN_VIRT_KVM ? "kvm" :
"tcg";
+ const char *typeStr = virQEMUCapsAccelStr(type);
if (virQEMUCapsLoadHostCPUModelInfo(caps, ctxt, typeStr) < 0)
return -1;
@@ -4632,7 +4642,7 @@ virQEMUCapsFormatAccel(virQEMUCaps *qemuCaps,
virDomainVirtType type)
{
virQEMUCapsAccel *caps = virQEMUCapsGetAccel(qemuCaps, type);
- const char *typeStr = type == VIR_DOMAIN_VIRT_KVM ? "kvm" :
"tcg";
+ const char *typeStr = virQEMUCapsAccelStr(type);
virQEMUCapsFormatHostCPUModelInfo(caps, buf, typeStr);
virQEMUCapsFormatCPUModels(caps, buf, typeStr);
--
2.34.1
Regards,
Daniel
--
|:
https://berrange.com -o-
https://www.flickr.com/photos/dberrange :|
|:
https://libvirt.org -o-
https://fstop138.berrange.com :|
|:
https://entangle-photo.org -o-
https://www.instagram.com/dberrange :|