qemu: Introduce virQEMUCapsAccelStr

This makes possible to add more accelerators by touching less code and
reduces code duplication.

Signed-off-by: Roman Bolshakov <r.bolshakov@yadro.com>
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Tested-by: Brad Laue <brad@brad-x.com>
Tested-by: Christophe Fergeau <cfergeau@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Roman Bolshakov 2018-10-19 19:38:33 +03:00 committed by Andrea Bolognani
parent c6bf66e1ee
commit 9c56dae1cb

View File

@ -839,6 +839,16 @@ virQEMUCapsFindTarget(virArch hostarch,
} }
static const char *
virQEMUCapsAccelStr(virDomainVirtType type)
{
if (type == VIR_DOMAIN_VIRT_KVM)
return "kvm";
return "tcg";
}
static virQEMUCapsAccel * static virQEMUCapsAccel *
virQEMUCapsGetAccel(virQEMUCaps *qemuCaps, virQEMUCapsGetAccel(virQEMUCaps *qemuCaps,
virDomainVirtType type) virDomainVirtType type)
@ -4067,7 +4077,7 @@ virQEMUCapsLoadAccel(virQEMUCaps *qemuCaps,
virDomainVirtType type) virDomainVirtType type)
{ {
virQEMUCapsAccel *caps = virQEMUCapsGetAccel(qemuCaps, 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) if (virQEMUCapsLoadHostCPUModelInfo(caps, ctxt, typeStr) < 0)
return -1; return -1;
@ -4620,7 +4630,7 @@ virQEMUCapsFormatAccel(virQEMUCaps *qemuCaps,
virDomainVirtType type) virDomainVirtType type)
{ {
virQEMUCapsAccel *caps = virQEMUCapsGetAccel(qemuCaps, 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); virQEMUCapsFormatHostCPUModelInfo(caps, buf, typeStr);
virQEMUCapsFormatCPUModels(caps, buf, typeStr); virQEMUCapsFormatCPUModels(caps, buf, typeStr);