mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-05 04:25:19 +00:00
qemu: hotplug: Simplify cleanup in qemuDomainChangeMediaLegacy
Switch to using VIR_AUTOFREE and remove the cleanup label. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
f709377301
commit
5ef886e9bc
@ -258,48 +258,48 @@ qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver,
|
|||||||
virStorageSourcePtr newsrc,
|
virStorageSourcePtr newsrc,
|
||||||
bool force)
|
bool force)
|
||||||
{
|
{
|
||||||
int ret = -1, rc;
|
int rc;
|
||||||
char *driveAlias = NULL;
|
VIR_AUTOFREE(char *) driveAlias = NULL;
|
||||||
qemuDomainObjPrivatePtr priv = vm->privateData;
|
qemuDomainObjPrivatePtr priv = vm->privateData;
|
||||||
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
|
||||||
const char *format = NULL;
|
const char *format = NULL;
|
||||||
char *sourcestr = NULL;
|
VIR_AUTOFREE(char *) sourcestr = NULL;
|
||||||
|
|
||||||
if (!disk->info.alias) {
|
if (!disk->info.alias) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
_("missing disk device alias name for %s"), disk->dst);
|
_("missing disk device alias name for %s"), disk->dst);
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(driveAlias = qemuAliasDiskDriveFromDisk(disk)))
|
if (!(driveAlias = qemuAliasDiskDriveFromDisk(disk)))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
rc = qemuMonitorEjectMedia(priv->mon, driveAlias, force);
|
rc = qemuMonitorEjectMedia(priv->mon, driveAlias, force);
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* If the tray is present wait for it to open. */
|
/* If the tray is present wait for it to open. */
|
||||||
if (!force && diskPriv->tray) {
|
if (!force && diskPriv->tray) {
|
||||||
rc = qemuHotplugWaitForTrayEject(vm, disk);
|
rc = qemuHotplugWaitForTrayEject(vm, disk);
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* re-issue ejection command to pop out the media */
|
/* re-issue ejection command to pop out the media */
|
||||||
qemuDomainObjEnterMonitor(driver, vm);
|
qemuDomainObjEnterMonitor(driver, vm);
|
||||||
rc = qemuMonitorEjectMedia(priv->mon, driveAlias, false);
|
rc = qemuMonitorEjectMedia(priv->mon, driveAlias, false);
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
/* otherwise report possible errors from the attempt to eject the media*/
|
/* otherwise report possible errors from the attempt to eject the media*/
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virStorageSourceIsEmpty(newsrc)) {
|
if (!virStorageSourceIsEmpty(newsrc)) {
|
||||||
if (qemuGetDriveSourceString(newsrc, NULL, &sourcestr) < 0)
|
if (qemuGetDriveSourceString(newsrc, NULL, &sourcestr) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR)
|
if (virStorageSourceGetActualType(newsrc) != VIR_STORAGE_TYPE_DIR)
|
||||||
format = virStorageFileFormatTypeToString(newsrc->format);
|
format = virStorageFileFormatTypeToString(newsrc->format);
|
||||||
@ -310,18 +310,13 @@ qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver,
|
|||||||
sourcestr,
|
sourcestr,
|
||||||
format);
|
format);
|
||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rc < 0)
|
if (rc < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
|
|
||||||
cleanup:
|
|
||||||
VIR_FREE(driveAlias);
|
|
||||||
VIR_FREE(sourcestr);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user