[PATCH v2 02/22] conf: Add usability blockers to virDomainCapsCPUModel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When a hypervisor marks a CPU model as unusable on the current host, it
may also give us a list of features which prevent the model from being
usable. Storing this list in virDomainCapsCPUModel will help the CPU
driver with creating a host-model CPU configuration.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
Reviewed-by: John Ferlan <jferlan@xxxxxxxxxx>
---

Notes:
    Version 2:
    - no change

 src/conf/domain_capabilities.c | 30 ++++++++++++++++++++++--------
 src/conf/domain_capabilities.h |  7 +++++--
 src/qemu/qemu_capabilities.c   | 11 ++++++-----
 tests/domaincapstest.c         |  6 +++---
 4 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index f62038b96c..be34576204 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -163,7 +163,8 @@ virDomainCapsCPUModelsCopy(virDomainCapsCPUModelsPtr old)
     for (i = 0; i < old->nmodels; i++) {
         if (virDomainCapsCPUModelsAdd(cpuModels,
                                       old->models[i].name, -1,
-                                      old->models[i].usable) < 0)
+                                      old->models[i].usable,
+                                      old->models[i].blockers) < 0)
             goto error;
     }
 
@@ -195,7 +196,8 @@ virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr old,
 
         if (virDomainCapsCPUModelsAdd(cpuModels,
                                       old->models[i].name, -1,
-                                      old->models[i].usable) < 0)
+                                      old->models[i].usable,
+                                      old->models[i].blockers) < 0)
             goto error;
     }
 
@@ -210,7 +212,8 @@ virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr old,
 int
 virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
                                char **name,
-                               virDomainCapsCPUUsable usable)
+                               virDomainCapsCPUUsable usable,
+                               char ***blockers)
 {
     if (VIR_RESIZE_N(cpuModels->models, cpuModels->nmodels_max,
                      cpuModels->nmodels, 1) < 0)
@@ -218,6 +221,10 @@ virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
 
     cpuModels->models[cpuModels->nmodels].usable = usable;
     VIR_STEAL_PTR(cpuModels->models[cpuModels->nmodels].name, *name);
+
+    if (blockers)
+        VIR_STEAL_PTR(cpuModels->models[cpuModels->nmodels].blockers, *blockers);
+
     cpuModels->nmodels++;
     return 0;
 }
@@ -227,20 +234,27 @@ int
 virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
                           const char *name,
                           ssize_t nameLen,
-                          virDomainCapsCPUUsable usable)
+                          virDomainCapsCPUUsable usable,
+                          char **blockers)
 {
-    char *copy = NULL;
+    char *nameCopy = NULL;
+    char **blockersCopy = NULL;
 
-    if (VIR_STRNDUP(copy, name, nameLen) < 0)
+    if (VIR_STRNDUP(nameCopy, name, nameLen) < 0)
         goto error;
 
-    if (virDomainCapsCPUModelsAddSteal(cpuModels, &copy, usable) < 0)
+    if (virStringListCopy(&blockersCopy, (const char **)blockers) < 0)
+        goto error;
+
+    if (virDomainCapsCPUModelsAddSteal(cpuModels, &nameCopy,
+                                       usable, &blockersCopy) < 0)
         goto error;
 
     return 0;
 
  error:
-    VIR_FREE(copy);
+    VIR_FREE(nameCopy);
+    virStringListFree(blockersCopy);
     return -1;
 }
 
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index 82183c4524..8c71dec21e 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -116,6 +116,7 @@ typedef virDomainCapsCPUModel *virDomainCapsCPUModelPtr;
 struct _virDomainCapsCPUModel {
     char *name;
     virDomainCapsCPUUsable usable;
+    char **blockers; /* NULL-terminated list of usability blockers */
 };
 
 typedef struct _virDomainCapsCPUModels virDomainCapsCPUModels;
