From nobody Fri Nov 7 12:48:34 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1548818142676534.8323089699988; Tue, 29 Jan 2019 19:15:42 -0800 (PST) Received: from localhost ([127.0.0.1]:59632 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gogLl-0003oT-LA for importer@patchew.org; Tue, 29 Jan 2019 22:15:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:34413) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gogKo-0003Rc-AU for qemu-devel@nongnu.org; Tue, 29 Jan 2019 22:14:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gogKm-0004u2-Kb for qemu-devel@nongnu.org; Tue, 29 Jan 2019 22:14:42 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gogKm-0004t2-D6 for qemu-devel@nongnu.org; Tue, 29 Jan 2019 22:14:40 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D331737E85; Wed, 30 Jan 2019 03:14:36 +0000 (UTC) Received: from jason-ThinkPad-T450s.redhat.com (ovpn-12-156.pek2.redhat.com [10.72.12.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 05826600C6; Wed, 30 Jan 2019 03:14:29 +0000 (UTC) From: Jason Wang To: qemu-devel@nongnu.org, jasowang@redhat.com Date: Wed, 30 Jan 2019 11:14:27 +0800 Message-Id: <20190130031427.13129-1-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 30 Jan 2019 03:14:36 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH V2] test-filter-mirror: pass UNIX domain socket through fd 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: Peter Maydell , Li Zhijian , Markus Armbruster , Peter Xu , "Dr . David Alan Gilbert" , Zhang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The tests tries to let qemu server mode to process the connection which turns out to be racy after commit 8258292e18c3 ("monitor: Remove "x-oob", offer capability "oob" unconditionally"). This is because the filter may try to mirror the packets before UNIX socket object is ready (connected was set to true) from the view of qemu. In this case the packet will be dropped silently. Fixing this by passing pre-connected socket created by socketpair() to qemu through fd. Cc: Peter Maydell Cc: Li Zhijian Cc: Peter Xu Cc: Dr. David Alan Gilbert Cc: Zhang Chen Cc: Markus Armbruster Cc: Daniel P. Berrange Signed-off-by: Jason Wang Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: Zhang Chen --- Changes from v1: - close the socket pairs in the end of test --- tests/test-filter-mirror.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/test-filter-mirror.c b/tests/test-filter-mirror.c index 7ab2aed8a0..d942c74a3f 100644 --- a/tests/test-filter-mirror.c +++ b/tests/test-filter-mirror.c @@ -21,10 +21,9 @@ =20 static void test_mirror(void) { - int send_sock[2], recv_sock; + int send_sock[2], recv_sock[2]; uint32_t ret =3D 0, len =3D 0; char send_buf[] =3D "Hello! filter-mirror~"; - char sock_path[] =3D "filter-mirror.XXXXXX"; char *recv_buf; uint32_t size =3D sizeof(send_buf); size =3D htonl(size); @@ -38,18 +37,15 @@ static void test_mirror(void) ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, send_sock); g_assert_cmpint(ret, !=3D, -1); =20 - ret =3D mkstemp(sock_path); + ret =3D socketpair(PF_UNIX, SOCK_STREAM, 0, recv_sock); g_assert_cmpint(ret, !=3D, -1); =20 qts =3D qtest_initf( "-netdev socket,id=3Dqtest-bn0,fd=3D%d " "-device %s,netdev=3Dqtest-bn0,id=3Dqtest-e0 " - "-chardev socket,id=3Dmirror0,path=3D%s,server,nowait " + "-chardev socket,id=3Dmirror0,fd=3D%d " "-object filter-mirror,id=3Dqtest-f0,netdev=3Dqtest-bn0,queue=3Dtx= ,outdev=3Dmirror0 " - , send_sock[1], devstr, sock_path); - - recv_sock =3D unix_connect(sock_path, NULL); - g_assert_cmpint(recv_sock, !=3D, -1); + , send_sock[1], devstr, recv_sock[1]); =20 struct iovec iov[] =3D { { @@ -67,18 +63,20 @@ static void test_mirror(void) g_assert_cmpint(ret, =3D=3D, sizeof(send_buf) + sizeof(size)); close(send_sock[0]); =20 - ret =3D qemu_recv(recv_sock, &len, sizeof(len), 0); + ret =3D qemu_recv(recv_sock[0], &len, sizeof(len), 0); g_assert_cmpint(ret, =3D=3D, sizeof(len)); len =3D ntohl(len); =20 g_assert_cmpint(len, =3D=3D, sizeof(send_buf)); recv_buf =3D g_malloc(len); - ret =3D qemu_recv(recv_sock, recv_buf, len, 0); + ret =3D qemu_recv(recv_sock[0], recv_buf, len, 0); g_assert_cmpstr(recv_buf, =3D=3D, send_buf); =20 g_free(recv_buf); - close(recv_sock); - unlink(sock_path); + close(send_sock[0]); + close(send_sock[1]); + close(recv_sock[0]); + close(recv_sock[1]); qtest_quit(qts); } =20 --=20 2.17.1