]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
cpu: Special case models == NULL in cpuGetModels
authorJiri Denemark <jdenemar@redhat.com>
Tue, 14 Jun 2016 09:12:49 +0000 (11:12 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Thu, 22 Sep 2016 13:40:08 +0000 (15:40 +0200)
Some CPU drivers (such as arm) do not provide list of CPUs libvirt
supports and just pass any CPU model from domain XML directly to QEMU.
Such driver need to return models == NULL and success from cpuGetModels.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
src/cpu/cpu.c
src/libvirt-host.c
tools/virsh-host.c

index 19afeab7b9b922211f2903aecc08f45c8c7e131b..d2b7ce3da9abcd809173910c48b47024930f73b6 100644 (file)
@@ -750,9 +750,13 @@ cpuModelIsAllowed(const char *model,
  * @arch: CPU architecture
  * @models: where to store the NULL-terminated list of supported models
  *
- * Fetches all CPU models supported by libvirt on @archName.
+ * Fetches all CPU models supported by libvirt on @archName. If there are
+ * no restrictions on CPU models on @archName (i.e., the CPU model is just
+ * passed directly to a hypervisor), this function returns 0 and sets
+ * @models to NULL.
  *
- * Returns number of supported CPU models or -1 on error.
+ * Returns number of supported CPU models, 0 if any CPU model is supported,
+ * or -1 on error.
  */
 int
 cpuGetModels(virArch arch, char ***models)
@@ -770,10 +774,9 @@ cpuGetModels(virArch arch, char ***models)
     }
 
     if (!driver->getModels) {
-        virReportError(VIR_ERR_NO_SUPPORT,
-                       _("CPU driver for %s has no CPU model support"),
-                       virArchToString(arch));
-        return -1;
+        if (models)
+            *models = NULL;
+        return 0;
     }
 
     return driver->getModels(models);
index 2a3de03115222f5c0f9b0d4e7d5d86f381ad544d..335798abf749cb854cbc12b67c83f0e58d2fe4a5 100644 (file)
@@ -1005,7 +1005,8 @@ virConnectCompareCPU(virConnectPtr conn,
  *
  * Get the list of supported CPU models for a specific architecture.
  *
- * Returns -1 on error, number of elements in @models on success.
+ * Returns -1 on error, number of elements in @models on success (0 means
+ * libvirt accepts any CPU model).
  */
 int
 virConnectGetCPUModelNames(virConnectPtr conn, const char *arch, char ***models,
index 2337ce8e6e7b1c166e87abb2e864d76c81ab06da..2fd368662a75392ac9ff432a7c53658b8fcaa06a 100644 (file)
@@ -1149,9 +1149,13 @@ cmdCPUModelNames(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    for (i = 0; i < nmodels; i++) {
-        vshPrint(ctl, "%s\n", models[i]);
-        VIR_FREE(models[i]);
+    if (nmodels == 0) {
+        vshPrintExtra(ctl, "%s\n", _("all CPU models are accepted"));
+    } else {
+        for (i = 0; i < nmodels; i++) {
+            vshPrint(ctl, "%s\n", models[i]);
+            VIR_FREE(models[i]);
+        }
     }
     VIR_FREE(models);