Use the new helper to initialize child XML element buffers. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/conf/domain_conf.c | 101 +++++++++++------------------------------ 1 file changed, 27 insertions(+), 74 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 81ab5eb138..f59f95c5be 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7112,7 +7112,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf, unsigned int flags) { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); int ret = -1; if ((flags & VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) && info->bootIndex) { @@ -7181,7 +7181,6 @@ virDomainDeviceInfoFormat(virBufferPtr buf, } if (!virZPCIDeviceAddressIsEmpty(&info->addr.pci.zpci)) { - virBufferSetChildIndent(&childBuf, buf); virBufferAsprintf(&childBuf, "<zpci uid='0x%.4x' fid='0x%.8x'/>\n", info->addr.pci.zpci.uid, @@ -24107,15 +24106,13 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf, unsigned int flags, virDomainXMLOptionPtr xmlopt) { - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); int ret = -1; if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) || !xmlopt || !xmlopt->privateData.storageFormat) return 0; - virBufferSetChildIndent(&childBuf, buf); - if (xmlopt->privateData.storageFormat(src, &childBuf) < 0) goto cleanup; @@ -24151,9 +24148,7 @@ virDomainDiskSourceFormat(virBufferPtr buf, virDomainXMLOptionPtr xmlopt) { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; - - virBufferSetChildIndent(&childBuf, buf); + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); switch ((virStorageType)src->type) { case VIR_STORAGE_TYPE_FILE: @@ -24238,12 +24233,10 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, unsigned int flags) { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); bool inactive = flags & VIR_DOMAIN_DEF_FORMAT_INACTIVE; virStorageSourcePtr backingStore = src->backingStore; - virBufferSetChildIndent(&childBuf, buf); - if (!backingStore) return 0; @@ -24293,9 +24286,7 @@ static int virDomainDiskDefFormatIotune(virBufferPtr buf, virDomainDiskDefPtr disk) { - virBuffer childBuf = VIR_BUFFER_INITIALIZER; - - virBufferSetChildIndent(&childBuf, buf); + virBuffer childBuf = VIR_BUFFER_INIT_CHILD(buf); FORMAT_IOTUNE(total_bytes_sec); FORMAT_IOTUNE(read_bytes_sec); @@ -24404,11 +24395,9 @@ virDomainDiskDefFormatMirror(virBufferPtr buf, virDomainXMLOptionPtr xmlopt) { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); const char *formatStr = NULL; - virBufferSetChildIndent(&childBuf, buf); - /* For now, mirroring is currently output-only: we only output it * for live domains, therefore we ignore it on input except for * the internal parse on libvirtd restart. We prefer to output @@ -24455,15 +24444,13 @@ virDomainDiskDefFormatPrivateData(virBufferPtr buf, unsigned int flags, virDomainXMLOptionPtr xmlopt) { - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); if (!(flags & VIR_DOMAIN_DEF_FORMAT_STATUS) || !xmlopt || !xmlopt->privateData.diskFormat) return 0; - virBufferSetChildIndent(&childBuf, buf); - if (xmlopt->privateData.diskFormat(disk, &childBuf) < 0) return -1; @@ -24641,9 +24628,7 @@ virDomainControllerDefFormat(virBufferPtr buf, const char *model = NULL; const char *modelName = NULL; g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; - - virBufferSetChildIndent(&childBuf, buf); + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); if (!type) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -25745,9 +25730,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf, unsigned int flags) { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; - - virBufferSetChildIndent(&childBuf, buf); + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); switch ((virDomainChrType)def->type) { case VIR_DOMAIN_CHR_TYPE_NULL: @@ -26023,12 +26006,10 @@ virDomainSmartcardDefFormat(virBufferPtr buf, unsigned int flags) { const char *mode = virDomainSmartcardTypeToString(def->type); - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); size_t i; int ret = -1; - virBufferSetChildIndent(&childBuf, buf); - if (!mode) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected smartcard type %d"), def->type); @@ -26153,12 +26134,10 @@ virDomainSoundDefFormat(virBufferPtr buf, unsigned int flags) { const char *model = virDomainSoundModelTypeToString(def->model); - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); size_t i; int ret = -1; - virBufferSetChildIndent(&childBuf, buf); - if (!model) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected sound model %d"), def->model); @@ -26194,7 +26173,7 @@ virDomainMemballoonDefFormat(virBufferPtr buf, { const char *model = virDomainMemballoonModelTypeToString(def->model); g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf); g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER; if (!model) { @@ -26209,8 +26188,6 @@ virDomainMemballoonDefFormat(virBufferPtr buf, virBufferAsprintf(&attrBuf, " autodeflate='%s'", virTristateSwitchTypeToString(def->autodeflate)); - virBufferSetChildIndent(&childrenBuf, buf); - if (def->period) virBufferAsprintf(&childrenBuf, "<stats period='%i'/>\n", def->period); @@ -26250,9 +26227,7 @@ virDomainWatchdogDefFormat(virBufferPtr buf, const char *model = virDomainWatchdogModelTypeToString(def->model); const char *action = virDomainWatchdogActionTypeToString(def->action); g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; - - virBufferSetChildIndent(&childBuf, buf); + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); if (!model) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -26280,13 +26255,12 @@ static int virDomainPanicDefFormat(virBufferPtr buf, virDomainPanicDefPtr def) { g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf); if (def->model) virBufferAsprintf(&attrBuf, " model='%s'", virDomainPanicModelTypeToString(def->model)); - virBufferSetChildIndent(&childrenBuf, buf); if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0) return -1; @@ -26619,7 +26593,7 @@ virDomainInputDefFormat(virBufferPtr buf, const char *type = virDomainInputTypeToString(def->type); const char *bus = virDomainInputBusTypeToString(def->bus); g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER; /* don't format keyboard into migratable XML for backward compatibility */ @@ -26654,7 +26628,6 @@ virDomainInputDefFormat(virBufferPtr buf, virBufferAsprintf(&attrBuf, " model='%s'", model); } - virBufferSetChildIndent(&childBuf, buf); virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL); @@ -27352,9 +27325,7 @@ virDomainHubDefFormat(virBufferPtr buf, { const char *type = virDomainHubTypeToString(def->type); g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; - - virBufferSetChildIndent(&childBuf, buf); + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); if (!type) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -27621,12 +27592,11 @@ virDomainCachetuneDefFormat(virBufferPtr buf, virDomainResctrlDefPtr resctrl, unsigned int flags) { - g_auto(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf); size_t i = 0; int ret = -1; g_autofree char *vcpus = NULL; - virBufferSetChildIndent(&childrenBuf, buf); if (virResctrlAllocForeachCache(resctrl->alloc, virDomainCachetuneDefFormatHelper, &childrenBuf) < 0) @@ -27687,11 +27657,10 @@ virDomainMemorytuneDefFormat(virBufferPtr buf, virDomainResctrlDefPtr resctrl, unsigned int flags) { - g_auto(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf); int ret = -1; g_autofree char *vcpus = NULL; - virBufferSetChildIndent(&childrenBuf, buf); if (virResctrlAllocForeachMemory(resctrl->alloc, virDomainMemorytuneDefFormatHelper, &childrenBuf) < 0) @@ -27731,10 +27700,9 @@ virDomainCputuneDefFormat(virBufferPtr buf, unsigned int flags) { size_t i; - g_auto(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf); int ret = -1; - virBufferSetChildIndent(&childrenBuf, buf); if (def->cputune.sharesSpecified) virBufferAsprintf(&childrenBuf, "<shares>%llu</shares>\n", @@ -27916,13 +27884,11 @@ static int virDomainIOMMUDefFormat(virBufferPtr buf, const virDomainIOMMUDef *iommu) { - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) driverAttrBuf = VIR_BUFFER_INITIALIZER; int ret = -1; - virBufferSetChildIndent(&childBuf, buf); - if (iommu->intremap != VIR_TRISTATE_SWITCH_ABSENT) { virBufferAsprintf(&driverAttrBuf, " intremap='%s'", virTristateSwitchTypeToString(iommu->intremap)); @@ -27957,9 +27923,7 @@ static void virDomainMemtuneFormat(virBufferPtr buf, const virDomainMemtune *mem) { - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; - - virBufferSetChildIndent(&childBuf, buf); + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); if (virMemoryLimitIsSet(mem->hard_limit)) { virBufferAsprintf(&childBuf, @@ -27990,9 +27954,7 @@ static void virDomainMemorybackingFormat(virBufferPtr buf, const virDomainMemtune *mem) { - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; - - virBufferSetChildIndent(&childBuf, buf); + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); if (mem->nhugepages) virDomainHugepagesFormat(&childBuf, mem->hugepages, mem->nhugepages); @@ -28020,7 +27982,7 @@ static int virDomainVsockDefFormat(virBufferPtr buf, virDomainVsockDefPtr vsock) { - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) cidAttrBuf = VIR_BUFFER_INITIALIZER; int ret = -1; @@ -28030,8 +27992,6 @@ virDomainVsockDefFormat(virBufferPtr buf, virDomainVsockModelTypeToString(vsock->model)); } - virBufferSetChildIndent(&childBuf, buf); - if (vsock->auto_cid != VIR_TRISTATE_BOOL_ABSENT) { virBufferAsprintf(&cidAttrBuf, " auto='%s'", virTristateBoolTypeToString(vsock->auto_cid)); @@ -28056,10 +28016,9 @@ static int virDomainDefFormatBlkiotune(virBufferPtr buf, virDomainDefPtr def) { - g_auto(virBuffer) childrenBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childrenBuf = VIR_BUFFER_INIT_CHILD(buf); ssize_t n; - virBufferSetChildIndent(&childrenBuf, buf); if (def->blkio.weight) virBufferAsprintf(&childrenBuf, "<weight>%u</weight>\n", def->blkio.weight); @@ -28103,14 +28062,12 @@ static int virDomainDefFormatFeatures(virBufferPtr buf, virDomainDefPtr def) { - g_auto(virBuffer) tmpAttrBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) tmpChildBuf = VIR_BUFFER_INITIALIZER; - g_auto(virBuffer) childBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf); size_t i; - virBufferSetChildIndent(&childBuf, buf); - for (i = 0; i < VIR_DOMAIN_FEATURE_LAST; i++) { + g_auto(virBuffer) tmpAttrBuf = VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) tmpChildBuf = VIR_BUFFER_INIT_CHILD(&childBuf); const char *name = virDomainFeatureTypeToString(i); size_t j; @@ -28176,7 +28133,6 @@ virDomainDefFormatFeatures(virBufferPtr buf, unsigned long long short_size = virFormatIntPretty(def->tseg_size, &unit); - virBufferSetChildIndent(&tmpChildBuf, &childBuf); virBufferAsprintf(&tmpChildBuf, "<tseg unit='%s'>%llu</tseg>\n", unit, short_size); } @@ -28297,8 +28253,6 @@ virDomainDefFormatFeatures(virBufferPtr buf, break; case VIR_DOMAIN_FEATURE_CAPABILITIES: - virBufferSetChildIndent(&tmpChildBuf, &childBuf); - for (j = 0; j < VIR_DOMAIN_PROCES_CAPS_FEATURE_LAST; j++) { if (def->caps_features[j] != VIR_TRISTATE_SWITCH_ABSENT) virBufferAsprintf(&tmpChildBuf, "<%s state='%s'/>\n", @@ -28343,7 +28297,6 @@ virDomainDefFormatFeatures(virBufferPtr buf, virDomainHPTResizingTypeToString(def->hpt_resizing)); } if (def->hpt_maxpagesize > 0) { - virBufferSetChildIndent(&tmpChildBuf, &childBuf); virBufferAsprintf(&tmpChildBuf, "<maxpagesize unit='KiB'>%llu</maxpagesize>\n", def->hpt_maxpagesize); -- 2.23.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list