1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-02-21 13:57:43 +03:00

qemu: hotplug: Be explicit about old/new sources when changing media

Some functions require us to replace disk->src with the new source for
them to work properly. To avoid confusion all places which allow
explicit virStorageSource should get the appropriate definition.

The legacy code fortunately does not need anything from the old source
so that does not require modifications.

Blockdev does require the old definition so we'll pass it explicitly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
This commit is contained in:
Peter Krempa 2018-10-04 17:56:46 +02:00
parent 50cb91dbc5
commit f86993112a

View File

@ -625,6 +625,7 @@ qemuHotplugDiskSourceRemove(qemuMonitorPtr mon,
* @driver: qemu driver structure * @driver: qemu driver structure
* @vm: domain definition * @vm: domain definition
* @disk: disk definition to change the source of * @disk: disk definition to change the source of
* @oldsrc: old source definition
* @newsrc: new disk source to change to * @newsrc: new disk source to change to
* @force: force the change of media * @force: force the change of media
* *
@ -639,6 +640,7 @@ static int
qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver, qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver,
virDomainObjPtr vm, virDomainObjPtr vm,
virDomainDiskDefPtr disk, virDomainDiskDefPtr disk,
virStorageSourcePtr oldsrc,
virStorageSourcePtr newsrc, virStorageSourcePtr newsrc,
bool force) bool force)
{ {
@ -646,19 +648,17 @@ qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver,
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk); qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
qemuHotplugDiskSourceDataPtr newbackend = NULL; qemuHotplugDiskSourceDataPtr newbackend = NULL;
qemuHotplugDiskSourceDataPtr oldbackend = NULL; qemuHotplugDiskSourceDataPtr oldbackend = NULL;
virStorageSourcePtr oldsrc = disk->src;
char *nodename = NULL; char *nodename = NULL;
int rc; int rc;
int ret = -1; int ret = -1;
if (!virStorageSourceIsEmpty(disk->src) && if (!virStorageSourceIsEmpty(oldsrc) &&
!(oldbackend = qemuHotplugDiskSourceRemovePrepare(disk, disk->src, !(oldbackend = qemuHotplugDiskSourceRemovePrepare(disk, oldsrc,
priv->qemuCaps))) priv->qemuCaps)))
goto cleanup; goto cleanup;
disk->src = newsrc; if (!virStorageSourceIsEmpty(newsrc)) {
if (!virStorageSourceIsEmpty(disk->src)) { if (!(newbackend = qemuHotplugDiskSourceAttachPrepare(disk, newsrc,
if (!(newbackend = qemuHotplugDiskSourceAttachPrepare(disk, disk->src,
priv->qemuCaps))) priv->qemuCaps)))
goto cleanup; goto cleanup;
@ -704,8 +704,6 @@ qemuDomainChangeMediaBlockdev(virQEMUDriverPtr driver,
qemuHotplugDiskSourceDataFree(newbackend); qemuHotplugDiskSourceDataFree(newbackend);
qemuHotplugDiskSourceDataFree(oldbackend); qemuHotplugDiskSourceDataFree(oldbackend);
VIR_FREE(nodename); VIR_FREE(nodename);
/* caller handles correct exchange of sources */
disk->src = oldsrc;
return ret; return ret;
} }
@ -743,7 +741,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
goto cleanup; goto cleanup;
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV)) if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
rc = qemuDomainChangeMediaBlockdev(driver, vm, disk, newsrc, force); rc = qemuDomainChangeMediaBlockdev(driver, vm, disk, disk->src, newsrc, force);
else else
rc = qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force); rc = qemuDomainChangeMediaLegacy(driver, vm, disk, newsrc, force);