[libvirt] [PATCH v8 10/21] conf: Add parameter to virDomainDiskSourceFormat

Eric Blake eblake at redhat.com
Wed Apr 17 14:09:10 UTC 2019


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 at redhat.com>
---
 src/conf/domain_conf.h   |  1 +
 src/conf/domain_conf.c   | 14 +++++++++-----
 src/conf/snapshot_conf.c |  3 ++-
 src/qemu/qemu_domain.c   |  2 +-
 tests/qemublocktest.c    |  3 ++-
 tests/virstoragetest.c   |  2 +-
 6 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 1ef72f79d8..456da9ec7e 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -3059,6 +3059,7 @@ int virDomainDefFormatInternal(virDomainDefPtr def,

 int virDomainDiskSourceFormat(virBufferPtr buf,
                               virStorageSourcePtr src,
+                              const char *element,
                               int policy,
                               bool attrIndex,
                               unsigned int flags,
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 1dc552b7f2..36f60fd54a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -23934,6 +23934,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
@@ -23945,6 +23946,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr buf,
 int
 virDomainDiskSourceFormat(virBufferPtr buf,
                           virStorageSourcePtr src,
+                          const char *element,
                           int policy,
                           bool attrIndex,
                           unsigned int flags,
@@ -24025,7 +24027,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;
@@ -24071,7 +24073,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)
@@ -24234,7 +24237,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)
@@ -24334,8 +24338,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
diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c
index 36c328f692..eaa9b3c5e6 100644
--- a/src/conf/snapshot_conf.c
+++ b/src/conf/snapshot_conf.c
@@ -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);
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 960aaff3c7..db67fe2193 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -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;

diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c
index c221b8af30..21db3e4881 100644
--- a/tests/qemublocktest.c
+++ b/tests/qemublocktest.c
@@ -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;
diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index 4f23511240..ef16b3c6e0 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -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;
-- 
2.20.1




More information about the libvir-list mailing list