qemu: block: Move and rename qemuHotplugRemoveStorageSourcePrepareData

Move it to qemu_block.c and call it qemuBlockStorageSourceDetachPrepare.
It will be reused in other parts as well.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2018-10-10 15:30:24 +02:00
parent 3026f6d9d9
commit fc341eedea
3 changed files with 63 additions and 61 deletions

View File

@ -1565,6 +1565,63 @@ qemuBlockStorageSourceAttachRollback(qemuMonitorPtr mon,
}
/**
* qemuBlockStorageSourceDetachPrepare:
* @src: disk source structure
* @driveAlias: Alias of the -drive backend, the pointer is always consumed
*
* Prepare qemuBlockStorageSourceAttachDataPtr for detaching a single source
* from a VM. If @driveAlias is NULL -blockdev is assumed.
*/
qemuBlockStorageSourceAttachDataPtr
qemuBlockStorageSourceDetachPrepare(virStorageSourcePtr src,
char *driveAlias)
{
qemuDomainStorageSourcePrivatePtr srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data = NULL;
qemuBlockStorageSourceAttachDataPtr ret = NULL;
if (VIR_ALLOC(data) < 0)
goto cleanup;
if (driveAlias) {
VIR_STEAL_PTR(data->driveAlias, driveAlias);
data->driveAdded = true;
} else {
data->formatNodeName = src->nodeformat;
data->formatAttached = true;
data->storageNodeName = src->nodestorage;
data->storageAttached = true;
}
if (src->pr &&
!virStoragePRDefIsManaged(src->pr) &&
VIR_STRDUP(data->prmgrAlias, src->pr->mgralias) < 0)
goto cleanup;
if (VIR_STRDUP(data->tlsAlias, src->tlsAlias) < 0)
goto cleanup;
if (srcpriv) {
if (srcpriv->secinfo &&
srcpriv->secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES &&
VIR_STRDUP(data->authsecretAlias, srcpriv->secinfo->s.aes.alias) < 0)
goto cleanup;
if (srcpriv->encinfo &&
srcpriv->encinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES &&
VIR_STRDUP(data->encryptsecretAlias, srcpriv->encinfo->s.aes.alias) < 0)
goto cleanup;
}
VIR_STEAL_PTR(ret, data);
cleanup:
VIR_FREE(driveAlias);
return ret;
}
/**
* qemuBlockStorageSourceDetachOneBlockdev:
* @driver: qemu driver object

View File

@ -107,6 +107,10 @@ VIR_DEFINE_AUTOPTR_FUNC(qemuBlockStorageSourceAttachData,
qemuBlockStorageSourceAttachDataPtr
qemuBlockStorageSourceAttachPrepareBlockdev(virStorageSourcePtr src);
qemuBlockStorageSourceAttachDataPtr
qemuBlockStorageSourceDetachPrepare(virStorageSourcePtr src,
char *driveAlias);
int
qemuBlockStorageSourceAttachApply(qemuMonitorPtr mon,
qemuBlockStorageSourceAttachDataPtr data);

View File

@ -448,64 +448,6 @@ qemuHotplugDiskSourceDataFree(qemuHotplugDiskSourceDataPtr data)
}
/**
* qemuDomainRemoveDiskStorageSourcePrepareData:
* @src: disk source structure
* @driveAlias: Alias of the -drive backend, the pointer is always consumed
*
* Prepare qemuBlockStorageSourceAttachDataPtr for detaching a single source
* from a VM. If @driveAlias is NULL -blockdev is assumed.
*/
static qemuBlockStorageSourceAttachDataPtr
qemuHotplugRemoveStorageSourcePrepareData(virStorageSourcePtr src,
char *driveAlias)
{
qemuDomainStorageSourcePrivatePtr srcpriv = QEMU_DOMAIN_STORAGE_SOURCE_PRIVATE(src);
VIR_AUTOPTR(qemuBlockStorageSourceAttachData) data = NULL;
qemuBlockStorageSourceAttachDataPtr ret = NULL;
if (VIR_ALLOC(data) < 0)
goto cleanup;
if (driveAlias) {
VIR_STEAL_PTR(data->driveAlias, driveAlias);
data->driveAdded = true;
} else {
data->formatNodeName = src->nodeformat;
data->formatAttached = true;
data->storageNodeName = src->nodestorage;
data->storageAttached = true;
}
if (src->pr &&
!virStoragePRDefIsManaged(src->pr) &&
VIR_STRDUP(data->prmgrAlias, src->pr->mgralias) < 0)
goto cleanup;
if (VIR_STRDUP(data->tlsAlias, src->tlsAlias) < 0)
goto cleanup;
if (srcpriv) {
if (srcpriv->secinfo &&
srcpriv->secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES &&
VIR_STRDUP(data->authsecretAlias, srcpriv->secinfo->s.aes.alias) < 0)
goto cleanup;
if (srcpriv->encinfo &&
srcpriv->encinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES &&
VIR_STRDUP(data->encryptsecretAlias, srcpriv->encinfo->s.aes.alias) < 0)
goto cleanup;
}
VIR_STEAL_PTR(ret, data);
cleanup:
VIR_FREE(driveAlias);
return ret;
}
static qemuHotplugDiskSourceDataPtr
qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
virStorageSourcePtr src,
@ -526,7 +468,7 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
goto cleanup;
for (n = src; virStorageSourceIsBacking(n); n = n->backingStore) {
if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(n, NULL)))
if (!(backend = qemuBlockStorageSourceDetachPrepare(n, NULL)))
goto cleanup;
if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 0)
@ -536,8 +478,7 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
goto cleanup;
if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(src,
drivealias)))
if (!(backend = qemuBlockStorageSourceDetachPrepare(src, drivealias)))
goto cleanup;
if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 0)