#endif
} virCPUCompareResult;
+typedef enum {
+ VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE = (1 << 0), /* treat incompatible
+ CPUs as failure */
+} virConnectCompareCPUFlags;
+
int virConnectCompareCPU(virConnectPtr conn,
const char *xmlDesc,
unsigned int flags);
bhyveConnPtr driver = conn->privateData;
int ret = VIR_CPU_COMPARE_ERROR;
virCapsPtr caps = NULL;
+ bool failIncompatible;
- virCheckFlags(0, VIR_CPU_COMPARE_ERROR);
+ virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
+ VIR_CPU_COMPARE_ERROR);
if (virConnectCompareCPUEnsureACL(conn) < 0)
goto cleanup;
+ failIncomaptible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
+
if (!(caps = bhyveDriverGetCapabilities(driver)))
goto cleanup;
if (!caps->host.cpu ||
!caps->host.cpu->model) {
- VIR_WARN("cannot get host CPU capabilities");
- ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+ if (failIncomaptible) {
+ virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s",
+ _("cannot get host CPU capabilities"));
+ } else {
+ VIR_WARN("cannot get host CPU capabilities");
+ ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+ }
} else {
- ret = cpuCompareXML(caps->host.cpu, xmlDesc, false);
+ ret = cpuCompareXML(caps->host.cpu, xmlDesc, failIncomaptible);
}
cleanup:
* virConnectCompareCPU:
* @conn: virConnect connection
* @xmlDesc: XML describing the CPU to compare with host CPU
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @flags: bitwise-OR of virConnectCompareCPUFlags
*
* Compares the given CPU description with the host CPU
*
- * Returns comparison result according to enum virCPUCompareResult
+ * Returns comparison result according to enum virCPUCompareResult. If
+ * VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE is used and @xmlDesc CPU is
+ * incompatible with host CPU, this function will return VIR_CPU_COMPARE_ERROR
+ * (instead of VIR_CPU_COMPARE_INCOMPATIBLE) and the error will use the
+ * VIR_ERR_CPU_INCOMPATIBLE code with a message providing more details about
+ * the incompatibility.
*/
int
virConnectCompareCPU(virConnectPtr conn,
virQEMUDriverPtr driver = conn->privateData;
int ret = VIR_CPU_COMPARE_ERROR;
virCapsPtr caps = NULL;
+ bool failIncomaptible;
- virCheckFlags(0, VIR_CPU_COMPARE_ERROR);
+ virCheckFlags(VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE,
+ VIR_CPU_COMPARE_ERROR);
if (virConnectCompareCPUEnsureACL(conn) < 0)
goto cleanup;
+ failIncomaptible = !!(flags & VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE);
+
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
if (!caps->host.cpu ||
!caps->host.cpu->model) {
- VIR_WARN("cannot get host CPU capabilities");
- ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+ if (failIncomaptible) {
+ virReportError(VIR_ERR_CPU_INCOMPATIBLE, "%s",
+ _("cannot get host CPU capabilities"));
+ } else {
+ VIR_WARN("cannot get host CPU capabilities");
+ ret = VIR_CPU_COMPARE_INCOMPATIBLE;
+ }
} else {
- ret = cpuCompareXML(caps->host.cpu, xmlDesc, false);
+ ret = cpuCompareXML(caps->host.cpu, xmlDesc, failIncomaptible);
}
cleanup:
.flags = VSH_OFLAG_REQ,
.help = N_("file containing an XML CPU description")
},
+ {.name = "error",
+ .type = VSH_OT_BOOL,
+ .help = N_("report error if CPUs are incompatible")
+ },
{.name = NULL}
};
char *buffer;
int result;
char *snippet = NULL;
-
+ unsigned int flags = 0;
xmlDocPtr xml = NULL;
xmlXPathContextPtr ctxt = NULL;
xmlNodePtr node;
+ if (vshCommandOptBool(cmd, "error"))
+ flags |= VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE;
+
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
goto cleanup;
}
- result = virConnectCompareCPU(ctl->conn, snippet, 0);
+ result = virConnectCompareCPU(ctl->conn, snippet, flags);
switch (result) {
case VIR_CPU_COMPARE_INCOMPATIBLE:
up the CPU, without this option features that are part of the CPU model
will not be listed in the XML description.
-=item B<cpu-compare> I<FILE>
+=item B<cpu-compare> I<FILE> [I<--error>]
Compare CPU definition from XML <file> with host CPU. The XML <file> may
contain either host or guest CPU definition. The host CPU definition is the
<cpu> element and its contents as printed by B<capabilities> command. The
guest CPU definition is the <cpu> element and its contents from domain XML
definition. For more information on guest CPU definition see:
-L<http://libvirt.org/formatdomain.html#elementsCPU>
+L<http://libvirt.org/formatdomain.html#elementsCPU>. If I<--error> is
+specified, the command will return an error when the given CPU is
+incompatible with host CPU and a message providing more details about the
+incompatibility will be printed out.
=item B<echo> [I<--shell>] [I<--xml>] [I<arg>...]