#include "virprobe.h"
#include "virstring.h"
#include "cpu/cpu_x86.h"
+#include "c-strcasestr.h"
#ifdef WITH_DTRACE_PROBES
# include "libvirt_qemu_probes.h"
}
+/**
+ * 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,
const char *dev_name,
bool force)
if (ret == 0)
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(reply);
return ret;
}
+/**
+ * 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,
const char *dev_name,
bool force)
* device not found, device is locked ...
* No message is printed on success it seems */
if (c_strcasestr(reply, "device ")) {
+ if (c_strcasestr(reply, "is locked"))
+ ret = -2;
virReportError(VIR_ERR_OPERATION_FAILED,
_("could not eject media on %s: %s"), dev_name, reply);
goto cleanup;