Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

286 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1989-2000 Microsoft Corporation
  3. Module Name:
  4. FspDisp.c
  5. Abstract:
  6. This module implements the main dispatch procedure/thread for the Cdfs
  7. Fsp
  8. // @@BEGIN_DDKSPLIT
  9. Author:
  10. Brian Andrew [BrianAn] 02-Jan-1991
  11. Revision History:
  12. // @@END_DDKSPLIT
  13. --*/
  14. #include "CdProcs.h"
  15. //
  16. // The Bug check file id for this module
  17. //
  18. #define BugCheckFileId (CDFS_BUG_CHECK_FSPDISP)
  19. VOID
  20. CdFspDispatch (
  21. IN PIRP_CONTEXT IrpContext
  22. )
  23. /*++
  24. Routine Description:
  25. This is the main FSP thread routine that is executed to receive
  26. and dispatch IRP requests. Each FSP thread begins its execution here.
  27. There is one thread created at system initialization time and subsequent
  28. threads created as needed.
  29. Arguments:
  30. IrpContext - IrpContext for a request to process.
  31. Return Value:
  32. None
  33. --*/
  34. {
  35. THREAD_CONTEXT ThreadContext;
  36. NTSTATUS Status;
  37. PIRP Irp = IrpContext->Irp;
  38. PIO_STACK_LOCATION IrpSp = IoGetCurrentIrpStackLocation( Irp );
  39. PVOLUME_DEVICE_OBJECT VolDo = NULL;
  40. //
  41. // If this request has an associated volume device object, remember it.
  42. //
  43. if (IrpSp->FileObject != NULL) {
  44. VolDo = CONTAINING_RECORD( IrpSp->DeviceObject,
  45. VOLUME_DEVICE_OBJECT,
  46. DeviceObject );
  47. }
  48. //
  49. // Now case on the function code. For each major function code,
  50. // either call the appropriate worker routine. This routine that
  51. // we call is responsible for completing the IRP, and not us.
  52. // That way the routine can complete the IRP and then continue
  53. // post processing as required. For example, a read can be
  54. // satisfied right away and then read can be done.
  55. //
  56. // We'll do all of the work within an exception handler that
  57. // will be invoked if ever some underlying operation gets into
  58. // trouble.
  59. //
  60. while ( TRUE ) {
  61. //
  62. // Set all the flags indicating we are in the Fsp.
  63. //
  64. SetFlag( IrpContext->Flags, IRP_CONTEXT_FSP_FLAGS );
  65. FsRtlEnterFileSystem();
  66. CdSetThreadContext( IrpContext, &ThreadContext );
  67. while (TRUE) {
  68. try {
  69. //
  70. // Reinitialize for the next try at completing this
  71. // request.
  72. //
  73. Status =
  74. IrpContext->ExceptionStatus = STATUS_SUCCESS;
  75. //
  76. // Initialize the Io status field in the Irp.
  77. //
  78. Irp->IoStatus.Status = STATUS_SUCCESS;
  79. Irp->IoStatus.Information = 0;
  80. //
  81. // Case on the major irp code.
  82. //
  83. switch (IrpContext->MajorFunction) {
  84. case IRP_MJ_CREATE :
  85. CdCommonCreate( IrpContext, Irp );
  86. break;
  87. case IRP_MJ_CLOSE :
  88. ASSERT( FALSE );
  89. break;
  90. case IRP_MJ_READ :
  91. CdCommonRead( IrpContext, Irp );
  92. break;
  93. case IRP_MJ_QUERY_INFORMATION :
  94. CdCommonQueryInfo( IrpContext, Irp );
  95. break;
  96. case IRP_MJ_SET_INFORMATION :
  97. CdCommonSetInfo( IrpContext, Irp );
  98. break;
  99. case IRP_MJ_QUERY_VOLUME_INFORMATION :
  100. CdCommonQueryVolInfo( IrpContext, Irp );
  101. break;
  102. case IRP_MJ_DIRECTORY_CONTROL :
  103. CdCommonDirControl( IrpContext, Irp );
  104. break;
  105. case IRP_MJ_FILE_SYSTEM_CONTROL :
  106. CdCommonFsControl( IrpContext, Irp );
  107. break;
  108. case IRP_MJ_DEVICE_CONTROL :
  109. CdCommonDevControl( IrpContext, Irp );
  110. break;
  111. case IRP_MJ_LOCK_CONTROL :
  112. CdCommonLockControl( IrpContext, Irp );
  113. break;
  114. case IRP_MJ_CLEANUP :
  115. CdCommonCleanup( IrpContext, Irp );
  116. break;
  117. case IRP_MJ_PNP :
  118. ASSERT( FALSE );
  119. CdCommonPnp( IrpContext, Irp );
  120. break;
  121. default :
  122. Status = STATUS_INVALID_DEVICE_REQUEST;
  123. CdCompleteRequest( IrpContext, Irp, Status );
  124. }
  125. } except( CdExceptionFilter( IrpContext, GetExceptionInformation() )) {
  126. Status = CdProcessException( IrpContext, Irp, GetExceptionCode() );
  127. }
  128. //
  129. // Break out of the loop if we didn't get CANT_WAIT.
  130. //
  131. if (Status != STATUS_CANT_WAIT) { break; }
  132. //
  133. // We are retrying this request. Cleanup the IrpContext for the retry.
  134. //
  135. SetFlag( IrpContext->Flags, IRP_CONTEXT_FLAG_MORE_PROCESSING );
  136. CdCleanupIrpContext( IrpContext, FALSE );
  137. }
  138. FsRtlExitFileSystem();
  139. //
  140. // If there are any entries on this volume's overflow queue, service
  141. // them.
  142. //
  143. if (VolDo != NULL) {
  144. KIRQL SavedIrql;
  145. PVOID Entry = NULL;
  146. //
  147. // We have a volume device object so see if there is any work
  148. // left to do in its overflow queue.
  149. //
  150. KeAcquireSpinLock( &VolDo->OverflowQueueSpinLock, &SavedIrql );
  151. if (VolDo->OverflowQueueCount > 0) {
  152. //
  153. // There is overflow work to do in this volume so we'll
  154. // decrement the Overflow count, dequeue the IRP, and release
  155. // the Event
  156. //
  157. VolDo->OverflowQueueCount -= 1;
  158. Entry = RemoveHeadList( &VolDo->OverflowQueue );
  159. }
  160. KeReleaseSpinLock( &VolDo->OverflowQueueSpinLock, SavedIrql );
  161. //
  162. // There wasn't an entry, break out of the loop and return to
  163. // the Ex Worker thread.
  164. //
  165. if (Entry == NULL) { break; }
  166. //
  167. // Extract the IrpContext , Irp, set wait to TRUE, and loop.
  168. //
  169. IrpContext = CONTAINING_RECORD( Entry,
  170. IRP_CONTEXT,
  171. WorkQueueItem.List );
  172. Irp = IrpContext->Irp;
  173. IrpSp = IoGetCurrentIrpStackLocation( Irp );
  174. continue;
  175. }
  176. break;
  177. }
  178. //
  179. // Decrement the PostedRequestCount if there was a volume device object.
  180. //
  181. if (VolDo) {
  182. InterlockedDecrement( &VolDo->PostedRequestCount );
  183. }
  184. return;
  185. }