Libvirt provides a portable, long term stable C API for managing the virtualization technologies provided by many operating systems. It includes support for QEMU, KVM, Xen, LXC, bhyve, Virtuozzo, VMware vCenter and ESX, VMware Desktop, Hyper-V, VirtualBox and the POWER Hypervisor.
Go to file
Christophe Fergeau defa8b8589 events: Fix domain event race on client disconnect
GNOME Boxes sometimes stops getting domain events from libvirtd, even
after restarting it. Further investigation in libvirtd shows that
events are properly queued with virDomainEventStateQueue, but the
timer virDomainEventTimer which flushes the events and sends them to
the clients never gets called. Looking at the event queue in gdb
shows that it's non-empty and that its size increases with each new
events.

virDomainEventTimer is set up in virDomainEventStateRegister[ID]
when going from 0 client connecte to 1 client connected, but is
initially disabled. The timer is removed in
virDomainEventStateRegister[ID] when the last client is disconnected
(going from 1 client connected to 0).

This timer (which handles sending the events to the clients) is
enabled in virDomainEventStateQueue when queueing an event on an
empty queue (queue containing 0 events). It's disabled in
virDomainEventStateFlush after flushing the queue (ie removing all
the elements from it). This way, no extra work is done when the queue
is empty, and when the next event comes up, the timer will get
reenabled because the queue will go from 0 event to 1 event, which
triggers enabling the timer.

However, with this Boxes bug, we have a client connected (Boxes), a
non-empty queue (there are events waiting to be sent), but a disabled
timer, so something went wrong.

When Boxes connects (it's the only client connecting to the libvirtd
instance I used for debugging), the event timer is not set as expected
(state->timer == -1 when virDomainEventStateRegisterID is called),
but at the same time the event queue is not empty. In other words,
we had no clients connected, but pending events. This also explains
why the timer never gets enabled as this is only done when an event
is queued on an empty queue.

I think this can happen if an event gets queued using
virDomainEventStateQueue and the client disconnection happens before
the event timer virDomainEventTimer gets a chance to run and flush
the event. In this situation, virDomainEventStateDeregister[ID] will
get called with a non-empty event queue, the timer will be destroyed
if this was the only client connected. Then, when other clients connect
at a later time, they will never get notified about domain events as
the event timer will never get enabled because the timer is only
enabled if the event queue is empty when virDomainEventStateRegister[ID]
gets called, which will is no longer the case.

To avoid this issue, this commit makes sure to remove all events from
the event queue when the last client in unregistered. As there is
no longer anyone interested in receiving these events, these events
are stale so there is no need to keep them around. A client connecting
later will have no interest in getting events that happened before it
got connected.
2012-09-07 14:45:00 +02:00
.gnulib@440a1dbe52 build: improved handling of <execinfo.h>, BSD <net/if.h> 2012-09-06 10:08:47 -06:00
build-aux Remove tabs from all perl files & enforce this 2012-07-30 13:09:57 +01:00
daemon Fix PMSuspend and PMWakeup events 2012-09-07 09:38:22 +02:00
docs build: don't fail when xsltproc is missing 2012-09-05 12:05:55 -06:00
examples examples: Fix event detail printing in python test 2012-09-07 09:38:22 +02:00
gnulib build: fix fresh checkout on RHEL5 2012-04-19 17:11:43 -06:00
include Add PMSUSPENDED life cycle event 2012-09-07 09:38:22 +02:00
m4 build: avoid warnings from gcc 4.2.1 2012-09-05 12:05:55 -06:00
po Release of libvirt-0.10.1 2012-08-31 20:41:06 +08:00
python Fix PMSuspend and PMWakeup events 2012-09-07 09:38:22 +02:00
src events: Fix domain event race on client disconnect 2012-09-07 14:45:00 +02:00
tests Introduce a test suite for the JSON monitor 2012-09-07 13:18:09 +01:00
tools virsh: Update only changed scheduler tunables 2012-09-07 08:08:37 +02:00
.dir-locals.el build: avoid tabs that failed syntax-check 2012-09-06 09:43:46 -06:00
.gitignore Introduce a test suite for the JSON monitor 2012-09-07 13:18:09 +01:00
.gitmodules make .gnulib a submodule 2009-07-08 16:17:51 +02:00
.mailmap build: fix author of previous commit 2012-08-09 15:39:34 -06:00
AUTHORS Pass a correct pointer type to localtime_r(3). 2012-09-04 17:20:08 -06:00
autobuild.sh Switch automated builds to use Mingw64 toolchain instead of Mingw32 2012-06-25 10:41:10 +01:00
autogen.sh Allow NOCONFIGURE=1 to make autogen.sh skip ./configure 2012-06-25 10:41:10 +01:00
bootstrap maint: regenerate bootstrap 2012-07-27 09:34:04 -06:00
bootstrap.conf build: improved handling of <execinfo.h>, BSD <net/if.h> 2012-09-06 10:08:47 -06:00
cfg.mk Add helper library for testing the qemu monitor code 2012-09-07 13:18:04 +01:00
ChangeLog-old virterror.c: Fix several spelling mistakes 2012-02-03 11:32:51 -07:00
configure.ac build: improved handling of <execinfo.h>, BSD <net/if.h> 2012-09-06 10:08:47 -06:00
COPYING.LIB remove all trailing blank lines 2009-07-16 15:06:42 +02:00
HACKING docs: Improve patch submission guidelines 2012-07-16 11:05:12 +02:00
libvirt.pc.in build: silence warning from autoconf 2012-05-30 09:22:02 -06:00
libvirt.spec.in Fix location of SELinux mount during RPM builds 2012-09-07 13:31:00 +01:00
Makefile.am Switch automated builds to use Mingw64 toolchain instead of Mingw32 2012-06-25 10:41:10 +01:00
Makefile.nonreentrant Ban use of all inet_* functions 2010-10-22 11:59:23 +01:00
mingw-libvirt.spec.in parallels: add driver skeleton 2012-08-01 11:44:26 +08:00
README Correct typos in the documentation (Atsushi SAKAI) 2008-01-24 10:15:13 +00:00
README-hacking maint: relax git minimum version 2010-02-24 14:29:27 -05:00
TODO Update todo list file to point at bugzilla/website 2010-10-13 16:45:26 +01:00

         LibVirt : simple API for virtualization

  Libvirt is a C toolkit to interact with the virtualization capabilities
of recent versions of Linux (and other OSes). It is free software
available under the GNU Lesser General Public License. Virtualization of
the Linux Operating System means the ability to run multiple instances of
Operating Systems concurrently on a single hardware system where the basic
resources are driven by a Linux instance. The library aim at providing
long term stable C API initially for the Xen paravirtualization but
should be able to integrate other virtualization mechanisms if needed.

Daniel Veillard <veillard@redhat.com>