[libvirt] [libvirt PATCH v6 15/15] xen_common: Change xenParseCharDev to using virConfGetValueStringList

Fabiano Fidêncio posted 15 patches 7 years, 4 months ago
[libvirt] [libvirt PATCH v6 15/15] xen_common: Change xenParseCharDev to using virConfGetValueStringList
Posted by Fabiano Fidêncio 7 years, 4 months ago
Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
---
 src/xenconfig/xen_common.c | 23 +++++++++++------------
 1 file changed, 11 insertions(+), 12 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index a6e77a9250..786c276c99 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -759,9 +759,11 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def)
 static int
 xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
 {
+    char **serials = NULL;
     const char *str;
     virConfValuePtr value = NULL;
     virDomainChrDefPtr chr = NULL;
+    int ret = -1;
 
     if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (xenConfigGetString(conf, "parallel", &str, NULL) < 0)
@@ -782,7 +784,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
 
         /* Try to get the list of values to support multiple serial ports */
         value = virConfGetValue(conf, "serial");
-        if (value && value->type == VIR_CONF_LIST) {
+        if (virConfGetValueStringList(conf, "serial", false, &serials) == 1) {
+            char **entries;
             int portnum = -1;
 
             if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
@@ -791,18 +794,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
                 goto cleanup;
             }
 
-            value = value->list;
-            while (value) {
-                char *port = NULL;
+            for (entries = serials; *entries; entries++) {
+                char *port = *entries;
 
-                if ((value->type != VIR_CONF_STRING) || (value->str == NULL))
-                    goto cleanup;
-                port = value->str;
                 portnum++;
-                if (STREQ(port, "none")) {
-                    value = value->next;
+                if (STREQ(port, "none"))
                     continue;
-                }
 
                 if (!(chr = xenParseSxprChar(port, NULL)))
                     goto cleanup;
@@ -827,6 +824,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
                 chr->target.port = 0;
                 def->serials[0] = chr;
                 def->nserials++;
+                chr = NULL;
             }
         }
     } else {
@@ -840,11 +838,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
         def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
     }
 
-    return 0;
+    ret = 0;
 
  cleanup:
     virDomainChrDefFree(chr);
-    return -1;
+    virStringListFree(serials);
+    return ret;
 }
 
 
-- 
2.17.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt PATCH v6 15/15] xen_common: Change xenParseCharDev to using virConfGetValueStringList
Posted by John Ferlan 7 years, 4 months ago

On 09/18/2018 02:48 PM, Fabiano Fidêncio wrote:
> Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
> ---
>  src/xenconfig/xen_common.c | 23 +++++++++++------------
>  1 file changed, 11 insertions(+), 12 deletions(-)
> 
> diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
> index a6e77a9250..786c276c99 100644
> --- a/src/xenconfig/xen_common.c
> +++ b/src/xenconfig/xen_common.c
> @@ -759,9 +759,11 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def)
>  static int
>  xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
>  {
> +    char **serials = NULL;
>      const char *str;
>      virConfValuePtr value = NULL;
>      virDomainChrDefPtr chr = NULL;
> +    int ret = -1;
>  
>      if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
>          if (xenConfigGetString(conf, "parallel", &str, NULL) < 0)

Heh heh - this is what I noted earlier - @str isn't going to be FREE'd.

> @@ -782,7 +784,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
>  
>          /* Try to get the list of values to support multiple serial ports */
>          value = virConfGetValue(conf, "serial");
> -        if (value && value->type == VIR_CONF_LIST) {
> +        if (virConfGetValueStringList(conf, "serial", false, &serials) == 1) {

Well this is similar to the previous two except that you kept @value
here and that line probably should have been deleted as would the value
= value->next below and the variable itself as it's unused... At least
it shouldn't run off the end of the list...

> +            char **entries;
>              int portnum = -1;
>  
>              if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
> @@ -791,18 +794,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
>                  goto cleanup;
>              }
>  
> -            value = value->list;
> -            while (value) {
> -                char *port = NULL;
> +            for (entries = serials; *entries; entries++) {
> +                char *port = *entries;
>  
> -                if ((value->type != VIR_CONF_STRING) || (value->str == NULL))
> -                    goto cleanup;
> -                port = value->str;
>                  portnum++;
> -                if (STREQ(port, "none")) {
> -                    value = value->next;
> +                if (STREQ(port, "none"))
>                      continue;
> -                }
>  
>                  if (!(chr = xenParseSxprChar(port, NULL)))
>                      goto cleanup;
> @@ -827,6 +824,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
>                  chr->target.port = 0;
>                  def->serials[0] = chr;
>                  def->nserials++;
> +                chr = NULL;

Hmmm... unrelated but equally bad bug.  This would require it's own
separate patch.

John


>              }
>          }
>      } else {
> @@ -840,11 +838,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
>          def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
>      }
>  
> -    return 0;
> +    ret = 0;
>  
>   cleanup:
>      virDomainChrDefFree(chr);
> -    return -1;
> +    virStringListFree(serials);
> +    return ret;
>  }
>  
>  
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [libvirt PATCH v6 15/15] xen_common: Change xenParseCharDev to using virConfGetValueStringList
Posted by Fabiano Fidêncio 7 years, 4 months ago
On Thu, Sep 20, 2018 at 12:12 AM, John Ferlan <jferlan@redhat.com> wrote:

