[ovs-dev] [RFC] lib/netdev-dpdk: add hotplug support

Mauricio Vasquez B mauricio.vasquezbernal at studenti.polito.it
Wed Mar 16 14:40:22 UTC 2016


In order to use dpdk ports in ovs they have to be bound to a DPDK
compatible driver before ovs is started.

This patch adds the possibility to hotplug (or hot-unplug) a device
after ovs has been started. The implementation adds two appctl commands:
netdev-dpdk/attach and netdev-dpdk/detach.

After the user attaches a new device, it can use the add-port command
to use it in a switch, similarly, before detaching a device, it has to
be removed using the del-port command.

Signed-off-by: Mauricio Vasquez B <mauricio.vasquezbernal at studenti.polito.it>
---
 lib/netdev-dpdk.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 79 insertions(+)

diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index f402354..c3a99e7 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -2253,12 +2253,91 @@ dpdk_vhost_user_class_init(void)
 }
 
 static void
+netdev_dpdk_attach(struct unixctl_conn *conn, int argc,
+                            const char *argv[], void *aux OVS_UNUSED)
+{
+    int ret;
+    uint8_t port_id;
+    char response[512];
+
+    ovs_mutex_lock(&dpdk_mutex);
+
+    ret = rte_eth_dev_attach(argv[1], &port_id);
+    if(ret < 0) {
+        snprintf(response, sizeof(response),
+                "Error attaching device ''", argv[1]);
+        unixctl_command_reply_error(conn, response);
+        goto unlock;
+    }
+
+    snprintf(response, sizeof(response),
+                "Device '%s' has been attached as 'dpdk%d'", argv[1], port_id);
+    unixctl_command_reply(conn, response);
+
+unlock:
+    ovs_mutex_unlock(&dpdk_mutex);
+}
+
+static void
+netdev_dpdk_detach(struct unixctl_conn *conn, int argc,
+                            const char *argv[], void *aux OVS_UNUSED)
+{
+    int ret;
+    unsigned int port_id;
+    char name[RTE_ETH_NAME_MAX_LEN];
+    char response[512];
+
+    ret = dpdk_dev_parse_name(argv[1], "dpdk", &port_id);
+    if(ret) {
+        snprintf(response, sizeof(response),
+                    "'%s' is not a valid dpdk device", argv[1]);
+        unixctl_command_reply_error(conn, response);
+        return;
+    }
+
+    ovs_mutex_lock(&dpdk_mutex);
+
+    struct netdev * netdev = netdev_from_name(argv[1]);
+    if(netdev) {
+        netdev_close(netdev);
+        snprintf(response, sizeof(response),
+                    "Port '%s' is being used. Remove it before detaching", argv[1]);
+        unixctl_command_reply_error(conn, response);
+        goto unlock;
+    }
+
+    rte_eth_dev_close(port_id);
+
+    ret = rte_eth_dev_detach(port_id, name);
+    if(ret < 0) {
+        snprintf(response, sizeof(response),
+                    "Port '%s' can not be detached", argv[1]);
+        unixctl_command_reply_error(conn, response);
+        goto unlock;
+    }
+
+    snprintf(response, sizeof(response), "Port '%s' has been detached", argv[1]);
+    unixctl_command_reply(conn, response);
+
+unlock:
+    ovs_mutex_unlock(&dpdk_mutex);
+}
+
+static void
 dpdk_common_init(void)
 {
     unixctl_command_register("netdev-dpdk/set-admin-state",
                              "[netdev] up|down", 1, 2,
                              netdev_dpdk_set_admin_state, NULL);
 
+    unixctl_command_register("netdev-dpdk/attach",
+                             "device", 1, 1,
+                             netdev_dpdk_attach, NULL);
+
+    unixctl_command_register("netdev-dpdk/detach",
+                             "port", 1, 1,
+                             netdev_dpdk_detach, NULL);
+
     ovs_thread_create("dpdk_watchdog", dpdk_watchdog, NULL);
 }
 
-- 
1.9.1




More information about the dev mailing list