[ovs-dev] [PATCH 1/6 v3] datapath-windows: refactor port enumeration code

Nithin Raju nithin at vmware.com
Wed Nov 25 20:00:53 UTC 2015


We already have functions HvCreatePort() and HvCreateNic() to
do the work. Might as well use that during port enumeration.
More refactoring in later patches.

Signed-off-by: Nithin Raju <nithin at vmware.com>
Acked-by: Sairam Venugopal <vsairam at vmware.com>
Acked-by: Alin Gabriel Serdean <aserdean at cloudbasesolutions.com>

---
 datapath-windows/ovsext/Switch.c |  6 ++-
 datapath-windows/ovsext/Vport.c  | 89 ++++++++++++----------------------------
 2 files changed, 31 insertions(+), 64 deletions(-)

diff --git a/datapath-windows/ovsext/Switch.c b/datapath-windows/ovsext/Switch.c
index 2878e91..a783ea1 100644
--- a/datapath-windows/ovsext/Switch.c
+++ b/datapath-windows/ovsext/Switch.c
@@ -549,6 +549,7 @@ OvsActivateSwitch(POVS_SWITCH_CONTEXT switchContext)
     OVS_LOG_TRACE("Enter: activate switch %p, dpNo: %ld",
                   switchContext, switchContext->dpNo);
 
+    switchContext->isActivated = TRUE;
     status = OvsAddConfiguredSwitchPorts(switchContext);
 
     if (status != NDIS_STATUS_SUCCESS) {
@@ -563,10 +564,13 @@ OvsActivateSwitch(POVS_SWITCH_CONTEXT switchContext)
         OvsClearAllSwitchVports(switchContext);
         goto cleanup;
     }
-    switchContext->isActivated = TRUE;
     OvsPostEvent(OVS_DEFAULT_PORT_NO, OVS_DEFAULT_EVENT_STATUS);
 
 cleanup:
+    if (status != NDIS_STATUS_SUCCESS) {
+        switchContext->isActivated = TRUE;
+    }
+
     OVS_LOG_TRACE("Exit: activate switch:%p, isActivated: %s, status = %lx",
                   switchContext,
                   (switchContext->isActivated ? "TRUE" : "FALSE"), status);
