Move the recursion to format the full backing store into
virDomainDiskSourceFormat controlled by a new argument so that it's
simpler to reuse in other places.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/domain_conf.c | 30 +++++++++++++++---------------
src/conf/domain_conf.h | 1 +
src/conf/snapshot_conf.c | 2 +-
tests/qemublocktest.c | 2 +-
tests/virstoragetest.c | 2 +-
5 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9d738f06cd..b67f9bbd2c 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23897,11 +23897,7 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf,
virStorageFileFormatTypeToString(backingStore->format));
/* We currently don't output seclabels for backing chain element */
if (virDomainDiskSourceFormat(&childBuf, backingStore, 0, flags, false,
- false, xmlopt) < 0)
- return -1;
-
- if (virDomainDiskBackingStoreFormat(&childBuf, backingStore->backingStore,
- xmlopt, flags) < 0)
+ false, true, xmlopt) < 0)
return -1;
return virXMLFormatElement(buf, "backingStore", &attrBuf,
&childBuf);
@@ -23954,6 +23950,7 @@ virDomainDiskSourceFormat(virBufferPtr buf,
unsigned int flags,
bool seclabels,
bool attrIndex,
+ bool backingStore,
virDomainXMLOptionPtr xmlopt)
{
VIR_AUTOCLEAN(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
@@ -23962,10 +23959,18 @@ virDomainDiskSourceFormat(virBufferPtr buf,
virBufferSetChildIndent(&childBuf, buf);
if (virDomainStorageSourceFormat(&attrBuf, &childBuf, src, flags,
- seclabels, attrIndex, policy, xmlopt) < 0)
+ seclabels, attrIndex,
+ policy, xmlopt) < 0)
return -1;
- return virXMLFormatElement(buf, "source", &attrBuf, &childBuf);
+ if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) <
0)
+ return -1;
+
+ if (backingStore && src->backingStore &&
+ virDomainDiskBackingStoreFormat(buf, src->backingStore, xmlopt, flags) <
0)
+ return -1;
+
+ return 0;
}
@@ -24119,7 +24124,8 @@ virDomainDiskDefFormatMirror(virBufferPtr buf,
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2);
virBufferEscapeString(buf, "<format type='%s'/>\n",
formatStr);
- if (virDomainDiskSourceFormat(buf, disk->mirror, 0, 0, true, false, xmlopt) <
0)
+ if (virDomainDiskSourceFormat(buf, disk->mirror, 0, 0, true, false, false,
+ xmlopt) < 0)
return -1;
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</mirror>\n");
@@ -24216,13 +24222,7 @@ virDomainDiskDefFormat(virBufferPtr buf,
virStorageAuthDefFormat(buf, def->src->auth);
if (virDomainDiskSourceFormat(buf, def->src, def->startupPolicy,
- flags, true, true, xmlopt) < 0)
- return -1;
-
- /* Don't format backingStore to inactive XMLs until the code for
- * persistent storage of backing chains is ready. */
- if (virDomainDiskBackingStoreFormat(buf, def->src->backingStore,
- xmlopt, flags) < 0)
+ flags, true, true, true, xmlopt) < 0)
return -1;
virBufferEscapeString(buf, "<backenddomain name='%s'/>\n",
def->domain_name);
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 7ea9822fe4..b373dbf939 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3018,6 +3018,7 @@ int virDomainDiskSourceFormat(virBufferPtr buf,
unsigned int flags,
bool seclabels,
bool attrIndex,
+ bool backingStore,
virDomainXMLOptionPtr xmlopt);
int virDomainNetDefFormat(virBufferPtr buf,
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index a849a58da3..bc4b9c8f11 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -768,7 +768,7 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf,
if (disk->src->format > 0)
virBufferEscapeString(buf, "<driver type='%s'/>\n",
virStorageFileFormatTypeToString(disk->src->format));
- if (virDomainDiskSourceFormat(buf, disk->src, 0, 0, true, false, xmlopt) < 0)
+ if (virDomainDiskSourceFormat(buf, disk->src, 0, 0, true, false, false, xmlopt)
< 0)
return -1;
virBufferAdjustIndent(buf, -2);
diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index 6b5571b7cb..f40cba36cd 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -87,7 +87,7 @@ testBackingXMLjsonXML(const void *args)
goto cleanup;
}
- if (virDomainDiskSourceFormat(&buf, jsonsrc, 0, 0, true, false, NULL) < 0 ||
+ if (virDomainDiskSourceFormat(&buf, jsonsrc, 0, 0, true, false, false, NULL) <
0 ||
!(actualxml = virBufferContentAndReset(&buf))) {
fprintf(stderr, "failed to format disk source xml\n");
goto cleanup;
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 75c60da537..9a11f5bfe8 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -657,7 +657,7 @@ testBackingParse(const void *args)
goto cleanup;
}
- if (virDomainDiskSourceFormat(&buf, src, 0, 0, true, false, NULL) < 0 ||
+ if (virDomainDiskSourceFormat(&buf, src, 0, 0, true, false, false, NULL) < 0
||
!(xml = virBufferContentAndReset(&buf))) {
fprintf(stderr, "failed to format disk source xml\n");
goto cleanup;
--
2.20.1