From patchwork Fri Aug 25 11:18:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciara Loftus X-Patchwork-Id: 805844 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=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xdzGH3dmsz9sR9 for ; Fri, 25 Aug 2017 21:19:51 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 1DFF5904; Fri, 25 Aug 2017 11:19:16 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 00A10A7B for ; Fri, 25 Aug 2017 11:19:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 1E159171 for ; Fri, 25 Aug 2017 11:18:47 +0000 (UTC) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP; 25 Aug 2017 04:18:45 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,425,1498546800"; d="scan'208";a="143839396" Received: from sivswdev01.ir.intel.com (HELO localhost.localdomain) ([10.237.217.45]) by fmsmga005.fm.intel.com with ESMTP; 25 Aug 2017 04:18:45 -0700 From: Ciara Loftus To: dev@openvswitch.org Date: Fri, 25 Aug 2017 12:18:42 +0100 Message-Id: <1503659923-24322-2-git-send-email-ciara.loftus@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1503659923-24322-1-git-send-email-ciara.loftus@intel.com> References: <1503659923-24322-1-git-send-email-ciara.loftus@intel.com> X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 1/2] netdev-dpdk: Helper function for vHost device setup X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org dpdkvhostuser and dpdkvhostuserclient ports share a lot of the same setup & configuration code. Create a common function they can share in order to remove some duplication of code. Signed-off-by: Ciara Loftus --- lib/netdev-dpdk.c | 113 +++++++++++++++++++++++++----------------------------- 1 file changed, 52 insertions(+), 61 deletions(-) diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c index 1aaf6f7..ade813b 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -947,35 +947,27 @@ vhost_common_construct(struct netdev *netdev) } static int -netdev_dpdk_vhost_construct(struct netdev *netdev) +dpdk_setup_vhost_device(struct netdev_dpdk *dev, bool client_mode) { - struct netdev_dpdk *dev = netdev_dpdk_cast(netdev); - const char *name = netdev->name; - int err; + const char *name = dev->up.name; + uint64_t flags = dev->vhost_driver_flags; + int err = 0; - /* 'name' is appended to 'vhost_sock_dir' and used to create a socket in - * the file system. '/' or '\' would traverse directories, so they're not - * acceptable in 'name'. */ - if (strchr(name, '/') || strchr(name, '\\')) { - VLOG_ERR("\"%s\" is not a valid name for a vhost-user port. " - "A valid name must not include '/' or '\\'", - name); - return EINVAL; + if (client_mode) { + flags |= RTE_VHOST_USER_CLIENT; } - ovs_mutex_lock(&dpdk_mutex); - /* Take the name of the vhost-user port and append it to the location where - * the socket is to be created, then register the socket. - */ - snprintf(dev->vhost_id, sizeof dev->vhost_id, "%s/%s", - dpdk_get_vhost_sock_dir(), name); - - dev->vhost_driver_flags &= ~RTE_VHOST_USER_CLIENT; - err = rte_vhost_driver_register(dev->vhost_id, dev->vhost_driver_flags); + err = rte_vhost_driver_register(dev->vhost_id, flags); if (err) { VLOG_ERR("vhost-user socket device setup failure for socket %s\n", dev->vhost_id); - goto out; + return err; + } else if (client_mode) { + /* Configuration successful */ + dev->vhost_driver_flags |= RTE_VHOST_USER_CLIENT; + VLOG_INFO("vHost User device '%s' created in 'client' mode, " + "using client socket '%s'", + name, dev->vhost_id); } else { fatal_signal_add_file_to_unlink(dev->vhost_id); VLOG_INFO("Socket %s created for vhost-user port %s\n", @@ -983,11 +975,11 @@ netdev_dpdk_vhost_construct(struct netdev *netdev) } err = rte_vhost_driver_callback_register(dev->vhost_id, - &virtio_net_device_ops); + &virtio_net_device_ops); if (err) { VLOG_ERR("rte_vhost_driver_callback_register failed for vhost user " "port: %s\n", name); - goto out; + return err; } err = rte_vhost_driver_disable_features(dev->vhost_id, @@ -997,13 +989,46 @@ netdev_dpdk_vhost_construct(struct netdev *netdev) if (err) { VLOG_ERR("rte_vhost_driver_disable_features failed for vhost user " "port: %s\n", name); - goto out; + return err; } err = rte_vhost_driver_start(dev->vhost_id); if (err) { VLOG_ERR("rte_vhost_driver_start failed for vhost user " - "port: %s\n", name); + "port: %s\n", name); + return err; + } + + return err; +} + +static int +netdev_dpdk_vhost_construct(struct netdev *netdev) +{ + struct netdev_dpdk *dev = netdev_dpdk_cast(netdev); + const char *name = netdev->name; + int err; + + /* 'name' is appended to 'vhost_sock_dir' and used to create a socket in + * the file system. '/' or '\' would traverse directories, so they're not + * acceptable in 'name'. */ + if (strchr(name, '/') || strchr(name, '\\')) { + VLOG_ERR("\"%s\" is not a valid name for a vhost-user port. " + "A valid name must not include '/' or '\\'", + name); + return EINVAL; + } + + ovs_mutex_lock(&dpdk_mutex); + /* Take the name of the vhost-user port and append it to the location where + * the socket is to be created, then register the socket. + */ + snprintf(dev->vhost_id, sizeof dev->vhost_id, "%s/%s", + dpdk_get_vhost_sock_dir(), name); + + dev->vhost_driver_flags &= ~RTE_VHOST_USER_CLIENT; + err = dpdk_setup_vhost_device(dev, false); + if (err) { goto out; } @@ -3262,42 +3287,8 @@ netdev_dpdk_vhost_client_reconfigure(struct netdev *netdev) if (!(dev->vhost_driver_flags & RTE_VHOST_USER_CLIENT) && strlen(dev->vhost_id)) { /* Register client-mode device */ - err = rte_vhost_driver_register(dev->vhost_id, - RTE_VHOST_USER_CLIENT); - if (err) { - VLOG_ERR("vhost-user device setup failure for device %s\n", - dev->vhost_id); - goto unlock; - } else { - /* Configuration successful */ - dev->vhost_driver_flags |= RTE_VHOST_USER_CLIENT; - VLOG_INFO("vHost User device '%s' created in 'client' mode, " - "using client socket '%s'", - dev->up.name, dev->vhost_id); - } - - err = rte_vhost_driver_callback_register(dev->vhost_id, - &virtio_net_device_ops); - if (err) { - VLOG_ERR("rte_vhost_driver_callback_register failed for " - "vhost user client port: %s\n", dev->up.name); - goto unlock; - } - - err = rte_vhost_driver_disable_features(dev->vhost_id, - 1ULL << VIRTIO_NET_F_HOST_TSO4 - | 1ULL << VIRTIO_NET_F_HOST_TSO6 - | 1ULL << VIRTIO_NET_F_CSUM); - if (err) { - VLOG_ERR("rte_vhost_driver_disable_features failed for vhost user " - "client port: %s\n", dev->up.name); - goto unlock; - } - - err = rte_vhost_driver_start(dev->vhost_id); + err = dpdk_setup_vhost_device(dev, true); if (err) { - VLOG_ERR("rte_vhost_driver_start failed for vhost user " - "client port: %s\n", dev->up.name); goto unlock; } }