[PATCH 12/14] secret: Introduce secretAssignDef

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

 



This new API will allocate the secret, assign the def pointer, and
insert the secret onto the passed list. Whether that's the temporary
list in loadSecrets which gets loaded into the driver list or driver
list during secretDefineXML.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/secret/secret_driver.c | 33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 70bd2f3..8ebe79d 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -168,6 +168,22 @@ secretFindByUsage(int usageType,
     return NULL;
 }
 
+
+static virSecretObjPtr
+secretAssignDef(virSecretObjPtr *list,
+                virSecretDefPtr def)
+{
+    virSecretObjPtr secret;
+
+    if (VIR_ALLOC(secret) < 0)
+        return NULL;
+
+    listInsert(list, secret);
+    secret->def = def;
+
+    return secret;
+}
+
 /* Permament secret storage */
 
 /* Secrets are stored in virSecretDriverStatePtr->configDir.  Each secret
@@ -374,7 +390,8 @@ listUnlinkSecret(virSecretObjPtr *pptr,
 
 
 static virSecretObjPtr
-secretLoad(const char *file,
+secretLoad(virSecretObjPtr *list,
+           const char *file,
            const char *path,
            const char *base64path)
 {
@@ -387,9 +404,8 @@ secretLoad(const char *file,
     if (secretLoadValidateUUID(def, file) < 0)
         goto cleanup;
 
-    if (VIR_ALLOC(secret) < 0)
+    if (!(secret = secretAssignDef(list, def)))
         goto cleanup;
-    secret->def = def;
     def = NULL;
 
     if (VIR_STRDUP(secret->configFile, path) < 0)
@@ -405,6 +421,7 @@ secretLoad(const char *file,
     secret = NULL;
 
  cleanup:
+    listUnlinkSecret(list, secret);
     secretFree(secret);
     virSecretDefFree(def);
     return ret;
@@ -449,7 +466,7 @@ loadSecrets(virSecretObjPtr *dest)
         }
         VIR_FREE(base64name);
 
-        if (!(secret = secretLoad(de->d_name, path, base64path))) {
+        if (!(secret = secretLoad(&list, de->d_name, path, base64path))) {
             virErrorPtr err = virGetLastError();
 
             VIR_ERROR(_("Error reading secret: %s"),
@@ -462,7 +479,6 @@ loadSecrets(virSecretObjPtr *dest)
 
         VIR_FREE(path);
         VIR_FREE(base64path);
-        listInsert(&list, secret);
     }
     /* Ignore error reported by readdir, if any.  It's better to keep the
        secrets we managed to find. */
@@ -712,7 +728,7 @@ secretDefineXML(virConnectPtr conn,
                 unsigned int flags)
 {
     virSecretPtr ret = NULL;
-    virSecretObjPtr secret;
+    virSecretObjPtr secret = NULL;
     virSecretDefPtr backup = NULL;
     virSecretDefPtr new_attrs;
 
@@ -742,7 +758,7 @@ secretDefineXML(virConnectPtr conn,
         }
 
         /* No existing secret at all, create one */
-        if (VIR_ALLOC(secret) < 0)
+        if (!(secret = secretAssignDef(&driver->secrets, new_attrs)))
             goto cleanup;
 
         /* Generate configFile using driver->configDir,
@@ -759,9 +775,6 @@ secretDefineXML(virConnectPtr conn,
             secretFree(secret);
             goto cleanup;
         }
-
-        listInsert(&driver->secrets, secret);
-        secret->def = new_attrs;
     } else {
         const char *newUsageID = secretUsageIDForDef(new_attrs);
         const char *oldUsageID = secretUsageIDForDef(secret->def);
-- 
2.5.0

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