Windows: Avoid deadlock during "fs memdump"

When the afs redirector is in use, it is possible that "fs memdump"
could be executed while all of the pages in the Windows page cache
are dirty with data that must be purged and flushed to \\afs. In
such a situation it is not safe for afsd_service.exe to hold
global locks such as buf_globalLock, cm_scacheLock, etc. while
performing WriteFile() calls against %TEMP%\afsd_alloc.log if
afsd_alloc.log was opened without the FILE_FLAG_NO_BUFFERING flag.
Doing so can result in a deadlock as it can become impossible for
the Windows page cache to purge data to complete the WriteFile()
as all extent operations block waiting for the global lock to
be cleared.

The correct long term approach would be to use the FILE_FLAG_NO_BUFFERING
flag when opening %TEMP%\afsd_alloc.log.  However, this requires that
all writes to the file be performed using buffers that are consistent
with the drive geometry.  Such an approach would be incompatible with
the _CrtMemDumpAllObjectsSince() operation and would require a redesign
of the current interfaces.  See

http://msdn.microsoft.com/en-us/library/windows/desktop/cc644950(v=vs.85).aspx

for requirements when using non-buffered writes.

The short term fix is to dump the contents without holding the
global locks.  This can result in an inconsistent view of the world
but will ensure that deadlocks are avoided.  This patchset makes
such a change when the afs redirector is in use.

Change-Id: I6ffc0ff7c80707f16bf132f2dcab7dab5727894d
Reviewed-on: http://gerrit.openafs.org/7391
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Jeffrey Altman <jaltman@secure-endpoints.com>
Tested-by: Jeffrey Altman <jaltman@secure-endpoints.com>
This commit is contained in:
Jeffrey Altman 2012-05-10 08:36:33 -04:00 committed by Jeffrey Altman
parent 90ecc0ff72
commit c6782b86d7

View File

@ -3299,11 +3299,11 @@ cm_IoctlMemoryDump(struct cm_ioctl *ioctlp, struct cm_user *userp)
/* dump all interesting data */
cm_MemDumpDirStats(hLogFile, cookie, 1);
cm_MemDumpBPlusStats(hLogFile, cookie, 1);
cm_DumpCells(hLogFile, cookie, 1);
cm_DumpVolumes(hLogFile, cookie, 1);
cm_DumpSCache(hLogFile, cookie, 1);
cm_DumpBufHashTable(hLogFile, cookie, 1);
cm_DumpServers(hLogFile, cookie, 1);
cm_DumpCells(hLogFile, cookie, !RDR_Initialized);
cm_DumpVolumes(hLogFile, cookie, !RDR_Initialized);
cm_DumpSCache(hLogFile, cookie, !RDR_Initialized);
cm_DumpBufHashTable(hLogFile, cookie, !RDR_Initialized);
cm_DumpServers(hLogFile, cookie, !RDR_Initialized);
smb_DumpVCP(hLogFile, cookie, 1);
rx_DumpCalls(hLogFile, cookie);
rx_DumpPackets(hLogFile, cookie);