From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60845) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCuUx-0005tA-9B for qemu-devel@nongnu.org; Tue, 14 Jun 2016 15:59:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bCuUs-0001PM-Ht for qemu-devel@nongnu.org; Tue, 14 Jun 2016 15:59:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bCuUs-0001PH-Bm for qemu-devel@nongnu.org; Tue, 14 Jun 2016 15:59:38 -0400 Date: Tue, 14 Jun 2016 22:59:36 +0300 From: "Michael S. Tsirkin" Message-ID: <20160614225936-mutt-send-email-mst@redhat.com> References: <1465934227-16558-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1465934227-16558-1-git-send-email-mst@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL v2 02/32] 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: Peter Maydell , Tetsuya Mukawa , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Yuanhan Liu , Victor Kaplansky , Jason Wang 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=E9 Lureau Tested-by: Yuanhan Liu Reviewed-by: Yuanhan Liu Reviewed-by: Victor Kaplansky Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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; =20 typedef struct VhostUserChardevProps { @@ -167,6 +168,20 @@ static NetClientInfo net_vhost_user_info =3D { .has_ufo =3D vhost_user_has_ufo, }; =20 +static gboolean net_vhost_user_watch(GIOChannel *chan, GIOCondition cond= , + void *opaque) +{ + VhostUserState *s =3D opaque; + uint8_t buf[1]; + + /* We don't actually want to read anything, but CHR_EVENT_CLOSED wil= l 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 =3D opaque; @@ -184,6 +199,8 @@ static void net_vhost_user_event(void *opaque, int ev= ent) trace_vhost_user_event(s->chr->label, event); switch (event) { case CHR_EVENT_OPENED: + s->watch =3D 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 ev= ent) case CHR_EVENT_CLOSED: qmp_set_link(name, false, &err); vhost_user_stop(queues, ncs); + g_source_remove(s->watch); + s->watch =3D 0; break; } =20 --=20 MST