From patchwork Wed Jan 30 03:14:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 1033223 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43q7lV1T9wz9s9h for ; Wed, 30 Jan 2019 14:15:02 +1100 (AEDT) Received: from localhost ([127.0.0.1]:59601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gogL6-0003Rv-4I for incoming@patchwork.ozlabs.org; Tue, 29 Jan 2019 22:15:00 -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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" 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é 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 @@ static void test_mirror(void) { - int send_sock[2], recv_sock; + int send_sock[2], recv_sock[2]; uint32_t ret = 0, len = 0; char send_buf[] = "Hello! filter-mirror~"; - char sock_path[] = "filter-mirror.XXXXXX"; char *recv_buf; uint32_t size = sizeof(send_buf); size = htonl(size); @@ -38,18 +37,15 @@ static void test_mirror(void) ret = socketpair(PF_UNIX, SOCK_STREAM, 0, send_sock); g_assert_cmpint(ret, !=, -1); - ret = mkstemp(sock_path); + ret = socketpair(PF_UNIX, SOCK_STREAM, 0, recv_sock); g_assert_cmpint(ret, !=, -1); qts = qtest_initf( "-netdev socket,id=qtest-bn0,fd=%d " "-device %s,netdev=qtest-bn0,id=qtest-e0 " - "-chardev socket,id=mirror0,path=%s,server,nowait " + "-chardev socket,id=mirror0,fd=%d " "-object filter-mirror,id=qtest-f0,netdev=qtest-bn0,queue=tx,outdev=mirror0 " - , send_sock[1], devstr, sock_path); - - recv_sock = unix_connect(sock_path, NULL); - g_assert_cmpint(recv_sock, !=, -1); + , send_sock[1], devstr, recv_sock[1]); struct iovec iov[] = { { @@ -67,18 +63,20 @@ static void test_mirror(void) g_assert_cmpint(ret, ==, sizeof(send_buf) + sizeof(size)); close(send_sock[0]); - ret = qemu_recv(recv_sock, &len, sizeof(len), 0); + ret = qemu_recv(recv_sock[0], &len, sizeof(len), 0); g_assert_cmpint(ret, ==, sizeof(len)); len = ntohl(len); g_assert_cmpint(len, ==, sizeof(send_buf)); recv_buf = g_malloc(len); - ret = qemu_recv(recv_sock, recv_buf, len, 0); + ret = qemu_recv(recv_sock[0], recv_buf, len, 0); g_assert_cmpstr(recv_buf, ==, send_buf); 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); }