]> xenbits.xensource.com Git - libvirt.git/commitdiff
virStorageVolDefFormat: Don't format empty <source>
authorPeter Krempa <pkrempa@redhat.com>
Thu, 25 Feb 2021 13:11:05 +0000 (14:11 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 1 Mar 2021 14:44:47 +0000 (15:44 +0100)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
21 files changed:
src/conf/storage_conf.c
tests/storagevolxml2xmlout/vol-file-backing.xml
tests/storagevolxml2xmlout/vol-file-iso.xml
tests/storagevolxml2xmlout/vol-file-naming.xml
tests/storagevolxml2xmlout/vol-file.xml
tests/storagevolxml2xmlout/vol-gluster-dir-neg-uid.xml
tests/storagevolxml2xmlout/vol-gluster-dir.xml
tests/storagevolxml2xmlout/vol-logical-backing.xml
tests/storagevolxml2xmlout/vol-logical.xml
tests/storagevolxml2xmlout/vol-luks-cipher.xml
tests/storagevolxml2xmlout/vol-luks.xml
tests/storagevolxml2xmlout/vol-partition.xml
tests/storagevolxml2xmlout/vol-qcow2-0.10-lazy.xml
tests/storagevolxml2xmlout/vol-qcow2-1.1.xml
tests/storagevolxml2xmlout/vol-qcow2-encryption.xml
tests/storagevolxml2xmlout/vol-qcow2-lazy.xml
tests/storagevolxml2xmlout/vol-qcow2-luks.xml
tests/storagevolxml2xmlout/vol-qcow2-nobacking.xml
tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml
tests/storagevolxml2xmlout/vol-qcow2.xml
tests/storagevolxml2xmlout/vol-sheepdog.xml

index fa3454750ce4a7143d7df44ab5f57044ccc7150c..2e07c81f8ad3cdb54aa9f378e062ba1b51a58907 100644 (file)
@@ -1678,6 +1678,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)
@@ -1689,14 +1690,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);
index cd33bee523ea381df6cc9cdac726b9da3a360448..e4180a8a00e8611f80d7ed106fc425ed1a9f0551 100644 (file)
@@ -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>
index 9783124b340f7bc8a343f9cba6cba25162bd7d6e..955bafd453643d7f3dae41d9c860ebb7f344b8dd 100644 (file)
@@ -1,7 +1,5 @@
 <volume type='file'>
   <name>test.iso</name>
-  <source>
-  </source>
   <capacity unit='bytes'>1048576</capacity>
   <allocation unit='bytes'>1048576</allocation>
   <target>
index e515502af163ac68eae6be58ec249a36016b6266..d1b1c1d2ba6a8c36904810d7b61c349ae37ef2da 100644 (file)
@@ -1,7 +1,5 @@
 <volume type='file'>
   <name>&lt;sparse&gt;.img</name>
-  <source>
-  </source>
   <capacity unit='bytes'>1099511627776</capacity>
   <allocation unit='bytes'>0</allocation>
   <target>
index 2923188e656c17e61e21c47df37ab09c8c1e0f2c..884cf7379708eb26200763337951d5d268e432cb 100644 (file)
@@ -1,7 +1,5 @@
 <volume type='file'>
   <name>sparse.img</name>
-  <source>
-  </source>
   <capacity unit='bytes'>1099511627776</capacity>
   <allocation unit='bytes'>0</allocation>
   <target>
index 0af0be179d5ba75071ba98869588efabbed9d1c5..8dd0f7472feea489ddd3d5aa5c25bce7a16da8f0 100644 (file)
@@ -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>
index d4222489ec80c6065eefa33578f2d7218c2f316b..fa01f989380f053f119dc6afd9f1e097f7bee304 100644 (file)
@@ -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>
index 07fe27767d0f86b57900d0b8713592af1a37dd73..7200f32f7f4769ebff9525900e6cfad144c9226e 100644 (file)
@@ -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>
index 0df5cc0864848418ceca9a1978857a91a3963c5b..ddaf0e24f51f8a9ab518115a10cebc6aa8fa82b3 100644 (file)
@@ -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>
index 2b58850aaf708118e6d20ee148a0dbf71e244df2..fd99793612f7da9d41bc4b9ab9672c4e163ff653 100644 (file)
@@ -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>
index 599b3c5c4d6dc11b8e3be19e849267158b845094..c011d4cc6296b28402dba5ca9a9305965c4a5893 100644 (file)
@@ -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>
index 147899edb1e160a3c13dab7c6ef66c9629b78306..dd9793fbb401c5bad566fb88e0326fe2a590d954 100644 (file)
@@ -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>
index 9b666ad5bc0a6ba4e98f61a528a2d347083404c4..afcd330e2dca035f2f3e112a08f91715ce25ebc7 100644 (file)
@@ -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>
index c033f5bd57eae37c463d27b6de1acc3385500528..634b0a409a1f5b5ca14c29c7f8c72143d6754327 100644 (file)
@@ -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>
index 31dc57873c9dfa062a6c160d6122073a61fa53e6..837adf41b137d293d703a70e74341d4afe66fcc2 100644 (file)
@@ -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>
index ee79e26050ff830ba32fd7aeb29e1b08712b7b3d..fc6b7542d827d07a116cd32353bbd0241d08d3d8 100644 (file)
@@ -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>
index 2e2b7ce12546541ef08005aa562c312ca8747ddb..78edc4239ce75297c266153a172e98e77f3006aa 100644 (file)
@@ -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>
index e8281e3b5065149bc17fcc4c70e729ac3caf5f91..7600e25cc19d49e93e26cf50c9726bd483d293d8 100644 (file)
@@ -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>
index dbf9003213b4217affa26de8953d7e6ef179d208..a83adb817688f37ba62be134fa65af0ba6fbe698 100644 (file)
@@ -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>
index a7d612135f6d2d401a5ee728cec637857726ab51..8c942d4b78470f7d6dd0fb50190038c7a44b8cbf 100644 (file)
@@ -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>
index d6e920bb8101c07d0c4ccb1c9e7709b51bb61903..47fb8eb418723ac89a3d11f7973e1705a02b5942 100644 (file)
@@ -1,7 +1,5 @@
 <volume type='network'>
   <name>test2</name>
-  <source>
-  </source>
   <capacity unit='bytes'>1024</capacity>
   <allocation unit='bytes'>0</allocation>
   <target>