From patchwork Mon Jun 6 16:44:59 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 9158869 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 0450C60572 for ; Mon, 6 Jun 2016 17:10:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E571127B13 for ; Mon, 6 Jun 2016 17:10:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D8CA52834C; Mon, 6 Jun 2016 17:10:01 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 5A23427B13 for ; Mon, 6 Jun 2016 17:10:01 +0000 (UTC) Received: from localhost ([::1]:43998 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9y2K-0006u0-Hm for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Jun 2016 13:10:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9xeQ-00047U-Jm for qemu-devel@nongnu.org; Mon, 06 Jun 2016 12:45:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9xeO-0005XC-Bn for qemu-devel@nongnu.org; Mon, 06 Jun 2016 12:45:17 -0400 Received: from mail-qt0-x243.google.com ([2607:f8b0:400d:c0d::243]:35701) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9xeO-0005Wz-85 for qemu-devel@nongnu.org; Mon, 06 Jun 2016 12:45:16 -0400 Received: by mail-qt0-x243.google.com with SMTP id 37so1669571qtc.2 for ; Mon, 06 Jun 2016 09:45:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nG8KlkyVaTAtzvEeMiUTg58m18TMEu/iDIgyFmlVlRE=; b=qRvuQZKw0xitmquNKyUzaQQGscKxcN6GdRoclWObIgae6Yng1z54GGDQgFKb68EcCb cvmz8jEV+5DMrjhfgN+Z0R6uVQ0Q4ROy5SSZ4MPCIdp4TO3LttS5vfR27wp96ChaWggf /O4k6+8vZamQq5udfSPVs6eWLZBDrEVwrs4wIKwFQY3feeD973Q0/DkeU7pkFchysQVi +yG5IT09guLxN/uXlvK3/KdUFtSZt0FgjbdYmvHIZ0COWaI4fKWjRqsWovPedgtki6ar iBNMQdgNm1B2+UyAD2WyI6/A79NVMecXrpCxQAZLfI1D26jKuWmqNmKQVYKcJGUS3TfC eaaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=nG8KlkyVaTAtzvEeMiUTg58m18TMEu/iDIgyFmlVlRE=; b=UOFg3/YlxfrHJ0t3IXJXbgkO7ZpIVawoYRHzviEuuZ+fg2isS378uCrTgVLBPTaz+H C3iwaPVasMqh173Opr1Cxtt32eqfZ5TWkCtdYEOx7byA7RlT+ta1Ps1deOcbdvEU7qU+ 4a/S1RLiJggjHCoXH8GhVIa8sBz7XYD1wWCe/GcqVD2d+fayepoflhzLE25FMhFXQAbi S/J6Pt9p6iO9z6V0ButO3LHvHEC1vrYeFG7IocciMSpclHSIc3D8xzX+DzS28VO34kXb FYwZY694zRON5pm2LzlhAAWZaymr+QHErl7/sV1d953y5R6LH5UQbNA/0iGWdH7ybTD8 Mjbw== X-Gm-Message-State: ALyK8tJOi/ewJxOz/YM2pkIV2IASB8wp3V2hMbjRSUxat+jG6WJlKEv/4PT2rRxaUO6U+A== X-Received: by 10.237.42.194 with SMTP id t60mr17007997qtd.40.1465231515790; Mon, 06 Jun 2016 09:45:15 -0700 (PDT) Received: from localhost (APoitiers-110-1-1-130.w193-248.abo.wanadoo.fr. [193.248.103.130]) by smtp.gmail.com with ESMTPSA id i63sm5359758qkd.13.2016.06.06.09.45.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jun 2016 09:45:14 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2016 18:44:59 +0200 Message-Id: <1465231508-30183-2-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465231508-30183-1-git-send-email-marcandre.lureau@redhat.com> References: <1465231508-30183-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c0d::243 Subject: [Qemu-devel] [PATCH 01/10] vhost-user: add ability to know vhost-user backend disconnection 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: Tetsuya Mukawa , Ilya Maximets , Yuanhan Liu , jonshin@cisco.com, "Michael S . Tsirkin" 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 Current QEMU cannot detect vhost-user backend disconnection. The patch adds ability to know it. To know disconnection, add watcher to detect G_IO_HUP event. When G_IO_HUP event is detected, the disconnected socket will be read to cause a CHR_EVENT_CLOSED. Signed-off-by: Tetsuya Mukawa Reviewed-by: Marc-André Lureau Tested-by: Yuanhan Liu Reviewed-by: Yuanhan Liu --- net/vhost-user.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/vhost-user.c b/net/vhost-user.c index 1b9e73a..4a7fd5f 100644 --- a/net/vhost-user.c +++ b/net/vhost-user.c @@ -22,6 +22,7 @@ typedef struct VhostUserState { NetClientState nc; CharDriverState *chr; VHostNetState *vhost_net; + int watch; } VhostUserState; typedef struct VhostUserChardevProps { @@ -167,6 +168,20 @@ static NetClientInfo net_vhost_user_info = { .has_ufo = vhost_user_has_ufo, }; +static gboolean net_vhost_user_watch(GIOChannel *chan, GIOCondition cond, + void *opaque) +{ + VhostUserState *s = opaque; + uint8_t buf[1]; + + /* We don't actually want to read anything, but CHR_EVENT_CLOSED will be + * raised as a side-effect of the read. + */ + qemu_chr_fe_read_all(s->chr, buf, sizeof(buf)); + + return FALSE; +} + static void net_vhost_user_event(void *opaque, int event) { const char *name = opaque; @@ -184,6 +199,8 @@ static void net_vhost_user_event(void *opaque, int event) trace_vhost_user_event(s->chr->label, event); switch (event) { case CHR_EVENT_OPENED: + s->watch = qemu_chr_fe_add_watch(s->chr, G_IO_HUP, + net_vhost_user_watch, s); if (vhost_user_start(queues, ncs) < 0) { exit(1); } @@ -192,6 +209,8 @@ static void net_vhost_user_event(void *opaque, int event) case CHR_EVENT_CLOSED: qmp_set_link(name, false, &err); vhost_user_stop(queues, ncs); + g_source_remove(s->watch); + s->watch = 0; break; }