conf: Add parameter to virDomainDiskSourceFormat

Commits 4bc42986 and 218c81ea removed virDomainStorageSourceFormat on
the grounds that there were no external callers; however, the upcoming
backup code wants to output a <target> (push mode) or <scratch> (pull
mode) element that is in all other respects identical to a domain's
<source> element, where the previous virDomainStorageSourceFormat fit
the bill nicely. But rather than reverting the commits, it's easier to
just add an additional parameter for the element name to use, and
update all callers.

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Eric Blake 2019-04-04 15:32:05 -05:00
parent 6b4aea5e4d
commit 1ec3e39742
6 changed files with 16 additions and 9 deletions

View File

@ -23929,6 +23929,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf,
* virDomainDiskSourceFormat:
* @buf: output buffer
* @src: storage source definition to format
* @element: name to use for the top-level element (often "source")
* @policy: startup policy attribute value, if necessary
* @attrIndex: the 'index' attribute of <source> is formatted if true
* @flags: XML formatter flags
@ -23940,6 +23941,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf,
int
virDomainDiskSourceFormat(virBufferPtr buf,
virStorageSourcePtr src,
const char *element,
int policy,
bool attrIndex,
unsigned int flags,
@ -24020,7 +24022,7 @@ virDomainDiskSourceFormat(virBufferPtr buf,
if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xmlopt) < 0)
return -1;
if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0)
if (virXMLFormatElement(buf, element, &attrBuf, &childBuf) < 0)
return -1;
return 0;
@ -24066,7 +24068,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
virBufferAsprintf(&childBuf, "<format type='%s'/>\n",
virStorageFileFormatTypeToString(backingStore->format));
if (virDomainDiskSourceFormat(&childBuf, backingStore, 0, false, flags, xmlopt) < 0)
if (virDomainDiskSourceFormat(&childBuf, backingStore, "source", 0, false,
flags, xmlopt) < 0)
return -1;
if (virDomainDiskBackingStoreFormat(&childBuf, backingStore, xmlopt, flags) < 0)
@ -24229,7 +24232,8 @@ virDomainDiskDefFormatMirror(virBufferPtr buf,
virDomainDiskMirrorStateTypeToString(disk->mirrorState));
virBufferEscapeString(&childBuf, "<format type='%s'/>\n", formatStr);
if (virDomainDiskSourceFormat(&childBuf, disk->mirror, 0, true, flags, xmlopt) < 0)
if (virDomainDiskSourceFormat(&childBuf, disk->mirror, "source", 0, true,
flags, xmlopt) < 0)
return -1;
if (virDomainDiskBackingStoreFormat(&childBuf, disk->mirror, xmlopt, flags) < 0)
@ -24329,8 +24333,8 @@ virDomainDiskDefFormat(virBufferPtr buf,
if (def->src->auth && !def->src->authInherited)
virStorageAuthDefFormat(buf, def->src->auth);
if (virDomainDiskSourceFormat(buf, def->src, def->startupPolicy, true,
flags, xmlopt) < 0)
if (virDomainDiskSourceFormat(buf, def->src, "source", def->startupPolicy,
true, flags, xmlopt) < 0)
return -1;
/* Don't format backingStore to inactive XMLs until the code for

View File

@ -3061,6 +3061,7 @@ int virDomainDefFormatInternal(virDomainDefPtr def,
int virDomainDiskSourceFormat(virBufferPtr buf,
virStorageSourcePtr src,
const char *element,
int policy,
bool attrIndex,
unsigned int flags,

View File

@ -772,7 +772,8 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
if (disk->src->format > 0)
virBufferEscapeString(buf, "<driver type='%s'/>\n",
virStorageFileFormatTypeToString(disk->src->format));
if (virDomainDiskSourceFormat(buf, disk->src, 0, false, 0, xmlopt) < 0)
if (virDomainDiskSourceFormat(buf, disk->src, "source", 0, false, 0,
xmlopt) < 0)
return -1;
virBufferAdjustIndent(buf, -2);

View File

@ -2360,7 +2360,7 @@ qemuDomainObjPrivateXMLFormatNBDMigrationSource(virBufferPtr buf,
virStorageTypeToString(src->type),
virStorageFileFormatTypeToString(src->format));
if (virDomainDiskSourceFormat(&childBuf, src, 0, false,
if (virDomainDiskSourceFormat(&childBuf, src, "source", 0, false,
VIR_DOMAIN_DEF_FORMAT_STATUS, xmlopt) < 0)
goto cleanup;

View File

@ -86,7 +86,8 @@ testBackingXMLjsonXML(const void *args)
return -1;
}
if (virDomainDiskSourceFormat(&buf, jsonsrc, 0, false, 0, NULL) < 0 ||
if (virDomainDiskSourceFormat(&buf, jsonsrc, "source", 0, false, 0,
NULL) < 0 ||
!(actualxml = virBufferContentAndReset(&buf))) {
fprintf(stderr, "failed to format disk source xml\n");
return -1;

View File

@ -627,7 +627,7 @@ testBackingParse(const void *args)
goto cleanup;
}
if (virDomainDiskSourceFormat(&buf, src, 0, false, 0, NULL) < 0 ||
if (virDomainDiskSourceFormat(&buf, src, "source", 0, false, 0, NULL) < 0 ||
!(xml = virBufferContentAndReset(&buf))) {
fprintf(stderr, "failed to format disk source xml\n");
goto cleanup;