[PATCH 5/4] storage: Use virSecretGetSecretString

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

 



Rather than inline code secret lookup for rbd/iscsi, use the common function.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 This just makes the iscsi/rbd storage driver use the common function...
 work that was started by pkrempa in commit id '1d632c39'


 src/Makefile.am                     |  1 +
 src/storage/storage_backend_iscsi.c | 48 +++++--------------------------------
 src/storage/storage_backend_rbd.c   | 45 +++-------------------------------
 3 files changed, 10 insertions(+), 84 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 12b66c2..2711ca5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1614,6 +1614,7 @@ libvirt_driver_storage_impl_la_SOURCES =
 libvirt_driver_storage_impl_la_CFLAGS = \
 		-I$(srcdir)/access \
 		-I$(srcdir)/conf \
+		-I$(srcdir)/secret \
 		$(AM_CFLAGS)
 libvirt_driver_storage_impl_la_LDFLAGS = $(AM_LDFLAGS)
 libvirt_driver_storage_impl_la_LIBADD =
diff --git a/src/storage/storage_backend_iscsi.c b/src/storage/storage_backend_iscsi.c
index bccfba3..999b610 100644
--- a/src/storage/storage_backend_iscsi.c
+++ b/src/storage/storage_backend_iscsi.c
@@ -1,7 +1,7 @@
 /*
  * storage_backend_iscsi.c: storage backend for iSCSI handling
  *
- * Copyright (C) 2007-2014 Red Hat, Inc.
+ * Copyright (C) 2007-2016 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -43,7 +43,7 @@
 #include "virobject.h"
 #include "virstring.h"
 #include "viruuid.h"
-
+#include "secret_util.h"
 #define VIR_FROM_THIS VIR_FROM_STORAGE
 
 VIR_LOG_INIT("storage.storage_backend_iscsi");
@@ -279,9 +279,9 @@ virStorageBackendISCSISetAuth(const char *portal,
 {
     virSecretPtr secret = NULL;
     unsigned char *secret_value = NULL;
+    size_t secret_size;
     virStorageAuthDefPtr authdef = source->auth;
     int ret = -1;
-    char uuidStr[VIR_UUID_STRING_BUFLEN];
 
     if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
         return 0;
@@ -301,45 +301,9 @@ virStorageBackendISCSISetAuth(const char *portal,
         return -1;
     }
 
-    if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID)
-        secret = virSecretLookupByUUID(conn, authdef->secret.uuid);
-    else
-        secret = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_ISCSI,
-                                        authdef->secret.usage);
-
-    if (secret) {
-        size_t secret_size;
-        secret_value =
-            conn->secretDriver->secretGetValue(secret, &secret_size, 0,
-                                               VIR_SECRET_GET_VALUE_INTERNAL_CALL);
-        if (!secret_value) {
-            if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
-                virUUIDFormat(authdef->secret.uuid, uuidStr);
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("could not get the value of the secret "
-                                 "for username %s using uuid '%s'"),
-                               authdef->username, uuidStr);
-            } else {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("could not get the value of the secret "
-                                 "for username %s using usage value '%s'"),
-                               authdef->username, authdef->secret.usage);
-            }
-            goto cleanup;
-        }
-    } else {
-        if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
-            virUUIDFormat(authdef->secret.uuid, uuidStr);
-            virReportError(VIR_ERR_NO_SECRET,
-                           _("no secret matches uuid '%s'"),
-                           uuidStr);
-        } else {
-            virReportError(VIR_ERR_NO_SECRET,
-                           _("no secret matches usage value '%s'"),
-                           authdef->secret.usage);
-        }
+    if (virSecretGetSecretString(conn, authdef, VIR_SECRET_USAGE_TYPE_ISCSI,
+                                 &secret_value, &secret_size) < 0)
         goto cleanup;
-    }
 
     if (virISCSINodeUpdate(portal,
                            source->devices[0].path,
@@ -359,7 +323,7 @@ virStorageBackendISCSISetAuth(const char *portal,
 
  cleanup:
     virObjectUnref(secret);
-    VIR_FREE(secret_value);
+    VIR_DISPOSE_N(secret_value, secret_size);
     return ret;
 }
 
diff --git a/src/storage/storage_backend_rbd.c b/src/storage/storage_backend_rbd.c
index ac46b9d..34005ce 100644
--- a/src/storage/storage_backend_rbd.c
+++ b/src/storage/storage_backend_rbd.c
@@ -36,6 +36,7 @@
 #include "virrandom.h"
 #include "rados/librados.h"
 #include "rbd/librbd.h"
+#include "secret_util.h"
 
 #define VIR_FROM_THIS VIR_FROM_STORAGE
 
@@ -63,7 +64,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
     char *rados_key = NULL;
     virBuffer mon_host = VIR_BUFFER_INITIALIZER;
     virSecretPtr secret = NULL;
-    char secretUuid[VIR_UUID_STRING_BUFLEN];
     size_t i;
     char *mon_buff = NULL;
     const char *client_mount_timeout = "30";
@@ -86,48 +86,9 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
             return -1;
         }
 
-        if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
-            virUUIDFormat(authdef->secret.uuid, secretUuid);
-            VIR_DEBUG("Looking up secret by UUID: %s", secretUuid);
-            secret = virSecretLookupByUUIDString(conn, secretUuid);
-        } else if (authdef->secret.usage != NULL) {
-            VIR_DEBUG("Looking up secret by usage: %s",
-                      authdef->secret.usage);
-            secret = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_CEPH,
-                                            authdef->secret.usage);
-        }
-
-        if (secret == NULL) {
-            if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
-                virReportError(VIR_ERR_NO_SECRET,
-                               _("no secret matches uuid '%s'"),
-                                 secretUuid);
-            } else {
-                virReportError(VIR_ERR_NO_SECRET,
-                               _("no secret matches usage value '%s'"),
-                                 authdef->secret.usage);
-            }
-            goto cleanup;
-        }
-
-        secret_value = conn->secretDriver->secretGetValue(secret,
-                                                          &secret_value_size, 0,
-                                                          VIR_SECRET_GET_VALUE_INTERNAL_CALL);
-
-        if (!secret_value) {
-            if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("could not get the value of the secret "
-                                 "for username '%s' using uuid '%s'"),
-                               authdef->username, secretUuid);
-            } else {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("could not get the value of the secret "
-                                 "for username '%s' using usage value '%s'"),
-                               authdef->username, authdef->secret.usage);
-            }
+        if (virSecretGetSecretString(conn, authdef, VIR_SECRET_USAGE_TYPE_CEPH,
+                                     &secret_value, &secret_value_size) < 0)
             goto cleanup;
-        }
 
         if (!(rados_key = virStringEncodeBase64(secret_value, secret_value_size)))
             goto cleanup;
-- 
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]