mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-23 06:05:27 +00:00
qemu: hotplug: Allow specifying explicit source for disk backend hotplug code
Since the code is also used when changing media we need to allow specifying explicit source for which we are going to prepare. With this change callers don't have to replace disk->src with the new source definition for generating these. Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
parent
7fec0e59d3
commit
50cb91dbc5
@ -458,6 +458,7 @@ qemuHotplugRemoveStorageSourcePrepareData(virStorageSourcePtr src,
|
|||||||
|
|
||||||
static qemuHotplugDiskSourceDataPtr
|
static qemuHotplugDiskSourceDataPtr
|
||||||
qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
|
qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
|
||||||
|
virStorageSourcePtr src,
|
||||||
virQEMUCapsPtr qemuCaps)
|
virQEMUCapsPtr qemuCaps)
|
||||||
{
|
{
|
||||||
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
||||||
@ -474,7 +475,7 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
|
|||||||
if (VIR_STRDUP(data->corAlias, diskPriv->nodeCopyOnRead) < 0)
|
if (VIR_STRDUP(data->corAlias, diskPriv->nodeCopyOnRead) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
|
for (n = src; virStorageSourceIsBacking(n); n = n->backingStore) {
|
||||||
if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(n, NULL)))
|
if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(n, NULL)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -485,7 +486,7 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
|
|||||||
if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
|
if (!(drivealias = qemuAliasDiskDriveFromDisk(disk)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(disk->src,
|
if (!(backend = qemuHotplugRemoveStorageSourcePrepareData(src,
|
||||||
drivealias)))
|
drivealias)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -505,6 +506,7 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
|
|||||||
/**
|
/**
|
||||||
* qemuHotplugDiskSourceAttachPrepare:
|
* qemuHotplugDiskSourceAttachPrepare:
|
||||||
* @disk: disk to generate attachment data for
|
* @disk: disk to generate attachment data for
|
||||||
|
* @src: disk source to prepare attachment
|
||||||
* @qemuCaps: capabilities of the qemu process
|
* @qemuCaps: capabilities of the qemu process
|
||||||
*
|
*
|
||||||
* Prepares and returns qemuHotplugDiskSourceData structure filled with all data
|
* Prepares and returns qemuHotplugDiskSourceData structure filled with all data
|
||||||
@ -512,11 +514,13 @@ qemuHotplugDiskSourceRemovePrepare(virDomainDiskDefPtr disk,
|
|||||||
*/
|
*/
|
||||||
static qemuHotplugDiskSourceDataPtr
|
static qemuHotplugDiskSourceDataPtr
|
||||||
qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr disk,
|
qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr disk,
|
||||||
|
virStorageSourcePtr src,
|
||||||
virQEMUCapsPtr qemuCaps)
|
virQEMUCapsPtr qemuCaps)
|
||||||
{
|
{
|
||||||
qemuBlockStorageSourceAttachDataPtr backend = NULL;
|
qemuBlockStorageSourceAttachDataPtr backend = NULL;
|
||||||
qemuHotplugDiskSourceDataPtr data;
|
qemuHotplugDiskSourceDataPtr data;
|
||||||
qemuHotplugDiskSourceDataPtr ret = NULL;
|
qemuHotplugDiskSourceDataPtr ret = NULL;
|
||||||
|
virStorageSourcePtr savesrc = NULL;
|
||||||
virStorageSourcePtr n;
|
virStorageSourcePtr n;
|
||||||
|
|
||||||
if (VIR_ALLOC(data) < 0)
|
if (VIR_ALLOC(data) < 0)
|
||||||
@ -527,7 +531,7 @@ qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr disk,
|
|||||||
!(data->corProps = qemuBlockStorageGetCopyOnReadProps(disk)))
|
!(data->corProps = qemuBlockStorageGetCopyOnReadProps(disk)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
for (n = disk->src; virStorageSourceIsBacking(n); n = n->backingStore) {
|
for (n = src; virStorageSourceIsBacking(n); n = n->backingStore) {
|
||||||
if (!(backend = qemuBlockStorageSourceAttachPrepareBlockdev(n)))
|
if (!(backend = qemuBlockStorageSourceAttachPrepareBlockdev(n)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -538,10 +542,15 @@ qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr disk,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
VIR_STEAL_PTR(savesrc, disk->src);
|
||||||
|
disk->src = src;
|
||||||
|
|
||||||
if (!(backend = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps)))
|
if (!(backend = qemuBuildStorageSourceAttachPrepareDrive(disk, qemuCaps)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (qemuBuildStorageSourceAttachPrepareCommon(disk->src, backend, qemuCaps) < 0)
|
VIR_STEAL_PTR(disk->src, savesrc);
|
||||||
|
|
||||||
|
if (qemuBuildStorageSourceAttachPrepareCommon(src, backend, qemuCaps) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 0)
|
if (VIR_APPEND_ELEMENT(data->backends, data->nbackends, backend) < 0)
|
||||||
@ -551,6 +560,9 @@ qemuHotplugDiskSourceAttachPrepare(virDomainDiskDefPtr disk,
|
|||||||
VIR_STEAL_PTR(ret, data);
|
VIR_STEAL_PTR(ret, data);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
if (savesrc)
|
||||||
|
VIR_STEAL_PTR(disk->src, savesrc);
|
||||||
|
|
||||||
qemuBlockStorageSourceAttachDataFree(backend);
|
qemuBlockStorageSourceAttachDataFree(backend);
|
||||||
qemuHotplugDiskSourceDataFree(data);
|
qemuHotplugDiskSourceDataFree(data);
|
||||||
return ret;
|
return ret;
|
||||||
@ -640,12 +652,13 @@ qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (!virStorageSourceIsEmpty(disk->src) &&
|
if (!virStorageSourceIsEmpty(disk->src) &&
|
||||||
!(oldbackend = qemuHotplugDiskSourceRemovePrepare(disk, priv->qemuCaps)))
|
!(oldbackend = qemuHotplugDiskSourceRemovePrepare(disk, disk->src,
|
||||||
|
priv->qemuCaps)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
disk->src = newsrc;
|
disk->src = newsrc;
|
||||||
if (!virStorageSourceIsEmpty(disk->src)) {
|
if (!virStorageSourceIsEmpty(disk->src)) {
|
||||||
if (!(newbackend = qemuHotplugDiskSourceAttachPrepare(disk,
|
if (!(newbackend = qemuHotplugDiskSourceAttachPrepare(disk, disk->src,
|
||||||
priv->qemuCaps)))
|
priv->qemuCaps)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
@ -782,7 +795,8 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
|
|||||||
if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
|
if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(diskdata = qemuHotplugDiskSourceAttachPrepare(disk, priv->qemuCaps)))
|
if (!(diskdata = qemuHotplugDiskSourceAttachPrepare(disk, disk->src,
|
||||||
|
priv->qemuCaps)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(devstr = qemuBuildDiskDeviceStr(vm->def, disk, 0, priv->qemuCaps)))
|
if (!(devstr = qemuBuildDiskDeviceStr(vm->def, disk, 0, priv->qemuCaps)))
|
||||||
@ -4159,7 +4173,8 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver,
|
|||||||
VIR_DEBUG("Removing disk %s from domain %p %s",
|
VIR_DEBUG("Removing disk %s from domain %p %s",
|
||||||
disk->info.alias, vm, vm->def->name);
|
disk->info.alias, vm, vm->def->name);
|
||||||
|
|
||||||
if (!(diskbackend = qemuHotplugDiskSourceRemovePrepare(disk, priv->qemuCaps)))
|
if (!(diskbackend = qemuHotplugDiskSourceRemovePrepare(disk, disk->src,
|
||||||
|
priv->qemuCaps)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < vm->def->ndisks; i++) {
|
for (i = 0; i < vm->def->ndisks; i++) {
|
||||||
|
Loading…
Reference in New Issue
Block a user