|
|
edecca |
From fdbb929cb1f83931378f9910a2922bf9d68f0c04 Mon Sep 17 00:00:00 2001
|
|
|
edecca |
Message-Id: <fdbb929cb1f83931378f9910a2922bf9d68f0c04@dist-git>
|
|
|
edecca |
From: John Ferlan <jferlan@redhat.com>
|
|
|
edecca |
Date: Fri, 2 Nov 2018 16:57:11 +0100
|
|
|
edecca |
Subject: [PATCH] storage: Allow for inputvol to have any format for encryption
|
|
|
edecca |
|
|
|
edecca |
Commit 39cef12a9 altered/fixed the inputvol processing to create
|
|
|
edecca |
a multistep process when using an inputvol to create an encrypted
|
|
|
edecca |
output volume; however, it unnecessarily assumed/restricted the
|
|
|
edecca |
inputvol to be of 'raw' format only.
|
|
|
edecca |
|
|
|
edecca |
Modify the processing code to allow the inputvol format to be checked
|
|
|
edecca |
and used in order to create the encrypted volume.
|
|
|
edecca |
|
|
|
edecca |
Signed-off-by: John Ferlan <jferlan@redhat.com>
|
|
|
edecca |
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
edecca |
(cherry picked from commit 80414718587ab8dd97025ec9145f30fa1a3654ed)
|
|
|
edecca |
|
|
|
edecca |
https://bugzilla.redhat.com/show_bug.cgi?id=1645459
|
|
|
edecca |
|
|
|
edecca |
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
|
|
|
edecca |
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
edecca |
---
|
|
|
edecca |
src/storage/storage_util.c | 14 ++++++++++++-
|
|
|
edecca |
.../luks-convert-qcow2.argv | 9 ++++++++
|
|
|
edecca |
tests/storagevolxml2argvtest.c | 4 ++++
|
|
|
edecca |
tests/storagevolxml2xmlin/vol-file-qcow2.xml | 21 +++++++++++++++++++
|
|
|
edecca |
4 files changed, 47 insertions(+), 1 deletion(-)
|
|
|
edecca |
create mode 100644 tests/storagevolxml2argvdata/luks-convert-qcow2.argv
|
|
|
edecca |
create mode 100644 tests/storagevolxml2xmlin/vol-file-qcow2.xml
|
|
|
edecca |
|
|
|
edecca |
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
|
|
|
edecca |
index 19e58714ca..c5e773ab6d 100644
|
|
|
edecca |
--- a/src/storage/storage_util.c
|
|
|
edecca |
+++ b/src/storage/storage_util.c
|
|
|
edecca |
@@ -692,6 +692,7 @@ storagePloopResize(virStorageVolDefPtr vol,
|
|
|
edecca |
struct _virStorageBackendQemuImgInfo {
|
|
|
edecca |
int format;
|
|
|
edecca |
const char *type;
|
|
|
edecca |
+ const char *inputType;
|
|
|
edecca |
const char *path;
|
|
|
edecca |
unsigned long long size_arg;
|
|
|
edecca |
unsigned long long allocation;
|
|
|
edecca |
@@ -1014,6 +1015,15 @@ virStorageBackendCreateQemuImgSetInfo(virStoragePoolObjPtr pool,
|
|
|
edecca |
return -1;
|
|
|
edecca |
}
|
|
|
edecca |
|
|
|
edecca |
+ if (inputvol &&
|
|
|
edecca |
+ !(info->inputType =
|
|
|
edecca |
+ virStorageFileFormatTypeToString(inputvol->target.format))) {
|
|
|
edecca |
+ virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
edecca |
+ _("unknown inputvol storage vol type %d"),
|
|
|
edecca |
+ inputvol->target.format);
|
|
|
edecca |
+ return -1;
|
|
|
edecca |
+ }
|
|
|
edecca |
+
|
|
|
edecca |
if (info->preallocate && info->format != VIR_STORAGE_FILE_QCOW2) {
|
|
|
edecca |
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
edecca |
_("metadata preallocation only available with qcow2"));
|
|
|
edecca |
@@ -1073,6 +1083,7 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
|
|
|
edecca |
struct _virStorageBackendQemuImgInfo info = {
|
|
|
edecca |
.format = vol->target.format,
|
|
|
edecca |
.type = NULL,
|
|
|
edecca |
+ .inputType = NULL,
|
|
|
edecca |
.path = vol->target.path,
|
|
|
edecca |
.allocation = vol->target.allocation,
|
|
|
edecca |
.encryption = !!vol->target.encryption,
|
|
|
edecca |
@@ -1145,7 +1156,8 @@ virStorageBackendCreateQemuImgCmdFromVol(virStoragePoolObjPtr pool,
|
|
|
edecca |
virCommandAddArgFormat(cmd, "%lluK", info.size_arg);
|
|
|
edecca |
} else {
|
|
|
edecca |
/* source */
|
|
|
edecca |
- virCommandAddArgFormat(cmd, "driver=raw,file.filename=%s",
|
|
|
edecca |
+ virCommandAddArgFormat(cmd, "driver=%s,file.filename=%s",
|
|
|
edecca |
+ info.inputType ? info.inputType : "raw",
|
|
|
edecca |
info.inputPath);
|
|
|
edecca |
|
|
|
edecca |
/* dest */
|
|
|
edecca |
diff --git a/tests/storagevolxml2argvdata/luks-convert-qcow2.argv b/tests/storagevolxml2argvdata/luks-convert-qcow2.argv
|
|
|
edecca |
new file mode 100644
|
|
|
edecca |
index 0000000000..9124f5f27c
|
|
|
edecca |
--- /dev/null
|
|
|
edecca |
+++ b/tests/storagevolxml2argvdata/luks-convert-qcow2.argv
|
|
|
edecca |
@@ -0,0 +1,9 @@
|
|
|
edecca |
+qemu-img create -f luks \
|
|
|
edecca |
+--object secret,id=OtherDemo.img_encrypt0,file=/path/to/secretFile \
|
|
|
edecca |
+-o key-secret=OtherDemo.img_encrypt0 \
|
|
|
edecca |
+/var/lib/libvirt/images/OtherDemo.img 5242880K
|
|
|
edecca |
+qemu-img convert --image-opts -n --target-image-opts \
|
|
|
edecca |
+--object secret,id=OtherDemo.img_encrypt0,file=/path/to/secretFile \
|
|
|
edecca |
+driver=qcow2,file.filename=/var/lib/libvirt/images/sparse-qcow2.img \
|
|
|
edecca |
+driver=luks,file.filename=/var/lib/libvirt/images/OtherDemo.img,\
|
|
|
edecca |
+key-secret=OtherDemo.img_encrypt0
|
|
|
edecca |
diff --git a/tests/storagevolxml2argvtest.c b/tests/storagevolxml2argvtest.c
|
|
|
edecca |
index b795f83aee..6a9a080dd1 100644
|
|
|
edecca |
--- a/tests/storagevolxml2argvtest.c
|
|
|
edecca |
+++ b/tests/storagevolxml2argvtest.c
|
|
|
edecca |
@@ -284,6 +284,10 @@ mymain(void)
|
|
|
edecca |
"pool-dir", "vol-file",
|
|
|
edecca |
"luks-convert", 0);
|
|
|
edecca |
|
|
|
edecca |
+ DO_TEST("pool-dir", "vol-luks-convert",
|
|
|
edecca |
+ "pool-dir", "vol-file-qcow2",
|
|
|
edecca |
+ "luks-convert-qcow2", 0);
|
|
|
edecca |
+
|
|
|
edecca |
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
|
|
|
edecca |
}
|
|
|
edecca |
|
|
|
edecca |
diff --git a/tests/storagevolxml2xmlin/vol-file-qcow2.xml b/tests/storagevolxml2xmlin/vol-file-qcow2.xml
|
|
|
edecca |
new file mode 100644
|
|
|
edecca |
index 0000000000..025e7e0239
|
|
|
edecca |
--- /dev/null
|
|
|
edecca |
+++ b/tests/storagevolxml2xmlin/vol-file-qcow2.xml
|
|
|
edecca |
@@ -0,0 +1,21 @@
|
|
|
edecca |
+<volume>
|
|
|
edecca |
+ <name>sparse-qcow2.img</name>
|
|
|
edecca |
+ <source/>
|
|
|
edecca |
+ <capacity unit="TiB">1</capacity>
|
|
|
edecca |
+ <allocation unit="bytes">0</allocation>
|
|
|
edecca |
+ <target>
|
|
|
edecca |
+ <path>/var/lib/libvirt/images/sparse-qcow2.img</path>
|
|
|
edecca |
+ <format type="qcow2"/>
|
|
|
edecca |
+ <permissions>
|
|
|
edecca |
+ <mode>0</mode>
|
|
|
edecca |
+ <owner>0744</owner>
|
|
|
edecca |
+ <group>0</group>
|
|
|
edecca |
+ <label>virt_image_t</label>
|
|
|
edecca |
+ </permissions>
|
|
|
edecca |
+ <timestamps>
|
|
|
edecca |
+ <atime>1341933637.273190990</atime>
|
|
|
edecca |
+ <mtime>1341930622.047245868</mtime>
|
|
|
edecca |
+ <ctime>1341930622.047245868</ctime>
|
|
|
edecca |
+ </timestamps>
|
|
|
edecca |
+ </target>
|
|
|
edecca |
+</volume>
|
|
|
edecca |
--
|
|
|
edecca |
2.19.1
|
|
|
edecca |
|