storage: Allow for inputvol to have any format for encryption

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>
This commit is contained in:
John Ferlan 2018-08-21 09:53:12 -04:00
parent f6aa977fab
commit 8041471858
4 changed files with 47 additions and 1 deletions

View 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 */

View File

@ -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

View 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;
}

View File

@ -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>