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.

274 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. RstrtSup.c
  5. Abstract:
  6. This module implements support for dealing with the Lfs restart area.
  7. Author:
  8. Brian Andrew [BrianAn] 20-June-1991
  9. Revision History:
  10. --*/
  11. #include "lfsprocs.h"
  12. //
  13. // The debug trace level
  14. //
  15. #define Dbg (DEBUG_TRACE_RESTART_SUP)
  16. #ifdef ALLOC_PRAGMA
  17. #pragma alloc_text(PAGE, LfsFindOldestClientLsn)
  18. #pragma alloc_text(PAGE, LfsWriteLfsRestart)
  19. #endif
  20. VOID
  21. LfsWriteLfsRestart (
  22. IN PLFCB Lfcb,
  23. IN ULONG ThisRestartSize,
  24. IN BOOLEAN WaitForIo
  25. )
  26. /*++
  27. Routine Description:
  28. This routine puts the Lfs restart area on the queue of operations to
  29. write to the file. We do this by allocating a second restart area
  30. and attaching it to the Lfcb. We also allocate a buffer control
  31. block to use for this write. We look at the WaitForIo boolean to
  32. determine whether this thread can perform the I/O. This also indicates
  33. whether this thread gives up the Lfcb.
  34. Arguments:
  35. Lfcb - A pointer to the log file control block for this operation.
  36. ThisRestartSize - This is the size to use for the restart area.
  37. WaitForIo - Indicates if this thread is to perform the work.
  38. Return Value:
  39. None.
  40. --*/
  41. {
  42. PLBCB NewLbcb = NULL;
  43. PLFS_RESTART_AREA NewRestart = NULL;
  44. PAGED_CODE();
  45. DebugTrace( +1, Dbg, "LfsWriteLfsRestart: Entered\n", 0 );
  46. DebugTrace( 0, Dbg, "Lfcb -> %08lx\n", Lfcb );
  47. DebugTrace( 0, Dbg, "Write Chkdsk -> %04x\n", WriteChkdsk );
  48. DebugTrace( 0, Dbg, "Restart Size -> %08lx\n", ThisRestartSize );
  49. DebugTrace( 0, Dbg, "WaitForIo -> %08lx\n", WaitForIo );
  50. //
  51. // We'd absolutely hate for this to happen on a read only volume.
  52. //
  53. ASSERT(!(FlagOn( Lfcb->Flags, LFCB_READ_ONLY )));
  54. //
  55. // Use a try-finally to facilitate cleanup.
  56. //
  57. try {
  58. PLBCB ActiveLbcb;
  59. //
  60. // We allocate another restart area and
  61. // copy the current area into it. Attach the new area to the Lfcb.
  62. //
  63. LfsAllocateRestartArea( &NewRestart, ThisRestartSize );
  64. //
  65. // We allocate a Lbcb structure and update the values to
  66. // reflect this restart area.
  67. //
  68. LfsAllocateLbcb( Lfcb, &NewLbcb );
  69. SetFlag( NewLbcb->LbcbFlags, LBCB_RESTART_LBCB );
  70. //
  71. // If this is the second page, then add a page to the offset.
  72. //
  73. if (!Lfcb->InitialRestartArea) {
  74. NewLbcb->FileOffset = Lfcb->LogPageSize + NewLbcb->FileOffset;
  75. }
  76. (ULONG)NewLbcb->Length = ThisRestartSize;
  77. NewLbcb->PageHeader = (PVOID) Lfcb->RestartArea;
  78. //
  79. // Lets put the current lsn in the Lbcb.
  80. //
  81. NewLbcb->LastEndLsn = NewLbcb->LastLsn = Lfcb->NextRestartLsn;
  82. Lfcb->NextRestartLsn.QuadPart = 1 + Lfcb->NextRestartLsn.QuadPart;
  83. //
  84. // Copy the existing restart area into the new area.
  85. //
  86. RtlCopyMemory( NewRestart, Lfcb->RestartArea, ThisRestartSize );
  87. Lfcb->RestartArea = NewRestart;
  88. Lfcb->ClientArray = Add2Ptr( NewRestart, Lfcb->ClientArrayOffset, PLFS_CLIENT_RECORD );
  89. NewRestart = NULL;
  90. //
  91. // Update the Lfcb to indicate that the other restart area
  92. // on the disk is to be used.
  93. //
  94. Lfcb->InitialRestartArea = !Lfcb->InitialRestartArea;
  95. //
  96. // Add this Lbcb to the end of the workque and flush to that point.
  97. //
  98. InsertTailList( &Lfcb->LbcbWorkque, &NewLbcb->WorkqueLinks );
  99. //
  100. // If we don't support a packed log file then we need to make
  101. // sure that all file records written out ahead of this
  102. // restart area make it out to disk and we don't add anything
  103. // to this page.
  104. //
  105. if (!FlagOn( Lfcb->Flags, LFCB_PACK_LOG )
  106. && !IsListEmpty( &Lfcb->LbcbActive )) {
  107. ActiveLbcb = CONTAINING_RECORD( Lfcb->LbcbActive.Flink,
  108. LBCB,
  109. ActiveLinks );
  110. if (FlagOn( ActiveLbcb->LbcbFlags, LBCB_NOT_EMPTY )) {
  111. RemoveEntryList( &ActiveLbcb->ActiveLinks );
  112. ClearFlag( ActiveLbcb->LbcbFlags, LBCB_ON_ACTIVE_QUEUE );
  113. }
  114. }
  115. if (WaitForIo) {
  116. LfsFlushLbcb( Lfcb, NewLbcb );
  117. }
  118. } finally {
  119. DebugUnwind( LfsWriteLfsRestart );
  120. if (NewRestart != NULL) {
  121. ExFreePool( NewRestart );
  122. }
  123. DebugTrace( -1, Dbg, "LfsWriteLfsRestart: Exit\n", 0 );
  124. }
  125. return;
  126. }
  127. VOID
  128. LfsFindOldestClientLsn (
  129. IN PLFS_RESTART_AREA RestartArea,
  130. IN PLFS_CLIENT_RECORD ClientArray,
  131. OUT PLSN OldestLsn
  132. )
  133. /*++
  134. Routine Description:
  135. This routine walks through the active clients to determine the oldest
  136. Lsn the system must maintain.
  137. Arguments:
  138. RestartArea - This is the Restart Area to examine.
  139. ClientArray - This is the start of the client data array.
  140. OldestLsn - We store the oldest Lsn we find in this value. It is
  141. initialized with a starting value, we won't return a more recent
  142. Lsn.
  143. Return Value:
  144. None.
  145. --*/
  146. {
  147. USHORT NextClient;
  148. PLFS_CLIENT_RECORD ClientBlock;
  149. PAGED_CODE();
  150. DebugTrace( +1, Dbg, "LfsFindOldestClientLsn: Entered\n", 0 );
  151. DebugTrace( 0, Dbg, "RestartArea -> %08lx\n", RestartArea );
  152. DebugTrace( 0, Dbg, "Base Lsn (Low) -> %08lx\n", BaseLsn.LowPart );
  153. DebugTrace( 0, Dbg, "Base Lsn (High) -> %08lx\n", BaseLsn.HighPart );
  154. //
  155. // Take the first client off the in use list.
  156. //
  157. NextClient = RestartArea->ClientInUseList;
  158. //
  159. // While there are more clients, compare their oldest Lsn with the
  160. // current oldest.
  161. //
  162. while (NextClient != LFS_NO_CLIENT) {
  163. ClientBlock = ClientArray + NextClient;
  164. //
  165. // We ignore this block if it's oldest Lsn is 0.
  166. //
  167. if (( ClientBlock->OldestLsn.QuadPart != 0 )
  168. && ( ClientBlock->OldestLsn.QuadPart < OldestLsn->QuadPart )) {
  169. *OldestLsn = ClientBlock->OldestLsn;
  170. }
  171. //
  172. // Try the next client block.
  173. //
  174. NextClient = ClientBlock->NextClient;
  175. }
  176. DebugTrace( 0, Dbg, "OldestLsn (Low) -> %08lx\n", BaseLsn.LowPart );
  177. DebugTrace( 0, Dbg, "OldestLsn (High) -> %08lx\n", BaseLsn.HighPart );
  178. DebugTrace( -1, Dbg, "LfsFindOldestClientLsn: Exit\n", 0 );
  179. return;
  180. }