On a Monday in 2020, Tim Wiederhake wrote:
Signed-off-by: Tim Wiederhake <twiederh(a)redhat.com>
---
include/libvirt/libvirt-host.h | 1 +
src/bhyve/bhyve_driver.c | 7 +++++--
src/libxl/libxl_driver.c | 7 +++++--
src/qemu/qemu_driver.c | 18 +++++++++++++-----
tools/virsh-host.c | 14 ++++++++++++++
5 files changed, 38 insertions(+), 9 deletions(-)
diff --git a/include/libvirt/libvirt-host.h b/include/libvirt/libvirt-host.h
index 6972834175..9e7840b9c2 100644
--- a/include/libvirt/libvirt-host.h
+++ b/include/libvirt/libvirt-host.h
@@ -754,6 +754,7 @@ typedef enum {
typedef enum {
VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE = (1 << 0), /* treat incompatible
CPUs as failure */
+ VIR_CONNECT_COMPARE_CPU_VALIDATE_XML = (1 << 1), /* validate xml files */
It does not strictly have to be a file.
We use:
Validate the XML document against schema
elsewhere
Jano
} virConnectCompareCPUFlags;
int virConnectCompareCPU(virConnectPtr conn,
diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index fc57ccd504..7dce3f8648 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1442,14 +1442,17 @@ bhyveConnectCompareCPU(virConnectPtr conn,
int ret = VIR_CPU_COMPARE_ERROR;
virCapsPtr caps = NULL;
bool failIncompatible;
+ bool validateXML;
- virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
+ virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE |
+ VIR_CONNECT_COMPARE_CPU_VALIDATE_XML,
VIR_CPU_COMPARE_ERROR);
if (virConnectCompareCPUEnsureACL(conn) < 0)
goto cleanup;
failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
+ validateXML = !!(flags & VIR_CONNECT_COMPARE_CPU_VALIDATE_XML);
if (!(caps = bhyveDriverGetCapabilities(driver)))
goto cleanup;
@@ -1465,7 +1468,7 @@ bhyveConnectCompareCPU(virConnectPtr conn,
}
} else {
ret = virCPUCompareXML(caps->host.arch, caps->host.cpu,
- xmlDesc, failIncompatible, false);
+ xmlDesc, failIncompatible, validateXML);
}
cleanup:
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 72864c2dc9..6d1f2edd54 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -6529,19 +6529,22 @@ libxlConnectCompareCPU(virConnectPtr conn,
libxlDriverConfigPtr cfg;
int ret = VIR_CPU_COMPARE_ERROR;
bool failIncompatible;
+ bool validateXML;
- virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
+ virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE |
+ VIR_CONNECT_COMPARE_CPU_VALIDATE_XML,
VIR_CPU_COMPARE_ERROR);
if (virConnectCompareCPUEnsureACL(conn) < 0)
return ret;
failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
+ validateXML = !!(flags & VIR_CONNECT_COMPARE_CPU_VALIDATE_XML);
cfg = libxlDriverConfigGet(driver);
ret = virCPUCompareXML(cfg->caps->host.arch, cfg->caps->host.cpu,
- xmlDesc, failIncompatible, false);
+ xmlDesc, failIncompatible, validateXML);
virObjectUnref(cfg);
return ret;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a7961ad3f0..a0c0a4c777 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -12227,20 +12227,23 @@ qemuConnectCompareCPU(virConnectPtr conn,
virQEMUDriverPtr driver = conn->privateData;
g_autoptr(virCPUDef) cpu = NULL;
bool failIncompatible;
+ bool validateXML;
- virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
+ virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE |
+ VIR_CONNECT_COMPARE_CPU_VALIDATE_XML,
VIR_CPU_COMPARE_ERROR);
if (virConnectCompareCPUEnsureACL(conn) < 0)
return VIR_CPU_COMPARE_ERROR;
failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
+ validateXML = !!(flags & VIR_CONNECT_COMPARE_CPU_VALIDATE_XML);
if (!(cpu = virQEMUDriverGetHostCPU(driver)))
return VIR_CPU_COMPARE_ERROR;
return virCPUCompareXML(driver->hostarch, cpu,
- xmlDesc, failIncompatible, false);
+ xmlDesc, failIncompatible, validateXML);
}
@@ -12295,18 +12298,21 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn,
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
g_autoptr(virQEMUCaps) qemuCaps = NULL;
bool failIncompatible;
+ bool validateXML;
virCPUDefPtr hvCPU;
virCPUDefPtr cpu = NULL;
virArch arch;
virDomainVirtType virttype;
- virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
+ virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE |
+ VIR_CONNECT_COMPARE_CPU_VALIDATE_XML,
VIR_CPU_COMPARE_ERROR);
if (virConnectCompareHypervisorCPUEnsureACL(conn) < 0)
goto cleanup;
failIncompatible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
+ validateXML = !!(flags & VIR_CONNECT_COMPARE_CPU_VALIDATE_XML);
qemuCaps = virQEMUCapsCacheLookupDefault(driver->qemuCapsCache,
emulator,
@@ -12330,10 +12336,12 @@ qemuConnectCompareHypervisorCPU(virConnectPtr conn,
}
if (ARCH_IS_X86(arch)) {
- ret = virCPUCompareXML(arch, hvCPU, xmlCPU, failIncompatible, false);
+ ret = virCPUCompareXML(arch, hvCPU, xmlCPU, failIncompatible,
+ validateXML);
} else if (ARCH_IS_S390(arch) &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_COMPARISON)) {
- if (virCPUDefParseXMLString(xmlCPU, VIR_CPU_TYPE_AUTO, &cpu, false) < 0)
+ if (virCPUDefParseXMLString(xmlCPU, VIR_CPU_TYPE_AUTO, &cpu,
+ validateXML) < 0)
goto cleanup;
ret = qemuConnectCPUModelComparison(qemuCaps, cfg->libDir,
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 722c47958b..80edfae16c 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -1214,6 +1214,10 @@ static const vshCmdOptDef opts_cpu_compare[] = {
.type = VSH_OT_BOOL,
.help = N_("report error if CPUs are incompatible")
},
+ {.name = "validate",
+ .type = VSH_OT_BOOL,
+ .help = N_("enable XML file validation")
+ },
{.name = NULL}
};
@@ -1230,6 +1234,9 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "error"))
flags |= VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE;
+ if (vshCommandOptBool(cmd, "validate"))
+ flags |= VIR_CONNECT_COMPARE_CPU_VALIDATE_XML;
+
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
@@ -1636,6 +1643,10 @@ static const vshCmdOptDef opts_hypervisor_cpu_compare[] = {
.type = VSH_OT_BOOL,
.help = N_("report error if CPUs are incompatible")
},
+ {.name = "validate",
+ .type = VSH_OT_BOOL,
+ .help = N_("enable XML file validation")
+ },
{.name = NULL}
};
@@ -1657,6 +1668,9 @@ cmdHypervisorCPUCompare(vshControl *ctl,
if (vshCommandOptBool(cmd, "error"))
flags |= VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE;
+ if (vshCommandOptBool(cmd, "validate"))
+ flags |= VIR_CONNECT_COMPARE_CPU_VALIDATE_XML;
+
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0 ||
vshCommandOptStringReq(ctl, cmd, "virttype", &virttype) < 0 ||
vshCommandOptStringReq(ctl, cmd, "emulator", &emulator) < 0 ||
--
2.26.2