[ovs-dev] [PATCH] datapath-windows: add support for OVS_DP_CMD_NEW netlink command

Nithin Raju nithin at vmware.com
Wed Oct 8 03:12:09 UTC 2014


In this change, we add support for the 'OVS_DP_CMD_NEW' netlink command
in the kernel. We don't really support creation of a new datapath. If
the name of the userspace is the same as the single datapath we support,
we return EEXIST.

This code is required to bootstrap ovs-vswitchd which makes the
following sequence of calls:
open_dpif_backer() -> dpif_create_and_open() -> dpif_create()

We also rename HandleDpTransaction() to HandleDpTransactionCommon().

Signed-off-by: Nithin Raju <nithin at vmware.com>
---
 datapath-windows/ovsext/Datapath.c |   72 +++++++++++++++++++++++++++++------
 1 files changed, 59 insertions(+), 13 deletions(-)

diff --git a/datapath-windows/ovsext/Datapath.c b/datapath-windows/ovsext/Datapath.c
index acd9dbb..b3167ba 100644
--- a/datapath-windows/ovsext/Datapath.c
+++ b/datapath-windows/ovsext/Datapath.c
@@ -101,6 +101,7 @@ static NetlinkCmdHandler OvsGetPidCmdHandler,
                          OvsPendEventCmdHandler,
                          OvsSubscribeEventCmdHandler,
                          OvsReadEventCmdHandler,
+                         OvsNewDpCmdHandler,
                          OvsGetDpCmdHandler,
                          OvsSetDpCmdHandler,
                          OvsGetVportCmdHandler,
@@ -114,8 +115,8 @@ static NTSTATUS HandleGetDpTransaction(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
                                        UINT32 *replyLen);
 static NTSTATUS HandleGetDpDump(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
                                 UINT32 *replyLen);
