00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
#include "lfsprocs.h"
00023
00024
00025
00026
00027
00028 #define Dbg (DEBUG_TRACE_LOG_RECORD_SUP)
00029
00030
VOID
00031
LfsPrepareLfcbForLogRecord (
00032 IN OUT
PLFCB Lfcb,
00033 IN ULONG RemainingLogBytes
00034 );
00035
00036
VOID
00037
LfsTransferLogBytes (
00038 IN
PLBCB Lbcb,
00039 IN OUT
PLFS_WRITE_ENTRY *ThisWriteEntry,
00040 IN OUT PCHAR *CurrentBuffer,
00041 IN OUT PULONG CurrentByteCount,
00042 IN OUT PULONG PadBytes,
00043 IN OUT PULONG RemainingPageBytes,
00044 IN OUT PULONG RemainingLogBytes
00045 );
00046
00047
#ifdef ALLOC_PRAGMA
00048
#pragma alloc_text(PAGE, LfsPrepareLfcbForLogRecord)
00049
#pragma alloc_text(PAGE, LfsTransferLogBytes)
00050
#pragma alloc_text(PAGE, LfsWriteLogRecordIntoLogPage)
00051
#endif
00052
00053
00054 BOOLEAN
00055 LfsWriteLogRecordIntoLogPage (
00056 IN
PLFCB Lfcb,
00057 IN
PLCH Lch,
00058 IN ULONG NumberOfWriteEntries,
00059 IN
PLFS_WRITE_ENTRY WriteEntries,
00060 IN LFS_RECORD_TYPE RecordType,
00061 IN TRANSACTION_ID *TransactionId OPTIONAL,
00062 IN LSN ClientUndoNextLsn OPTIONAL,
00063 IN LSN ClientPreviousLsn OPTIONAL,
00064 IN LONG UndoRequirement,
00065 IN BOOLEAN ForceToDisk,
00066 OUT PLSN Lsn
00067 )
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 {
00124
PLFS_WRITE_ENTRY ThisWriteEntry;
00125
00126 ULONG RemainingLogBytes;
00127 ULONG OriginalLogBytes;
00128
00129 ULONG RemainingPageBytes;
00130 ULONG HeaderAdjust;
00131
00132
PLBCB ThisLbcb;
00133
00134
LSN NextLsn;
00135
00136
PLFS_RECORD_HEADER RecordHeader;
00137
00138 PCHAR CurrentBuffer;
00139 ULONG CurrentByteCount;
00140 ULONG PadBytes;
00141
00142 BOOLEAN LogFileFull =
FALSE;
00143
00144
PAGED_CODE();
00145
00146
DebugTrace( +1,
Dbg,
"LfsWriteLogRecordIntoLogPage: Entered\n", 0 );
00147
DebugTrace( 0,
Dbg,
"Lfcb -> %08lx\n", Lfcb );
00148
DebugTrace( 0,
Dbg,
"Lch -> %08lx\n", Lch );
00149
DebugTrace( 0,
Dbg,
"Number of Write Entries -> %08lx\n", NumberOfWriteEntries );
00150
DebugTrace( 0,
Dbg,
"Write Entries -> %08lx\n", WriteEntries );
00151
DebugTrace( 0,
Dbg,
"Record Type -> %08lx\n", RecordType );
00152
DebugTrace( 0,
Dbg,
"Transaction Id -> %08lx\n", TransactionId );
00153
DebugTrace( 0,
Dbg,
"ClientUndoNextLsn (Low) -> %08lx\n", ClientUndoNextLsn.LowPart );
00154
DebugTrace( 0,
Dbg,
"ClientUndoNextLsn (High) -> %08lx\n", ClientUndoNextLsn.HighPart );
00155
DebugTrace( 0,
Dbg,
"ClientPreviousLsn (Low) -> %08lx\n", ClientPreviousLsn.LowPart );
00156
DebugTrace( 0,
Dbg,
"ClientPreviousLsn (High) -> %08lx\n", ClientPreviousLsn.HighPart );
00157
DebugTrace( 0,
Dbg,
"UndoRequirement -> %08lx\n", UndoRequirement );
00158
DebugTrace( 0,
Dbg,
"ForceToDisk -> %04x\n", ForceToDisk );
00159
00160
00161
00162
00163
00164 ThisWriteEntry = WriteEntries;
00165
00166 RemainingLogBytes = 0;
00167
00168
while (NumberOfWriteEntries--) {
00169
00170 RemainingLogBytes +=
QuadAlign( ThisWriteEntry->
ByteLength );
00171
00172 ThisWriteEntry++;
00173 }
00174
00175 OriginalLogBytes = RemainingLogBytes;
00176
00177 ThisWriteEntry = WriteEntries;
00178
00179
00180
00181
00182
00183
00184
00185
while (
TRUE) {
00186
00187 LogFileFull =
LfsVerifyLogSpaceAvail( Lfcb,
00188 Lch,
00189 RemainingLogBytes,
00190 UndoRequirement,
00191 ForceToDisk );
00192
00193
00194
00195
00196
00197
00198
LfsPrepareLfcbForLogRecord( Lfcb,
00199 RemainingLogBytes + Lfcb->RecordHeaderLength );
00200
00201 ThisLbcb = CONTAINING_RECORD( Lfcb->LbcbActive.Flink,
00202
LBCB,
00203 ActiveLinks );
00204
00205
00206
00207
00208
00209
if (ThisLbcb->
LogPageBcb !=
NULL) {
break; }
00210
00211
00212
00213
00214
00215 Lfcb->Waiters += 1;
00216
00217
LfsReleaseLfcb( Lfcb );
00218
00219
KeWaitForSingleObject( &Lfcb->Sync->Event,
00220
Executive,
00221
KernelMode,
00222
FALSE,
00223
NULL );
00224
00225
LfsAcquireLfcb( Lfcb );
00226 Lfcb->Waiters -= 1;
00227 }
00228
00229 RemainingPageBytes = (ULONG)Lfcb->LogPageSize - (ULONG)ThisLbcb->
BufferOffset;
00230
00231
00232
00233
00234
00235 NextLsn.QuadPart =
LfsComputeLsnFromLbcb( Lfcb, ThisLbcb );
00236
00237
00238
00239
00240
00241
00242 RecordHeader =
Add2Ptr( ThisLbcb->
PageHeader,
00243 (ULONG)ThisLbcb->
BufferOffset,
00244
PLFS_RECORD_HEADER );
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254 RtlZeroMemory( RecordHeader, Lfcb->RecordHeaderLength );
00255
00256
00257
00258
00259
00260 RecordHeader->
ThisLsn = NextLsn;
00261 RecordHeader->
ClientPreviousLsn = ClientPreviousLsn;
00262 RecordHeader->
ClientUndoNextLsn = ClientUndoNextLsn;
00263
00264
if (TransactionId !=
NULL) {
00265 RecordHeader->
TransactionId = *TransactionId;
00266 }
00267
00268 RecordHeader->
ClientDataLength = RemainingLogBytes;
00269 RecordHeader->
ClientId = Lch->ClientId;
00270 RecordHeader->
RecordType = RecordType;
00271
00272
00273
00274
00275
00276
if (RemainingLogBytes + Lfcb->RecordHeaderLength > RemainingPageBytes) {
00277
00278
SetFlag( RecordHeader->
Flags,
LOG_RECORD_MULTI_PAGE );
00279 }
00280
00281 RemainingPageBytes -= Lfcb->RecordHeaderLength;
00282
00283
00284
00285
00286
00287 (ULONG)ThisLbcb->
BufferOffset += Lfcb->RecordHeaderLength;
00288 HeaderAdjust = Lfcb->RecordHeaderLength;
00289
00290
00291
00292
00293
00294 CurrentBuffer = ThisWriteEntry->
Buffer;
00295 CurrentByteCount = ThisWriteEntry->
ByteLength;
00296
00297 PadBytes = (8 - (CurrentByteCount & ~(0xfffffff8))) & ~(0xfffffff8);
00298
00299
00300
00301
00302
00303
00304
while (RemainingLogBytes != 0) {
00305
00306
PLFS_RECORD_PAGE_HEADER PageHeader;
00307
00308 PageHeader = (
PLFS_RECORD_PAGE_HEADER) ThisLbcb->
PageHeader;
00309
00310
00311
00312
00313
00314
00315
00316
if (!
FlagOn( ThisLbcb->
LbcbFlags,
LBCB_NOT_EMPTY )) {
00317
00318
00319
00320
00321
00322
00323
00324
00325
if ((ULONG)ThisLbcb->
BufferOffset - HeaderAdjust == (ULONG)Lfcb->LogPageDataOffset) {
00326
00327
00328 Lfcb->CurrentAvailable = Lfcb->CurrentAvailable - Lfcb->ReservedLogPageSize;
00329 }
00330
00331 InsertTailList( &Lfcb->LbcbWorkque, &ThisLbcb->
WorkqueLinks );
00332
SetFlag( ThisLbcb->
LbcbFlags,
LBCB_NOT_EMPTY );
00333 }
00334
00335 HeaderAdjust = 0;
00336
00337
00338
00339
00340
00341
00342
00343
LfsTransferLogBytes( ThisLbcb,
00344 &ThisWriteEntry,
00345 &CurrentBuffer,
00346 &CurrentByteCount,
00347 &PadBytes,
00348 &RemainingPageBytes,
00349 &RemainingLogBytes );
00350
00351
00352
00353
00354
00355
00356
if (RemainingLogBytes == 0) {
00357
00358
SetFlag( ThisLbcb->
Flags,
LOG_PAGE_LOG_RECORD_END );
00359 ThisLbcb->
LastEndLsn = NextLsn;
00360
00361
if (
FlagOn( Lfcb->Flags,
LFCB_PACK_LOG )) {
00362
00363 PageHeader->
Header.Packed.LastEndLsn = NextLsn;
00364 PageHeader->
Header.Packed.NextRecordOffset = (
USHORT)ThisLbcb->
BufferOffset;
00365 }
00366 }
00367
00368
00369
00370
00371
00372
if (RemainingPageBytes == 0
00373 || RemainingLogBytes == 0) {
00374
00375
00376
00377
00378
00379 ThisLbcb->
LastLsn = NextLsn;
00380 PageHeader->
Copy.LastLsn = NextLsn;
00381 PageHeader->
Flags = ThisLbcb->
Flags;
00382
00383
00384
00385
00386
00387
00388
if (RemainingPageBytes < Lfcb->RecordHeaderLength) {
00389
00390 RemoveHeadList( &Lfcb->LbcbActive );
00391
ClearFlag( ThisLbcb->
LbcbFlags,
LBCB_ON_ACTIVE_QUEUE );
00392
00393
00394
00395
00396
00397
if (RemainingLogBytes != 0) {
00398
00399 ThisLbcb = CONTAINING_RECORD( Lfcb->LbcbActive.Flink,
00400
LBCB,
00401 ActiveLinks );
00402
00403 RemainingPageBytes = (ULONG)Lfcb->LogPageSize
00404 - (ULONG)ThisLbcb->
BufferOffset;
00405 }
00406 }
00407 }
00408 }
00409
00410 *Lsn = NextLsn;
00411
00412 Lfcb->RestartArea->CurrentLsn = NextLsn;
00413
00414 Lfcb->RestartArea->LastLsnDataLength = OriginalLogBytes;
00415
00416
ClearFlag( Lfcb->Flags,
LFCB_NO_LAST_LSN );
00417
00418
DebugTrace( 0,
Dbg,
"Lsn (Low) -> %08lx\n", Lsn->LowPart );
00419
DebugTrace( 0,
Dbg,
"Lsn (High) -> %08lx\n", Lsn->HighPart );
00420
DebugTrace( -1,
Dbg,
"LfsWriteLogRecordIntoLogPage: Exit\n", 0 );
00421
00422
return LogFileFull;
00423 }
00424
00425
00426
00427
00428
00429
00430
VOID
00431 LfsPrepareLfcbForLogRecord (
00432 IN OUT
PLFCB Lfcb,
00433 IN ULONG RemainingLogBytes
00434 )
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459 {
00460
PLBCB ThisLbcb;
00461 ULONG RemainingPageBytes;
00462 PLIST_ENTRY LbcbLinks;
00463
00464
PAGED_CODE();
00465
00466
DebugTrace( +1,
Dbg,
"LfsPrepareLfcbForLogRecord: Entered\n", 0 );
00467
DebugTrace( 0,
Dbg,
"Lfcb -> %08lx\n", Lfcb );
00468
DebugTrace( 0,
Dbg,
"RemainingLogBytes -> %08lx\n", RemainingLogBytes );
00469
00470
00471
00472
00473
00474
if (!IsListEmpty( &Lfcb->LbcbActive )) {
00475
00476
00477
00478
00479
00480
00481 ThisLbcb = CONTAINING_RECORD( Lfcb->LbcbActive.Flink,
00482
LBCB,
00483 ActiveLinks );
00484
00485 RemainingPageBytes = (ULONG)Lfcb->LogPageSize
00486 - (ULONG)ThisLbcb->
BufferOffset;
00487
00488
00489
00490
00491
00492
00493
00494
if (RemainingLogBytes > RemainingPageBytes
00495 && !
FlagOn( Lfcb->Flags,
LFCB_PACK_LOG )
00496 && (ULONG)ThisLbcb->
BufferOffset != (ULONG)Lfcb->LogPageDataOffset) {
00497
00498 RemoveHeadList( &Lfcb->LbcbActive );
00499
ClearFlag( ThisLbcb->
LbcbFlags,
LBCB_ON_ACTIVE_QUEUE );
00500 }
00501 }
00502
00503
00504
00505
00506
00507
00508 LbcbLinks = Lfcb->LbcbActive.Flink;
00509
00510
while (
TRUE) {
00511
00512
00513
00514
00515
00516
00517
if (LbcbLinks == &Lfcb->LbcbActive) {
00518
00519 ThisLbcb =
LfsGetLbcb( Lfcb );
00520
00521 }
else {
00522
00523 ThisLbcb = CONTAINING_RECORD( LbcbLinks,
00524
LBCB,
00525 ActiveLinks );
00526 }
00527
00528
00529
00530
00531
00532
00533 RemainingPageBytes = (ULONG)Lfcb->LogPageSize - (ULONG)ThisLbcb->
BufferOffset;
00534
00535
if (RemainingPageBytes >= RemainingLogBytes) {
00536
00537
break;
00538 }
00539
00540
00541
00542
00543
00544 RemainingLogBytes -= RemainingPageBytes;
00545
00546 LbcbLinks = ThisLbcb->
ActiveLinks.Flink;
00547 }
00548
00549
DebugTrace( -1,
Dbg,
"LfsPrepareLfcbForLogRecord: Exit\n", 0 );
00550
00551
return;
00552 }
00553
00554
00555
VOID
00556 LfsTransferLogBytes (
00557 IN
PLBCB Lbcb,
00558 IN OUT
PLFS_WRITE_ENTRY *ThisWriteEntry,
00559 IN OUT PCHAR *CurrentBuffer,
00560 IN OUT PULONG CurrentByteCount,
00561 IN OUT PULONG PadBytes,
00562 IN OUT PULONG RemainingPageBytes,
00563 IN OUT PULONG RemainingLogBytes
00564 )
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605 {
00606 PCHAR CurrentLogPagePosition;
00607 PCHAR CurrentClientPosition;
00608
00609 ULONG TransferBytes;
00610 ULONG ThisPadBytes;
00611
00612
PAGED_CODE();
00613
00614
DebugTrace( +1,
Dbg,
"LfsTransferLogBytes: Entered\n", 0 );
00615
DebugTrace( 0,
Dbg,
"Lbcb -> %08lx\n", Lbcb );
00616
DebugTrace( 0,
Dbg,
"ThisWriteEntry -> %08lx\n", *ThisWriteEntry );
00617
DebugTrace( 0,
Dbg,
"CurrentBuffer -> %08lx\n", *CurrentBuffer );
00618
DebugTrace( 0,
Dbg,
"CurrentByteCount -> %08lx\n", *CurrentByteCount );
00619
DebugTrace( 0,
Dbg,
"RemainingPageBytes -> %08lx\n", *RemainingPageBytes );
00620
DebugTrace( 0,
Dbg,
"RemainingLogBytes -> %08lx\n", *RemainingLogBytes );
00621
00622
00623
00624
00625
00626
00627 CurrentLogPagePosition =
Add2Ptr( Lbcb->PageHeader, (ULONG)Lbcb->BufferOffset, PCHAR );
00628 CurrentClientPosition = *CurrentBuffer;
00629
00630
00631
00632
00633
00634
00635
if (*CurrentByteCount <= *RemainingPageBytes) {
00636
00637 TransferBytes = *CurrentByteCount;
00638
00639 ThisPadBytes = *PadBytes;
00640
00641
if (*RemainingLogBytes != (*CurrentByteCount + *PadBytes) ) {
00642
00643 (*ThisWriteEntry)++;
00644
00645 *CurrentBuffer = (*ThisWriteEntry)->Buffer;
00646 *CurrentByteCount = (*ThisWriteEntry)->ByteLength;
00647
00648 *PadBytes = (8 - (*CurrentByteCount & ~(0xfffffff8))) & ~(0xfffffff8);
00649 }
00650
00651 }
else {
00652
00653 TransferBytes = *RemainingPageBytes;
00654
00655 ThisPadBytes = 0;
00656
00657 *CurrentByteCount -= TransferBytes;
00658
00659
if (*CurrentBuffer !=
NULL) {
00660
00661 *CurrentBuffer += TransferBytes;
00662 }
00663 }
00664
00665
00666
00667
00668
00669
if (CurrentClientPosition !=
NULL) {
00670
00671 RtlCopyMemory( CurrentLogPagePosition, CurrentClientPosition, TransferBytes );
00672
00673 }
else {
00674
00675 RtlZeroMemory( CurrentLogPagePosition, TransferBytes );
00676 }
00677
00678
00679
00680
00681
00682
00683 *RemainingLogBytes -= (TransferBytes + ThisPadBytes);
00684 *RemainingPageBytes -= (TransferBytes + ThisPadBytes);
00685
00686 (ULONG)Lbcb->BufferOffset += (TransferBytes + ThisPadBytes);
00687
00688
DebugTrace( -1,
Dbg,
"LfsTransferLogBytes: Exit\n", 0 );
00689
00690
return;
00691 }