[PATCH 05/12] storage_util: Generate the qcow secret earlier

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

 



Rather than having storageBackendCreateQemuImgCheckEncryption
perform the virStorageGenerateQcowEncryption, let's just do that
earlier during storageBackendCreateQemuImg so that the check
helper is just a check helper rather doing something different
based on whether the format is qcow[2] or raw based encryption.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/storage/storage_util.c | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 37a649d17b..64d4d1d7d2 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -901,10 +901,10 @@ storageBackendCreateQemuImgCheckEncryption(int format,
                            _("too many secrets for qcow encryption"));
             return -1;
         }
-        if (enc->format == VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT ||
-            enc->nsecrets == 0) {
-            if (virStorageGenerateQcowEncryption(vol) < 0)
-                return -1;
+        if (enc->nsecrets == 0) {
+            virReportError(VIR_ERR_XML_ERROR, "%s",
+                           _("no secret provided for qcow encryption"));
+            return -1;
         }
     } else if (format == VIR_STORAGE_FILE_RAW) {
         if (enc->format != VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
@@ -1309,6 +1309,26 @@ storageBackendCreateQemuImgSecretPath(virStoragePoolObjPtr pool,
 }
 
 
+static int
+storageBackendGenerateSecretData(virStorageVolDefPtr vol)
+{
+    virStorageEncryptionPtr enc = vol->target.encryption;
+
+    if (!enc)
+        return 0;
+
+    if ((vol->target.format == VIR_STORAGE_FILE_QCOW ||
+         vol->target.format == VIR_STORAGE_FILE_QCOW2) &&
+        (enc->format == VIR_STORAGE_ENCRYPTION_FORMAT_DEFAULT ||
+         enc->nsecrets == 0)) {
+        if (virStorageGenerateQcowEncryption(vol) < 0)
+            return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 storageBackendCreateQemuImg(virStoragePoolObjPtr pool,
                             virStorageVolDefPtr vol,
@@ -1330,6 +1350,9 @@ storageBackendCreateQemuImg(virStoragePoolObjPtr pool,
         return -1;
     }
 
+    if (storageBackendGenerateSecretData(vol) < 0)
+        goto cleanup;
+
     if (vol->target.format == VIR_STORAGE_FILE_RAW &&
         vol->target.encryption &&
         vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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