[libvirt] [PATCH 03/23] qemu: Store CPU usability blockers in caps cache

Jiri Denemark posted 23 patches 8 years, 4 months ago
There is a newer version of this series
[libvirt] [PATCH 03/23] qemu: Store CPU usability blockers in caps cache
Posted by Jiri Denemark 8 years, 4 months ago
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_capabilities.c | 51 ++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 49 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index b20dd6ec32..1ce2aa375f 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3727,6 +3727,10 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
     size_t i;
     int n;
     int ret = -1;
+    xmlNodePtr node;
+    xmlNodePtr *blockerNodes = NULL;
+    char **blockers = NULL;
+    int nblockers;
 
     if (type == VIR_DOMAIN_VIRT_KVM)
         n = virXPathNodeSet("./cpu[@type='kvm']", ctxt, &nodes);
@@ -3769,7 +3773,34 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
             goto cleanup;
         }
 
-        if (virDomainCapsCPUModelsAddSteal(cpus, &str, usable, NULL) < 0)
+        node = ctxt->node;
+        ctxt->node = nodes[i];
+        nblockers = virXPathNodeSet("./blocker", ctxt, &blockerNodes);
+        ctxt->node = node;
+
+        if (nblockers < 0) {
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("failed to parse qemu capabilities cpus"));
+            goto cleanup;
+        }
+
+        if (nblockers > 0) {
+            size_t j;
+
+            if (VIR_ALLOC_N(blockers, nblockers + 1) < 0)
+                goto cleanup;
+
+            for (j = 0; j < nblockers; j++) {
+                if (!(blockers[j] = virXMLPropString(blockerNodes[j], "name"))) {
+                    virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                                   _("missing blocker name in QEMU "
+                                     "capabilities cache"));
+                    goto cleanup;
+                }
+            }
+        }
+
+        if (virDomainCapsCPUModelsAddSteal(cpus, &str, usable, &blockers) < 0)
             goto cleanup;
     }
 
@@ -3778,6 +3809,8 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
  cleanup:
     VIR_FREE(nodes);
     VIR_FREE(str);
+    VIR_FREE(blockerNodes);
+    virStringListFree(blockers);
     return ret;
 }
 
@@ -4135,7 +4168,21 @@ virQEMUCapsFormatCPUModels(virQEMUCapsPtr qemuCaps,
             virBufferAsprintf(buf, " usable='%s'",
                               virDomainCapsCPUUsableTypeToString(cpu->usable));
         }
-        virBufferAddLit(buf, "/>\n");
+
+        if (cpu->blockers) {
+            size_t j;
+
+            virBufferAddLit(buf, ">\n");
+            virBufferAdjustIndent(buf, 2);
+
+            for (j = 0; cpu->blockers[j]; j++)
+                virBufferAsprintf(buf, "<blocker name='%s'/>\n", cpu->blockers[j]);
+
+            virBufferAdjustIndent(buf, -2);
+            virBufferAddLit(buf, "</cpu>\n");
+        } else {
+            virBufferAddLit(buf, "/>\n");
+        }
     }
 }
 
-- 
2.14.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 03/23] qemu: Store CPU usability blockers in caps cache
Posted by John Ferlan 8 years, 3 months ago

On 10/04/2017 10:58 AM, Jiri Denemark wrote:
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/qemu/qemu_capabilities.c | 51 ++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 49 insertions(+), 2 deletions(-)
> 
> diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> index b20dd6ec32..1ce2aa375f 100644
> --- a/src/qemu/qemu_capabilities.c
> +++ b/src/qemu/qemu_capabilities.c
> @@ -3727,6 +3727,10 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
>      size_t i;
>      int n;
>      int ret = -1;
> +    xmlNodePtr node;
> +    xmlNodePtr *blockerNodes = NULL;
> +    char **blockers = NULL;
> +    int nblockers;
>  
>      if (type == VIR_DOMAIN_VIRT_KVM)
>          n = virXPathNodeSet("./cpu[@type='kvm']", ctxt, &nodes);
> @@ -3769,7 +3773,34 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
>              goto cleanup;
>          }
>  
> -        if (virDomainCapsCPUModelsAddSteal(cpus, &str, usable, NULL) < 0)
> +        node = ctxt->node;
> +        ctxt->node = nodes[i];
> +        nblockers = virXPathNodeSet("./blocker", ctxt, &blockerNodes);
> +        ctxt->node = node;
> +
> +        if (nblockers < 0) {
> +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                           _("failed to parse qemu capabilities cpus"));

s/qemu/QEMU
s/cpus/blockers/

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 03/23] qemu: Store CPU usability blockers in caps cache
Posted by Jiri Denemark 8 years, 3 months ago
On Thu, Oct 12, 2017 at 07:23:41 -0400, John Ferlan wrote:
> 
> 
> On 10/04/2017 10:58 AM, Jiri Denemark wrote:
> > Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> > ---
> >  src/qemu/qemu_capabilities.c | 51 ++++++++++++++++++++++++++++++++++++++++++--
> >  1 file changed, 49 insertions(+), 2 deletions(-)
> > 
> > diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
> > index b20dd6ec32..1ce2aa375f 100644
> > --- a/src/qemu/qemu_capabilities.c
> > +++ b/src/qemu/qemu_capabilities.c
> > @@ -3727,6 +3727,10 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
> >      size_t i;
> >      int n;
> >      int ret = -1;
> > +    xmlNodePtr node;
> > +    xmlNodePtr *blockerNodes = NULL;
> > +    char **blockers = NULL;
> > +    int nblockers;
> >  
> >      if (type == VIR_DOMAIN_VIRT_KVM)
> >          n = virXPathNodeSet("./cpu[@type='kvm']", ctxt, &nodes);
> > @@ -3769,7 +3773,34 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
> >              goto cleanup;
> >          }
> >  
> > -        if (virDomainCapsCPUModelsAddSteal(cpus, &str, usable, NULL) < 0)
> > +        node = ctxt->node;
> > +        ctxt->node = nodes[i];
> > +        nblockers = virXPathNodeSet("./blocker", ctxt, &blockerNodes);
> > +        ctxt->node = node;
> > +
> > +        if (nblockers < 0) {
> > +            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
> > +                           _("failed to parse qemu capabilities cpus"));
> 
> s/qemu/QEMU
> s/cpus/blockers/

Oops, too much copypasta. I changed it to
"failed to parse CPU blockers in QEMU capabilities"

Jirka

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