[PATCH 4/4] qemu: block: Split up formatting of JSON props for 'raw' and 'luks' drivers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 src/qemu/qemu_block.c                         | 42 ++++++++++++-------
 .../disk-slices.x86_64-latest.args            |  2 +-
 2 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index ee15167215..5c85ddd44c 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -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:
diff --git a/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args b/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args
index 63bdaa58be..869b4c0af0 100644
--- a/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/disk-slices.x86_64-latest.args
@@ -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 \
-- 
2.24.1





[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux