From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33171) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alx4M-0005Sj-2i for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:16:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alx4J-0001kh-NQ for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:16:50 -0400 Received: from mail-qg0-x234.google.com ([2607:f8b0:400d:c04::234]:34319) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alx4J-0001kb-IH for qemu-devel@nongnu.org; Fri, 01 Apr 2016 07:16:47 -0400 Received: by mail-qg0-x234.google.com with SMTP id n34so85419504qge.1 for ; Fri, 01 Apr 2016 04:16:47 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Fri, 1 Apr 2016 13:16:16 +0200 Message-Id: <1459509388-6185-7-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1459509388-6185-1-git-send-email-marcandre.lureau@redhat.com> References: <1459509388-6185-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH 06/18] vhost-user: add ability to know vhost-user backend disconnection List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Tetsuya Mukawa , Ilya Maximets , Yuanhan Liu , jonshin@cisco.com, "Michael S. Tsirkin" 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 --- net/vhost-user.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/net/vhost-user.c b/net/vhost-user.c index 9007d0b..3dae53c 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 { @@ -169,6 +170,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; @@ -186,6 +201,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); } @@ -194,6 +211,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; } -- 2.5.5