[PATCH v2 3/4] storage_util: Don't assume "luks" encryption for resize

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

 



Similar to encrypted image creation/conversion resizing the
volume requires providing different parameters for luks and
qcow[2] encryption.

Alter storageBackendResizeQemuImgImageOpts to take the @type
parameter filled in during storageBackendResizeQemuImg to either
the current type or "luks" for a RAW image and use that to
generate the "driver=%s" value and to determine whether to use
"encrypt.key-secret" or "key-secret".

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

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 29adf0cdbe..b7b86d76cb 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -1088,20 +1088,26 @@ storageBackendCreateQemuImgSecretObject(virCommandPtr cmd,
 
 
 /* Add a --image-opts to the qemu-img resize command line:
- *    --image-opts driver=luks,file.filename=$volpath,key-secret=$secretAlias
- *
- *    NB: format=raw is assumed
+ *    --image-opts driver=%s,\
+ *        [encrypt.]key-secret=$secretAlias,\
+ *        file.filename=$volpath
  */
 static int
 storageBackendResizeQemuImgImageOpts(virCommandPtr cmd,
+                                     const char *type,
                                      const char *path,
                                      const char *secretAlias)
 {
     virBuffer buf = VIR_BUFFER_INITIALIZER;
     char *commandStr = NULL;
 
-    virBufferAsprintf(&buf, "driver=luks,key-secret=%s,file.filename=",
-                      secretAlias);
+    virBufferAsprintf(&buf, "driver=%s,", type);
+    if (STREQ(type, "luks"))
+        virBufferAsprintf(&buf, "key-secret=%s,", secretAlias);
+    else
+        virBufferAsprintf(&buf, "encrypt.key-secret=%s,", secretAlias);
+    virBufferAddLit(&buf, "file.filename=");
+
     virQEMUBuildBufferEscapeComma(&buf, path);
 
     if (virBufferCheckError(&buf) < 0) {
@@ -2403,7 +2409,7 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr pool,
     int ret = -1;
     char *img_tool = NULL;
     virCommandPtr cmd = NULL;
-    const char *type;
+    const char *type = virStorageFileFormatTypeToString(vol->target.format);
     char *secretPath = NULL;
     char *secretAlias = NULL;
 
@@ -2417,8 +2423,6 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr pool,
     if (vol->target.encryption) {
         if (vol->target.format == VIR_STORAGE_FILE_RAW)
             type = "luks";
-        else
-            type = virStorageFileFormatTypeToString(vol->target.format);
 
         storageBackendLoadDefaultSecrets(vol);
 
@@ -2448,7 +2452,7 @@ storageBackendResizeQemuImg(virStoragePoolObjPtr pool,
                                                     secretAlias) < 0)
             goto cleanup;
 
-        if (storageBackendResizeQemuImgImageOpts(cmd, vol->target.path,
+        if (storageBackendResizeQemuImgImageOpts(cmd, type, vol->target.path,
                                                  secretAlias) < 0)
             goto cleanup;
     }
-- 
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