]> xenbits.xensource.com Git - libvirt.git/commitdiff
xen_common: Change xenParsePCIList to use virConfGetValueStringList
authorFabiano FidĂȘncio <fidencio@redhat.com>
Thu, 20 Sep 2018 13:28:50 +0000 (15:28 +0200)
committerJohn Ferlan <jferlan@redhat.com>
Thu, 20 Sep 2018 20:39:09 +0000 (16:39 -0400)
The `if(!list || list->type != VIR_CONF_LIST)` check couldn't be
written in a 100% similar way. Instead, we're just checking whether
`virConfGetValueStringList() <= 0` and creating a new function to:
- return -1 in case virConfGetValueStringList fails either due to some
  allocation failure or when traversing the list;
- resetting the last error and return 0 otherwise;

Taking this approach we can have the behaviour with the new code as
close as possible to the old one.

Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
src/xenconfig/xen_common.c

index 25fd432bde724d14c2f45a88ace899a6a5863664..ed3d89c2c6d80a6c4efd18d692932e7da06a6bdc 100644 (file)
@@ -454,21 +454,41 @@ xenParsePCI(char *entry)
 }
 
 
+static int
+xenHandleConfGetValueStringListErrors(int ret)
+{
+    if (ret < 0) {
+        /* It means virConfGetValueStringList() didn't fail because the
+         * cval->type switch fell through - since we're passing
+         * @compatString == false - assumes failures for memory allocation
+         * and VIR_CONF_LIST traversal failure should cause -1 to be
+         * returned to the caller with the error message set. */
+        if (virGetLastErrorCode() != VIR_ERR_INTERNAL_ERROR)
+            return -1;
+
+        /* If we did fall through the switch, then ignore and clear the
+         * last error. */
+        virResetLastError();
+    }
+    return 0;
+}
+
+
 static int
 xenParsePCIList(virConfPtr conf, virDomainDefPtr def)
 {
-    virConfValuePtr list = virConfGetValue(conf, "pci");
+    VIR_AUTOPTR(virString) pcis = NULL;
+    virString *entries = NULL;
+    int rc;
 
-    if (!list || list->type != VIR_CONF_LIST)
-        return 0;
+    if ((rc = virConfGetValueStringList(conf, "pci", false, &pcis)) <= 0)
+        return xenHandleConfGetValueStringListErrors(rc);
 
-    for (list = list->list; list; list = list->next) {
+    for (entries = pcis; *entries; entries++) {
+        virString entry = *entries;
         virDomainHostdevDefPtr hostdev;
 
-        if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
-            continue;
-
-        if (!(hostdev = xenParsePCI(list->str)))
+        if (!(hostdev = xenParsePCI(entry)))
             return -1;
 
         if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) {