From patchwork Wed Jul 12 09:41:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Freimann X-Patchwork-Id: 9836547 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 4E77960363 for ; Wed, 12 Jul 2017 11:48:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E6B3285C1 for ; Wed, 12 Jul 2017 11:48:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3343E285DB; Wed, 12 Jul 2017 11:48:16 +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 C02DA285C1 for ; Wed, 12 Jul 2017 11:48:15 +0000 (UTC) Received: from localhost ([::1]:51979 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVG7q-0002gH-KA for patchwork-qemu-devel@patchwork.kernel.org; Wed, 12 Jul 2017 07:48:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43770) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dVEAE-0000fV-7E for qemu-devel@nongnu.org; Wed, 12 Jul 2017 05:42:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dVEAD-0002y7-F7 for qemu-devel@nongnu.org; Wed, 12 Jul 2017 05:42:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46202) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dVEAD-0002xr-8V for qemu-devel@nongnu.org; Wed, 12 Jul 2017 05:42:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 30E8AC0587C0 for ; Wed, 12 Jul 2017 09:42:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 30E8AC0587C0 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jfreimann@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 30E8AC0587C0 Received: from localhost (dhcp-192-218.str.redhat.com [10.33.192.218]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F000F5D6A6; Wed, 12 Jul 2017 09:42:22 +0000 (UTC) From: Jens Freimann To: qemu-devel@nongnu.org Date: Wed, 12 Jul 2017 11:41:49 +0200 Message-Id: <20170712094149.23069-4-jfreimann@redhat.com> In-Reply-To: <20170712094149.23069-1-jfreimann@redhat.com> References: <20170712094149.23069-1-jfreimann@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 12 Jul 2017 09:42:32 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 X-Mailman-Approved-At: Wed, 12 Jul 2017 07:42:21 -0400 Subject: [Qemu-devel] [PATCH RFC 3/3] libvhost-user: quit when no more data received 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: marcandre.lureau@redhat.com, maxime.coquelin@redhat.com, victork@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jens Freimann When recvmsg() returns a message size of zero and errno is ENOENT end processing of vhost-user messages. Without this we run into a vubr_panic() call and get PANIC: Error while recvmsg: No such file or directory Error while dispatching. Add a switch "quit" to the vhost user device and set true to stop processing messages. Signed-off-by: Jens Freimann --- contrib/libvhost-user/libvhost-user.c | 12 +++++++++++- contrib/libvhost-user/libvhost-user.h | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/libvhost-user.c index 9efb9da..5538859 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -161,7 +161,10 @@ vu_message_read(VuDev *dev, int conn_fd, VhostUserMsg *vmsg) rc = recvmsg(conn_fd, &msg, 0); } while (rc < 0 && (errno == EINTR || errno == EAGAIN)); - if (rc <= 0) { + if (rc == 0 && (errno == ENOENT)) { + vmsg->size = 0; + dev->quit = true; + } else if (rc < 0) { vu_panic(dev, "Error while recvmsg: %s", strerror(errno)); return false; } @@ -755,6 +758,10 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg) DPRINT("Flags: 0x%x\n", vmsg->flags); DPRINT("Size: %d\n", vmsg->size); + if (dev->quit) { + return true; + } + if (vmsg->fd_num) { int i; DPRINT("Fds:"); @@ -822,6 +829,9 @@ vu_dispatch(VuDev *dev) bool success = false; if (!vu_message_read(dev, dev->sock, &vmsg)) { + if (vmsg.size == 0) { + success = true; + } goto end; } diff --git a/contrib/libvhost-user/libvhost-user.h b/contrib/libvhost-user/libvhost-user.h index 53ef222..c02215a 100644 --- a/contrib/libvhost-user/libvhost-user.h +++ b/contrib/libvhost-user/libvhost-user.h @@ -217,6 +217,7 @@ struct VuDev { uint64_t features; uint64_t protocol_features; bool broken; + bool quit; /* @set_watch: add or update the given fd to the watch set, * call cb when condition is met */