From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:44153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szegq-0001NZ-QC for qemu-devel@nongnu.org; Thu, 09 Aug 2012 22:11:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Szego-0002WD-G8 for qemu-devel@nongnu.org; Thu, 09 Aug 2012 22:11:04 -0400 Received: from e3.ny.us.ibm.com ([32.97.182.143]:48361) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Szego-0002VV-Bg for qemu-devel@nongnu.org; Thu, 09 Aug 2012 22:11:02 -0400 Received: from /spool/local by e3.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 9 Aug 2012 22:11:01 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 106996E8044 for ; Thu, 9 Aug 2012 22:10:59 -0400 (EDT) Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q7A2AvAa180972 for ; Thu, 9 Aug 2012 22:10:58 -0400 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q7A2AvFM018448 for ; Thu, 9 Aug 2012 20:10:57 -0600 From: Corey Bryant Date: Thu, 9 Aug 2012 22:10:45 -0400 Message-Id: <1344564649-6272-4-git-send-email-coreyb@linux.vnet.ibm.com> In-Reply-To: <1344564649-6272-1-git-send-email-coreyb@linux.vnet.ibm.com> References: <1344564649-6272-1-git-send-email-coreyb@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH v8 3/7] monitor: Clean up fd sets on monitor disconnect List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, libvir-list@redhat.com, Corey Bryant , lcapitulino@redhat.com, pbonzini@redhat.com, eblake@redhat.com Fd sets are shared by all monitor connections. Fd sets are considered to be in use while at least one monitor is connected. When the last monitor disconnects, all fds that are members of an fd set with refcount of zero are closed. This prevents any fd leakage associated with a client disconnect prior to using a passed fd. Signed-off-by: Corey Bryant --- v5: -This patch is new in v5. -This support addresses concerns from v4 regarding fd leakage if the client disconnects unexpectedly. (eblake@redhat.com, kwolf@redhat.com, dberrange@redhat.com) v6: -No changes v7: -Removed monitor_fdsets_set_in_use() function since we now use mon_refcount to determine if fdsets are in use. -Added monitor_fdsets_cleanup() function, and increment/decrement of mon_refcount when monitor connects/disconnects. v8: -Use camel case for structures. (stefanha@linux.vnet.ibm.com) monitor.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/monitor.c b/monitor.c index f9a0577..96aafec 100644 --- a/monitor.c +++ b/monitor.c @@ -2433,6 +2433,16 @@ static void monitor_fdset_cleanup(MonFdset *mon_fdset) } } +static void monitor_fdsets_cleanup(void) +{ + MonFdset *mon_fdset; + MonFdset *mon_fdset_next; + + QLIST_FOREACH_SAFE(mon_fdset, &mon_fdsets, next, mon_fdset_next) { + monitor_fdset_cleanup(mon_fdset); + } +} + AddfdInfo *qmp_add_fd(bool has_fdset_id, int64_t fdset_id, bool has_opaque, const char *opaque, Error **errp) { @@ -4781,9 +4791,12 @@ static void monitor_control_event(void *opaque, int event) data = get_qmp_greeting(); monitor_json_emitter(mon, data); qobject_decref(data); + mon_refcount++; break; case CHR_EVENT_CLOSED: json_message_parser_destroy(&mon->mc->parser); + mon_refcount--; + monitor_fdsets_cleanup(); break; } } @@ -4824,6 +4837,12 @@ static void monitor_event(void *opaque, int event) readline_show_prompt(mon->rs); } mon->reset_seen = 1; + mon_refcount++; + break; + + case CHR_EVENT_CLOSED: + mon_refcount--; + monitor_fdsets_cleanup(); break; } } -- 1.7.10.4