Rather than inline code secret lookup for rbd/iscsi, use the common function.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/Makefile.am | 1 +
src/storage/storage_backend_iscsi.c | 49 +++++--------------------------------
src/storage/storage_backend_rbd.c | 48 +++---------------------------------
3 files changed, 10 insertions(+), 88 deletions(-)
diff --git a/src/Makefile.am b/src/Makefile.am
index 1aff57d..4333c2b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1618,6 +1618,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..6cefd50 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,6 +43,7 @@
#include "virobject.h"
#include "virstring.h"
#include "viruuid.h"
+#include "secret_util.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE
@@ -277,11 +278,10 @@ virStorageBackendISCSISetAuth(const char *portal,
virConnectPtr conn,
virStoragePoolSourcePtr source)
{
- 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,
@@ -358,8 +322,7 @@ virStorageBackendISCSISetAuth(const char *portal,
ret = 0;
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..64ec545 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
@@ -62,8 +63,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
size_t secret_value_size = 0;
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 +85,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);
- }
+ if (virSecretGetSecretString(conn, authdef, VIR_SECRET_USAGE_TYPE_CEPH,
+ &secret_value, &secret_value_size) < 0)
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);
- }
- goto cleanup;
- }
if (!(rados_key = virStringEncodeBase64(secret_value, secret_value_size)))
goto cleanup;
@@ -227,8 +187,6 @@ virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
VIR_DISPOSE_N(secret_value, secret_value_size);
VIR_DISPOSE_STRING(rados_key);
- virObjectUnref(secret);
-
virBufferFreeAndReset(&mon_host);
VIR_FREE(mon_buff);
return ret;
--
2.5.5