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