1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

util: xml: Make virXMLFormatElement void

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@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2019-10-24 15:50:50 +02:00
parent 0967708b81
commit bf0e7bdeeb
5 changed files with 69 additions and 91 deletions

View File

@ -7254,8 +7254,7 @@ virDomainDeviceInfoFormat(virBufferPtr buf,
break; break;
} }
if (virXMLFormatElement(buf, "address", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "address", &attrBuf, &childBuf);
goto cleanup;
ret = 0; ret = 0;
@ -24120,8 +24119,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf,
if (xmlopt->privateData.storageFormat(src, &childBuf) < 0) if (xmlopt->privateData.storageFormat(src, &childBuf) < 0)
goto cleanup; goto cleanup;
if (virXMLFormatElement(buf, "privateData", NULL, &childBuf) < 0) virXMLFormatElement(buf, "privateData", NULL, &childBuf);
goto cleanup;
ret = 0; ret = 0;
@ -24227,8 +24225,7 @@ virDomainDiskSourceFormat(virBufferPtr buf,
if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xmlopt) < 0) if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xmlopt) < 0)
return -1; return -1;
if (virXMLFormatElement(buf, element, &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, element, &attrBuf, &childBuf);
return -1;
return 0; return 0;
} }
@ -24280,8 +24277,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
if (virDomainDiskBackingStoreFormat(&childBuf, backingStore, xmlopt, flags) < 0) if (virDomainDiskBackingStoreFormat(&childBuf, backingStore, xmlopt, flags) < 0)
return -1; return -1;
if (virXMLFormatElement(buf, "backingStore", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "backingStore", &attrBuf, &childBuf);
return -1;
return 0; return 0;
} }
@ -24332,7 +24328,9 @@ virDomainDiskDefFormatIotune(virBufferPtr buf,
FORMAT_IOTUNE(read_iops_sec_max_length); FORMAT_IOTUNE(read_iops_sec_max_length);
FORMAT_IOTUNE(write_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 #undef FORMAT_IOTUNE
@ -24394,7 +24392,8 @@ virDomainDiskDefFormatDriver(virBufferPtr buf,
virDomainVirtioOptionsFormat(&driverBuf, disk->virtio); virDomainVirtioOptionsFormat(&driverBuf, disk->virtio);
return virXMLFormatElement(buf, "driver", &driverBuf, NULL); virXMLFormatElement(buf, "driver", &driverBuf, NULL);
return 0;
} }
@ -24444,8 +24443,7 @@ virDomainDiskDefFormatMirror(virBufferPtr buf,
if (virDomainDiskBackingStoreFormat(&childBuf, disk->mirror, xmlopt, flags) < 0) if (virDomainDiskBackingStoreFormat(&childBuf, disk->mirror, xmlopt, flags) < 0)
return -1; return -1;
if (virXMLFormatElement(buf, "mirror", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "mirror", &attrBuf, &childBuf);
return -1;
return 0; return 0;
} }
@ -24469,7 +24467,8 @@ virDomainDiskDefFormatPrivateData(virBufferPtr buf,
if (xmlopt->privateData.diskFormat(disk, &childBuf) < 0) if (xmlopt->privateData.diskFormat(disk, &childBuf) < 0)
return -1; return -1;
return virXMLFormatElement(buf, "privateData", NULL, &childBuf); virXMLFormatElement(buf, "privateData", NULL, &childBuf);
return 0;
} }
@ -24627,7 +24626,9 @@ virDomainControllerDriverFormat(virBufferPtr buf,
virDomainVirtioOptionsFormat(&driverBuf, def->virtio); virDomainVirtioOptionsFormat(&driverBuf, def->virtio);
return virXMLFormatElement(buf, "driver", &driverBuf, NULL); virXMLFormatElement(buf, "driver", &driverBuf, NULL);
return 0;
} }
@ -24779,7 +24780,9 @@ virDomainControllerDefFormat(virBufferPtr buf,
"pcihole64>\n", def->opts.pciopts.pcihole64size); "pcihole64>\n", def->opts.pciopts.pcihole64size);
} }
return virXMLFormatElement(buf, "controller", &attrBuf, &childBuf); virXMLFormatElement(buf, "controller", &attrBuf, &childBuf);
return 0;
} }
@ -25622,8 +25625,7 @@ virDomainNetDefFormat(virBufferPtr buf,
virTristateBoolTypeToString(def->managed_tap)); virTristateBoolTypeToString(def->managed_tap));
} }
if (virXMLFormatElement(buf, "target", &attrBuf, NULL) < 0) virXMLFormatElement(buf, "target", &attrBuf, NULL);
return -1;
if (def->ifname_guest || def->ifname_guest_actual) { if (def->ifname_guest || def->ifname_guest_actual) {
virBufferAddLit(buf, "<guest"); virBufferAddLit(buf, "<guest");
@ -25772,8 +25774,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
virDomainSourceDefFormatSeclabel(&childBuf, def->nseclabels, virDomainSourceDefFormatSeclabel(&childBuf, def->nseclabels,
def->seclabels, flags); def->seclabels, flags);
if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "source", &attrBuf, &childBuf);
goto error;
} }
break; break;
@ -25816,8 +25817,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
virDomainChrSourceReconnectDefFormat(&childBuf, virDomainChrSourceReconnectDefFormat(&childBuf,
&def->data.tcp.reconnect); &def->data.tcp.reconnect);
if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "source", &attrBuf, &childBuf);
goto error;
virBufferAsprintf(buf, "<protocol type='%s'/>\n", virBufferAsprintf(buf, "<protocol type='%s'/>\n",
virDomainChrTcpProtocolTypeToString( virDomainChrTcpProtocolTypeToString(
@ -25835,8 +25835,7 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
virDomainChrSourceReconnectDefFormat(&childBuf, virDomainChrSourceReconnectDefFormat(&childBuf,
&def->data.nix.reconnect); &def->data.nix.reconnect);
if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "source", &attrBuf, &childBuf);
goto error;
} }
break; break;
@ -25857,9 +25856,6 @@ virDomainChrSourceDefFormat(virBufferPtr buf,
} }
return 0; return 0;
error:
return -1;
} }
@ -26223,10 +26219,10 @@ virDomainMemballoonDefFormat(virBufferPtr buf,
virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
if (virXMLFormatElement(&childrenBuf, "driver", &driverAttrBuf, NULL) < 0) virXMLFormatElement(&childrenBuf, "driver", &driverAttrBuf, NULL);
return -1; virXMLFormatElement(buf, "memballoon", &attrBuf, &childrenBuf);
return virXMLFormatElement(buf, "memballoon", &attrBuf, &childrenBuf); return 0;
} }
static int static int
@ -26275,7 +26271,9 @@ virDomainWatchdogDefFormat(virBufferPtr buf,
if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
return -1; return -1;
return virXMLFormatElement(buf, "watchdog", &attrBuf, &childBuf); virXMLFormatElement(buf, "watchdog", &attrBuf, &childBuf);
return 0;
} }
static int virDomainPanicDefFormat(virBufferPtr buf, static int virDomainPanicDefFormat(virBufferPtr buf,
@ -26292,7 +26290,9 @@ static int virDomainPanicDefFormat(virBufferPtr buf,
if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0) if (virDomainDeviceInfoFormat(&childrenBuf, &def->info, 0) < 0)
return -1; return -1;
return virXMLFormatElement(buf, "panic", &attrBuf, &childrenBuf); virXMLFormatElement(buf, "panic", &attrBuf, &childrenBuf);
return 0;
} }
static int static int
@ -26375,8 +26375,7 @@ virDomainRNGDefFormat(virBufferPtr buf,
virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
if (virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL) < 0) virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL);
return -1;
if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0) if (virDomainDeviceInfoFormat(buf, &def->info, flags) < 0)
return -1; return -1;
@ -26658,14 +26657,15 @@ virDomainInputDefFormat(virBufferPtr buf,
virBufferSetChildIndent(&childBuf, buf); virBufferSetChildIndent(&childBuf, buf);
virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio); virDomainVirtioOptionsFormat(&driverAttrBuf, def->virtio);
if (virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL) < 0) virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL);
return -1;
virBufferEscapeString(&childBuf, "<source evdev='%s'/>\n", def->source.evdev); virBufferEscapeString(&childBuf, "<source evdev='%s'/>\n", def->source.evdev);
if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0) if (virDomainDeviceInfoFormat(&childBuf, &def->info, flags) < 0)
return -1; return -1;
return virXMLFormatElement(buf, "input", &attrBuf, &childBuf); virXMLFormatElement(buf, "input", &attrBuf, &childBuf);
return 0;
} }
@ -27367,7 +27367,9 @@ virDomainHubDefFormat(virBufferPtr buf,
virBufferAsprintf(&attrBuf, " type='%s'", type); virBufferAsprintf(&attrBuf, " type='%s'", type);
return virXMLFormatElement(buf, "hub", &attrBuf, &childBuf); virXMLFormatElement(buf, "hub", &attrBuf, &childBuf);
return 0;
} }
@ -27938,18 +27940,15 @@ virDomainIOMMUDefFormat(virBufferPtr buf,
virTristateSwitchTypeToString(iommu->iotlb)); virTristateSwitchTypeToString(iommu->iotlb));
} }
if (virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL) < 0) virXMLFormatElement(&childBuf, "driver", &driverAttrBuf, NULL);
goto cleanup;
virBufferAsprintf(&attrBuf, " model='%s'", virBufferAsprintf(&attrBuf, " model='%s'",
virDomainIOMMUModelTypeToString(iommu->model)); virDomainIOMMUModelTypeToString(iommu->model));
if (virXMLFormatElement(buf, "iommu", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "iommu", &attrBuf, &childBuf);
goto cleanup;
ret = 0; ret = 0;
cleanup:
return ret; return ret;
} }
@ -27984,8 +27983,7 @@ virDomainMemtuneFormat(virBufferPtr buf,
mem->swap_hard_limit); mem->swap_hard_limit);
} }
if (virXMLFormatElement(buf, "memtune", NULL, &childBuf) < 0) virXMLFormatElement(buf, "memtune", NULL, &childBuf);
goto cleanup;
virBufferSetChildIndent(&childBuf, buf); virBufferSetChildIndent(&childBuf, buf);
@ -28007,11 +28005,9 @@ virDomainMemtuneFormat(virBufferPtr buf,
if (mem->discard) if (mem->discard)
virBufferAddLit(&childBuf, "<discard/>\n"); virBufferAddLit(&childBuf, "<discard/>\n");
if (virXMLFormatElement(buf, "memoryBacking", NULL, &childBuf) < 0) virXMLFormatElement(buf, "memoryBacking", NULL, &childBuf);
goto cleanup;
ret = 0; ret = 0;
cleanup:
return ret; return ret;
} }
@ -28038,14 +28034,12 @@ virDomainVsockDefFormat(virBufferPtr buf,
} }
if (vsock->guest_cid != 0) if (vsock->guest_cid != 0)
virBufferAsprintf(&cidAttrBuf, " address='%u'", vsock->guest_cid); virBufferAsprintf(&cidAttrBuf, " address='%u'", vsock->guest_cid);
if (virXMLFormatElement(&childBuf, "cid", &cidAttrBuf, NULL) < 0) virXMLFormatElement(&childBuf, "cid", &cidAttrBuf, NULL);
goto cleanup;
if (virDomainDeviceInfoFormat(&childBuf, &vsock->info, 0) < 0) if (virDomainDeviceInfoFormat(&childBuf, &vsock->info, 0) < 0)
goto cleanup; goto cleanup;
if (virXMLFormatElement(buf, "vsock", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "vsock", &attrBuf, &childBuf);
goto cleanup;
ret = 0; ret = 0;
@ -28095,7 +28089,9 @@ virDomainDefFormatBlkiotune(virBufferPtr buf,
virBufferAddLit(&childrenBuf, "</device>\n"); virBufferAddLit(&childrenBuf, "</device>\n");
} }
return virXMLFormatElement(buf, "blkiotune", NULL, &childrenBuf); virXMLFormatElement(buf, "blkiotune", NULL, &childrenBuf);
return 0;
} }
@ -28181,8 +28177,7 @@ virDomainDefFormatFeatures(virBufferPtr buf,
unit, short_size); unit, short_size);
} }
if (virXMLFormatElement(&childBuf, "smm", &tmpAttrBuf, &tmpChildBuf) < 0) virXMLFormatElement(&childBuf, "smm", &tmpAttrBuf, &tmpChildBuf);
return -1;
break; break;
@ -28313,8 +28308,7 @@ virDomainDefFormatFeatures(virBufferPtr buf,
virBufferAsprintf(&tmpAttrBuf, " policy='%s'", virBufferAsprintf(&tmpAttrBuf, " policy='%s'",
virDomainCapabilitiesPolicyTypeToString(def->features[i])); virDomainCapabilitiesPolicyTypeToString(def->features[i]));
if (virXMLFormatElement(&childBuf, "capabilities", &tmpAttrBuf, &tmpChildBuf) < 0) virXMLFormatElement(&childBuf, "capabilities", &tmpAttrBuf, &tmpChildBuf);
return -1;
break; break;
case VIR_DOMAIN_FEATURE_GIC: case VIR_DOMAIN_FEATURE_GIC:
@ -28351,8 +28345,7 @@ virDomainDefFormatFeatures(virBufferPtr buf,
def->hpt_maxpagesize); def->hpt_maxpagesize);
} }
if (virXMLFormatElement(&childBuf, "hpt", &tmpAttrBuf, &tmpChildBuf) < 0) virXMLFormatElement(&childBuf, "hpt", &tmpAttrBuf, &tmpChildBuf);
return -1;
break; break;
case VIR_DOMAIN_FEATURE_MSRS: case VIR_DOMAIN_FEATURE_MSRS:
@ -28369,7 +28362,8 @@ virDomainDefFormatFeatures(virBufferPtr buf,
} }
} }
return virXMLFormatElement(buf, "features", NULL, &childBuf); virXMLFormatElement(buf, "features", NULL, &childBuf);
return 0;
} }
int int

