-
Notifications
You must be signed in to change notification settings - Fork 4
/
parse.c
1036 lines (1021 loc) · 34.1 KB
/
parse.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
/*
* Disktest
* Copyright (c) International Business Machines Corp., 2001
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Please send e-mail to yardleyb@us.ibm.com if you have
* questions or comments.
*
* Project Website: TBD
*
* $Id: parse.c,v 1.30.2.1 2009/01/21 00:53:26 yardleyb Exp $
*
*/
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <signal.h>
#include <time.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include "globals.h"
#include "threading.h"
#include "main.h"
#include "usage.h"
#include "sfunc.h"
#include "parse.h"
int fill_cld_args(int argc, char **argv, child_args_t *args)
{
extern char *optarg;
extern int optind;
extern unsigned long glb_flags;
signed char c;
char *leftovers;
while((c = getopt(argc, argv, "?a:A:B:cC:dD:E:f:Fh:I:K:L:m:M:nN:o:p:P:qQrR:s:S:t:T:wvV:z")) != -1) {
switch(c) {
case ':' :
pMsg(WARN, args, "Missing argument for perameter.\n");
usage();
return(-1);
case 'V' :
#ifdef _DEBUG
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
exit(1);
}
if(!isdigit(optarg[0])) {
pMsg(WARN, args, "-%c argument is non numeric.\n", c);
exit(1);
}
gbl_dbg_lvl = atoi(optarg);
#else
pMsg(ERR, args, "Debug code not compiled in, recompile with _DEBUG directive.\n", c);
exit(1);
#endif
break;
case 'd' :
glb_flags |= GLB_FLG_QUIET;
args->flags |= CLD_FLG_DUMP;
break;
case 'a' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(!isdigit(optarg[0])) {
pMsg(WARN, args, "-%c arguments is non numeric.\n", c);
return(-1);
}
args->seed = (unsigned int) strtol(optarg, NULL, 0);
break;
case 'A' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
exit(1);
}
if (strchr(optarg,'g')) {
glb_flags |= GLB_FLG_KILL;
}
if (strchr(optarg,'c')) {
args->flags &= ~CLD_FLG_ALLDIE;
}
if (strchr(optarg,'m')) {
args->flags |= CLD_FLG_ERR_MARK;
}
if (strchr(optarg,'r')) {
args->flags &= ~CLD_FLG_ERR_REREAD;
}
if (strchr(optarg,'s')) {
args->flags &= ~CLD_FLG_LBA_SYNC;
}
if (strchr(optarg,'S')) {
args->flags |= CLD_FLG_IO_SERIAL;
}
if (strchr(optarg,'w')) {
args->flags |= CLD_FLG_WRITE_ONCE;
}
if (strchr(optarg,'W')) {
args->flags |= CLD_FLG_UNIQ_WRT;
}
if (strchr(optarg,'t')) {
args->flags |= CLD_FLG_TMO_ERROR;
}
break;
case 'q' :
glb_flags |= GLB_FLG_QUIET;
break;
case 'Q' :
glb_flags |= GLB_FLG_SUPRESS;
break;
case 'v' :
pMsg(INFO, args, "Version %s\n", VER_STR);
exit(0);
case 'p' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(args->flags & (CLD_FLG_LINEAR|CLD_FLG_RANDOM)) {
pMsg(WARN, args, "Only one seek type, -p, can be specified.\n");
return(-1);
}
/* seek pattern type */
if (strchr(optarg,'L'))
args->flags |= CLD_FLG_LINEAR;
else if (strchr(optarg,'l'))
args->flags |= (CLD_FLG_LINEAR|CLD_FLG_NTRLVD);
else if (strchr(optarg,'R'))
args->flags |= CLD_FLG_RANDOM;
else if (strchr(optarg,'r'))
args->flags |= (CLD_FLG_RANDOM|CLD_FLG_NTRLVD);
else if (strchr(optarg,'S') || strchr(optarg,'s'))
args->flags |= CLD_FLG_SWEEP;
else {
pMsg(WARN, args, "Unknown Seek pattern\n");
usage();
return(-1);
}
if (strchr(optarg,'U') || strchr(optarg,'u'))
if((args->flags & (CLD_FLG_LINEAR)) &&
!(args->flags & CLD_FLG_LUND))
args->flags |= CLD_FLG_LUNU;
if (strchr(optarg,'D') || strchr(optarg,'d'))
if((args->flags & (CLD_FLG_LINEAR)) &&
!(args->flags & CLD_FLG_LUNU))
args->flags |= CLD_FLG_LUND;
break;
case 'B' :
if(!isdigit(optarg[0])) {
pMsg(WARN, args, "-%c arguments is non numeric. %c:\n", c, optarg[0]);
return(-1);
}
if(strchr(optarg,':') != NULL) { /* we are given a range of transfer sizes */
args->flags |= CLD_FLG_RTRSIZ;
args->ltrsiz = strtoul(optarg, &leftovers, 10);
if(leftovers == strchr(leftovers,'k')) { /* first value had a 'k' */
args->ltrsiz *= 2;
leftovers++;
} else if(leftovers == strchr(leftovers, 'm')) { /* first value had a 'm' */
args->ltrsiz *= (2 * 1024);
leftovers++;
} else if(leftovers == strchr(leftovers, 'l')) { /* first value had a 'l', lba override */
leftovers++;
} else {
if (args->ltrsiz > 256)
args->ltrsiz /= BLK_SIZE;
}
if(!isdigit(leftovers[1])) {
pMsg(WARN, args, "-%c arguments is non numeric. %c:\n", c, leftovers[1]);
pMsg(WARN, args, "-%c arguments is non numeric.\n", c);
return(-1);
}
args->htrsiz = atol((char *)strchr(leftovers,':')+1);
if((strchr(leftovers,'k')) != NULL) {/* second value had a 'k' */
args->htrsiz *= 2;
} else if((strchr(leftovers,'m')) != NULL) { /* second value had a 'm' */
args->htrsiz *= (2 * 1024);
} else if((strchr(leftovers,'l')) != NULL) { /* second value had a 'l' */
} else {
if (args->htrsiz > 256)
args->htrsiz /= BLK_SIZE;
}
} else { /* only a single value given for transfer size */
args->ltrsiz = atoi(optarg);
if(strchr(optarg,'k')) {
args->ltrsiz *= 2;
} else if(strchr(optarg,'m')) {
args->ltrsiz *= (2 * 1024);
} else if(strchr(optarg,'l')) {
} else {
if (args->ltrsiz > 256)
args->ltrsiz /= BLK_SIZE;
}
args->htrsiz = args->ltrsiz;
}
#ifdef _DEBUG
PDBG5(DBUG, args, "Parsed Transfer size: %ld\n", args->htrsiz);
#endif
break;
case 'c' :
if(args->flags & CLD_FLG_PTYPS) {
pMsg(WARN, args, "Please specify only one pattern type\n");
usage();
return(-1);
}
args->flags |= CLD_FLG_CPTYPE;
break;
case 'n' :
if(args->flags & CLD_FLG_PTYPS) {
pMsg(WARN, args, "Please specify only one pattern type\n");
usage();
return(-1);
}
args->flags |= CLD_FLG_LPTYPE;
break;
case 'f' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(args->flags & CLD_FLG_PTYPS) {
pMsg(WARN, args, "Please specify only one pattern type\n");
usage();
return(-1);
}
args->pattern = my_strtofft(optarg);
args->flags |= CLD_FLG_FPTYPE;
break;
case 'F' :
/* the filespec is a list of filespecs in a file */
args->flags |= CLD_FLG_FSLIST;
break;
case 'z' :
if(args->flags & CLD_FLG_PTYPS) {
pMsg(WARN, args, "Please specify only one pattern type\n");
usage();
return(-1);
}
args->flags |= CLD_FLG_RPTYPE;
break;
case 'h' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(!isdigit(optarg[0])) {
pMsg(WARN, args, "-%c arguments is non numeric.\n", c);
usage();
return(-1);
}
args->flags |= CLD_FLG_HBEAT;
args->hbeat = atoi(optarg);
if(strchr(optarg,'m')) { /* multiply by sec */
args->hbeat *= 60;
} else if(strchr(optarg,'h')) { /* multiply sec*min */
args->hbeat *= (time_t) (60*60);
} else if(strchr(optarg,'d')) { /* multiply by sec*min*hours */
args->hbeat *= (time_t) (60*60*24);
}
break;
case 'D' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(!isdigit(optarg[0])) {
pMsg(WARN, args, "-%c arguments is non numeric.\n", c);
usage();
return(-1);
}
args->rperc = atoi(optarg);
args->wperc = atoi((char *)(strchr(optarg,':')+1));
args->flags |= CLD_FLG_DUTY;
break;
case 'r' :
args->flags |= CLD_FLG_R;
break;
case 'w' :
args->flags |= CLD_FLG_W;
break;
case 'o' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
args->offset = atol(optarg);
args->flags |= CLD_FLG_OFFSET;
break;
case 'R' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(strchr(optarg,':') != NULL) { /* we are given a retry delay */
args->retries = strtol(optarg, &leftovers, 10);
args->retry_delay = (time_t) atol((char *)strchr(leftovers,':')+1);
} else { /* only a retry count given */
args->retries = atoi(optarg);
}
break;
case 'M' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
args->flags |= CLD_FLG_ALT_MARK;
args->alt_mark = my_strtofft(optarg);
break;
case 'm' :
args->flags |= CLD_FLG_MBLK;
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if (strchr(optarg,'l')) { /* returns NULL if char is not found */
args->flags |= CLD_FLG_MRK_LBA;
}
if (strchr(optarg,'p')) {
args->flags |= CLD_FLG_MRK_PASS;
}
if (strchr(optarg,'t')) {
args->flags |= CLD_FLG_MRK_TIME;
}
if (strchr(optarg,'s')) {
args->flags |= CLD_FLG_MRK_SEED;
}
if (strchr(optarg,'h')) {
args->flags |= CLD_FLG_MRK_HOST;
}
if (strchr(optarg,'f')) {
args->flags |= CLD_FLG_MRK_TARGET;
}
if (strchr(optarg,'a')) {
args->flags |= CLD_FLG_MRK_ALL;
}
if (!strchr(optarg,'l') &&
!strchr(optarg,'p') &&
!strchr(optarg,'t') &&
!strchr(optarg,'s') &&
!strchr(optarg,'h') &&
!strchr(optarg,'f') &&
!strchr(optarg,'a')) {
pMsg(WARN, args, "Unknown header mark option\n");
return(-1);
}
break;
case 'E' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(!isdigit(optarg[0])) {
pMsg(WARN, args, "-%c arguments are non numeric.\n", c);
usage();
return(-1);
}
args->flags |= CLD_FLG_CMPR;
args->cmp_lng = strtol(optarg,NULL,0);
if(strchr(optarg,'k')) { /* multiply by 2^10 */
args->cmp_lng <<= 10;
} else if(strchr(optarg,'K')) { /* multiply 10^3 */
args->cmp_lng *= 1000;
} else if(strchr(optarg,'m')) { /* multiply by 2^20 */
args->cmp_lng <<= 20;
} else if(strchr(optarg,'M')) { /* multiply by 10^6 */
args->cmp_lng *= 1000000;
}
break;
case 'N' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(!isdigit(optarg[0])) {
pMsg(WARN, args, "-%c arguments are non numeric.\n", c);
return(-1);
}
args->flags |= CLD_FLG_VSIZ;
args->vsiz = my_strtofft(optarg);
if(strchr(optarg,'k')) { /* multiply by 2^10 */
args->vsiz <<= 10;
} else if(strchr(optarg,'K')) { /* multiply 10^3 */
args->vsiz *= 1000;
} else if(strchr(optarg,'m')) { /* multiply by 2^20 */
args->vsiz <<= 20;
} else if(strchr(optarg,'M')) { /* multiply by 10^6 */
args->vsiz *= 1000000;
} else if(strchr(optarg,'g')) { /* multiply by 2^30 */
args->vsiz <<= 30;
} else if(strchr(optarg,'G')) { /* multiply by 10^9 */
args->vsiz *= 1000000000;
}
break;
case 'I' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if (strchr(optarg,'R') || strchr(optarg,'r')) {
if (!(args->flags & CLD_FLG_BLK) &&
!(args->flags & CLD_FLG_FILE)) {
args->flags |= CLD_FLG_RAW;
} else {
pMsg(WARN, args, "Can only specify one IO type\n");
return(-1);
}
}
if (strchr(optarg,'B') || strchr(optarg,'b')) {
if (!(args->flags & CLD_FLG_RAW) &&
!(args->flags & CLD_FLG_FILE)) {
args->flags |= CLD_FLG_BLK;
} else {
pMsg(WARN, args, "Can only specify one IO type\n");
return(-1);
}
}
if (strchr(optarg,'F') || strchr(optarg,'f')) {
if (!(args->flags & CLD_FLG_RAW) &&
!(args->flags & CLD_FLG_BLK)) {
args->flags |= CLD_FLG_FILE;
} else {
pMsg(WARN, args, "Can only specify one IO type\n");
return(-1);
}
}
if (strchr(optarg,'D') || strchr(optarg,'d')) {
args->flags |= CLD_FLG_DIRECT;
}
if (strchr(optarg,'s')) {
args->sync_interval = strtoul((char *)strchr(optarg,'s')+1, NULL, 10);
#ifdef _DEBUG
PDBG3(DBUG, args, "Parsed sync interval: %ld\n", args->sync_interval);
#endif
if((args->flags & CLD_FLG_DIRECT)) {
pMsg(ERR, args, "Can't specify sync with Direct IO\n");
return(-1);
}
args->flags |= CLD_FLG_WFSYNC;
}
break;
case 't' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(strchr(optarg,':') != NULL) { /* we are given a option for delay & timeout */
args->delayTimeMin = strtoul(optarg, &leftovers, 10);
/* check to see if we have one or more then one ':' */
if((char *)strchr(optarg,':') == (char *)strrchr(optarg,':')) {
/* only one ':', assume no random delayTime, and ioTimeout */
args->delayTimeMax = args->delayTimeMin;
args->ioTimeout = (time_t) atol((char *)strchr(leftovers,':')+1);
} else {
/* more then one ':', assume random delayTime, and ioTimeout */
args->delayTimeMax = strtoul(leftovers+1, &leftovers, 10);
args->ioTimeout = (time_t) atol((char *)strchr(leftovers,':')+1);
}
if(strchr(leftovers,'m')) { /* multiply by sec */
args->ioTimeout *= 60;
} else if(strchr(leftovers,'h')) { /* multiply sec*min */
args->ioTimeout *= (time_t) (60*60);
} else if(strchr(leftovers,'d')) { /* multiply by sec*min*hours */
args->ioTimeout *= (time_t) (60*60*24);
}
} else {
args->delayTimeMin = strtoul(optarg, (char **)NULL, 10);
args->delayTimeMax = args->delayTimeMin;
}
break;
case 'T' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
args->run_time = atoi(optarg);
args->flags |= CLD_FLG_TMD;
if(strchr(optarg,'m')) { /* multiply by sec */
args->run_time *= 60;
} else if(strchr(optarg,'h')) { /* multiply sec*min */
args->run_time *= (time_t) (60*60);
} else if(strchr(optarg,'d')) { /* multiply by sec*min*hours */
args->run_time *= (time_t) (60*60*24);
}
break;
case 'L' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
args->seeks = atoi(optarg);
args->flags |= CLD_FLG_SKS;
if(strchr(optarg,'k')) { /* multiply by 2^10 */
args->seeks <<= 10;
} else if(strchr(optarg,'K')) { /* multiply 10^3 */
args->seeks *= 1000;
} else if(strchr(optarg,'m')) { /* multiply by 2^20 */
args->seeks <<= 20;
} else if(strchr(optarg,'M')) { /* multiply by 10^6 */
args->seeks *= 1000000;
} else if(strchr(optarg,'g')) { /* multiply by 2^30 */
args->seeks <<= 30;
} else if(strchr(optarg,'G')) { /* multiply by 10^9 */
args->seeks *= 1000000000;
}
break;
case 'C' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(!isdigit(optarg[0])) {
pMsg(WARN, args, "-%c arguments is non numeric.\n", c);
usage();
return(-1);
}
args->flags |= CLD_FLG_CYC;
args->cycles = atol(optarg);
break;
case 'K' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if(!isdigit(optarg[0])) {
pMsg(WARN, args, "-%c arguments is non numeric.\n", c);
usage();
return(-1);
}
if(atoi(optarg) > MAX_THREADS) {
pMsg(WARN, args, "%u exceeds max of %u threads.\n", atoi(optarg), MAX_THREADS);
return(-1);
}
args->t_kids = atoi(optarg);
break;
case 'P' :
if(optarg == NULL) {
pMsg(WARN, args, "-%c option requires an argument.\n", c);
return(-1);
}
if (strchr(optarg,'X')) { /* returns NULL if char is not found */
args->flags |= CLD_FLG_XFERS;
}
if (strchr(optarg,'T')) {
args->flags |= CLD_FLG_TPUTS;
}
if (strchr(optarg,'P')) {
glb_flags |= GLB_FLG_PERFP;
}
if (strchr(optarg,'R')) {
args->flags |= CLD_FLG_RUNT;
}
if (strchr(optarg,'C')) {
args->flags |= CLD_FLG_PCYC;
}
if (strchr(optarg,'A')) {
args->flags |= CLD_FLG_PRFTYPS;
}
if (!strchr(optarg,'P') &&
!strchr(optarg,'A') &&
!strchr(optarg,'X') &&
!strchr(optarg,'R') &&
!strchr(optarg,'C') &&
!strchr(optarg,'T')) {
pMsg(WARN, args, "Unknown performance option\n");
return(-1);
}
break;
case 'S' :
if(!isdigit((int)optarg[0])) {
pMsg(WARN, args, "-%c arguments is non numeric.\n", c);
return(-1);
}
args->flags |= CLD_FLG_BLK_RNG;
if(strchr(optarg,':') != NULL) { /* we are given a range */
args->start_blk = (OFF_T) strtoul(optarg, &leftovers, 0);
if(leftovers == strchr(leftovers,'k')) { /* multiply by 2^10 */
args->start_blk <<= 10;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'K')) { /* multiply 10^3 */
args->start_blk *= 1000;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'m')) { /* multiply by 2^20 */
args->start_blk <<= 20;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'M')) { /* multiply by 10^6 */
args->start_blk *= 1000000;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'g')) { /* multiply by 2^30 */
args->start_blk <<= 30;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'G')) { /* multiply by 10^9 */
args->start_blk *= 1000000000;
leftovers++; /* at the ':' */
}
leftovers++; /* should be at the next value */
if(!isdigit((int) leftovers[0])) {
pMsg(WARN, args, "-%c arguments is non numeric.\n", c);
return(-1);
}
args->stop_blk = (OFF_T) strtoul(leftovers, &leftovers, 0);
if(leftovers == strchr(leftovers,'k')) { /* multiply by 2^10 */
args->stop_blk <<= 10;
} else if(leftovers == strchr(leftovers,'K')) { /* multiply 10^3 */
args->stop_blk *= 1000;
} else if(leftovers == strchr(leftovers,'m')) { /* multiply by 2^20 */
args->stop_blk <<= 20;
} else if(leftovers == strchr(leftovers,'M')) { /* multiply by 10^6 */
args->stop_blk *= 1000000;
} else if(leftovers == strchr(leftovers,'g')) { /* multiply by 2^30 */
args->stop_blk <<= 30;
} else if(leftovers == strchr(leftovers,'G')) { /* multiply by 10^9 */
args->stop_blk *= 1000000000;
}
} else { /* only a single value given */
args->start_blk = (OFF_T) strtoul(optarg, &leftovers, 0);
if(leftovers == strchr(leftovers,'k')) { /* multiply by 2^10 */
args->start_blk <<= 10;
} else if(leftovers == strchr(leftovers,'K')) { /* multiply 10^3 */
args->start_blk *= 1000;
} else if(leftovers == strchr(leftovers,'m')) { /* multiply by 2^20 */
args->start_blk <<= 20;
} else if(leftovers == strchr(leftovers,'M')) { /* multiply by 10^6 */
args->start_blk *= 1000000;
} else if(leftovers == strchr(leftovers,'g')) { /* multiply by 2^30 */
args->start_blk <<= 30;
} else if(leftovers == strchr(leftovers,'G')) { /* multiply by 10^9 */
args->start_blk *= 1000000000;
}
}
break;
case 's' :
if(!isdigit((int)optarg[0])) {
pMsg(WARN, args, "-%c argument is non numeric.\n", c);
return(-1);
}
args->flags |= CLD_FLG_LBA_RNG;
if(strchr(optarg,':') != NULL) { /* we are given a range */
args->start_lba = (OFF_T) strtoul(optarg, &leftovers, 0);
if(leftovers == strchr(leftovers,'k')) { /* multiply by 2^10 */
args->start_lba <<= 10;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'K')) { /* multiply 10^3 */
args->start_lba *= 1000;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'m')) { /* multiply by 2^20 */
args->start_lba <<= 20;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'M')) { /* multiply by 10^6 */
args->start_lba *= 1000000;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'g')) { /* multiply by 2^30 */
args->start_lba <<= 30;
leftovers++; /* at the ':' */
} else if(leftovers == strchr(leftovers,'G')) { /* multiply by 10^9 */
args->start_lba *= 1000000000;
leftovers++; /* at the ':' */
}
leftovers++; /* should be at the next value */
if(!isdigit((int) leftovers[0])) {
pMsg(WARN, args, "-%c second argument is non numeric.\n", c);
return(-1);
}
args->stop_lba = (OFF_T) strtoul(leftovers, &leftovers, 0);
if(leftovers == strchr(leftovers,'k')) { /* multiply by 2^10 */
args->stop_lba <<= 10;
} else if(leftovers == strchr(leftovers,'K')) { /* multiply 10^3 */
args->stop_lba *= 1000;
} else if(leftovers == strchr(leftovers,'m')) { /* multiply by 2^20 */
args->stop_lba <<= 20;
} else if(leftovers == strchr(leftovers,'M')) { /* multiply by 10^6 */
args->stop_lba *= 1000000;
} else if(leftovers == strchr(leftovers,'g')) { /* multiply by 2^30 */
args->stop_lba <<= 30;
} else if(leftovers == strchr(leftovers,'G')) { /* multiply by 10^9 */
args->stop_lba *= 1000000000;
}
} else { /* only a single value given */
args->start_lba = (OFF_T) strtoul(optarg, &leftovers, 0);
if(leftovers == strchr(leftovers,'k')) { /* multiply by 2^10 */
args->start_lba <<= 10;
} else if(leftovers == strchr(leftovers,'K')) { /* multiply 10^3 */
args->start_lba *= 1000;
} else if(leftovers == strchr(leftovers,'m')) { /* multiply by 2^20 */
args->start_lba <<= 20;
} else if(leftovers == strchr(leftovers,'M')) { /* multiply by 10^6 */
args->start_lba *= 1000000;
} else if(leftovers == strchr(leftovers,'g')) { /* multiply by 2^30 */
args->start_lba <<= 30;
} else if(leftovers == strchr(leftovers,'G')) { /* multiply by 10^9 */
args->start_lba *= 1000000000;
}
}
break;
case '?' :
default :
usage();
return(-1);
}
}
if(argv[optind] == NULL) {
pMsg(ERR, args, "Unspecified target.\n");
return(-1);
}
strncpy(args->device, argv[optind], (DEV_NAME_LEN-1));
return(0);
}
int make_assumptions(child_args_t *args)
{
char TmpStr[80];
struct stat stat_buf;
int rv;
if(!(args->flags & CLD_FLG_IOTYPS)) {
/* use stat to get file properties, and use to set -I */
rv = stat(args->device, &stat_buf);
if(0 == rv) {
if(IS_FILE(stat_buf.st_mode) ) {
strncat(args->argstr, "(-I f) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
args->flags |= CLD_FLG_FILE;
} else if(IS_BLK(stat_buf.st_mode)) {
strncat(args->argstr, "(-I b) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
args->flags |= CLD_FLG_BLK;
#ifndef WINDOWS
} else if(S_ISCHR(stat_buf.st_mode)) {
strncat(args->argstr, "(-I r) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
args->flags |= CLD_FLG_RAW;
#endif
}
} else {
pMsg(WARN, args, "Can't get status on %s, defaulting to file, errno = %d\n", args->device, GETLASTERROR());
strncat(args->argstr, "(-I f) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
args->flags |= CLD_FLG_FILE;
}
}
if((args->flags & CLD_FLG_WFSYNC) && (0 == args->sync_interval)) {
pMsg(INFO, args, "Sync interval set to zero, assuming interval of 1.\n");
args->sync_interval = 1;
}
if(args->ltrsiz <= 0) {
sprintf(TmpStr, "(-B %d) ", TRSIZ*BLK_SIZE);
strncat(args->argstr, TmpStr, (MAX_ARG_LEN-1)-strlen(args->argstr));
args->ltrsiz=TRSIZ;
args->htrsiz=TRSIZ;
}
if(args->flags & CLD_FLG_LBA_RNG) {
args->start_blk = args->start_lba / args->htrsiz;
if(!(args->stop_lba < 0))
args->stop_blk = args->stop_lba / args->htrsiz;
}
if(args->flags & CLD_FLG_BLK_RNG) {
args->start_lba = args->start_blk * args->htrsiz;
if(!(args->stop_blk < 0))
args->stop_lba = (args->stop_blk * args->htrsiz) + (args->htrsiz - 1);
}
/* if vsiz is still not set, try and get it from the file */
if((args->vsiz <=0) && (args->flags & CLD_FLG_FILE)) {
if(0 != get_file_size(args->device)) { /* file size retrieved */
args->vsiz=get_file_size(args->device);
}
}
/* if vsiz is still not set, try and get it from the device */
if((args->vsiz <= 0) && !(args->flags & CLD_FLG_FILE)) {
args->vsiz=get_vsiz(args->device);
}
/* if vsiz is still not set, set based on given range */
if((args->vsiz <=0) && (args->flags & (CLD_FLG_LBA_RNG|CLD_FLG_BLK_RNG))) {
if(!(args->stop_lba < 0))
args->vsiz=args->stop_lba+1;
else
args->vsiz=args->start_lba+1;
}
/* if vsiz is still not set, then set it to the default size */
if(args->vsiz <= 0) {
args->vsiz=VSIZ;
}
if(!(args->flags & CLD_FLG_VSIZ)) {
sprintf(TmpStr, N_ASSUME, args->vsiz);
strncat(args->argstr, TmpStr, (MAX_ARG_LEN-1)-strlen(args->argstr));
}
if(args->stop_lba == -1) {
args->stop_lba=args->vsiz-1;
}
if(args->stop_blk == -1) {
args->stop_blk=(args->stop_lba / (OFF_T) args->htrsiz);
}
/* If doing sweep test, force threads to 1 */
if(args->flags & CLD_FLG_SWEEP) {
sprintf(TmpStr, "(-K 1) ");
strncat(args->argstr, TmpStr, (MAX_ARG_LEN-1)-strlen(args->argstr));
args->t_kids=1;
}
if(args->t_kids == 0) {
sprintf(TmpStr, "(-K %d) ", KIDS);
strncat(args->argstr, TmpStr, (MAX_ARG_LEN-1)-strlen(args->argstr));
args->t_kids=KIDS;
}
if((args->flags & (CLD_FLG_W|CLD_FLG_R)) == 0) {
if(args->flags & CLD_FLG_DUTY) { /* no read/write but duty cycle specified */
if(args->rperc > 0) {
args->flags |= CLD_FLG_R;
strncat(args->argstr, "(-r) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
}
if(args->wperc > 0) {
args->flags |= CLD_FLG_W;
strncat(args->argstr, "(-w) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
}
} else {
strncat(args->argstr, "(-r) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
args->flags |= CLD_FLG_R;
}
}
if(!(args->flags & CLD_FLG_PTYPS)) {
strncat(args->argstr, "(-c) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
args->flags |= CLD_FLG_CPTYPE;
}
if(!(args->flags & CLD_FLG_SKTYPS)) {
strncat(args->argstr, "(-p R) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
args->flags |= CLD_FLG_RANDOM;
}
if(!(args->flags & CLD_FLG_SKS)) {
if(args->start_blk == args->stop_blk) { /* diskcache test, w/ no seek count set */
args->seeks = SEEKS;
} else if(args->flags & (CLD_FLG_BLK_RNG|CLD_FLG_LBA_RNG)) { /* range set, w/ no seek count */
args->seeks = args->stop_blk - args->start_blk + 1;
} else {
/* if vsiz is available, calculated seeks are in terms of the largest transfer size */
args->seeks = (args->vsiz > 0) ? (args->vsiz / args->htrsiz) : SEEKS;
}
if((args->flags & CLD_FLG_LINEAR) && (args->flags & CLD_FLG_R) && (args->flags & CLD_FLG_W)) {
args->seeks *= 2;
}
if(!(args->flags & CLD_FLG_TMD)) {
sprintf(TmpStr, L_ASSUME, args->seeks);
strncat(args->argstr, TmpStr, (MAX_ARG_LEN-1)-strlen(args->argstr));
}
}
if(!(args->flags & (CLD_FLG_SKS|CLD_FLG_TMD)) || ((args->flags & CLD_FLG_CYC) && !(args->flags & (CLD_FLG_SKS|CLD_FLG_TMD)))) {
args->flags |= CLD_FLG_SKS;
}
if(args->flags & (CLD_FLG_LINEAR)) {
if(!(args->flags & (CLD_FLG_LUNU|CLD_FLG_LUND))) {
strncat(args->argstr, "(-p u) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
args->flags |= CLD_FLG_LUNU;
}
}
normalize_percs(args);
if(!(args->flags & CLD_FLG_DUTY) && (args->flags & CLD_FLG_RANDOM) && !(args->flags & CLD_FLG_NTRLVD)) {
sprintf(TmpStr, "(-D %d:%d) ", args->rperc, args->wperc);
strncat(args->argstr, TmpStr, (MAX_ARG_LEN-1)-strlen(args->argstr));
args->flags |= CLD_FLG_DUTY;
}
if((args->delayTimeMin == 0) && (args->delayTimeMax == 0) && (args->ioTimeout == DEFAULT_IO_TIMEOUT)) {
strncat(args->argstr, "(-t 0:2m) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
}
if(!(args->flags & CLD_FLG_OFFSET)) {
strncat(args->argstr, "(-o 0) ", (MAX_ARG_LEN-1)-strlen(args->argstr));
}
return(0);
}
/*
* checks validity of data after parsing
* args and make assumtions. returns 0 on
* success and -1 on failure.
*/
int check_conclusions(child_args_t *args)
{
extern unsigned long glb_flags;
struct stat stat_buf;
int rv;
if((args->flags & CLD_FLG_DUTY) && ((args->flags & CLD_FLG_LINEAR) || (args->flags & CLD_FLG_NTRLVD))) {
pMsg(WARN, args, "Duty cycle testing is supported for random (-pR) tests only.\n");
return(-1);
}
if((args->flags & CLD_FLG_BLK_RNG) && (args->flags & CLD_FLG_RTRSIZ)) {
pMsg(WARN, args, "Can't have unfixed block sizes and specify seek range in terms of blocks.\n");
return(-1);
}
if((args->vsiz < 0) || (args->ltrsiz < 1) || (args->htrsiz < 1)) {
pMsg(WARN, args, "Bounds exceeded for transfer size and/or volume size.\n");
pMsg(WARN, args, MAXTRSIZ, (args->htrsiz*BLK_SIZE),args->vsiz);
return(-1);
}
if(args->htrsiz < args->ltrsiz) {
pMsg(ERR, args, "Min transfer size, %lu, greater then Max transfer size, %lu.\n", args->ltrsiz, args->htrsiz);
return(-1);
}
if(args->vsiz < (args->stop_lba-args->start_lba+1)) {
pMsg(ERR, args, "Volume stop block/lba exceeds volume size.\n");
return(-1);
}
if(args->vsiz < args->htrsiz) {
pMsg(WARN, args, VSIZETS, args->vsiz, args->htrsiz);
return(-1);
}
if((!args->flags & CLD_FLG_TMD) && (args->seeks <= 0)) {
pMsg(WARN,args, TSEEK, args->seeks);
return(-1);
}
if((args->flags & CLD_FLG_SKS) && (args->t_kids > args->seeks)) {
pMsg(WARN, args, "Can't have more children then max number of seeks, use -K/-L to adjust.\n");
return(-1);
}
if((args->start_blk > args->vsiz) && !(args->flags & (CLD_FLG_BLK_RNG|CLD_FLG_LBA_RNG))) {
pMsg(WARN, args, STBGTTLBA, args->start_blk, (args->vsiz / args->htrsiz));
return(-1);
}
if((args->stop_blk > args->vsiz) && !(args->flags & (CLD_FLG_BLK_RNG|CLD_FLG_LBA_RNG))) {
pMsg(WARN, args, SBGTTLBA, args->stop_blk, (args->vsiz / args->htrsiz));
return(-1);
}
if((args->start_lba > args->vsiz) && !(args->flags & (CLD_FLG_BLK_RNG|CLD_FLG_LBA_RNG))) {
pMsg(WARN, args, STLBAGTLBA, args->start_lba, args->vsiz);
return(-1);
}
if((args->stop_lba > args->vsiz) && !(args->flags & (CLD_FLG_BLK_RNG|CLD_FLG_LBA_RNG))) {
pMsg(WARN, args, SLBAGTLBA, args->stop_lba, args->vsiz);
return(-1);
}
if(args->start_blk > args->stop_blk) {
pMsg(WARN, args, SBRSB, args->stop_blk, args->start_blk);
return(-1);
}
if(args->start_lba > args->stop_lba) {
pMsg(ERR, args, SLBARSLBA, args->stop_lba, args->start_lba);
return(-1);
}
if((args->flags & CLD_FLG_LBA_RNG) && (args->flags & CLD_FLG_BLK_RNG)) {
pMsg(ERR, args, "Can't specify range in both block and LBA, use -s or -S.\n");
return(-1);
}
/* use stat to get file properties, and test then agains specified -I */
rv = stat(args->device, &stat_buf);
if(0 == rv) { /* no error on call to stat, compare against -I option */
/* files are usually file type */
if((args->flags & CLD_FLG_FILE) && !IS_FILE(stat_buf.st_mode) ) {
pMsg(ERR, args, "Can't open non-file filespec with file device type, -If.\n");
return(-1);
}
/* block devices, are usually block type */
if((args->flags & CLD_FLG_BLK) && !IS_BLK(stat_buf.st_mode)) {
pMsg(ERR, args, "Can't open non-block filespec with block device type, -Ib.\n");
return(-1);
}
#ifndef WINDOWS
/* raw devices, are usually character type */
if((args->flags & CLD_FLG_RAW) && !S_ISCHR(stat_buf.st_mode)) {
pMsg(ERR, args, "Can't open non-raw filespec with raw device type, -Ir.\n");
return(-1);
}
#else
if(args->flags & CLD_FLG_RAW) {
pMsg(ERR, args, "RAW IO type not supported in Windows, use direct IO instead.\n");
return(-1);
}
#endif
#ifdef _DEBUG
} else {
PDBG1(DBUG, args, "Can't get status on %s, assuming a new file, errno = %d\n", args->device, GETLASTERROR());
#endif
}
if((args->hbeat > 0) && (args->flags & CLD_FLG_TMD) && (args->hbeat > args->run_time)) {
pMsg(ERR, args, "Heartbeat should be at least equal to runtime, use -h/-T to adjust.\n");
return(-1);
}
if((args->hbeat > 0) && !(args->flags & CLD_FLG_PRFTYPS)) {
pMsg(ERR, args, "At least one performance option, -P, must be specified when using -h.\n");
return(-1);
}
if((args->flags & CLD_FLG_W) && !(args->flags & CLD_FLG_R) && (args->flags & CLD_FLG_CMPR)) {