[PATCH v2 03/14] secret: Introduce virSecretUsageIDForDef

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

 



Move the driver specific secretUsageIDForDef into secret_conf.c. It could
be more of a general purpose API.

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

diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index 4eebae5..8373051 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -1,7 +1,7 @@
 /*
  * secret_conf.c: internal <secret> XML handling
  *
- * Copyright (C) 2009-2014 Red Hat, Inc.
+ * Copyright (C) 2009-2014, 2016 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -39,6 +39,28 @@ VIR_LOG_INIT("conf.secret_conf");
 VIR_ENUM_IMPL(virSecretUsage, VIR_SECRET_USAGE_TYPE_LAST,
               "none", "volume", "ceph", "iscsi")
 
+const char *
+virSecretUsageIDForDef(virSecretDefPtr def)
+{
+    switch (def->usage_type) {
+    case VIR_SECRET_USAGE_TYPE_NONE:
+        return "";
+
+    case VIR_SECRET_USAGE_TYPE_VOLUME:
+        return def->usage.volume;
+
+    case VIR_SECRET_USAGE_TYPE_CEPH:
+        return def->usage.ceph;
+
+    case VIR_SECRET_USAGE_TYPE_ISCSI:
+        return def->usage.target;
+
+    default:
+        return NULL;
+    }
+}
+
+
 void
 virSecretDefFree(virSecretDefPtr def)
 {
diff --git a/src/conf/secret_conf.h b/src/conf/secret_conf.h
index 9c13f05..c87efe4 100644
--- a/src/conf/secret_conf.h
+++ b/src/conf/secret_conf.h
@@ -1,7 +1,7 @@
 /*
  * secret_conf.h: internal <secret> XML handling API
  *
- * Copyright (C) 2009-2010, 2013-2014 Red Hat, Inc.
+ * Copyright (C) 2009-2010, 2013-2014, 2016 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -43,6 +43,8 @@ struct _virSecretDef {
     } usage;
 };
 
+const char *virSecretUsageIDForDef(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 2b55369..b2eb43f 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -786,6 +786,7 @@ virSecretDefFormat;
 virSecretDefFree;
 virSecretDefParseFile;
 virSecretDefParseString;
+virSecretUsageIDForDef;
 virSecretUsageTypeFromString;
 virSecretUsageTypeToString;
 
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 9165a9f..336f00f 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -567,26 +567,6 @@ secretConnectListSecrets(virConnectPtr conn,
     return -1;
 }
 
-static const char *
-secretUsageIDForDef(virSecretDefPtr def)
-{
-    switch (def->usage_type) {
-    case VIR_SECRET_USAGE_TYPE_NONE:
-        return "";
-
-    case VIR_SECRET_USAGE_TYPE_VOLUME:
-        return def->usage.volume;
-
-    case VIR_SECRET_USAGE_TYPE_CEPH:
-        return def->usage.ceph;
-
-    case VIR_SECRET_USAGE_TYPE_ISCSI:
-        return def->usage.target;
-
-    default:
-        return NULL;
-    }
-}
 
 #define MATCH(FLAG) (flags & (FLAG))
 static int
@@ -640,7 +620,7 @@ secretConnectListAllSecrets(virConnectPtr conn,
                   virGetSecret(conn,
                                secret->def->uuid,
                                secret->def->usage_type,
-                               secretUsageIDForDef(secret->def))))
+                               virSecretUsageIDForDef(secret->def))))
                 goto cleanup;
         }
         ret_nsecrets++;
@@ -691,7 +671,7 @@ secretLookupByUUID(virConnectPtr conn,
     ret = virGetSecret(conn,
                        secret->def->uuid,
                        secret->def->usage_type,
-                       secretUsageIDForDef(secret->def));
+                       virSecretUsageIDForDef(secret->def));
 
  cleanup:
     secretDriverUnlock();
@@ -721,7 +701,7 @@ secretLookupByUsage(virConnectPtr conn,
     ret = virGetSecret(conn,
                        secret->def->uuid,
                        secret->def->usage_type,
-                       secretUsageIDForDef(secret->def));
+                       virSecretUsageIDForDef(secret->def));
 
  cleanup:
     secretDriverUnlock();
@@ -752,7 +732,7 @@ secretDefineXML(virConnectPtr conn,
     if (!(secret = secretFindByUUID(new_attrs->uuid))) {
         /* No existing secret with same UUID,
          * try look for matching usage instead */
-        const char *usageID = secretUsageIDForDef(new_attrs);
+        const char *usageID = virSecretUsageIDForDef(new_attrs);
         char uuidstr[VIR_UUID_STRING_BUFLEN];
 
         if ((secret = secretFindByUsage(new_attrs->usage_type, usageID))) {
@@ -785,8 +765,8 @@ secretDefineXML(virConnectPtr conn,
             goto cleanup;
         }
     } else {
-        const char *newUsageID = secretUsageIDForDef(new_attrs);
-        const char *oldUsageID = secretUsageIDForDef(secret->def);
+        const char *newUsageID = virSecretUsageIDForDef(new_attrs);
+        const char *oldUsageID = virSecretUsageIDForDef(secret->def);
         if (STRNEQ(oldUsageID, newUsageID)) {
             char uuidstr[VIR_UUID_STRING_BUFLEN];
             virUUIDFormat(secret->def->uuid, uuidstr);
@@ -831,7 +811,7 @@ secretDefineXML(virConnectPtr conn,
     ret = virGetSecret(conn,
                        secret->def->uuid,
                        secret->def->usage_type,
-                       secretUsageIDForDef(secret->def));
+                       virSecretUsageIDForDef(secret->def));
     goto cleanup;
 
  restore_backup:
-- 
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]