From 83fe11e950bc639758a984b97ff5052eda92bd97 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 13 Jul 2018 17:55:59 +0200 Subject: [PATCH] qemu: hotplug: Make qemuHotplugWaitForTrayEject reusable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove the issue of the monitor command to the caller so that the function can be used with the modern approach. Additionally improve the error message. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/qemu/qemu_hotplug.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index d1e16fc9d0..f2c29859f9 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -155,10 +155,8 @@ qemuHotplugPrepareDiskAccess(virQEMUDriverPtr driver, static int -qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, - virDomainObjPtr vm, - virDomainDiskDefPtr disk, - const char *driveAlias) +qemuHotplugWaitForTrayEject(virDomainObjPtr vm, + virDomainDiskDefPtr disk) { unsigned long long now; int rc; @@ -174,19 +172,14 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, /* the caller called qemuMonitorEjectMedia which usually reports an * error. Report the failure in an off-chance that it didn't. */ if (virGetLastErrorCode() == VIR_ERR_OK) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("timed out waiting for disk tray status update")); + virReportError(VIR_ERR_OPERATION_FAILED, + _("timed out waiting to open tray of '%s'"), + disk->dst); } return -1; } } - /* re-issue ejection command to pop out the media */ - qemuDomainObjEnterMonitor(driver, vm); - rc = qemuMonitorEjectMedia(qemuDomainGetMonitor(vm), driveAlias, false); - if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) - return -1; - return 0; } @@ -242,9 +235,16 @@ qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver, /* If the tray is present and tray change event is supported wait for it to open. */ if (!force && diskPriv->tray && virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) { - rc = qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias); + rc = qemuHotplugWaitForTrayEject(vm, disk); if (rc < 0) goto cleanup; + + /* re-issue ejection command to pop out the media */ + qemuDomainObjEnterMonitor(driver, vm); + rc = qemuMonitorEjectMedia(priv->mon, driveAlias, false); + if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) + goto cleanup; + } else { /* otherwise report possible errors from the attempt to eject the media*/ if (rc < 0) -- GitLab