qemu: add multi-secret support in qemuBlockStorageSourceAttachData

This commit changes the qemuBlockStorageSourceAttachData struct
to support multiple secrets (instead of a single one before this commit).
This will useful for storage encryption requiring more than a single secret.

Signed-off-by: Or Ozeri <oro@il.ibm.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Or Ozeri 2023-03-13 04:50:19 -05:00 committed by Peter Krempa
parent e239f7d0a8
commit 5c84e6fcdd
4 changed files with 47 additions and 15 deletions

View File

@ -1311,6 +1311,7 @@ qemuBlockStorageSourceGetBlockdevStorageSliceProps(virStorageSource *src)
void
qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachData *data)
{
size_t i;
if (!data)
return;
@ -1320,12 +1321,16 @@ qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachData *data)
virJSONValueFree(data->prmgrProps);
virJSONValueFree(data->authsecretProps);
virJSONValueFree(data->httpcookiesecretProps);
virJSONValueFree(data->encryptsecretProps);
for (i = 0; i < data->encryptsecretCount; ++i) {
virJSONValueFree(data->encryptsecretProps[i]);
g_free(data->encryptsecretAlias[i]);
}
virJSONValueFree(data->tlsProps);
virJSONValueFree(data->tlsKeySecretProps);
g_free(data->tlsAlias);
g_free(data->tlsKeySecretAlias);
g_free(data->authsecretAlias);
g_free(data->encryptsecretProps);
g_free(data->encryptsecretAlias);
g_free(data->httpcookiesecretAlias);
g_free(data->driveCmd);
@ -1436,10 +1441,12 @@ static int
qemuBlockStorageSourceAttachApplyFormatDeps(qemuMonitor *mon,
qemuBlockStorageSourceAttachData *data)
{
if (data->encryptsecretProps &&
qemuMonitorAddObject(mon, &data->encryptsecretProps,
&data->encryptsecretAlias) < 0)
return -1;
size_t i;
for (i = 0; i < data->encryptsecretCount; ++i) {
if (qemuMonitorAddObject(mon, &data->encryptsecretProps[i],
&data->encryptsecretAlias[i]) < 0)
return -1;
}
return 0;
}
@ -1525,6 +1532,7 @@ qemuBlockStorageSourceAttachRollback(qemuMonitor *mon,
qemuBlockStorageSourceAttachData *data)
{
virErrorPtr orig_err;
size_t i;
virErrorPreserveLast(&orig_err);
@ -1550,8 +1558,10 @@ qemuBlockStorageSourceAttachRollback(qemuMonitor *mon,
if (data->authsecretAlias)
ignore_value(qemuMonitorDelObject(mon, data->authsecretAlias, false));
if (data->encryptsecretAlias)
ignore_value(qemuMonitorDelObject(mon, data->encryptsecretAlias, false));
for (i = 0; i < data->encryptsecretCount; ++i) {
if (data->encryptsecretAlias[i])
ignore_value(qemuMonitorDelObject(mon, data->encryptsecretAlias[i], false));
}
if (data->httpcookiesecretAlias)
ignore_value(qemuMonitorDelObject(mon, data->httpcookiesecretAlias, false));
@ -1606,8 +1616,12 @@ qemuBlockStorageSourceDetachPrepare(virStorageSource *src)
if (srcpriv->secinfo)
data->authsecretAlias = g_strdup(srcpriv->secinfo->alias);
if (srcpriv->encinfo)
data->encryptsecretAlias = g_strdup(srcpriv->encinfo->alias);
if (srcpriv->encinfo) {
data->encryptsecretCount = 1;
data->encryptsecretProps = g_new0(virJSONValue *, 1);
data->encryptsecretAlias = g_new0(char *, 1);
data->encryptsecretAlias[0] = g_strdup(srcpriv->encinfo->alias);
}
if (srcpriv->httpcookie)
data->httpcookiesecretAlias = g_strdup(srcpriv->httpcookie->alias);

View File

@ -89,8 +89,9 @@ struct qemuBlockStorageSourceAttachData {
virJSONValue *authsecretProps;
char *authsecretAlias;
virJSONValue *encryptsecretProps;
char *encryptsecretAlias;
size_t encryptsecretCount;
virJSONValue **encryptsecretProps;
char **encryptsecretAlias;
virJSONValue *httpcookiesecretProps;
char *httpcookiesecretAlias;

View File

@ -1336,9 +1336,15 @@ qemuBlockJobProcessEventConcludedCreate(virQEMUDriver *driver,
/* the format node part was not attached yet, so we don't need to detach it */
backend->formatAttached = false;
if (job->data.create.storage) {
size_t i;
backend->storageAttached = false;
backend->storageSliceAttached = false;
for (i = 0; i < backend->encryptsecretCount; ++i) {
VIR_FREE(backend->encryptsecretAlias[i]);
}
VIR_FREE(backend->encryptsecretAlias);
VIR_FREE(backend->encryptsecretProps);
}
if (qemuDomainObjEnterMonitorAsync(vm, asyncJob) < 0)

View File

@ -2108,15 +2108,21 @@ qemuBuildBlockStorageSourceAttachDataCommandline(virCommand *cmd,
virQEMUCaps *qemuCaps)
{
char *tmp;
size_t i;
if (qemuBuildObjectCommandline(cmd, data->prmgrProps, qemuCaps) < 0 ||
qemuBuildObjectCommandline(cmd, data->authsecretProps, qemuCaps) < 0 ||
qemuBuildObjectCommandline(cmd, data->encryptsecretProps, qemuCaps) < 0 ||
qemuBuildObjectCommandline(cmd, data->httpcookiesecretProps, qemuCaps) < 0 ||
qemuBuildObjectCommandline(cmd, data->tlsKeySecretProps, qemuCaps) < 0 ||
qemuBuildObjectCommandline(cmd, data->tlsProps, qemuCaps) < 0)
return -1;
for (i = 0; i < data->encryptsecretCount; ++i) {
if (qemuBuildObjectCommandline(cmd, data->encryptsecretProps[i], qemuCaps) < 0) {
return -1;
}
}
if (data->driveCmd)
virCommandAddArgList(cmd, "-drive", data->driveCmd, NULL);
@ -10770,9 +10776,14 @@ qemuBuildStorageSourceAttachPrepareCommon(virStorageSource *src,
qemuBuildSecretInfoProps(srcpriv->secinfo, &data->authsecretProps) < 0)
return -1;
if (srcpriv->encinfo &&
qemuBuildSecretInfoProps(srcpriv->encinfo, &data->encryptsecretProps) < 0)
return -1;
if (srcpriv->encinfo) {
data->encryptsecretCount = 1;
data->encryptsecretProps = g_new0(virJSONValue *, 1);
data->encryptsecretAlias = g_new0(char *, 1);
if (qemuBuildSecretInfoProps(srcpriv->encinfo, &data->encryptsecretProps[0]) < 0)
return -1;
}
if (srcpriv->httpcookie &&
qemuBuildSecretInfoProps(srcpriv->httpcookie, &data->httpcookiesecretProps) < 0)