A hack that allows threading to work and various bug fixes (Rev 450)
authortzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 21 Nov 2005 12:28:10 +0000 (12:28 +0000)
committertzachid <tzachid@ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86>
Mon, 21 Nov 2005 12:28:10 +0000 (12:28 +0000)
git-svn-id: svn://openib.tc.cornell.edu/gen1/trunk@179 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86

ulp/sdp/kernel/Precompile.h
ulp/sdp/kernel/SdpDriver.cpp
ulp/sdp/kernel/SdpDriver.h
ulp/sdp/kernel/SdpLock.h
ulp/sdp/kernel/SdpRecvPool.cpp
ulp/sdp/kernel/SdpSocket.cpp
ulp/sdp/kernel/SdpUserFile.cpp
ulp/sdp/kernel/SdpUserFile.h
ulp/sdp/todo

index 0fca28d..f1741e1 100644 (file)
@@ -22,9 +22,9 @@ class SdpArp;
 #include "sdpLock.h"\r
 #include "RefCount.h"\r
 #include "SdpBufferPool.h"\r
+#include "SdpUserFile.h"\r
 #include "sdpdriver.h"\r
 #include "SdpShared.h"\r
-#include "SdpUserFile.h"\r
 #include "SdpRecvPool.h"\r
 #include "SdpConnectionList.h"\r
 #include "SdpSocket.h"\r
index f975c88..207c760 100644 (file)
@@ -319,14 +319,31 @@ SdpDriver::Init(PDEVICE_OBJECT pDevObj, PDRIVER_OBJECT  DriverObject)
         SDP_PRINT(SDP_ERR, SDP_DRIVER, ("m_pSdpArp->Init failed rc = 0x%x\n", rc ));        \r
         goto Cleanup;\r
     }\r
+    \r
+    m_SdpGlobalSockets = new SdpUserFile; \r
+    if (m_SdpGlobalSockets == NULL) {\r
+        SDP_PRINT(SDP_ERR, SDP_DRIVER, ("new SdpUserFile failed \n"));        \r
+        goto Cleanup;\r
+    }\r
+\r
+    rc = m_SdpGlobalSockets->Init();\r
+    if (!NT_SUCCESS(rc)) {\r
+        SDP_PRINT(SDP_ERR, SDP_DRIVER, ("m_SdpGlobalSockets->Init failed rc = 0x%x\n", rc ));        \r
+        goto Cleanup;\r
+    }\r
 \r
     ExInitializeFastMutex(&m_ThreadsMutex);\r
     \r
 Cleanup:\r
     if (!NT_SUCCESS(rc)) {\r
         if (m_pSdpArp) {\r
+            m_pSdpArp->Shutdown();\r
             delete m_pSdpArp;\r
         }\r
+        if (m_SdpGlobalSockets) {\r
+            m_SdpGlobalSockets->Shutdown();\r
+            delete m_SdpGlobalSockets;\r
+        }\r
     }\r
     return rc;\r
 }\r
@@ -335,6 +352,7 @@ VOID
 SdpDriver::Shutdown()\r
 {\r
     m_pSdpArp->Shutdown();\r
+    m_SdpGlobalSockets->Shutdown();\r
     WaitForAllThreadsToDie();\r
 \r
 }\r
