[PATCH 13/10] secret: Introduce virSecretObjGetDef and virSecretObjSetDef

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

 



Introduce fetch and set accessor to the secretObj->def field for usage
by the driver to avoid the driver needing to know the format of virSecretObj

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/conf/secret_conf.c     | 15 +++++++++++++
 src/conf/secret_conf.h     |  4 ++++
 src/libvirt_private.syms   |  2 ++
 src/secret/secret_driver.c | 54 ++++++++++++++++++++++++++++------------------
 4 files changed, 54 insertions(+), 21 deletions(-)

diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index 3528288..0410328 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -775,6 +775,21 @@ virSecretObjSaveData(virSecretObjPtr secret)
 }
 
 
+virSecretDefPtr
+virSecretObjGetDef(virSecretObjPtr secret)
+{
+    return secret->def;
+}
+
+
+void
+virSecretObjSetDef(virSecretObjPtr secret,
+                   virSecretDefPtr def)
+{
+    secret->def = def;
+}
+
+
 void
 virSecretDefFree(virSecretDefPtr def)
 {
diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h
index d40b510..ce714c1 100644
--- a/src/conf/secret_conf.h
+++ b/src/conf/secret_conf.h
@@ -122,6 +122,10 @@ int virSecretObjSaveConfig(virSecretObjPtr secret);
 
 int virSecretObjSaveData(virSecretObjPtr secret);
 
+virSecretDefPtr virSecretObjGetDef(virSecretObjPtr secret);
+
+void virSecretObjSetDef(virSecretObjPtr secret, virSecretDefPtr def);
+
 void virSecretDefFree(virSecretDefPtr def);
 virSecretDefPtr virSecretDefParseString(const char *xml);
 virSecretDefPtr virSecretDefParseFile(const char *filename);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 9e1a09e..3a417f0 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -790,6 +790,7 @@ virSecretLoadAllConfigs;
 virSecretObjDeleteConfig;
 virSecretObjDeleteData;
 virSecretObjEndAPI;
+virSecretObjGetDef;
 virSecretObjListAdd;
 virSecretObjListExport;
 virSecretObjListFindByUsage;
@@ -800,6 +801,7 @@ virSecretObjListNumOfSecrets;
 virSecretObjListRemove;
 virSecretObjSaveConfig;
 virSecretObjSaveData;
+virSecretObjSetDef;
 virSecretUsageIDForDef;
 virSecretUsageTypeFromString;
 virSecretUsageTypeToString;
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 1b4dfea..676c02e 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -152,6 +152,7 @@ secretLookupByUUID(virConnectPtr conn,
 {
     virSecretPtr ret = NULL;
     virSecretObjPtr secret;
+    virSecretDefPtr def;
 
     if (!(secret = virSecretObjListFindByUUID(driver->secrets, uuid))) {
         char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -161,13 +162,14 @@ secretLookupByUUID(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (virSecretLookupByUUIDEnsureACL(conn, secret->def) < 0)
+    def = virSecretObjGetDef(secret);
+    if (virSecretLookupByUUIDEnsureACL(conn, def) < 0)
         goto cleanup;
 
     ret = virGetSecret(conn,
-                       secret->def->uuid,
-                       secret->def->usage_type,
-                       virSecretUsageIDForDef(secret->def));
+                       def->uuid,
+                       def->usage_type,
+                       virSecretUsageIDForDef(def));
 
  cleanup:
     virSecretObjEndAPI(&secret);
@@ -182,6 +184,7 @@ secretLookupByUsage(virConnectPtr conn,
 {
     virSecretPtr ret = NULL;
     virSecretObjPtr secret;
+    virSecretDefPtr def;
 
     if (!(secret = virSecretObjListFindByUsage(driver->secrets,
                                                usageType, usageID))) {
@@ -190,13 +193,14 @@ secretLookupByUsage(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (virSecretLookupByUsageEnsureACL(conn, secret->def) < 0)
+    def = virSecretObjGetDef(secret);
+    if (virSecretLookupByUsageEnsureACL(conn, def) < 0)
         goto cleanup;
 
     ret = virGetSecret(conn,
-                       secret->def->uuid,
-                       secret->def->usage_type,
-                       virSecretUsageIDForDef(secret->def));
+                       def->uuid,
+                       def->usage_type,
+                       virSecretUsageIDForDef(def));
 
  cleanup:
     virSecretObjEndAPI(&secret);
@@ -249,22 +253,22 @@ secretDefineXML(virConnectPtr conn,
         virSecretObjDeleteData(secret);
     }
     /* Saved successfully - drop old values */
-    new_attrs = NULL;
     virSecretDefFree(backup);
 
     ret = virGetSecret(conn,
-                       secret->def->uuid,
-                       secret->def->usage_type,
-                       virSecretUsageIDForDef(secret->def));
+                       new_attrs->uuid,
+                       new_attrs->usage_type,
+                       virSecretUsageIDForDef(new_attrs));
+    new_attrs = NULL;
     goto cleanup;
 
  restore_backup:
     /* If we have a backup, then secret was defined before, so just restore
-     * the backup. The current secret->def (new_attrs) will be handled below.
+     * the backup. The current (new_attrs) will be handled below.
      * Otherwise, this is a new secret, thus remove it.
      */
     if (backup)
-        secret->def = backup;
+        virSecretObjSetDef(secret, backup);
     else
         virSecretObjListRemove(driver->secrets, secret);
 
@@ -281,16 +285,18 @@ secretGetXMLDesc(virSecretPtr obj,
 {
     char *ret = NULL;
     virSecretObjPtr secret;
+    virSecretDefPtr def;
 
     virCheckFlags(0, NULL);
 
     if (!(secret = secretObjFromSecret(obj)))
         goto cleanup;
 
-    if (virSecretGetXMLDescEnsureACL(obj->conn, secret->def) < 0)
+    def = virSecretObjGetDef(secret);
+    if (virSecretGetXMLDescEnsureACL(obj->conn, def) < 0)
         goto cleanup;
 
-    ret = virSecretDefFormat(secret->def);
+    ret = virSecretDefFormat(def);
 
  cleanup:
     virSecretObjEndAPI(&secret);
@@ -308,6 +314,7 @@ secretSetValue(virSecretPtr obj,
     unsigned char *old_value, *new_value;
     size_t old_value_size;
     virSecretObjPtr secret;
+    virSecretDefPtr def;
 
     virCheckFlags(0, -1);
 
@@ -317,7 +324,8 @@ secretSetValue(virSecretPtr obj,
     if (!(secret = secretObjFromSecret(obj)))
         goto cleanup;
 
-    if (virSecretSetValueEnsureACL(obj->conn, secret->def) < 0)
+    def = virSecretObjGetDef(secret);
+    if (virSecretSetValueEnsureACL(obj->conn, def) < 0)
         goto cleanup;
 
     old_value = secret->value;
@@ -326,7 +334,7 @@ secretSetValue(virSecretPtr obj,
     memcpy(new_value, value, value_size);
     secret->value = new_value;
     secret->value_size = value_size;
-    if (!secret->def->ephemeral) {
+    if (!def->ephemeral) {
         if (secretEnsureDirectory() < 0)
             goto cleanup;
 
@@ -365,13 +373,15 @@ secretGetValue(virSecretPtr obj,
 {
     unsigned char *ret = NULL;
     virSecretObjPtr secret;
+    virSecretDefPtr def;
 
     virCheckFlags(0, NULL);
 
     if (!(secret = secretObjFromSecret(obj)))
         goto cleanup;
 
-    if (virSecretGetValueEnsureACL(obj->conn, secret->def) < 0)
+    def = virSecretObjGetDef(secret);
+    if (virSecretGetValueEnsureACL(obj->conn, def) < 0)
         goto cleanup;
 
     if (secret->value == NULL) {
@@ -383,7 +393,7 @@ secretGetValue(virSecretPtr obj,
     }
 
     if ((internalFlags & VIR_SECRET_GET_VALUE_INTERNAL_CALL) == 0 &&
-        secret->def->private) {
+        def->private) {
         virReportError(VIR_ERR_INVALID_SECRET, "%s",
                        _("secret is private"));
         goto cleanup;
@@ -405,11 +415,13 @@ secretUndefine(virSecretPtr obj)
 {
     int ret = -1;
     virSecretObjPtr secret;
+    virSecretDefPtr def;
 
     if (!(secret = secretObjFromSecret(obj)))
         goto cleanup;
 
-    if (virSecretUndefineEnsureACL(obj->conn, secret->def) < 0)
+    def = virSecretObjGetDef(secret);
+    if (virSecretUndefineEnsureACL(obj->conn, def) < 0)
         goto cleanup;
 
     if (virSecretObjDeleteConfig(secret) < 0)
-- 
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]