提交 97e3397c 编写于 作者: J John Ferlan

Utilize virDomainDiskAuth for storage pools

Replace the authType, chap, and cephx unions in virStoragePoolSource
with a single pointer to a virStorageAuthDefPtr.  Adjust all users of
the previous chap/cephx and secret unions with the source->auth data.
上级 f1aa00b4
...@@ -44,9 +44,12 @@ ...@@ -44,9 +44,12 @@
#include "viralloc.h" #include "viralloc.h"
#include "virfile.h" #include "virfile.h"
#include "virstring.h" #include "virstring.h"
#include "virlog.h"
#define VIR_FROM_THIS VIR_FROM_STORAGE #define VIR_FROM_THIS VIR_FROM_STORAGE
VIR_LOG_INIT("conf.storage_conf");
#define DEFAULT_POOL_PERM_MODE 0755 #define DEFAULT_POOL_PERM_MODE 0755
#define DEFAULT_VOL_PERM_MODE 0600 #define DEFAULT_VOL_PERM_MODE 0600
...@@ -98,10 +101,6 @@ VIR_ENUM_IMPL(virStoragePoolSourceAdapter, ...@@ -98,10 +101,6 @@ VIR_ENUM_IMPL(virStoragePoolSourceAdapter,
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_LAST, VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_LAST,
"default", "scsi_host", "fc_host") "default", "scsi_host", "fc_host")
VIR_ENUM_IMPL(virStoragePoolAuth,
VIR_STORAGE_POOL_AUTH_LAST,
"none", "chap", "ceph")
typedef const char *(*virStorageVolFormatToString)(int format); typedef const char *(*virStorageVolFormatToString)(int format);
typedef int (*virStorageVolFormatFromString)(const char *format); typedef int (*virStorageVolFormatFromString)(const char *format);
typedef const char *(*virStorageVolFeatureToString)(int feature); typedef const char *(*virStorageVolFeatureToString)(int feature);
...@@ -376,18 +375,9 @@ virStoragePoolSourceClear(virStoragePoolSourcePtr source) ...@@ -376,18 +375,9 @@ virStoragePoolSourceClear(virStoragePoolSourcePtr source)
VIR_FREE(source->name); VIR_FREE(source->name);
virStoragePoolSourceAdapterClear(source->adapter); virStoragePoolSourceAdapterClear(source->adapter);
VIR_FREE(source->initiator.iqn); VIR_FREE(source->initiator.iqn);
virStorageAuthDefFree(source->auth);
VIR_FREE(source->vendor); VIR_FREE(source->vendor);
VIR_FREE(source->product); VIR_FREE(source->product);
if (source->authType == VIR_STORAGE_POOL_AUTH_CHAP) {
VIR_FREE(source->auth.chap.username);
VIR_FREE(source->auth.chap.secret.usage);
}
if (source->authType == VIR_STORAGE_POOL_AUTH_CEPHX) {
VIR_FREE(source->auth.cephx.username);
VIR_FREE(source->auth.cephx.secret.usage);
}
} }
void void
...@@ -463,96 +453,6 @@ virStoragePoolObjRemove(virStoragePoolObjListPtr pools, ...@@ -463,96 +453,6 @@ virStoragePoolObjRemove(virStoragePoolObjListPtr pools,
} }
} }
static int
virStoragePoolDefParseAuthSecret(xmlXPathContextPtr ctxt,
virStoragePoolAuthSecretPtr secret)
{
char *uuid = NULL;
int ret = -1;
uuid = virXPathString("string(./auth/secret/@uuid)", ctxt);
secret->usage = virXPathString("string(./auth/secret/@usage)", ctxt);
if (uuid == NULL && secret->usage == NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing auth secret uuid or usage attribute"));
return -1;
}
if (uuid != NULL) {
if (secret->usage != NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("either auth secret uuid or usage expected"));
goto cleanup;
}
if (virUUIDParse(uuid, secret->uuid) < 0) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("invalid auth secret uuid"));
goto cleanup;
}
secret->uuidUsable = true;
} else {
secret->uuidUsable = false;
}
ret = 0;
cleanup:
VIR_FREE(uuid);
return ret;
}
static int
virStoragePoolDefParseAuth(xmlXPathContextPtr ctxt,
virStoragePoolSourcePtr source)
{
int ret = -1;
char *authType = NULL;
char *username = NULL;
authType = virXPathString("string(./auth/@type)", ctxt);
if (authType == NULL) {
source->authType = VIR_STORAGE_POOL_AUTH_NONE;
ret = 0;
goto cleanup;
}
if ((source->authType =
virStoragePoolAuthTypeFromString(authType)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown auth type '%s'"),
authType);
goto cleanup;
}
username = virXPathString("string(./auth/@username)", ctxt);
if (username == NULL) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("missing auth username attribute"));
goto cleanup;
}
if (source->authType == VIR_STORAGE_POOL_AUTH_CHAP) {
source->auth.chap.username = username;
username = NULL;
if (virStoragePoolDefParseAuthSecret(ctxt,
&source->auth.chap.secret) < 0)
goto cleanup;
}
else if (source->authType == VIR_STORAGE_POOL_AUTH_CEPHX) {
source->auth.cephx.username = username;
username = NULL;
if (virStoragePoolDefParseAuthSecret(ctxt,
&source->auth.cephx.secret) < 0)
goto cleanup;
}
ret = 0;
cleanup:
VIR_FREE(authType);
VIR_FREE(username);
return ret;
}
static int static int
virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
virStoragePoolSourcePtr source, virStoragePoolSourcePtr source,
...@@ -560,10 +460,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, ...@@ -560,10 +460,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
xmlNodePtr node) xmlNodePtr node)
{ {
int ret = -1; int ret = -1;
xmlNodePtr relnode, *nodeset = NULL; xmlNodePtr relnode, authnode, *nodeset = NULL;
int nsource; int nsource;
size_t i; size_t i;
virStoragePoolOptionsPtr options; virStoragePoolOptionsPtr options;
virStorageAuthDefPtr authdef = NULL;
char *name = NULL; char *name = NULL;
char *port = NULL; char *port = NULL;
char *adapter_type = NULL; char *adapter_type = NULL;
...@@ -707,8 +608,18 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt, ...@@ -707,8 +608,18 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST; VIR_STORAGE_POOL_SOURCE_ADAPTER_TYPE_SCSI_HOST;
} }
if (virStoragePoolDefParseAuth(ctxt, source) < 0) if ((authnode = virXPathNode("./auth", ctxt))) {
goto cleanup; if (!(authdef = virStorageAuthDefParse(node->doc, authnode)))
goto cleanup;
if (authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("storage pool missing auth type"));
goto cleanup;
}
source->auth = authdef;
}
source->vendor = virXPathString("string(./vendor/@name)", ctxt); source->vendor = virXPathString("string(./vendor/@name)", ctxt);
source->product = virXPathString("string(./product/@name)", ctxt); source->product = virXPathString("string(./product/@name)", ctxt);
...@@ -1059,7 +970,6 @@ virStoragePoolSourceFormat(virBufferPtr buf, ...@@ -1059,7 +970,6 @@ virStoragePoolSourceFormat(virBufferPtr buf,
virStoragePoolSourcePtr src) virStoragePoolSourcePtr src)
{ {
size_t i, j; size_t i, j;
char uuid[VIR_UUID_STRING_BUFLEN];
virBufferAddLit(buf, "<source>\n"); virBufferAddLit(buf, "<source>\n");
virBufferAdjustIndent(buf, 2); virBufferAdjustIndent(buf, 2);
...@@ -1140,29 +1050,9 @@ virStoragePoolSourceFormat(virBufferPtr buf, ...@@ -1140,29 +1050,9 @@ virStoragePoolSourceFormat(virBufferPtr buf,
virBufferAsprintf(buf, "<format type='%s'/>\n", format); virBufferAsprintf(buf, "<format type='%s'/>\n", format);
} }
if (src->authType == VIR_STORAGE_POOL_AUTH_CHAP || if (src->auth) {
src->authType == VIR_STORAGE_POOL_AUTH_CEPHX) { if (virStorageAuthDefFormat(buf, src->auth) < 0)
virBufferAsprintf(buf, "<auth type='%s' ", return -1;
virStoragePoolAuthTypeToString(src->authType));
virBufferEscapeString(buf, "username='%s'>\n",
(src->authType == VIR_STORAGE_POOL_AUTH_CHAP ?
src->auth.chap.username :
src->auth.cephx.username));
virBufferAdjustIndent(buf, 2);
virBufferAddLit(buf, "<secret");
if (src->auth.cephx.secret.uuidUsable) {
virUUIDFormat(src->auth.cephx.secret.uuid, uuid);
virBufferAsprintf(buf, " uuid='%s'", uuid);
}
if (src->auth.cephx.secret.usage != NULL) {
virBufferAsprintf(buf, " usage='%s'", src->auth.cephx.secret.usage);
}
virBufferAddLit(buf, "/>\n");
virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</auth>\n");
} }
virBufferEscapeString(buf, "<vendor name='%s'/>\n", src->vendor); virBufferEscapeString(buf, "<vendor name='%s'/>\n", src->vendor);
......
...@@ -106,37 +106,6 @@ typedef enum { ...@@ -106,37 +106,6 @@ typedef enum {
} virStoragePoolDeviceType; } virStoragePoolDeviceType;
typedef enum {
VIR_STORAGE_POOL_AUTH_NONE,
VIR_STORAGE_POOL_AUTH_CHAP,
VIR_STORAGE_POOL_AUTH_CEPHX,
VIR_STORAGE_POOL_AUTH_LAST,
} virStoragePoolAuthType;
VIR_ENUM_DECL(virStoragePoolAuth)
typedef struct _virStoragePoolAuthSecret virStoragePoolAuthSecret;
typedef virStoragePoolAuthSecret *virStoragePoolAuthSecretPtr;
struct _virStoragePoolAuthSecret {
unsigned char uuid[VIR_UUID_BUFLEN];
char *usage;
bool uuidUsable;
};
typedef struct _virStoragePoolAuthChap virStoragePoolAuthChap;
typedef virStoragePoolAuthChap *virStoragePoolAuthChapPtr;
struct _virStoragePoolAuthChap {
char *username;
virStoragePoolAuthSecret secret;
};
typedef struct _virStoragePoolAuthCephx virStoragePoolAuthCephx;
typedef virStoragePoolAuthCephx *virStoragePoolAuthCephxPtr;
struct _virStoragePoolAuthCephx {
char *username;
virStoragePoolAuthSecret secret;
};
/* /*
* For remote pools, info on how to reach the host * For remote pools, info on how to reach the host
*/ */
...@@ -243,11 +212,8 @@ struct _virStoragePoolSource { ...@@ -243,11 +212,8 @@ struct _virStoragePoolSource {
/* Initiator IQN */ /* Initiator IQN */
virStoragePoolSourceInitiatorAttr initiator; virStoragePoolSourceInitiatorAttr initiator;
int authType; /* virStoragePoolAuthType */ /* Authentication information */
union { virStorageAuthDefPtr auth;
virStoragePoolAuthChap chap;
virStoragePoolAuthCephx cephx;
} auth;
/* Vendor of the source */ /* Vendor of the source */
char *vendor; char *vendor;
......
...@@ -1211,54 +1211,18 @@ qemuAddISCSIPoolSourceHost(virDomainDiskDefPtr def, ...@@ -1211,54 +1211,18 @@ qemuAddISCSIPoolSourceHost(virDomainDiskDefPtr def,
static int static int
qemuTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def, qemuTranslateDiskSourcePoolAuth(virDomainDiskDefPtr def,
virStoragePoolDefPtr pooldef) virStoragePoolSourcePtr source)
{ {
int ret = -1; int ret = -1;
virStorageAuthDefPtr authdef;
/* Only necessary when authentication set */ /* Only necessary when authentication set */
if (pooldef->source.authType == VIR_STORAGE_POOL_AUTH_NONE) { if (!source->auth) {
ret = 0; ret = 0;
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC(def->src->auth) < 0) def->src->auth = virStorageAuthDefCopy(source->auth);
if (!def->src->auth)
goto cleanup; goto cleanup;
authdef = def->src->auth;
/* Copy the authentication information from the storage pool
* into the virDomainDiskDef
*/
if (pooldef->source.authType == VIR_STORAGE_POOL_AUTH_CHAP) {
if (VIR_STRDUP(authdef->username,
pooldef->source.auth.chap.username) < 0)
goto cleanup;
if (pooldef->source.auth.chap.secret.uuidUsable) {
authdef->secretType = VIR_STORAGE_SECRET_TYPE_UUID;
memcpy(authdef->secret.uuid,
pooldef->source.auth.chap.secret.uuid,
VIR_UUID_BUFLEN);
} else {
if (VIR_STRDUP(authdef->secret.usage,
pooldef->source.auth.chap.secret.usage) < 0)
goto cleanup;
authdef->secretType = VIR_STORAGE_SECRET_TYPE_USAGE;
}
} else if (pooldef->source.authType == VIR_STORAGE_POOL_AUTH_CEPHX) {
if (VIR_STRDUP(authdef->username,
pooldef->source.auth.cephx.username) < 0)
goto cleanup;
if (pooldef->source.auth.cephx.secret.uuidUsable) {
authdef->secretType = VIR_STORAGE_SECRET_TYPE_UUID;
memcpy(authdef->secret.uuid,
pooldef->source.auth.cephx.secret.uuid,
VIR_UUID_BUFLEN);
} else {
if (VIR_STRDUP(authdef->secret.usage,
pooldef->source.auth.cephx.secret.usage) < 0)
goto cleanup;
authdef->secretType = VIR_STORAGE_SECRET_TYPE_USAGE;
}
}
ret = 0; ret = 0;
cleanup: cleanup:
...@@ -1387,7 +1351,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn, ...@@ -1387,7 +1351,7 @@ qemuTranslateDiskSourcePool(virConnectPtr conn,
def->src->srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK; def->src->srcpool->actualtype = VIR_STORAGE_TYPE_NETWORK;
def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI; def->src->protocol = VIR_STORAGE_NET_PROTOCOL_ISCSI;
if (qemuTranslateDiskSourcePoolAuth(def, pooldef) < 0) if (qemuTranslateDiskSourcePoolAuth(def, &pooldef->source) < 0)
goto cleanup; goto cleanup;
if (qemuAddISCSIPoolSourceHost(def, pooldef) < 0) if (qemuAddISCSIPoolSourceHost(def, pooldef) < 0)
......
...@@ -278,18 +278,20 @@ virStorageBackendISCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -278,18 +278,20 @@ virStorageBackendISCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
static int static int
virStorageBackendISCSISetAuth(const char *portal, virStorageBackendISCSISetAuth(const char *portal,
virConnectPtr conn, virConnectPtr conn,
virStoragePoolDefPtr def) virStoragePoolSourcePtr source)
{ {
virSecretPtr secret = NULL; virSecretPtr secret = NULL;
unsigned char *secret_value = NULL; unsigned char *secret_value = NULL;
virStoragePoolAuthChap chap; virStorageAuthDefPtr authdef = source->auth;
int ret = -1; int ret = -1;
char uuidStr[VIR_UUID_STRING_BUFLEN]; char uuidStr[VIR_UUID_STRING_BUFLEN];
if (def->source.authType == VIR_STORAGE_POOL_AUTH_NONE) if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
return 0; return 0;
if (def->source.authType != VIR_STORAGE_POOL_AUTH_CHAP) { VIR_DEBUG("username='%s' authType=%d secretType=%d",
authdef->username, authdef->authType, authdef->secretType);
if (authdef->authType != VIR_STORAGE_AUTH_TYPE_CHAP) {
virReportError(VIR_ERR_XML_ERROR, "%s", virReportError(VIR_ERR_XML_ERROR, "%s",
_("iscsi pool only supports 'chap' auth type")); _("iscsi pool only supports 'chap' auth type"));
return -1; return -1;
...@@ -302,12 +304,11 @@ virStorageBackendISCSISetAuth(const char *portal, ...@@ -302,12 +304,11 @@ virStorageBackendISCSISetAuth(const char *portal,
return -1; return -1;
} }
chap = def->source.auth.chap; if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID)
if (chap.secret.uuidUsable) secret = virSecretLookupByUUID(conn, authdef->secret.uuid);
secret = virSecretLookupByUUID(conn, chap.secret.uuid);
else else
secret = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_ISCSI, secret = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_ISCSI,
chap.secret.usage); authdef->secret.usage);
if (secret) { if (secret) {
size_t secret_size; size_t secret_size;
...@@ -315,44 +316,44 @@ virStorageBackendISCSISetAuth(const char *portal, ...@@ -315,44 +316,44 @@ virStorageBackendISCSISetAuth(const char *portal,
conn->secretDriver->secretGetValue(secret, &secret_size, 0, conn->secretDriver->secretGetValue(secret, &secret_size, 0,
VIR_SECRET_GET_VALUE_INTERNAL_CALL); VIR_SECRET_GET_VALUE_INTERNAL_CALL);
if (!secret_value) { if (!secret_value) {
if (chap.secret.uuidUsable) { if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
virUUIDFormat(chap.secret.uuid, uuidStr); virUUIDFormat(authdef->secret.uuid, uuidStr);
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not get the value of the secret " _("could not get the value of the secret "
"for username %s using uuid '%s'"), "for username %s using uuid '%s'"),
chap.username, uuidStr); authdef->username, uuidStr);
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not get the value of the secret " _("could not get the value of the secret "
"for username %s using usage value '%s'"), "for username %s using usage value '%s'"),
chap.username, chap.secret.usage); authdef->username, authdef->secret.usage);
} }
goto cleanup; goto cleanup;
} }
} else { } else {
if (chap.secret.uuidUsable) { if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
virUUIDFormat(chap.secret.uuid, uuidStr); virUUIDFormat(authdef->secret.uuid, uuidStr);
virReportError(VIR_ERR_NO_SECRET, virReportError(VIR_ERR_NO_SECRET,
_("no secret matches uuid '%s'"), _("no secret matches uuid '%s'"),
uuidStr); uuidStr);
} else { } else {
virReportError(VIR_ERR_NO_SECRET, virReportError(VIR_ERR_NO_SECRET,
_("no secret matches usage value '%s'"), _("no secret matches usage value '%s'"),
chap.secret.usage); authdef->secret.usage);
} }
goto cleanup; goto cleanup;
} }
if (virISCSINodeUpdate(portal, if (virISCSINodeUpdate(portal,
def->source.devices[0].path, source->devices[0].path,
"node.session.auth.authmethod", "node.session.auth.authmethod",
"CHAP") < 0 || "CHAP") < 0 ||
virISCSINodeUpdate(portal, virISCSINodeUpdate(portal,
def->source.devices[0].path, source->devices[0].path,
"node.session.auth.username", "node.session.auth.username",
chap.username) < 0 || authdef->username) < 0 ||
virISCSINodeUpdate(portal, virISCSINodeUpdate(portal,
def->source.devices[0].path, source->devices[0].path,
"node.session.auth.password", "node.session.auth.password",
(const char *)secret_value) < 0) (const char *)secret_value) < 0)
goto cleanup; goto cleanup;
...@@ -404,7 +405,7 @@ virStorageBackendISCSIStartPool(virConnectPtr conn, ...@@ -404,7 +405,7 @@ virStorageBackendISCSIStartPool(virConnectPtr conn,
NULL, NULL) < 0) NULL, NULL) < 0)
goto cleanup; goto cleanup;
if (virStorageBackendISCSISetAuth(portal, conn, pool->def) < 0) if (virStorageBackendISCSISetAuth(portal, conn, &pool->def->source) < 0)
goto cleanup; goto cleanup;
if (virISCSIConnectionLogin(portal, if (virISCSIConnectionLogin(portal,
......
...@@ -50,10 +50,11 @@ typedef virStorageBackendRBDState *virStorageBackendRBDStatePtr; ...@@ -50,10 +50,11 @@ typedef virStorageBackendRBDState *virStorageBackendRBDStatePtr;
static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
virConnectPtr conn, virConnectPtr conn,
virStoragePoolObjPtr pool) virStoragePoolSourcePtr source)
{ {
int ret = -1; int ret = -1;
int r = 0; int r = 0;
virStorageAuthDefPtr authdef = source->auth;
unsigned char *secret_value = NULL; unsigned char *secret_value = NULL;
size_t secret_value_size; size_t secret_value_size;
char *rados_key = NULL; char *rados_key = NULL;
...@@ -66,12 +67,9 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, ...@@ -66,12 +67,9 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
const char *mon_op_timeout = "30"; const char *mon_op_timeout = "30";
const char *osd_op_timeout = "30"; const char *osd_op_timeout = "30";
VIR_DEBUG("Found Cephx username: %s", if (authdef) {
pool->def->source.auth.cephx.username); VIR_DEBUG("Using cephx authorization, username: %s", authdef->username);
r = rados_create(&ptr->cluster, authdef->username);
if (pool->def->source.auth.cephx.username != NULL) {
VIR_DEBUG("Using cephx authorization");
r = rados_create(&ptr->cluster, pool->def->source.auth.cephx.username);
if (r < 0) { if (r < 0) {
virReportSystemError(-r, "%s", _("failed to initialize RADOS")); virReportSystemError(-r, "%s", _("failed to initialize RADOS"));
goto cleanup; goto cleanup;
...@@ -84,46 +82,45 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, ...@@ -84,46 +82,45 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
return -1; return -1;
} }
if (pool->def->source.auth.cephx.secret.uuidUsable) { if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
virUUIDFormat(pool->def->source.auth.cephx.secret.uuid, secretUuid); virUUIDFormat(authdef->secret.uuid, secretUuid);
VIR_DEBUG("Looking up secret by UUID: %s", secretUuid); VIR_DEBUG("Looking up secret by UUID: %s", secretUuid);
secret = virSecretLookupByUUIDString(conn, secretUuid); secret = virSecretLookupByUUIDString(conn, secretUuid);
} else if (pool->def->source.auth.cephx.secret.usage != NULL) { } else if (authdef->secret.usage != NULL) {
VIR_DEBUG("Looking up secret by usage: %s", VIR_DEBUG("Looking up secret by usage: %s",
pool->def->source.auth.cephx.secret.usage); authdef->secret.usage);
secret = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_CEPH, secret = virSecretLookupByUsage(conn, VIR_SECRET_USAGE_TYPE_CEPH,
pool->def->source.auth.cephx.secret.usage); authdef->secret.usage);
} }
if (secret == NULL) { if (secret == NULL) {
if (pool->def->source.auth.cephx.secret.uuidUsable) { if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
virReportError(VIR_ERR_NO_SECRET, virReportError(VIR_ERR_NO_SECRET,
_("no secret matches uuid '%s'"), _("no secret matches uuid '%s'"),
secretUuid); secretUuid);
} else { } else {
virReportError(VIR_ERR_NO_SECRET, virReportError(VIR_ERR_NO_SECRET,
_("no secret matches usage value '%s'"), _("no secret matches usage value '%s'"),
pool->def->source.auth.cephx.secret.usage); authdef->secret.usage);
} }
goto cleanup; goto cleanup;
} }
secret_value = conn->secretDriver->secretGetValue(secret, &secret_value_size, 0, secret_value = conn->secretDriver->secretGetValue(secret,
&secret_value_size, 0,
VIR_SECRET_GET_VALUE_INTERNAL_CALL); VIR_SECRET_GET_VALUE_INTERNAL_CALL);
if (!secret_value) { if (!secret_value) {
if (pool->def->source.auth.cephx.secret.uuidUsable) { if (authdef->secretType == VIR_STORAGE_SECRET_TYPE_UUID) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not get the value of the secret " _("could not get the value of the secret "
"for username '%s' using uuid '%s'"), "for username '%s' using uuid '%s'"),
pool->def->source.auth.cephx.username, authdef->username, secretUuid);
secretUuid);
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not get the value of the secret " _("could not get the value of the secret "
"for username '%s' using usage value '%s'"), "for username '%s' using usage value '%s'"),
pool->def->source.auth.cephx.username, authdef->username, authdef->secret.usage);
pool->def->source.auth.cephx.secret.usage);
} }
goto cleanup; goto cleanup;
} }
...@@ -170,18 +167,18 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr, ...@@ -170,18 +167,18 @@ static int virStorageBackendRBDOpenRADOSConn(virStorageBackendRBDStatePtr ptr,
} }
VIR_DEBUG("Found %zu RADOS cluster monitors in the pool configuration", VIR_DEBUG("Found %zu RADOS cluster monitors in the pool configuration",
pool->def->source.nhost); source->nhost);
for (i = 0; i < pool->def->source.nhost; i++) { for (i = 0; i < source->nhost; i++) {
if (pool->def->source.hosts[i].name != NULL && if (source->hosts[i].name != NULL &&
!pool->def->source.hosts[i].port) { !source->hosts[i].port) {
virBufferAsprintf(&mon_host, "%s:6789,", virBufferAsprintf(&mon_host, "%s:6789,",
pool->def->source.hosts[i].name); source->hosts[i].name);
} else if (pool->def->source.hosts[i].name != NULL && } else if (source->hosts[i].name != NULL &&
pool->def->source.hosts[i].port) { source->hosts[i].port) {
virBufferAsprintf(&mon_host, "%s:%d,", virBufferAsprintf(&mon_host, "%s:%d,",
pool->def->source.hosts[i].name, source->hosts[i].name,
pool->def->source.hosts[i].port); source->hosts[i].port);
} else { } else {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("received malformed monitor, check the XML definition")); _("received malformed monitor, check the XML definition"));
...@@ -333,7 +330,7 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn, ...@@ -333,7 +330,7 @@ static int virStorageBackendRBDRefreshPool(virConnectPtr conn,
ptr.cluster = NULL; ptr.cluster = NULL;
ptr.ioctx = NULL; ptr.ioctx = NULL;
if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, pool) < 0) { if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) {
goto cleanup; goto cleanup;
} }
...@@ -435,7 +432,7 @@ static int virStorageBackendRBDDeleteVol(virConnectPtr conn, ...@@ -435,7 +432,7 @@ static int virStorageBackendRBDDeleteVol(virConnectPtr conn,
VIR_WARN("%s", _("This storage backend does not supported zeroed removal of volumes")); VIR_WARN("%s", _("This storage backend does not supported zeroed removal of volumes"));
} }
if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, pool) < 0) { if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) {
goto cleanup; goto cleanup;
} }
...@@ -518,7 +515,7 @@ virStorageBackendRBDBuildVol(virConnectPtr conn, ...@@ -518,7 +515,7 @@ virStorageBackendRBDBuildVol(virConnectPtr conn,
virCheckFlags(0, -1); virCheckFlags(0, -1);
if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, pool) < 0) if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0)
goto cleanup; goto cleanup;
if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0) if (virStorageBackendRBDOpenIoCTX(&ptr, pool) < 0)
...@@ -558,7 +555,7 @@ static int virStorageBackendRBDRefreshVol(virConnectPtr conn, ...@@ -558,7 +555,7 @@ static int virStorageBackendRBDRefreshVol(virConnectPtr conn,
ptr.ioctx = NULL; ptr.ioctx = NULL;
int ret = -1; int ret = -1;
if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, pool) < 0) { if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) {
goto cleanup; goto cleanup;
} }
...@@ -592,7 +589,7 @@ static int virStorageBackendRBDResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -592,7 +589,7 @@ static int virStorageBackendRBDResizeVol(virConnectPtr conn ATTRIBUTE_UNUSED,
virCheckFlags(0, -1); virCheckFlags(0, -1);
if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, pool) < 0) { if (virStorageBackendRBDOpenRADOSConn(&ptr, conn, &pool->def->source) < 0) {
goto cleanup; goto cleanup;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册