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