From patchwork Tue Jun 14 19:59:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 9176755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9C92560573 for ; Tue, 14 Jun 2016 20:00:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8F00727E78 for ; Tue, 14 Jun 2016 20:00:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 831A62823D; Tue, 14 Jun 2016 20:00:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F38A827E78 for ; Tue, 14 Jun 2016 20:00:18 +0000 (UTC) Received: from localhost ([::1]:37795 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCuVW-0005wn-4T for patchwork-qemu-devel@patchwork.kernel.org; Tue, 14 Jun 2016 16:00:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCuUx-0005t4-4x for qemu-devel@nongnu.org; Tue, 14 Jun 2016 15:59:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCuUw-0001Qm-8U for qemu-devel@nongnu.org; Tue, 14 Jun 2016 15:59:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33365) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCuUw-0001QX-0O for qemu-devel@nongnu.org; Tue, 14 Jun 2016 15:59:42 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8224D73059; Tue, 14 Jun 2016 19:59:41 +0000 (UTC) Received: from redhat.com (unused [10.16.197.238] (may be forged)) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5EJxevd021847; Tue, 14 Jun 2016 15:59:40 -0400 Date: Tue, 14 Jun 2016 22:59:40 +0300 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <20160614225940-mutt-send-email-mst@redhat.com> References: <1465934227-16558-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1465934227-16558-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 14 Jun 2016 19:59:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL v2 05/32] qemu-char: add qemu_chr_disconnect to close a fd accepted by listen fd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , Yuanhan Liu , Victor Kaplansky , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Tetsuya Mukawa , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Tetsuya Mukawa The patch introduces qemu_chr_disconnect(). The function is used for closing a fd accepted by listen fd. Though we already have qemu_chr_delete(), but it closes not only accepted fd but also listen fd. This new function is used when we still want to keep listen fd. Signed-off-by: Tetsuya Mukawa Reviewed-by: Marc-André Lureau Tested-by: Yuanhan Liu Reviewed-by: Yuanhan Liu Reviewed-by: Victor Kaplansky Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/sysemu/char.h | 7 +++++++ qemu-char.c | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 372a6fd..1eb2d0f 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -75,6 +75,7 @@ struct CharDriverState { IOReadHandler *chr_read; void *handler_opaque; void (*chr_close)(struct CharDriverState *chr); + void (*chr_disconnect)(struct CharDriverState *chr); void (*chr_accept_input)(struct CharDriverState *chr); void (*chr_set_echo)(struct CharDriverState *chr, bool echo); void (*chr_set_fe_open)(struct CharDriverState *chr, int fe_open); @@ -143,6 +144,12 @@ void qemu_chr_parse_common(QemuOpts *opts, ChardevCommon *backend); */ CharDriverState *qemu_chr_new(const char *label, const char *filename, void (*init)(struct CharDriverState *s)); +/** + * @qemu_chr_disconnect: + * + * Close a fd accpeted by character backend. + */ +void qemu_chr_disconnect(CharDriverState *chr); /** * @qemu_chr_new_noreplay: diff --git a/qemu-char.c b/qemu-char.c index b13ecbb..e312777 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -4012,6 +4012,13 @@ void qemu_chr_fe_release(CharDriverState *s) s->avail_connections++; } +void qemu_chr_disconnect(CharDriverState *chr) +{ + if (chr->chr_disconnect) { + chr->chr_disconnect(chr); + } +} + static void qemu_chr_free_common(CharDriverState *chr) { g_free(chr->filename); @@ -4389,6 +4396,7 @@ static CharDriverState *qmp_chardev_open_socket(const char *id, chr->chr_write = tcp_chr_write; chr->chr_sync_read = tcp_chr_sync_read; chr->chr_close = tcp_chr_close; + chr->chr_disconnect = tcp_chr_disconnect; chr->get_msgfds = tcp_get_msgfds; chr->set_msgfds = tcp_set_msgfds; chr->chr_add_client = tcp_chr_add_client;