If there are no source extents the volume XML has an empty <source>
element. Remove it if there's nothing in it by using
virXMLFormatElement.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/conf/storage_conf.c | 10 +++++-----
tests/storagevolxml2xmlout/vol-file-backing.xml | 2 --
tests/storagevolxml2xmlout/vol-file-iso.xml | 2 --
tests/storagevolxml2xmlout/vol-file-naming.xml | 2 --
tests/storagevolxml2xmlout/vol-file.xml | 2 --
tests/storagevolxml2xmlout/vol-gluster-dir-neg-uid.xml | 2 --
tests/storagevolxml2xmlout/vol-gluster-dir.xml | 2 --
tests/storagevolxml2xmlout/vol-logical-backing.xml | 2 --
tests/storagevolxml2xmlout/vol-logical.xml | 2 --
tests/storagevolxml2xmlout/vol-luks-cipher.xml | 2 --
tests/storagevolxml2xmlout/vol-luks.xml | 2 --
tests/storagevolxml2xmlout/vol-partition.xml | 2 --
tests/storagevolxml2xmlout/vol-qcow2-0.10-lazy.xml | 2 --
tests/storagevolxml2xmlout/vol-qcow2-1.1.xml | 2 --
tests/storagevolxml2xmlout/vol-qcow2-encryption.xml | 2 --
tests/storagevolxml2xmlout/vol-qcow2-lazy.xml | 2 --
tests/storagevolxml2xmlout/vol-qcow2-luks.xml | 2 --
tests/storagevolxml2xmlout/vol-qcow2-nobacking.xml | 2 --
tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml | 2 --
tests/storagevolxml2xmlout/vol-qcow2.xml | 2 --
tests/storagevolxml2xmlout/vol-sheepdog.xml | 2 --
21 files changed, 5 insertions(+), 45 deletions(-)
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index 1bc27ff194..c840bc4b4f 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -1677,6 +1677,7 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
{
virStorageVolOptionsPtr options;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
+ g_auto(virBuffer) sourceChildBuf = VIR_BUFFER_INITIALIZER;
options = virStorageVolOptionsForPoolType(pool->type);
if (options == NULL)
@@ -1688,14 +1689,13 @@ virStorageVolDefFormat(virStoragePoolDefPtr pool,
virBufferEscapeString(&buf, "<name>%s</name>\n",
def->name);
virBufferEscapeString(&buf, "<key>%s</key>\n",
def->key);
- virBufferAddLit(&buf, "<source>\n");
- virBufferAdjustIndent(&buf, 2);
+
+ virBufferSetIndent(&sourceChildBuf, virBufferGetIndent(&buf) + 2);
if (def->source.nextent)
- virStorageVolDefFormatSourceExtents(&buf, def);
+ virStorageVolDefFormatSourceExtents(&sourceChildBuf, def);
- virBufferAdjustIndent(&buf, -2);
- virBufferAddLit(&buf, "</source>\n");
+ virXMLFormatElement(&buf, "source", NULL, &sourceChildBuf);
virBufferAsprintf(&buf, "<capacity
unit='bytes'>%llu</capacity>\n",
def->target.capacity);
diff --git a/tests/storagevolxml2xmlout/vol-file-backing.xml
b/tests/storagevolxml2xmlout/vol-file-backing.xml
index cd33bee523..e4180a8a00 100644
--- a/tests/storagevolxml2xmlout/vol-file-backing.xml
+++ b/tests/storagevolxml2xmlout/vol-file-backing.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>sparse.img</name>
<key>/var/lib/libvirt/images/sparse.img</key>
- <source>
- </source>
<capacity unit='bytes'>10000000000</capacity>
<allocation unit='bytes'>0</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-file-iso.xml
b/tests/storagevolxml2xmlout/vol-file-iso.xml
index 9783124b34..955bafd453 100644
--- a/tests/storagevolxml2xmlout/vol-file-iso.xml
+++ b/tests/storagevolxml2xmlout/vol-file-iso.xml
@@ -1,7 +1,5 @@
<volume type='file'>
<name>test.iso</name>
- <source>
- </source>
<capacity unit='bytes'>1048576</capacity>
<allocation unit='bytes'>1048576</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-file-naming.xml
b/tests/storagevolxml2xmlout/vol-file-naming.xml
index e515502af1..d1b1c1d2ba 100644
--- a/tests/storagevolxml2xmlout/vol-file-naming.xml
+++ b/tests/storagevolxml2xmlout/vol-file-naming.xml
@@ -1,7 +1,5 @@
<volume type='file'>
<name><sparse>.img</name>
- <source>
- </source>
<capacity unit='bytes'>1099511627776</capacity>
<allocation unit='bytes'>0</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-file.xml
b/tests/storagevolxml2xmlout/vol-file.xml
index 2923188e65..884cf73797 100644
--- a/tests/storagevolxml2xmlout/vol-file.xml
+++ b/tests/storagevolxml2xmlout/vol-file.xml
@@ -1,7 +1,5 @@
<volume type='file'>
<name>sparse.img</name>
- <source>
- </source>
<capacity unit='bytes'>1099511627776</capacity>
<allocation unit='bytes'>0</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-gluster-dir-neg-uid.xml
b/tests/storagevolxml2xmlout/vol-gluster-dir-neg-uid.xml
index 0af0be179d..8dd0f7472f 100644
--- a/tests/storagevolxml2xmlout/vol-gluster-dir-neg-uid.xml
+++ b/tests/storagevolxml2xmlout/vol-gluster-dir-neg-uid.xml
@@ -1,8 +1,6 @@
<volume type='netdir'>
<name>dir</name>
<key>vol/dir</key>
- <source>
- </source>
<capacity unit='bytes'>0</capacity>
<allocation unit='bytes'>0</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-gluster-dir.xml
b/tests/storagevolxml2xmlout/vol-gluster-dir.xml
index d4222489ec..fa01f98938 100644
--- a/tests/storagevolxml2xmlout/vol-gluster-dir.xml
+++ b/tests/storagevolxml2xmlout/vol-gluster-dir.xml
@@ -1,8 +1,6 @@
<volume type='netdir'>
<name>dir</name>
<key>vol/dir</key>
- <source>
- </source>
<capacity unit='bytes'>0</capacity>
<allocation unit='bytes'>0</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-logical-backing.xml
b/tests/storagevolxml2xmlout/vol-logical-backing.xml
index 07fe27767d..7200f32f7f 100644
--- a/tests/storagevolxml2xmlout/vol-logical-backing.xml
+++ b/tests/storagevolxml2xmlout/vol-logical-backing.xml
@@ -1,8 +1,6 @@
<volume type='block'>
<name>Swap</name>
<key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
- <source>
- </source>
<capacity unit='bytes'>2080374784</capacity>
<allocation unit='bytes'>2080374784</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-logical.xml
b/tests/storagevolxml2xmlout/vol-logical.xml
index 0df5cc0864..ddaf0e24f5 100644
--- a/tests/storagevolxml2xmlout/vol-logical.xml
+++ b/tests/storagevolxml2xmlout/vol-logical.xml
@@ -1,8 +1,6 @@
<volume type='block'>
<name>Swap</name>
<key>r4xkCv-MQhr-WKIT-R66x-Epn2-e8hG-1Z5gY0</key>
- <source>
- </source>
<capacity unit='bytes'>2080374784</capacity>
<allocation unit='bytes'>2080374784</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-luks-cipher.xml
b/tests/storagevolxml2xmlout/vol-luks-cipher.xml
index 2b58850aaf..fd99793612 100644
--- a/tests/storagevolxml2xmlout/vol-luks-cipher.xml
+++ b/tests/storagevolxml2xmlout/vol-luks-cipher.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>LuksDemo.img</name>
<key>/var/lib/libvirt/images/LuksDemo.img</key>
- <source>
- </source>
<capacity unit='bytes'>5368709120</capacity>
<allocation unit='bytes'>294912</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-luks.xml
b/tests/storagevolxml2xmlout/vol-luks.xml
index 599b3c5c4d..c011d4cc62 100644
--- a/tests/storagevolxml2xmlout/vol-luks.xml
+++ b/tests/storagevolxml2xmlout/vol-luks.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>LuksDemo.img</name>
<key>/var/lib/libvirt/images/LuksDemo.img</key>
- <source>
- </source>
<capacity unit='bytes'>5368709120</capacity>
<allocation unit='bytes'>294912</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-partition.xml
b/tests/storagevolxml2xmlout/vol-partition.xml
index 147899edb1..dd9793fbb4 100644
--- a/tests/storagevolxml2xmlout/vol-partition.xml
+++ b/tests/storagevolxml2xmlout/vol-partition.xml
@@ -1,8 +1,6 @@
<volume type='block'>
<name>sda1</name>
<key>/dev/sda1</key>
- <source>
- </source>
<capacity unit='bytes'>106896384</capacity>
<allocation unit='bytes'>106896384</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-qcow2-0.10-lazy.xml
b/tests/storagevolxml2xmlout/vol-qcow2-0.10-lazy.xml
index 9b666ad5bc..afcd330e2d 100644
--- a/tests/storagevolxml2xmlout/vol-qcow2-0.10-lazy.xml
+++ b/tests/storagevolxml2xmlout/vol-qcow2-0.10-lazy.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>OtherDemo.img</name>
<key>/var/lib/libvirt/images/OtherDemo.img</key>
- <source>
- </source>
<capacity unit='bytes'>5368709120</capacity>
<allocation unit='bytes'>294912</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-qcow2-1.1.xml
b/tests/storagevolxml2xmlout/vol-qcow2-1.1.xml
index c033f5bd57..634b0a409a 100644
--- a/tests/storagevolxml2xmlout/vol-qcow2-1.1.xml
+++ b/tests/storagevolxml2xmlout/vol-qcow2-1.1.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>OtherDemo.img</name>
<key>/var/lib/libvirt/images/OtherDemo.img</key>
- <source>
- </source>
<capacity unit='bytes'>5368709120</capacity>
<allocation unit='bytes'>294912</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-qcow2-encryption.xml
b/tests/storagevolxml2xmlout/vol-qcow2-encryption.xml
index 31dc57873c..837adf41b1 100644
--- a/tests/storagevolxml2xmlout/vol-qcow2-encryption.xml
+++ b/tests/storagevolxml2xmlout/vol-qcow2-encryption.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>OtherDemo.img</name>
<key>/var/lib/libvirt/images/OtherDemo.img</key>
- <source>
- </source>
<capacity unit='bytes'>5368709120</capacity>
<allocation unit='bytes'>294912</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-qcow2-lazy.xml
b/tests/storagevolxml2xmlout/vol-qcow2-lazy.xml
index ee79e26050..fc6b7542d8 100644
--- a/tests/storagevolxml2xmlout/vol-qcow2-lazy.xml
+++ b/tests/storagevolxml2xmlout/vol-qcow2-lazy.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>OtherDemo.img</name>
<key>/var/lib/libvirt/images/OtherDemo.img</key>
- <source>
- </source>
<capacity unit='bytes'>5368709120</capacity>
<allocation unit='bytes'>294912</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-qcow2-luks.xml
b/tests/storagevolxml2xmlout/vol-qcow2-luks.xml
index 2e2b7ce125..78edc4239c 100644
--- a/tests/storagevolxml2xmlout/vol-qcow2-luks.xml
+++ b/tests/storagevolxml2xmlout/vol-qcow2-luks.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>OtherDemoLuks.img</name>
<key>/var/lib/libvirt/images/OtherDemoLuks.img</key>
- <source>
- </source>
<capacity unit='bytes'>5368709120</capacity>
<allocation unit='bytes'>294912</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-qcow2-nobacking.xml
b/tests/storagevolxml2xmlout/vol-qcow2-nobacking.xml
index e8281e3b50..7600e25cc1 100644
--- a/tests/storagevolxml2xmlout/vol-qcow2-nobacking.xml
+++ b/tests/storagevolxml2xmlout/vol-qcow2-nobacking.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>OtherDemo.img</name>
<key>/var/lib/libvirt/images/OtherDemo.img</key>
- <source>
- </source>
<capacity unit='bytes'>5368709120</capacity>
<allocation unit='bytes'>294912</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml
b/tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml
index dbf9003213..a83adb8176 100644
--- a/tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml
+++ b/tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>OtherDemo.img</name>
<key>/var/lib/libvirt/images/OtherDemo.img</key>
- <source>
- </source>
<capacity unit='bytes'>0</capacity>
<allocation unit='bytes'>0</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-qcow2.xml
b/tests/storagevolxml2xmlout/vol-qcow2.xml
index a7d612135f..8c942d4b78 100644
--- a/tests/storagevolxml2xmlout/vol-qcow2.xml
+++ b/tests/storagevolxml2xmlout/vol-qcow2.xml
@@ -1,8 +1,6 @@
<volume type='file'>
<name>OtherDemo.img</name>
<key>/var/lib/libvirt/images/OtherDemo.img</key>
- <source>
- </source>
<capacity unit='bytes'>5368709120</capacity>
<allocation unit='bytes'>294912</allocation>
<target>
diff --git a/tests/storagevolxml2xmlout/vol-sheepdog.xml
b/tests/storagevolxml2xmlout/vol-sheepdog.xml
index d6e920bb81..47fb8eb418 100644
--- a/tests/storagevolxml2xmlout/vol-sheepdog.xml
+++ b/tests/storagevolxml2xmlout/vol-sheepdog.xml
@@ -1,7 +1,5 @@
<volume type='network'>
<name>test2</name>
- <source>
- </source>
<capacity unit='bytes'>1024</capacity>
<allocation unit='bytes'>0</allocation>
<target>
--
2.29.2