[libvirt] [PATCH 03/14] qemu: Introduce qemuDomainChrDefPostParse()

Andrea Bolognani posted 14 patches 7 years, 6 months ago
There is a newer version of this series
[libvirt] [PATCH 03/14] qemu: Introduce qemuDomainChrDefPostParse()
Posted by Andrea Bolognani 7 years, 6 months ago
Having a separate function for char device handling is better than
adding even more code to qemuDomainDeviceDefPostParse().

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
 src/qemu/qemu_domain.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cc7596bad..2d5eee01e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4036,6 +4036,19 @@ qemuDomainControllerDefPostParse(virDomainControllerDefPtr cont,
     return 0;
 }
 
+static int
+qemuDomainChrDefPostParse(virDomainChrDefPtr chr,
+                          const virDomainDef *def)
+{
+    /* set the default console type for S390 arches */
+    if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
+        chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE &&
+        ARCH_IS_S390(def->os.arch)) {
+        chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO;
+    }
+
+    return 0;
+}
 
 static int
 qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
@@ -4096,13 +4109,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         }
     }
 
-    /* set the default console type for S390 arches */
-    if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
-        dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
-        dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE &&
-        ARCH_IS_S390(def->os.arch))
-        dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO;
-
     /* clear auto generated unix socket path for inactive definitions */
     if ((parseFlags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
         dev->type == VIR_DOMAIN_DEVICE_CHR) {
@@ -4154,6 +4160,11 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         qemuDomainShmemDefPostParse(dev->data.shmem) < 0)
         goto cleanup;
 
+    if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
+        qemuDomainChrDefPostParse(dev->data.chr, def) < 0) {
+        goto cleanup;
+    }
+
     ret = 0;
 
  cleanup:
-- 
2.13.6

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 03/14] qemu: Introduce qemuDomainChrDefPostParse()
Posted by Pavel Hrdina 7 years, 5 months ago
On Wed, Nov 15, 2017 at 12:50:06PM +0100, Andrea Bolognani wrote:
> Having a separate function for char device handling is better than
> adding even more code to qemuDomainDeviceDefPostParse().
> 
> Signed-off-by: Andrea Bolognani <abologna@redhat.com>
> ---
>  src/qemu/qemu_domain.c | 25 ++++++++++++++++++-------
>  1 file changed, 18 insertions(+), 7 deletions(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index cc7596bad..2d5eee01e 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -4036,6 +4036,19 @@ qemuDomainControllerDefPostParse(virDomainControllerDefPtr cont,
>      return 0;
>  }
>  
> +static int
> +qemuDomainChrDefPostParse(virDomainChrDefPtr chr,
> +                          const virDomainDef *def)
> +{
> +    /* set the default console type for S390 arches */
> +    if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
> +        chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE &&
> +        ARCH_IS_S390(def->os.arch)) {
> +        chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO;
> +    }
> +
> +    return 0;
> +}
>  
>  static int
>  qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
> @@ -4096,13 +4109,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
>          }
>      }
>  
> -    /* set the default console type for S390 arches */
> -    if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
> -        dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
> -        dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE &&
> -        ARCH_IS_S390(def->os.arch))
> -        dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO;
> -

You've missed the following condition that clears auto generated unix
socket path, it is also for char devices.

>      /* clear auto generated unix socket path for inactive definitions */
>      if ((parseFlags & VIR_DOMAIN_DEF_PARSE_INACTIVE) &&
>          dev->type == VIR_DOMAIN_DEVICE_CHR) {
> @@ -4154,6 +4160,11 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
>          qemuDomainShmemDefPostParse(dev->data.shmem) < 0)
>          goto cleanup;
>  
> +    if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
> +        qemuDomainChrDefPostParse(dev->data.chr, def) < 0) {
> +        goto cleanup;
> +    }
> +

Is there any specific reason why did you move it to a different place?

Pavel
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 03/14] qemu: Introduce qemuDomainChrDefPostParse()
Posted by Andrea Bolognani 7 years, 5 months ago
On Thu, 2017-11-16 at 11:30 +0100, Pavel Hrdina wrote:
> > @@ -4096,13 +4109,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
> >          }
> >      }
> >  
> > -    /* set the default console type for S390 arches */
> > -    if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
> > -        dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
> > -        dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE &&
> > -        ARCH_IS_S390(def->os.arch))
> > -        dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO;
> > -
> 
> You've missed the following condition that clears auto generated unix
> socket path, it is also for char devices.

Right. I was focusing on the target type, but the stuff you mention
should definitely go in qemuDomainChrDefPostParse() too.

> > @@ -4154,6 +4160,11 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
> >          qemuDomainShmemDefPostParse(dev->data.shmem) < 0)
> >          goto cleanup;
> >  
> > +    if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
> > +        qemuDomainChrDefPostParse(dev->data.chr, def) < 0) {
> > +        goto cleanup;
> > +    }
> > +
> 
> Is there any specific reason why did you move it to a different place?

All the ad-hoc code is before the sub-functions, and it looks nicer
to have the sub-functions all together. There should be no functional
impact with moving it.

-- 
Andrea Bolognani / Red Hat / Virtualization

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