]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Change return type of qemuMonitorGetGuestCPU()
authorPeter Krempa <pkrempa@redhat.com>
Mon, 11 Nov 2013 13:47:08 +0000 (14:47 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 12 Nov 2013 18:35:51 +0000 (19:35 +0100)
To allow returning more granular errors, change the error type to an
integer.

src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_monitor_json.h
src/qemu/qemu_process.c
tests/qemumonitorjsontest.c

index 14e4e2d2fd28db8afc87037769b82010990fe949..30315b38a0d7864267e3cad4df711ad63bc57ba4 100644 (file)
@@ -3933,28 +3933,33 @@ qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd)
  * qemuMonitorJSONGetGuestCPU:
  * @mon: Pointer to the monitor
  * @arch: arch of the guest
+ * @data: returns the cpu data
  *
  * Retrieve the definition of the guest CPU from a running qemu instance.
  *
- * Returns the cpu definition object. On error returns NULL.
+ * Returns 0 on success, -2 if the operation is not supported by the guest,
+ * -1 on other errors.
  */
-virCPUDataPtr
+int
 qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
-                       virArch arch)
+                       virArch arch,
+                       virCPUDataPtr *data)
 {
-    VIR_DEBUG("mon=%p, arch='%s'", mon, virArchToString(arch));
+    VIR_DEBUG("mon=%p, arch='%s' data='%p'", mon, virArchToString(arch), data);
 
     if (!mon) {
         virReportError(VIR_ERR_INVALID_ARG, "%s",
                        _("monitor must not be NULL"));
-        return NULL;
+        return -1;
     }
 
     if (!mon->json) {
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
                        _("JSON monitor is required"));
-        return NULL;
+        return -1;
     }
 
-    return qemuMonitorJSONGetGuestCPU(mon, arch);
+    *data = NULL;
+
+    return qemuMonitorJSONGetGuestCPU(mon, arch, data);
 }
index ecc6d7b38fd8fc2ce12673483bb1741da85974d5..f893b1f224b0bd3365ec25fca228f535f4f3c85b 100644 (file)
@@ -764,8 +764,9 @@ int qemuMonitorGetDeviceAliases(qemuMonitorPtr mon,
 
 int qemuMonitorSetDomainLog(qemuMonitorPtr mon, int logfd);
 
-virCPUDataPtr qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
-                                     virArch arch);
+int qemuMonitorGetGuestCPU(qemuMonitorPtr mon,
+                           virArch arch,
+                           virCPUDataPtr *data);
 
 /**
  * When running two dd process and using <> redirection, we need a
index 593c90fcf2190c37d6ca5ca7394a016263d76593..87990e2f39642d994b79dff7a1c814233a0627f8 100644 (file)
@@ -5503,9 +5503,10 @@ qemuMonitorJSONParseCPUx86FeatureWord(virJSONValuePtr data,
 }
 
 
-static virCPUDataPtr
+static int
 qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon,
-                             const char *property)
+                             const char *property,
+                             virCPUDataPtr *cpudata)
 {
     virJSONValuePtr cmd;
     virJSONValuePtr reply = NULL;
@@ -5513,14 +5514,14 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon,
     virCPUx86Data *x86Data = NULL;
     virCPUx86CPUID cpuid;
     size_t i;
-    virCPUDataPtr ret = NULL;
     int n;
+    int ret = -1;
 
     if (!(cmd = qemuMonitorJSONMakeCommand("qom-get",
                                            "s:path", QOM_CPU_PATH,
                                            "s:property", property,
                                            NULL)))
-        return NULL;
+        return -1;
 
     if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
         goto cleanup;
@@ -5551,9 +5552,11 @@ qemuMonitorJSONGetCPUx86Data(qemuMonitorPtr mon,
             goto cleanup;
     }
 
-    if (!(ret = virCPUx86MakeData(VIR_ARCH_X86_64, &x86Data)))
+    if (!(*cpudata = virCPUx86MakeData(VIR_ARCH_X86_64, &x86Data)))
         goto cleanup;
 
+    ret = 0;
+
 cleanup:
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
@@ -5566,24 +5569,27 @@ cleanup:
  * qemuMonitorJSONGetGuestCPU:
  * @mon: Pointer to the monitor
  * @arch: arch of the guest
+ * @data: returns the cpu data of the guest
  *
  * Retrieve the definition of the guest CPU from a running qemu instance.
  *
- * Returns the cpu definition object. On error returns NULL.
+ * Returns 0 on success, -2 if guest doesn't support this feature,
+ * -1 on other errors.
  */
