mirror of https://gitee.com/openkylin/libvirt.git
qemu: hotplug: Extract hotplug of TLS into qemuBlockStorageSourceAttachApply
Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
191780e856
commit
99239432d3
|
@ -1488,6 +1488,8 @@ qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachDataPtr data)
|
|||
virJSONValueFree(data->prmgrProps);
|
||||
virJSONValueFree(data->authsecretProps);
|
||||
virJSONValueFree(data->encryptsecretProps);
|
||||
virJSONValueFree(data->tlsProps);
|
||||
VIR_FREE(data->tlsAlias);
|
||||
VIR_FREE(data->authsecretAlias);
|
||||
VIR_FREE(data->encryptsecretAlias);
|
||||
VIR_FREE(data->driveCmd);
|
||||
|
@ -1567,6 +1569,10 @@ qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
|
|||
&data->encryptsecretAlias) < 0)
|
||||
return -1;
|
||||
|
||||
if (data->tlsProps &&
|
||||
qemuMonitorAddObject(mon, &data->tlsProps, &data->tlsAlias) < 0)
|
||||
return -1;
|
||||
|
||||
if (data->storageProps) {
|
||||
rv = qemuMonitorBlockdevAdd(mon, data->storageProps);
|
||||
data->storageProps = NULL;
|
||||
|
@ -1637,6 +1643,9 @@ qemuBlockStorageSourceAttachRollback(qemuMonitorPtr mon,
|
|||
if (data->encryptsecretAlias)
|
||||
ignore_value(qemuMonitorDelObject(mon, data->encryptsecretAlias));
|
||||
|
||||
if (data->tlsAlias)
|
||||
ignore_value(qemuMonitorDelObject(mon, data->tlsAlias));
|
||||
|
||||
|
||||
virErrorRestore(&orig_err);
|
||||
}
|
||||
|
|
|
@ -91,6 +91,9 @@ struct qemuBlockStorageSourceAttachData {
|
|||
|
||||
virJSONValuePtr encryptsecretProps;
|
||||
char *encryptsecretAlias;
|
||||
|
||||
virJSONValuePtr tlsProps;
|
||||
char *tlsAlias;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -10491,13 +10491,15 @@ qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk,
|
|||
* qemuBuildStorageSourceAttachPrepareCommon:
|
||||
* @src: storage source
|
||||
* @data: already initialized data for disk source addition
|
||||
* @qemuCaps: qemu capabilities object
|
||||
*
|
||||
* Prepare data for configuration associated with the disk source such as
|
||||
* secrets/TLS/pr objects etc ...
|
||||
*/
|
||||
int
|
||||
qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src,
|
||||
qemuBlockStorageSourceAttachDataPtr data)
|
||||
qemuBlockStorageSourceAttachDataPtr data,
|
||||
virQEMUCapsPtr qemuCaps)
|
||||
{
|
||||
qemuDomainStorageSourcePrivatePtr srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
|
||||
|
||||
|
@ -10517,5 +10519,10 @@ qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src,
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (src->haveTLS == VIR_TRISTATE_BOOL_YES &&
|
||||
qemuBuildTLSx509BackendProps(src->tlsCertdir, false, true, src->tlsAlias,
|
||||
NULL, qemuCaps, &data->tlsProps) < 0)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -108,7 +108,8 @@ qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk,
|
|||
virQEMUCapsPtr qemuCaps);
|
||||
int
|
||||
qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src,
|
||||
qemuBlockStorageSourceAttachDataPtr data);
|
||||
qemuBlockStorageSourceAttachDataPtr data,
|
||||
virQEMUCapsPtr qemuCaps);
|
||||
|
||||
/* Current, best practice */
|
||||
char *qemuBuildDriveDevStr(const virDomainDef *def,
|
||||
|
|
|
@ -154,35 +154,6 @@ qemuHotplugPrepareDiskAccess(virQEMUDriverPtr driver,
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuDomainAddDiskSrcTLSObject(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
virStorageSourcePtr src)
|
||||
{
|
||||
int ret = -1;
|
||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||
virJSONValuePtr tlsProps = NULL;
|
||||
|
||||
if (qemuDomainGetTLSObjects(priv->qemuCaps, NULL,
|
||||
src->tlsCertdir,
|
||||
false, true,
|
||||
src->tlsAlias,
|
||||
&tlsProps, NULL) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuDomainAddTLSObjects(driver, vm, QEMU_ASYNC_JOB_NONE,
|
||||
NULL, &tlsProps) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virJSONValueFree(tlsProps);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver,
|
||||
virDomainObjPtr vm,
|
||||
|
@ -413,11 +384,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
|||
if (!(data = qemuBuildStorageSourceAttachPrepareDrive(disk, priv->qemuCaps)))
|
||||
goto error;
|
||||
|
||||
if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, data) < 0)
|
||||
goto error;
|
||||
|
||||
if (disk->src->haveTLS == VIR_TRISTATE_BOOL_YES &&
|
||||
qemuDomainAddDiskSrcTLSObject(driver, vm, disk->src) < 0)
|
||||
if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, data, priv->qemuCaps) < 0)
|
||||
goto error;
|
||||
|
||||
if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps)))
|
||||
|
@ -463,8 +430,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
|||
virErrorPreserveLast(&orig_err);
|
||||
if (managedPrmgrAlias)
|
||||
ignore_value(qemuMonitorDelObject(priv->mon, managedPrmgrAlias));
|
||||
if (disk->src->tlsAlias)
|
||||
ignore_value(qemuMonitorDelObject(priv->mon, disk->src->tlsAlias));
|
||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||
ret = -2;
|
||||
virErrorRestore(&orig_err);
|
||||
|
|
Loading…
Reference in New Issue