[PATCH 19/19] util: xml: Make virXMLFormatElement void

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Now that we don't have to deal with errors of virBuffer we can also make
this function void.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/domain_conf.c | 112 +++++++++++++++++++----------------------
 src/qemu/qemu_domain.c |  24 ++++-----
 src/util/virsysinfo.c  |   5 +-
 src/util/virxml.c      |  14 ++----
 src/util/virxml.h      |   5 +-
 5 files changed, 69 insertions(+), 91 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 778858fe3e..5d45cb23a9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7254,8 +7254,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
         break;
     }

-    if (virXMLFormatElement(buf, "address", &attrBuf, &childBuf) < 0)
-        goto cleanup;
+    virXMLFormatElement(buf, "address", &attrBuf, &childBuf);

     ret = 0;

@@ -24126,8 +24125,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf,
     if (xmlopt->privateData.storageFormat(src, &childBuf) < 0)
         goto cleanup;

-    if (virXMLFormatElement(buf, "privateData", NULL, &childBuf) < 0)
-        goto cleanup;
+    virXMLFormatElement(buf, "privateData", NULL, &childBuf);

     ret = 0;

@@ -24233,8 +24231,7 @@ virDomainDiskSourceFormat(virBufferPtr buf,
     if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xmlopt) < 0)
         return -1;

-    if (virXMLFormatElement(buf, element, &attrBuf, &childBuf) < 0)
-        return -1;
+    virXMLFormatElement(buf, element, &attrBuf, &childBuf);

     return 0;
 }
@@ -24286,8 +24283,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
     if (virDomainDiskBackingStoreFormat(&childBuf, backingStore, xmlopt, flags) < 0)
         return -1;

-    if (virXMLFormatElement(buf, "backingStore", &attrBuf, &childBuf) < 0)
-        return -1;
+    virXMLFormatElement(buf, "backingStore", &attrBuf, &childBuf);

     return 0;
 }
@@ -24338,7 +24334,9 @@ virDomainDiskDefFormatIotune(virBufferPtr buf,
     FORMAT_IOTUNE(read_iops_sec_max_length);
     FORMAT_IOTUNE(write_iops_sec_max_length);

-    return virXMLFormatElement(buf, "iotune", NULL, &childBuf);
+    virXMLFormatElement(buf, "iotune", NULL, &childBuf);
+
+    return 0;
 }

 #undef FORMAT_IOTUNE
@@ -24400,7 +24398,8 @@ virDomainDiskDefFormatDriver(virBufferPtr buf,

     virDomainVirtioOptionsFormat(&driverBuf, disk->virtio);

-    return virXMLFormatElement(buf, "driver", &driverBuf, NULL);
+    virXMLFormatElement(buf, "driver", &driverBuf, NULL);
+    return 0;
 }


@@ -24450,8 +24449,7 @@ virDomainDiskDefFormatMirror(virBufferPtr buf,
     if (virDomainDiskBackingStoreFormat(&childBuf, disk->mirror, xmlopt, flags) < 0)
         return -1;

-    if (virXMLFormatElement(buf, "mirror", &attrBuf, &childBuf) < 0)
-        return -1;
+    virXMLFormatElement(buf, "mirror", &attrBuf, &childBuf);

     return 0;
 }
@@ -24475,7 +24473,8 @@ virDomainDiskDefFormatPrivateData(virBufferPtr buf,
     if (xmlopt->privateData.diskFormat(disk, &childBuf) < 0)
         return -1;

-    return virXMLFormatElement(buf, "privateData", NULL, &childBuf);
+    virXMLFormatElement(buf, "privateData", NULL, &childBuf);
+    return 0;
 }


@@ -24633,7 +24632,9 @@ virDomainControllerDriverFormat(virBufferPtr buf,

     virDomainVirtioOptionsFormat(&driverBuf, def->virtio);

-    return virXMLFormatElement(buf, "driver", &driverBuf, NULL);
+    virXMLFormatElement(buf, "driver", &driverBuf, NULL);
+
+    return 0;
 }


@@ -24785,7 +24786,9 @@ virDomainControllerDefFormat(virBufferPtr buf,
                           "pcihole64>\n", def->opts.pciopts.pcihole64size);
     }

-    return virXMLFormatElement(buf, "controller", &attrBuf, &childBuf);
+    virXMLFormatElement(buf, "controller", &attrBuf, &childBuf);
+
+    return 0;
 }


@@ -25628,8 +25631,7 @@ virDomainNetDefFormat(virBufferPtr buf,
                           virTristateBoolTypeToString(def->managed_tap));
     }

