]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: block: Split up formatting of JSON props for 'raw' and 'luks' drivers
authorPeter Krempa <pkrempa@redhat.com>
Thu, 19 Mar 2020 16:23:33 +0000 (17:23 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 20 Mar 2020 08:47:16 +0000 (09:47 +0100)
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>
src/qemu/qemu_block.c
tests/qemuxml2argvdata/disk-slices.x86_64-latest.args

index ee1516721544489fe6cfc672eb16391b99bf6922..5c85ddd44ca989d097826bbf1dd8d086704cc2f4 100644 (file)
@@ -1200,24 +1200,32 @@ qemuBlockStorageSourceGetBackendProps(virStorageSourcePtr src,
 
 
 static int
-qemuBlockStorageSourceGetFormatRawProps(virStorageSourcePtr src,
-                                        virJSONValuePtr props)
+qemuBlockStorageSourceGetFormatLUKSProps(virStorageSourcePtr src,
+                                         virJSONValuePtr props)
 {
     qemuDomainStorageSourcePrivatePtr srcPriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
-    const char *driver = "raw";
-    const char *secretalias = NULL;
 
-    if (src->encryption &&
-        src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS &&
-        srcPriv &&
-        srcPriv->encinfo) {
-        driver = "luks";
-        secretalias = srcPriv->encinfo->s.aes.alias;
+    if (!srcPriv || !srcPriv->encinfo || !srcPriv->encinfo->s.aes.alias) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("missing secret info for 'luks' driver"));
+        return -1;
     }
 
     if (virJSONValueObjectAdd(props,
-                              "s:driver", driver,
-                              "S:key-secret", secretalias, NULL) < 0)
+                              "s:driver", "luks",
+                              "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;
 
     /* 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
          * put a raw layer on top */
     case VIR_STORAGE_FILE_RAW:
-        if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0)
-            return NULL;
+        if (src->encryption &&
+            src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
+            if (qemuBlockStorageSourceGetFormatLUKSProps(src, props) < 0)
+                return NULL;
+        } else {
+            if (qemuBlockStorageSourceGetFormatRawProps(src, props) < 0)
+                return NULL;
+        }
         break;
 
     case VIR_STORAGE_FILE_QCOW2:
index 63bdaa58be18b9c56b758b7b467c5e562e5a4c87..869b4c0af06f33b8f703ebbedead09104200c944 100644 (file)
@@ -56,7 +56,7 @@ keyid=masterKey0,iv=AAECAwQFBgcICQoLDA0ODw==,format=base64 \
 "size":321,"file":"libvirt-1-storage","auto-read-only":true,\
 "discard":"unmap"}' \
 -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"}' \
 -device virtio-blk-pci,scsi=off,bus=pci.0,addr=0x4,drive=libvirt-1-format,\
 id=virtio-disk2 \