[libvirt] [PATCH 4/7] qemu: Add qemuProcessUpdateLiveGuestCPU

Jiri Denemark posted 7 patches 8 years, 5 months ago
[libvirt] [PATCH 4/7] qemu: Add qemuProcessUpdateLiveGuestCPU
Posted by Jiri Denemark 8 years, 5 months ago
Separated from qemuProcessUpdateAndVerifyCPU to handle updating of an
active guest CPU definition according to live data from QEMU.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_process.c | 70 +++++++++++++++++++++++++++++--------------------
 1 file changed, 42 insertions(+), 28 deletions(-)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ebd13057b..926c64197 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -4011,17 +4011,53 @@ qemuProcessVerifyCPU(virDomainObjPtr vm,
 
 
 static int
+qemuProcessUpdateLiveGuestCPU(virDomainObjPtr vm,
+                              virCPUDataPtr enabled,
+                              virCPUDataPtr disabled)
+{
+    virDomainDefPtr def = vm->def;
+    qemuDomainObjPrivatePtr priv = vm->privateData;
+    virCPUDefPtr orig = NULL;
+    int rc;
+    int ret = -1;
+
+    if (!enabled ||
+        !def->cpu ||
+        (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
+         !def->cpu->model))
+        return 0;
+
+    if (!(orig = virCPUDefCopy(def->cpu)))
+        goto cleanup;
+
+    if ((rc = virCPUUpdateLive(def->os.arch, def->cpu, enabled, disabled)) < 0) {
+        goto cleanup;
+    } else if (rc == 0) {
+        /* Store the original CPU in priv if QEMU changed it and we didn't
+         * get the original CPU via migration, restore, or snapshot revert.
+         */
+        if (!priv->origCPU && !virCPUDefIsEqual(def->cpu, orig, false))
+            VIR_STEAL_PTR(priv->origCPU, orig);
+
+        def->cpu->check = VIR_CPU_CHECK_FULL;
+    }
+
+    ret = 0;
+
+ cleanup:
+    virCPUDefFree(orig);
+    return ret;
+}
+
+
+static int
 qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               qemuDomainAsyncJob asyncJob)
 {
-    virDomainDefPtr def = vm->def;
     virCPUDataPtr cpu = NULL;
     virCPUDataPtr disabled = NULL;
-    qemuDomainObjPrivatePtr priv = vm->privateData;
-    int rc;
     int ret = -1;
-    virCPUDefPtr orig = NULL;
 
     if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < 0)
         goto cleanup;
@@ -4029,36 +4065,14 @@ qemuProcessUpdateAndVerifyCPU(virQEMUDriverPtr driver,
     if (qemuProcessVerifyCPU(vm, cpu) < 0)
         goto cleanup;
 
-    if (cpu) {
-        if (!def->cpu ||
-            (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
-             !def->cpu->model)) {
-            ret = 0;
-            goto cleanup;
-        }
-
-        if (!(orig = virCPUDefCopy(def->cpu)))
-            goto cleanup;
-
-        if ((rc = virCPUUpdateLive(def->os.arch, def->cpu, cpu, disabled)) < 0) {
-            goto cleanup;
-        } else if (rc == 0) {
-            /* Store the original CPU in priv if QEMU changed it and we didn't
-             * get the original CPU via migration, restore, or snapshot revert.
-             */
-            if (!priv->origCPU && !virCPUDefIsEqual(def->cpu, orig, false))
-                VIR_STEAL_PTR(priv->origCPU, orig);
-
-            def->cpu->check = VIR_CPU_CHECK_FULL;
-        }
-    }
+    if (qemuProcessUpdateLiveGuestCPU(vm, cpu, disabled) < 0)
+        goto cleanup;
 
     ret = 0;
 
  cleanup:
     virCPUDataFree(cpu);
     virCPUDataFree(disabled);
-    virCPUDefFree(orig);
     return ret;
 }
 