-static NTSTATUS HandleDpTransaction(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
-                                    UINT32 *replyLen);
+static NTSTATUS HandleDpTransactionCommon(
+                    POVS_USER_PARAMS_CONTEXT usrParamsCtx, UINT32 *replyLen);
 
 /*
  * The various netlink families, along with the supported commands. Most of
@@ -159,11 +160,16 @@ NETLINK_FAMILY nlControlFamilyOps = {
 
 /* Netlink datapath family. */
 NETLINK_CMD nlDatapathFamilyCmdOps[] = {
+    { .cmd             = OVS_DP_CMD_NEW,
+      .handler         = OvsNewDpCmdHandler,
+      .supportedDevOp  = OVS_TRANSACTION_DEV_OP,
+      .validateDpIndex = FALSE
+    },
     { .cmd             = OVS_DP_CMD_GET,
       .handler         = OvsGetDpCmdHandler,
       .supportedDevOp  = OVS_WRITE_DEV_OP | OVS_READ_DEV_OP |
                          OVS_TRANSACTION_DEV_OP,
-       .validateDpIndex = FALSE
+      .validateDpIndex = FALSE
     },
     { .cmd             = OVS_DP_CMD_SET,
       .handler         = OvsSetDpCmdHandler,
@@ -1076,6 +1082,19 @@ done:
 
 /*
  * --------------------------------------------------------------------------
+ *  Command Handler for 'OVS_DP_CMD_NEW'.
+ * --------------------------------------------------------------------------
+ */
+static NTSTATUS
+OvsNewDpCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
+                   UINT32 *replyLen)
+{
+    return HandleDpTransactionCommon(usrParamsCtx, replyLen);
+}
+
+
+/*
+ * --------------------------------------------------------------------------
  *  Command Handler for 'OVS_DP_CMD_GET'.
  *
  *  The function handles both the dump based as well as the transaction based
@@ -1104,7 +1123,7 @@ static NTSTATUS
 HandleGetDpTransaction(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
                        UINT32 *replyLen)
 {
-    return HandleDpTransaction(usrParamsCtx, replyLen);
+    return HandleDpTransactionCommon(usrParamsCtx, replyLen);
 }
 
 
@@ -1182,23 +1201,27 @@ static NTSTATUS
 OvsSetDpCmdHandler(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
                    UINT32 *replyLen)
 {
-    return HandleDpTransaction(usrParamsCtx, replyLen);
+    return HandleDpTransactionCommon(usrParamsCtx, replyLen);
 }
 
 /*
  * --------------------------------------------------------------------------
- *  Function for handling transaction based 'OVS_DP_CMD_GET' and
- *  'OVS_DP_CMD_SET' commands.
+ *  Function for handling transaction based 'OVS_DP_CMD_NEW', 'OVS_DP_CMD_GET'
+ *  and 'OVS_DP_CMD_SET' commands.
+ *
+ * 'OVS_DP_CMD_NEW' is implemented to keep userspace code happy. Creation of a
+ * new datapath is not supported currently.
  * --------------------------------------------------------------------------
  */
 static NTSTATUS
-HandleDpTransaction(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
-                    UINT32 *replyLen)
+HandleDpTransactionCommon(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
+                          UINT32 *replyLen)
 {
     POVS_MESSAGE msgIn = (POVS_MESSAGE)usrParamsCtx->inputBuffer;
     POVS_MESSAGE msgOut = (POVS_MESSAGE)usrParamsCtx->outputBuffer;
     NTSTATUS status = STATUS_SUCCESS;
     NL_BUFFER nlBuf;
+    NL_ERROR nlError = NL_ERROR_SUCCESS;
     static const NL_POLICY ovsDatapathSetPolicy[] = {
         [OVS_DP_ATTR_NAME] = { .type = NL_A_STRING, .maxLen = IFNAMSIZ },
         [OVS_DP_ATTR_UPCALL_PID] = { .type = NL_A_U32, .optional = TRUE },
@@ -1210,7 +1233,9 @@ HandleDpTransaction(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
     ASSERT(msgIn != NULL && usrParamsCtx->inputLength >= sizeof *msgIn);
 
     /* Parse any attributes in the request. */
-    if (usrParamsCtx->ovsMsg->genlMsg.cmd == OVS_DP_CMD_SET) {
+    if (usrParamsCtx->ovsMsg->genlMsg.cmd == OVS_DP_CMD_SET ||
+        usrParamsCtx->ovsMsg->genlMsg.cmd == OVS_DP_CMD_NEW) {
+
         if (!NlAttrParse((PNL_MSG_HDR)msgIn,
                         NLMSG_HDRLEN + GENL_HDRLEN + OVS_HDRLEN,
                         NlMsgAttrsLen((PNL_MSG_HDR)msgIn),
@@ -1240,12 +1265,25 @@ HandleDpTransaction(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
             !OvsCompareString(NlAttrGet(dpAttrs[OVS_DP_ATTR_NAME]),
                               OVS_SYSTEM_DP_NAME)) {
             OvsReleaseCtrlLock();
-            status = STATUS_NOT_FOUND;
+
+            /* Creation of new datapaths is not supported. */
+            if (usrParamsCtx->ovsMsg->genlMsg.cmd == OVS_DP_CMD_SET) {
+                nlError = NL_ERROR_NOTSUPP;
+                goto cleanup;
+            }
+
+            nlError = NL_ERROR_NODEV;
             goto cleanup;
         }
     } else if ((UINT32)msgIn->ovsHdr.dp_ifindex != gOvsSwitchContext->dpNo) {
         OvsReleaseCtrlLock();
-        status = STATUS_NOT_FOUND;
+        nlError = NL_ERROR_NODEV;
+        goto cleanup;
+    }
+
+    if (usrParamsCtx->ovsMsg->genlMsg.cmd == OVS_DP_CMD_NEW) {
+        OvsReleaseCtrlLock();
+        nlError = NL_ERROR_EXIST;
         goto cleanup;
     }
 
@@ -1255,7 +1293,15 @@ HandleDpTransaction(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
     *replyLen = NlBufSize(&nlBuf);
 
 cleanup:
-    return status;
+    if (nlError != NL_ERROR_SUCCESS) {
+        POVS_MESSAGE_ERROR msgError = (POVS_MESSAGE_ERROR)
+            usrParamsCtx->outputBuffer;
+
+        BuildErrorMsg(msgIn, msgError, nlError);
+        *replyLen = msgError->nlMsg.nlmsgLen;
+    }
+
+    return STATUS_SUCCESS;
 }
 
 
-- 
1.7.4.1




More information about the dev mailing list