]> xenbits.xensource.com Git - libvirt.git/commitdiff
do not send monitor command after monitor meet error
authorWen Congyang <wency@cn.fujitsu.com>
Wed, 30 Mar 2011 01:43:25 +0000 (09:43 +0800)
committerWen Congyang <wency@cn.fujitsu.com>
Wed, 30 Mar 2011 08:32:22 +0000 (16:32 +0800)
If the monitor met a error, and we will call qemuProcessHandleMonitorEOF().
But we may try to send monitor command after qemuProcessHandleMonitorEOF()
returned. Then libvirtd will be blocked in qemuMonitorSend().

Steps to reproduce this bug:
1. use gdb to attach libvirtd, and set a breakpoint in the function
   qemuConnectMonitor()
2. start a vm
3. let the libvirtd to run until qemuMonitorOpen() returns.
4. kill the qemu process
5. continue running libvirtd

Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
src/qemu/qemu_monitor.c

index 800f7444bfab5be095d74c751619eb563d6f189c..e35906c3cb5ab2382e83620af6a135e576cc2c61 100644 (file)
@@ -587,6 +587,15 @@ qemuMonitorIO(int watch, int fd, int events, void *opaque) {
         void (*eofNotify)(qemuMonitorPtr, virDomainObjPtr, int)
             = mon->cb->eofNotify;
         virDomainObjPtr vm = mon->vm;
+
+        /* If qemu quited unexpectedly, and we may try to send monitor
+         * command later. But we have no chance to wake up it. So set
+         * mon->lastErrno to EIO, and check it before sending monitor
+         * command.
+         */
+        if (!mon->lastErrno)
+            mon->lastErrno = EIO;
+
         /* Make sure anyone waiting wakes up now */
         virCondSignal(&mon->notify);
         if (qemuMonitorUnref(mon) > 0)
@@ -725,6 +734,12 @@ int qemuMonitorSend(qemuMonitorPtr mon,
 {
     int ret = -1;
 
+    /* Check whether qemu quited unexpectedly */
+    if (mon->lastErrno) {
+        msg->lastErrno = mon->lastErrno;
+        return -1;
+    }
+
     mon->msg = msg;
     qemuMonitorUpdateWatch(mon);