>
>
> On 09/18/2018 02:48 PM, Fabiano Fidêncio wrote:
> > Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
> > ---
> >  src/xenconfig/xen_common.c | 23 +++++++++++------------
> >  1 file changed, 11 insertions(+), 12 deletions(-)
> >
> > diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
> > index a6e77a9250..786c276c99 100644
> > --- a/src/xenconfig/xen_common.c
> > +++ b/src/xenconfig/xen_common.c
> > @@ -759,9 +759,11 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def)
> >  static int
> >  xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char
> *nativeFormat)
> >  {
> > +    char **serials = NULL;
> >      const char *str;
> >      virConfValuePtr value = NULL;
> >      virDomainChrDefPtr chr = NULL;
> > +    int ret = -1;
> >
> >      if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
> >          if (xenConfigGetString(conf, "parallel", &str, NULL) < 0)
>
> Heh heh - this is what I noted earlier - @str isn't going to be FREE'd.
>
> > @@ -782,7 +784,8 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr
> def, const char *nativeFormat)
> >
> >          /* Try to get the list of values to support multiple serial
> ports */
> >          value = virConfGetValue(conf, "serial");
> > -        if (value && value->type == VIR_CONF_LIST) {
> > +        if (virConfGetValueStringList(conf, "serial", false, &serials)
> == 1) {
>
> Well this is similar to the previous two except that you kept @value
> here and that line probably should have been deleted as would the value
> = value->next below and the variable itself as it's unused... At least
> it shouldn't run off the end of the list...
>
> > +            char **entries;
> >              int portnum = -1;
> >
> >              if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
> > @@ -791,18 +794,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr
> def, const char *nativeFormat)
> >                  goto cleanup;
> >              }
> >
> > -            value = value->list;
> > -            while (value) {
> > -                char *port = NULL;
> > +            for (entries = serials; *entries; entries++) {
> > +                char *port = *entries;
> >
> > -                if ((value->type != VIR_CONF_STRING) || (value->str ==
> NULL))
> > -                    goto cleanup;
> > -                port = value->str;
> >                  portnum++;
> > -                if (STREQ(port, "none")) {
> > -                    value = value->next;
> > +                if (STREQ(port, "none"))
> >                      continue;
> > -                }
> >
> >                  if (!(chr = xenParseSxprChar(port, NULL)))
> >                      goto cleanup;
> > @@ -827,6 +824,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr
> def, const char *nativeFormat)
> >                  chr->target.port = 0;
> >                  def->serials[0] = chr;
> >                  def->nserials++;
> > +                chr = NULL;
>
> Hmmm... unrelated but equally bad bug.  This would require it's own
> separate patch.
>

After re-working the patches this change is not needed anymore! \o/


>
> John
>
>
> >              }
> >          }
> >      } else {
> > @@ -840,11 +838,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr
> def, const char *nativeFormat)
> >          def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_
> TYPE_XEN;
> >      }
> >
> > -    return 0;
> > +    ret = 0;
> >
> >   cleanup:
> >      virDomainChrDefFree(chr);
> > -    return -1;
> > +    virStringListFree(serials);
> > +    return ret;
> >  }
> >
> >
> >
>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list