Patch: 
https://github.com/openvswitch/ovs/commit/69c51582ff786a68fc325c1c50624715482bc460
broke Windows userpace - kernel communication.

On windows we create netlink sockets when the handlers are initiated and
reuse them.
This patch remaps the usage of the netlink socket pool.

Fixes:
https://github.com/openvswitch/ovs-issues/issues/164

Signed-off-by: Alin Gabriel Serdean <[email protected]>
Acked-by: Shashank Ram <[email protected]>
Tested-by: Shashank Ram <[email protected]>
---
RFC -> v1: Improve wording, change function name and add ifdef guard for them
---
 lib/dpif-netlink.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c
index 69c145cc3..d2adb8b60 100644
--- a/lib/dpif-netlink.c
+++ b/lib/dpif-netlink.c
@@ -246,6 +246,37 @@ static int dpif_netlink_port_query__(const struct 
dpif_netlink *dpif,
                                      odp_port_t port_no, const char *port_name,
                                      struct dpif_port *dpif_port);
 
+#ifdef _WIN32
+static struct nl_sock *
+create_socksp_windows(struct dpif_netlink *dpif, int *error)
+OVS_REQ_WRLOCK(dpif->upcall_lock)
+{
+    struct nl_sock *socksp;
+    /* Pick netlink sockets to use in a round-robin fashion from each
+     * handler's pool of sockets. */
+    struct dpif_handler *handler = &dpif->handlers[0];
+    struct dpif_windows_vport_sock *sock_pool = handler->vport_sock_pool;
+    size_t index = handler->last_used_pool_idx;
+    /* A pool of sockets is allocated when the handler is initialized. */
+    if (sock_pool == NULL) {
+        *error = EINVAL;
+        return NULL;
+    }
+    ovs_assert(index < VPORT_SOCK_POOL_SIZE);
+    socksp = sock_pool[index].nl_sock;
+    ovs_assert(socksp);
+    index = (index == VPORT_SOCK_POOL_SIZE - 1) ? 0 : index + 1;
+    handler->last_used_pool_idx = index;
+    *error = 0;
+    return socksp;
+}
+static void
+del_socksp_windows(struct dpif_netlink *dpif, struct nl_sock *socksp)
+{
+    socksp = NULL;
+}
+#endif
+
 static struct dpif_netlink *
 dpif_netlink_cast(const struct dpif *dpif)
 {
@@ -716,7 +747,12 @@ dpif_netlink_port_add__(struct dpif_netlink *dpif, const 
char *name,
     int error = 0;
 
     if (dpif->handlers) {
-        if (nl_sock_create(NETLINK_GENERIC, &socksp)) {
+#ifdef _WIN32
+        socksp = create_socksp_windows(dpif, &error);
+#else
+        error = nl_sock_create(NETLINK_GENERIC, &socksp);
+#endif
+        if (!socksp) {
             return error;
         }
     }
@@ -748,7 +784,11 @@ dpif_netlink_port_add__(struct dpif_netlink *dpif, const 
char *name,
                       dpif_name(&dpif->dpif), *port_nop);
         }
 
+#ifdef _WIN32
+        del_socksp_windows(dpif, socksp);
+#else
         nl_sock_destroy(socksp);
+#endif
         goto exit;
     }
 
@@ -763,7 +803,11 @@ dpif_netlink_port_add__(struct dpif_netlink *dpif, const 
char *name,
         request.dp_ifindex = dpif->dp_ifindex;
         request.port_no = *port_nop;
         dpif_netlink_vport_transact(&request, NULL, NULL);
+#ifdef _WIN32
+        del_socksp_windows(dpif, socksp);
+#else
         nl_sock_destroy(socksp);
+#endif
         goto exit;
     }
 
@@ -2249,15 +2293,26 @@ dpif_netlink_refresh_channels(struct dpif_netlink 
*dpif, uint32_t n_handlers)
             || !vport_get_pid(dpif, port_no, &upcall_pid)) {
             struct nl_sock *socksp;
 
+#ifdef _WIN32
+            socksp = create_socksp_windows(dpif, &error);
+            if (!socksp) {
+                goto error;
+            }
+#else
             if (nl_sock_create(NETLINK_GENERIC, &socksp)) {
                 goto error;
             }
+#endif
 
             error = vport_add_channel(dpif, vport.port_no, socksp);
             if (error) {
                 VLOG_INFO("%s: could not add channels for port %s",
                           dpif_name(&dpif->dpif), vport.name);
+#ifdef _WIN32
+                del_socksp_windows(dpif, socksp);
+#else
                 nl_sock_destroy(socksp);
+#endif
                 retval = error;
                 goto error;
             }
-- 
2.16.1.windows.1

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to