@@ -537,7 +555,8 @@ SdpDriver::DispatchDeviceIoControl(
             }\r
             if (pWspAcceptOut->pAccaptedSocket != NULL) {\r
                 pAcceptedSdpSocket = (SdpSocket *) pWspAcceptOut->pAccaptedSocket;\r
-                rc = pSdpUserFile->AddSocket(pAcceptedSdpSocket);\r
+                //rc = pSdpUserFile->AddSocket(pAcceptedSdpSocket);\r
+                rc = g_pSdpDriver->m_SdpGlobalSockets->AddSocket(pAcceptedSdpSocket);\r
                 if (!NT_SUCCESS(rc)) {\r
                     SDP_PRINT(SDP_ERR, SDP_DRIVER, ("pSdpUserFile->AddSocket failed rc = 0x%x\n", rc ));\r
                     pAcceptedSdpSocket->Shutdown();\r
@@ -569,6 +588,8 @@ SdpDriver::DispatchDeviceIoControl(
             // be accessable for the user. (currently succesfull or not)\r
             // BUGBUG: Change this behavior while the linger don't linger staff is fixed\r
             pSdpUserFile->RemoveSocket(pSdpSocket); // Must succed\r
+            // BUGBUG: are we taking the socket from the correct place\r
+            // It is possible that not, but the chanses of an error seems small\r
             if (!NT_SUCCESS(rc)) {\r
                 SDP_PRINT(SDP_ERR, SDP_DRIVER, ("pSdpSocket->WSPCloseSocket failed rc = 0x%x\n", rc ));        \r
                 goto Cleanup; \r
index 0dd2793..9f66c41 100644 (file)
@@ -20,6 +20,7 @@ public:
         m_al_handle = NULL;\r
         m_pDevObj = NULL;\r
         m_pSdpArp = NULL;\r
+        m_SdpGlobalSockets = NULL;\r
     }\r
     \r
        NTSTATUS Init(PDEVICE_OBJECT pDevObj, PDRIVER_OBJECT  DriverObject);\r
@@ -58,6 +59,8 @@ public:
     ib_al_handle_t m_al_handle ;\r
     SdpArp *m_pSdpArp;\r
 \r
+    SdpUserFile *m_SdpGlobalSockets;\r
+\r
 private:\r
 \r
     VOID WaitForThreadsToDie(LARGE_INTEGER  *pWWaitTime);\r
index b911893..af447de 100644 (file)
@@ -284,7 +284,7 @@ Cleanup:
         return rc;\r
     }\r
 \r
-    VOID SignalError(NTSTATUS rc) {ASSERT (FALSE);\r
+    VOID SignalError(NTSTATUS rc) {\r
         m_flags |= ERROR_SIGNALLED;\r
     } \r
 \r
index ba928e7..a49e752 100644 (file)
@@ -64,8 +64,8 @@ RecvPool::Init(
 NTSTATUS\r
 RecvPool::RecievedBuffer(BufferDescriptor *pBufferDescriptor, bool error)\r
 {\r
-    SDP_PRINT(SDP_DEBUG, SDP_BUFFER_POOL, ("this = 0x%p pBufferDescriptor = 0x%p error = %s\n"\r
-        ,m_pSdpSocket, pBufferDescriptor, error ? "true" : "false"));\r
+    SDP_PRINT(SDP_DEBUG, SDP_BUFFER_POOL, ("this = 0x%p pBufferDescriptor = 0x%p sucess = %s\n"\r
+        ,m_pSdpSocket, pBufferDescriptor, error ? "false" : "true"));\r
     AssertLocked();\r
     NTSTATUS rc = STATUS_SUCCESS;\r
 \r
index 59a31b1..b683797 100644 (file)
@@ -339,8 +339,8 @@ SdpSocket::WSPRecv(
 \r
         if ((m_state != SS_CONNECTED && m_state!= SS_CONNECTED_DREP_SENT ) ) {\r
             // We can not recv now.\r
-            SDP_PRINT(SDP_WARN, SDP_SOCKET, ("Can't recv now, m_state = %s\n",\r
-                SS2String(m_state)\r
+            SDP_PRINT(SDP_WARN, SDP_SOCKET, ("Can't recv now, m_state = %s this = %p\n",\r
+                SS2String(m_state), this\r
             ));\r
             rc = STATUS_SHUTDOWN_IN_PROGRESS;\r
             pWspRecvOut->Errno = WSAENOTCONN;\r
@@ -915,6 +915,7 @@ SdpSocket::WSPAccept(
 Cleanup:    \r
     ASSERT(Locked == false);\r
     if (NT_SUCCESS(rc) ) {\r
+        SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("this = 0x%p returning socket 0x%p \n",this, pNewSocket));\r
         pWspAcceptOut->pAccaptedSocket = pNewSocket;\r
         pWspAcceptOut->IP = IP;\r
         pWspAcceptOut->Port = Port;\r
@@ -1561,11 +1562,12 @@ ErrorLocked:
 VOID \r
 SdpSocket::CmRtuCallback(IN   ib_cm_rtu_rec_t *p_cm_rtu_rec)\r
 {\r
-    SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("this = 0x%p\n", this));\r
     NTSTATUS rc = STATUS_SUCCESS;\r
     ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL);\r
 \r
     SdpSocket *pSocket = (SdpSocket *) p_cm_rtu_rec->qp_context;\r
+    SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("this = 0x%p pSocket = 0x%p\n", this, pSocket));\r
+\r
     // In order to make our model more consistent we increase the refcount here.\r
     // (This is not a must since this is a callback and we are gurantied that the last\r
     // callback won't happen untill we free IBAL)\r
index d675f37..760d708 100644 (file)
@@ -2,6 +2,12 @@
 \r
 #include "Precompile.h"\r
 \r
+SdpUserFile::SdpUserFile()\r
+{\r
+    InitializeListHead(&m_SocketsList);\r
+    m_shutdown = false;\r
+}\r
+\r
 NTSTATUS SdpUserFile::Init()\r
 {\r
     KeInitializeSpinLock(&m_Lock);\r
@@ -73,8 +79,9 @@ VOID SdpUserFile::RemoveSocket(SdpSocket *pSdpSocket)
 }\r
 \r
 \r
-SdpSocket *SdpUserFile::SocketByPointer(VOID *Socket)\r
+SdpSocket *SdpUserFile::SocketByPointer(VOID *Socket, bool LookInGlobal)\r
 {\r
+    NTSTATUS rc = STATUS_SUCCESS;\r
     SdpSocket *pSdpSocket = NULL;\r
     PLIST_ENTRY pNext;\r
     CSpinLockWrapper Lock(m_Lock);\r
@@ -93,11 +100,34 @@ SdpSocket *SdpUserFile::SocketByPointer(VOID *Socket)
         }\r
         pNext = pNext->Flink;\r
     }\r
+    if (pSdpSocket != Socket) {\r
+        // We have found something, but this is not the correct object\r
+        pSdpSocket = NULL;\r
+    }\r
     if (pSdpSocket) {   \r
         pSdpSocket->AddRef();\r
     }\r
     \r
     Lock.Unlock();\r
+\r
+    if (pSdpSocket == NULL && LookInGlobal == true) {\r
+        // We are looking in the gloabl pool\r
+        pSdpSocket = g_pSdpDriver->m_SdpGlobalSockets->SocketByPointer(Socket, false);\r
+        if (pSdpSocket) {\r
+            // We will now move this socket to the correct place\r
+            RemoveSocket(pSdpSocket); // removes it no meter from\r
+            rc = AddSocket(pSdpSocket);\r
+            if(!NT_SUCCESS(rc)) {\r
+                // We free the socket and return NULL\r
+                SDP_PRINT(SDP_ERR, SDP_BUFFER_POOL, ("AddSocket failed rc = 0x%x\n", rc ));\r
+                pSdpSocket->Release();\r
+                pSdpSocket = NULL;\r
+            }\r
+            \r
+        }\r
+        \r
+\r
+    }\r
     return pSdpSocket;\r
 }\r
 \r
index 1e782d3..68c31ec 100644 (file)
@@ -23,10 +23,12 @@ private:
     \r
 public:\r
 \r
+    SdpUserFile();\r
+\r
     NTSTATUS Init();\r
     VOID Shutdown();\r
 \r
-    SdpSocket *SocketByPointer(VOID *Socket);\r
+    SdpSocket *SocketByPointer(VOID *Socket, bool LookInGlobal = true);\r
     \r
     NTSTATUS AddSocket(SdpSocket *pSdpSocket);\r
 \r
index 1813675..b5bb951 100644 (file)
@@ -26,6 +26,9 @@ general:
        Close the IPOIB device: Probably based on the example from src\general\toaster\toastmon\toastmon.c\r
        proabably (EventCategoryDeviceInterfaceChange)\r
        \r
+       Find a better solution for threading and remove the current solution.\r
+       Fix the race of sdp user file\r
+       \r
 \r
 USER MODE:\r
 \r