From nobody Mon Apr 29 05:21:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500631277605325.3264810720359; Fri, 21 Jul 2017 03:01:17 -0700 (PDT) Received: from localhost ([::1]:42070 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYUkG-0007yd-C1 for importer@patchew.org; Fri, 21 Jul 2017 06:01:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54315) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYUfT-00041E-LA for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:56:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYUfQ-0000aP-Jk for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:56:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40240) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYUfQ-0000a7-Dk for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:56:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A4B66686A for ; Fri, 21 Jul 2017 09:56:15 +0000 (UTC) Received: from localhost (dhcp-192-218.str.redhat.com [10.33.192.218]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 03FF17E08D; Fri, 21 Jul 2017 09:56:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5A4B66686A Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jfreimann@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 5A4B66686A From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 11:55:50 +0200 Message-Id: <20170721095553.10717-2-jfreimann@redhat.com> In-Reply-To: <20170721095553.10717-1-jfreimann@redhat.com> References: <20170721095553.10717-1-jfreimann@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 21 Jul 2017 09:56:15 +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 Subject: [Qemu-devel] [PATCH 1/4] tests/vhost-user-bridge: disable debug output by default 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, stefanha@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jens Freimann vhost-user-bridge prints out a lot of information, including dumps of all transmitted data. When called from a testcase this output clutters the actual test results, so let's make the default no debug output. Reviewed-by: Maxime Coquelin Signed-off-by: Jens Freimann --- tests/vhost-user-bridge.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c index 1e5b5ca..93d9535 100644 --- a/tests/vhost-user-bridge.c +++ b/tests/vhost-user-bridge.c @@ -34,7 +34,7 @@ #include "standard-headers/linux/virtio_net.h" #include "contrib/libvhost-user/libvhost-user.h" =20 -#define VHOST_USER_BRIDGE_DEBUG 1 +#define VHOST_USER_BRIDGE_DEBUG 0 =20 #define DPRINT(...) \ do { \ --=20 2.9.4 From nobody Mon Apr 29 05:21:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500631264575167.3075553527559; Fri, 21 Jul 2017 03:01:04 -0700 (PDT) Received: from localhost ([::1]:42050 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYUhC-00057t-7W for importer@patchew.org; Fri, 21 Jul 2017 05:58:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYUff-000483-Ej for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:56:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYUfc-0000hv-6F for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:56:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40502) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYUfb-0000hQ-Ti for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:56:28 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9F63EA075D for ; Fri, 21 Jul 2017 09:56:26 +0000 (UTC) Received: from localhost (dhcp-192-218.str.redhat.com [10.33.192.218]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 09DE95C269; Fri, 21 Jul 2017 09:56:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9F63EA075D Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jfreimann@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 9F63EA075D From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 11:55:51 +0200 Message-Id: <20170721095553.10717-3-jfreimann@redhat.com> In-Reply-To: <20170721095553.10717-1-jfreimann@redhat.com> References: <20170721095553.10717-1-jfreimann@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 21 Jul 2017 09:56:26 +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 Subject: [Qemu-devel] [PATCH 2/4] net: fix -netdev socket, fd= for UDP sockets 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, stefanha@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This patch fixes -netdev socket,fd=3D for UDP sockets Currently -netdev socket,fd=3D<...> results in qemu: error: specified mcastaddr "127.0.0.1" (0x7f000001) does not contain a multicast address qemu-system-x86_64: -netdev socket,id=3Dn1,fd=3D3: Device 'socket' could not be initialized To fix these we need to allow specifying multicast and fd arguments for the same netdev. With this the user can specify "-netdev fd=3D3,mcast=3D" Fixes: 3d830459b1eccdb61b75e2712fd364012ce5a115 Signed-off-by: Jens Freimann Reviewed-by: Michael S. Tsirkin --- net/socket.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/net/socket.c b/net/socket.c index f85ef7d..18af2ab 100644 --- a/net/socket.c +++ b/net/socket.c @@ -320,11 +320,11 @@ static NetClientInfo net_dgram_socket_info =3D { static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, const char *model, const char *name, - int fd, int is_connected) + int fd, int is_connected, + const char *mcast) { struct sockaddr_in saddr; int newfd; - socklen_t saddr_len =3D sizeof(saddr); NetClientState *nc; NetSocketState *s; =20 @@ -333,8 +333,13 @@ static NetSocketState *net_socket_fd_init_dgram(NetCli= entState *peer, * by ONLY ONE process: we must "clone" this dgram socket --jjo */ =20 - if (is_connected) { - if (getsockname(fd, (struct sockaddr *) &saddr, &saddr_len) =3D=3D= 0) { + if (is_connected && mcast !=3D NULL) { + if (parse_host_port(&saddr, mcast) < 0) { + fprintf(stderr, + "qemu: error: init_dgram: fd=3D%d failed parse_hos= t_port()\n", + fd); + goto err; + } /* must be bound */ if (saddr.sin_addr.s_addr =3D=3D 0) { fprintf(stderr, "qemu: error: init_dgram: fd=3D%d unbound,= " @@ -351,12 +356,6 @@ static NetSocketState *net_socket_fd_init_dgram(NetCli= entState *peer, dup2(newfd, fd); close(newfd); =20 - } else { - fprintf(stderr, - "qemu: error: init_dgram: fd=3D%d failed getsockname()= : %s\n", - fd, strerror(errno)); - goto err; - } } =20 nc =3D qemu_new_net_client(&net_dgram_socket_info, peer, model, name); @@ -432,7 +431,7 @@ static NetSocketState *net_socket_fd_init_stream(NetCli= entState *peer, =20 static NetSocketState *net_socket_fd_init(NetClientState *peer, const char *model, const char *n= ame, - int fd, int is_connected) + int fd, int is_connected, const = char *mc) { int so_type =3D -1, optlen=3Dsizeof(so_type); =20 @@ -445,7 +444,7 @@ static NetSocketState *net_socket_fd_init(NetClientStat= e *peer, } switch(so_type) { case SOCK_DGRAM: - return net_socket_fd_init_dgram(peer, model, name, fd, is_connecte= d); + return net_socket_fd_init_dgram(peer, model, name, fd, is_connecte= d, mc); case SOCK_STREAM: return net_socket_fd_init_stream(peer, model, name, fd, is_connect= ed); default: @@ -567,7 +566,7 @@ static int net_socket_connect_init(NetClientState *peer, break; } } - s =3D net_socket_fd_init(peer, model, name, fd, connected); + s =3D net_socket_fd_init(peer, model, name, fd, connected, NULL); if (!s) return -1; snprintf(s->nc.info_str, sizeof(s->nc.info_str), @@ -602,7 +601,7 @@ static int net_socket_mcast_init(NetClientState *peer, if (fd < 0) return -1; =20 - s =3D net_socket_fd_init(peer, model, name, fd, 0); + s =3D net_socket_fd_init(peer, model, name, fd, 0, NULL); if (!s) return -1; =20 @@ -652,7 +651,7 @@ static int net_socket_udp_init(NetClientState *peer, } qemu_set_nonblock(fd); =20 - s =3D net_socket_fd_init(peer, model, name, fd, 0); + s =3D net_socket_fd_init(peer, model, name, fd, 0, NULL); if (!s) { return -1; } @@ -675,9 +674,9 @@ int net_init_socket(const Netdev *netdev, const char *n= ame, assert(netdev->type =3D=3D NET_CLIENT_DRIVER_SOCKET); sock =3D &netdev->u.socket; =20 - if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mc= ast + - sock->has_udp !=3D 1) { - error_report("exactly one of fd=3D, listen=3D, connect=3D, mcast= =3D or udp=3D" + if (sock->has_listen + sock->has_connect + sock->has_mcast + + sock->has_udp > 1) { + error_report("exactly one of listen=3D, connect=3D, mcast=3D or ud= p=3D" " is required"); return -1; } @@ -696,7 +695,7 @@ int net_init_socket(const Netdev *netdev, const char *n= ame, return -1; } qemu_set_nonblock(fd); - if (!net_socket_fd_init(peer, "socket", name, fd, 1)) { + if (!net_socket_fd_init(peer, "socket", name, fd, 1, sock->mcast))= { return -1; } return 0; --=20 2.9.4 From nobody Mon Apr 29 05:21:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500631503088362.49941143432864; Fri, 21 Jul 2017 03:05:03 -0700 (PDT) Received: from localhost ([::1]:42051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYUhN-0005H8-TP for importer@patchew.org; Fri, 21 Jul 2017 05:58:17 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54382) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYUfq-0004EA-4m for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:56:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYUfn-0000vW-2V for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:56:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56632) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYUfm-0000v5-SJ for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:56:38 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCAB02C1552 for ; Fri, 21 Jul 2017 09:56:37 +0000 (UTC) Received: from localhost (dhcp-192-218.str.redhat.com [10.33.192.218]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4CD6C81740; Fri, 21 Jul 2017 09:56:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BCAB02C1552 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jfreimann@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BCAB02C1552 From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 11:55:52 +0200 Message-Id: <20170721095553.10717-4-jfreimann@redhat.com> In-Reply-To: <20170721095553.10717-1-jfreimann@redhat.com> References: <20170721095553.10717-1-jfreimann@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Fri, 21 Jul 2017 09:56:37 +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 Subject: [Qemu-devel] [PATCH 3/4] 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, stefanha@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jens Freimann End processing of messages when VHOST_USER_NO_MESSAGE is received. Without this we run into a vubr_panic() call and get "PANIC: Unhandled request: 0" Signed-off-by: Jens Freimann --- contrib/libvhost-user/libvhost-user.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/libvhost-user/libvhost-user.c b/contrib/libvhost-user/= libvhost-user.c index 9efb9da..85523ca 100644 --- a/contrib/libvhost-user/libvhost-user.c +++ b/contrib/libvhost-user/libvhost-user.c @@ -161,7 +161,7 @@ vu_message_read(VuDev *dev, int conn_fd, VhostUserMsg *= vmsg) rc =3D recvmsg(conn_fd, &msg, 0); } while (rc < 0 && (errno =3D=3D EINTR || errno =3D=3D EAGAIN)); =20 - if (rc <=3D 0) { + if (rc < 0) { vu_panic(dev, "Error while recvmsg: %s", strerror(errno)); return false; } @@ -806,6 +806,8 @@ vu_process_message(VuDev *dev, VhostUserMsg *vmsg) return vu_get_queue_num_exec(dev, vmsg); case VHOST_USER_SET_VRING_ENABLE: return vu_set_vring_enable_exec(dev, vmsg); + case VHOST_USER_NONE: + return true; default: vmsg_close_fds(vmsg); vu_panic(dev, "Unhandled request: %d", vmsg->request); --=20 2.9.4 From nobody Mon Apr 29 05:21:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1500631351226797.6083424206902; Fri, 21 Jul 2017 03:02:31 -0700 (PDT) Received: from localhost ([::1]:42074 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYUlR-00009d-Ut for importer@patchew.org; Fri, 21 Jul 2017 06:02:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dYUgJ-0004e9-3s for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:57:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dYUgH-0001M8-Va for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:57:11 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57540) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dYUgH-0001LM-Lk for qemu-devel@nongnu.org; Fri, 21 Jul 2017 05:57:09 -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 8B13E2C154A for ; Fri, 21 Jul 2017 09:57:08 +0000 (UTC) Received: from localhost (dhcp-192-218.str.redhat.com [10.33.192.218]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 488545D75A; Fri, 21 Jul 2017 09:56:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8B13E2C154A Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jfreimann@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8B13E2C154A From: Jens Freimann To: qemu-devel@nongnu.org Date: Fri, 21 Jul 2017 11:55:53 +0200 Message-Id: <20170721095553.10717-5-jfreimann@redhat.com> In-Reply-To: <20170721095553.10717-1-jfreimann@redhat.com> References: <20170721095553.10717-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.39]); Fri, 21 Jul 2017 09:57:08 +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 Subject: [Qemu-devel] [PATCH 4/4] tests/pxe-test: add testcase using vhost-user-bridge 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, stefanha@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jens Freimann Add a PXE testcase tunneling traffic through vhost-user-bridge process. Create a vhost-user-bridge process and connect it to qemu via a socket. Signed-off-by: Jens Freimann --- tests/Makefile.include | 4 +- tests/pxe-test.c | 140 +++++++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 142 insertions(+), 2 deletions(-) diff --git a/tests/Makefile.include b/tests/Makefile.include index 7af278d..e40550c 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -705,7 +705,8 @@ tests/boot-order-test$(EXESUF): tests/boot-order-test.o= $(libqos-obj-y) tests/boot-serial-test$(EXESUF): tests/boot-serial-test.o $(libqos-obj-y) tests/bios-tables-test$(EXESUF): tests/bios-tables-test.o \ tests/boot-sector.o tests/acpi-utils.o $(libqos-obj-y) -tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o $(libqos-obj= -y) +tests/pxe-test$(EXESUF): tests/pxe-test.o tests/boot-sector.o \ + tests/vhost-user-bridge$(EXESUF) $(libqos-obj-y) tests/tmp105-test$(EXESUF): tests/tmp105-test.o $(libqos-omap-obj-y) tests/ds1338-test$(EXESUF): tests/ds1338-test.o $(libqos-imx-obj-y) tests/m25p80-test$(EXESUF): tests/m25p80-test.o @@ -834,6 +835,7 @@ $(patsubst %, check-qtest-%, $(QTEST_TARGETS)): check-q= test-%: $(check-qtest-y) $(if $(CONFIG_GCOV),@rm -f *.gcda */*.gcda */*/*.gcda */*/*/*.gcda,) $(call quiet-command,QTEST_QEMU_BINARY=3D$*-softmmu/qemu-system-$* \ QTEST_QEMU_IMG=3Dqemu-img$(EXESUF) \ + QTEST_VUBR_BINARY=3D./tests/vhost-user-bridge$(EXESUF) \ MALLOC_PERTURB_=3D$${MALLOC_PERTURB_:-$$(( $${RANDOM:-0} % 255 + 1))} \ gtester $(GTESTER_OPTIONS) -m=3D$(SPEED) $(check-qtest-$*-y) $(check-qte= st-generic-y),"GTESTER","$@") $(if $(CONFIG_GCOV),@for f in $(gcov-files-$*-y) $(gcov-files-generic-y);= do \ diff --git a/tests/pxe-test.c b/tests/pxe-test.c index 34282d3..d6379a8 100644 --- a/tests/pxe-test.c +++ b/tests/pxe-test.c @@ -5,7 +5,8 @@ * * Authors: * Michael S. Tsirkin , - * Victor Kaplansky + * Victor Kaplansky , + * Jens Freimann * * This work is licensed under the terms of the GNU GPL, version 2 or late= r. * See the COPYING file in the top-level directory. @@ -13,14 +14,150 @@ =20 #include "qemu/osdep.h" #include +#include #include "qemu-common.h" #include "libqtest.h" #include "boot-sector.h" +#include =20 +#define LPORT 5555 +#define RPORT 4444 #define NETNAME "net0" +#define QEMU_CMD_MEM "--enable-kvm -m %d "\ + "-object memory-backend-file,id=3Dmem,size=3D%dM,"\ + "mem-path=3D%s,share=3Don -numa node,memdev=3Dmem = -mem-prealloc " +#define QEMU_CMD_CHR " -chardev socket,id=3D%s,path=3D%s" +#define QEMU_CMD_NETDEV " -device virtio-net-pci,netdev=3Dnet0 "\ + " -netdev vhost-user,id=3Dnet0,chardev=3D%s,vhostf= orce "\ + " -netdev user,id=3Dn0,tftp=3D./,bootfile=3D%s "\ + " -netdev socket,id=3Dn1,fd=3D%d" +#define QEMU_CMD_NET " -device virtio-net-pci,netdev=3Dn0 "\ + " -device virtio-net-pci,netdev=3Dn1 " + +#define QEMU_CMD QEMU_CMD_MEM QEMU_CMD_CHR \ + QEMU_CMD_NETDEV QEMU_CMD_NET + +#define HUGETLBFS_MAGIC 0x958458f6 +#define VUBR_SOCK "vubr.sock" +#define MEMSZ 1024 =20 static char disk[] =3D "tests/pxe-test-disk-XXXXXX"; =20 +static const char *init_hugepagefs(const char *path) +{ + struct statfs fs; + int ret; + + if (access(path, R_OK | W_OK | X_OK)) { + g_test_message("access on path (%s): %s\n", path, strerror(errno)); + return NULL; + } + + do { + ret =3D statfs(path, &fs); + } while (ret !=3D 0 && errno =3D=3D EINTR); + + if (ret !=3D 0) { + g_test_message("statfs on path (%s): %s\n", path, strerror(errno)); + return NULL; + } + + if (fs.f_type !=3D HUGETLBFS_MAGIC) { + g_test_message("Warning: path not on HugeTLBFS: %s\n", path); + return NULL; + } + + return path; +} + +static int vubr_create_socket(struct sockaddr_in *si_remote, int rport) +{ + int sock; + + if (inet_aton("127.0.0.1", (struct in_addr *) &si_remote->sin_addr.s_a= ddr) + =3D=3D 0) { + g_test_message("inet_aton failed\n"); + return -1; + } + sock =3D socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); + if (sock =3D=3D -1) { + g_test_message("socket creation failed\n"); + return -1; + } + if (connect(sock, (struct sockaddr *) si_remote, sizeof(*si_remote))) { + g_test_message("connect failed: %s", strerror(errno)); + return -1; + } + + return sock; +} + +static void test_pxe_vhost_user(void) +{ + char template[] =3D "/tmp/vhost-user-bridge-XXXXXX"; + char template2[] =3D "/tmp/hugepages-XXXXXX"; + gchar * vubr_args[] =3D {NULL, NULL, NULL, NULL}; + struct sockaddr_in si_remote =3D { + .sin_family =3D AF_INET, + .sin_port =3D htons(RPORT), + }; + const char *hugefs =3D NULL; + const char *tmpfs2 =3D NULL; + const char *tmpfs =3D NULL; + const char *root =3D NULL; + GError *error =3D NULL; + char *vubr_binary; + char *qemu_args; + GPid vubr_pid; + int sock =3D -1; + + tmpfs =3D mkdtemp(template); + if (!tmpfs) { + g_test_message("mkdtemp on path(%s): %s\n", + template, strerror(errno)); + } + vubr_binary =3D getenv("QTEST_VUBR_BINARY"); + g_assert(vubr_binary); + vubr_args[0] =3D g_strdup_printf("%s", vubr_binary); + vubr_args[1] =3D g_strdup_printf("-u"); + vubr_args[2] =3D g_strdup_printf("%s/%s", tmpfs, VUBR_SOCK); + g_spawn_async(NULL, vubr_args, NULL, + G_SPAWN_SEARCH_PATH_FROM_ENVP | + G_SPAWN_SEARCH_PATH, + NULL, NULL, &vubr_pid, &error); + g_assert_no_error(error); + + hugefs =3D getenv("QTEST_HUGETLBFS_PATH"); + if (hugefs) { + root =3D init_hugepagefs(hugefs); + g_assert(root); + } else { + tmpfs2 =3D mkdtemp(template2); + g_assert(tmpfs2); + root =3D tmpfs2; + } + + sock =3D vubr_create_socket(&si_remote, RPORT); + g_assert_cmpint(sock, !=3D, -1); + + qemu_args =3D g_strdup_printf(QEMU_CMD, MEMSZ, MEMSZ, (root), + "char0", vubr_args[2], "char0", + disk, sock); + qtest_start(qemu_args); + boot_sector_test(); + qtest_quit(global_qtest); + g_free(qemu_args); + g_free(vubr_args[0]); + g_free(vubr_args[1]); + g_free(vubr_args[2]); + g_assert_cmpint(g_remove(g_strdup_printf("%s/%s", tmpfs, VUBR_SOCK)), + =3D=3D, 0); + if (tmpfs2) { + g_assert_cmpint(rmdir(tmpfs2), =3D=3D, 0); + } + g_assert_cmpint(g_rmdir(tmpfs), =3D=3D, 0); +} + static void test_pxe_one(const char *params, bool ipv6) { char *args; @@ -65,6 +202,7 @@ int main(int argc, char *argv[]) if (strcmp(arch, "i386") =3D=3D 0 || strcmp(arch, "x86_64") =3D=3D 0) { qtest_add_func("pxe/e1000", test_pxe_e1000); qtest_add_func("pxe/virtio", test_pxe_virtio_pci); + qtest_add_func("pxe/vhost-user", test_pxe_vhost_user); } else if (strcmp(arch, "ppc64") =3D=3D 0) { qtest_add_func("pxe/virtio", test_pxe_virtio_pci); qtest_add_func("pxe/spapr-vlan", test_pxe_spapr_vlan); --=20 2.9.4