render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 0ef69d9942be58851bdbfca900274aa24c871812 Mon Sep 17 00:00:00 2001
Message-Id: <0ef69d9942be58851bdbfca900274aa24c871812@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Fri, 10 Jul 2015 12:39:31 +0200
Subject: [PATCH] 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>
(cherry picked from commit 256496e1499fcc7b20a51919eb4471987a36dbab)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1147471

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_monitor_json.c | 14 ++++++++++++++
 src/qemu/qemu_monitor_text.c | 10 ++++++++++
 2 files changed, 24 insertions(+)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 4323c2a..4040ff0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -44,6 +44,7 @@
 #include "virprobe.h"
 #include "virstring.h"
 #include "cpu/cpu_x86.h"
+#include "c-strcasestr.h"
 
 #ifdef WITH_DTRACE_PROBES
 # include "libvirt_qemu_probes.h"
@@ -2209,6 +2210,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,
                               const char *dev_name,
                               bool force)
@@ -2227,6 +2236,11 @@ int qemuMonitorJSONEjectMedia(qemuMonitorPtr mon,
     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;
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 2e77534..2aa0460 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -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,
                               const char *dev_name,
                               bool force)
@@ -1187,6 +1195,8 @@ int qemuMonitorTextEjectMedia(qemuMonitorPtr mon,
      * 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;
-- 
2.4.5