Source code of Windows XP (NT5)
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.

300 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. Flush.c
  5. Abstract:
  6. This module implements the File Flush buffers routine for Rx called by the
  7. dispatch driver.
  8. In a future version of the wrapper, it may be that flush will be routed thru lowio.
  9. Author:
  10. Joe Linn [JoeLinn] 15-dec-1994
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. //
  16. // The local debug trace level
  17. //
  18. #define Dbg (DEBUG_TRACE_FLUSH)
  19. //RXSTATUS
  20. //RxLowIoFlushShell (
  21. // IN PRX_CONTEXT RxContext
  22. // );
  23. //
  24. //RXSTATUS
  25. //RxLowIoFlushShellCompletion (
  26. // IN PRX_CONTEXT RxContext
  27. // );
  28. #ifdef ALLOC_PRAGMA
  29. #pragma alloc_text(PAGE, RxCommonFlushBuffers)
  30. #pragma alloc_text(PAGE, RxFlushFile)
  31. #endif
  32. NTSTATUS
  33. RxCommonFlushBuffers ( RXCOMMON_SIGNATURE )
  34. /*++
  35. Routine Description:
  36. This is the common routine for flushing file buffers.
  37. Arguments:
  38. Irp - Supplies the Irp to process
  39. Return Value:
  40. RXSTATUS - The return status for the operation
  41. --*/
  42. {
  43. NTSTATUS Status;
  44. RxCaptureRequestPacket;
  45. RxCaptureFcb; RxCaptureFobx; RxCaptureParamBlock; RxCaptureFileObject;
  46. NODE_TYPE_CODE TypeOfOpen = NodeType(capFcb);
  47. PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
  48. BOOLEAN FcbAcquired = FALSE;
  49. PAGED_CODE();
  50. RxDbgTrace(+1, Dbg, ("RxCommonFlush...IrpC %08lx, Fobx %08lx, Fcb %08lx\n",
  51. RxContext, capFobx, capFcb));
  52. RxLog(("%s %lx %lx %lx\n","slF",RxContext,capFcb,capFobx));
  53. //
  54. // CcFlushCache is always synchronous, so if we can't wait enqueue
  55. // the irp to the Fsp.
  56. if ( !FlagOn(RxContext->Flags, RX_CONTEXT_FLAG_WAIT) ) {
  57. Status = RxFsdPostRequest( RxContext );
  58. RxDbgTrace(-1, Dbg, ("RxCommonFlushBuffers -> %08lx\n", Status ));
  59. return Status;
  60. }
  61. Status = STATUS_SUCCESS;
  62. try {
  63. //
  64. // Case on the type of open that we are trying to flush
  65. //
  66. switch (TypeOfOpen) {
  67. case RDBSS_NTC_STORAGE_TYPE_FILE:
  68. RxDbgTrace(0, Dbg, ("Flush User File Open\n", 0));
  69. Status = RxAcquireExclusiveFcb( RxContext, capFcb );
  70. if (Status != STATUS_SUCCESS) break;
  71. FcbAcquired = TRUE;
  72. //
  73. // If the file is cached then flush its cache
  74. //
  75. Status = RxFlushFile( RxContext, capFcb );
  76. if (!NT_SUCCESS( Status )) break;
  77. //rdrs don't do this.....only local FSs
  78. ////
  79. //// Check if we should be changing the time or file size
  80. //
  81. //RxAdjustFileTimesAndSize(RXCOMMON_ARGUMENTS);
  82. // if we make this lowio.........
  83. ////
  84. //// Initialize LowIO_CONTEXT block in the RxContext and Calldown
  85. //
  86. //RxInitializeLowIoContext(LowIoContext,LOWIO_OP_FLUSH);
  87. //
  88. //Status = RxLowIoFlushShell(RxContext);
  89. MINIRDR_CALL(Status,RxContext,capFcb->MRxDispatch,MRxFlush,(RxContext));
  90. break;
  91. case RDBSS_NTC_SPOOLFILE:
  92. RxDbgTrace(0, Dbg, ("Flush Sppol File\n", 0));
  93. Status = RxAcquireExclusiveFcb( RxContext, capFcb );
  94. if (Status != STATUS_SUCCESS) break;
  95. FcbAcquired = TRUE;
  96. // should this be low io???
  97. ////
  98. //// Initialize LowIO_CONTEXT block in the RxContext and Calldown
  99. //
  100. //RxInitializeLowIoContext(LowIoContext,LOWIO_OP_FLUSH);
  101. //
  102. //Status = RxLowIoFlushShell(RxContext);
  103. MINIRDR_CALL(Status,RxContext,capFcb->MRxDispatch,MRxFlush,(RxContext));
  104. break;
  105. default:
  106. Status = STATUS_INVALID_DEVICE_REQUEST;
  107. }
  108. } finally {
  109. DebugUnwind( RxCommonFlushBuffers );
  110. if (FcbAcquired) { RxReleaseFcb( RxContext, capFcb ); }
  111. //
  112. // If this is a normal termination then pass the request on
  113. // to the target device object.
  114. //
  115. if (!AbnormalTermination()) {
  116. NOTHING;
  117. }
  118. }
  119. RxDbgTrace(-1, Dbg, ("RxCommonFlushBuffers -> %08lx\n", Status));
  120. return Status;
  121. }
  122. #if 0
  123. BUGBUG
  124. THIS CODE WOULD BE USED IF THIS IS CHANGED TO LOWIO
  125. NTSTATUS
  126. RxLowIoFlushShellCompletion (
  127. IN PRX_CONTEXT RxContext
  128. )
  129. /*++
  130. Routine Description:
  131. these completion shells are pretty similar. BUT as the error handling gets more
  132. robust the routines will become increasingly dissimilar. for flush, everything is synchronous...that's
  133. a difference with read/write/lock; we keep the same declarations and format for later when we decide to roll up the
  134. common part of these routines.
  135. This routine postprocesses a flush request after it comes back from the
  136. minirdr. It is the complement of LowIoFlushShell.
  137. Arguments:
  138. RxContext - the usual
  139. Return Value:
  140. whatever value supplied by the caller or STATUS_MORE_PROCESSING_REQUIRED.
  141. --*/
  142. {
  143. NTSTATUS Status;
  144. RxCaptureRequestPacket;
  145. RxCaptureFcb; RxCaptureFobx; RxCaptureParamBlock;
  146. PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
  147. BOOLEAN SynchronousIo = !BooleanFlagOn(RxContext->Flags,RX_CONTEXT_FLAG_ASYNC_OPERATION);
  148. BOOLEAN PagingIo = BooleanFlagOn(capReqPacket->Flags, IRP_PAGING_IO);
  149. ERESOURCE_THREAD ThisResourceThreadId;
  150. Status = RxContext->StoredStatus;
  151. RxDbgTrace(+1, Dbg, ("RxLowIoFlushShellCompletion entry Status = %08lx\n", Status));
  152. RxLog(("FlshShlComp %x\n",RxContext));
  153. //switch (Status) {
  154. //case STATUS_SUCCESS:
  155. // break;
  156. //case STATUS_CONNECTION_INVALID:
  157. // //joejoe here is where the failover will happen
  158. // //first we give the local guy current minirdr another chance...then we go
  159. // //to fullscale retry
  160. // //return(RxStatus(DISCONNECTED)); //special....let LowIo get us back
  161. // break;
  162. //}
  163. capReqPacket->IoStatus.Status = Status;
  164. RxDbgTrace(-1, Dbg, ("RxLowIoFlushShellCompletion exit Status = %08lx\n", Status));
  165. return(Status);
  166. //NOTE THAT THE ASYNC COMPLETION TAIL IS MISSING
  167. }
  168. #define RxSdwFlush(RXCONTEXT) {NOTHING;}
  169. }
  170. NTSTATUS
  171. RxLowIoFlushShell (
  172. IN PRX_CONTEXT RxContext
  173. )
  174. /*++
  175. Routine Description:
  176. This routine preprocesses a Flush request before it goes down to the minirdr. It does callouts
  177. to handle compression, buffering and shadowing. It is the opposite number of LowIoFlushShellCompletion.
  178. By the time we get here, we are going to the wire.
  179. Flush buffering was already tried in the UncachedFlush strategy
  180. Arguments:
  181. RxContext - the usual
  182. Return Value:
  183. whatever value is returned by a callout....or by LowIo.
  184. --*/
  185. {
  186. NTSTATUS Status;
  187. RxCaptureFcb; RxCaptureFobx; RxCaptureParamBlock;
  188. PLOWIO_CONTEXT LowIoContext = &RxContext->LowIoContext;
  189. RxDbgTrace(+1, Dbg, ("RxLowIoFlushShell entry %08lx\n", 0));
  190. RxLog(("FlshShl in%x\n",RxContext));
  191. if (FlagOn(Fcb->FcbState, FCB_STATE_FILE_IS_SHADOWED)) {
  192. RxSdwFlush(RxContext);
  193. }
  194. Status = RxLowIoSubmit(RxContext,RxLowIoFlushShellCompletion);
  195. RxDbgTrace(-1, Dbg, ("RxLowIoFlushShell exit Status = %08lx\n", Status));
  196. return(Status);
  197. }
  198. #endif
  199.