ntStatus = AFSCommonWrite( AFSRDRDeviceObject, Irp, NULL);
}
- __except( AFSExceptionFilter( GetExceptionCode(), GetExceptionInformation()) )
+ __except( AFSExceptionFilter( __FUNCTION__, GetExceptionCode(), GetExceptionInformation()) )
{
ntStatus = STATUS_INSUFFICIENT_RESOURCES;
BOOLEAN bPagingIo = FALSE;
BOOLEAN bNonCachedIo = FALSE;
BOOLEAN bReleaseMain = FALSE;
+ BOOLEAN bReleaseSectionObject = FALSE;
BOOLEAN bReleasePaging = FALSE;
BOOLEAN bExtendingWrite = FALSE;
BOOLEAN bCompleteIrp = TRUE;
- BOOLEAN bForceFlush = FALSE;
BOOLEAN bLockOK;
- BOOLEAN bMapped = TRUE;
HANDLE hCallingUser = OnBehalfOf;
ULONG ulExtensionLength = 0;
BOOLEAN bRetry = FALSE;
+ ULONGLONG ullProcessId = (ULONGLONG)PsGetCurrentProcessId();
pIrpSp = IoGetCurrentIrpStackLocation( Irp);
if( NULL != pFileObject->SectionObjectPointer->DataSectionObject && !bPagingIo && bNonCachedIo)
{
bNonCachedIo = FALSE;
- bForceFlush = TRUE;
}
- if( (!bPagingIo && !bNonCachedIo))
- {
+ if ( !bNonCachedIo) {
- if( pFileObject->PrivateCacheMap == NULL)
+ if( !bPagingIo)
{
- __try
+ if( pFileObject->PrivateCacheMap == NULL)
{
- AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+ AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonWrite Initialize caching on Fcb %08lX FileObject %08lX\n",
- pFcb,
- pFileObject);
+ "AFSCommonWrite Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+ &pNPFcb->SectionObjectResource,
+ PsGetCurrentThread());
- CcInitializeCacheMap( pFileObject,
- (PCC_FILE_SIZES)&pFcb->Header.AllocationSize,
- FALSE,
- AFSLibCacheManagerCallbacks,
- pFcb);
+ AFSAcquireExcl( &pNPFcb->SectionObjectResource,
+ TRUE);
- CcSetReadAheadGranularity( pFileObject,
- READ_AHEAD_GRANULARITY);
+ bReleaseSectionObject = TRUE;
- }
- __except( EXCEPTION_EXECUTE_HANDLER)
- {
+ __try
+ {
- ntStatus = GetExceptionCode();
+ AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonWrite Initialize caching on Fcb %08lX FileObject %08lX\n",
+ pFcb,
+ pFileObject);
- AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
- AFS_TRACE_LEVEL_ERROR,
- "AFSCommonWrite (%08lX) Exception thrown while initializing cache map Status %08lX\n",
- Irp,
- ntStatus);
- }
+ CcInitializeCacheMap( pFileObject,
+ (PCC_FILE_SIZES)&pFcb->Header.AllocationSize,
+ FALSE,
+ AFSLibCacheManagerCallbacks,
+ pFcb);
- if( !NT_SUCCESS( ntStatus))
- {
+ CcSetReadAheadGranularity( pFileObject,
+ pDeviceExt->Specific.RDR.MaximumRPCLength);
- try_return( ntStatus);
+ CcSetDirtyPageThreshold( pFileObject,
+ AFS_DIRTY_CHUNK_THRESHOLD * pDeviceExt->Specific.RDR.MaximumRPCLength);
+ }
+ __except( EXCEPTION_EXECUTE_HANDLER)
+ {
+
+ ntStatus = GetExceptionCode();
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+ AFS_TRACE_LEVEL_ERROR,
+ "AFSCommonWrite (%08lX) Exception thrown while initializing cache map Status %08lX\n",
+ Irp,
+ ntStatus);
+ }
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonWrite Releasing Fcb SectionObject lock %08lX EXCL %08lX\n",
+ &pNPFcb->SectionObjectResource,
+ PsGetCurrentThread());
+
+ AFSReleaseResource( &pNPFcb->SectionObjectResource);
+
+ bReleaseSectionObject = FALSE;
+
+
+ if( !NT_SUCCESS( ntStatus))
+ {
+
+ try_return( ntStatus);
+ }
}
}
- }
- while (!bNonCachedIo && !CcCanIWrite( pFileObject,
- ulByteCount,
- FALSE,
- bRetry))
- {
- static const LONGLONG llWriteDelay = (LONGLONG)-100000;
- bRetry = TRUE;
- KeDelayExecutionThread(KernelMode, FALSE, (PLARGE_INTEGER)&llWriteDelay);
+ while (!CcCanIWrite( pFileObject,
+ ulByteCount,
+ FALSE,
+ bRetry))
+ {
+ static const LONGLONG llWriteDelay = (LONGLONG)-100000;
+ bRetry = TRUE;
+ KeDelayExecutionThread(KernelMode, FALSE, (PLARGE_INTEGER)&llWriteDelay);
+ }
}
//
if( !bPagingIo &&
( pFcb->Specific.File.ExtentRequestProcessId == 0 ||
- ( PsGetCurrentProcessId() != AFSSysProcess &&
- pFcb->Specific.File.ExtentRequestProcessId != (ULONGLONG)PsGetCurrentProcessId())))
+ ( ullProcessId != (ULONGLONG)AFSSysProcess &&
+ pFcb->Specific.File.ExtentRequestProcessId != ullProcessId)))
{
- pFcb->Specific.File.ExtentRequestProcessId = (ULONGLONG)PsGetCurrentProcessId();
+ pFcb->Specific.File.ExtentRequestProcessId = ullProcessId;
- if( pFcb->Specific.File.ExtentRequestProcessId == (ULONGLONG)AFSSysProcess)
+ if( ullProcessId == (ULONGLONG)AFSSysProcess)
{
AFSDbgLogMsg( AFS_SUBSYSTEM_EXTENT_PROCESSING,
AFS_TRACE_LEVEL_WARNING,
__FUNCTION__,
pFcb);
}
-
- pFcb->NPFcb->Specific.File.ExtentsRequestStatus = STATUS_SUCCESS;
- }
-
- //
- // We should be ready to go. So first of all ask for the extents
- // Provoke a get of the extents - if we need to.
- //
-
- /*
- if( !bPagingIo && !bNonCachedIo)
- {
-
- ntStatus = AFSRequestExtentsAsync( pFcb, pCcb, &liStartingByte, ulByteCount);
-
- if (!NT_SUCCESS(ntStatus))
- {
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
- AFS_TRACE_LEVEL_ERROR,
- "AFSCommonWrite (%08lX) Failed to request extents Status %08lX\n",
- Irp,
- ntStatus);
-
- try_return( ntStatus );
- }
- }
- */
-
- //
- // If they are not mapped and we are the Lazy Writer then just
- // say "not now"
- //
- if (!bMapped && pFcb->Specific.File.LazyWriterThread == PsGetCurrentThread())
- {
-
- AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonWrite (%08lX) Failing lazy writer for unmapped request\n",
- Irp);
-
- try_return ( ntStatus = STATUS_FILE_LOCK_CONFLICT);
}
//
// Take locks
//
- // - if Paging then we need to nothing (the precalls will
+ // - if Paging then we need to do nothing (the precalls will
// have acquired the paging resource), for clarity we will collect
// the paging resource
// - If extending Write then take the fileresource EX (EOF will change, Allocation will only move out)
do
{
- if( !bPagingIo)
- {
-
- bExtendingWrite = (((liStartingByte.QuadPart + ulByteCount) >=
- pFcb->Header.FileSize.QuadPart) ||
- (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
- liStartingByte.HighPart == -1)) ;
- }
-
if( bPagingIo)
{
//
bLockOK = TRUE;
}
- else if( bExtendingWrite)
+ else
{
- //
- // Check for lock inversion
- //
- ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
+ bExtendingWrite = (((liStartingByte.QuadPart + ulByteCount) >=
+ pFcb->Header.FileSize.QuadPart) ||
+ (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
+ liStartingByte.HighPart == -1)) ;
+
+ if( bExtendingWrite)
+ {
+ //
+ // Check for lock inversion
+ //
- AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonWrite Acquiring Fcb lock %08lX EXCL %08lX\n",
- &pNPFcb->Resource,
- PsGetCurrentThread());
+ ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
- AFSAcquireExcl( &pNPFcb->Resource,
- TRUE);
+ AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonWrite Acquiring Fcb lock %08lX EXCL %08lX\n",
+ &pNPFcb->Resource,
+ PsGetCurrentThread());
- if (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
- liStartingByte.HighPart == -1)
- {
- if (pFcb->Header.ValidDataLength.QuadPart > pFcb->Header.FileSize.QuadPart)
- {
- liStartingByte = pFcb->Header.ValidDataLength;
- }
- else
+ AFSAcquireExcl( &pNPFcb->Resource,
+ TRUE);
+
+ bReleaseMain = TRUE;
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonWrite Acquiring Fcb SectionObject lock %08lX EXCL %08lX\n",
+ &pNPFcb->SectionObjectResource,
+ PsGetCurrentThread());
+
+ AFSAcquireExcl( &pNPFcb->SectionObjectResource,
+ TRUE);
+
+ bReleaseSectionObject = TRUE;
+
+ if (liStartingByte.LowPart == FILE_WRITE_TO_END_OF_FILE &&
+ liStartingByte.HighPart == -1)
{
- liStartingByte = pFcb->Header.FileSize;
+ if (pFcb->Header.ValidDataLength.QuadPart > pFcb->Header.FileSize.QuadPart)
+ {
+ liStartingByte = pFcb->Header.ValidDataLength;
+ }
+ else
+ {
+ liStartingByte = pFcb->Header.FileSize;
+ }
}
+
+ //
+ // We have the correct lock - even if we don't end up truncating
+ //
+ bLockOK = TRUE;
}
- bReleaseMain = TRUE;
+ else
+ {
+ ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
- //
- // We have the correct lock - even if we don't end up truncating
- //
- bLockOK = TRUE;
- }
- else
- {
- ASSERT( !ExIsResourceAcquiredLite( &pNPFcb->PagingResource ));
+ AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonWrite Acquiring Fcb lock %08lX SHARED %08lX\n",
+ &pNPFcb->Resource,
+ PsGetCurrentThread());
- AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSCommonWrite Acquiring Fcb lock %08lX SHARED %08lX\n",
- &pNPFcb->Resource,
- PsGetCurrentThread());
+ AFSAcquireShared( &pNPFcb->Resource,
+ TRUE);
- AFSAcquireShared( &pNPFcb->Resource,
- TRUE);
+ bReleaseMain = TRUE;
- bReleaseMain = TRUE;
+ AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
+ AFS_TRACE_LEVEL_VERBOSE,
+ "AFSCommonWrite Acquiring Fcb SectionObject lock %08lX SHARED %08lX\n",
+ &pNPFcb->SectionObjectResource,
+ PsGetCurrentThread());
- //
- // Have things moved? Are we extending? If so, the the lock isn't OK
- //
- bLockOK = (liStartingByte.QuadPart + ulByteCount) < pFcb->Header.FileSize.QuadPart;
+ AFSAcquireShared( &pNPFcb->SectionObjectResource,
+ TRUE);
- if (!bLockOK)
- {
- AFSReleaseResource( &pNPFcb->Resource);
- bReleaseMain = FALSE;
+ bReleaseSectionObject = TRUE;
+
+ //
+ // Have things moved? Are we extending? If so, the the lock isn't OK
+ //
+ bLockOK = (liStartingByte.QuadPart + ulByteCount) < pFcb->Header.FileSize.QuadPart;
+
+ if (!bLockOK)
+ {
+ AFSReleaseResource( &pNPFcb->Resource);
+
+ bReleaseMain = FALSE;
+ }
}
}
}
while (!bLockOK);
- //
- // Check the BR locks on the file.
- //
-
- if( !bPagingIo &&
- !FsRtlCheckLockForWriteAccess( &pFcb->Specific.File.FileLock,
- Irp))
+ if( !bPagingIo)
{
- AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
- AFS_TRACE_LEVEL_ERROR,
- "AFSCommonWrite (%08lX) Request failed due to lock conflict\n",
- Irp);
+ //
+ // Check the BR locks on the file.
+ //
- try_return( ntStatus = STATUS_FILE_LOCK_CONFLICT);
- }
+ if ( !FsRtlCheckLockForWriteAccess( &pFcb->Specific.File.FileLock,
+ Irp))
+ {
- if( bExtendingWrite)
- {
+ AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+ AFS_TRACE_LEVEL_ERROR,
+ "AFSCommonWrite (%08lX) Request failed due to lock conflict\n",
+ Irp);
- ntStatus = AFSExtendingWrite( pFcb, pFileObject, (liStartingByte.QuadPart + ulByteCount));
+ try_return( ntStatus = STATUS_FILE_LOCK_CONFLICT);
+ }
- if( !NT_SUCCESS(ntStatus))
+ if( bExtendingWrite)
{
- AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
- AFS_TRACE_LEVEL_ERROR,
- "AFSCommonWrite (%08lX) Failed extending write request Status %08lX\n",
- Irp,
- ntStatus);
+ ntStatus = AFSExtendingWrite( pFcb, pFileObject, (liStartingByte.QuadPart + ulByteCount));
+
+ if( !NT_SUCCESS(ntStatus))
+ {
+
+ AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
+ AFS_TRACE_LEVEL_ERROR,
+ "AFSCommonWrite (%08lX) Failed extending write request Status %08lX\n",
+ Irp,
+ ntStatus);
- try_return( ntStatus );
+ try_return( ntStatus );
+ }
}
}
!bNonCachedIo)
{
+ //
+ // Main and SectionObject resources held Shared
+ //
+
AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
"AFSCommonWrite (%08lX) Processing CACHED request Offset %I64X Len %08lX\n",
liStartingByte.QuadPart,
ulByteCount);
- ntStatus = AFSCachedWrite( DeviceObject, Irp, liStartingByte, ulByteCount, bForceFlush);
+ ntStatus = AFSCachedWrite( DeviceObject, Irp, liStartingByte, ulByteCount, TRUE);
}
else
{
+ //
+ // if bPagingIo, Paging Resource held Shared
+ // else Main and SectionObject resources held Shared
+ //
+
+ if( bReleaseSectionObject)
+ {
+
+ AFSReleaseResource( &pNPFcb->SectionObjectResource);
+
+ bReleaseSectionObject = FALSE;
+ }
+
+ if( bReleasePaging)
+ {
+
+ AFSReleaseResource( &pNPFcb->PagingResource);
+
+ bReleasePaging = FALSE;
+ }
+
+ if( bReleaseMain)
+ {
+
+ AFSReleaseResource( &pNPFcb->Resource);
+
+ bReleaseMain = FALSE;
+ }
+
AFSDbgLogMsg( AFS_SUBSYSTEM_IO_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
"AFSCommonWrite (%08lX) Processing NON-CACHED request Offset %I64X Len %08lX\n",
ObDereferenceObject(pFileObject);
- if( bReleaseMain)
+ if( bReleaseSectionObject)
{
- AFSReleaseResource( &pNPFcb->Resource);
+ AFSReleaseResource( &pNPFcb->SectionObjectResource);
}
if( bReleasePaging)
AFSReleaseResource( &pNPFcb->PagingResource);
}
+ if( bReleaseMain)
+ {
+
+ AFSReleaseResource( &pNPFcb->Resource);
+ }
+
if( bCompleteIrp)
{
LARGE_INTEGER liCurrentTime, liLastRequestTime;
AFSDeviceExt *pControlDevExt = (AFSDeviceExt *)AFSControlDeviceObject->DeviceExtension;
PFILE_OBJECT pCacheFileObject = NULL;
+ BOOLEAN bDerefExtents = FALSE;
__Enter
{
bLocked= FALSE;
//
- // We will re-request the extents after 10 seconds of waiting for them
+ // We will re-request the extents after waiting for them
//
KeQueryTickCount( &liCurrentTime);
// Wait for it
//
- ntStatus = AFSWaitForExtentMapping ( pFcb );
+ ntStatus = AFSWaitForExtentMapping ( pFcb, pCcb);
if (!NT_SUCCESS(ntStatus))
{
AFSReferenceActiveExtents( pStartExtent,
extentsCount);
+ bDerefExtents = TRUE;
+
AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
AFS_TRACE_LEVEL_VERBOSE,
"AFSNonCachedWrite Releasing(2) Fcb extents lock %08lX SHARED %08lX\n",
try_return( ntStatus);
}
- //
- // Since this is dirty we can mark the extents dirty now.
- // AFSMarkDirty will dereference the extents. Do not call
- // AFSDereferenceActiveExtents() in this code path.
- //
-
- AFSMarkDirty( pFcb,
- pStartExtent,
- extentsCount,
- &StartingByte);
+try_exit:
- if (!bPagingIo)
+ if( NT_SUCCESS( ntStatus) &&
+ pStartExtent != NULL &&
+ Irp->IoStatus.Information > 0)
{
+
+ if ( !bLocked)
+ {
+
+ AFSAcquireShared( &pFcb->NPFcb->Specific.File.ExtentsResource,
+ TRUE);
+ bLocked = TRUE;
+ }
+
//
- // This was an uncached user write - tell the server to do
- // the flush when the worker thread next wakes up
+ // Since this is dirty we can mark the extents dirty now.
+ // AFSMarkDirty will dereference the extents. Do not call
+ // AFSDereferenceActiveExtents() in this code path.
//
- pFcb->Specific.File.LastServerFlush.QuadPart = 0;
- }
- //
- // All done
- //
+ AFSMarkDirty( pFcb,
+ pStartExtent,
+ extentsCount,
+ &StartingByte,
+ bDerefExtents);
-try_exit:
+ if (!bPagingIo)
+ {
+ //
+ // This was an uncached user write - tell the server to do
+ // the flush when the worker thread next wakes up
+ //
+ pFcb->Specific.File.LastServerFlush.QuadPart = 0;
+ }
+ }
if( pCacheFileObject != NULL)
{
if( pGatherIo)
{
- AFSExFreePool(pGatherIo);
+ AFSExFreePoolWithTag(pGatherIo, AFS_GATHER_TAG);
}
if( NULL != pIoRuns &&
stIoRuns != pIoRuns)
{
- AFSExFreePool(pIoRuns);
+ AFSExFreePoolWithTag(pIoRuns, AFS_IO_RUN_TAG);
}
if( bCompleteIrp)
Fcb->ObjectInformation,
&pCcb->AuthGroup);
- AFSDbgLogMsg( AFS_SUBSYSTEM_LOCK_PROCESSING,
- AFS_TRACE_LEVEL_VERBOSE,
- "AFSExtendingWrite Acquiring Fcb lock %08lX EXCL %08lX\n",
- &Fcb->NPFcb->Resource,
- PsGetCurrentThread());
-
if (NT_SUCCESS(ntStatus))
{
if( pIoRequest != NULL)
{
- AFSExFreePool( pIoRequest);
+ AFSExFreePoolWithTag( pIoRequest, AFS_GENERIC_MEMORY_14_TAG);
}
}