]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
Allow cloning volumes with no capacity specified
authorJán Tomko <jtomko@redhat.com>
Tue, 17 Feb 2015 15:54:53 +0000 (16:54 +0100)
committerJán Tomko <jtomko@redhat.com>
Mon, 2 Mar 2015 07:07:11 +0000 (08:07 +0100)
In virStorageVolCreateXML, add VIR_VOL_XML_PARSE_NO_CAPACITY
to the call parsing the XML of the new volume to make the capacity
optional.

If the capacity is omitted, use the capacity of the old volume.
We already do that for values that are less than the original
volume capacity.

src/storage/storage_driver.c
tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv [new file with mode: 0644]
tests/storagevolxml2argvtest.c
tests/storagevolxml2xmlin/vol-qcow2-nocapacity.xml [new file with mode: 0644]
tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml [new file with mode: 0644]
tests/storagevolxml2xmltest.c

index bc16e87c6ba667ee4a010d1249d9ebd946d7000c..6e51603d10656905ed68f62a7fd20591fd9ecb6c 100644 (file)
@@ -1810,7 +1810,8 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
         goto cleanup;
     }
 
-    newvol = virStorageVolDefParseString(pool->def, xmldesc, 0);
+    newvol = virStorageVolDefParseString(pool->def, xmldesc,
+                                         VIR_VOL_XML_PARSE_NO_CAPACITY);
     if (newvol == NULL)
         goto cleanup;
 
@@ -1824,7 +1825,8 @@ storageVolCreateXMLFrom(virStoragePoolPtr obj,
         goto cleanup;
     }
 
-    /* Is there ever a valid case for this? */
+    /* Use the original volume's capacity in case the new capacity
+     * is less than that, or it was omitted */
     if (newvol->target.capacity < origvol->target.capacity)
         newvol->target.capacity = origvol->target.capacity;
 
diff --git a/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv b/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv
new file mode 100644 (file)
index 0000000..9073b1b
--- /dev/null
@@ -0,0 +1,4 @@
+qemu-img convert -f raw -O qcow2 \
+-o encryption=on,preallocation=metadata \
+/var/lib/libvirt/images/sparse.img \
+/var/lib/libvirt/images/OtherDemo.img
index c1f8a9d46e85ec582b346e6ab2a0979be3365c8d..52bb85625dcae9b46d5199ae8fc11ae62ff7a028 100644 (file)
@@ -49,6 +49,7 @@ testCompareXMLToArgvFiles(bool shouldFail,
     char *expectedCmdline = NULL;
     char *actualCmdline = NULL;
     int ret = -1;
+    unsigned long parse_flags = 0;
 
     int len;
 
@@ -84,7 +85,10 @@ testCompareXMLToArgvFiles(bool shouldFail,
             goto cleanup;
     }
 
-    if (!(vol = virStorageVolDefParseString(pool, volXmlData, 0)))
+    if (inputvolxml)
+        parse_flags |= VIR_VOL_XML_PARSE_NO_CAPACITY;
+
+    if (!(vol = virStorageVolDefParseString(pool, volXmlData, parse_flags)))
         goto cleanup;
 
     if (inputvolxml &&
@@ -305,6 +309,9 @@ mymain(void)
     DO_TEST("pool-dir", "vol-qcow2-nocow",
             NULL, NULL,
             "qcow2-nocow-compat", 0, FMT_COMPAT);
+    DO_TEST("pool-dir", "vol-qcow2-nocapacity",
+            "pool-dir", "vol-file",
+            "qcow2-nocapacity-convert-prealloc", flags, FMT_OPTIONS);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
diff --git a/tests/storagevolxml2xmlin/vol-qcow2-nocapacity.xml b/tests/storagevolxml2xmlin/vol-qcow2-nocapacity.xml
new file mode 100644 (file)
index 0000000..9746900
--- /dev/null
@@ -0,0 +1,19 @@
+<volume>
+  <name>OtherDemo.img</name>
+  <key>/var/lib/libvirt/images/OtherDemo.img</key>
+  <source>
+  </source>
+  <target>
+    <path>/var/lib/libvirt/images/OtherDemo.img</path>
+    <format type='qcow2'/>
+    <permissions>
+      <mode>0644</mode>
+      <owner>0</owner>
+      <group>0</group>
+      <label>unconfined_u:object_r:virt_image_t:s0</label>
+    </permissions>
+    <encryption format='qcow'>
+      <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
+    </encryption>
+  </target>
+</volume>
diff --git a/tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml b/tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml
new file mode 100644 (file)
index 0000000..223e689
--- /dev/null
@@ -0,0 +1,21 @@
+<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>
+    <path>/var/lib/libvirt/images/OtherDemo.img</path>
+    <format type='qcow2'/>
+    <permissions>
+      <mode>0644</mode>
+      <owner>0</owner>
+      <group>0</group>
+      <label>unconfined_u:object_r:virt_image_t:s0</label>
+    </permissions>
+    <encryption format='qcow'>
+      <secret type='passphrase' uuid='e78d4b51-a2af-485f-b0f5-afca709a80f4'/>
+    </encryption>
+  </target>
+</volume>
index 5deb62c55e3cb74dd4de178490069fd9d866913f..0d6c818e0d83fc5c6c163bf99de96e17b7277edb 100644 (file)
@@ -126,6 +126,8 @@ mymain(void)
     DO_TEST("pool-sheepdog", "vol-sheepdog");
     DO_TEST("pool-gluster", "vol-gluster-dir");
     DO_TEST("pool-gluster", "vol-gluster-dir-neg-uid");
+    DO_TEST_FULL("pool-dir", "vol-qcow2-nocapacity",
+                 VIR_VOL_XML_PARSE_NO_CAPACITY);
 
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }