mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-03 11:35:19 +00:00
virDomainSnapshotDiskDefFormat: Use virXMLFormatElement
Refactor the code to use modern XML formatting approach. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
de69f96365
commit
a01726e9cf
@ -772,33 +772,30 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
|
|||||||
virDomainSnapshotDiskDefPtr disk,
|
virDomainSnapshotDiskDefPtr disk,
|
||||||
virDomainXMLOptionPtr xmlopt)
|
virDomainXMLOptionPtr xmlopt)
|
||||||
{
|
{
|
||||||
int type = disk->src->type;
|
g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
|
||||||
|
g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
|
||||||
|
|
||||||
if (!disk->name)
|
if (!disk->name)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
virBufferEscapeString(buf, "<disk name='%s'", disk->name);
|
virBufferEscapeString(&attrBuf, " name='%s'", disk->name);
|
||||||
if (disk->snapshot > 0)
|
if (disk->snapshot > 0)
|
||||||
virBufferAsprintf(buf, " snapshot='%s'",
|
virBufferAsprintf(&attrBuf, " snapshot='%s'",
|
||||||
virDomainSnapshotLocationTypeToString(disk->snapshot));
|
virDomainSnapshotLocationTypeToString(disk->snapshot));
|
||||||
|
|
||||||
if (!disk->src->path && disk->src->format == 0) {
|
if (disk->src->path || disk->src->format != 0) {
|
||||||
virBufferAddLit(buf, "/>\n");
|
virBufferAsprintf(&attrBuf, " type='%s'", virStorageTypeToString(disk->src->type));
|
||||||
return 0;
|
|
||||||
|
if (disk->src->format > 0)
|
||||||
|
virBufferEscapeString(&childBuf, "<driver type='%s'/>\n",
|
||||||
|
virStorageFileFormatTypeToString(disk->src->format));
|
||||||
|
|
||||||
|
if (virDomainDiskSourceFormat(&childBuf, disk->src, "source", 0, false, 0,
|
||||||
|
false, false, xmlopt) < 0)
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virBufferAsprintf(buf, " type='%s'>\n", virStorageTypeToString(type));
|
virXMLFormatElement(buf, "disk", &attrBuf, &childBuf);
|
||||||
virBufferAdjustIndent(buf, 2);
|
|
||||||
|
|
||||||
if (disk->src->format > 0)
|
|
||||||
virBufferEscapeString(buf, "<driver type='%s'/>\n",
|
|
||||||
virStorageFileFormatTypeToString(disk->src->format));
|
|
||||||
if (virDomainDiskSourceFormat(buf, disk->src, "source", 0, false, 0,
|
|
||||||
false, false, xmlopt) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
virBufferAdjustIndent(buf, -2);
|
|
||||||
virBufferAddLit(buf, "</disk>\n");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user