Dumping the state of a resource or locking at any members whithout acquiring its internal locks is kinda unsafe. Use a debugger , and dont relay on dbg prits for serious debugging. I cant figure out what happnes there from your code. As Rob says , your design is most likely broken.
----- Original Message -----
From: Lijun Wang
To: File Systems Developers
Sent: Wednesday, July 10, 2002 6:29 PM
Subject: [ntfsd] Re: Can’t acquire resource!
I am implmenting the redirector in C++. The resource was being acquired and released through a member function only. By monitoring the lock function, I am pretty sure it was not locked in between the two event. Since I don’t have another machine, I can’t use Windbg to debug it in real time. In stead, I ouput the information about the resource by writing to a file.
Following is the code managing the resource. Anything wrong with it?
Lijun
LLFsd_SynConnection::LLFsd_SynConnection(
LLFsd_Driver * driver,
PDEVICE_OBJECT driverDevice,
PDEVICE_OBJECT transport,
PFILE_OBJECT TransportFile):
LLFsd_Connection(driver, driverDevice, transport, TransportFile)
{
LilyZeroMemory(&m_Resource, sizeof(ERESOURCE));
ExInitializeResourceLite(&m_Resource);
}
LLFsd_SynConnection::~LLFsd_SynConnection()
{
// release resource…
//UnLock();
ExDeleteResourceLite(&m_Resource);
}
bool LLFsd_SynConnection::Lock(bool bExclusive /*= true */, bool bWait /*= true*/)
{
#ifdef LOG_DEBUG
char mess[1024];
sprintf(mess, “Lock: Owner Thread %p %p %p %d\n”,
m_Resource.OwnerThreads[0].OwnerThread,
m_Resource.OwnerThreads[1].OwnerThread,
m_Resource.OwnerTable,
m_Resource.ActiveCount);
LLFsdLog(mess, LLFSD_GLOBAL_DATA.logfile);
#endif
if(ExIsResourceAcquiredExclusiveLite(&m_Resource)) {
return true;
}
BOOLEAN bAcquired = false;
{
if(bExclusive) {
bAcquired = ExAcquireResourceExclusiveLite(&m_Resource, bWait);
}
else {
bAcquired = ExAcquireResourceSharedLite(&m_Resource, bWait);
}
}
#ifdef LOG_DEBUG
sprintf(mess, “[ LLFsd_SynConnection: Locked, Thread %p\n”, ExGetCurrentResourceThread());
LLFsdLog(mess, LLFSD_GLOBAL_DATA.logfile);
#endif
return (bAcquired != 0);
}
// IRQL <= DISPATCH_LEVEL.
void LLFsd_SynConnection::UnLock()
{
ExReleaseResourceForThreadLite(&m_Resource,
ExGetCurrentResourceThread());
#ifdef LOG_DEBUG
char mess[1024];
sprintf(mess, “] LLFsd_SynConnection: UnLock, Thread %p releaed %d\n”,
ExGetCurrentResourceThread(),
!ExIsResourceAcquiredExclusiveLite(&m_Resource));
LLFsdLog(mess, LLFSD_GLOBAL_DATA.logfile);
sprintf(mess, “After Unlock: Owner Thread %p %p %p %d\n”,
m_Resource.OwnerThreads[0].OwnerThread,
m_Resource.OwnerThreads[1].OwnerThread,
m_Resource.OwnerTable,
m_Resource.ActiveCount);
LLFsdLog(mess, LLFSD_GLOBAL_DATA.logfile);
#endif
}
Dan Partelly wrote:
Somewhere , in between, something happens which makes the resource to be acquired again , and never released. Windbg is preety acurate in dumping ERESOURCE objects. Are you by any chanche acquiring the resource and hold it untill IoCompletion occures or something like that ?
“Lijun Wang” wrote in message news:xxxxx@ntfsd…
Dan,
Sorry for the confusion. It happens in such a senario:
The resource was last succesfully locked in one thread, say, thread A, in an IRP_MJ_QUERY_INFORMATION request then released. Dump from thread A shows it was actually released (no owner). Then another thread, say, thread B, issued an IRP_MJ_CREATE. Dump before acquiring the resource shows it was still locked by thread A, rendering thread B deadlocked for the resource.
This happens in a special occasion: a request IRP_MJ_CLEANUP for the last file opened by thread A was received, but its corresponding IRP_MJ_CLOSE was never delivered although caching was not initiated at all. That makes me wondering who is still referencing the file object. I am not sure if the causes the above deadlock problem and if it does, why?
Also, this problem happens only on NT not on W2K.
Thanks.
Lijun
Dan Partelly wrote:
>> and found although I the lock on the resouce was released in another thread, but in another thread, the dump shows it was >> still locked by the earlier thread
Can you please clear this phrase a bit ? Im not sure I understand what scenario you have.
“Lijun Wang” wrote in message news:xxxxx@ntfsd…
I dumped out the ERESOURCE and found although I the lock on the resouce was released in another thread, but in another thread, the dump shows it was still locked by the earlier thread. This is very strange! I checked before lock a resource I called KeEnterCritialRegion and after release called KeExitCritialRegion.
Anyone know why this is happening?
Thanks!
Dan Partelly wrote:
Break into the debugger just before this, and the dump the ERESOUCE state, and see if indeed there is no current owner of the resource. You can use !locks command in windbg. Also, check if you corectly use KeEnterCritialRegion() before any aquisition & KeLeaveCriticalRegion() after you release. Failure to disable normal kernel APCs can cause reenteracy , thus compromise the integrity of locks hierarchy.
Dan
“Lijun Wang” wrote in message news:xxxxx@ntfsd…
Hi All,
I am using an ERESOURCE to synchronize all the output to a network connection in my redirector. I met a very strange problem with the resource. At some point I can’t acquire the resource using ExAcquireResourceExclusiveLite even I am pretty sure I release every previous lock to the resource.
This problem happens when a file was created then IRP_MJ_CLEANUP was received but the IRP_MJ_CLOSE was never delivered on that file object (caching on that file is never initiated).
Does anyone encountered this kind of problem before??
Lijun
------------------------------------------------------------------
Do You Yahoo!?
New! SBC Yahoo! Dial - 1st Month Free & unlimited access
—
You are currently subscribed to ntfsd as: xxxxx@yahoo.com
To unsubscribe send a blank email to %%email.unsub%%
----------------------------------------------------------------------
Do You Yahoo!?
New! SBC Yahoo! Dial - 1st Month Free & unlimited access
—
You are currently subscribed to ntfsd as: xxxxx@yahoo.com
To unsubscribe send a blank email to %%email.unsub%%
--------------------------------------------------------------------------
Do You Yahoo!?
New! SBC Yahoo! Dial - 1st Month Free & unlimited access
—
You are currently subscribed to ntfsd as: xxxxx@yahoo.com
To unsubscribe send a blank email to %%email.unsub%%
------------------------------------------------------------------------------
Do You Yahoo!?
New! SBC Yahoo! Dial - 1st Month Free & unlimited access — You are currently subscribed to ntfsd as: xxxxx@rdsor.ro To unsubscribe send a blank email to %%email.unsub%%