[libvirt] [PATCH 4/9] Allow cloning volumes with no capacity specified

Ján Tomko jtomko at redhat.com
Thu Feb 19 14:59:12 UTC 2015


We can get the capacity from the input volume.
---
 src/storage/storage_backend.c                       |  2 +-
 src/storage/storage_driver.c                        |  3 ++-
 .../qcow2-nocapacity-convert-prealloc.argv          |  4 ++++
 tests/storagevolxml2argvtest.c                      |  9 ++++++++-
 tests/storagevolxml2xmlin/vol-qcow2-nocapacity.xml  | 19 +++++++++++++++++++
 tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml | 21 +++++++++++++++++++++
 tests/storagevolxml2xmltest.c                       |  2 ++
 7 files changed, 57 insertions(+), 3 deletions(-)
 create mode 100644 tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv
 create mode 100644 tests/storagevolxml2xmlin/vol-qcow2-nocapacity.xml
 create mode 100644 tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index a67d50c..dd33436 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1055,7 +1055,7 @@ virStorageBackendCreateQemuImgCmd(virConnectPtr conn,
     if (convert)
         virCommandAddArg(cmd, inputPath);
     virCommandAddArg(cmd, vol->target.path);
-    if (!convert)
+    if (!convert && size_arg)
         virCommandAddArgFormat(cmd, "%lluK", size_arg);
 
     return cmd;
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index bc16e87..409b486 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -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;
 
diff --git a/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv b/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv
new file mode 100644
index 0000000..9073b1b
--- /dev/null
+++ b/tests/storagevolxml2argvdata/qcow2-nocapacity-convert-prealloc.argv
@@ -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
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
index c1f8a9d..52bb856 100644
--- a/tests/storagevolxml2argvtest.c
+++ b/tests/storagevolxml2argvtest.c
@@ -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
index 0000000..9746900
--- /dev/null
+++ b/tests/storagevolxml2xmlin/vol-qcow2-nocapacity.xml
@@ -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
index 0000000..223e689
--- /dev/null
+++ b/tests/storagevolxml2xmlout/vol-qcow2-nocapacity.xml
@@ -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>
diff --git a/tests/storagevolxml2xmltest.c b/tests/storagevolxml2xmltest.c
index ee0495b..e04b4ef 100644
--- a/tests/storagevolxml2xmltest.c
+++ b/tests/storagevolxml2xmltest.c
@@ -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;
 }
-- 
2.0.5




More information about the libvir-list mailing list