-    if (virXMLFormatElement(buf, "target", &attrBuf, NULL) < 0)
-        return -1;
+    virXMLFormatElement(buf, "target", &attrBuf, NULL);

     if (def->ifname_guest || def->ifname_guest_actual) {
         virBufferAddLit(buf, "<guest");
@@ -25778,8 +25780,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
             virDomainSourceDefFormatSeclabel(&childBuf, def->nseclabels,
                                              def->seclabels, flags);

-            if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0)
-                goto error;
+            virXMLFormatElement(buf, "source", &attrBuf, &childBuf);
         }
         break;

@@ -25822,8 +25823,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
         virDomainChrSourceReconnectDefFormat(&childBuf,
                                              &def->data.tcp.reconnect);

-        if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0)
-            goto error;
+        virXMLFormatElement(buf, "source", &attrBuf, &childBuf);

         virBufferAsprintf(buf, "<protocol type='%s'/>\n",
                           virDomainChrTcpProtocolTypeToString(
@@ -25841,8 +25841,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
             virDomainChrSourceReconnectDefFormat(&childBuf,
                                                  &def->data.nix.reconnect);

-            if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0)
-                goto error;
+            virXMLFormatElement(buf, "source", &attrBuf, &childBuf);
         }
         break;

@@ -25863,9 +25862,6 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
     }

     return 0;
-
- error:
-    return -1;
 }


@@ -26229,10 +26225,10 @@ virDomainMemballoonDefFormat(virBufferPtr buf,

     virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);

-    if (virXMLFormatElement(&childrenBuf, "driver", &driverAttrBuf, NULL) < 0)
-        return -1;
+    virXMLFormatElement(&childrenBuf, "driver", &driverAttrBuf, NULL);
+    virXMLFormatElement(buf, "memballoon", &attrBuf, &childrenBuf);

-    return virXMLFormatElement(buf, "memballoon", &attrBuf, &childrenBuf);
+    return 0;
 }

 static int
@@ -26281,7 +26277,9 @@ virDomainWatchdogDefFormat(virBufferPtr buf,
     if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
         return -1;

-    return virXMLFormatElement(buf, "watchdog", &attrBuf, &childBuf);
+    virXMLFormatElement(buf, "watchdog", &attrBuf, &childBuf);
+
+    return 0;
 }

 static int virDomainPanicDefFormat(virBufferPtr buf,
@@ -26298,7 +26296,9 @@ static int virDomainPanicDefFormat(virBufferPtr buf,
     if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0)
         return -1;

-    return virXMLFormatElement(buf, "panic", &attrBuf, &childrenBuf);
+    virXMLFormatElement(buf, "panic", &attrBuf, &childrenBuf);
+
+    return 0;
 }

 static int
@@ -26381,8 +26381,7 @@ virDomainRNGDefFormat(virBufferPtr buf,

     virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);

-    if (virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL) < 0)
-        return -1;
+    virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);

     if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
         return -1;
@@ -26664,14 +26663,15 @@ virDomainInputDefFormat(virBufferPtr buf,
     virBufferSetChildIndent(&childBuf, buf);
     virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);

-    if (virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL) < 0)
-        return -1;
+    virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL);

     virBufferEscapeString(&childBuf, "<source evdev='%s'/>\n", def->source.evdev);
     if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
         return -1;

-    return virXMLFormatElement(buf, "input", &attrBuf, &childBuf);
+    virXMLFormatElement(buf, "input", &attrBuf, &childBuf);
+
+    return 0;
 }


@@ -27373,7 +27373,9 @@ virDomainHubDefFormat(virBufferPtr buf,

     virBufferAsprintf(&attrBuf, " type='%s'", type);

-    return virXMLFormatElement(buf, "hub", &attrBuf, &childBuf);
+    virXMLFormatElement(buf, "hub", &attrBuf, &childBuf);
+
+    return 0;
 }


@@ -27944,18 +27946,15 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
                           virTristateSwitchTypeToString(iommu->iotlb));
     }

-    if (virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL) < 0)
-        goto cleanup;
+    virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL);

     virBufferAsprintf(&attrBuf, " model='%s'",
                       virDomainIOMMUModelTypeToString(iommu->model));

-    if (virXMLFormatElement(buf, "iommu", &attrBuf, &childBuf) < 0)
-        goto cleanup;
+    virXMLFormatElement(buf, "iommu", &attrBuf, &childBuf);

     ret = 0;

- cleanup:
     return ret;
 }

@@ -27990,8 +27989,7 @@ virDomainMemtuneFormat(virBufferPtr buf,
                           mem->swap_hard_limit);
     }

