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.

696 lines
17 KiB

  1. /*++ BUILD Version: 0000 // Increment this if a change has global effects
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. LfsStruc.h
  5. Abstract:
  6. This module defines the data structures that make up the major internal
  7. part of the Log File Service.
  8. Author:
  9. Brian Andrew [BrianAn] 13-June-1991
  10. Revision History:
  11. --*/
  12. #ifndef _LFSSTRUC_
  13. #define _LFSSTRUC_
  14. typedef PVOID PBCB; //**** Bcb's are now part of the cache module
  15. //
  16. // Log Enumeration Block. A pointer to this structure is returned to the user
  17. // when a client is reading a particular set of log records from the log
  18. // file.
  19. //
  20. typedef struct _LEB {
  21. //
  22. // The type and size of this record (must be LFS_NTC_LEB)
  23. //
  24. NODE_TYPE_CODE NodeTypeCode;
  25. NODE_BYTE_SIZE NodeByteSize;
  26. //
  27. // Log record header. This is the mapped log record header and bcb
  28. // for the record header of the current Lsn.
  29. //
  30. struct _LFS_RECORD_HEADER *RecordHeader;
  31. PBCB RecordHeaderBcb;
  32. //
  33. // Context Mode. This is the mode governing the log record lookup. We
  34. // can look backwards via the ClientUndoNextLsn or ClientPreviousLsn.
  35. // We can also look forwards by walking through all the log records and
  36. // comparing ClientId fields.
  37. //
  38. LFS_CONTEXT_MODE ContextMode;
  39. //
  40. // Client Id. This is the client ID for the log records being returned.
  41. //
  42. LFS_CLIENT_ID ClientId;
  43. //
  44. // Log record pointer. This is the address returned to the user as the
  45. // log record referred to by CurrentLsn. If we allocated a buffer to
  46. // hold the record, we need to deallocate it as necessary.
  47. //
  48. // This field is either the actual mapped log record or a pointer to
  49. // an auxilary buffer allocated by the Lfs.
  50. //
  51. PVOID CurrentLogRecord;
  52. BOOLEAN AuxilaryBuffer;
  53. } LEB, *PLEB;
  54. //
  55. // Lfcb synchronization. This is the synchronization structure used by the Lfcb.
  56. //
  57. typedef struct _LFCB_SYNC {
  58. //
  59. // Principal Lfcb Resource.
  60. //
  61. ERESOURCE Resource;
  62. //
  63. // Notification Event. This event is set to the Signalled state when
  64. // pages are flushed to the cache file. Any waiters will then check
  65. // to see if the Lsn they're waiting for made it to disk.
  66. //
  67. KEVENT Event;
  68. //
  69. // User Count. Number of clients using this structure. We will deallocate
  70. // when all clients are gone.
  71. //
  72. ULONG UserCount;
  73. //
  74. // Mutant to guard Leb spare list
  75. //
  76. FAST_MUTEX SpareListMutex;
  77. } LFCB_SYNC, *PLFCB_SYNC;
  78. //
  79. // Log Client Structure. The Lfs allocates one of these for each active
  80. // client. The address of this structure will be returned to the user
  81. // as a log handle.
  82. //
  83. typedef struct _LCH {
  84. //
  85. // The type and size of this record (must be LFS_NTC_LCH)
  86. //
  87. NODE_TYPE_CODE NodeTypeCode;
  88. NODE_BYTE_SIZE NodeByteSize;
  89. //
  90. // Links for all the client handles on an Lfcb.
  91. //
  92. LIST_ENTRY LchLinks;
  93. //
  94. // Log File Control Block. This is the log file for this log handle.
  95. //
  96. struct _LFCB *Lfcb;
  97. //
  98. // Client Id. This refers to the client record for this client in the
  99. // Lfs restart area.
  100. //
  101. LFS_CLIENT_ID ClientId;
  102. //
  103. // The following is the number of bytes this client has asked to
  104. // have reserved in the log file. It includes the space
  105. // for the log record headers.
  106. //
  107. LONGLONG ClientUndoCommitment;
  108. //
  109. // Byte offset in the client array.
  110. //
  111. ULONG ClientArrayByteOffset;
  112. //
  113. // Pointer to the resource in the Lfcb. We access the resource with
  114. // this pointer for the times when the lfcb has been deleted.
  115. //
  116. PLFCB_SYNC Sync;
  117. } LCH, *PLCH;
  118. //
  119. // Log Buffer Control Block. A buffer control block is associated with
  120. // each of the log buffers. They are used to serialize access to the
  121. // log file.
  122. //
  123. typedef struct _LBCB {
  124. //
  125. // The type and size of this record (must be LFS_NTC_LBCB)
  126. //
  127. NODE_TYPE_CODE NodeTypeCode;
  128. NODE_BYTE_SIZE NodeByteSize;
  129. //
  130. // Buffer Block Links. These fields are used to link the buffer blocks
  131. // together.
  132. //
  133. LIST_ENTRY WorkqueLinks;
  134. LIST_ENTRY ActiveLinks;
  135. //
  136. // Log file position and length. This is the location in the log file to write
  137. // out this buffer.
  138. //
  139. LONGLONG FileOffset;
  140. LONGLONG Length;
  141. //
  142. // Sequence number. This is the sequence number for log records which
  143. // begin on this page.
  144. //
  145. LONGLONG SeqNumber;
  146. //
  147. // Next Offset. This is the next offset to write a log record in the
  148. // this log page. Stored as a large integer to facilitate large
  149. // integer operations.
  150. //
  151. LONGLONG BufferOffset;
  152. //
  153. // Buffer. This field points to the buffer containing the log page
  154. // for this block. For a log record page this is a pointer to
  155. // a pinned cache buffer, for a log restart page, this is a pointer
  156. // to an auxilary buffer.
  157. //
  158. PVOID PageHeader;
  159. //
  160. // Bcb for Log Page Block. This is the Bcb for the pinned data.
  161. // If this buffer block describes an Lfs restart area, this field is NULL.
  162. //
  163. PBCB LogPageBcb;
  164. //
  165. // Last Lsn. This is the Lsn for the last log record on this page. We delay
  166. // writing it until the page is flushed, storing it here instead.
  167. //
  168. LSN LastLsn;
  169. //
  170. // Last complete Lsn. This is the Lsn for the last log record which ends
  171. // on this page.
  172. //
  173. LSN LastEndLsn;
  174. //
  175. // Page Flags. These are the flags associated with this log page.
  176. // We store them in the Lbcb until the page is written. They flags
  177. // to use are the same as in the log record page header.
  178. //
  179. // LOG_PAGE_LOG_RECORD_END - Page contains the end of a log record
  180. // LOG_PAGE_PACKED - Page contains packed log records
  181. // LOG_PAGE_TAIL_COPY - Page is a copy of the log file end
  182. //
  183. ULONG Flags;
  184. //
  185. // Lbcb flags. These are flags used to describe this Lbcb.
  186. //
  187. // LBCB_LOG_WRAPPED - Lbcb has wrapped the log file
  188. // LBCB_ON_ACTIVE_QUEUE - Lbcb is on the active queue
  189. // LBCB_NOT_EMPTY - Page has existing log record
  190. // LBCB_FLUSH_COPY - Write copy of this page first
  191. // LBCB_RESTART_LBCB - This Lbcb contains a restart page
  192. //
  193. ULONG LbcbFlags;
  194. //
  195. // This is the thread which has locked the log page.
  196. //
  197. ERESOURCE_THREAD ResourceThread;
  198. } LBCB, *PLBCB;
  199. #define LBCB_LOG_WRAPPED (0x00000001)
  200. #define LBCB_ON_ACTIVE_QUEUE (0x00000002)
  201. #define LBCB_NOT_EMPTY (0x00000004)
  202. #define LBCB_FLUSH_COPY (0x00000008)
  203. #define LBCB_RESTART_LBCB (0x00000020)
  204. //
  205. // Log file data. This data structure is used on a per-log file basis.
  206. //
  207. typedef enum _LFS_IO_STATE {
  208. LfsNoIoInProgress = 0,
  209. LfsClientThreadIo
  210. } LFS_IO_STATE;
  211. typedef struct _LFCB {
  212. //
  213. // The type and size of this record (must be LFS_NTC_LFCB)
  214. //
  215. NODE_TYPE_CODE NodeTypeCode;
  216. NODE_BYTE_SIZE NodeByteSize;
  217. //
  218. // Lfcb Links. The following links the file control blocks to the
  219. // global data structure.
  220. //
  221. LIST_ENTRY LfcbLinks;
  222. //
  223. // Lch Links. The following links all of the handles for the Lfcb.
  224. //
  225. LIST_ENTRY LchLinks;
  226. //
  227. //
  228. // File Object. This is the file object for the log file.
  229. //
  230. PFILE_OBJECT FileObject;
  231. //
  232. // Log File Size. This is the size of the log file.
  233. // The second value is the size proposed by this open.
  234. //
  235. LONGLONG FileSize;
  236. //
  237. // Log page size, masks and shift count to do multiplication and division
  238. // of log pages.
  239. //
  240. LONGLONG LogPageSize;
  241. ULONG LogPageMask;
  242. LONG LogPageInverseMask;
  243. ULONG LogPageShift;
  244. //
  245. // First log page. This is the offset in the file of the first
  246. // log page with log records.
  247. //
  248. LONGLONG FirstLogPage;
  249. //
  250. // Next log page offset. This is the offset of the next log page to use.
  251. // If we are reusing this page we store the offset to begin with.
  252. //
  253. LONGLONG NextLogPage;
  254. ULONG ReusePageOffset;
  255. //
  256. // Data Offset. This is the offset within a log page of the data that
  257. // appears on that page. This will be the actual restart data for
  258. // an Lfs restart page, or the beginning of log record data for a log
  259. // record page.
  260. //
  261. ULONG RestartDataOffset;
  262. LONGLONG LogPageDataOffset;
  263. //
  264. // Data Size. This is the amount of data that may be stored on a
  265. // log page. It is included here because it is frequently used. It
  266. // is simply the log page size minus the data offset.
  267. //
  268. ULONG RestartDataSize;
  269. LONGLONG LogPageDataSize;
  270. //
  271. // Record header size. This is the size to use for the record headers
  272. // when reading the log file.
  273. //
  274. USHORT RecordHeaderLength;
  275. //
  276. // Sequence number. This is the number of times we have cycled through
  277. // the log file. The wrap sequence number is used to confirm that we
  278. // have gone through the entire file at least once. When we write a
  279. // log record page for an Lsn with this sequence number, then we have
  280. // cycled through the file.
  281. //
  282. LONGLONG SeqNumber;
  283. LONGLONG SeqNumberForWrap;
  284. ULONG SeqNumberBits;
  285. ULONG FileDataBits;
  286. //
  287. // Buffer Block Links. The following links the buffer blocks for this
  288. // log file.
  289. //
  290. LIST_ENTRY LbcbWorkque;
  291. LIST_ENTRY LbcbActive;
  292. PLBCB ActiveTail;
  293. PLBCB PrevTail;
  294. //
  295. // The enumerated type indicates if there is an active write for
  296. // this log file and whether it is being done by an Lfs or
  297. // client thread.
  298. //
  299. LFS_IO_STATE LfsIoState;
  300. //
  301. // Current Restart Area. The following is the in-memory image of the
  302. // next restart area. We also store a pointer to the client data
  303. // array in the restart area. The client array offset is from the start of
  304. // the restart area.
  305. //
  306. PLFS_RESTART_AREA RestartArea;
  307. PLFS_CLIENT_RECORD ClientArray;
  308. USHORT ClientArrayOffset;
  309. USHORT ClientNameOffset;
  310. //
  311. // Restart Area size. This is the usable size of the restart area.
  312. //
  313. ULONG RestartAreaSize;
  314. USHORT LogClients;
  315. //
  316. // Initial Restart area. If true, then the in-memory restart area is to
  317. // be written to the first position on the disk.
  318. //
  319. BOOLEAN InitialRestartArea;
  320. //
  321. // The following pseudo Lsn's are used to track when restart areas
  322. // are flushed to the disk.
  323. //
  324. LSN NextRestartLsn;
  325. LSN LastFlushedRestartLsn;
  326. //
  327. // The following is the earliest Lsn we will guarantee is still in the
  328. // log file.
  329. //
  330. LSN OldestLsn;
  331. //
  332. // The following is the file offset of the oldest Lsn in the system.
  333. // We redundantly store it in this form since we will be constantly
  334. // checking if a new log record will write over part of the file
  335. // we are trying to maintain.
  336. //
  337. LONGLONG OldestLsnOffset;
  338. //
  339. // Last Flushed Lsn. The following is the last Lsn guaranteed to
  340. // be flushed to the disk.
  341. //
  342. LSN LastFlushedLsn;
  343. //
  344. //
  345. // The following fields are used to track current usage in the log file.
  346. //
  347. // TotalAvailable - is the total number of bytes available for
  348. // log records. It is the number of log pages times the
  349. // data size of each page.
  350. //
  351. // TotalAvailInPages - is the total number of bytes in the log
  352. // pages for log records. This is TotalAvailable without
  353. // subtracting the size of the page headers.
  354. //
  355. // TotalUndoCommitment - is the number of bytes reserved for
  356. // possible abort operations. This includes space for
  357. // log record headers as well.
  358. //
  359. // MaxCurrentAvail - is the maximum available in all pages
  360. // subtracting the page header and any reserved tail.
  361. //
  362. // CurrentAvailable - is the total number of bytes available in
  363. // unused pages in the log file.
  364. //
  365. // ReservedLogPageSize - is the number of bytes on a page available
  366. // for reservation.
  367. //
  368. LONGLONG TotalAvailable;
  369. LONGLONG TotalAvailInPages;
  370. LONGLONG TotalUndoCommitment;
  371. LONGLONG MaxCurrentAvail;
  372. LONGLONG CurrentAvailable;
  373. LONGLONG ReservedLogPageSize;
  374. //
  375. // The following fields are used to store information about the
  376. // update sequence arrays.
  377. //
  378. USHORT RestartUsaOffset;
  379. USHORT UsaArraySize;
  380. USHORT LogRecordUsaOffset;
  381. //
  382. // Major and minor version numbers.
  383. //
  384. SHORT MajorVersion;
  385. SHORT MinorVersion;
  386. //
  387. // Log File Flags.
  388. //
  389. // LFCB_LOG_WRAPPED - We found an Lbcb which wraps the log file
  390. // LFCB_MULTIPLE_PAGE_IO - Write multiple pages if possible
  391. // LFCB_NO_LAST_LSN - There are no log records to return
  392. // LFCB_PACK_LOG - Pack the records into the pages
  393. // LFCB_REUSE_TAIL - We will be reusing the tail of the log file after restart
  394. // LFCB_NO_OLDEST_LSN - There is no oldest page being reserved
  395. //
  396. ULONG Flags;
  397. //
  398. // The following are the spare Lbcb's for the volume and a field with
  399. // the count for these.
  400. //
  401. ULONG SpareLbcbCount;
  402. LIST_ENTRY SpareLbcbList;
  403. //
  404. // The following are sparse LEB's to be used rather than having to allocate
  405. // then when reading log records
  406. //
  407. ULONG SpareLebCount;
  408. LIST_ENTRY SpareLebList;
  409. //
  410. // The following structure synchronizes access to this structure.
  411. //
  412. PLFCB_SYNC Sync;
  413. //
  414. // Count of waiters wanting access to flush the Lfcb.
  415. //
  416. ULONG Waiters;
  417. //
  418. // On-disk value for OpenLogCount. This is the value we will stuff into
  419. // the client handles.
  420. //
  421. ULONG CurrentOpenLogCount;
  422. //
  423. // Maintain the flush range for this file.
  424. //
  425. PLFS_WRITE_DATA UserWriteData;
  426. ERESOURCE_THREAD LfsIoThread;
  427. //
  428. // Buffer and mdls which hold down the first 4 pages at the head of the log
  429. // this includes the lfs restart areas and the ping pong pages. The partial mdl
  430. // is used to pin pieces of the total buffer
  431. //
  432. PMDL LogHeadMdl;
  433. PMDL LogHeadPartialMdl;
  434. PVOID LogHeadBuffer;
  435. //
  436. // preallocated error log packet for use logging errors to the eventlog
  437. //
  438. PIO_ERROR_LOG_PACKET ErrorLogPacket;
  439. #ifdef LFS_CLUSTER_CHECK
  440. LSN LsnAtMount;
  441. ULONG LsnRangeIndex;
  442. #endif
  443. //
  444. // Embedded array with enough space for SYSTEM PAGE / LOG PAGE SIZE
  445. // used to facilitate flushing partial system pages
  446. //
  447. PLBCB DirtyLbcb[0];
  448. } LFCB, *PLFCB;
  449. #define LFCB_LOG_WRAPPED (0x00000001)
  450. #define LFCB_MULTIPLE_PAGE_IO (0x00000002)
  451. #define LFCB_NO_LAST_LSN (0x00000004)
  452. #define LFCB_PACK_LOG (0x00000008)
  453. #define LFCB_REUSE_TAIL (0x00000010)
  454. #define LFCB_NO_OLDEST_LSN (0x00000020)
  455. #define LFCB_LOG_FILE_CORRUPT (0x00000040)
  456. #define LFCB_FINAL_SHUTDOWN (0x00000080)
  457. #define LFCB_READ_FIRST_RESTART (0x00000100)
  458. #define LFCB_READ_SECOND_RESTART (0x00000200)
  459. #define LFCB_READ_ONLY (0x00000400)
  460. #ifdef LFS_CLUSTER_CHECK
  461. #define LFCB_DEVICE_OFFLINE_SEEN (0x80000000)
  462. #define LFCB_FLUSH_FAILED (0x40000000)
  463. #endif
  464. #define LFCB_RESERVE_LBCB_COUNT (5)
  465. #define LFCB_MAX_LBCB_COUNT (25)
  466. #define LFCB_RESERVE_LEB_COUNT (5)
  467. #define LFCB_MAX_LEB_COUNT (25)
  468. //
  469. // Global Log Data. The following structure has only one instance and
  470. // maintains global information for the entire logging service.
  471. //
  472. typedef struct _LFS_DATA {
  473. //
  474. // The type and size of this record (must be LFS_NTC_DATA)
  475. //
  476. NODE_TYPE_CODE NodeTypeCode;
  477. NODE_BYTE_SIZE NodeByteSize;
  478. //
  479. // The following field links all of the Log File Control Blocks for
  480. // the logging system.
  481. //
  482. LIST_ENTRY LfcbLinks;
  483. //
  484. // Flag field.
  485. //
  486. ULONG Flags;
  487. //
  488. // The following mutex controls access to this structure.
  489. //
  490. FAST_MUTEX LfsDataLock;
  491. //
  492. // Allocated buffers for reading spanning log records in low memory case.
  493. // Flags indicate which buffers owned.
  494. // LFS_BUFFER1_OWNED
  495. // LFS_BUFFER2_OWNED
  496. //
  497. PVOID Buffer1;
  498. PVOID Buffer2;
  499. ERESOURCE_THREAD BufferOwner;
  500. ULONG BufferFlags;
  501. FAST_MUTEX BufferLock;
  502. KEVENT BufferNotification;
  503. } LFS_DATA, *PLFS_DATA;
  504. #define LFS_DATA_INIT_FAILED (0x00000001)
  505. #define LFS_DATA_INITIALIZED (0x00000002)
  506. #define LFS_BUFFER1_OWNED (0x00000001)
  507. #define LFS_BUFFER2_OWNED (0x00000002)
  508. #define LFS_BUFFER_SIZE (0x10000)
  509. #endif // _LFSSTRUC_