datapath-windows: don't free switch cxt until ref == 0
authorNithin Raju <nithin@vmware.com>
Thu, 23 Apr 2015 00:10:10 +0000 (17:10 -0700)
committerBen Pfaff <blp@nicira.com>
Thu, 23 Apr 2015 18:01:38 +0000 (11:01 -0700)
This is a hard to hit corner case, because currently we recommend that
all handles to the kernel datapath be closed before trying to unload the
OVS extension.

Signed-off-by: Nithin Raju <nithin@vmware.com>
Acked-by: Sorin Vinturis <svinturis@cloudbasesolutions.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
datapath-windows/ovsext/Switch.c

index 11092de..9e1e9a4 100644 (file)
@@ -211,7 +211,6 @@ OvsCreateSwitch(NDIS_HANDLE ndisFilterHandle,
     status = OvsTunnelFilterInitialize(gOvsExtDriverObject);
     if (status != NDIS_STATUS_SUCCESS) {
         OvsUninitSwitchContext(switchContext);
     status = OvsTunnelFilterInitialize(gOvsExtDriverObject);
     if (status != NDIS_STATUS_SUCCESS) {
         OvsUninitSwitchContext(switchContext);
-        OvsFreeMemoryWithTag(switchContext, OVS_SWITCH_POOL_TAG);
         goto create_switch_done;
     }
     *switchContextOut = switchContext;
         goto create_switch_done;
     }
     *switchContextOut = switchContext;
@@ -270,7 +269,6 @@ OvsDeleteSwitch(POVS_SWITCH_CONTEXT switchContext)
         OvsTunnelFilterUninitialize(gOvsExtDriverObject);
         OvsClearAllSwitchVports(switchContext);
         OvsUninitSwitchContext(switchContext);
         OvsTunnelFilterUninitialize(gOvsExtDriverObject);
         OvsClearAllSwitchVports(switchContext);
         OvsUninitSwitchContext(switchContext);
-        OvsFreeMemoryWithTag(switchContext, OVS_SWITCH_POOL_TAG);
     }
     OVS_LOG_TRACE("Exit: deleted switch %p  dpNo: %d", switchContext, dpNo);
 }
     }
     OVS_LOG_TRACE("Exit: deleted switch %p  dpNo: %d", switchContext, dpNo);
 }
@@ -441,7 +439,12 @@ OvsUninitSwitchContext(POVS_SWITCH_CONTEXT switchContext)
     OvsReleaseSwitchContext(switchContext);
 }
 
     OvsReleaseSwitchContext(switchContext);
 }
 
-VOID
+/*
+ * --------------------------------------------------------------------------
+ *  Frees up the contents of and also the switch context.
+ * --------------------------------------------------------------------------
+ */
+static VOID
 OvsDeleteSwitchContext(POVS_SWITCH_CONTEXT switchContext)
 {
     OVS_LOG_TRACE("Enter: Delete switchContext:%p", switchContext);
 OvsDeleteSwitchContext(POVS_SWITCH_CONTEXT switchContext)
 {
     OVS_LOG_TRACE("Enter: Delete switchContext:%p", switchContext);
@@ -467,6 +470,8 @@ OvsDeleteSwitchContext(POVS_SWITCH_CONTEXT switchContext)
     switchContext->pidHashArray = NULL;
     OvsDeleteFlowTable(&switchContext->datapath);
     OvsCleanupBufferPool(switchContext);
     switchContext->pidHashArray = NULL;
     OvsDeleteFlowTable(&switchContext->datapath);
     OvsCleanupBufferPool(switchContext);
+
+    OvsFreeMemoryWithTag(switchContext, OVS_SWITCH_POOL_TAG);
     OVS_LOG_TRACE("Exit: Delete switchContext: %p", switchContext);
 }
 
     OVS_LOG_TRACE("Exit: Delete switchContext: %p", switchContext);
 }