-    if (virXMLFormatElement(buf, "memtune", NULL, &childBuf) < 0)
-        goto cleanup;
+    virXMLFormatElement(buf, "memtune", NULL, &childBuf);

     virBufferSetChildIndent(&childBuf, buf);

@@ -28013,11 +28011,9 @@ virDomainMemtuneFormat(virBufferPtr buf,
     if (mem->discard)
         virBufferAddLit(&childBuf, "<discard/>\n");

-    if (virXMLFormatElement(buf, "memoryBacking", NULL, &childBuf) < 0)
-        goto cleanup;
+    virXMLFormatElement(buf, "memoryBacking", NULL, &childBuf);

     ret = 0;
- cleanup:
     return ret;
 }

@@ -28044,14 +28040,12 @@ virDomainVsockDefFormat(virBufferPtr buf,
     }
     if (vsock->guest_cid != 0)
         virBufferAsprintf(&cidAttrBuf, " address='%u'", vsock->guest_cid);
-    if (virXMLFormatElement(&childBuf, "cid", &cidAttrBuf, NULL) < 0)
-        goto cleanup;
+    virXMLFormatElement(&childBuf, "cid", &cidAttrBuf, NULL);

     if (virDomainDeviceInfoFormat(&childBuf, &vsock->info, 0) < 0)
         goto cleanup;

-    if (virXMLFormatElement(buf, "vsock", &attrBuf, &childBuf) < 0)
-        goto cleanup;
+    virXMLFormatElement(buf, "vsock", &attrBuf, &childBuf);

     ret = 0;

@@ -28101,7 +28095,9 @@ virDomainDefFormatBlkiotune(virBufferPtr buf,
         virBufferAddLit(&childrenBuf, "</device>\n");
     }

-    return virXMLFormatElement(buf, "blkiotune", NULL, &childrenBuf);
+    virXMLFormatElement(buf, "blkiotune", NULL, &childrenBuf);
+
+    return 0;
 }


@@ -28187,8 +28183,7 @@ virDomainDefFormatFeatures(virBufferPtr buf,
                                   unit, short_size);
             }

-            if (virXMLFormatElement(&childBuf, "smm", &tmpAttrBuf, &tmpChildBuf) < 0)
-                return -1;
+            virXMLFormatElement(&childBuf, "smm", &tmpAttrBuf, &tmpChildBuf);

             break;

@@ -28319,8 +28314,7 @@ virDomainDefFormatFeatures(virBufferPtr buf,
                 virBufferAsprintf(&tmpAttrBuf, " policy='%s'",
                                   virDomainCapabilitiesPolicyTypeToString(def->features[i]));

-            if (virXMLFormatElement(&childBuf, "capabilities", &tmpAttrBuf, &tmpChildBuf) < 0)
-                return -1;
+            virXMLFormatElement(&childBuf, "capabilities", &tmpAttrBuf, &tmpChildBuf);
             break;

         case VIR_DOMAIN_FEATURE_GIC:
@@ -28357,8 +28351,7 @@ virDomainDefFormatFeatures(virBufferPtr buf,
                                   def->hpt_maxpagesize);
             }

-            if (virXMLFormatElement(&childBuf, "hpt", &tmpAttrBuf, &tmpChildBuf) < 0)
-                return -1;
+            virXMLFormatElement(&childBuf, "hpt", &tmpAttrBuf, &tmpChildBuf);
             break;

         case VIR_DOMAIN_FEATURE_MSRS:
@@ -28375,7 +28368,8 @@ virDomainDefFormatFeatures(virBufferPtr buf,
         }
     }

-    return virXMLFormatElement(buf, "features", NULL, &childBuf);
+    virXMLFormatElement(buf, "features", NULL, &childBuf);
+    return 0;
 }

 int
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 71309d9c83..667cc89072 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2327,8 +2327,7 @@ qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src,
     if (src->tlsAlias)
         virBufferAsprintf(&tmp, "<TLSx509 alias='%s'/>\n", src->tlsAlias);

-    if (virXMLFormatElement(buf, "objects", NULL, &tmp) < 0)
-        goto cleanup;
+    virXMLFormatElement(buf, "objects", NULL, &tmp);

     ret = 0;

@@ -2461,8 +2460,7 @@ qemuDomainObjPrivateXMLFormatBlockjobFormatSource(virBufferPtr buf,
         virDomainDiskBackingStoreFormat(&childBuf, src, xmlopt, xmlflags) < 0)
         return -1;

-    if (virXMLFormatElement(buf, element, &attrBuf, &childBuf) < 0)
-        return -1;
+    virXMLFormatElement(buf, element, &attrBuf, &childBuf);

     return 0;
 }
