[libvirt] [PATCH 2/7] qemu: Add qemuProcessVerifyCPU

Jiri Denemark posted 7 patches 8 years, 5 months ago
[libvirt] [PATCH 2/7] qemu: Add qemuProcessVerifyCPU
Posted by Jiri Denemark 8 years, 5 months ago
Separated from qemuProcessUpdateLiveGuestCPU. The function makes sure
a guest CPU provides all features required by a domain definition.

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

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index b2d27b6be..198f68d93 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3986,6 +3986,31 @@ qemuProcessFetchGuestCPU(virQEMUDriverPtr driver,
 
 
 static int
+qemuProcessVerifyCPU(virDomainObjPtr vm,
+                     virCPUDataPtr cpu)
+{
+    virDomainDefPtr def = vm->def;
+
+    if (!cpu)
+        return 0;
+
+    if (qemuProcessVerifyKVMFeatures(def, cpu) < 0 ||
+        qemuProcessVerifyHypervFeatures(def, cpu) < 0)
+        return -1;
+
+    if (!def->cpu ||
+        (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
+         !def->cpu->model))
+        return 0;
+
+    if (qemuProcessVerifyCPUFeatures(def, cpu) < 0)
+        return -1;
+
+    return 0;
+}
+
+
+static int
 qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver,
                               virDomainObjPtr vm,
                               qemuDomainAsyncJob asyncJob)
@@ -4001,11 +4026,10 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver,
     if (qemuProcessFetchGuestCPU(driver, vm, asyncJob, &cpu, &disabled) < 0)
         goto cleanup;
 
-    if (cpu) {
-        if (qemuProcessVerifyKVMFeatures(def, cpu) < 0 ||
-            qemuProcessVerifyHypervFeatures(def, cpu) < 0)
-            goto cleanup;
+    if (qemuProcessVerifyCPU(vm, cpu) < 0)
+        goto cleanup;
 
+    if (cpu) {
         if (!def->cpu ||
             (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
              !def->cpu->model)) {
@@ -4013,9 +4037,6 @@ qemuProcessUpdateLiveGuestCPU(virQEMUDriverPtr driver,
             goto cleanup;
         }
 
-        if (qemuProcessVerifyCPUFeatures(def, cpu) < 0)
-            goto cleanup;
-
         if (!(orig = virCPUDefCopy(def->cpu)))
             goto cleanup;
 
-- 
2.13.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/7] qemu: Add qemuProcessVerifyCPU
Posted by Pavel Hrdina 8 years, 5 months ago
On Wed, Jul 12, 2017 at 02:56:48PM +0200, Jiri Denemark wrote:
> Separated from qemuProcessUpdateLiveGuestCPU. The function makes sure
> a guest CPU provides all features required by a domain definition.
> 
> Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> ---
>  src/qemu/qemu_process.c | 35 ++++++++++++++++++++++++++++-------
>  1 file changed, 28 insertions(+), 7 deletions(-)
> 
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index b2d27b6be..198f68d93 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -3986,6 +3986,31 @@ qemuProcessFetchGuestCPU(virQEMUDriverPtr driver,
>  
>  
>  static int
> +qemuProcessVerifyCPU(virDomainObjPtr vm,
> +                     virCPUDataPtr cpu)
> +{
> +    virDomainDefPtr def = vm->def;
> +
> +    if (!cpu)
> +        return 0;
> +
> +    if (qemuProcessVerifyKVMFeatures(def, cpu) < 0 ||
> +        qemuProcessVerifyHypervFeatures(def, cpu) < 0)
> +        return -1;
> +
> +    if (!def->cpu ||
> +        (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
> +         !def->cpu->model))

This condition is now on two places, it would be worth to create a
macro/function with some description why this specific condition.

> +        return 0;
> +
> +    if (qemuProcessVerifyCPUFeatures(def, cpu) < 0)
> +        return -1;
> +
> +    return 0;
> +}
> +

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 2/7] qemu: Add qemuProcessVerifyCPU
Posted by Jiri Denemark 8 years, 5 months ago
On Wed, Jul 12, 2017 at 15:14:20 +0200, Pavel Hrdina wrote:
> On Wed, Jul 12, 2017 at 02:56:48PM +0200, Jiri Denemark wrote:
> > Separated from qemuProcessUpdateLiveGuestCPU. The function makes sure
> > a guest CPU provides all features required by a domain definition.
> > 
> > Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
> > ---
> >  src/qemu/qemu_process.c | 35 ++++++++++++++++++++++++++++-------
> >  1 file changed, 28 insertions(+), 7 deletions(-)
> > 
> > diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> > index b2d27b6be..198f68d93 100644
> > --- a/src/qemu/qemu_process.c
> > +++ b/src/qemu/qemu_process.c
> > @@ -3986,6 +3986,31 @@ qemuProcessFetchGuestCPU(virQEMUDriverPtr driver,
> >  
> >  
> >  static int
> > +qemuProcessVerifyCPU(virDomainObjPtr vm,
> > +                     virCPUDataPtr cpu)
> > +{
> > +    virDomainDefPtr def = vm->def;
> > +
> > +    if (!cpu)
> > +        return 0;
> > +
> > +    if (qemuProcessVerifyKVMFeatures(def, cpu) < 0 ||
> > +        qemuProcessVerifyHypervFeatures(def, cpu) < 0)
> > +        return -1;
> > +
> > +    if (!def->cpu ||
> > +        (def->cpu->mode == VIR_CPU_MODE_CUSTOM &&
> > +         !def->cpu->model))
> 
> This condition is now on two places, it would be worth to create a
> macro/function with some description why this specific condition.

Oh yeah, good idea. This condition is very likely repeated in a lot of
places which need to check whether the CPU def contains only topology
data. I'll try to come up with a good name for the function and make a
patch replacing all open coded conditions with it.

Jirka

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