[libvirt] [PATCH 02/23] conf: Add usability blockers to virDomainCapsCPUModel

Jiri Denemark posted 23 patches 7 years, 7 months ago
There is a newer version of this series
[libvirt] [PATCH 02/23] conf: Add usability blockers to virDomainCapsCPUModel
Posted by Jiri Denemark 7 years, 7 months ago
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@redhat.com>
---
 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 085910dd4d..b20dd6ec32 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -795,7 +795,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));
 
@@ -853,7 +853,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));
 
@@ -2524,7 +2524,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;
     }
 
@@ -3005,7 +3005,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;
     }
 
@@ -3768,7 +3769,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@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 02/23] conf: Add usability blockers to virDomainCapsCPUModel
Posted by John Ferlan 7 years, 7 months ago

On 10/04/2017 10:58 AM, Jiri Denemark wrote:
> 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@redhat.com>
> ---
>  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);
> +

So @name is required and @blockers can be NULL/optional... Hopefully no
one ever gets confused.

>      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)

Obviously based on patch 1 comment, this would change slightly...

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

[...]

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 02/23] conf: Add usability blockers to virDomainCapsCPUModel
Posted by Jiri Denemark 7 years, 7 months ago
On Thu, Oct 12, 2017 at 07:23:25 -0400, John Ferlan wrote:
> 
> 
> On 10/04/2017 10:58 AM, Jiri Denemark wrote:
> > 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@redhat.com>
> > ---
> >  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);
> > +
> 
> So @name is required and @blockers can be NULL/optional... Hopefully no
> one ever gets confused.

I don't think there's any room for confusion since @blockers only make
sense if the CPU model @name is unusable. They are naturally optional.

Jirka

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