]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage_util: Move secretPath generation
authorJohn Ferlan <jferlan@redhat.com>
Wed, 18 Apr 2018 18:18:14 +0000 (14:18 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 15 May 2018 20:57:24 +0000 (16:57 -0400)
Move generation of secretPath to storageBackendGenerateSecretData
and simplify a bit since we know vol->target.encryption is set plus
we have a local @enc.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/storage/storage_util.c

index 64d4d1d7d2bbe7662a046b7c0a624ea5744cf04e..d20a1093064d70ce7ae6965360238b0aebf22fbb 100644 (file)
@@ -1310,7 +1310,9 @@ storageBackendCreateQemuImgSecretPath(virStoragePoolObjPtr pool,
 
 
 static int
-storageBackendGenerateSecretData(virStorageVolDefPtr vol)
+storageBackendGenerateSecretData(virStoragePoolObjPtr pool,
+                                 virStorageVolDefPtr vol,
+                                 char **secretPath)
 {
     virStorageEncryptionPtr enc = vol->target.encryption;
 
@@ -1325,6 +1327,12 @@ storageBackendGenerateSecretData(virStorageVolDefPtr vol)
             return -1;
     }
 
+    if (vol->target.format == VIR_STORAGE_FILE_RAW &&
+        enc->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
+        if (!(*secretPath = storageBackendCreateQemuImgSecretPath(pool, vol)))
+            return -1;
+    }
+
     return 0;
 }
 
@@ -1350,17 +1358,9 @@ storageBackendCreateQemuImg(virStoragePoolObjPtr pool,
         return -1;
     }
 
-    if (storageBackendGenerateSecretData(vol) < 0)
+    if (storageBackendGenerateSecretData(pool, vol, &secretPath) < 0)
         goto cleanup;
 
-    if (vol->target.format == VIR_STORAGE_FILE_RAW &&
-        vol->target.encryption &&
-        vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) {
-        if (!(secretPath =
-              storageBackendCreateQemuImgSecretPath(pool, vol)))
-            goto cleanup;
-    }
-
     cmd = virStorageBackendCreateQemuImgCmdFromVol(pool, vol, inputvol,
                                                    flags, create_tool,
                                                    secretPath);