]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
secret: Alter FindByUUID to expect the formatted uuidstr
authorJohn Ferlan <jferlan@redhat.com>
Fri, 21 Apr 2017 15:43:37 +0000 (11:43 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 14 Jul 2017 11:22:41 +0000 (07:22 -0400)
Since we're storing a virUUIDFormat'd string in our Hash Table, let's
modify the Lookup API to receive a formatted string as well.

Signed-off-by: John Ferlan <jferlan@redhat.com>
src/conf/virsecretobj.c
src/conf/virsecretobj.h
src/secret/secret_driver.c

index 0311335ba3e9bb74a3e3db435ddb7f0683f474c9..62b86b7ddb64b3d349ef91419b5b236545b76170 100644 (file)
@@ -171,12 +171,8 @@ virSecretObjListDispose(void *obj)
  */
 static virSecretObjPtr
 virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets,
-                                 const unsigned char *uuid)
+                                 const char *uuidstr)
 {
-    char uuidstr[VIR_UUID_STRING_BUFLEN];
-
-    virUUIDFormat(uuid, uuidstr);
-
     return virObjectRef(virHashLookup(secrets->objs, uuidstr));
 }
 
@@ -184,7 +180,7 @@ virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets,
 /**
  * virSecretObjFindByUUID:
  * @secrets: list of secret objects
- * @uuid: secret uuid to find
+ * @uuidstr: secret uuid to find
  *
  * This function locks @secrets and finds the secret object which
  * corresponds to @uuid.
@@ -193,12 +189,12 @@ virSecretObjListFindByUUIDLocked(virSecretObjListPtr secrets,
  */
 virSecretObjPtr
 virSecretObjListFindByUUID(virSecretObjListPtr secrets,
-                           const unsigned char *uuid)
+                           const char *uuidstr)
 {
     virSecretObjPtr obj;
 
     virObjectLock(secrets);
-    obj = virSecretObjListFindByUUIDLocked(secrets, uuid);
+    obj = virSecretObjListFindByUUIDLocked(secrets, uuidstr);
     virObjectUnlock(secrets);
     if (obj)
         virObjectLock(obj);
@@ -346,13 +342,14 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
     if (oldDef)
         *oldDef = NULL;
 
+    virUUIDFormat(newdef->uuid, uuidstr);
+
     /* Is there a secret already matching this UUID */
-    if ((obj = virSecretObjListFindByUUIDLocked(secrets, newdef->uuid))) {
+    if ((obj = virSecretObjListFindByUUIDLocked(secrets, uuidstr))) {
         virObjectLock(obj);
         def = obj->def;
 
         if (STRNEQ_NULLABLE(def->usage_id, newdef->usage_id)) {
-            virUUIDFormat(def->uuid, uuidstr);
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            _("a secret with UUID %s is already defined for "
                              "use with %s"),
@@ -390,7 +387,6 @@ virSecretObjListAdd(virSecretObjListPtr secrets,
         /* Generate the possible configFile and base64File strings
          * using the configDir, uuidstr, and appropriate suffix
          */
-        virUUIDFormat(newdef->uuid, uuidstr);
         if (!(configFile = virFileBuildPath(configDir, uuidstr, ".xml")) ||
             !(base64File = virFileBuildPath(configDir, uuidstr, ".base64")))
             goto cleanup;
index a355da747549a98b7236127044cde6364ecbbac6..0196813e46cc23201cfea42827450d7064d2ff11 100644 (file)
@@ -40,7 +40,7 @@ virSecretObjListNew(void);
 
 virSecretObjPtr
 virSecretObjListFindByUUID(virSecretObjListPtr secrets,
-                           const unsigned char *uuid);
+                           const char *uuidstr);
 
 virSecretObjPtr
 virSecretObjListFindByUsage(virSecretObjListPtr secrets,
index cffbede65530e5e1607e31dd502147085973c1e3..30124b47cb0381555a957145411f0ea7842a5d35 100644 (file)
@@ -86,8 +86,8 @@ secretObjFromSecret(virSecretPtr secret)
     virSecretObjPtr obj;
     char uuidstr[VIR_UUID_STRING_BUFLEN];
 
-    if (!(obj = virSecretObjListFindByUUID(driver->secrets, secret->uuid))) {
-        virUUIDFormat(secret->uuid, uuidstr);
+    virUUIDFormat(secret->uuid, uuidstr);
+    if (!(obj = virSecretObjListFindByUUID(driver->secrets, uuidstr))) {
         virReportError(VIR_ERR_NO_SECRET,
                        _("no secret with matching uuid '%s'"), uuidstr);
         return NULL;
@@ -148,10 +148,10 @@ secretLookupByUUID(virConnectPtr conn,
     virSecretPtr ret = NULL;
     virSecretObjPtr obj;
     virSecretDefPtr def;
+    char uuidstr[VIR_UUID_STRING_BUFLEN];
 
-    if (!(obj = virSecretObjListFindByUUID(driver->secrets, uuid))) {
-        char uuidstr[VIR_UUID_STRING_BUFLEN];
-        virUUIDFormat(uuid, uuidstr);
+    virUUIDFormat(uuid, uuidstr);
+    if (!(obj = virSecretObjListFindByUUID(driver->secrets, uuidstr))) {
         virReportError(VIR_ERR_NO_SECRET,
                        _("no secret with matching uuid '%s'"), uuidstr);
         goto cleanup;