mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 22:25:25 +00:00
storage: Use virSecretGetSecretString
Rather than inline code secret lookup for rbd/iscsi, use the common function. Signed-off-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
7df631b66a
commit
35f6abef6b
@ -1622,6 +1622,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 =
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user