-
Notifications
You must be signed in to change notification settings - Fork 15
/
dtapp.c
2919 lines (2610 loc) · 96.5 KB
/
dtapp.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 2021 NetApp
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
*/
/*
* dtapp.c - I/O Behavior for dtapp functionality.
*
* Author: Robin T. Miller
* Date Created: September 12th, 2015
*
* Modification History:
*
* November 9, 2021 by Chris Nelson (nelc@netapp.com)
* Add MIT license, in order to distribute to FOSS community so it can
* be used and maintained by a larger audience, particularly for the
* public dt at https://github.com/RobinTMiller/dt
*
* May 7th, 2020 by Robin T. Miller
* When using step option, honor the end offset even without slices.
*
* May 5th, 2020 by Robin T. Miller
* Use high resolution timer for more accurate I/O timing. This is
* implemented on Windows, but Unix systems still use gettimeofday() API.
*
* December 21st, 2016 by Robin T. Miller
* Disable random I/O operations to avoid false data corruptions.
*
* February 10th, 2016 by Robin T. Miller
* Update dtapp_read_record() to use common read_record() now that
* we've switched to pread() in the latter function.
* When cleaning up devices, catch the case where dips is NULL, which
* happens when the job log cannot be opened, yet we still do cleanup.
*
* October 8th, 2015 by Robin T. Miller
* Added btag CRC to write ordering extension to increase verification.
*/
#include "dt.h"
/*
* Definitions:
*/
#define DEFAULT_THREAD_COUNT 1
#define DEFAULT_RUNTIME 0
#define DTAPP_DEFAULT_LOG_PREFIX "%prog (j:%job t:%thread d:%devnum): "
#if defined(NETAPP)
# define DTAPP_DEFAULT_NATE_LOG_PREFIX "%nate (%prog j:%job t:%thread d:%devnum): "
#endif /* defined(NETAPP */
#define BTAG_NO_DEVICE_INDEX 0xFF
/*
* dtapp Specific Information:
*/
typedef struct dtapp_information {
dinfo_t *dta_primary_dip; /* The primary device information. */
file_type_t dta_primary_type; /* The primary device type (input or output)*/
int dta_current_index; /* The current device index. */
int dta_input_count; /* The number of input devices. */
char **dta_input_devices; /* Pointers to input device names. */
dinfo_t **dta_input_dips; /* Pointers to input device information. */
int dta_output_count; /* The number of output devices. */
char **dta_output_devices; /* Pointers to output device names. */
dinfo_t **dta_output_dips; /* Pointers to output device information. */
int dta_write_order_entries; /* The number of write order entries. */
int dta_write_order_index; /* The current write order index. */
btag_write_order_t *dta_write_orders; /* Write order table (array). */
btag_write_order_t *dta_last_write_order; /* Pointer to last entry. */
} dtapp_information_t;
/*
* Forward References:
*/
void dtapp_help(dinfo_t *dip);
/*
* I/O Behavior Functions:
*/
int dtapp_initialize(dinfo_t *dip);
int dtapp_initiate_job(dinfo_t *dip);
int dtapp_initialize_devices(dinfo_t *mdip, dtapp_information_t *dtap);
dinfo_t *dtapp_initialize_input_device(dinfo_t *mdip, char *device, hbool_t master);
int dtapp_initialize_input_devices(dinfo_t *mdip, dtapp_information_t *dtap);
dinfo_t *dtapp_initialize_output_device(dinfo_t *mdip, char *device, hbool_t master);
int dtapp_initialize_output_devices(dinfo_t *mdip, dtapp_information_t *dtap);
int dtapp_parser(dinfo_t *dip, char *option);
void dtapp_cleanup_information(dinfo_t *dip);
int dtapp_clone_information(dinfo_t *dip, dinfo_t *cdip, hbool_t new_context);
int dtapp_job_finish(dinfo_t *mdip, job_info_t *job);
void *dtapp_thread(void *arg);
int dtapp_validate_parameters(dinfo_t *dip);
char *dtapp_make_device_list(char **devices, int device_count);
void dtapp_report_all_statistics(dinfo_t *tdip, dtapp_information_t *dtap, char **devices, int device_count);
int dtapp_doio(dinfo_t *dip);
int dtapp_doreadpass(dinfo_t *dip);
int dtapp_dowritepass(dinfo_t *dip);
void dtapp_report_write_stats(dinfo_t *dip);
void dtapp_do_prepass_processing(dinfo_t *dip);
int dtapp_report_pass_statistics(dinfo_t *dip, dinfo_t **dips, int device_count, stats_t stats_type, hbool_t end_of_pass);
int dtapp_finish_test(dinfo_t *dip, int exit_code, hbool_t do_cleanup);
void dtapp_finish_test_common(dinfo_t *dip, int thread_status);
int dtapp_count_devices(char *devices);
char **dtapp_clone_devices(dinfo_t *dip, char **device_list, int num_devices);
dinfo_t **dtapp_clone_dips(dinfo_t *dip, dinfo_t **dips, int num_devices);
void dtapp_free_devices(dinfo_t *dip, char **device_list, int num_devices);
void dtapp_free_dips(dinfo_t *dip, dinfo_t **dips, int num_devices);
int dtapp_close_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_close_input_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_close_output_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_open_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_open_input_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_open_output_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_flush_output_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_lock_unlock(dinfo_t **dips, int device_count, lock_type_t lock_type, large_t data_limit);
large_t dtapp_get_data_limit(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_set_device_offset(dinfo_t *dip);
int dtapp_set_device_offsets(dinfo_t *dip, dtapp_information_t *dtap);
#define IterateInputDevices(dtap, func, arg) \
dtapp_iterate_devices(dtap->dta_input_dips, dtap->dta_input_count, &func, arg);
#define IterateOutputDevices(dtap, func, arg) \
dtapp_iterate_devices(dtap->dta_output_dips, dtap->dta_output_count, &func, arg);
#define IterateAllDevices(dtap, func, arg, rc) \
if ( (rc = dtapp_iterate_devices(dtap->dta_input_dips, dtap->dta_input_count, &func, arg)) == SUCCESS) { \
rc = dtapp_iterate_devices(dtap->dta_output_dips, dtap->dta_output_count, &func, arg); \
}
int dtapp_iterate_devices(dinfo_t **dips, int device_count, int (*func)(dinfo_t *dip, void *arg), void *arg);
int dtapp_set_open_flags(dinfo_t *dip, void *arg);
int dtapp_end_pass(dinfo_t *dip, void *arg);
int dtapp_gather_stats(dinfo_t *dip, void *arg);
int dtapp_error_count(dinfo_t *dip, void *arg);
int dtapp_pass_count(dinfo_t *dip, void *arg);
int dtapp_report_history(dinfo_t *dip, void *arg);
int dtapp_report_pass(dinfo_t *dip, void *arg);
int dtapp_prepass_processing(dinfo_t *dip, void *arg);
int dtapp_postwrite_processing(dinfo_t *dip, void *arg);
int dtapp_start_read_pass(dinfo_t *dip, void *arg);
int dtapp_start_write_pass(dinfo_t *dip, void *arg);
int dtapp_test_startup(dinfo_t *dip, void *arg);
int dtapp_test_complete(dinfo_t *dip, void *arg);
int dtapp_parse_devices(dinfo_t *dip, dtapp_information_t *dtap);
char **dtapp_parse_device_list(dinfo_t *dip, char *devices, int num_devices);
int dtapp_setup_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_setup_input_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_setup_output_devices(dinfo_t *dip, dtapp_information_t *dtap);
int dtapp_setup_write_orders(dinfo_t *dip, dtapp_information_t *dtap, int entries);
void dtapp_set_write_order_entry(dinfo_t *dip, btag_t *btag);
int dtapp_common_device_setup(dinfo_t *dip);
int dtapp_read_data(dinfo_t *dip);
int dtapp_write_data(dinfo_t *dip);
int dtapp_report_btag(dinfo_t *dip, btag_t *ebtag, btag_t *rbtag, hbool_t raw_flag);
int dtapp_update_btag(dinfo_t *dip, btag_t *btag, Offset_t offset,
uint32_t record_index, size_t record_size, uint32_t record_number);
int dtapp_verify_btag(dinfo_t *dip, btag_t *ebtag, btag_t *rbtag,
uint32_t *eindex, hbool_t raw_flag);
int dtapp_verify_btag_opaque_data(dinfo_t *dip, btag_t *btag);
int verify_btag_write_order(dinfo_t *dip, btag_t *btag, size_t transfer_count);
int verify_ordered_btags(dinfo_t *dip, btag_t *btag, btag_write_order_t *wrop, void *buffer, size_t record_size, btag_t **error_btag);
void dtapp_report_ordered_btags_error(dinfo_t *dip, dinfo_t *pdip, btag_t *btag, btag_t *pbtag, btag_t *error_btag);
ssize_t dtapp_read_record(dinfo_t *dip, uint8_t *buffer, size_t bsize, size_t dsize, Offset_t offset, int *status);
static char *empty_str = "";
static char *incorrect_str = "incorrect";
static char *expected_str = "Expected";
static char *received_str = "Received";
/*
* Declare the I/O behavior functions:
*/
iobehavior_funcs_t dtapp_iobehavior_funcs = {
"dtapp", /* iob_name */
DTAPP_IO, /* iob_iobehavior */
NULL, /* iob_map_options */
NULL, /* iob_maptodt_name */
NULL, /* iob_dtmap_options */
&dtapp_initialize, /* iob_initialize */
&dtapp_initiate_job, /* iob_initiate_job */
&dtapp_parser, /* iob_parser */
&dtapp_cleanup_information, /* iob_cleanup */
&dtapp_clone_information, /* iob_clone */
&dtapp_thread, /* iob_thread */
NULL, /* iob_thread1 */
NULL, /* iob_job_init */
NULL, /* iob_job_cleanup */
&dtapp_job_finish, /* iob_job_finish */
NULL, /* iob_job_modify */
NULL, /* iob_job_query */
NULL, /* iob_job_keepalive */
NULL, /* iob_thread_keepalive */
NULL, /* iob_show_parameters */
&dtapp_validate_parameters /* iob_validate_parameters */
};
/*
* Declare the generic (default) test functions.
*/
dtfuncs_t dtapp_funcs = {
/* tf_open, tf_close, tf_initialize, */
open_file, close_file, initialize,
/* tf_start_test, tf_end_test, */
init_file, nofunc,
/* tf_read_file, tf_read_data, tf_cancel_reads, */
nofunc, dtapp_read_data, nofunc,
/* tf_write_file, tf_write_data, tf_cancel_writes, */
nofunc, dtapp_write_data, nofunc,
/* tf_flush_data, tf_verify_data, tf_reopen_file, */
flush_file, verify_data, reopen_file,
/* tf_startup, tf_cleanup, tf_validate_opts */
nofunc, nofunc, validate_opts,
/* tf_report_btag, tf_update_btag tf_verify_btag */
&dtapp_report_btag, &dtapp_update_btag, &dtapp_verify_btag,
};
int
dtapp_count_devices(char *devices)
{
char *p = devices;
int num_devices = 1;
/* Count the devices specified. */
while (p = strchr(p, ',')) {
num_devices++; p++;
}
return(num_devices);
}
char **
dtapp_parse_device_list(dinfo_t *dip, char *devices, int num_devices)
{
char *token, *saveptr;
char **device_list;
int device;
device_list = Malloc(dip, sizeof(char **) * num_devices);
if (device_list == NULL) return(NULL);
if (num_devices == 1) {
device_list[0] = strdup(devices);
return(device_list);
}
/* Parse the device list. */
/* Note: strtok_r() replaces "," with '\0'! */
token = strtok_r(devices, ",", &saveptr);
for (device = 0; (device < num_devices); device++) {
device_list[device] = strdup(token);
token = strtok_r(NULL, ",", &saveptr); /* Next device please! */
}
return(device_list);
}
void
dtapp_set_iobehavior_funcs(dinfo_t *dip)
{
dip->di_iobf = &dtapp_iobehavior_funcs;
return;
}
/* ---------------------------------------------------------------------- */
int
dtapp_parser(dinfo_t *dip, char *option)
{
dtapp_information_t *dtap = dip->di_opaque;
int status = PARSE_MATCH;
if (match(&option, "-")) { /* Optional "-" to match dtapp options! */
;
}
if (match(&option, "help")) {
dtapp_help(dip);
return(STOP_PARSING);
}
/* Add dtapp specific parsing here... */
return(PARSE_NOMATCH);
}
/* ---------------------------------------------------------------------- */
char *
dtapp_make_device_list(char **devices, int device_count)
{
char buffer[STRING_BUFFER_SIZE];
char *strp = buffer;
int device;
for (device = 0; (device < device_count); device++) {
strp += sprintf(strp, "%s,", devices[device]);
}
strp--; *strp = '\0';
return( strdup(buffer) );
}
void
dtapp_report_all_statistics(dinfo_t *tdip, dtapp_information_t *dtap, char **devices, int device_count)
{
char *device_list = dtapp_make_device_list(devices, device_count);
char *dname = tdip->di_dname;
tdip->di_dname = device_list;
report_stats(tdip, TOTAL_STATS);
tdip->di_dname = dname;
return;
}
int
dtapp_job_finish(dinfo_t *dip, job_info_t *job)
{
dtapp_information_t *dtap;
threads_info_t *tip = job->ji_tinfo;
dinfo_t *tdip;
int device, thread;
/*
* Accumulate the total statistics for each thread.
*/
for (thread = 0; (thread < tip->ti_threads); thread++) {
tdip = tip->ti_dts[thread];
dtap = tdip->di_opaque;
/* Accumulate thread statistics here...*/
device = 0;
if ( (dtap->dta_primary_type == INPUT_FILE) && (tdip == dtap->dta_primary_dip) ) {
device++;
report_stats(tdip, TOTAL_STATS);
}
for ( ; device < dtap->dta_input_count; device++) {
dinfo_t *idip = dtap->dta_input_dips[device];
tdip->di_total_bytes += (idip->di_total_bytes_read + idip->di_total_bytes_written);
tdip->di_total_files += (idip->di_total_files_read + idip->di_total_files_written);
tdip->di_total_records += idip->di_pass_total_records;
tdip->di_total_partial += idip->di_pass_total_partial;
report_stats(idip, TOTAL_STATS);
}
if (device > 1) {
dtapp_report_all_statistics(tdip, dtap, dtap->dta_input_devices, dtap->dta_input_count);
}
device = 0;
if ( (dtap->dta_primary_type == OUTPUT_FILE) && (tdip == dtap->dta_primary_dip) ) {
device++;
report_stats(tdip, TOTAL_STATS);
}
for ( ; device < dtap->dta_output_count; device++) {
dinfo_t *odip = dtap->dta_output_dips[device];
tdip->di_total_bytes += (odip->di_total_bytes_read + odip->di_total_bytes_written);
tdip->di_total_files += (odip->di_total_files_read + odip->di_total_files_written);
tdip->di_total_records += odip->di_pass_total_records;
tdip->di_total_partial += odip->di_pass_total_partial;
report_stats(odip, TOTAL_STATS);
}
if (device > 1) {
dtapp_report_all_statistics(tdip, dtap, dtap->dta_output_devices, dtap->dta_output_count);
}
}
return(SUCCESS);
}
void *
dtapp_thread(void *arg)
{
dinfo_t *dip = arg;
dtapp_information_t *dtap = dip->di_opaque;
uint64_t iterations = 0;
hbool_t do_cleanup = False;
int status = SUCCESS, rc;
/* Do first, to propogate log file to all devices. */
/* TODO: This function wants to know if we're a FS! */
/* The FS is *not* known until devices are setup below! */
/* Sets up file/directory names and creates top directory. */
status = do_common_thread_startup(dip);
if (status == FAILURE) goto thread_exit;
/*
* Only the 1st device is initialized, now do any others.
*/
status = dtapp_initialize_devices(dip, dtap);
if (status == FAILURE) goto thread_exit;
if (dip->di_debug_flag || dip->di_tDebugFlag) {
Printf(dip, "Starting dtapp, Job %u, Thread %u, Thread ID "OS_TID_FMT"\n",
dip->di_job->ji_job_id, dip->di_thread_number, (os_tid_t)pthread_self());
}
/*
* This does all device setup and then opens each device.
*/
status = dtapp_setup_devices(dip, dtap);
if (status == FAILURE) goto thread_exit;
/* This is delayed to here since it needs the device type! */
(void)do_monitor_processing(master_dinfo, dip);
IterateAllDevices(dtap, dtapp_test_startup, NULL, rc);
while (True) {
PAUSE_THREAD(dip);
if ( THREAD_TERMINATING(dip) ) break;
if (dip->di_terminating) break;
/* Do some I/O here... */
status = dtapp_doio(dip);
break;
} /* end while(True) */
status = dtapp_close_devices(dip, dtap);
/*
* Triggers may bump the error count, but the status won't be failure.
*/
if (dip->di_error_count && (status != FAILURE) ) {
status = FAILURE;
}
if (dip->di_debug_flag || dip->di_tDebugFlag) {
Printf(dip, "I/O has completed, thread exiting with status %d...\n", status);
}
do_cleanup = True;
thread_exit:
status = dtapp_finish_test(dip, status, do_cleanup);
do_common_thread_exit(dip, status);
/*NOT REACHED*/
return(NULL);
}
/* Temp stuff to get us compiling! */
#define HANDLE_LOOP_ERROR(dip, error) \
if (error == FAILURE) { \
status = error; \
if ( THREAD_TERMINATING(dip) || \
(dip->di_error_count >= dip->di_error_limit) ) { \
break; \
} \
} else if (error == WARNING) { /* No more files! */ \
break; \
}
int
dtapp_doio(dinfo_t *dip)
{
dtapp_information_t *dtap = dip->di_opaque;
int rc, status = SUCCESS;
unsigned long error_count = 0;
while ( !THREAD_TERMINATING(dip) &&
(error_count < dip->di_error_limit) &&
((dip->di_pass_count < dip->di_pass_limit) || dip->di_runtime) ) {
IterateAllDevices(dtap, dtapp_prepass_processing, NULL, rc);
if (dip->di_output_file) { /* Write/read the file. */
rc = dtapp_dowritepass(dip);
HANDLE_LOOP_ERROR(dip, rc);
} else { /* Reading only. */
rc = dtapp_doreadpass(dip);
HANDLE_LOOP_ERROR(dip, rc);
} /* End of a pass! */
error_count = 0;
IterateAllDevices(dtap, dtapp_error_count, &error_count, rc);
}
return(status);
}
void
dtapp_do_prepass_processing(dinfo_t *dip)
{
/*
* This sets a pattern and/or the pattern buffer.
*/
initialize_pattern(dip);
if ( UseRandomSeed(dip) ) {
setup_random_seeds(dip);
}
/*
* Vary the I/O Type (if requested)
*/
if (dip->di_vary_iotype) {
switch (rand() % NUM_IOTYPES) {
case RANDOM_IO:
dip->di_io_type = RANDOM_IO;
dip->di_random_io = True;
break;
case SEQUENTIAL_IO:
dip->di_io_type = SEQUENTIAL_IO;
dip->di_random_io = False;
break;
}
}
if (dip->di_vary_iodir && (dip->di_io_type == SEQUENTIAL_IO) ) {
switch (rand() % NUM_IODIRS) {
case FORWARD:
dip->di_io_dir = FORWARD;
dip->di_random_io = False;
dip->di_io_type = SEQUENTIAL_IO;
break;
case REVERSE:
dip->di_io_dir = REVERSE;
dip->di_random_io = True;
dip->di_io_type = SEQUENTIAL_IO;
break;
}
}
return;
}
#define HANDLE_LOOP_ERROR_RETURN(dip, error) \
if (error == FAILURE) { \
status = error; \
if ( THREAD_TERMINATING(dip) || \
(dip->di_error_count >= dip->di_error_limit) ) { \
return(status); \
} \
} else if (error == WARNING) { /* No more files! */ \
return(status); \
}
int
dtapp_doreadpass(dinfo_t *dip)
{
dtapp_information_t *dtap = dip->di_opaque;
dtfuncs_t *dtf = dip->di_funcs;
int rc, status = SUCCESS;
unsigned long error_count = 0;
(void)IterateInputDevices(dtap, dtapp_start_read_pass, NULL);
/*
* Note: User must specify random seed to repeat previous write sequence!
*/
if ( dip->di_user_rseed && UseRandomSeed(dip) ) {
set_rseed(dip, dip->di_random_seed);
}
rc = (*dtf->tf_read_data)(dip);
if (rc == FAILURE) status = rc;
/*
* Prevent pass unless looping, since terminate reports
* the total statistics when called (prevents dup stats).
*/
if ( (dip->di_pass_limit > 1) || dip->di_runtime) {
stats_t stats_type = READ_STATS;
(void)IterateInputDevices(dtap, dtapp_pass_count, NULL);
(void)IterateInputDevices(dtap, dtapp_report_pass, &stats_type);
} else {
IterateAllDevices(dtap, dtapp_pass_count, NULL, rc);
}
if (dip->di_pass_cmd) {
rc = ExecutePassCmd(dip);
if (rc == FAILURE) {
status = rc;
dip->di_error_count++;
}
}
(void)IterateInputDevices(dtap, dtapp_error_count, &error_count);
/*
* End of a read pass, prepare for the next pass (if any).
*/
if ( (error_count < dip->di_error_limit) &&
((dip->di_pass_count < dip->di_pass_limit) || dip->di_runtime) ) {
rc = dtapp_close_devices(dip, dtap);
HANDLE_LOOP_ERROR_RETURN(dip, rc);
if (dip->di_bufmode_count) {
SetupBufferingMode(dip, &dip->di_initial_flags);
(void)IterateInputDevices(dtap, dtapp_set_open_flags, &dip->di_initial_flags);
}
rc = dtapp_open_devices(dip, dtap);
HANDLE_LOOP_ERROR_RETURN(dip, rc);
}
(void)IterateInputDevices(dtap, dtapp_end_pass, NULL);
return(status);
}
int
dtapp_dowritepass(dinfo_t *dip)
{
dtapp_information_t *dtap = dip->di_opaque;
dtfuncs_t *dtf = dip->di_funcs;
int rc, status = SUCCESS;
unsigned long error_count = 0;
hbool_t do_read_pass;
restart:
IterateAllDevices(dtap, dtapp_start_write_pass, NULL, rc);
rc = (*dtf->tf_write_data)(dip);
if (rc == FAILURE) status = rc;
rc = dtapp_flush_output_devices(dip, dtap);
if (rc == FAILURE) status = rc;
/* Note: This may go with multiple devices! */
/*
* Special handling of "file system full" conditions.
*/
if ( dip->di_fsfile_flag && dip->di_file_system_full ) {
rc = handle_file_system_full(dip, True);
if (rc == SUCCESS) {
init_stats(dip);
Wprintf(dip, "Restarting write pass after file system full detected!\n");
goto restart;
} else if (rc == FAILURE) {
status = rc;
}
/* Note: WARNING indicates we proceed with the read pass! */
}
IterateAllDevices(dtap, dtapp_error_count, &error_count, rc);
/*
* We finished the write pass, see if we should continue with read pass.
*/
if ( THREAD_TERMINATING(dip) || (error_count >= dip->di_error_limit) ) {
dtapp_report_write_stats(dip);
return(status);
}
/* Note: This may not be accurate, other devices may have been written. */
/* FYI: This was originally added to avoid reading nothing, and false errors! */
/* REVISIT this! */
do_read_pass = True;
//do_read_pass = (dip->di_dbytes_written != (large_t) 0);
/*
* Now verify (read and compare) the data just written.
*
* Note: This is *only* executed when doing a separate read pass!
*/
if ( dip->di_verify_flag && do_read_pass &&
( (dip->di_raw_flag == False) || (dip->di_raw_flag && dip->di_reread_flag)) ) {
stats_t stats_type;
dtapp_report_write_stats(dip);
rc = dtapp_close_devices(dip, dtap);
HANDLE_LOOP_ERROR_RETURN(dip, rc);
IterateAllDevices(dtap, dtapp_end_pass, NULL, rc);
dip->di_initial_flags = (dip->di_read_mode | dip->di_open_flags);
(void)IterateOutputDevices(dtap, dtapp_set_open_flags, &dip->di_initial_flags);
rc = dtapp_open_devices(dip, dtap);
HANDLE_LOOP_ERROR_RETURN(dip, rc);
/*
* Reset the random seed, so reads mimic what we wrote!
*/
if ( UseRandomSeed(dip) ) {
set_rseed(dip, dip->di_random_seed);
}
(void)IterateOutputDevices(dtap, dtapp_start_read_pass, NULL);
rc = (*dtf->tf_read_data)(dip);
if (rc == FAILURE) status = rc;
stats_type = READ_STATS;
IterateAllDevices(dtap, dtapp_pass_count, NULL, rc);
(void)IterateOutputDevices(dtap, dtapp_report_pass, &stats_type);
/* Nothing done with mirror devices on the read pass right now! */
} else { /* Writing only or read-after-write enabled! */
if ( (dip->di_pass_limit > 1) || dip->di_runtime) {
IterateAllDevices(dtap, dtapp_pass_count, NULL, rc);
dtapp_report_write_stats(dip);
} else {
IterateAllDevices(dtap, dtapp_pass_count, NULL, rc);
}
}
error_count = 0;
IterateAllDevices(dtap, dtapp_error_count, &error_count, rc);
/*
* Remember, a full pass is both the write/read cycle (legacy dt way).
*/
IterateAllDevices(dtap, dtapp_end_pass, NULL, rc);
if ( THREAD_TERMINATING(dip) || (error_count >= dip->di_error_limit) ) {
return(status);
}
/*
* Do post write processing to allow unmap or pass script.
*/
rc = IterateOutputDevices(dtap, dtapp_postwrite_processing, NULL);
if (rc == FAILURE) status = rc;
/*
* Don't reopen if we've reached the error limit or the pass count, since we'll
* be terminating shortly. Otherwise, prepare for the next write pass. (messy!)
*/
if ( ((dip->di_pass_count < dip->di_pass_limit) || dip->di_runtime) ) {
rc = dtapp_close_devices(dip, dtap);
HANDLE_LOOP_ERROR_RETURN(dip, rc);
if (dip->di_raw_flag == True) {
dip->di_initial_flags = (dip->di_rwopen_mode | dip->di_write_flags | dip->di_open_flags);
} else {
dip->di_initial_flags = (dip->di_write_mode | dip->di_write_flags | dip->di_open_flags);
}
SetupBufferingMode(dip, &dip->di_initial_flags);
rc = IterateOutputDevices(dtap, dtapp_set_open_flags, &dip->di_initial_flags);
rc = dtapp_open_devices(dip, dtap);
HANDLE_LOOP_ERROR_RETURN(dip, rc);
}
return(status);
}
void
dtapp_report_write_stats(dinfo_t *dip)
{
dtapp_information_t *dtap = dip->di_opaque;
stats_t stats_type;
if (dip->di_raw_flag) {
stats_type = RAW_STATS;
} else {
stats_type = WRITE_STATS;
}
(void)IterateOutputDevices(dtap, dtapp_report_pass, &stats_type);
if (dtap->dta_input_count) {
stats_type = MIRROR_STATS;
(void)IterateInputDevices(dtap, dtapp_report_pass, &stats_type);
}
return;
}
/*
* TODO: Loop over all devices for per device operations!
*/
int
dtapp_finish_test(dinfo_t *dip, int exit_code, hbool_t do_cleanup)
{
dtapp_information_t *dtap = dip->di_opaque;
int rc, status = SUCCESS;
/*
* Close file, which for AIO waits for outstanding I/O's,
* before reporting statistics so they'll be correct.
*/
if (dip && do_cleanup && (dip->di_fd != NoFd) ) {
dtapp_information_t *dtap = dip->di_opaque;
status = dtapp_close_devices(dip, dtap);
//status = (*dip->di_funcs->tf_close)(dip);
if (status == FAILURE) exit_code = status;
}
IterateAllDevices(dtap, dtapp_gather_stats, NULL, rc);
/*
* If keep on error, do the appropriate thing!
*/
if (dip->di_dispose_mode == KEEP_ON_ERROR) {
/* Note: Signals cause files to be kept! */
if ( (exit_code != SUCCESS) && (exit_code != END_OF_FILE) ) {
dip->di_dispose_mode = KEEP_FILE;
} else if (dip && (dip->di_existing_file == False)) {
dip->di_dispose_mode = DELETE_FILE;
}
}
IterateAllDevices(dtap, dtapp_test_complete, &do_cleanup, rc);
if (rc == FAILURE) exit_code = rc;
if ( (dip->di_eof_status_flag == False) && (exit_code == END_OF_FILE) ) {
exit_code = SUCCESS; /* Map end-of-file status to Success! */
}
dtapp_finish_test_common(dip, exit_code);
if (exit_code == WARNING) {
exit_code = SUCCESS; /* Map warning errors to Success! */
}
/*
* Map signal numbers and/or other errno's to FAILURE. (cleanup)
* ( easier for scripts to handle! )
*/
if ( (exit_code != FAILURE) && (exit_code != SUCCESS) && (exit_code != END_OF_FILE) ) {
exit_code = FAILURE; /* Usually a signal number. */
}
return(exit_code);
}
void
dtapp_finish_test_common(dinfo_t *dip, int thread_status)
{
if (dip->di_syslog_flag) {
SystemLog(dip, LOG_INFO, "Finished: %s", dip->di_cmd_line);
}
/*
* If thread status is FAILURE, log the command line.
* Also log to thread log when log trailer flag enabled.
*/
if ( (thread_status == FAILURE) || dip->di_logtrailer_flag ) {
log_header(dip, True);
}
#if defined(NETAPP)
if (dip->di_debug_flag || dip->di_pDebugFlag || dip->di_tDebugFlag || dip->di_nate_flag) {
Printf (dip, "Thread exiting with status %d...\n", thread_status);
}
if (dip->di_nate_flag) {
report_nate_results(dip, thread_status);
}
#else /* !defined(NETAPP) */
if (dip->di_debug_flag || dip->di_pDebugFlag || dip->di_tDebugFlag) {
Printf (dip, "Thread exiting with status %d...\n", thread_status);
}
#endif /* defined(NETAPP) */
return;
}
/*
* Note: We only get called for the first device entry for each thread.
* Therefore, this function must cleanup the other list of devices setup.
* But that said, we do not free the primary device, since the common cleanup
* logic will do this, and we must avoid duplicate freeing.
*/
void
dtapp_cleanup_information(dinfo_t *dip)
{
dtapp_information_t *dtap;
if ( (dtap = dip->di_opaque) == NULL) {
return;
}
if (dtap->dta_input_count) {
dtapp_free_devices(dip, dtap->dta_input_devices, dtap->dta_input_count);
dtap->dta_input_devices = NULL;
if ( (dtap->dta_primary_type == INPUT_FILE) && (dip == dtap->dta_primary_dip) ) {
if (dtap->dta_input_dips) {
dtap->dta_input_dips[0] = NULL; /* Caller will free this dip! */
}
}
dtapp_free_dips(dip, dtap->dta_input_dips, dtap->dta_input_count);
dtap->dta_input_dips = NULL;
dtap->dta_input_count = 0;
}
if (dtap->dta_output_count) {
dtapp_free_devices(dip, dtap->dta_output_devices, dtap->dta_output_count);
dtap->dta_output_devices = NULL;
if ( (dtap->dta_primary_type == OUTPUT_FILE) && (dip == dtap->dta_primary_dip) ) {
if (dtap->dta_output_dips) {
dtap->dta_output_dips[0] = NULL; /* Caller will free this dip! */
}
}
dtapp_free_dips(dip, dtap->dta_output_dips, dtap->dta_output_count);
dtap->dta_output_dips = NULL;
dtap->dta_output_count = 0;
}
if (dtap->dta_write_orders) {
Free(dip, dtap->dta_write_orders);
dtap->dta_write_orders = NULL;
dtap->dta_last_write_order = NULL;
}
FreeMem(dip, dtap, sizeof(*dtap));
dip->di_opaque = NULL;
return;
}
void
dtapp_free_devices(dinfo_t *dip, char **device_list, int num_devices)
{
int device;
if (num_devices == 0) return;
for (device = 0; (device < num_devices); device++) {
FreeStr(dip, device_list[device]);
device_list[device] = NULL;
}
Free(dip, device_list);
return;
}
void
dtapp_free_dips(dinfo_t *dip, dinfo_t **dips, int num_devices)
{
int device;
if (num_devices == 0) return;
if (dips == NULL) return;
for (device = 0; (device < num_devices); device++) {
dinfo_t *cdip;
/* Free the device information we created. */
if (cdip = dips[device]) {
cdip->di_opaque = NULL; /* Avoid recursion. */
cdip->di_log_opened = False; /* Master will close log file! */
cleanup_device(cdip, False);
FreeMem(dip, cdip, sizeof(*cdip));
dips[device] = NULL;
}
}
Free(dip, dips);
return;
}
/*
* We are called each time a device is cloned, to duplicate per device/thread
* information. The new contect flag is set when new threads are executed, so
* for this I/O behavior, it lets us know we need a new device list context.
*/
int
dtapp_clone_information(dinfo_t *dip, dinfo_t *cdip, hbool_t new_context)
{
/*
* Each thread needs its' own copy of the per thread information.
* Each device within a thread share the primary device information!
*/
if (new_context == True) {
dtapp_information_t *dtap = dip->di_opaque;
dtapp_information_t *cdtap; /* clone */
cdtap = Malloc(dip, sizeof(*cdtap));
if (cdtap == NULL) return(FAILURE);
cdip->di_opaque = cdtap;
*cdtap = *dtap;
cdtap->dta_primary_dip = cdip;
if (dtap->dta_input_count) {
cdtap->dta_input_devices = dtapp_clone_devices(dip, dtap->dta_input_devices, dtap->dta_input_count);
}
if (dtap->dta_output_count) {
cdtap->dta_output_devices = dtapp_clone_devices(dip, dtap->dta_output_devices, dtap->dta_output_count);
}
/* TODO: Clone all per thread allocated data! */
}
return(SUCCESS);
}
char **
dtapp_clone_devices(dinfo_t *dip, char **device_list, int num_devices)
{
int device;
char **cdevice_list;
if (num_devices == 0) return(NULL);
cdevice_list = Malloc(dip, sizeof(char **) * num_devices);
if (cdevice_list == NULL) return(NULL);
for (device = 0; (device < num_devices); device++) {
cdevice_list[device] = strdup(device_list[device]);
}
return(cdevice_list);
}
dinfo_t **
dtapp_clone_dips(dinfo_t *dip, dinfo_t **dips, int num_devices)
{
int device;
dinfo_t **cdips;
if (num_devices == 0) return(NULL);
cdips = Malloc(dip, sizeof(dinfo_t **) * num_devices);
if (cdips == NULL) return(NULL);
for (device = 0; (device < num_devices); device++) {
cdips[device] = dips[device];
}
return(cdips);
}
int
dtapp_initialize(dinfo_t *dip)
{
dtapp_information_t *dtap;
dtap = Malloc(dip, sizeof(*dtap));
if (dtap == NULL) return(FAILURE);
dip->di_opaque = dtap;
dip->di_btag_flag = True;