[libvirt] [PATCH] blockjob: Report correct error when missing qemu support

2011-08-22 Thread Adam Litke
When executing blockjob monitor commands, we are not checking for
CommandNotFound errors.  This results in 'unexpected error' messages when using
a qemu without support for the required commands.  Fix this up by checking for
CommandNotFound errors for QMP and detecting this condition for the text
monitor.

This fixes the problem reported in Bug 727502.

Signed-off-by: Adam Litke a...@us.ibm.com
---
 src/qemu/qemu_monitor_json.c |3 +++
 src/qemu/qemu_monitor_text.c |   20 
 2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 7adfb26..4c8a08b 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -2939,6 +2939,9 @@ int qemuMonitorJSONBlockJob(qemuMonitorPtr mon,
 else if (qemuMonitorJSONHasError(reply, NotSupported))
 qemuReportError(VIR_ERR_OPERATION_INVALID,
 _(Operation is not supported for device: %s), device);
+else if (qemuMonitorJSONHasError(reply, CommandNotFound))
+qemuReportError(VIR_ERR_OPERATION_INVALID, %s,
+_(Operation is not supported));
 else
 qemuReportError(VIR_ERR_INTERNAL_ERROR, %s,
 _(Unexpected error));
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 52d924a..d9cad2d 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -271,6 +271,19 @@ qemuMonitorTextCommandWithFd(qemuMonitorPtr mon,
  scm_fd, reply);
 }
 
+/* Check monitor output for evidence that the command was not recognized.
+ * For 'info' commands, qemu returns help text.  For other commands, qemu
+ * returns 'unknown command:'.
+ */
+static int
+qemuMonitorTextCommandNotFound(const char *reply)
+{
+if (strstr(reply, unknown command:))
+return 1;
+if (strstr(reply, info version  -- show the version of QEMU))
+return 1;
+return 0;
+}
 
 static int
 qemuMonitorSendDiskPassphrase(qemuMonitorPtr mon,
@@ -3056,6 +3069,13 @@ int qemuMonitorTextBlockJob(qemuMonitorPtr mon,
 goto cleanup;
 }
 
+if (qemuMonitorTextCommandNotFound(reply)) {
+qemuReportError(VIR_ERR_OPERATION_INVALID, %s,
+_(Operation is not supported));
+ret = -1;
+goto cleanup;
+}
+
 ret = qemuMonitorTextParseBlockJob(reply, device, info);
 
 cleanup:
-- 
1.7.3

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] blockjob: Report correct error when missing qemu support

2011-08-22 Thread Eric Blake

On 08/22/2011 09:45 AM, Adam Litke wrote:

When executing blockjob monitor commands, we are not checking for
CommandNotFound errors.  This results in 'unexpected error' messages when using
a qemu without support for the required commands.  Fix this up by checking for
CommandNotFound errors for QMP and detecting this condition for the text
monitor.

This fixes the problem reported in Bug 727502.

Signed-off-by: Adam Litkea...@us.ibm.com
---
  src/qemu/qemu_monitor_json.c |3 +++
  src/qemu/qemu_monitor_text.c |   20 
  2 files changed, 23 insertions(+), 0 deletions(-)


Hmm, I like the factorization into qemuMonitorTextCommandNotFound() a 
little better than Osier's patch for the same issue:

https://www.redhat.com/archives/libvir-list/2011-August/msg00963.html

But I like Osier's approach of listing which command was not found 
better than this one.



+++ b/src/qemu/qemu_monitor_text.c
@@ -271,6 +271,19 @@ qemuMonitorTextCommandWithFd(qemuMonitorPtr mon,
   scm_fd, reply);
  }

+/* Check monitor output for evidence that the command was not recognized.
+ * For 'info' commands, qemu returns help text.  For other commands, qemu
+ * returns 'unknown command:'.
+ */
+static int
+qemuMonitorTextCommandNotFound(const char *reply)
+{
+if (strstr(reply, unknown command:))
+return 1;
+if (strstr(reply, info version  -- show the version of QEMU))


This seems too specific.  Isn't it better to just check for info 
version, in case the text on the rest of the line changes over time?


Can you coordinate with Osier, and agree on a single patch between the 
two of you?


--
Eric Blake   ebl...@redhat.com+1-801-349-2682
Libvirt virtualization library http://libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list