[PATCH 2/3] storage: Split out setting default secret for encryption

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

 



Split the qcow setting of encryption secrets into a helper

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/storage/storage_backend_fs.c | 79 +++++++++++++++++++++++++---------------
 1 file changed, 49 insertions(+), 30 deletions(-)

diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 45474cb..a11df36 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -1280,6 +1280,51 @@ virStorageBackendFileSystemVolDelete(virConnectPtr conn ATTRIBUTE_UNUSED,
 }
 
 
+/* virStorageBackendFileSystemLoadDefaultSecrets:
+ * @conn: Connection pointer to fetch secret
+ * @vol: volume being refreshed
+ *
+ * If the volume had a QCOW secret generated, we need to regenerate the
+ * secret
+ *
+ * Returns 0 if no secret or secret setup was successful,
+ * -1 on failures w/ error message set
+ */
+static int
+virStorageBackendFileSystemLoadDefaultSecrets(virConnectPtr conn,
+                                              virStorageVolDefPtr vol)
+{
+    virSecretPtr sec;
+    virStorageEncryptionSecretPtr encsec = NULL;
+
+    /* Only necessary for qcow format */
+    if (!vol->target.encryption ||
+        vol->target.encryption->format != VIR_STORAGE_ENCRYPTION_FORMAT_QCOW ||
+        vol->target.encryption->nsecrets != 0)
+        return 0;
+
+    if (!(sec = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_VOLUME,
+                                       vol->target.path)))
+        return 0;
+
+    if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
+        VIR_ALLOC(encsec) < 0) {
+        VIR_FREE(vol->target.encryption->secrets);
+        virObjectUnref(sec);
+        return -1;
+    }
+
+    vol->target.encryption->nsecrets = 1;
+    vol->target.encryption->secrets[0] = encsec;
+
+    encsec->type = VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE;
+    virSecretGetUUID(sec, encsec->uuid);
+    virObjectUnref(sec);
+
+    return 0;
+}
+
+
 /**
  * Update info about a volume's capacity/allocation
  */
@@ -1291,39 +1336,13 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
     int ret;
 
     /* Refresh allocation / capacity / permissions info in case its changed */
-    ret = virStorageBackendUpdateVolInfo(vol, false,
-                                         VIR_STORAGE_VOL_FS_OPEN_FLAGS, 0);
-    if (ret < 0)
+    if ((ret = virStorageBackendUpdateVolInfo(vol, false,
+                                              VIR_STORAGE_VOL_FS_OPEN_FLAGS,
+                                              0)) < 0)
         return ret;
 
     /* Load any secrets if possible */
-    if (vol->target.encryption &&
-        vol->target.encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_QCOW &&
-        vol->target.encryption->nsecrets == 0) {
-        virSecretPtr sec;
-        virStorageEncryptionSecretPtr encsec = NULL;
-
-        sec = virSecretLookupByUsage(conn,
-                                     VIR_SECRET_USAGE_TYPE_VOLUME,
-                                     vol->target.path);
-        if (sec) {
-            if (VIR_ALLOC_N(vol->target.encryption->secrets, 1) < 0 ||
-                VIR_ALLOC(encsec) < 0) {
-                VIR_FREE(vol->target.encryption->secrets);
-                virObjectUnref(sec);
-                return -1;
-            }
-
-            vol->target.encryption->nsecrets = 1;
-            vol->target.encryption->secrets[0] = encsec;
-
-            encsec->type = VIR_STORAGE_ENCRYPTION_SECRET_TYPE_PASSPHRASE;
-            virSecretGetUUID(sec, encsec->uuid);
-            virObjectUnref(sec);
-        }
-    }
-
-    return 0;
+    return virStorageBackendFileSystemLoadDefaultSecrets(conn, vol);
 }
 
 static int
-- 
2.5.5

--
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]