提交 816f0f93 编写于 作者: P Peter Krempa

qemu: Refactor qemuGetDriveSourceString to take virStorageSourcePtr

Refactor the function to avoid multiple wrappers splitting identical
fields from the now common metadata struct.

The refactor is done by folding in the wrapper used for disk sources
which allows us to lookup secrets via the secret driver. This may allow
using stored secrets for snapshot disk images too in the future.
上级 cecd6566
...@@ -3816,91 +3816,77 @@ qemuBuildNetworkDriveURI(int protocol, ...@@ -3816,91 +3816,77 @@ qemuBuildNetworkDriveURI(int protocol,
int int
qemuGetDriveSourceString(int type, qemuGetDriveSourceString(virStorageSourcePtr src,
const char *src, virConnectPtr conn,
int protocol,
size_t nhosts,
virStorageNetHostDefPtr hosts,
const char *username,
const char *secret,
char **path)
{
*path = NULL;
switch ((enum virStorageType) type) {
case VIR_STORAGE_TYPE_BLOCK:
case VIR_STORAGE_TYPE_FILE:
case VIR_STORAGE_TYPE_DIR:
if (!src)
return 1;
if (VIR_STRDUP(*path, src) < 0)
return -1;
break;
case VIR_STORAGE_TYPE_NETWORK:
if (!(*path = qemuBuildNetworkDriveURI(protocol,
src,
nhosts,
hosts,
username,
secret)))
return -1;
break;
case VIR_STORAGE_TYPE_VOLUME:
case VIR_STORAGE_TYPE_NONE:
case VIR_STORAGE_TYPE_LAST:
break;
}
return 0;
}
static int
qemuDomainDiskGetSourceString(virConnectPtr conn,
virDomainDiskDefPtr disk,
char **source) char **source)
{ {
int actualType = virStorageSourceGetActualType(&disk->src); int actualType = virStorageSourceGetActualType(src);
char *secret = NULL; char *secret = NULL;
char *username = NULL;
int ret = -1; int ret = -1;
*source = NULL; *source = NULL;
if (conn) {
if (actualType == VIR_STORAGE_TYPE_NETWORK && if (actualType == VIR_STORAGE_TYPE_NETWORK &&
disk->src.auth.username && src->auth.username &&
(disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI || (src->protocol == VIR_STORAGE_NET_PROTOCOL_ISCSI ||
disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD)) { src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD)) {
bool encode = false; bool encode = false;
int secretType = VIR_SECRET_USAGE_TYPE_ISCSI; int secretType = VIR_SECRET_USAGE_TYPE_ISCSI;
const char *protocol = virStorageNetProtocolTypeToString(src->protocol);
username = src->auth.username;
if (disk->src.protocol == VIR_STORAGE_NET_PROTOCOL_RBD) { if (src->protocol == VIR_STORAGE_NET_PROTOCOL_RBD) {
/* qemu requires the secret to be encoded for RBD */ /* qemu requires the secret to be encoded for RBD */
encode = true; encode = true;
secretType = VIR_SECRET_USAGE_TYPE_CEPH; secretType = VIR_SECRET_USAGE_TYPE_CEPH;
} }
if (!(secret = qemuGetSecretString(conn, if (!(secret = qemuGetSecretString(conn,
virStorageNetProtocolTypeToString(disk->src.protocol), protocol,
encode, encode,
disk->src.auth.secretType, src->auth.secretType,
disk->src.auth.username, username,
disk->src.auth.secret.uuid, src->auth.secret.uuid,
disk->src.auth.secret.usage, src->auth.secret.usage,
secretType))) secretType)))
goto cleanup; goto cleanup;
} }
}
ret = qemuGetDriveSourceString(actualType, switch ((enum virStorageType) actualType) {
disk->src.path, case VIR_STORAGE_TYPE_BLOCK:
disk->src.protocol, case VIR_STORAGE_TYPE_FILE:
disk->src.nhosts, case VIR_STORAGE_TYPE_DIR:
disk->src.hosts, if (!src->path) {
disk->src.auth.username, ret = 1;
secret, goto cleanup;
source); }
if (VIR_STRDUP(*source, src->path) < 0)
goto cleanup;
break;
case VIR_STORAGE_TYPE_NETWORK:
if (!(*source = qemuBuildNetworkDriveURI(src->protocol,
src->path,
src->nhosts,
src->hosts,
username,
secret)))
goto cleanup;
break;
case VIR_STORAGE_TYPE_VOLUME:
case VIR_STORAGE_TYPE_NONE:
case VIR_STORAGE_TYPE_LAST:
break;
}
ret = 0;
cleanup: cleanup:
VIR_FREE(secret); VIR_FREE(secret);
...@@ -4003,7 +3989,7 @@ qemuBuildDriveStr(virConnectPtr conn, ...@@ -4003,7 +3989,7 @@ qemuBuildDriveStr(virConnectPtr conn,
break; break;
} }
if (qemuDomainDiskGetSourceString(conn, disk, &source) < 0) if (qemuGetDriveSourceString(&disk->src, conn, &source) < 0)
goto error; goto error;
if (source && if (source &&
......
...@@ -314,13 +314,7 @@ qemuParseKeywords(const char *str, ...@@ -314,13 +314,7 @@ qemuParseKeywords(const char *str,
int *retnkeywords, int *retnkeywords,
int allowEmptyValue); int allowEmptyValue);
int qemuGetDriveSourceString(int type, int qemuGetDriveSourceString(virStorageSourcePtr src,
const char *src, virConnectPtr conn,
int protocol, char **source);
size_t nhosts,
virStorageNetHostDefPtr hosts,
const char *username,
const char *secret,
char **path);
#endif /* __QEMU_COMMAND_H__*/ #endif /* __QEMU_COMMAND_H__*/
...@@ -11999,23 +11999,6 @@ qemuDomainMigrateGetMaxSpeed(virDomainPtr dom, ...@@ -11999,23 +11999,6 @@ qemuDomainMigrateGetMaxSpeed(virDomainPtr dom,
} }
static int
qemuDomainSnapshotDiskGetSourceString(virDomainSnapshotDiskDefPtr disk,
char **source)
{
*source = NULL;
return qemuGetDriveSourceString(virStorageSourceGetActualType(&disk->src),
disk->src.path,
disk->src.protocol,
disk->src.nhosts,
disk->src.hosts,
NULL,
NULL,
source);
}
typedef enum { typedef enum {
VIR_DISK_CHAIN_NO_ACCESS, VIR_DISK_CHAIN_NO_ACCESS,
VIR_DISK_CHAIN_READ_ONLY, VIR_DISK_CHAIN_READ_ONLY,
...@@ -12758,7 +12741,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver, ...@@ -12758,7 +12741,7 @@ qemuDomainSnapshotCreateSingleDiskActive(virQEMUDriverPtr driver,
if (virStorageFileInit(&snap->src) < 0) if (virStorageFileInit(&snap->src) < 0)
goto cleanup; goto cleanup;
if (qemuDomainSnapshotDiskGetSourceString(snap, &source) < 0) if (qemuGetDriveSourceString(&snap->src, NULL, &source) < 0)
goto cleanup; goto cleanup;
if (VIR_STRDUP(newsource, snap->src.path) < 0) if (VIR_STRDUP(newsource, snap->src.path) < 0)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册