From patchwork Mon Jun 6 16:45:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marc-Andr=C3=A9_Lureau?= X-Patchwork-Id: 9158785 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 16ACB60573 for ; Mon, 6 Jun 2016 16:46:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0802028349 for ; Mon, 6 Jun 2016 16:46:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E83C52834C; Mon, 6 Jun 2016 16:46:08 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID 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 7F20128349 for ; Mon, 6 Jun 2016 16:46:08 +0000 (UTC) Received: from localhost ([::1]:43772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9xfD-0004Ju-Jm for patchwork-qemu-devel@patchwork.kernel.org; Mon, 06 Jun 2016 12:46:07 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49507) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9xeW-0004DJ-8y for qemu-devel@nongnu.org; Mon, 06 Jun 2016 12:45:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9xeS-0005YK-7S for qemu-devel@nongnu.org; Mon, 06 Jun 2016 12:45:24 -0400 Received: from mail-qg0-x241.google.com ([2607:f8b0:400d:c04::241]:34086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9xeS-0005Y4-25 for qemu-devel@nongnu.org; Mon, 06 Jun 2016 12:45:20 -0400 Received: by mail-qg0-x241.google.com with SMTP id z67so7154040qgz.1 for ; Mon, 06 Jun 2016 09:45:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kvVexCitPyM8DhQkUCt73Z0V/+xAmek+sf2+m9+boaw=; b=f3TPbwmcA40kJnuzEBo++YCwhci3ohphzSpAPr3EgU89AUKDIP2FKahMQDs8rWHtrT gxQTlqBv804MWfNzjoYgy/iiPwsO/nNMxQ8l8JhBA9boDz7Y5hCT5rt8/xG+KiMk3gdb fMoOqyi7379fuk7awr1x045NHNfG2nGLklGLI89P0y7XO9kXx8j+eSA/ZRrNMCmqN+Bd b0McwQNsIaetsRozu6TrpvrxzRPleYS1OIUF20UQ2whX5dBgizyNsp4xkixDcPRr1gGB VtwwueQ+2wR6JUye4aLbG7U4qNUIfiIsUXr5fBXt8tkBQZZFVHIGxqCAAOdCZUtg0792 7NWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=kvVexCitPyM8DhQkUCt73Z0V/+xAmek+sf2+m9+boaw=; b=hwkrkLnN6W98AG02xCa+HCcrna0BmAYknL0b+VmunO50ZCgLDIZ95ZyItie9wDkCFk bDLdCD3pvTgrr61Yi8ozcU5S6yvVJJTROtkpbX8TxZKHx/D15nuN3Bs0iMl6x3KHI2V+ x3WSieXBmatcEmFmPZWilzPYkCVgGSQBVCNjG5PZYgJ0gTNoXsIzISf/pdBQGGBr5pUE QRZDFJzkaM4XFIdZ0Tk2PQ4n6vptEaaCRkXleN/Kh/+whY5VkbxDG4V4h1jXlBnAu0Cc AO0sfOpKVXunVLiKr4T4Wz/ub/0QGhuk+iJwrG9JA83d1cjUtC4l0WhqwB/SPGCCnuDX lOYA== X-Gm-Message-State: ALyK8tKN6k0Xifr2eYn29MaNHOSPQbrinKnab4uNsce5VrAL+ThK4t+CU50b6PsxZBxJ7Q== X-Received: by 10.140.21.47 with SMTP id 44mr15907943qgk.43.1465231519610; Mon, 06 Jun 2016 09:45:19 -0700 (PDT) Received: from localhost (APoitiers-110-1-1-130.w193-248.abo.wanadoo.fr. [193.248.103.130]) by smtp.gmail.com with ESMTPSA id f19sm5374918qgd.21.2016.06.06.09.45.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Jun 2016 09:45:18 -0700 (PDT) From: marcandre.lureau@redhat.com To: qemu-devel@nongnu.org Date: Mon, 6 Jun 2016 18:45:00 +0200 Message-Id: <1465231508-30183-3-git-send-email-marcandre.lureau@redhat.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1465231508-30183-1-git-send-email-marcandre.lureau@redhat.com> References: <1465231508-30183-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c04::241 Subject: [Qemu-devel] [PATCH 02/10] tests/vhost-user-bridge: add client mode 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: Yuanhan Liu , "Michael S . Tsirkin" , Ilya Maximets , jonshin@cisco.com, Tetsuya Mukawa , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Marc-André Lureau If -c is specified, vubr will try to connect to the socket instead of listening for connections. Signed-off-by: Marc-André Lureau Tested-by: Yuanhan Liu Reviewed-by: Yuanhan Liu --- tests/vhost-user-bridge.c | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/tests/vhost-user-bridge.c b/tests/vhost-user-bridge.c index 0779ba2..f907ce7 100644 --- a/tests/vhost-user-bridge.c +++ b/tests/vhost-user-bridge.c @@ -1204,12 +1204,13 @@ vubr_accept_cb(int sock, void *ctx) } static VubrDev * -vubr_new(const char *path) +vubr_new(const char *path, bool client) { VubrDev *dev = (VubrDev *) calloc(1, sizeof(VubrDev)); dev->nregions = 0; int i; struct sockaddr_un un; + CallbackFunc cb; size_t len; for (i = 0; i < MAX_NR_VIRTQUEUE; i++) { @@ -1238,19 +1239,27 @@ vubr_new(const char *path) un.sun_family = AF_UNIX; strcpy(un.sun_path, path); len = sizeof(un.sun_family) + strlen(path); - unlink(path); - if (bind(dev->sock, (struct sockaddr *) &un, len) == -1) { - vubr_die("bind"); - } + if (!client) { + unlink(path); + + if (bind(dev->sock, (struct sockaddr *) &un, len) == -1) { + vubr_die("bind"); + } - if (listen(dev->sock, 1) == -1) { - vubr_die("listen"); + if (listen(dev->sock, 1) == -1) { + vubr_die("listen"); + } + cb = vubr_accept_cb; + } else { + if (connect(dev->sock, (struct sockaddr *)&un, len) == -1) { + vubr_die("connect"); + } + cb = vubr_receive_cb; } dispatcher_init(&dev->dispatcher); - dispatcher_add(&dev->dispatcher, dev->sock, (void *)dev, - vubr_accept_cb); + dispatcher_add(&dev->dispatcher, dev->sock, (void *)dev, cb); DPRINT("Waiting for connections on UNIX socket %s ...\n", path); return dev; @@ -1369,8 +1378,9 @@ main(int argc, char *argv[]) { VubrDev *dev; int opt; + bool client = false; - while ((opt = getopt(argc, argv, "l:r:u:")) != -1) { + while ((opt = getopt(argc, argv, "l:r:u:c")) != -1) { switch (opt) { case 'l': @@ -1386,16 +1396,20 @@ main(int argc, char *argv[]) case 'u': ud_socket_path = strdup(optarg); break; + case 'c': + client = true; + break; default: goto out; } } - DPRINT("ud socket: %s\n", ud_socket_path); + DPRINT("ud socket: %s (%s)\n", ud_socket_path, + client ? "client" : "server"); DPRINT("local: %s:%s\n", lhost, lport); DPRINT("remote: %s:%s\n", rhost, rport); - dev = vubr_new(ud_socket_path); + dev = vubr_new(ud_socket_path, client); if (!dev) { return 1; }