mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
qemu-hotplug: fix eject media
QEMU changed the error message to: "Tray of device 'drive-sata0-0-1' is not open" and they may change the error massage in the future. This updates the code to not depend on the text from the error message but only on error itself. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
dc56475f72
commit
0f4d317204
@ -202,15 +202,14 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
|||||||
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
if (qemuDomainObjExitMonitor(driver, vm) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (rc == -2) {
|
if (rc < 0) {
|
||||||
/* we've already tried, error out */
|
/* we've already tried, error out */
|
||||||
if (ejectRetry)
|
if (ejectRetry)
|
||||||
goto error;
|
goto error;
|
||||||
VIR_DEBUG("tray is locked, wait for the guest to unlock "
|
|
||||||
"the tray and try to eject it again");
|
|
||||||
ejectRetry = true;
|
ejectRetry = true;
|
||||||
} else if (rc < 0) {
|
VIR_DEBUG("tray may be locked, wait for the guest to unlock "
|
||||||
goto error;
|
"the tray and try to eject it again");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virTimeMillisNow(&now) < 0)
|
if (virTimeMillisNow(&now) < 0)
|
||||||
@ -220,7 +219,7 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver,
|
|||||||
if (virDomainObjWaitUntil(vm, now + CHANGE_MEDIA_TIMEOUT) != 0)
|
if (virDomainObjWaitUntil(vm, now + CHANGE_MEDIA_TIMEOUT) != 0)
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
} while (ejectRetry && rc != 0);
|
} while (rc < 0);
|
||||||
|
|
||||||
if (!virStorageSourceIsEmpty(newsrc)) {
|
if (!virStorageSourceIsEmpty(newsrc)) {
|
||||||
if (qemuGetDriveSourceString(newsrc, conn, &sourcestr) < 0)
|
if (qemuGetDriveSourceString(newsrc, conn, &sourcestr) < 0)
|
||||||
|
@ -2272,8 +2272,7 @@ int qemuMonitorJSONSetCPU(qemuMonitorPtr mon,
|
|||||||
* Run QMP command to eject a media from ejectable device.
|
* Run QMP command to eject a media from ejectable device.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* -2 on error, when the tray is locked
|
* -1 on error
|
||||||
* -1 on all other errors
|
|
||||||
* 0 on success
|
* 0 on success
|
||||||
*/
|
*/
|
||||||
int qemuMonitorJSONEjectMedia(qemuMonitorPtr mon,
|
int qemuMonitorJSONEjectMedia(qemuMonitorPtr mon,
|
||||||
@ -2294,15 +2293,6 @@ int qemuMonitorJSONEjectMedia(qemuMonitorPtr mon,
|
|||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = qemuMonitorJSONCheckError(cmd, reply);
|
ret = qemuMonitorJSONCheckError(cmd, reply);
|
||||||
|
|
||||||
if (ret < 0) {
|
|
||||||
virJSONValuePtr error = virJSONValueObjectGet(reply, "error");
|
|
||||||
if (error) {
|
|
||||||
const char *errorStr = virJSONValueObjectGetString(error, "desc");
|
|
||||||
if (errorStr && c_strcasestr(errorStr, "is locked"))
|
|
||||||
ret = -2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virJSONValueFree(cmd);
|
virJSONValueFree(cmd);
|
||||||
virJSONValueFree(reply);
|
virJSONValueFree(reply);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1170,8 +1170,7 @@ int qemuMonitorTextSetCPU(qemuMonitorPtr mon, int cpu, bool online)
|
|||||||
* Run HMP command to eject a media from ejectable device.
|
* Run HMP command to eject a media from ejectable device.
|
||||||
*
|
*
|
||||||
* Returns:
|
* Returns:
|
||||||
* -2 on error, when the tray is locked
|
* -1 on error
|
||||||
* -1 on all other errors
|
|
||||||
* 0 on success
|
* 0 on success
|
||||||
*/
|
*/
|
||||||
int qemuMonitorTextEjectMedia(qemuMonitorPtr mon,
|
int qemuMonitorTextEjectMedia(qemuMonitorPtr mon,
|
||||||
@ -1192,8 +1191,6 @@ int qemuMonitorTextEjectMedia(qemuMonitorPtr mon,
|
|||||||
* device not found, device is locked ...
|
* device not found, device is locked ...
|
||||||
* No message is printed on success it seems */
|
* No message is printed on success it seems */
|
||||||
if (c_strcasestr(reply, "device ")) {
|
if (c_strcasestr(reply, "device ")) {
|
||||||
if (c_strcasestr(reply, "is locked"))
|
|
||||||
ret = -2;
|
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("could not eject media on %s: %s"), dev_name, reply);
|
_("could not eject media on %s: %s"), dev_name, reply);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
Loading…
Reference in New Issue
Block a user