[libvirt] [PATCH 2/4] Avoid bogus I/O event errors when closing the QEMU monitor

2012-09-28 Thread Daniel P. Berrange
From: Daniel P. Berrange berra...@redhat.com

After calling qemuMonitorClose(), it is still possible for
the QEMU monitor I/O event callback to get invoked. This
will trigger an error message because mon-fd has been set
to -1 at this point. Silently ignore the case where mon-fd
is -1, likewise for mon-watch being zero.

Signed-off-by: Daniel P. Berrange berra...@redhat.com
---
 src/qemu/qemu_monitor.c | 13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index cb121e8..6c3f09e 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -538,6 +538,9 @@ static void qemuMonitorUpdateWatch(qemuMonitorPtr mon)
 VIR_EVENT_HANDLE_HANGUP |
 VIR_EVENT_HANDLE_ERROR;
 
+if (!mon-watch)
+return;
+
 if (mon-lastError.code == VIR_ERR_OK) {
 events |= VIR_EVENT_HANDLE_READABLE;
 
@@ -563,6 +566,11 @@ qemuMonitorIO(int watch, int fd, int events, void *opaque) 
{
 #if DEBUG_IO
 VIR_DEBUG(Monitor %p I/O on watch %d fd %d events %d, mon, watch, fd, 
events);
 #endif
+if (mon-fd == -1 || mon-watch == 0) {
+qemuMonitorUnlock(mon);
+virObjectUnref(mon);
+return;
+}
 
 if (mon-fd != fd || mon-watch != watch) {
 if (events  (VIR_EVENT_HANDLE_HANGUP | VIR_EVENT_HANDLE_ERROR))
@@ -830,9 +838,12 @@ void qemuMonitorClose(qemuMonitorPtr mon)
   mon=%p refs=%d, mon, mon-object.refs);
 
 if (mon-fd = 0) {
-if (mon-watch)
+if (mon-watch) {
 virEventRemoveHandle(mon-watch);
+mon-watch = 0;
+}
 VIR_FORCE_CLOSE(mon-fd);
+fprintf(stderr, Closing monitr\n);
 }
 
 /* In case another thread is waiting for its monitor command to be
-- 
1.7.11.4

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


Re: [libvirt] [PATCH 2/4] Avoid bogus I/O event errors when closing the QEMU monitor

2012-09-28 Thread Eric Blake
On 09/28/2012 08:58 AM, Daniel P. Berrange wrote:
 From: Daniel P. Berrange berra...@redhat.com
 
 After calling qemuMonitorClose(), it is still possible for
 the QEMU monitor I/O event callback to get invoked. This
 will trigger an error message because mon-fd has been set
 to -1 at this point. Silently ignore the case where mon-fd
 is -1, likewise for mon-watch being zero.
 
 Signed-off-by: Daniel P. Berrange berra...@redhat.com
 ---
  src/qemu/qemu_monitor.c | 13 -
  1 file changed, 12 insertions(+), 1 deletion(-)
 

 @@ -830,9 +838,12 @@ void qemuMonitorClose(qemuMonitorPtr mon)
mon=%p refs=%d, mon, mon-object.refs);
  
  if (mon-fd = 0) {
 -if (mon-watch)
 +if (mon-watch) {
  virEventRemoveHandle(mon-watch);
 +mon-watch = 0;
 +}
  VIR_FORCE_CLOSE(mon-fd);
 +fprintf(stderr, Closing monitr\n);

Oops.

ACK with the debugging cruft elided.

-- 
Eric Blake   ebl...@redhat.com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list