[libvirt] [PATCH 02/20] Wait to receive QMP greeting before sending any monitor commands

Daniel P. Berrange berrange at redhat.com
Wed Sep 12 16:37:05 UTC 2012


On Tue, Sep 11, 2012 at 05:34:55PM -0600, Eric Blake wrote:
> On 09/11/2012 05:26 PM, Eric Blake wrote:
> > On 09/11/2012 08:11 AM, Daniel P. Berrange wrote:
> >> From: "Daniel P. Berrange" <berrange at redhat.com>
> >>
> >> Technically speaking we should wait until we receive the QMP
> >> greeting message before attempting to send any QMP monitor
> >> commands. Mostly we've got away with this, but there is a race
> >> in some QEMU which cause it to SEGV if you sent it data too
> >> soon after startup. Waiting for the QMP greeting avoids the
> >> race
> >>
> >> Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
> >> ---
> >>  src/qemu/qemu_monitor.c | 9 ++++++++-
> >>  1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > ACK.
> 
> Spoke too soon. This makes the testsuite hang in qemumonitorjsontest, as
> the fake json monitor never manages to trigger the wait_greeting reset
> to 0.  I'm not sure how best to fix the infloop, but that is needed
> before this patch can go in.

Oh, the fix is to actually send the expected greeting, as a normal QEMU
would :-)

The following patch prevents a hang in the test suite for me. Can you
confirm:

diff --git a/tests/qemumonitortestutils.c b/tests/qemumonitortestutils.c
index 76b11e6..77e9a47 100644
--- a/tests/qemumonitortestutils.c
+++ b/tests/qemumonitortestutils.c
@@ -418,6 +418,9 @@ static qemuMonitorCallbacks qemuCallbacks = {
     .errorNotify = qemuMonitorTestErrorNotify,
 };
 
+#define QEMU_JSON_GREETING "{\"QMP\": {\"version\": {\"qemu\": {\"micro\": 1, \"minor\": 0, \"major\": 1}, \"package\": \" (qemu-kvm-1.0.1)\"}, \"capabilities\
+#define QEMU_TEXT_GREETING "QEMU 1.0,1 monitor - type 'help' for more information"
+
 qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps)
 {
     qemuMonitorTestPtr test;
@@ -468,8 +471,13 @@ qemuMonitorTestPtr qemuMonitorTestNew(bool json, virCapsPtr caps)
     if (!test->client)
         goto error;
 
+    if (qemuMonitorTestAddReponse(test, json ?
+                                  QEMU_JSON_GREETING :
+                                  QEMU_TEXT_GREETING) < 0)
+        goto error;
+
     if (virNetSocketAddIOCallback(test->client,
-                                  VIR_EVENT_HANDLE_READABLE,
+                                  VIR_EVENT_HANDLE_WRITABLE,
                                   qemuMonitorTestIO,
                                   test,
                                   NULL) < 0)



Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list