monitor: maintain at most one G_IO_OUT watch
commit293d2a0014a0e849477413f55aaa05f2743b2e04
authorLaszlo Ersek <lersek@redhat.com>
Tue, 16 Jul 2013 18:19:41 +0000 (16 20:19 +0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Thu, 18 Jul 2013 16:22:57 +0000 (18 11:22 -0500)
treefe9d005b60aa177949eeb1e2756fe2bd5d1fab2c
parentac8c26f633b01bb32cdf347f9dbd5a80c6712925
monitor: maintain at most one G_IO_OUT watch

When monitor_flush() is invoked repeatedly outside the monitor_unblocked()
callback, for example from tlb_info() -> ... -> print_pte(), several
watches may be added for the same event.

This is no problem per se because the extra monitor_unblocked() callbacks
are harmless if mon->outbuf is empty, the watches will be removed
gradually. However a big number of watches can grow "gpollfds" without
limit in glib_pollfds_fill(), triggering a -1/EINVAL condition in
g_poll().

Keep at most one such watch, by following the pattern observable in eg.
commits c874ea97 and c3d6b96e. The change has no effect when
monitor_unblocked() calls monitor_flush() (when the watch can either be
removed or renewed 1-for-1), but non-callback contexts won't create an
additional watch when the monitor already has one.

Related RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=970047

Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Amit Shah <amit.shah@redhat.com>
Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
Message-id: 1373998781-29561-3-git-send-email-lersek@redhat.com
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
monitor.c