test: lfsstruc.h Source File

Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

# lfsstruc.h

Go to the documentation of this file.

    00001 /*++ BUILD Version: 0000    // Increment this if a change has global effects
    00002
    00003 Copyright (c) 1989  Microsoft Corporation
    00004
    00005 Module Name:
    00006
    00007     LfsStruc.h
    00008
    00009 Abstract:
    00010
    00011     This module defines the data structures that make up the major internal
    00012     part of the Log File Service.
    00013
    00014 Author:
    00015
    00016     Brian Andrew    [BrianAn]   13-June-1991
    00017
    00018 Revision History:
    00019
    00020 --*/
    00021
    00022 #ifndef _LFSSTRUC_
    00023 #define _LFSSTRUC_
    00024
    00025 typedef PVOID PBCB;     //**** Bcb's are now part of the cache module
    00026
    00027
    00028 //
    00029 //  Log Context Block.  A pointer to this structure is returned to the user
    00030 //  when a client is reading a particular set of log records from the log
    00031 //  file.
    00032 //
    00033
    00034 typedef struct _LCB {
    00035
    00036     //
    00037     //  The type and size of this record (must be LFS_NTC_LCB)
    00038     //
    00039
    00040     NODE_TYPE_CODE NodeTypeCode;
    00041     NODE_BYTE_SIZE NodeByteSize;
    00042
    00043     //
    00044     //  Log record header.  This is the mapped log record header and bcb
    00045     //  for the record header of the current Lsn.
    00046     //
    00047
    00048     struct _LFS_RECORD_HEADER *RecordHeader;
    00049     PBCB RecordHeaderBcb;
    00050
    00051     //
    00052     //  Context Mode.  This is the mode governing the log record lookup.  We
    00053     //  can look backwards via the ClientUndoNextLsn or ClientPreviousLsn.
    00054     //  We can also look forwards by walking through all the log records and
    00055     //  comparing ClientId fields.
    00056     //
    00057
    00058     LFS_CONTEXT_MODE ContextMode;
    00059
    00060     //
    00061     //  Client Id.  This is the client ID for the log records being returned.
    00062     //
    00063
    00064     LFS_CLIENT_ID ClientId;
    00065
    00066     //
    00067     //  Log record pointer.  This is the address returned to the user as the
    00068     //  log record referred to by CurrentLsn.  If we allocated a buffer to
    00069     //  hold the record, we need to deallocate it as necessary.
    00070     //
    00071     //  This field is either the actual mapped log record or a pointer to
    00072     //  an auxilary buffer allocated by the Lfs.
    00073     //
    00074
    00075     PVOID CurrentLogRecord;
    00076     BOOLEAN AuxilaryBuffer;
    00077
    00078 } LCB, *PLCB;
    00079
    00080
    00081 //
    00082 //  Lfcb synchronization.  This is the synchronization structure used by the Lfcb.
    00083 //
    00084
    00085 typedef struct _LFCB_SYNC {
    00086
    00087     //
    00088     //  Principal Lfcb Resource.
    00089     //
    00090
    00091     ERESOURCE Resource;
    00092
    00093     //
    00094     //  Notification Event.  This event is set to the Signalled state when
    00095     //  pages are flushed to the cache file.  Any waiters will then check
    00096     //  to see if the Lsn they're waiting for made it to disk.
    00097     //
    00098
    00099     KEVENT Event;
    00100
    00101     //
    00102     //  User Count.  Number of clients using this structure.  We will deallocate
    00103     //  when all clients are gone.
    00104     //
    00105
    00106     ULONG UserCount;
    00107
    00108     //
    00109     //  Mutant to guard Lcb spare list
    00110     //
    00111
    00112     FAST_MUTEX SpareListMutex;
    00113
    00114 } LFCB_SYNC, *PLFCB_SYNC;
    00115
    00116
    00117 //
    00118 //  Log Client Structure.  The Lfs allocates one of these for each active
    00119 //  client.  The address of this structure will be returned to the user
    00120 //  as a log handle.
    00121 //
    00122
    00123 typedef struct _LCH {
    00124
    00125     //
    00126     //  The type and size of this record (must be LFS_NTC_LCH)
    00127     //
    00128
    00129     NODE_TYPE_CODE NodeTypeCode;
    00130     NODE_BYTE_SIZE NodeByteSize;
    00131
    00132     //
    00133     //  Links for all the client handles on an Lfcb.
    00134     //
    00135
    00136     LIST_ENTRY LchLinks;
    00137
    00138     //
    00139     //  Log File Control Block.  This is the log file for this log handle.
    00140     //
    00141
    00142     struct _LFCB *Lfcb;
    00143
    00144     //
    00145     //  Client Id.  This refers to the client record for this client in the
    00146     //  Lfs restart area.
    00147     //
    00148
    00149     LFS_CLIENT_ID ClientId;
    00150
    00151     //
    00152     //  The following is the number of bytes this client has asked to
    00153     //  have reserved in the log file.  It includes the space
    00154     //  for the log record headers.
    00155     //
    00156
    00157     LONGLONG ClientUndoCommitment;
    00158
    00159     //
    00160     //  Byte offset in the client array.
    00161     //
    00162
    00163     ULONG ClientArrayByteOffset;
    00164
    00165     //
    00166     //  Pointer to the resource in the Lfcb.  We access the resource with
    00167     //  this pointer for the times when the lfcb has been deleted.
    00168     //
    00169
    00170     PLFCB_SYNC Sync;
    00171
    00172 } LCH, *PLCH;
    00173
    00174
    00175 //
    00176 //  Log Buffer Control Block.  A buffer control block is associated with
    00177 //  each of the log buffers.  They are used to serialize access to the
    00178 //  log file.
    00179 //
    00180
    00181 typedef struct _LBCB {
    00182
    00183     //
    00184     //  The type and size of this record (must be LFS_NTC_LBCB)
    00185     //
    00186
    00187     NODE_TYPE_CODE NodeTypeCode;
    00188     NODE_BYTE_SIZE NodeByteSize;
    00189
    00190     //
    00191     //  Buffer Block Links.  These fields are used to link the buffer blocks
    00192     //  together.
    00193     //
    00194
    00195     LIST_ENTRY WorkqueLinks;
    00196     LIST_ENTRY ActiveLinks;
    00197
    00198     //
    00199     //  Log file position and length.  This is the location in the log file to write
    00200     //  out this buffer.
    00201     //
    00202
    00203     LONGLONG FileOffset;
    00204     LONGLONG Length;
    00205
    00206     //
    00207     //  Sequence number.  This is the sequence number for log records which
    00208     //  begin on this page.
    00209     //
    00210
    00211     LONGLONG SeqNumber;
    00212
    00213     //
    00214     //  Next Offset.  This is the next offset to write a log record in the
    00215     //  this log page.  Stored as a large integer to facilitate large
    00216     //  integer operations.
    00217     //
    00218
    00219     LONGLONG BufferOffset;
    00220
    00221     //
    00222     //  Buffer.  This field points to the buffer containing the log page
    00223     //  for this block.  For a log record page this is a pointer to
    00224     //  a pinned cache buffer, for a log restart page, this is a pointer
    00225     //  to an auxilary buffer.
    00226     //
    00227
    00228     PVOID PageHeader;
    00229
    00230     //
    00231     //  Bcb for Log Page Block.  This is the Bcb for the pinned data.
    00232     //  If this buffer block describes an Lfs restart area, this field is NULL.
    00233     //
    00234
    00235     PBCB LogPageBcb;
    00236
    00237     //
    00238     //  Last Lsn.  This is the Lsn for the last log record on this page.  We delay
    00239     //  writing it until the page is flushed, storing it here instead.
    00240     //
    00241
    00242     LSN LastLsn;
    00243
    00244     //
    00245     //  Last complete Lsn.  This is the Lsn for the last log record which ends
    00246     //  on this page.
    00247     //
    00248
    00249     LSN LastEndLsn;
    00250
    00251     //
    00252     //  Page Flags.  These are the flags associated with this log page.
    00253     //  We store them in the Lbcb until the page is written.  They flags
    00254     //  to use are the same as in the log record page header.
    00255     //
    00256     //      LOG_PAGE_LOG_RECORD_END     -   Page contains the end of a log record
    00257     //      LOG_PAGE_PACKED             -   Page contains packed log records
    00258     //      LOG_PAGE_TAIL_COPY          -   Page is a copy of the log file end
    00259     //
    00260
    00261     ULONG Flags;
    00262
    00263     //
    00264     //  Lbcb flags.  These are flags used to describe this Lbcb.
    00265     //
    00266     //      LBCB_LOG_WRAPPED            -   Lbcb has wrapped the log file
    00267     //      LBCB_ON_ACTIVE_QUEUE        -   Lbcb is on the active queue
    00268     //      LBCB_NOT_EMPTY              -   Page has existing log record
    00269     //      LBCB_FLUSH_COPY             -   Write copy of this page first
    00270     //      LBCB_RESTART_LBCB           -   This Lbcb contains a restart page
    00271     //
    00272
    00273     ULONG LbcbFlags;
    00274
    00275     //
    00276     //  This is the thread which has locked the log page.
    00277     //
    00278
    00279     ERESOURCE_THREAD ResourceThread;
    00280
    00281 } LBCB, *PLBCB;
    00282
    00283 #define LBCB_LOG_WRAPPED                        (0x00000001)
    00284 #define LBCB_ON_ACTIVE_QUEUE                    (0x00000002)
    00285 #define LBCB_NOT_EMPTY                          (0x00000004)
    00286 #define LBCB_FLUSH_COPY                         (0x00000008)
    00287 #define LBCB_RESTART_LBCB                       (0x00000020)
    00288
    00289
    00290 //
    00291 //  Log file data.  This data structure is used on a per-log file basis.
    00292 //
    00293
    00294 typedef enum _LFS_IO_STATE {
    00295
    00296     LfsNoIoInProgress = 0,
    00297     LfsClientThreadIo
    00298
    00299 } LFS_IO_STATE;
    00300
    00301 typedef struct _LFCB {
    00302
    00303     //
    00304     //  The type and size of this record (must be LFS_NTC_LFCB)
    00305     //
    00306
    00307     NODE_TYPE_CODE NodeTypeCode;
    00308     NODE_BYTE_SIZE NodeByteSize;
    00309
    00310     //
    00311     //  Lfcb Links.  The following links the file control blocks to the
    00312     //  global data structure.
    00313     //
    00314
    00315     LIST_ENTRY LfcbLinks;
    00316
    00317     //
    00318     //  Lch Links.  The following links all of the handles for the Lfcb.
    00319     //
    00320
    00321     LIST_ENTRY LchLinks;
    00322
    00323     //
    00324     //
    00325     //  File Object.  This is the file object for the log file.
    00326     //
    00327
    00328     PFILE_OBJECT FileObject;
    00329
    00330     //
    00331     //  Log File Size.  This is the size of the log file.
    00332     //  The second value is the size proposed by this open.
    00333     //
    00334
    00335     LONGLONG FileSize;
    00336
    00337     //
    00338     //  System page size and masks.
    00339     //
    00340
    00341     LONGLONG SystemPageSize;
    00342     ULONG SystemPageMask;
    00343     LONG SystemPageInverseMask;
    00344
    00345     //
    00346     //  Log page size, masks and shift count to do multiplication and division
    00347     //  of log pages.
    00348     //
    00349
    00350     LONGLONG  LogPageSize;
    00351     ULONG LogPageMask;
    00352     LONG LogPageInverseMask;
    00353     ULONG LogPageShift;
    00354
    00355     //
    00356     //  First log page.  This is the offset in the file of the first
    00357     //  log page with log records.
    00358     //
    00359
    00360     LONGLONG FirstLogPage;
    00361
    00362     //
    00363     //  Next log page offset.  This is the offset of the next log page to use.
    00364     //  If we are reusing this page we store the offset to begin with.
    00365     //
    00366
    00367     LONGLONG NextLogPage;
    00368     ULONG ReusePageOffset;
    00369
    00370     //
    00371     //  Data Offset.  This is the offset within a log page of the data that
    00372     //  appears on that page.  This will be the actual restart data for
    00373     //  an Lfs restart page, or the beginning of log record data for a log
    00374     //  record page.
    00375     //
    00376
    00377     ULONG RestartDataOffset;
    00378     LONGLONG LogPageDataOffset;
    00379
    00380     //
    00381     //  Data Size.  This is the amount of data that may be stored on a
    00382     //  log page.  It is included here because it is frequently used.  It
    00383     //  is simply the log page size minus the data offset.
    00384     //
    00385
    00386     ULONG RestartDataSize;
    00387     LONGLONG LogPageDataSize;
    00388
    00389     //
    00390     //  Record header size.  This is the size to use for the record headers
    00391     //  when reading the log file.
    00392     //
    00393
    00394     USHORT RecordHeaderLength;
    00395
    00396     //
    00397     //  Sequence number.  This is the number of times we have cycled through
    00398     //  the log file.  The wrap sequence number is used to confirm that we
    00399     //  have gone through the entire file at least once.  When we write a
    00400     //  log record page for an Lsn with this sequence number, then we have
    00401     //  cycled through the file.
    00402     //
    00403
    00404     LONGLONG SeqNumber;
    00405     LONGLONG SeqNumberForWrap;
    00406     ULONG SeqNumberBits;
    00407     ULONG FileDataBits;
    00408
    00409     //
    00410     //  Buffer Block Links.  The following links the buffer blocks for this
    00411     //  log file.
    00412     //
    00413
    00414     LIST_ENTRY LbcbWorkque;
    00415     LIST_ENTRY LbcbActive;
    00416
    00417     PLBCB ActiveTail;
    00418     PLBCB PrevTail;
    00419
    00420     //
    00421     //  The enumerated type indicates if there is an active write for
    00422     //  this log file and whether it is being done by an Lfs or
    00423     //  client thread.
    00424     //
    00425
    00426     LFS_IO_STATE LfsIoState;
    00427
    00428     //
    00429     //  Current Restart Area.  The following is the in-memory image of the
    00430     //  next restart area.  We also store a pointer to the client data
    00431     //  array in the restart area.  The client array offset is from the start of
    00432     //  the restart area.
    00433     //
    00434
    00435     PLFS_RESTART_AREA RestartArea;
    00436     PLFS_CLIENT_RECORD ClientArray;
    00437     USHORT ClientArrayOffset;
    00438     USHORT ClientNameOffset;
    00439
    00440     //
    00441     //  Restart Area size.  This is the usable size of the restart area.
    00442     //
    00443
    00444     ULONG RestartAreaSize;
    00445     USHORT LogClients;
    00446
    00447     //
    00448     //  Initial Restart area.  If true, then the in-memory restart area is to
    00449     //  be written to the first position on the disk.
    00450     //
    00451
    00452     BOOLEAN InitialRestartArea;
    00453
    00454     //
    00455     //  The following pseudo Lsn's are used to track when restart areas
    00456     //  are flushed to the disk.
    00457     //
    00458
    00459     LSN NextRestartLsn;
    00460     LSN LastFlushedRestartLsn;
    00461
    00462     //
    00463     //  The following is the earliest Lsn we will guarantee is still in the
    00464     //  log file.
    00465     //
    00466
    00467     LSN OldestLsn;
    00468
    00469     //
    00470     //  The following is the file offset of the oldest Lsn in the system.
    00471     //  We redundantly store it in this form since we will be constantly
    00472     //  checking if a new log record will write over part of the file
    00473     //  we are trying to maintain.
    00474     //
    00475
    00476     LONGLONG OldestLsnOffset;
    00477
    00478     //
    00479     //  Last Flushed Lsn.  The following is the last Lsn guaranteed to
    00480     //  be flushed to the disk.
    00481     //
    00482
    00483     LSN LastFlushedLsn;
    00484
    00485     //
    00486     //
    00487     //  The following fields are used to track current usage in the log file.
    00488     //
    00489     //      TotalAvailable - is the total number of bytes available for
    00490     //          log records.  It is the number of log pages times the
    00491     //          data size of each page.
    00492     //
    00493     //      TotalAvailInPages - is the total number of bytes in the log
    00494     //          pages for log records.  This is TotalAvailable without
    00495     //          subtracting the size of the page headers.
    00496     //
    00497     //      TotalUndoCommitment - is the number of bytes reserved for
    00498     //          possible abort operations.  This includes space for
    00499     //          log record headers as well.
    00500     //
    00501     //      MaxCurrentAvail - is the maximum available in all pages
    00502     //          subtracting the page header and any reserved tail.
    00503     //
    00504     //      CurrentAvailable - is the total number of bytes available in
    00505     //          unused pages in the log file.
    00506     //
    00507     //      ReservedLogPageSize - is the number of bytes on a page available
    00508     //          for reservation.
    00509     //
    00510
    00511     LONGLONG TotalAvailable;
    00512     LONGLONG TotalAvailInPages;
    00513     LONGLONG TotalUndoCommitment;
    00514     LONGLONG MaxCurrentAvail;
    00515     LONGLONG CurrentAvailable;
    00516
    00517     LONGLONG ReservedLogPageSize;
    00518
    00519     //
    00520     //  The following fields are used to store information about the
    00521     //  update sequence arrays.
    00522     //
    00523
    00524     USHORT RestartUsaOffset;
    00525     USHORT RestartUsaArraySize;
    00526
    00527     USHORT LogRecordUsaOffset;
    00528     USHORT LogRecordUsaArraySize;
    00529
    00530     //
    00531     //  Major and minor version numbers.
    00532     //
    00533
    00534     SHORT MajorVersion;
    00535     SHORT MinorVersion;
    00536
    00537     //
    00538     //  Log File Flags.
    00539     //
    00540     //      LFCB_LOG_WRAPPED        -   We found an Lbcb which wraps the log file
    00541     //      LFCB_MULTIPLE_PAGE_IO   -   Write multiple pages if possible
    00542     //      LFCB_NO_LAST_LSN        -   There are no log records to return
    00543     //      LFCB_PACK_LOG           -   Pack the records into the pages
    00544     //      LFCB_REUSE_TAIL         -   We will be reusing the tail of the log file after restart
    00545     //      LFCB_NO_OLDEST_LSN      -   There is no oldest page being reserved
    00546     //
    00547
    00548     ULONG Flags;
    00549
    00550     //
    00551     //  The following are the spare Lbcb's for the volume and a field with
    00552     //  the count for these.
    00553     //
    00554
    00555     ULONG SpareLbcbCount;
    00556     LIST_ENTRY SpareLbcbList;
    00557
    00558     //
    00559     //  The following are sparse LCB's to be used rather than having to allocate
    00560     //  then when reading log records
    00561     //
    00562
    00563     ULONG SpareLcbCount;
    00564     LIST_ENTRY SpareLcbList;
    00565
    00566     //
    00567     //  The following structure synchronizes access to this structure.
    00568     //
    00569
    00570     PLFCB_SYNC Sync;
    00571
    00572     //
    00573     //  Count of waiters wanting access to flush the Lfcb.
    00574     //
    00575
    00576     ULONG Waiters;
    00577
    00578     //
    00579     //  On-disk value for OpenLogCount.  This is the value we will stuff into
    00580     //  the client handles.
    00581     //
    00582
    00583     ULONG CurrentOpenLogCount;
    00584
    00585     //
    00586     //  Maintain the flush range for this file.
    00587     //
    00588
    00589     PLFS_WRITE_DATA UserWriteData;
    00590
    00591     PLBCB PageToDirty;
    00592
    00593 #ifdef BRIANDBG
    00594     ERESOURCE_THREAD LfsIoThread;
    00595 #endif
    00596
    00597 } LFCB, *PLFCB;
    00598
    00599 #define LFCB_LOG_WRAPPED                (0x00000001)
    00600 #define LFCB_MULTIPLE_PAGE_IO           (0x00000002)
    00601 #define LFCB_NO_LAST_LSN                (0x00000004)
    00602 #define LFCB_PACK_LOG                   (0x00000008)
    00603 #define LFCB_REUSE_TAIL                 (0x00000010)
    00604 #define LFCB_NO_OLDEST_LSN              (0x00000020)
    00605 #define LFCB_LOG_FILE_CORRUPT           (0x00000040)
    00606 #define LFCB_FINAL_SHUTDOWN             (0x00000080)
    00607 #define LFCB_READ_FIRST_RESTART         (0x00000100)
    00608 #define LFCB_READ_SECOND_RESTART        (0x00000200)
    00609
    00610 #define LFCB_RESERVE_LBCB_COUNT         (5)
    00611 #define LFCB_MAX_LBCB_COUNT             (25)
    00612
    00613 #define LFCB_RESERVE_LCB_COUNT          (5)
    00614 #define LFCB_MAX_LCB_COUNT              (25)
    00615
    00616
    00617 //
    00618 //  Global Log Data.  The following structure has only one instance and
    00619 //  maintains global information for the entire logging service.
    00620 //
    00621
    00622 typedef struct _LFS_DATA {
    00623
    00624     //
    00625     //  The type and size of this record (must be LFS_NTC_DATA)
    00626     //
    00627
    00628     NODE_TYPE_CODE NodeTypeCode;
    00629     NODE_BYTE_SIZE NodeByteSize;
    00630
    00631     //
    00632     //  The following field links all of the Log File Control Blocks for
    00633     //  the logging system.
    00634     //
    00635
    00636     LIST_ENTRY LfcbLinks;
    00637
    00638     //
    00639     //  Flag field.
    00640     //
    00641
    00642     ULONG Flags;
    00643
    00644     //
    00645     //  The following mutex controls access to this structure.
    00646     //
    00647
    00648     FAST_MUTEX LfsDataLock;
    00649
    00650     //
    00651     //  Allocated buffers for reading spanning log records in low memory case.
    00652     //  Flags indicate which buffers owned.
    00653     //      LFS_BUFFER1_OWNED
    00654     //      LFS_BUFFER2_OWNED
    00655     //
    00656
    00657     PVOID Buffer1;
    00658     PVOID Buffer2;
    00659     ERESOURCE_THREAD BufferOwner;
    00660     ULONG BufferFlags;
    00661
    00662     FAST_MUTEX BufferLock;
    00663     KEVENT BufferNotification;
    00664
    00665 } LFS_DATA, *PLFS_DATA;
    00666
    00667 #define LFS_DATA_INIT_FAILED                (0x00000001)
    00668 #define LFS_DATA_INITIALIZED                (0x00000002)
    00669
    00670 #define LFS_BUFFER1_OWNED                   (0x00000001)
    00671 #define LFS_BUFFER2_OWNED                   (0x00000002)
    00672
    00673 #define LFS_BUFFER_SIZE                     (0x10000)
    00674 #endif // _LFSSTRUC_
    00675