qemu: block: Split up formatting of JSON props for 'raw' and 'luks' drivers

qemuBlockStorageSourceGetFormatRawProps aggregated both formats but
since we now have props specific for either of those formats it's
unwanted to aggregate the code such way. Split out the 'luks' props
formatter into qemuBlockStorageSourceGetFormatLUKSProps.

The wrong separation demonstrates istself on formatting of the 'size'
and 'offset' attributes for the 'luks' driver which does not conform
to the qapi schema.

https://bugzilla.redhat.com/show_bug.cgi?id=1814975

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2020-03-19 17:23:33 +01:00
parent 7393be3bbc
commit 1a86e3b24a
2 changed files with 29 additions and 15 deletions

View File

@ -1200,24 +1200,32 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
static int static int
qemuBlockStorageSourceGetFormatRawProps(virStorageSourcePtr src, qemuBlockStorageSourceGetFormatLUKSProps(virStorageSourcePtr src,
virJSONValuePtr props) virJSONValuePtr props)
{ {
qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src); qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
const char *driver = "raw";
const char *secretalias = NULL;
if (src->encryption && if (!srcPriv || !srcPriv->encinfo || !srcPriv->encinfo->s.aes.alias) {
src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS && virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
srcPriv && _("missing secret info for 'luks' driver"));
srcPriv->encinfo) { return -1;
driver = "luks";
secretalias = srcPriv->encinfo->s.aes.alias;
} }
if (virJSONValueObjectAdd(props, if (virJSONValueObjectAdd(props,
"s:driver", driver, "s:driver", "luks",
"S:key-secret", secretalias, NULL) < 0) "s:key-secret", srcPriv->encinfo->s.aes.alias,
NULL) < 0)
return -1;
return 0;
}
static int
qemuBlockStorageSourceGetFormatRawProps(virStorageSourcePtr src,
virJSONValuePtr props)
{
if (virJSONValueObjectAdd(props, "s:driver", "raw", NULL) < 0)
return -1; return -1;
/* Currently only storage slices are supported. We'll have to calculate /* Currently only storage slices are supported. We'll have to calculate
@ -1371,8 +1379,14 @@ qemuBlockStorageSourceGetBlockdevFormatProps(virStorageSourcePtr src)
/* The fat layer is emulated by the storage access layer, so we need to /* The fat layer is emulated by the storage access layer, so we need to
* put a raw layer on top */ * put a raw layer on top */
case VIR_STORAGE_FILE_RAW: case VIR_STORAGE_FILE_RAW:
if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0) if (src->encryption &&
return NULL; src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
if (qemuBlockStorageSourceGetFormatLUKSProps(src, props) < 0)
return NULL;
} else {
if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0)
return NULL;
}
break; break;
case VIR_STORAGE_FILE_QCOW2: case VIR_STORAGE_FILE_QCOW2:

View File

@ -56,7 +56,7 @@ keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \
"size":321,"file":"libvirt-1-storage","auto-read-only":true,\ "size":321,"file":"libvirt-1-storage","auto-read-only":true,\
"discard":"unmap"}' \ "discard":"unmap"}' \
-blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"luks",\ -blockdev '{"node-name":"libvirt-1-format","read-only":false,"driver":"luks",\
"key-secret":"libvirt-1-format-encryption-secret0","offset":1234,"size":321,\ "key-secret":"libvirt-1-format-encryption-secret0",\
"file":"libvirt-1-slice-sto"}' \ "file":"libvirt-1-slice-sto"}' \
-device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=libvirt-1-format,\ -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=libvirt-1-format,\
id=virtio-disk2 \ id=virtio-disk2 \