]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Allow for inputvol to have any format for encryption
authorJohn Ferlan <jferlan@redhat.com>
Tue, 21 Aug 2018 13:53:12 +0000 (09:53 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 12 Sep 2018 11:24:04 +0000 (07:24 -0400)
Commit 39cef12a9 altered/fixed the inputvol processing to create
a multistep process when using an inputvol to create an encrypted
output volume; however, it unnecessarily assumed/restricted the
inputvol to be of 'raw' format only.

Modify the processing code to allow the inputvol format to be checked
and used in order to create the encrypted volume.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
src/storage/storage_util.c
tests/storagevolxml2argvdata/luks-convert-qcow2.argv [new file with mode: 0644]
tests/storagevolxml2argvtest.c
tests/storagevolxml2xmlin/vol-file-qcow2.xml [new file with mode: 0644]

index 86d18add586cabf473198ad0b862a8489f34f375..92d5c09a90609d2f8be5447e0ba9ff7ae467ba1e 100644 (file)
@@ -699,6 +699,7 @@ storagePloopResize(virStorageVolDefPtr vol,
 struct _virStorageBackendQemuImgInfo {
     int format;
     const char *type;
+    const char *inputType;
     const char *path;
     unsigned long long size_arg;
     unsigned long long allocation;
@@ -1021,6 +1022,15 @@ virStorageBackendCreateQemuImgSetInfo(virStoragePoolObjPtr pool,
         return -1;
     }
 
+    if (inputvol &&
+        !(info->inputType =
+          virStorageFileFormatTypeToString(inputvol->target.format))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("unknown inputvol storage vol type %d"),
+                       inputvol->target.format);
+        return -1;
+    }
+
     if (info->preallocate && info->format != VIR_STORAGE_FILE_QCOW2) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("metadata preallocation only available with qcow2"));
@@ -1080,6 +1090,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
     struct _virStorageBackendQemuImgInfo info = {
         .format = vol->target.format,
         .type = NULL,
+        .inputType = NULL,
         .path = vol->target.path,
         .allocation = vol->target.allocation,
         .encryption = !!vol->target.encryption,
@@ -1152,7 +1163,8 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
             virCommandAddArgFormat(cmd, "%lluK", info.size_arg);
     } else {
         /* source */
-        virCommandAddArgFormat(cmd, "driver=raw,file.filename=%s",
+        virCommandAddArgFormat(cmd, "driver=%s,file.filename=%s",
+                               info.inputType ? info.inputType : "raw",
                                info.inputPath);
 
         /* dest */
diff --git a/tests/storagevolxml2argvdata/luks-convert-qcow2.argv b/tests/storagevolxml2argvdata/luks-convert-qcow2.argv
new file mode 100644 (file)
index 0000000..9124f5f
--- /dev/null
@@ -0,0 +1,9 @@
+qemu-img create -f luks \
+--object secret,id=OtherDemo.img_encrypt0,file=/path/to/secretFile \
+-o key-secret=OtherDemo.img_encrypt0 \
+/var/lib/libvirt/images/OtherDemo.img 5242880K
+qemu-img convert --image-opts -n --target-image-opts \
+--object secret,id=OtherDemo.img_encrypt0,file=/path/to/secretFile \
+driver=qcow2,file.filename=/var/lib/libvirt/images/sparse-qcow2.img \
+driver=luks,file.filename=/var/lib/libvirt/images/OtherDemo.img,\
+key-secret=OtherDemo.img_encrypt0
index b795f83aee759d68dd5a21892bd416e70a87505b..6a9a080dd1ce513a3c31939bc571b73cd2be4880 100644 (file)
@@ -284,6 +284,10 @@ mymain(void)
             "pool-dir", "vol-file",
             "luks-convert", 0);
 
+    DO_TEST("pool-dir", "vol-luks-convert",
+            "pool-dir", "vol-file-qcow2",
+            "luks-convert-qcow2", 0);
+
     return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 
diff --git a/tests/storagevolxml2xmlin/vol-file-qcow2.xml b/tests/storagevolxml2xmlin/vol-file-qcow2.xml
new file mode 100644 (file)
index 0000000..025e7e0
--- /dev/null
@@ -0,0 +1,21 @@
+<volume>
+  <name>sparse-qcow2.img</name>
+  <source/>
+  <capacity unit="TiB">1</capacity>
+  <allocation unit="bytes">0</allocation>
+  <target>
+    <path>/var/lib/libvirt/images/sparse-qcow2.img</path>
+    <format type="qcow2"/>
+    <permissions>
+      <mode>0</mode>
+      <owner>0744</owner>
+      <group>0</group>
+      <label>virt_image_t</label>
+    </permissions>
+    <timestamps>
+      <atime>1341933637.273190990</atime>
+      <mtime>1341930622.047245868</mtime>
+      <ctime>1341930622.047245868</ctime>
+    </timestamps>
+  </target>
+</volume>