From 82c2e30a84ad025496f997c3e9445ff5c4c9f6a1 Mon Sep 17 00:00:00 2001 From: tzachid Date: Mon, 21 Nov 2005 12:28:10 +0000 Subject: [PATCH] A hack that allows threading to work and various bug fixes (Rev 450) git-svn-id: svn://openib.tc.cornell.edu/gen1@179 ad392aa1-c5ef-ae45-8dd8-e69d62a5ef86 --- trunk/ulp/sdp/kernel/Precompile.h | 2 +- trunk/ulp/sdp/kernel/SdpDriver.cpp | 23 +++++++++++++++++++- trunk/ulp/sdp/kernel/SdpDriver.h | 3 +++ trunk/ulp/sdp/kernel/SdpLock.h | 2 +- trunk/ulp/sdp/kernel/SdpRecvPool.cpp | 4 ++-- trunk/ulp/sdp/kernel/SdpSocket.cpp | 8 ++++--- trunk/ulp/sdp/kernel/SdpUserFile.cpp | 32 +++++++++++++++++++++++++++- trunk/ulp/sdp/kernel/SdpUserFile.h | 4 +++- trunk/ulp/sdp/todo | 3 +++ 9 files changed, 71 insertions(+), 10 deletions(-) diff --git a/trunk/ulp/sdp/kernel/Precompile.h b/trunk/ulp/sdp/kernel/Precompile.h index 0fca28d9..f1741e1f 100644 --- a/trunk/ulp/sdp/kernel/Precompile.h +++ b/trunk/ulp/sdp/kernel/Precompile.h @@ -22,9 +22,9 @@ class SdpArp; #include "sdpLock.h" #include "RefCount.h" #include "SdpBufferPool.h" +#include "SdpUserFile.h" #include "sdpdriver.h" #include "SdpShared.h" -#include "SdpUserFile.h" #include "SdpRecvPool.h" #include "SdpConnectionList.h" #include "SdpSocket.h" diff --git a/trunk/ulp/sdp/kernel/SdpDriver.cpp b/trunk/ulp/sdp/kernel/SdpDriver.cpp index f975c88f..207c760f 100644 --- a/trunk/ulp/sdp/kernel/SdpDriver.cpp +++ b/trunk/ulp/sdp/kernel/SdpDriver.cpp @@ -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 )); goto Cleanup; } + + m_SdpGlobalSockets = new SdpUserFile; + if (m_SdpGlobalSockets == NULL) { + SDP_PRINT(SDP_ERR, SDP_DRIVER, ("new SdpUserFile failed \n")); + goto Cleanup; + } + + rc = m_SdpGlobalSockets->Init(); + if (!NT_SUCCESS(rc)) { + SDP_PRINT(SDP_ERR, SDP_DRIVER, ("m_SdpGlobalSockets->Init failed rc = 0x%x\n", rc )); + goto Cleanup; + } ExInitializeFastMutex(&m_ThreadsMutex); Cleanup: if (!NT_SUCCESS(rc)) { if (m_pSdpArp) { + m_pSdpArp->Shutdown(); delete m_pSdpArp; } + if (m_SdpGlobalSockets) { + m_SdpGlobalSockets->Shutdown(); + delete m_SdpGlobalSockets; + } } return rc; } @@ -335,6 +352,7 @@ VOID SdpDriver::Shutdown() { m_pSdpArp->Shutdown(); + m_SdpGlobalSockets->Shutdown(); WaitForAllThreadsToDie(); } @@ -537,7 +555,8 @@ SdpDriver::DispatchDeviceIoControl( } if (pWspAcceptOut->pAccaptedSocket != NULL) { pAcceptedSdpSocket = (SdpSocket *) pWspAcceptOut->pAccaptedSocket; - rc = pSdpUserFile->AddSocket(pAcceptedSdpSocket); + //rc = pSdpUserFile->AddSocket(pAcceptedSdpSocket); + rc = g_pSdpDriver->m_SdpGlobalSockets->AddSocket(pAcceptedSdpSocket); if (!NT_SUCCESS(rc)) { SDP_PRINT(SDP_ERR, SDP_DRIVER, ("pSdpUserFile->AddSocket failed rc = 0x%x\n", rc )); pAcceptedSdpSocket->Shutdown(); @@ -569,6 +588,8 @@ SdpDriver::DispatchDeviceIoControl( // be accessable for the user. (currently succesfull or not) // BUGBUG: Change this behavior while the linger don't linger staff is fixed pSdpUserFile->RemoveSocket(pSdpSocket); // Must succed + // BUGBUG: are we taking the socket from the correct place + // It is possible that not, but the chanses of an error seems small if (!NT_SUCCESS(rc)) { SDP_PRINT(SDP_ERR, SDP_DRIVER, ("pSdpSocket->WSPCloseSocket failed rc = 0x%x\n", rc )); goto Cleanup; diff --git a/trunk/ulp/sdp/kernel/SdpDriver.h b/trunk/ulp/sdp/kernel/SdpDriver.h index 0dd2793b..9f66c412 100644 --- a/trunk/ulp/sdp/kernel/SdpDriver.h +++ b/trunk/ulp/sdp/kernel/SdpDriver.h @@ -20,6 +20,7 @@ public: m_al_handle = NULL; m_pDevObj = NULL; m_pSdpArp = NULL; + m_SdpGlobalSockets = NULL; } NTSTATUS Init(PDEVICE_OBJECT pDevObj, PDRIVER_OBJECT DriverObject); @@ -58,6 +59,8 @@ public: ib_al_handle_t m_al_handle ; SdpArp *m_pSdpArp; + SdpUserFile *m_SdpGlobalSockets; + private: VOID WaitForThreadsToDie(LARGE_INTEGER *pWWaitTime); diff --git a/trunk/ulp/sdp/kernel/SdpLock.h b/trunk/ulp/sdp/kernel/SdpLock.h index b9118932..af447de8 100644 --- a/trunk/ulp/sdp/kernel/SdpLock.h +++ b/trunk/ulp/sdp/kernel/SdpLock.h @@ -284,7 +284,7 @@ Cleanup: return rc; } - VOID SignalError(NTSTATUS rc) {ASSERT (FALSE); + VOID SignalError(NTSTATUS rc) { m_flags |= ERROR_SIGNALLED; } diff --git a/trunk/ulp/sdp/kernel/SdpRecvPool.cpp b/trunk/ulp/sdp/kernel/SdpRecvPool.cpp index ba928e76..a49e7529 100644 --- a/trunk/ulp/sdp/kernel/SdpRecvPool.cpp +++ b/trunk/ulp/sdp/kernel/SdpRecvPool.cpp @@ -64,8 +64,8 @@ RecvPool::Init( NTSTATUS RecvPool::RecievedBuffer(BufferDescriptor *pBufferDescriptor, bool error) { - SDP_PRINT(SDP_DEBUG, SDP_BUFFER_POOL, ("this = 0x%p pBufferDescriptor = 0x%p error = %s\n" - ,m_pSdpSocket, pBufferDescriptor, error ? "true" : "false")); + SDP_PRINT(SDP_DEBUG, SDP_BUFFER_POOL, ("this = 0x%p pBufferDescriptor = 0x%p sucess = %s\n" + ,m_pSdpSocket, pBufferDescriptor, error ? "false" : "true")); AssertLocked(); NTSTATUS rc = STATUS_SUCCESS; diff --git a/trunk/ulp/sdp/kernel/SdpSocket.cpp b/trunk/ulp/sdp/kernel/SdpSocket.cpp index 59a31b13..b6837978 100644 --- a/trunk/ulp/sdp/kernel/SdpSocket.cpp +++ b/trunk/ulp/sdp/kernel/SdpSocket.cpp @@ -339,8 +339,8 @@ SdpSocket::WSPRecv( if ((m_state != SS_CONNECTED && m_state!= SS_CONNECTED_DREP_SENT ) ) { // We can not recv now. - SDP_PRINT(SDP_WARN, SDP_SOCKET, ("Can't recv now, m_state = %s\n", - SS2String(m_state) + SDP_PRINT(SDP_WARN, SDP_SOCKET, ("Can't recv now, m_state = %s this = %p\n", + SS2String(m_state), this )); rc = STATUS_SHUTDOWN_IN_PROGRESS; pWspRecvOut->Errno = WSAENOTCONN; @@ -915,6 +915,7 @@ SdpSocket::WSPAccept( Cleanup: ASSERT(Locked == false); if (NT_SUCCESS(rc) ) { + SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("this = 0x%p returning socket 0x%p \n",this, pNewSocket)); pWspAcceptOut->pAccaptedSocket = pNewSocket; pWspAcceptOut->IP = IP; pWspAcceptOut->Port = Port; @@ -1561,11 +1562,12 @@ ErrorLocked: VOID SdpSocket::CmRtuCallback(IN ib_cm_rtu_rec_t *p_cm_rtu_rec) { - SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("this = 0x%p\n", this)); NTSTATUS rc = STATUS_SUCCESS; ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL); SdpSocket *pSocket = (SdpSocket *) p_cm_rtu_rec->qp_context; + SDP_PRINT(SDP_TRACE, SDP_SOCKET, ("this = 0x%p pSocket = 0x%p\n", this, pSocket)); + // In order to make our model more consistent we increase the refcount here. // (This is not a must since this is a callback and we are gurantied that the last // callback won't happen untill we free IBAL) diff --git a/trunk/ulp/sdp/kernel/SdpUserFile.cpp b/trunk/ulp/sdp/kernel/SdpUserFile.cpp index d675f374..760d7084 100644 --- a/trunk/ulp/sdp/kernel/SdpUserFile.cpp +++ b/trunk/ulp/sdp/kernel/SdpUserFile.cpp @@ -2,6 +2,12 @@ #include "Precompile.h" +SdpUserFile::SdpUserFile() +{ + InitializeListHead(&m_SocketsList); + m_shutdown = false; +} + NTSTATUS SdpUserFile::Init() { KeInitializeSpinLock(&m_Lock); @@ -73,8 +79,9 @@ VOID SdpUserFile::RemoveSocket(SdpSocket *pSdpSocket) } -SdpSocket *SdpUserFile::SocketByPointer(VOID *Socket) +SdpSocket *SdpUserFile::SocketByPointer(VOID *Socket, bool LookInGlobal) { + NTSTATUS rc = STATUS_SUCCESS; SdpSocket *pSdpSocket = NULL; PLIST_ENTRY pNext; CSpinLockWrapper Lock(m_Lock); @@ -93,11 +100,34 @@ SdpSocket *SdpUserFile::SocketByPointer(VOID *Socket) } pNext = pNext->Flink; } + if (pSdpSocket != Socket) { + // We have found something, but this is not the correct object + pSdpSocket = NULL; + } if (pSdpSocket) { pSdpSocket->AddRef(); } Lock.Unlock(); + + if (pSdpSocket == NULL && LookInGlobal == true) { + // We are looking in the gloabl pool + pSdpSocket = g_pSdpDriver->m_SdpGlobalSockets->SocketByPointer(Socket, false); + if (pSdpSocket) { + // We will now move this socket to the correct place + RemoveSocket(pSdpSocket); // removes it no meter from + rc = AddSocket(pSdpSocket); + if(!NT_SUCCESS(rc)) { + // We free the socket and return NULL + SDP_PRINT(SDP_ERR, SDP_BUFFER_POOL, ("AddSocket failed rc = 0x%x\n", rc )); + pSdpSocket->Release(); + pSdpSocket = NULL; + } + + } + + + } return pSdpSocket; } diff --git a/trunk/ulp/sdp/kernel/SdpUserFile.h b/trunk/ulp/sdp/kernel/SdpUserFile.h index 1e782d3c..68c31ecb 100644 --- a/trunk/ulp/sdp/kernel/SdpUserFile.h +++ b/trunk/ulp/sdp/kernel/SdpUserFile.h @@ -23,10 +23,12 @@ private: public: + SdpUserFile(); + NTSTATUS Init(); VOID Shutdown(); - SdpSocket *SocketByPointer(VOID *Socket); + SdpSocket *SocketByPointer(VOID *Socket, bool LookInGlobal = true); NTSTATUS AddSocket(SdpSocket *pSdpSocket); diff --git a/trunk/ulp/sdp/todo b/trunk/ulp/sdp/todo index 1813675b..b5bb951a 100644 --- a/trunk/ulp/sdp/todo +++ b/trunk/ulp/sdp/todo @@ -26,6 +26,9 @@ general: Close the IPOIB device: Probably based on the example from src\general\toaster\toastmon\toastmon.c proabably (EventCategoryDeviceInterfaceChange) + Find a better solution for threading and remove the current solution. + Fix the race of sdp user file + USER MODE: -- 2.41.0