提交 83fe11e9 编写于 作者: P Peter Krempa

qemu: hotplug: Make qemuHotplugWaitForTrayEject reusable

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: NPeter Krempa <pkrempa@redhat.com>
Reviewed-by: NJán Tomko <jtomko@redhat.com>
上级 22480cf9
...@@ -155,10 +155,8 @@ qemuHotplugPrepareDiskAccess(virQEMUDriverPtr driver, ...@@ -155,10 +155,8 @@ qemuHotplugPrepareDiskAccess(virQEMUDriverPtr driver,
static int static int
qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, qemuHotplugWaitForTrayEject(virDomainObjPtr vm,
virDomainObjPtr vm, virDomainDiskDefPtr disk)
virDomainDiskDefPtr disk,
const char *driveAlias)
{ {
unsigned long long now; unsigned long long now;
int rc; int rc;
...@@ -174,19 +172,14 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, ...@@ -174,19 +172,14 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver,
/* the caller called qemuMonitorEjectMedia which usually reports an /* the caller called qemuMonitorEjectMedia which usually reports an
* error. Report the failure in an off-chance that it didn't. */ * error. Report the failure in an off-chance that it didn't. */
if (virGetLastErrorCode() == VIR_ERR_OK) { if (virGetLastErrorCode() == VIR_ERR_OK) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_OPERATION_FAILED,
_("timed out waiting for disk tray status update")); _("timed out waiting to open tray of '%s'"),
disk->dst);
} }
return -1; 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; return 0;
} }
...@@ -242,9 +235,16 @@ qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver, ...@@ -242,9 +235,16 @@ qemuDomainChangeMediaLegacy(virQEMUDriverPtr driver,
/* If the tray is present and tray change event is supported wait for it to open. */ /* If the tray is present and tray change event is supported wait for it to open. */
if (!force && diskPriv->tray && if (!force && diskPriv->tray &&
virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) { virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) {
rc = qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias); rc = qemuHotplugWaitForTrayEject(vm, disk);
if (rc < 0) if (rc < 0)
goto cleanup; 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 { } 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册