View File

@ -2327,8 +2327,7 @@ qemuStorageSourcePrivateDataFormat(virStorageSourcePtr src,
if (src->tlsAlias) if (src->tlsAlias)
virBufferAsprintf(&tmp, "<TLSx509 alias='%s'/>\n", src->tlsAlias); virBufferAsprintf(&tmp, "<TLSx509 alias='%s'/>\n", src->tlsAlias);
if (virXMLFormatElement(buf, "objects", NULL, &tmp) < 0) virXMLFormatElement(buf, "objects", NULL, &tmp);
goto cleanup;
ret = 0; ret = 0;
@ -2461,8 +2460,7 @@ qemuDomainObjPrivateXMLFormatBlockjobFormatSource(virBufferPtr buf,
virDomainDiskBackingStoreFormat(&childBuf, src, xmlopt, xmlflags) < 0) virDomainDiskBackingStoreFormat(&childBuf, src, xmlopt, xmlflags) < 0)
return -1; return -1;
if (virXMLFormatElement(buf, element, &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, element, &attrBuf, &childBuf);
return -1;
return 0; return 0;
} }
@ -2515,8 +2513,7 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload,
true) < 0) true) < 0)
return -1; return -1;
if (virXMLFormatElement(&childBuf, "chains", NULL, &chainsBuf) < 0) virXMLFormatElement(&childBuf, "chains", NULL, &chainsBuf);
return -1;
} }
switch ((qemuBlockJobType) job->type) { switch ((qemuBlockJobType) job->type) {
@ -2559,7 +2556,8 @@ qemuDomainObjPrivateXMLFormatBlockjobIterator(void *payload,
break; 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) &iterdata) < 0)
return -1; 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) VIR_DOMAIN_DEF_FORMAT_STATUS, xmlopt) < 0)
goto cleanup; goto cleanup;
if (virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "migrationSource", &attrBuf, &childBuf);
goto cleanup;
ret = 0; ret = 0;
@ -2664,8 +2662,7 @@ qemuDomainObjPrivateXMLFormatNBDMigration(virBufferPtr buf,
priv->driver->xmlopt) < 0) priv->driver->xmlopt) < 0)
goto cleanup; goto cleanup;
if (virXMLFormatElement(buf, "disk", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "disk", &attrBuf, &childBuf);
goto cleanup;
} }
ret = 0; ret = 0;
@ -2714,8 +2711,7 @@ qemuDomainObjPrivateXMLFormatJob(virBufferPtr buf,
if (priv->job.migParams) if (priv->job.migParams)
qemuMigrationParamsFormat(&childBuf, priv->job.migParams); qemuMigrationParamsFormat(&childBuf, priv->job.migParams);
if (virXMLFormatElement(buf, "job", &attrBuf, &childBuf) < 0) virXMLFormatElement(buf, "job", &attrBuf, &childBuf);
goto cleanup;
ret = 0; ret = 0;

View File

@ -1505,10 +1505,7 @@ virSysinfoFormat(virBufferPtr buf, virSysinfoDefPtr def)
virBufferAsprintf(&attrBuf, " type='%s'", type); virBufferAsprintf(&attrBuf, " type='%s'", type);
if (virXMLFormatElement(buf, "sysinfo", &attrBuf, &childrenBuf) < 0) { virXMLFormatElement(buf, "sysinfo", &attrBuf, &childrenBuf);
virBufferFreeAndReset(buf);
return -1;
}
return 0; return 0;
} }