@@ -2515,8 +2513,7 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload,
                                                               true) < 0)
             return -1;

-        if (virXMLFormatElement(&childBuf, "chains", NULL, &chainsBuf) < 0)
-            return -1;
+        virXMLFormatElement(&childBuf, "chains", NULL, &chainsBuf);
     }

     switch ((qemuBlockJobType) job->type) {
@@ -2559,7 +2556,8 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload,
             break;
     }

-    return virXMLFormatElement(data->buf, "blockjob", &attrBuf, &childBuf);
+    virXMLFormatElement(data->buf, "blockjob", &attrBuf, &childBuf);
+    return 0;
 }


@@ -2585,7 +2583,8 @@ qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf,
                        &iterdata) < 0)
         return -1;

-    return virXMLFormatElement(buf, "blockjobs", &attrBuf, &childBuf);
+    virXMLFormatElement(buf, "blockjobs", &attrBuf, &childBuf);
+    return 0;
 }


@@ -2627,8 +2626,7 @@ qemuDomainObjPrivateXMLFormatNBDMigrationSource(virBufferPtr buf,
                                   VIR_DOMAIN_DEF_FORMAT_STATUS, xmlopt) < 0)
         goto cleanup;

-    if (virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf) < 0)
-        goto cleanup;
+    virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf);

     ret = 0;

@@ -2664,8 +2662,7 @@ qemuDomainObjPrivateXMLFormatNBDMigration(virBufferPtr buf,
                                                             priv->driver->xmlopt) < 0)
             goto cleanup;

-        if (virXMLFormatElement(buf, "disk", &attrBuf, &childBuf) < 0)
-            goto cleanup;
+        virXMLFormatElement(buf, "disk", &attrBuf, &childBuf);
     }

     ret = 0;
@@ -2714,8 +2711,7 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
     if (priv->job.migParams)
         qemuMigrationParamsFormat(&childBuf, priv->job.migParams);

-    if (virXMLFormatElement(buf, "job", &attrBuf, &childBuf) < 0)
-        goto cleanup;
+    virXMLFormatElement(buf, "job", &attrBuf, &childBuf);

     ret = 0;

diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 0714661237..9d013067fe 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -1505,10 +1505,7 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)

     virBufferAsprintf(&attrBuf, " type='%s'", type);

-    if (virXMLFormatElement(buf, "sysinfo", &attrBuf, &childrenBuf) < 0) {
-        virBufferFreeAndReset(buf);
-        return -1;
-    }
+    virXMLFormatElement(buf, "sysinfo", &attrBuf, &childrenBuf);

     return 0;
 }
diff --git a/src/util/virxml.c b/src/util/virxml.c
index 31e7bb3c73..0e66d1623b 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -1371,21 +1371,16 @@ virXMLValidatorFree(virXMLValidatorPtr validator)
  * formatted.
  *
  * Both passed buffers are always consumed and freed.
- *
- * Returns 0 on success, -1 on error.
  */
-int
+void
 virXMLFormatElement(virBufferPtr buf,
                     const char *name,
                     virBufferPtr attrBuf,
                     virBufferPtr childBuf)
 {
-    int ret = -1;
-
     if ((!attrBuf || virBufferUse(attrBuf) == 0) &&
-        (!childBuf || virBufferUse(childBuf) == 0)) {
-        return 0;
-    }
+        (!childBuf || virBufferUse(childBuf) == 0))
+        return;

     virBufferAsprintf(buf, "<%s", name);

@@ -1400,11 +1395,8 @@ virXMLFormatElement(virBufferPtr buf,
         virBufferAddLit(buf, "/>\n");
     }

-    ret = 0;
-
     virBufferFreeAndReset(attrBuf);
     virBufferFreeAndReset(childBuf);
-    return ret;
 }


diff --git a/src/util/virxml.h b/src/util/virxml.h
index dfdc1f73c3..26ab9f9c2d 100644
--- a/src/util/virxml.h
+++ b/src/util/virxml.h
@@ -215,12 +215,11 @@ virXMLValidateAgainstSchema(const char *schemafile,
 void
 virXMLValidatorFree(virXMLValidatorPtr validator);

-int
+void
 virXMLFormatElement(virBufferPtr buf,
                     const char *name,
                     virBufferPtr attrBuf,
-                    virBufferPtr childBuf)
-    G_GNUC_WARN_UNUSED_RESULT;
+                    virBufferPtr childBuf);

 struct _virXPathContextNodeSave {
     xmlXPathContextPtr ctxt;
-- 
2.21.0

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





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux