From patchwork Wed Oct 11 14:21:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ciara Loftus X-Patchwork-Id: 824454 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 3yBx6M4VjZz9s7M for ; Thu, 12 Oct 2017 01:23:23 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 403CABDE; Wed, 11 Oct 2017 14:22:11 +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 D3EFCBC0 for ; Wed, 11 Oct 2017 14:22:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 6358C171 for ; Wed, 11 Oct 2017 14:22:09 +0000 (UTC) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2017 07:22:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.43,361,1503385200"; d="scan'208"; a="1229619718" Received: from sivswdev01.ir.intel.com (HELO localhost.localdomain) ([10.237.217.45]) by fmsmga002.fm.intel.com with ESMTP; 11 Oct 2017 07:22:07 -0700 From: Ciara Loftus To: dev@openvswitch.org Date: Wed, 11 Oct 2017 15:21:52 +0100 Message-Id: <1507731713-9302-2-git-send-email-ciara.loftus@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1507731713-9302-1-git-send-email-ciara.loftus@intel.com> References: <1507731713-9302-1-git-send-email-ciara.loftus@intel.com> X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD autolearn=disabled version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2 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 572987c..0b910cd 100644 --- a/lib/netdev-dpdk.c +++ b/lib/netdev-dpdk.c @@ -973,35 +973,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", @@ -1009,11 +1001,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, @@ -1023,13 +1015,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; } @@ -3298,42 +3323,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; } }