-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdtverify.c
2446 lines (2324 loc) · 81 KB
/
dtverify.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/****************************************************************************
* *
* COPYRIGHT (c) 1988 - 2021 *
* This Software Provided *
* By *
* Robin's Nest Software Inc. *
* *
* Permission to use, copy, modify, distribute and sell this software and *
* its documentation for any purpose and without fee is hereby granted, *
* provided that the above copyright notice appear in all copies and that *
* both that copyright notice and this permission notice appear in the *
* supporting documentation, and that the name of the author not be used *
* in advertising or publicity pertaining to distribution of the software *
* without specific, written prior permission. *
* *
* THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN *
* NO EVENT SHALL HE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL *
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR *
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS *
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF *
* THIS SOFTWARE. *
* *
****************************************************************************/
/*
* Module: dtverify.c
* Author: Robin T. Miller
* Date: August 17th, 2013
*
* Description:
* Data Verification functions.
*
* Modification History:
*
* March 8th, 2021 by Robin T. Miller
* When corruptions occur, if onerr=stop is enabled, stop other threads,
* thereby reducing I/O in traces and expediting trigger(s) execution.
*
* November 30th, 2020 by Robin T. Miller
* When reporting extended error information, clarify the LBA type.
*
* July 9th, 2020 by Robin T. Miller
* For Windows, when saving corrupted data files, check for both the
* native directory separator '\' and the POSIX directory separator '/',
* since we don't know which was setup during startup.
*
* June 12th, 2020 by Robin T. Miller
* Fix improper limit calculation when dumping expected/received buffers.
* The limit was going negative, which caused a segmentation fault when hit!
*
* May 4th, 2020 by Robin T. Miller
* Display the command to re-read all data including corrupted record.
*
* April 26th, 2020 by Robin T. Miller
* Add the job and thread ID's to corrupted files being saved, so it's
* easier to identify the job/thread that created them. While files often
* have this information, direct disk device names do not, so adding.
*
* April 8th, 2020 by Robin T. Miller
* When dumping block tags (btags), dump the buffer in hex bytes.
*
* December 22nd, 2019 by Robin T. Miller
* For file systems, report the physical LBA if we can translate.
*
* December 16th, 2-19 by Robin T. Miller
* When dumping buffers, for received data display the file offsets
* rather than memory addresses, which are more useful for troubleshooting.
*
* December 14th, 2019 by Robin T. Miller
* Provide more extended error information to help with troubleshooting.
*
* December 3rd, 2019 by Robin T. Miller
* Add writing corrupted and reread data to a file for later analysis.
* This especially helps with "transient" (temporary) verification errors.
*
* November 21st, 2019 by Robin T. Miller
* Added separate retry data corruption delay (was sharing retry delay).
* Added retry data corruption limit, rather than just loop on error.
*
* June 11th, 2019 by Robin T. Miller
* When looping on data corruption, use the corruption dip (cdip),
* for stopping or terminating the thread (was using cloned dip).
*
* April 30th, 2018 by Robin T. Miller
* Added extra compare flag, to control btag prefix verification.
* Note: The btags is usually sufficient, extra compare is for my debug.
*
* April 26th, 2018 by Robin T. Miller
* When reading only, if the btag is valid, also verify the prefix
* string (if any), for higher validation. While this is not fullproof,
* it does catch valid btags with an incorrect prefix strings.
*
* June 7th, 2015 by Robin T. Miller
* Adding support for verifying block tags (btags).
* Updated dumping buffers display all data if less than dump limit.
*
* April 25th, 2015 by Robin T. Miller
* During verify retries, always display the dt reread command line,
* but disable compare if pattern options do not permit data verification.
*
* April 21st, 2015 by Robin T. Miller
* Modified dump_buffer() to use log buffer to consolidate output.
*
* April 20th, 2015 by Robin T. Miller
* For file systems, during errors report the file identifier (i-node).
*
* April 29th, 2014 by Robin T. Miller
* WHen rereading after a corruption, for Linux NFS file systems, do
* *not* disable Direct I/O (DIO) if the I/O size of offset is not modulo
* the block size. For SAN on local file systems, these *must* be aligned,
* or else EINVAL is returned on the read().
*
* August 17th, 2013 by Robin T Miller
* Moving verify functions here.
*/
#include "dt.h"
#include <ctype.h>
/*
* Forward References:
*/
int verify_prefix(struct dinfo *dip, u_char *buffer, size_t bcount, int bindex, size_t *pcount);
static void report_reread_corrupted(dinfo_t *dip, size_t request_size, Offset_t record_offset, uint32_t pattern);
static int update_reread_file(dinfo_t *dip, char *buffer, char *reread_file);
static int verify_data_with_btags( struct dinfo *dip,
uint8_t *buffer,
size_t bytes,
uint32_t pattern,
lbdata_t *lba,
hbool_t raw_flag );
static int verify_data_normal( struct dinfo *dip,
u_char *buffer,
size_t bcount,
u_int32 pattern,
hbool_t raw_flag );
static int verify_data_prefix( struct dinfo *dip,
u_char *buffer,
size_t bcount,
u_int32 pattern,
hbool_t raw_flag );
static int verify_data_with_lba(struct dinfo *dip,
u_char *buffer,
size_t bcount,
u_int32 pattern,
u_int32 *lba,
hbool_t raw_flag );
static size_t CalculateDumpSize(dinfo_t *dip, size_t size);
static int dopad_verify( struct dinfo *dip,
u_char *buffer,
size_t offset,
u_int32 pattern,
size_t pbytes,
size_t pindex,
hbool_t inverted );
#if 0
static char *pad_str = "Pad";
#endif
static char *lba_str = "Lba";
static char *data_str = "Data";
static char *btag_str = "Block Tag";
static char *pattern_str = "Pattern";
static char *prefix_str = "Prefix";
static char *verify_str = "Verify";
static char *compare_error_str = "Data compare error at byte";
/************************************************************************
* *
* CalculateDumpSize() - Calculate the number of data bytes to dump. *
* *
* Description: *
* For non-memory mapped files, we'll dump the pad bytes. These *
* pad bytes do not exist for memory mapped files which are directly *
* mapped to memory addresses. *
* *
* Inputs: *
* dip = The device information pointer. *
* size = The size of the buffer to dump. *
* *
* Outputs: Size of buffer to dump. *
* *
************************************************************************/
static size_t
CalculateDumpSize(dinfo_t *dip, size_t size)
{
size_t dump_size = size;
if (dip->di_mmap_flag == False) {
dump_size += PADBUFR_SIZE;
}
if (dump_size > dip->di_data_size) {
dump_size = dip->di_data_size;
}
return(dump_size);
}
void
dump_buffer ( dinfo_t *dip,
char *name,
uint8_t *base,
uint8_t *cptr,
size_t dump_size,
size_t bufr_size,
hbool_t expected )
{
if (dip->di_random_access == False) {
dump_buffer_legacy(dip, name, base, cptr, dump_size, bufr_size, expected);
} else if (expected == True) {
dump_expected_buffer(dip, name, base, cptr, dump_size, bufr_size);
} else {
dump_received_buffer(dip, name, base, cptr, dump_size, bufr_size);
}
return;
}
/************************************************************************
* *
* dump_buffer_legacy() Dump data buffer legacy format. *
* *
* Inputs: *
* dip = The device infromation pointer. *
* name = The buffer name being dumped. *
* base = Base pointer of buffer to dump. *
* ptr = Pointer into buffer being dumped. *
* dump_size = The size of the buffer to dump. *
* bufr_size = The maximum size of this buffer. *
* expected = Boolean flag (True = Expected). *
* *
* Return Value: *
* Void. *
* *
************************************************************************/
void
dump_buffer_legacy ( dinfo_t *dip,
char *name,
uint8_t *base,
uint8_t *ptr,
size_t dump_size,
size_t bufr_size,
hbool_t expected )
{
size_t boff, coff, limit, offset;
u_int field_width = 16;
uint8_t *bend;
uint8_t *bptr;
uint8_t data;
uint8_t *abufp, *abp;
size_t dindex;
if ( (base == NULL) || (ptr == NULL) ) {
/* Avoid strange segmentation faults, making debug more difficult! */
Eprintf(dip, "BUG: The base "LLPX0FMT" and/or dump buffer "LLPX0FMT", are NULL!\n",
base, ptr);
return;
}
bend = (base + bufr_size);
bptr = base;
dindex = (ptr - base);
abufp = abp = (u_char *)Malloc(dip, (field_width + 1) );
/*
* Since many requests do large transfers, limit data dumped.
*/
limit = (dump_size < dip->di_dump_limit) ? dump_size : dip->di_dump_limit;
/*
* Now to provide context, attempt to dump data on both sides of
* the corrupted data, ensuring buffer limits are not exceeded.
* Note: Only adjust the dumping, if index is > dump limit!
*/
if (dindex > limit) {
bptr = (ptr - (limit >> 1));
if (bptr < base) bptr = base;
if ( (bptr + limit) > bend) {
limit = (bend - bptr); /* Dump to end of buffer. */
}
}
offset = (ptr - base); /* Offset to failing data. */
coff = (ptr - bptr); /* Offset from dump start. */
/*
* Note: Rotate parameters are not displayed since we don't have
* the base data address and can't use global due to AIO design.
* [ if I get ambitious, I'll correct this in a future release. ]
*/
Lprintf(dip, "The %scorrect data starts at address "LLPXFMT" (marked by asterisk '*')\n",
(expected) ? "" : "in", ptr);
Lprintf(dip, "Dumping %s Buffer (base = "LLPXFMT", buffer offset = %u, limit = %u bytes):\n",
name, base, offset, limit);
#if defined(MACHINE_64BITS)
Lprintf(dip, " Memory Address / Offset\n");
#else /* !defined(MACHINE_64BITS) */
Lprintf(dip, " Address / Offset\n");
#endif /* defined(MACHINE_64BITS) */
/*
* Note: This may be deprecated with new side by side comparision, but at
* present it's needed for non-IOT patterns, and also provides context.
*/
for (boff = 0; boff < limit; boff++, bptr++) {
if ((boff % field_width) == (size_t) 0) {
if (boff) Lprintf(dip, " \"%s\"\n", abufp); abp = abufp;
Lprintf(dip, LLPX0FMT"/%6u |", bptr, (boff + (offset - coff)));
}
data = *bptr;
Lprintf(dip, "%c%02x", (bptr == ptr) ? '*' : ' ', data);
abp += Sprintf((char *)abp, "%c", isprint((int)data) ? data : ' ');
}
if (abp != abufp) {
while (boff++ % field_width) Lprintf(dip, " ");
Lprintf(dip, " \"%s\"\n", abufp);
}
Free(dip, abufp);
if (expected) {
Lprintf(dip, "\n");
}
eLflush(dip);
return;
}
/************************************************************************
* *
* dump_expected_buffer() Dump the expected data buffer. *
* *
* Inputs: *
* dip = The device infromation pointer. *
* name = The buffer name being dumped. *
* base = Base pointer of buffer to dump. *
* cptr = Pointer into buffer being dumped. *
* dump_size = The size of the buffer to dump. *
* bufr_size = The maximum size of this buffer. *
* *
* Return Value: *
* Void. *
* *
************************************************************************/
void
dump_expected_buffer ( dinfo_t *dip,
char *name,
uint8_t *base,
uint8_t *cptr,
size_t dump_size,
size_t bufr_size )
{
size_t bytes, coff, limit, mindex;
u_int field_width = 16;
uint8_t *bend, *bptr;
uint8_t data;
uint8_t *abufp, *abp;
size_t dindex;
if ( (base == NULL) || (cptr == NULL) ) {
/* Avoid strange segmentation faults, making debug more difficult! */
Eprintf(dip, "BUG: The base "LLPX0FMT" and/or dump buffer "LLPX0FMT", are NULL!\n",
base, cptr);
return;
}
bend = (base + bufr_size);
bptr = base;
dindex = (cptr - base);
abufp = abp = (u_char *)Malloc(dip, (field_width + 1) );
/*
* Since many requests do large transfers, limit data dumped.
*/
limit = (dump_size < dip->di_dump_limit) ? dump_size : dip->di_dump_limit;
/*
* Now to provide context, attempt to dump data on both sides of
* the corrupted data, ensuring buffer limits are not exceeded.
* Note: Only adjust the dumping, if index is > dump limit!
*/
mindex = (cptr - base); /* Index to mismatch data. */
if (dindex >= limit) {
bptr = (cptr - (limit >> 1));
if ( (bptr < base) || (bptr < bend) ) {
bptr = base;
}
if ( (bptr + limit) > bend) {
limit = (bend - bptr); /* Dump to end of buffer. */
}
}
coff = (cptr - bptr); /* Corruption offset from dump start. */
Lprintf(dip, "The correct data starts at memory address "LLPX0FMT" (marked by asterisk '*')\n", cptr);
Lprintf(dip, "Dumping %s Buffer (base = "LLPXFMT", mismatch offset = "SDF", limit = "SDF" bytes):\n",
name, base, mindex, limit);
Lprintf(dip, " / Buffer\n");
Lprintf(dip, " Memory Address / Index \n");
/*
* Note: This may be deprecated with new side by side comparision, but at
* present it's needed for non-IOT patterns, and also provides context.
*/
for (bytes = 0; (bytes < limit) && (bptr < bend); bytes++, bptr++) {
if ((bytes % field_width) == (size_t) 0) {
if (bytes) Lprintf(dip, " \"%s\"\n", abufp); abp = abufp;
Lprintf(dip, LLPX0FMT"/%6u |", bptr, (bytes + (mindex - coff)));
}
data = *bptr;
Lprintf(dip, "%c%02x", (bptr == cptr) ? '*' : ' ', data);
abp += Sprintf((char *)abp, "%c", isprint((int)data) ? data : ' ');
}
if (abp != abufp) {
while (bytes++ % field_width) Lprintf(dip, " ");
Lprintf(dip, " \"%s\"\n", abufp);
}
Free(dip, abufp);
Lprintf(dip, "\n");
eLflush(dip);
return;
}
/************************************************************************
* *
* dump_received_buffer() Dump the received data buffer. *
* *
* Inputs: *
* dip = The device infromation pointer. *
* name = The buffer name being dumped. *
* base = Base pointer of buffer to dump. *
* cptr = Pointer into buffer being dumped. *
* dump_size = The size of the buffer to dump. *
* bufr_size = The maximum size of this buffer. *
* *
* Return Value: *
* Void. *
* *
************************************************************************/
void
dump_received_buffer ( dinfo_t *dip,
char *name,
uint8_t *base,
uint8_t *cptr,
size_t dump_size,
size_t bufr_size )
{
size_t bytes, coff, limit, mindex;
u_int field_width = 16;
uint8_t *bend, *bptr;
uint8_t data;
uint8_t *abufp, *abp;
Offset_t fbase, fend, foff, fcptr, fptr;
size_t dindex;
if ( (base == NULL) || (cptr == NULL) ) {
/* Avoid strange segmentation faults, making debug more difficult! */
Eprintf(dip, "BUG: The base "LLPX0FMT" and/or dump buffer "LLPX0FMT", are NULL!\n",
base, cptr);
return;
}
bend = (base + bufr_size);
bptr = base;
dindex = (cptr - base);
fbase = fptr = getFileOffset(dip);
fend = (fbase + bufr_size);
abufp = abp = (u_char *)Malloc(dip, (field_width + 1) );
/*
* Since many requests do large transfers, limit data dumped.
*/
limit = (dump_size < dip->di_dump_limit) ? dump_size : dip->di_dump_limit;
/*
* Now to provide context, attempt to dump data on both sides of
* the corrupted data, ensuring buffer limits are not exceeded.
* Note: Only adjust the dumping, if index is > dump limit!
*/
mindex = (cptr - base); /* Index to mismatch data. */
fcptr = (fbase + mindex); /* File offset of corruption. */
if (dindex >= limit) {
size_t context = (limit >> 1);
fptr = (fcptr - context);
if (fptr < fbase) {
fptr = fbase;
}
bptr = (cptr - context);
if ( (bptr < base) || (bptr > bend) ) {
bptr = base;
}
if ( (bptr + limit) > bend) {
limit = (bend - bptr); /* Dump to end of buffer. */
}
}
coff = (cptr - bptr); /* Corruption offset from dump start. */
foff = (fcptr - fptr); /* Note: This should match the above! */
Lprintf(dip, "The incorrect data starts at memory address "LLPX0FMT" (for Robin's debug! :)\n", cptr);
Lprintf(dip, "The incorrect data starts at file offset %018llu (marked by asterisk '*')\n", fcptr);
Lprintf(dip, "Dumping %s File offsets (base = "LUF", mismatch offset = "SDF", limit = "SDF" bytes):\n",
name, fbase, mindex, limit);
Lprintf(dip, " / Block\n");
Lprintf(dip, " File Offset / Index \n");
/*
* Note: This may be deprecated with new side by side comparision, but at
* present it's needed for non-IOT patterns, and also provides context.
*/
for (bytes = 0; (bytes < limit) && (bptr < bend); bytes++, bptr++, fptr++) {
if ((bytes % field_width) == (size_t) 0) {
if (bytes) Lprintf(dip, " \"%s\"\n", abufp); abp = abufp;
uint32_t foffset = (uint32_t)(bytes + (mindex - foff));
Lprintf(dip, "%018llu/%6u |", fptr, (uint32_t)(foffset % dip->di_device_size));
}
data = *bptr;
Lprintf(dip, "%c%02x", (bptr == cptr) ? '*' : ' ', data);
abp += Sprintf((char *)abp, "%c", isprint((int)data) ? data : ' ');
}
if (abp != abufp) {
while (bytes++ % field_width) Lprintf(dip, " ");
Lprintf(dip, " \"%s\"\n", abufp);
}
Free(dip, abufp);
Lprintf(dip, "\n");
eLflush(dip);
return;
}
/************************************************************************
* *
* dump_file_buffer() - Dump the received file buffer. *
* *
* Inputs: *
* dip = The device infromation pointer. *
* name = The buffer name being dumped. *
* base = Base pointer of buffer to dump. *
* cptr = Pointer into buffer being dumped. *
* dump_size = The size of the buffer to dump. *
* bufr_size = The maximum size of this buffer. *
* *
* Note: Mostly a clone of dump_receive_buffer(). *
* *
* Return Value: *
* Void. *
* *
************************************************************************/
void
dump_file_buffer ( dinfo_t *dip,
char *name,
uint8_t *base,
uint8_t *cptr,
size_t dump_size,
size_t bufr_size )
{
size_t bytes, coff, limit, mindex;
u_int field_width = 16;
uint8_t *bend, *bptr;
uint8_t data;
uint8_t *abufp, *abp;
Offset_t fbase, fend, foff, fcptr, fptr;
size_t dindex;
if (dip->di_dump_limit == 0) { return; }
if ((base == NULL) || (cptr == NULL)) {
/* Avoid strange segmentation faults, making debug more difficult! */
Eprintf(dip, "BUG: The base "LLPX0FMT" and/or dump buffer "LLPX0FMT", are NULL!\n",
base, cptr);
return;
}
bend = (base + bufr_size);
bptr = base;
dindex = (cptr - base);
fbase = fptr = getFileOffset(dip);
fend = (fbase + bufr_size);
abufp = abp = (u_char *)Malloc(dip, (field_width + 1) );
/*
* Since many requests do large transfers, limit data dumped.
*/
limit = (dump_size < dip->di_dump_limit) ? dump_size : dip->di_dump_limit;
/*
* Now to provide context, attempt to dump data on both sides of
* the corrupted data, ensuring buffer limits are not exceeded.
* Note: Only adjust the dumping, if index is > dump limit!
*/
mindex = (cptr - base); /* Index to mismatch data. */
fcptr = (fbase + mindex); /* File offset of corruption. */
if (dindex >= limit) {
fptr = (fcptr - (limit >> 1));
if (fptr < fbase) fptr = fbase;
bptr = (cptr - (limit >> 1));
if (bptr < base) bptr = base;
if ( (bptr + limit) > bend) {
limit = (bend - bptr); /* Dump to end of buffer. */
}
}
coff = (cptr - bptr); /* Corruption offset from dump start. */
foff = (fcptr - fptr); /* Note: This should match the above! */
Lprintf(dip, "Dumping %s File offsets (base offset = "LUF", limit = %u bytes):\n",
name, fbase, limit);
Lprintf(dip, " / Block\n");
Lprintf(dip, " File Offset / Index \n");
/*
* Note: This may be deprecated with new side by side comparision, but at
* present it's needed for non-IOT patterns, and also provides context.
*/
for (bytes = 0; bytes < limit; bytes++, bptr++, fptr++) {
if ((bytes % field_width) == (size_t) 0) {
if (bytes) Lprintf(dip, " \"%s\"\n", abufp); abp = abufp;
uint32_t foffset = (uint32_t)(bytes + (mindex - foff));
Lprintf(dip, "%018llu/%6u |", fptr, (uint32_t)(foffset % dip->di_device_size));
}
data = *bptr;
Lprintf(dip, " %02x", data);
abp += Sprintf((char *)abp, "%c", isprint((int)data) ? data : ' ');
}
if (abp != abufp) {
while (bytes++ % field_width) Lprintf(dip, " ");
Lprintf(dip, " \"%s\"\n", abufp);
}
Free(dip, abufp);
Lprintf(dip, "\n");
eLflush(dip);
return;
}
#if defined(TIMESTAMP)
void
display_timestamp(dinfo_t *dip, u_char *buffer)
{
time_t seconds;
seconds = (time_t)stoh(buffer, sizeof(iotlba_t));
Fprintf(dip, "The data block was written on %s\n",
os_ctime(&seconds, dip->di_time_buffer, sizeof(dip->di_time_buffer)));
return;
}
#endif /* defined(TIMESTAMP) */
/*
* verify_prefix() - Verify Buffer with Prefix String.
*
* Inputs:
* dip = The device information pointer.
* buffer = Address of buffer to verify.
* bcount = The full buffer count.
* bindex = The index into the buffer.
* pcount = Pointer to return prefix count verified.
*
* Outputs:
* pcount gets the prefix string count verified.
* Return value is Success or Failure.
*/
int
verify_prefix( struct dinfo *dip, u_char *buffer, size_t bcount, int bindex, size_t *pcount )
{
register u_char *bptr = buffer;
register u_char *pstr = (u_char *)dip->di_fprefix_string;
register size_t count;
register size_t i;
int status = SUCCESS;
count = MIN((size_t)dip->di_fprefix_size, (bcount - bindex));
for (i = 0; (i < count); i++, bptr++, pstr++) {
if (*bptr != *pstr) {
size_t dump_size;
ReportCompareError(dip, bcount, (u_int)(bindex + i), *pstr, *bptr);
Fprintf(dip, "Mismatch of data pattern prefix: '%s' (%d bytes w/pad)\n",
dip->di_fprefix_string, dip->di_fprefix_size);
/* expected */
dump_size = dip->di_fprefix_size;
if (dump_size > dip->di_data_size) {
dump_size = dip->di_data_size;
}
//dump_size = CalculateDumpSize(dip, dip->di_fprefix_size);
dump_buffer(dip, prefix_str, (u_char *)dip->di_fprefix_string,
pstr, dump_size, dip->di_fprefix_size, True);
/* received */
#if defined(TIMESTAMP)
if (dip->di_timestamp_flag) {
display_timestamp(dip, buffer+count);
}
#endif /* defined(TIMESTAMP) */
dump_size = CalculateDumpSize(dip, bcount);
dump_buffer(dip, data_str, buffer, bptr, dump_size, bcount, False);
status = FAILURE;
if ( (dip->di_retrying == False) && (dip->di_trigdelay_flag == False) ) {
if ( (dip->di_trigger_control == TRIGGER_ON_ALL) ||
(dip->di_trigger_control == TRIGGER_ON_MISCOMPARE) ) {
(void)ExecuteTrigger(dip, miscompare_op);
}
}
break;
}
}
*pcount = count;
return (status);
}
/************************************************************************
* *
* verify_buffers() - Verify Data Buffers. *
* *
* Description: *
* Simple verification of two data buffers. *
* *
* Inputs: dip = The device information pointer. *
* dbuffer = Data buffer to verify with. *
* vbuffer = Verification buffer to use. *
* count = The number of bytes to compare. *
* *
* Outputs: Returns SUCCESS/FAILURE = Data Ok/Compare Error. *
* *
************************************************************************/
int
verify_buffers( struct dinfo *dip,
u_char *dbuffer,
u_char *vbuffer,
size_t count )
{
u_int32 i;
u_char *dptr = dbuffer;
u_char *vptr = vbuffer;
if (dip->di_verify_delay) { /* Optional verify delay. (for debug) */
mySleep(dip, dip->di_verify_delay);
}
for (i = 0; (i < count); i++, dptr++, vptr++) {
if (*dptr != *vptr) {
size_t dump_size = CalculateDumpSize(dip, count);
ReportCompareError(dip, count, i, *dptr, *vptr);
/* expected */
dump_buffer(dip, data_str, dbuffer, dptr, dump_size, count, True);
/* received */
#if defined(TIMESTAMP)
if (dip->di_timestamp_flag) {
display_timestamp(dip, vbuffer);
}
#endif /* defined(TIMESTAMP) */
dump_buffer(dip, verify_str, vbuffer, vptr, dump_size, count, False);
if ( (dip->di_retrying == False) && (dip->di_trigdelay_flag == False) ) {
if ( (dip->di_trigger_control == TRIGGER_ON_ALL) ||
(dip->di_trigger_control == TRIGGER_ON_MISCOMPARE) ) {
(void)ExecuteTrigger(dip, miscompare_op);
}
}
return (FAILURE);
}
}
return (SUCCESS);
}
/************************************************************************
* *
* verify_lbdata() - Verify Logical Block Address in Buffer. *
* *
* Description: *
* Note: This function is used during read-after-write tests. *
* *
* Inputs: dip = The device information pointer. *
* dbuffer = Data buffer to verify with. *
* vbuffer = Verification buffer to use. *
* count = The number of bytes to compare. *
* lba = Pointer to return last lba verified. *
* *
* Outputs: Returns SUCCESS/FAILURE = lba Ok/Compare Error. *
* *
************************************************************************/
int
verify_lbdata( struct dinfo *dip,
u_char *dbuffer,
u_char *vbuffer,
size_t count,
u_int32 *lba )
{
u_int32 i, dlbn = 0, vlbn;
u_char *dptr = dbuffer;
u_char *vptr = vbuffer;
int status = SUCCESS;
/*
* Note: With timestamps enabled, we overwrite the lba.
*/
if (dip->di_timestamp_flag) { return (status); }
for (i = 0; (i+sizeof(dlbn) <= count); i += dip->di_lbdata_size,
dptr += dip->di_lbdata_size, vptr += dip->di_lbdata_size) {
if (dip->di_iot_pattern) {
dlbn = get_lbn(dptr);
vlbn = get_lbn(vptr);
} else {
dlbn = (u_int32)stoh(dptr, sizeof(dlbn));
vlbn = (u_int32)stoh(vptr, sizeof(vlbn));
}
if (dlbn != vlbn) {
size_t dump_size = CalculateDumpSize(dip, count);
ReportLbdataError(dip, *lba, (uint32_t)count, i, dlbn, vlbn);
/* expected */
dump_buffer(dip, data_str, dbuffer, dptr, dump_size, count, True);
/* received */
dump_buffer(dip, verify_str, vbuffer, vptr, dump_size, count, False);
status = FAILURE;
break;
}
}
*lba = (dlbn + 1);
return (status);
}
/************************************************************************
* *
* verify_data() - Verify Data Pattern. *
* *
* Description: *
* If a pattern_buffer exists, then this data is used to compare *
* the buffer instead of the pattern specified. *
* *
* Inputs: dip = The device information pointer. *
* buffer = Pointer to data to verify. *
* count = The number of bytes to compare. *
* pattern = Data pattern to compare against. *
* lba = Pointer to starting logical block address. *
* raw_flag = Performing read-after-write flag. *
* *
* Outputs: Returns SUCCESS/FAILURE = Data Ok/Compare Error. *
* lba gets updated with the next lba to verify with. *
* *
************************************************************************/
int
verify_data ( struct dinfo *dip,
uint8_t *buffer,
size_t count,
uint32_t pattern,
uint32_t *lba,
hbool_t raw_flag )
{
hbool_t check_lba = (dip->di_iot_pattern || (dip->di_lbdata_flag && dip->di_lbdata_size));
int status;
if (dip->di_verify_delay) { /* Optional verify delay. (for debug) */
mySleep(dip, dip->di_verify_delay);
}
if (dip->di_btag_flag == True) {
status = verify_data_with_btags(dip, buffer, count, pattern, lba, raw_flag);
} else if ( (check_lba == False) && (dip->di_fprefix_string == NULL) ) {
status = verify_data_normal(dip, buffer, count, pattern, raw_flag);
} else if ( (check_lba == False) && dip->di_fprefix_string ) {
status = verify_data_prefix(dip, buffer, count, pattern, raw_flag);
} else {
status = verify_data_with_lba(dip, buffer, count, pattern, lba, raw_flag);
}
if ( (status == SUCCESS) || (dip->di_retrying == True) ) {
return(status);
}
/*
* For random access devices, on verify errors, perform read retries.
*/
if (dip->di_retryDC_flag && dip->di_random_access) {
(void)verify_reread(dip, buffer, count, pattern, lba);
}
/*
* To capture read retries, for triggers which stop I/O, we now allow
* mismatch triggers to be delayed until *after* re-read retries.
*/
if (dip->di_trigdelay_flag == True) {
if ( (dip->di_trigger_control == TRIGGER_ON_ALL) ||
(dip->di_trigger_control == TRIGGER_ON_MISCOMPARE) ) {
(void)ExecuteTrigger(dip, miscompare_op);
}
}
/*
* The file system map gets allocated whenever file errors are reported.
* Free the file system map if doing read-after-write, to force refresh.
*/
if (raw_flag && dip->di_fsmap) {
os_free_file_map(dip);
}
return (status);
}
/*
* verify_reread() - Verify Data after Rereading with Direct I/O.
*
* Description:
* If a pattern_buffer exists, then this data is used to compare
* the buffer instead of the pattern specified.
*
* Inputs:
* cdip = The current device information pointer.
* buffer = Pointer to the write data to verify.
* count = The number of bytes to compare.
* pattern = Data pattern to compare against.
* lba = Pointer to starting logical block address.
*
* Return Value:
* Returns SUCCESS/FAILURE = Data Ok/Compare Error.
* lba gets updated with the next lba to verify with.
*/
int
verify_reread(
struct dinfo *cdip,
u_char *buffer,
size_t bcount,
u_int32 pattern,
u_int32 *lba )
{
dinfo_t *dip = NULL;
uint8_t *reread_buffer = NULL;
Offset_t record_offset;
ssize_t reread_count;
int oflags = OS_READONLY_MODE;
uint32_t retries = 0;
hbool_t saved_aio_flag;
hbool_t saved_dio_flag;
hbool_t saved_rDebugFlag;
int status;
Fprintf(cdip, "\n");
if (cdip->di_save_corrupted) {
if (cdip->di_iot_pattern == True) {
void *pattern_buffer = (cdip->di_saved_pattern_ptr) ? cdip->di_saved_pattern_ptr : cdip->di_pattern_bufptr;
(void)save_corrupted_data(cdip, cdip->di_dname, pattern_buffer, bcount, CTYPE_EXPECTED);
}
(void)save_corrupted_data(cdip, cdip->di_dname, buffer, bcount, CTYPE_CORRUPTED);
}
/*
* Please Note: For SAN disks, using a SCSI Read may be desirable?
* Also Note: Dated code, overdue for a cleanup/rewrite (IMHO).
*/
if ( (cdip->di_dtype->dt_dtype == DT_REGULAR) ||
(cdip->di_dtype->dt_dtype == DT_BLOCK) ) {
Fprintf(cdip, "Rereading and verifying record data using Direct I/O...\n");
} else {
Fprintf(cdip, "Rereading and verifying record data...\n");
}
cdip->di_retrying = True;
/*
* We have a bit of work to reread the data.
*/
dip = Malloc(cdip, sizeof(*dip));
if (dip == NULL) goto cleanup_exit;
reread_buffer = malloc_palign(cdip, bcount, 0);
if (reread_buffer == NULL) goto cleanup_exit;
*dip = *cdip; /* Copy current device information. */
/* Use the cloned device pointer for retries! */
dip->di_fd = NoFd;
record_offset = cdip->di_offset;
/*
* Enable direct I/O for our reread (bypass buffer cache).
*/
saved_aio_flag = dip->di_aio_flag;
saved_dio_flag = dip->di_dio_flag;
dip->di_aio_flag = False; /* Avoid overlapped attribute Windows. */
/*
* Only enable Direct I/O for regular files, not raw disks!
*/
if ( (dip->di_dtype->dt_dtype == DT_REGULAR) ||
(dip->di_dtype->dt_dtype == DT_BLOCK) ) {
/*
* For Linux and Windows DIO, the buffer, count, and offset must be
* block aligned/sized to avoid errors:
* Linux: dt: 'read', errno = 22 - Invalid argument
* Windows: 'SetFilePointer', errno = 87 - The parameter is incorrect.
* Others? Solaris, FreeBSD, etc?
* OS's like Tru64 and HP-UX have special fixup code so Ok.
*/
#if defined(__linux__) || defined(WIN32)
/* Mickey Mouse, trying to avoid SAN DIO read failures! */
if ( (dip->di_bypass_flag == False) &&
(bcount % BLOCK_SIZE) || (record_offset % BLOCK_SIZE) ) {
if (dip->di_filesystem_type && EQS(dip->di_filesystem_type, "nfs")) {
;
} else {
dip->di_dio_flag = False;
Wprintf(dip, "The I/O size or offset is NOT block aligned, so Direct I/O is disabled!\n");
}
} else
#endif /* defined(__linux__) || defined(WIN32) */
{
dip->di_dio_flag = True; /* Valid for Solaris & native Windows. */
#if defined(O_DIRECT)
oflags |= O_DIRECT; /* Direct disk access. */
#endif
}
#if defined(__linux__)
} else if (dip->di_dtype->dt_dtype == DT_DISK) {
/* Linux disks are block devices, grrrr! */
oflags |= O_DIRECT; /* Bypass the buffer cache, please! */
#endif /* defined(__linux__) */
}
/*
* Steps/Logic:
* - open the device/file (again)
* - reread the record data
* - verify against previous read data (verify == write error)
* - verify against expected data (verify == read error)
*/
status = (*dip->di_funcs->tf_reopen_file)(dip, oflags);
if (status != SUCCESS) goto cleanup_exit;
saved_rDebugFlag = dip->di_rDebugFlag;
dip->di_rDebugFlag = True; /* Report our seek info. */