[ovs-dev,2/4] datapath-windows: Changed gOvsCtrlLock into a passive-level lock
diff mbox

Message ID 1441199397-20449-3-git-send-email-svinturis@cloudbasesolutions.com
State Deferred
Headers show

Commit Message

Sorin Vinturis Sept. 30, 2015, 1:29 p.m. UTC
There is the need for a passive level lock, in order for the tunnel
filter initialization to successfully complete. Also, there are
cases where shared synchronization is enough and an ERESOURCE
object provides both exclusive/shared synchronization.

Signed-off-by: Sorin Vinturis <svinturis@cloudbasesolutions.com>
---
 datapath-windows/ovsext/Datapath.c | 26 ++++++++++++++------------
 datapath-windows/ovsext/Datapath.h |  2 +-
 datapath-windows/ovsext/User.c     |  7 +++----
 3 files changed, 18 insertions(+), 17 deletions(-)

Patch
diff mbox

diff --git a/datapath-windows/ovsext/Datapath.c b/datapath-windows/ovsext/Datapath.c
index b3dbd71..96505e0 100644
--- a/datapath-windows/ovsext/Datapath.c
+++ b/datapath-windows/ovsext/Datapath.c
@@ -343,8 +343,8 @@  POVS_OPEN_INSTANCE ovsOpenInstanceArray[OVS_MAX_OPEN_INSTANCES];
 UINT32 ovsNumberOfOpenInstances;
 extern POVS_SWITCH_CONTEXT gOvsSwitchContext;
 
-NDIS_SPIN_LOCK ovsCtrlLockObj;
-PNDIS_SPIN_LOCK gOvsCtrlLock;
+ERESOURCE ovsCtrlLockObj;
+PERESOURCE gOvsCtrlLock;
 
 NTSTATUS
 InitUserDumpState(POVS_OPEN_INSTANCE instance,
@@ -382,7 +382,7 @@  VOID
 OvsInit()
 {
     gOvsCtrlLock = &ovsCtrlLockObj;
-    NdisAllocateSpinLock(gOvsCtrlLock);
+    ExInitializeResourceLite(gOvsCtrlLock);
     OvsInitEventQueue();
 }
 
@@ -390,22 +390,24 @@  VOID
 OvsCleanup()
 {
     OvsCleanupEventQueue();
-    if (gOvsCtrlLock) {
-        NdisFreeSpinLock(gOvsCtrlLock);
-        gOvsCtrlLock = NULL;
-    }
+    ExDeleteResourceLite(gOvsCtrlLock);
+    gOvsCtrlLock = NULL;
 }
 
 VOID
-OvsAcquireCtrlLock()
+OvsAcquireCtrlLock(BOOLEAN exclusive)
 {
-    NdisAcquireSpinLock(gOvsCtrlLock);
+    if (exclusive) {
+        ExAcquireResourceExclusiveLite(gOvsCtrlLock, TRUE);
+    } else {
+        ExAcquireResourceSharedLite(gOvsCtrlLock, TRUE);
+    }
 }
 
 VOID
 OvsReleaseCtrlLock()
 {
-    NdisReleaseSpinLock(gOvsCtrlLock);
+    ExReleaseResourceLite(gOvsCtrlLock);
 }
 
 
@@ -532,7 +534,7 @@  OvsAddOpenInstance(POVS_DEVICE_EXTENSION ovsExt,
     if (instance == NULL) {
         return STATUS_NO_MEMORY;
     }
-    OvsAcquireCtrlLock();
+    OvsAcquireCtrlLock(TRUE);
     ASSERT(OvsFindOpenInstance(fileObject) == NULL);
 
     if (ovsNumberOfOpenInstances >= OVS_MAX_OPEN_INSTANCES) {
@@ -580,7 +582,7 @@  OvsRemoveOpenInstance(PFILE_OBJECT fileObject)
     instance = (POVS_OPEN_INSTANCE)fileObject->FsContext;
     ASSERT(instance->cookie < OVS_MAX_OPEN_INSTANCES);
 
-    OvsAcquireCtrlLock();
+    OvsAcquireCtrlLock(TRUE);
     fileObject->FsContext = NULL;
     ASSERT(ovsOpenInstanceArray[instance->cookie] == instance);
     ovsOpenInstanceArray[instance->cookie] = NULL;
diff --git a/datapath-windows/ovsext/Datapath.h b/datapath-windows/ovsext/Datapath.h
index 2c61d82..010c1c5 100644
--- a/datapath-windows/ovsext/Datapath.h
+++ b/datapath-windows/ovsext/Datapath.h
@@ -73,7 +73,7 @@  POVS_OPEN_INSTANCE OvsGetOpenInstance(PFILE_OBJECT fileObject,
 
 NTSTATUS OvsCompleteIrpRequest(PIRP irp, ULONG_PTR infoPtr, NTSTATUS status);
 
-VOID OvsAcquireCtrlLock();
+VOID OvsAcquireCtrlLock(BOOLEAN exclusive);
 VOID OvsReleaseCtrlLock();
 
 /*
diff --git a/datapath-windows/ovsext/User.c b/datapath-windows/ovsext/User.c
index e7be904..a19b4a1 100644
--- a/datapath-windows/ovsext/User.c
+++ b/datapath-windows/ovsext/User.c
@@ -41,7 +41,6 @@ 
 #include "Debug.h"
 
 POVS_PACKET_QUEUE_ELEM OvsGetNextPacket(POVS_OPEN_INSTANCE instance);
-extern PNDIS_SPIN_LOCK gOvsCtrlLock;
 extern POVS_SWITCH_CONTEXT gOvsSwitchContext;
 OVS_USER_STATS ovsUserStats;
 
@@ -532,16 +531,16 @@  OvsCancelIrpDatapath(PDEVICE_OBJECT deviceObject,
     if (fileObject == NULL) {
         goto done;
     }
-    NdisAcquireSpinLock(gOvsCtrlLock);
+    OvsAcquireCtrlLock(FALSE);
     instance = (POVS_OPEN_INSTANCE)fileObject->FsContext;
     if (instance) {
         queue = instance->packetQueue;
     }
     if (instance == NULL || queue == NULL) {
-        NdisReleaseSpinLock(gOvsCtrlLock);
+        OvsReleaseCtrlLock();
         goto done;
     }
-    NdisReleaseSpinLock(gOvsCtrlLock);
+    OvsReleaseCtrlLock();
     NdisAcquireSpinLock(&queue->queueLock);
     if (queue->pendingIrp == irp) {
         queue->pendingIrp = NULL;