mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 14:15:28 +00:00
qemu: Refactor virQEMUCapsLoadAccel
And make it use virQEMUCapsGetAccel once rather than repeating the same code in all functions called from virQEMUCapsLoadAccel. Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
948d2fbb66
commit
4fd90d06e6
@ -3340,26 +3340,22 @@ virQEMUCapsSetCPUModelInfo(virQEMUCapsPtr qemuCaps,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
|
virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccelPtr caps,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
virDomainVirtType virtType)
|
const char *typeStr)
|
||||||
{
|
{
|
||||||
char *str = NULL;
|
char *str = NULL;
|
||||||
xmlNodePtr hostCPUNode;
|
xmlNodePtr hostCPUNode;
|
||||||
xmlNodePtr *nodes = NULL;
|
xmlNodePtr *nodes = NULL;
|
||||||
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
VIR_XPATH_NODE_AUTORESTORE(ctxt);
|
||||||
qemuMonitorCPUModelInfoPtr hostCPU = NULL;
|
qemuMonitorCPUModelInfoPtr hostCPU = NULL;
|
||||||
|
g_autofree char *xpath = g_strdup_printf("./hostCPU[@type='%s']", typeStr);
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
size_t i;
|
size_t i;
|
||||||
int n;
|
int n;
|
||||||
int val;
|
int val;
|
||||||
|
|
||||||
if (virtType == VIR_DOMAIN_VIRT_KVM)
|
if (!(hostCPUNode = virXPathNode(xpath, ctxt))) {
|
||||||
hostCPUNode = virXPathNode("./hostCPU[@type='kvm']", ctxt);
|
|
||||||
else
|
|
||||||
hostCPUNode = virXPathNode("./hostCPU[@type='tcg']", ctxt);
|
|
||||||
|
|
||||||
if (!hostCPUNode) {
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -3460,8 +3456,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virQEMUCapsSetCPUModelInfo(qemuCaps, virtType, hostCPU);
|
caps->hostCPU.info = g_steal_pointer(&hostCPU);
|
||||||
hostCPU = NULL;
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
@ -3473,22 +3468,18 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCaps,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
|
virQEMUCapsLoadCPUModels(virQEMUCapsAccelPtr caps,
|
||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
virDomainVirtType type)
|
const char *typeStr)
|
||||||
{
|
{
|
||||||
g_autoptr(qemuMonitorCPUDefs) defs = NULL;
|
g_autoptr(qemuMonitorCPUDefs) defs = NULL;
|
||||||
g_autofree xmlNodePtr * nodes = NULL;
|
g_autofree xmlNodePtr * nodes = NULL;
|
||||||
|
g_autofree char *xpath = g_strdup_printf("./cpu[@type='%s']", typeStr);
|
||||||
size_t i;
|
size_t i;
|
||||||
int n;
|
int n;
|
||||||
xmlNodePtr node;
|
xmlNodePtr node;
|
||||||
|
|
||||||
if (type == VIR_DOMAIN_VIRT_KVM)
|
if ((n = virXPathNodeSet(xpath, ctxt, &nodes)) < 0) {
|
||||||
n = virXPathNodeSet("./cpu[@type='kvm']", ctxt, &nodes);
|
|
||||||
else
|
|
||||||
n = virXPathNodeSet("./cpu[@type='tcg']", ctxt, &nodes);
|
|
||||||
|
|
||||||
if (n < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("failed to parse qemu capabilities cpus"));
|
_("failed to parse qemu capabilities cpus"));
|
||||||
return -1;
|
return -1;
|
||||||
@ -3552,11 +3543,7 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == VIR_DOMAIN_VIRT_KVM)
|
caps->cpuModels = g_steal_pointer(&defs);
|
||||||
qemuCaps->kvm.cpuModels = g_steal_pointer(&defs);
|
|
||||||
else
|
|
||||||
qemuCaps->tcg.cpuModels = g_steal_pointer(&defs);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3566,10 +3553,13 @@ virQEMUCapsLoadAccel(virQEMUCapsPtr qemuCaps,
|
|||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
virDomainVirtType type)
|
virDomainVirtType type)
|
||||||
{
|
{
|
||||||
if (virQEMUCapsLoadHostCPUModelInfo(qemuCaps, ctxt, type) < 0)
|
virQEMUCapsAccelPtr caps = virQEMUCapsGetAccel(qemuCaps, type);
|
||||||
|
const char *typeStr = type == VIR_DOMAIN_VIRT_KVM ? "kvm" : "tcg";
|
||||||
|
|
||||||
|
if (virQEMUCapsLoadHostCPUModelInfo(caps, ctxt, typeStr) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virQEMUCapsLoadCPUModels(qemuCaps, ctxt, type) < 0)
|
if (virQEMUCapsLoadCPUModels(caps, ctxt, typeStr) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user