[libvirt] [libvirt PATCH v7 6/6] xen_common: Change xenParseCharDev to using virConfGetValueStringList

Fabiano Fidêncio posted 6 patches 7 years, 4 months ago
[libvirt] [libvirt PATCH v7 6/6] 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 | 27 +++++++++++++--------------
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 058f35825e..21f1f4a24c 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -773,11 +773,13 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def)
 static int
 xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
 {
-    virConfValuePtr value = NULL;
+    VIR_AUTOPTR(virString) serials = NULL;
     virDomainChrDefPtr chr = NULL;
 
     if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         VIR_AUTOFREE(char *) parallel = NULL;
+        int rc;
+
         if (xenConfigGetString(conf, "parallel", &parallel, NULL) < 0)
             goto cleanup;
         if (parallel && STRNEQ(parallel, "none") &&
@@ -795,8 +797,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 ((rc = virConfGetValueStringList(conf, "serial", false, &serials)) == 1) {
+            virString *entries;
             int portnum = -1;
 
             if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
@@ -805,18 +807,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
                 goto cleanup;
             }
 
-            value = value->list;
-            while (value) {
-                char *port = NULL;
+            for (entries = serials; *entries; entries++) {
+                virString 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;
@@ -824,11 +820,14 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
                 chr->target.port = portnum;
                 if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0)
                     goto cleanup;
-
-                value = value->next;
             }
         } else {
             VIR_AUTOFREE(char *) serial = NULL;
+
+            rc = xenHandleConfGetValueStringListErrors(rc, virGetLastErrorCode());
+            if (rc < 0)
+                goto cleanup;
+
             /* If domain is not using multiple serial ports we parse data old way */
             if (xenConfigGetString(conf, "serial", &serial, NULL) < 0)
                 goto cleanup;
-- 
2.17.1

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

On 09/20/2018 09:28 AM, Fabiano Fidêncio wrote:
> Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
> ---
>  src/xenconfig/xen_common.c | 27 +++++++++++++--------------
>  1 file changed, 13 insertions(+), 14 deletions(-)
> 
> diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
> index 058f35825e..21f1f4a24c 100644
> --- a/src/xenconfig/xen_common.c
> +++ b/src/xenconfig/xen_common.c
> @@ -773,11 +773,13 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def)
>  static int
>  xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
>  {
> -    virConfValuePtr value = NULL;
> +    VIR_AUTOPTR(virString) serials = NULL;
>      virDomainChrDefPtr chr = NULL;
>  
>      if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
>          VIR_AUTOFREE(char *) parallel = NULL;
> +        int rc;
> +
>          if (xenConfigGetString(conf, "parallel", &parallel, NULL) < 0)
>              goto cleanup;
>          if (parallel && STRNEQ(parallel, "none") &&
> @@ -795,8 +797,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 ((rc = virConfGetValueStringList(conf, "serial", false, &serials)) == 1) {
> +            virString *entries;
>              int portnum = -1;
>  
>              if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
> @@ -805,18 +807,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
>                  goto cleanup;
>              }
>  
> -            value = value->list;
> -            while (value) {
> -                char *port = NULL;
> +            for (entries = serials; *entries; entries++) {
> +                virString 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;
> @@ -824,11 +820,14 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char *nativeFormat)
>                  chr->target.port = portnum;
>                  if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0)
>                      goto cleanup;
> -
> -                value = value->next;
>              }
>          } else {
>              VIR_AUTOFREE(char *) serial = NULL;
> +
> +            rc = xenHandleConfGetValueStringListErrors(rc, virGetLastErrorCode());
> +            if (rc < 0)

Based on patch4 change, this is simplified to just:


            if (xenHandleConfGetValueStringListErrors(rc) < 0)

I can alter before pushing if you're fine with that.

Reviewed-by: John Ferlan <jferlan@redhat.com>

John

Logic is sooo much nicer with these VIR_AUTOFREE and VIR_AUTOPTR!

> +                goto cleanup;
> +
>              /* If domain is not using multiple serial ports we parse data old way */
>              if (xenConfigGetString(conf, "serial", &serial, NULL) < 0)
>                  goto cleanup;
> 

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

>
>
> On 09/20/2018 09:28 AM, Fabiano Fidêncio wrote:
> > Signed-off-by: Fabiano Fidêncio <fidencio@redhat.com>
> > ---
> >  src/xenconfig/xen_common.c | 27 +++++++++++++--------------
> >  1 file changed, 13 insertions(+), 14 deletions(-)
> >
> > diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
> > index 058f35825e..21f1f4a24c 100644
> > --- a/src/xenconfig/xen_common.c
> > +++ b/src/xenconfig/xen_common.c
> > @@ -773,11 +773,13 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def)
> >  static int
> >  xenParseCharDev(virConfPtr conf, virDomainDefPtr def, const char
> *nativeFormat)
> >  {
> > -    virConfValuePtr value = NULL;
> > +    VIR_AUTOPTR(virString) serials = NULL;
> >      virDomainChrDefPtr chr = NULL;
> >
> >      if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
> >          VIR_AUTOFREE(char *) parallel = NULL;
> > +        int rc;
> > +
> >          if (xenConfigGetString(conf, "parallel", &parallel, NULL) < 0)
> >              goto cleanup;
> >          if (parallel && STRNEQ(parallel, "none") &&
> > @@ -795,8 +797,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 ((rc = virConfGetValueStringList(conf, "serial", false,
> &serials)) == 1) {
> > +            virString *entries;
> >              int portnum = -1;
> >
> >              if (STREQ(nativeFormat, XEN_CONFIG_FORMAT_XM)) {
> > @@ -805,18 +807,12 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr
> def, const char *nativeFormat)
> >                  goto cleanup;
> >              }
> >
> > -            value = value->list;
> > -            while (value) {
> > -                char *port = NULL;
> > +            for (entries = serials; *entries; entries++) {
> > +                virString 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;
> > @@ -824,11 +820,14 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr
> def, const char *nativeFormat)
> >                  chr->target.port = portnum;
> >                  if (VIR_APPEND_ELEMENT(def->serials, def->nserials,
> chr) < 0)
> >                      goto cleanup;
> > -
> > -                value = value->next;
> >              }
> >          } else {
> >              VIR_AUTOFREE(char *) serial = NULL;
> > +
> > +            rc = xenHandleConfGetValueStringListErrors(rc,
> virGetLastErrorCode());
> > +            if (rc < 0)
>
> Based on patch4 change, this is simplified to just:
>
>
>             if (xenHandleConfGetValueStringListErrors(rc) < 0)
>
> I can alter before pushing if you're fine with that.
>

Sure. Thanks a lot for the review, John!


>
> Reviewed-by: John Ferlan <jferlan@redhat.com>
>
> John
>
> Logic is sooo much nicer with these VIR_AUTOFREE and VIR_AUTOPTR!
>
> > +                goto cleanup;
> > +
> >              /* If domain is not using multiple serial ports we parse
> data old way */
> >              if (xenConfigGetString(conf, "serial", &serial, NULL) < 0)
> >                  goto cleanup;
> >
>
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list