qemuDomainSecretAESSetupFromSecret: Use 'qemuAliasForSecret'

Replace qemuDomainGetSecretAESAlias by the new function so that we can
reuse qemuDomainSecretAESSetupFromSecret also for setting up other kinds
of objects.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa
2020-03-09 06:56:04 +01:00
parent 740dd1a4e5
commit 86fecaedf5

View File

@@ -1575,34 +1575,32 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv,
* qemuDomainSecretAESSetupFromSecret: * qemuDomainSecretAESSetupFromSecret:
* @priv: pointer to domain private object * @priv: pointer to domain private object
* @srcalias: Alias of the disk/hostdev used to generate the secret alias * @srcalias: Alias of the disk/hostdev used to generate the secret alias
* @secretuse: specific usage for the secret (may be NULL if main object is using it)
* @usageType: The virSecretUsageType * @usageType: The virSecretUsageType
* @username: username to use for authentication (may be NULL) * @username: username to use for authentication (may be NULL)
* @seclookupdef: Pointer to seclookupdef data * @seclookupdef: Pointer to seclookupdef data
* @isLuks: True/False for is for luks (alias generation)
* *
* Looks up a secret in the secret driver based on @usageType and @seclookupdef * Looks up a secret in the secret driver based on @usageType and @seclookupdef
* and builds qemuDomainSecretInfoPtr from it. * and builds qemuDomainSecretInfoPtr from it. @use describes the usage of the
* secret in case if @srcalias requires more secrets for various usage cases.
*/ */
static qemuDomainSecretInfoPtr static qemuDomainSecretInfoPtr
qemuDomainSecretAESSetupFromSecret(qemuDomainObjPrivatePtr priv, qemuDomainSecretAESSetupFromSecret(qemuDomainObjPrivatePtr priv,
const char *srcalias, const char *srcalias,
const char *secretuse,
virSecretUsageType usageType, virSecretUsageType usageType,
const char *username, const char *username,
virSecretLookupTypeDefPtr seclookupdef, virSecretLookupTypeDefPtr seclookupdef)
bool isLuks)
{ {
g_autoptr(virConnect) conn = virGetConnectSecret(); g_autoptr(virConnect) conn = virGetConnectSecret();
qemuDomainSecretInfoPtr secinfo; qemuDomainSecretInfoPtr secinfo;
g_autofree char *alias = NULL; g_autofree char *alias = qemuAliasForSecret(srcalias, secretuse);
uint8_t *secret = NULL; uint8_t *secret = NULL;
size_t secretlen = 0; size_t secretlen = 0;
if (!conn) if (!conn)
return NULL; return NULL;
if (!(alias = qemuDomainGetSecretAESAlias(srcalias, isLuks)))
return NULL;
if (virSecretGetSecretString(conn, seclookupdef, usageType, if (virSecretGetSecretString(conn, seclookupdef, usageType,
&secret, &secretlen) < 0) &secret, &secretlen) < 0)
return NULL; return NULL;
@@ -1687,9 +1685,9 @@ qemuDomainSecretInfoTLSNew(qemuDomainObjPrivatePtr priv,
} }
seclookupdef.type = VIR_SECRET_LOOKUP_TYPE_UUID; seclookupdef.type = VIR_SECRET_LOOKUP_TYPE_UUID;
return qemuDomainSecretAESSetupFromSecret(priv, srcAlias, return qemuDomainSecretAESSetupFromSecret(priv, srcAlias, NULL,
VIR_SECRET_USAGE_TYPE_TLS, VIR_SECRET_USAGE_TYPE_TLS,
NULL, &seclookupdef, false); NULL, &seclookupdef);
} }
@@ -1780,10 +1778,10 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
&src->auth->seclookupdef); &src->auth->seclookupdef);
} else { } else {
srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv, aliasprotocol, srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv, aliasprotocol,
NULL,
usageType, usageType,
src->auth->username, src->auth->username,
&src->auth->seclookupdef, &src->auth->seclookupdef);
false);
} }
if (!srcPriv->secinfo) if (!srcPriv->secinfo)
@@ -1792,10 +1790,10 @@ qemuDomainSecretStorageSourcePrepare(qemuDomainObjPrivatePtr priv,
if (hasEnc) { if (hasEnc) {
if (!(srcPriv->encinfo = qemuDomainSecretAESSetupFromSecret(priv, aliasformat, if (!(srcPriv->encinfo = qemuDomainSecretAESSetupFromSecret(priv, aliasformat,
"luks",
VIR_SECRET_USAGE_TYPE_VOLUME, VIR_SECRET_USAGE_TYPE_VOLUME,
NULL, NULL,
&src->encryption->secrets[0]->seclookupdef, &src->encryption->secrets[0]->seclookupdef)))
true)))
return -1; return -1;
} }
@@ -1856,10 +1854,10 @@ qemuDomainSecretHostdevPrepare(qemuDomainObjPrivatePtr priv,
} else { } else {
srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv, srcPriv->secinfo = qemuDomainSecretAESSetupFromSecret(priv,
hostdev->info->alias, hostdev->info->alias,
NULL,
usageType, usageType,
src->auth->username, src->auth->username,
&src->auth->seclookupdef, &src->auth->seclookupdef);
false);
} }
if (!srcPriv->secinfo) if (!srcPriv->secinfo)