mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-30 01:43:23 +00:00
monitor: detect that eject fails because the tray is locked
Modify the eject monitor functions to parse the return code and detect, whether the error contains "is locked" to report this type of failure to upper layers. Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
6b278f3ad6
commit
256496e149
@ -44,6 +44,7 @@
|
|||||||
#include "virprobe.h"
|
#include "virprobe.h"
|
||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "cpu/cpu_x86.h"
|
#include "cpu/cpu_x86.h"
|
||||||
|
#include "c-strcasestr.h"
|
||||||
|
|
||||||
#ifdef WITH_DTRACE_PROBES
|
#ifdef WITH_DTRACE_PROBES
|
||||||
# include "libvirt_qemu_probes.h"
|
# include "libvirt_qemu_probes.h"
|
||||||
@ -2180,6 +2181,14 @@ int qemuMonitorJSONSetCPU(qemuMonitorPtr mon,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run QMP command to eject a media from ejectable device.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* -2 on error, when the tray is locked
|
||||||
|
* -1 on all other errors
|
||||||
|
* 0 on success
|
||||||
|
*/
|
||||||
int qemuMonitorJSONEjectMedia(qemuMonitorPtr mon,
|
int qemuMonitorJSONEjectMedia(qemuMonitorPtr mon,
|
||||||
const char *dev_name,
|
const char *dev_name,
|
||||||
bool force)
|
bool force)
|
||||||
@ -2198,6 +2207,11 @@ int qemuMonitorJSONEjectMedia(qemuMonitorPtr mon,
|
|||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
ret = qemuMonitorJSONCheckError(cmd, reply);
|
ret = qemuMonitorJSONCheckError(cmd, reply);
|
||||||
|
|
||||||
|
VIR_DEBUG("%s", virJSONValueToString(reply, false));
|
||||||
|
|
||||||
|
if (ret < 0 && c_strcasestr(virJSONValueToString(reply, false), "is locked"))
|
||||||
|
ret = -2;
|
||||||
|
|
||||||
virJSONValueFree(cmd);
|
virJSONValueFree(cmd);
|
||||||
virJSONValueFree(reply);
|
virJSONValueFree(reply);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -1169,6 +1169,14 @@ int qemuMonitorTextSetCPU(qemuMonitorPtr mon, int cpu, bool online)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Run HMP command to eject a media from ejectable device.
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* -2 on error, when the tray is locked
|
||||||
|
* -1 on all other errors
|
||||||
|
* 0 on success
|
||||||
|
*/
|
||||||
int qemuMonitorTextEjectMedia(qemuMonitorPtr mon,
|
int qemuMonitorTextEjectMedia(qemuMonitorPtr mon,
|
||||||
const char *dev_name,
|
const char *dev_name,
|
||||||
bool force)
|
bool force)
|
||||||
@ -1187,6 +1195,8 @@ 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