[ovs-dev] [PATCH v2 1/2] netdev-dpdk: Helper function for vHost device setup
Ciara Loftus
ciara.loftus at intel.com
Wed Oct 11 14:21:52 UTC 2017
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 <ciara.loftus at intel.com>
---
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;
}
}
--
2.7.5
More information about the dev
mailing list