View File

@ -1371,21 +1371,16 @@ virXMLValidatorFree(virXMLValidatorPtr validator)
* formatted. * formatted.
* *
* Both passed buffers are always consumed and freed. * Both passed buffers are always consumed and freed.
*
* Returns 0 on success, -1 on error.
*/ */
int void
virXMLFormatElement(virBufferPtr buf, virXMLFormatElement(virBufferPtr buf,
const char *name, const char *name,
virBufferPtr attrBuf, virBufferPtr attrBuf,
virBufferPtr childBuf) virBufferPtr childBuf)
{ {
int ret = -1;
if ((!attrBuf || virBufferUse(attrBuf) == 0) && if ((!attrBuf || virBufferUse(attrBuf) == 0) &&
(!childBuf || virBufferUse(childBuf) == 0)) { (!childBuf || virBufferUse(childBuf) == 0))
return 0; return;
}
virBufferAsprintf(buf, "<%s", name); virBufferAsprintf(buf, "<%s", name);
@ -1400,11 +1395,8 @@ virXMLFormatElement(virBufferPtr buf,
virBufferAddLit(buf, "/>\n"); virBufferAddLit(buf, "/>\n");
} }
ret = 0;
virBufferFreeAndReset(attrBuf); virBufferFreeAndReset(attrBuf);
virBufferFreeAndReset(childBuf); virBufferFreeAndReset(childBuf);
return ret;
} }

View File

@ -215,12 +215,11 @@ virXMLValidateAgainstSchema(const char *schemafile,
void void
virXMLValidatorFree(virXMLValidatorPtr validator); virXMLValidatorFree(virXMLValidatorPtr validator);
int void
virXMLFormatElement(virBufferPtr buf, virXMLFormatElement(virBufferPtr buf,
const char *name, const char *name,
virBufferPtr attrBuf, virBufferPtr attrBuf,
virBufferPtr childBuf) virBufferPtr childBuf);
G_GNUC_WARN_UNUSED_RESULT;
struct _virXPathContextNodeSave { struct _virXPathContextNodeSave {
xmlXPathContextPtr ctxt; xmlXPathContextPtr ctxt;