-- 
2.13.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/7] qemu: Add qemuProcessUpdateLiveGuestCPU
Posted by Pavel Hrdina 8 years, 5 months ago
On Wed, Jul 12, 2017 at 02:56:50PM +0200, Jiri Denemark wrote:
> Separated from qemuProcessUpdateAndVerifyCPU to handle updating of an
> active guest CPU definition according to live data from QEMU.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/qemu/qemu_process.c | 70 +++++++++++++++++++++++++++++--------------------
>  1 file changed, 42 insertions(+), 28 deletions(-)
> 
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index ebd13057b..926c64197 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -4011,17 +4011,53 @@ qemuProcessVerifyCPU(virDomainObjPtr vm,
>  
>  
>  static int
> +qemuProcessUpdateLiveGuestCPU(virDomainObjPtr vm,
> +                              virCPUDataPtr enabled,
> +                              virCPUDataPtr disabled)
> +{
> +    virDomainDefPtr def = vm->def;
> +    qemuDomainObjPrivatePtr priv = vm->privateData;
> +    virCPUDefPtr orig = NULL;
> +    int rc;
> +    int ret = -1;
> +
> +    if (!enabled ||
> +        !def->cpu ||
> +        (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
> +         !def->cpu->model))

Now the condition is extended by another check, this makes the code
fragile.  I would prefer separating the "!enabled".

> +        return 0;
> +
> +    if (!(orig = virCPUDefCopy(def->cpu)))
> +        goto cleanup;
> +
> +    if ((rc = virCPUUpdateLive(def->os.arch, def->cpu, enabled, disabled)) < 0) {
> +        goto cleanup;
> +    } else if (rc == 0) {
> +        /* Store the original CPU in priv if QEMU changed it and we didn't
> +         * get the original CPU via migration, restore, or snapshot revert.
> +         */
> +        if (!priv->origCPU && !virCPUDefIsEqual(def->cpu, orig, false))
> +            VIR_STEAL_PTR(priv->origCPU, orig);
> +
> +        def->cpu->check = VIR_CPU_CHECK_FULL;
> +    }
> +
> +    ret = 0;
> +
> + cleanup:
> +    virCPUDefFree(orig);
> +    return ret;
> +}

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 4/7] qemu: Add qemuProcessUpdateLiveGuestCPU
Posted by Jiri Denemark 8 years, 5 months ago
On Wed, Jul 12, 2017 at 15:18:58 +0200, Pavel Hrdina wrote:
> On Wed, Jul 12, 2017 at 02:56:50PM +0200, Jiri Denemark wrote:
> > Separated from qemuProcessUpdateAndVerifyCPU to handle updating of an
> > active guest CPU definition according to live data from QEMU.
> > 
> > Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> > ---
> >  src/qemu/qemu_process.c | 70 +++++++++++++++++++++++++++++--------------------
> >  1 file changed, 42 insertions(+), 28 deletions(-)
> > 
> > diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> > index ebd13057b..926c64197 100644
> > --- a/src/qemu/qemu_process.c
> > +++ b/src/qemu/qemu_process.c
> > @@ -4011,17 +4011,53 @@ qemuProcessVerifyCPU(virDomainObjPtr vm,
> >  
> >  
> >  static int
> > +qemuProcessUpdateLiveGuestCPU(virDomainObjPtr vm,
> > +                              virCPUDataPtr enabled,
> > +                              virCPUDataPtr disabled)
> > +{
> > +    virDomainDefPtr def = vm->def;
> > +    qemuDomainObjPrivatePtr priv = vm->privateData;
> > +    virCPUDefPtr orig = NULL;
> > +    int rc;
> > +    int ret = -1;
> > +
> > +    if (!enabled ||
> > +        !def->cpu ||
> > +        (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
> > +         !def->cpu->model))
> 
> Now the condition is extended by another check, this makes the code
> fragile.  I would prefer separating the "!enabled".

OK

Jirka

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