]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
virConnectCompareCPU: Introduce FAIL_INCOMPATIBLE flag
authorJiri Denemark <jdenemar@redhat.com>
Wed, 28 May 2014 13:12:59 +0000 (15:12 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Wed, 25 Jun 2014 22:44:02 +0000 (00:44 +0200)
The new VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE flag for
virConnectCompareCPU can be used to get an error
(VIR_ERR_CPU_INCOMPATIBLE) describing the incompatibility instead of the
usual VIR_CPU_COMPARE_INCOMPATIBLE return code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
include/libvirt/libvirt.h.in
src/bhyve/bhyve_driver.c
src/libvirt.c
src/qemu/qemu_driver.c
tools/virsh-domain.c
tools/virsh.pod

index 3f7a201634098cc1a980bdad2777bd7bad5a5e30..594521eba0e67e503303d28969066e919f69c655 100644 (file)
@@ -4122,6 +4122,11 @@ typedef enum {
 #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);
index 9bece84c2c007aba91fb023f0f5b61dcd815f0b6..d784ed18bd4255195625d2d94db1709cff5dca4b 100644 (file)
@@ -1318,21 +1318,30 @@ bhyveConnectCompareCPU(virConnectPtr conn,
     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:
index a0cdfa21a1b99cfb2a26132148fa19e9c84897c8..566f9847addd810166919375f4cf0ae04dadb05a 100644 (file)
@@ -17245,11 +17245,16 @@ virConnectIsSecure(virConnectPtr conn)
  * 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,
index 3c23fc7cf7763494e9ba378b0a59fef6342dbee5..d8cecffeec0d7d24883bbc1e049dc9f610f3dc3d 100644 (file)
@@ -11514,21 +11514,30 @@ qemuConnectCompareCPU(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:
index 0ae1538a94c0559f5869faaf04ecb6f280f0400b..f55dae4bacc1ea43daed5fcf716bd17b8af9d31d 100644 (file)
@@ -6214,6 +6214,10 @@ static const vshCmdOptDef opts_cpu_compare[] = {
      .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}
 };
 
@@ -6225,11 +6229,14 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
     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;
 
@@ -6253,7 +6260,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
         goto cleanup;
     }
 
-    result = virConnectCompareCPU(ctl->conn, snippet, 0);
+    result = virConnectCompareCPU(ctl->conn, snippet, flags);
 
     switch (result) {
     case VIR_CPU_COMPARE_INCOMPATIBLE:
index e00c80c3fa6121711fe81825d02053243ef36739..b248c9a346e4ebd7dd4568c0bfc1f86c80d0c018 100644 (file)
@@ -535,14 +535,17 @@ resulting XML description will explicitly include all features that make
 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>...]