-virCPUDataPtr
+int
 qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon,
-                           virArch arch)
+                           virArch arch,
+                           virCPUDataPtr *data)
 {
     switch (arch) {
     case VIR_ARCH_X86_64:
     case VIR_ARCH_I686:
-        return qemuMonitorJSONGetCPUx86Data(mon, "feature-words");
+        return qemuMonitorJSONGetCPUx86Data(mon, "feature-words", data);
 
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("CPU definition retrieval isn't supported for '%s'"),
                        virArchToString(arch));
-        return NULL;
+        return -1;
     }
 }
index 9e0a0c97409197574a3dda3bd7754a4f0c6b913c..a93c51eeb0135b47db4dffc1a4ccb1b3b6792f1f 100644 (file)
@@ -427,5 +427,7 @@ int qemuMonitorJSONDetachCharDev(qemuMonitorPtr mon,
 int qemuMonitorJSONGetDeviceAliases(qemuMonitorPtr mon,
                                     char ***aliases);
 
-virCPUDataPtr qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon, virArch arch);
+int qemuMonitorJSONGetGuestCPU(qemuMonitorPtr mon,
+                               virArch arch,
+                               virCPUDataPtr *data);
 #endif /* QEMU_MONITOR_JSON_H */
index fcceeddf18ade480197864cb0b6ff5860f96604b..e34f542e3fa11bb5db498c67e8107eeb4329c635 100644 (file)
@@ -3472,17 +3472,22 @@ qemuProcessVerifyGuestCPU(virQEMUDriverPtr driver, virDomainObjPtr vm)
     virArch arch = def->os.arch;
     virCPUDataPtr guestcpu = NULL;
     qemuDomainObjPrivatePtr priv = vm->privateData;
+    int rc;
     bool ret = false;
 
     switch (arch) {
     case VIR_ARCH_I686:
     case VIR_ARCH_X86_64:
         qemuDomainObjEnterMonitor(driver, vm);
-        guestcpu = qemuMonitorGetGuestCPU(priv->mon, arch);
+        rc = qemuMonitorGetGuestCPU(priv->mon, arch, &guestcpu);
         qemuDomainObjExitMonitor(driver, vm);
 
-        if (!(guestcpu))
+        if (rc < 0) {
+            if (rc == -2)
+                break;
+
             goto cleanup;
+        }
 
         if (def->features[VIR_DOMAIN_FEATURE_PVSPINLOCK] == VIR_DOMAIN_FEATURE_STATE_ON) {
             if (!cpuHasFeature(guestcpu, VIR_CPU_x86_KVM_PV_UNHALT)) {
index a6bd3467a116e833a842e667623a925e3da5a603..5636d951d2719be6f4dbffdfcff64125ef9e4f17 100644 (file)
@@ -1997,8 +1997,9 @@ testQemuMonitorJSONGetCPUData(const void *opaque)
     if (qemuMonitorTestAddItem(test, "qom-get", jsonStr) < 0)
         goto cleanup;
 
-    if (!(cpuData = qemuMonitorJSONGetGuestCPU(qemuMonitorTestGetMonitor(test),
-                                               VIR_ARCH_X86_64)))
+    if (qemuMonitorJSONGetGuestCPU(qemuMonitorTestGetMonitor(test),
+                                   VIR_ARCH_X86_64,
+                                   &cpuData) < 0)
         goto cleanup;
 
     if (!(actual = cpuDataFormat(cpuData)))