diff --git a/datapath-windows/ovsext/Vport.c b/datapath-windows/ovsext/Vport.c
index 3f90039..dac537f 100644
--- a/datapath-windows/ovsext/Vport.c
+++ b/datapath-windows/ovsext/Vport.c
@@ -376,6 +376,12 @@ HvCreateNic(POVS_SWITCH_CONTEXT switchContext,
 
 add_nic_done:
     NdisReleaseRWLock(switchContext->dispatchLock, &lockState);
+    if (status == STATUS_SUCCESS &&
+        (vport->portType == NdisSwitchPortTypeInternal ||
+         (vport->portType == NdisSwitchPortTypeExternal &&
+          nicParam->NicIndex != 0))) {
+        AssignNicNameSpecial(vport);
+    }
     if (portNo != OVS_DPPORT_NUMBER_INVALID && event) {
         OvsPostEvent(portNo, event);
     }
@@ -1017,6 +1023,10 @@ AssignNicNameSpecial(POVS_VPORT_ENTRY vport)
     status = ConvertInterfaceGuidToLuid(&vport->netCfgInstanceId,
                                         &interfaceLuid);
     if (status == STATUS_SUCCESS) {
+        /*
+         * Must be called from PASSIVE_LEVEL. Resulted in a
+         * STATUS_INVALID_DEVICE_REQUEST if not.
+         */
         status = ConvertInterfaceLuidToAlias(&interfaceLuid, interfaceName,
                                              IF_MAX_STRING_SIZE + 1);
         if (status == STATUS_SUCCESS) {
@@ -1333,8 +1343,11 @@ OvsRemoveTunnelVport(POVS_USER_PARAMS_CONTEXT usrParamsCtx,
                                  tunnelContext);
 }
 
-
-
+/*
+ * --------------------------------------------------------------------------
+ * Enumerates the ports on the Hyper-V switch.
+ * --------------------------------------------------------------------------
+ */
 NDIS_STATUS
 OvsAddConfiguredSwitchPorts(POVS_SWITCH_CONTEXT switchContext)
 {
@@ -1342,7 +1355,6 @@ OvsAddConfiguredSwitchPorts(POVS_SWITCH_CONTEXT switchContext)
     ULONG arrIndex;
     PNDIS_SWITCH_PORT_PARAMETERS portParam;
     PNDIS_SWITCH_PORT_ARRAY portArray = NULL;
-    POVS_VPORT_ENTRY vport;
 
     OVS_LOG_TRACE("Enter: switchContext:%p", switchContext);
 
@@ -1358,16 +1370,9 @@ OvsAddConfiguredSwitchPorts(POVS_SWITCH_CONTEXT switchContext)
              continue;
          }
 
-         vport = (POVS_VPORT_ENTRY)OvsAllocateVport();
-         if (vport == NULL) {
-             status = NDIS_STATUS_RESOURCES;
-             goto cleanup;
-         }
-         OvsInitVportWithPortParam(vport, portParam);
-         status = InitHvVportCommon(switchContext, vport, TRUE);
-         if (status != NDIS_STATUS_SUCCESS) {
-             OvsFreeMemoryWithTag(vport, OVS_VPORT_POOL_TAG);
-             goto cleanup;
+         status = HvCreatePort(switchContext, portParam);
+         if (status != STATUS_SUCCESS && status != STATUS_DATA_NOT_ACCEPTED) {
+             break;
          }
     }
 
@@ -1383,7 +1388,11 @@ cleanup:
     return status;
 }
 
-
+/*
+ * --------------------------------------------------------------------------
+ * Enumerates the NICs on the Hyper-V switch.
+ * --------------------------------------------------------------------------
+ */
 NDIS_STATUS
 OvsInitConfiguredSwitchNics(POVS_SWITCH_CONTEXT switchContext)
 {
@@ -1391,7 +1400,6 @@ OvsInitConfiguredSwitchNics(POVS_SWITCH_CONTEXT switchContext)
     PNDIS_SWITCH_NIC_ARRAY nicArray = NULL;
     ULONG arrIndex;
     PNDIS_SWITCH_NIC_PARAMETERS nicParam;
-    POVS_VPORT_ENTRY vport;
 
     OVS_LOG_TRACE("Enter: switchContext: %p", switchContext);
     /*
@@ -1402,63 +1410,18 @@ OvsInitConfiguredSwitchNics(POVS_SWITCH_CONTEXT switchContext)
         goto cleanup;
     }
     for (arrIndex = 0; arrIndex < nicArray->NumElements; ++arrIndex) {
-
         nicParam = NDIS_SWITCH_NIC_AT_ARRAY_INDEX(nicArray, arrIndex);
 
         /*
          * XXX: Check if the port is configured with a VLAN. Disallow such a
          * configuration, since we don't support tag-in-tag.
-         */
-
-        /*
          * XXX: Check if the port is connected to a VF. Disconnect the VF in
          * such a case.
          */
 
-        if (nicParam->NicType == NdisSwitchNicTypeExternal &&
-            nicParam->NicIndex != 0) {
-            POVS_VPORT_ENTRY virtExtVport =
-                   (POVS_VPORT_ENTRY)switchContext->virtualExternalVport;
-
-            vport = OvsAllocateVport();
-            if (vport) {
-                OvsInitPhysNicVport(vport, virtExtVport,
-                                    nicParam->NicIndex);
-                OvsInitVportWithNicParam(switchContext, vport, nicParam);
-                status = InitHvVportCommon(switchContext, vport, TRUE);
-                if (status != NDIS_STATUS_SUCCESS) {
-                    OvsFreeMemoryWithTag(vport, OVS_VPORT_POOL_TAG);
-                    vport = NULL;
-                }
-            } else {
-                OVS_LOG_ERROR("Fail to allocate vport.");
-                continue;
-            }
-        } else {
-            vport = OvsFindVportByPortIdAndNicIndex(switchContext,
-                                                    nicParam->PortId,
-                                                    nicParam->NicIndex);
-            if (vport == NULL) {
-                OVS_LOG_ERROR(
-                    "Could not found vport with portId: %d and nicIndex: %d.",
-                    nicParam->PortId, nicParam->NicIndex);
-                continue;
-            }
-            OvsInitVportWithNicParam(switchContext, vport, nicParam);
-        }
-
-        if (nicParam->NicType == NdisSwitchNicTypeInternal) {
-            /*
-             * Overwrite the 'portFriendlyName' of the internal vport. 
-             * Note:
-             * The call to AssignNicNameSpecial() is needed here, because the
-             * necessary 'netCfgInstanceId' of the vport is available.
-             * On port creation the latter information is missing and the
-             * 'portFriendlyName' of the vport fails to be overwritten with the
-             * correct information.
-             */
-            AssignNicNameSpecial(vport);
-            OvsInternalAdapterUp(vport->portNo, &nicParam->NetCfgInstanceId);
+        status = HvCreateNic(switchContext, nicParam);
+        if (status == NDIS_STATUS_SUCCESS) {
+            HvConnectNic(switchContext, nicParam);
         }
     }
 cleanup:
-- 
1.8.5.6




More information about the dev mailing list