@@ -171,11 +172,13 @@ virDomainCapsCPUModelsPtr virDomainCapsCPUModelsFilter(virDomainCapsCPUModelsPtr
                                                        const char **blacklist);
 int virDomainCapsCPUModelsAddSteal(virDomainCapsCPUModelsPtr cpuModels,
                                    char **name,
-                                   virDomainCapsCPUUsable usable);
+                                   virDomainCapsCPUUsable usable,
+                                   char ***blockers);
 int virDomainCapsCPUModelsAdd(virDomainCapsCPUModelsPtr cpuModels,
                               const char *name,
                               ssize_t nameLen,
-                              virDomainCapsCPUUsable usable);
+                              virDomainCapsCPUUsable usable,
+                              char **blockers);
 
 # define VIR_DOMAIN_CAPS_ENUM_SET(capsEnum, ...)            \
     do {                                                    \
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index f9028157f1..7f4d019e9b 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -796,7 +796,7 @@ virQEMUCapsParseX86Models(const char *output,
         }
 
         if (virDomainCapsCPUModelsAdd(cpus, p, len,
-                                      VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
+                                      VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL) < 0)
             goto error;
     } while ((p = next));
 
@@ -854,7 +854,7 @@ virQEMUCapsParsePPCModels(const char *output,
             continue;
 
         if (virDomainCapsCPUModelsAdd(cpus, p, t - p - 1,
-                                      VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0)
+                                      VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL) < 0)
             goto error;
     } while ((p = next));
 
@@ -2526,7 +2526,7 @@ virQEMUCapsAddCPUDefinitions(virQEMUCapsPtr qemuCaps,
     }
 
     for (i = 0; i < count; i++) {
-        if (virDomainCapsCPUModelsAdd(cpus, name[i], -1, usable) < 0)
+        if (virDomainCapsCPUModelsAdd(cpus, name[i], -1, usable, NULL) < 0)
             return -1;
     }
 
@@ -3007,7 +3007,8 @@ virQEMUCapsProbeQMPCPUDefinitions(virQEMUCapsPtr qemuCaps,
         else if (cpus[i]->usable == VIR_TRISTATE_BOOL_NO)
             usable = VIR_DOMCAPS_CPU_USABLE_NO;
 
-        if (virDomainCapsCPUModelsAddSteal(models, &cpus[i]->name, usable) < 0)
+        if (virDomainCapsCPUModelsAddSteal(models, &cpus[i]->name, usable,
+                                           NULL) < 0)
             goto cleanup;
     }
 
@@ -3770,7 +3771,7 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
             goto cleanup;
         }
 
-        if (virDomainCapsCPUModelsAddSteal(cpus, &str, usable) < 0)
+        if (virDomainCapsCPUModelsAddSteal(cpus, &str, usable, NULL) < 0)
             goto cleanup;
     }
 
diff --git a/tests/domaincapstest.c b/tests/domaincapstest.c
index 2719473244..7aeac4507f 100644
--- a/tests/domaincapstest.c
+++ b/tests/domaincapstest.c
@@ -88,11 +88,11 @@ fillAllCaps(virDomainCapsPtr domCaps)
     cpu->hostModel = virCPUDefCopy(&host);
     if (!(cpu->custom = virDomainCapsCPUModelsNew(3)) ||
         virDomainCapsCPUModelsAdd(cpu->custom, "Model1", -1,
-                                  VIR_DOMCAPS_CPU_USABLE_UNKNOWN) < 0 ||
+                                  VIR_DOMCAPS_CPU_USABLE_UNKNOWN, NULL) < 0 ||
         virDomainCapsCPUModelsAdd(cpu->custom, "Model2", -1,
-                                  VIR_DOMCAPS_CPU_USABLE_NO) < 0 ||
+                                  VIR_DOMCAPS_CPU_USABLE_NO, NULL) < 0 ||
         virDomainCapsCPUModelsAdd(cpu->custom, "Model3", -1,
-                                  VIR_DOMCAPS_CPU_USABLE_YES) < 0)
+                                  VIR_DOMCAPS_CPU_USABLE_YES, NULL) < 0)
         return -1;
 
     disk->supported = true;
-- 
2.14.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux