From patchwork Mon Jul 23 13:08:02 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Corey Bryant X-Patchwork-Id: 172673 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DB4862C0337 for ; Mon, 23 Jul 2012 23:08:57 +1000 (EST) Received: from localhost ([::1]:44127 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StINb-0003GB-S8 for incoming@patchwork.ozlabs.org; Mon, 23 Jul 2012 09:08:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StINL-0002zi-5p for qemu-devel@nongnu.org; Mon, 23 Jul 2012 09:08:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StINF-000761-4O for qemu-devel@nongnu.org; Mon, 23 Jul 2012 09:08:39 -0400 Received: from e9.ny.us.ibm.com ([32.97.182.139]:51599) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StINE-00073v-Us for qemu-devel@nongnu.org; Mon, 23 Jul 2012 09:08:33 -0400 Received: from /spool/local by e9.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 23 Jul 2012 09:08:22 -0400 Received: from d01dlp03.pok.ibm.com (9.56.224.17) by e9.ny.us.ibm.com (192.168.1.109) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 23 Jul 2012 09:08:20 -0400 Received: from d01relay04.pok.ibm.com (d01relay04.pok.ibm.com [9.56.227.236]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id DAE93C90021 for ; Mon, 23 Jul 2012 09:08:19 -0400 (EDT) Received: from d03av03.boulder.ibm.com (d03av03.boulder.ibm.com [9.17.195.169]) by d01relay04.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q6ND8I0L371398 for ; Mon, 23 Jul 2012 09:08:19 -0400 Received: from d03av03.boulder.ibm.com (loopback [127.0.0.1]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q6ND8IRT020149 for ; Mon, 23 Jul 2012 07:08:18 -0600 Received: from localhost ([9.80.86.136]) by d03av03.boulder.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q6ND8HQv020085; Mon, 23 Jul 2012 07:08:18 -0600 From: Corey Bryant To: qemu-devel@nongnu.org Date: Mon, 23 Jul 2012 09:08:02 -0400 Message-Id: <1343048885-1701-4-git-send-email-coreyb@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1343048885-1701-1-git-send-email-coreyb@linux.vnet.ibm.com> References: <1343048885-1701-1-git-send-email-coreyb@linux.vnet.ibm.com> X-Content-Scanned: Fidelis XPS MAILER x-cbid: 12072313-7182-0000-0000-0000020CAF5F X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.182.139 Cc: kwolf@redhat.com, aliguori@us.ibm.com, stefanha@linux.vnet.ibm.com, libvir-list@redhat.com, Corey Bryant , lcapitulino@redhat.com, eblake@redhat.com Subject: [Qemu-devel] [PATCH v5 3/6] monitor: Clean up fd sets on monitor disconnect X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Each fd set has a boolean that keeps track of whether or not the fd set is in use by a monitor connection. When a 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. 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) Signed-off-by: Corey Bryant --- monitor.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/monitor.c b/monitor.c index e27dbbe..30b085f 100644 --- a/monitor.c +++ b/monitor.c @@ -2538,6 +2538,19 @@ FdsetInfoList *qmp_query_fdsets(Error **errp) return fdset_list; } +static void monitor_fdsets_set_in_use(Monitor *mon, bool in_use) +{ + mon_fdset_t *mon_fdset; + mon_fdset_t *mon_fdset_next; + + QLIST_FOREACH_SAFE(mon_fdset, &mon->fdsets, next, mon_fdset_next) { + mon_fdset->in_use = in_use; + if (!in_use) { + monitor_fdset_cleanup(mon_fdset); + } + } +} + /* mon_cmds and info_cmds would be sorted at runtime */ static mon_cmd_t mon_cmds[] = { #include "hmp-commands.h" @@ -4751,9 +4764,11 @@ static void monitor_control_event(void *opaque, int event) data = get_qmp_greeting(); monitor_json_emitter(mon, data); qobject_decref(data); + monitor_fdsets_set_in_use(mon, true); break; case CHR_EVENT_CLOSED: json_message_parser_destroy(&mon->mc->parser); + monitor_fdsets_set_in_use(mon, false); break; } }