mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 07:17:44 +00:00
qemu: hotplug: Extract hotplug of PR into qemuBlockStorageSourceAttachApply
Introduce a new setup function for all the related configuration and move the setup and attachment of the PR code. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
ca174424ba
commit
1990a01e6e
@ -1485,6 +1485,7 @@ qemuBlockStorageSourceAttachDataFree(qemuBlockStorageSourceAttachDataPtr data)
|
||||
|
||||
virJSONValueFree(data->storageProps);
|
||||
virJSONValueFree(data->formatProps);
|
||||
virJSONValueFree(data->prmgrProps);
|
||||
VIR_FREE(data->driveCmd);
|
||||
VIR_FREE(data->driveAlias);
|
||||
VIR_FREE(data);
|
||||
@ -1548,6 +1549,10 @@ qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
|
||||
{
|
||||
int rv;
|
||||
|
||||
if (data->prmgrProps &&
|
||||
qemuMonitorAddObject(mon, &data->prmgrProps, &data->prmgrAlias) < 0)
|
||||
return -1;
|
||||
|
||||
if (data->storageProps) {
|
||||
rv = qemuMonitorBlockdevAdd(mon, data->storageProps);
|
||||
data->storageProps = NULL;
|
||||
@ -1609,6 +1614,9 @@ qemuBlockStorageSourceAttachRollback(qemuMonitorPtr mon,
|
||||
if (data->storageAttached)
|
||||
ignore_value(qemuMonitorBlockdevDel(mon, data->storageNodeName));
|
||||
|
||||
if (data->prmgrAlias)
|
||||
ignore_value(qemuMonitorDelObject(mon, data->prmgrAlias));
|
||||
|
||||
virErrorRestore(&orig_err);
|
||||
}
|
||||
|
||||
|
@ -71,6 +71,9 @@ qemuBlockStorageSourceGetBlockdevProps(virStorageSourcePtr src);
|
||||
typedef struct qemuBlockStorageSourceAttachData qemuBlockStorageSourceAttachData;
|
||||
typedef qemuBlockStorageSourceAttachData *qemuBlockStorageSourceAttachDataPtr;
|
||||
struct qemuBlockStorageSourceAttachData {
|
||||
virJSONValuePtr prmgrProps;
|
||||
char *prmgrAlias;
|
||||
|
||||
virJSONValuePtr storageProps;
|
||||
const char *storageNodeName;
|
||||
bool storageAttached;
|
||||
|
@ -10485,3 +10485,24 @@ qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk,
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* qemuBuildStorageSourceAttachPrepareCommon:
|
||||
* @src: storage source
|
||||
* @data: already initialized data for disk source addition
|
||||
*
|
||||
* Prepare data for configuration associated with the disk source such as
|
||||
* secrets/TLS/pr objects etc ...
|
||||
*/
|
||||
int
|
||||
qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src,
|
||||
qemuBlockStorageSourceAttachDataPtr data)
|
||||
{
|
||||
if (src->pr &&
|
||||
!virStoragePRDefIsManaged(src->pr) &&
|
||||
!(data->prmgrProps = qemuBuildPRManagerInfoProps(src)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -106,6 +106,9 @@ char *qemuDeviceDriveHostAlias(virDomainDiskDefPtr disk);
|
||||
qemuBlockStorageSourceAttachDataPtr
|
||||
qemuBuildStorageSourceAttachPrepareDrive(virDomainDiskDefPtr disk,
|
||||
virQEMUCapsPtr qemuCaps);
|
||||
int
|
||||
qemuBuildStorageSourceAttachPrepareCommon(virStorageSourcePtr src,
|
||||
qemuBlockStorageSourceAttachDataPtr data);
|
||||
|
||||
/* Current, best practice */
|
||||
char *qemuBuildDriveDevStr(const virDomainDef *def,
|
||||
|
@ -394,14 +394,12 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
||||
qemuBlockStorageSourceAttachDataPtr data = NULL;
|
||||
virErrorPtr orig_err;
|
||||
char *devstr = NULL;
|
||||
char *unmanagedPrmgrAlias = NULL;
|
||||
char *managedPrmgrAlias = NULL;
|
||||
char *encobjAlias = NULL;
|
||||
char *secobjAlias = NULL;
|
||||
virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
|
||||
virJSONValuePtr secobjProps = NULL;
|
||||
virJSONValuePtr encobjProps = NULL;
|
||||
virJSONValuePtr unmanagedPrmgrProps = NULL;
|
||||
virJSONValuePtr managedPrmgrProps = NULL;
|
||||
qemuDomainStorageSourcePrivatePtr srcPriv;
|
||||
qemuDomainSecretInfoPtr secinfo = NULL;
|
||||
@ -433,12 +431,10 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
||||
if (qemuDomainDiskAttachManagedPR(vm, disk, &managedPrmgrProps) < 0)
|
||||
goto error;
|
||||
|
||||
if (disk->src->pr &&
|
||||
!virStoragePRDefIsManaged(disk->src->pr) &&
|
||||
!(unmanagedPrmgrProps = qemuBuildPRManagerInfoProps(disk->src)))
|
||||
if (!(data = qemuBuildStorageSourceAttachPrepareDrive(disk, priv->qemuCaps)))
|
||||
goto error;
|
||||
|
||||
if (!(data = qemuBuildStorageSourceAttachPrepareDrive(disk, priv->qemuCaps)))
|
||||
if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, data) < 0)
|
||||
goto error;
|
||||
|
||||
if (disk->src->haveTLS == VIR_TRISTATE_BOOL_YES &&
|
||||
@ -465,10 +461,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
||||
qemuMonitorAddObject(priv->mon, &managedPrmgrProps, &managedPrmgrAlias) < 0)
|
||||
goto exit_monitor;
|
||||
|
||||
if (unmanagedPrmgrProps &&
|
||||
qemuMonitorAddObject(priv->mon, &unmanagedPrmgrProps, &unmanagedPrmgrAlias) < 0)
|
||||
goto exit_monitor;
|
||||
|
||||
if (qemuBlockStorageSourceAttachApply(priv->mon, data) < 0)
|
||||
goto exit_monitor;
|
||||
|
||||
@ -488,12 +480,10 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
||||
cleanup:
|
||||
qemuBlockStorageSourceAttachDataFree(data);
|
||||
virJSONValueFree(managedPrmgrProps);
|
||||
virJSONValueFree(unmanagedPrmgrProps);
|
||||
virJSONValueFree(encobjProps);
|
||||
virJSONValueFree(secobjProps);
|
||||
qemuDomainSecretDiskDestroy(disk);
|
||||
VIR_FREE(managedPrmgrAlias);
|
||||
VIR_FREE(unmanagedPrmgrAlias);
|
||||
VIR_FREE(secobjAlias);
|
||||
VIR_FREE(encobjAlias);
|
||||
VIR_FREE(devstr);
|
||||
@ -508,8 +498,6 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
||||
ignore_value(qemuMonitorDelObject(priv->mon, secobjAlias));
|
||||
if (encobjAlias)
|
||||
ignore_value(qemuMonitorDelObject(priv->mon, encobjAlias));
|
||||
if (unmanagedPrmgrAlias)
|
||||
ignore_value(qemuMonitorDelObject(priv->mon, unmanagedPrmgrAlias));
|
||||
if (managedPrmgrAlias)
|
||||
ignore_value(qemuMonitorDelObject(priv->mon, managedPrmgrAlias));
|
||||
if (disk->src->tlsAlias)
|
||||
|
Loading…
Reference in New Issue
Block a user