-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
3126 lines (2721 loc) · 69.8 KB
/
init.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
/*
* This file contains job initialization and setup functions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <dlfcn.h>
#ifdef CONFIG_VALGRIND_DEV
#include <valgrind/drd.h>
#else
#define DRD_IGNORE_VAR(x) do { } while (0)
#endif
#include "fio.h"
#ifndef FIO_NO_HAVE_SHM_H
#include <sys/shm.h>
#endif
#include "parse.h"
#include "smalloc.h"
#include "filehash.h"
#include "verify.h"
#include "profile.h"
#include "server.h"
#include "idletime.h"
#include "filelock.h"
#include "steadystate.h"
#include "blktrace.h"
#include "oslib/asprintf.h"
#include "oslib/getopt.h"
#include "oslib/strcasestr.h"
#include "crc/test.h"
#include "lib/pow2.h"
#include "lib/memcpy.h"
const char fio_version_string[] = FIO_VERSION;
#define FIO_RANDSEED (0xb1899bedUL)
static char **ini_file;
static bool dump_cmdline;
static bool parse_only;
static bool merge_blktrace_only;
static struct thread_data def_thread;
struct thread_segment segments[REAL_MAX_SEG];
static char **job_sections;
static int nr_job_sections;
bool exitall_on_terminate = false;
int output_format = FIO_OUTPUT_NORMAL;
int eta_print = FIO_ETA_AUTO;
unsigned int eta_interval_msec = 1000;
int eta_new_line = 0;
FILE *f_out = NULL;
FILE *f_err = NULL;
char *exec_profile = NULL;
int warnings_fatal = 0;
int terse_version = 3;
bool is_backend = false;
bool is_local_backend = false;
int nr_clients = 0;
bool log_syslog = false;
bool write_bw_log = false;
bool read_only = false;
int status_interval = 0;
char *trigger_file = NULL;
long long trigger_timeout = 0;
char *trigger_cmd = NULL;
char *trigger_remote_cmd = NULL;
char *aux_path = NULL;
static int prev_group_jobs;
unsigned long fio_debug = 0;
unsigned int fio_debug_jobno = -1;
unsigned int *fio_debug_jobp = NULL;
unsigned int *fio_warned = NULL;
static char cmd_optstr[256];
static bool did_arg;
#define FIO_CLIENT_FLAG (1 << 16)
/*
* Command line options. These will contain the above, plus a few
* extra that only pertain to fio itself and not jobs.
*/
static struct option l_opts[FIO_NR_OPTIONS] = {
{
.name = (char *) "output",
.has_arg = required_argument,
.val = 'o' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "latency-log",
.has_arg = required_argument,
.val = 'l' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "bandwidth-log",
.has_arg = no_argument,
.val = 'b' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "minimal",
.has_arg = no_argument,
.val = 'm' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "output-format",
.has_arg = required_argument,
.val = 'F' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "append-terse",
.has_arg = optional_argument,
.val = 'f',
},
{
.name = (char *) "version",
.has_arg = no_argument,
.val = 'v' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "help",
.has_arg = no_argument,
.val = 'h' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "cmdhelp",
.has_arg = optional_argument,
.val = 'c' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "enghelp",
.has_arg = optional_argument,
.val = 'i' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "showcmd",
.has_arg = no_argument,
.val = 's' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "readonly",
.has_arg = no_argument,
.val = 'r' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "eta",
.has_arg = required_argument,
.val = 'e' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "eta-interval",
.has_arg = required_argument,
.val = 'O' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "eta-newline",
.has_arg = required_argument,
.val = 'E' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "debug",
.has_arg = required_argument,
.val = 'd' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "parse-only",
.has_arg = no_argument,
.val = 'P' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "section",
.has_arg = required_argument,
.val = 'x' | FIO_CLIENT_FLAG,
},
#ifdef CONFIG_ZLIB
{
.name = (char *) "inflate-log",
.has_arg = required_argument,
.val = 'X' | FIO_CLIENT_FLAG,
},
#endif
{
.name = (char *) "alloc-size",
.has_arg = required_argument,
.val = 'a' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "profile",
.has_arg = required_argument,
.val = 'p' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "warnings-fatal",
.has_arg = no_argument,
.val = 'w' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "max-jobs",
.has_arg = required_argument,
.val = 'j' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "terse-version",
.has_arg = required_argument,
.val = 'V' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "server",
.has_arg = optional_argument,
.val = 'S',
},
#ifdef WIN32
{
.name = (char *) "server-internal",
.has_arg = required_argument,
.val = 'N',
},
#endif
{ .name = (char *) "daemonize",
.has_arg = required_argument,
.val = 'D',
},
{
.name = (char *) "client",
.has_arg = required_argument,
.val = 'C',
},
{
.name = (char *) "remote-config",
.has_arg = required_argument,
.val = 'R',
},
{
.name = (char *) "cpuclock-test",
.has_arg = no_argument,
.val = 'T',
},
{
.name = (char *) "crctest",
.has_arg = optional_argument,
.val = 'G',
},
{
.name = (char *) "memcpytest",
.has_arg = optional_argument,
.val = 'M',
},
{
.name = (char *) "idle-prof",
.has_arg = required_argument,
.val = 'I',
},
{
.name = (char *) "status-interval",
.has_arg = required_argument,
.val = 'L' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "trigger-file",
.has_arg = required_argument,
.val = 'W',
},
{
.name = (char *) "trigger-timeout",
.has_arg = required_argument,
.val = 'B',
},
{
.name = (char *) "trigger",
.has_arg = required_argument,
.val = 'H',
},
{
.name = (char *) "trigger-remote",
.has_arg = required_argument,
.val = 'J',
},
{
.name = (char *) "aux-path",
.has_arg = required_argument,
.val = 'K',
},
{
.name = (char *) "merge-blktrace-only",
.has_arg = no_argument,
.val = 'A' | FIO_CLIENT_FLAG,
},
{
.name = NULL,
},
};
void free_threads_shm(void)
{
int i;
for (i = 0; i < nr_segments; i++) {
struct thread_segment *seg = &segments[i];
if (seg->threads) {
void *tp = seg->threads;
#ifndef CONFIG_NO_SHM
struct shmid_ds sbuf;
seg->threads = NULL;
shmdt(tp);
shmctl(seg->shm_id, IPC_RMID, &sbuf);
seg->shm_id = -1;
#else
seg->threads = NULL;
free(tp);
#endif
}
}
nr_segments = 0;
cur_segment = 0;
}
static void free_shm(void)
{
#ifndef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
if (nr_segments) {
flow_exit();
fio_debug_jobp = NULL;
fio_warned = NULL;
free_threads_shm();
}
free(trigger_file);
free(trigger_cmd);
free(trigger_remote_cmd);
trigger_file = trigger_cmd = trigger_remote_cmd = NULL;
options_free(fio_options, &def_thread.o);
fio_filelock_exit();
file_hash_exit();
scleanup();
#endif
}
static int add_thread_segment(void)
{
struct thread_segment *seg = &segments[nr_segments];
size_t size = JOBS_PER_SEG * sizeof(struct thread_data);
int i;
if (nr_segments + 1 >= REAL_MAX_SEG) {
log_err("error: maximum number of jobs reached.\n");
return -1;
}
size += 2 * sizeof(unsigned int);
#ifndef CONFIG_NO_SHM
seg->shm_id = shmget(0, size, IPC_CREAT | 0600);
if (seg->shm_id == -1) {
if (errno != EINVAL && errno != ENOMEM && errno != ENOSPC)
perror("shmget");
return -1;
}
#else
seg->threads = malloc(size);
if (!seg->threads)
return -1;
#endif
#ifndef CONFIG_NO_SHM
seg->threads = shmat(seg->shm_id, NULL, 0);
if (seg->threads == (void *) -1) {
perror("shmat");
return 1;
}
if (shm_attach_to_open_removed())
shmctl(seg->shm_id, IPC_RMID, NULL);
#endif
nr_segments++;
memset(seg->threads, 0, JOBS_PER_SEG * sizeof(struct thread_data));
for (i = 0; i < JOBS_PER_SEG; i++)
DRD_IGNORE_VAR(seg->threads[i]);
seg->nr_threads = 0;
/* Not first segment, we're done */
if (nr_segments != 1) {
cur_segment++;
return 0;
}
fio_debug_jobp = (unsigned int *)(seg->threads + JOBS_PER_SEG);
*fio_debug_jobp = -1;
fio_warned = fio_debug_jobp + 1;
*fio_warned = 0;
flow_init();
return 0;
}
/*
* The thread areas are shared between the main process and the job
* threads/processes, and is split into chunks of JOBS_PER_SEG. If the current
* segment has no more room, add a new chunk.
*/
static int expand_thread_area(void)
{
struct thread_segment *seg = &segments[cur_segment];
if (nr_segments && seg->nr_threads < JOBS_PER_SEG)
return 0;
return add_thread_segment();
}
static void dump_print_option(struct print_option *p)
{
const char *delim;
if (!strcmp("description", p->name))
delim = "\"";
else
delim = "";
log_info("--%s%s", p->name, p->value ? "" : " ");
if (p->value)
log_info("=%s%s%s ", delim, p->value, delim);
}
static void dump_opt_list(struct thread_data *td)
{
struct flist_head *entry;
struct print_option *p;
if (flist_empty(&td->opt_list))
return;
flist_for_each(entry, &td->opt_list) {
p = flist_entry(entry, struct print_option, list);
dump_print_option(p);
}
}
static void copy_opt_list(struct thread_data *dst, struct thread_data *src)
{
struct flist_head *entry;
if (flist_empty(&src->opt_list))
return;
flist_for_each(entry, &src->opt_list) {
struct print_option *srcp, *dstp;
srcp = flist_entry(entry, struct print_option, list);
dstp = malloc(sizeof(*dstp));
dstp->name = strdup(srcp->name);
if (srcp->value)
dstp->value = strdup(srcp->value);
else
dstp->value = NULL;
flist_add_tail(&dstp->list, &dst->opt_list);
}
}
/*
* Return a free job structure.
*/
static struct thread_data *get_new_job(bool global, struct thread_data *parent,
bool preserve_eo, const char *jobname)
{
struct thread_segment *seg;
struct thread_data *td;
if (global)
return &def_thread;
if (expand_thread_area()) {
log_err("error: failed to setup shm segment\n");
return NULL;
}
seg = &segments[cur_segment];
td = &seg->threads[seg->nr_threads++];
thread_number++;
*td = *parent;
INIT_FLIST_HEAD(&td->opt_list);
if (parent != &def_thread)
copy_opt_list(td, parent);
td->io_ops = NULL;
td->io_ops_init = 0;
if (!preserve_eo)
td->eo = NULL;
td->o.uid = td->o.gid = -1U;
dup_files(td, parent);
fio_options_mem_dupe(td);
profile_add_hooks(td);
td->thread_number = thread_number;
td->subjob_number = 0;
if (jobname)
td->o.name = strdup(jobname);
if (!parent->o.group_reporting || parent == &def_thread)
stat_number++;
return td;
}
static void put_job(struct thread_data *td)
{
if (td == &def_thread)
return;
profile_td_exit(td);
flow_exit_job(td);
if (td->error)
log_info("fio: %s\n", td->verror);
fio_options_free(td);
fio_dump_options_free(td);
if (td->io_ops)
free_ioengine(td);
if (td->o.name)
free(td->o.name);
memset(td, 0, sizeof(*td));
segments[cur_segment].nr_threads--;
thread_number--;
}
static int __setup_rate(struct thread_data *td, enum fio_ddir ddir)
{
unsigned long long bs = td->o.min_bs[ddir];
assert(ddir_rw(ddir));
if (td->o.rate[ddir])
td->rate_bps[ddir] = td->o.rate[ddir];
else
td->rate_bps[ddir] = (uint64_t) td->o.rate_iops[ddir] * bs;
if (!td->rate_bps[ddir]) {
log_err("rate lower than supported\n");
return -1;
}
td->rate_next_io_time[ddir] = 0;
td->rate_io_issue_bytes[ddir] = 0;
td->last_usec[ddir] = 0;
return 0;
}
static int setup_rate(struct thread_data *td)
{
int ret = 0;
for_each_rw_ddir(ddir) {
if (td->o.rate[ddir] || td->o.rate_iops[ddir]) {
ret |= __setup_rate(td, ddir);
}
}
return ret;
}
static int fixed_block_size(struct thread_options *o)
{
return o->min_bs[DDIR_READ] == o->max_bs[DDIR_READ] &&
o->min_bs[DDIR_WRITE] == o->max_bs[DDIR_WRITE] &&
o->min_bs[DDIR_TRIM] == o->max_bs[DDIR_TRIM] &&
o->min_bs[DDIR_READ] == o->min_bs[DDIR_WRITE] &&
o->min_bs[DDIR_READ] == o->min_bs[DDIR_TRIM];
}
/*
* <3 Johannes
*/
static unsigned int gcd(unsigned int m, unsigned int n)
{
if (!n)
return m;
return gcd(n, m % n);
}
/*
* Lazy way of fixing up options that depend on each other. We could also
* define option callback handlers, but this is easier.
*/
static int fixup_options(struct thread_data *td)
{
struct thread_options *o = &td->o;
int ret = 0;
if (read_only && (td_write(td) || td_trim(td))) {
log_err("fio: trim and write operations are not allowed"
" with the --readonly parameter.\n");
ret |= 1;
}
#ifndef CONFIG_PSHARED
if (!o->use_thread) {
log_info("fio: this platform does not support process shared"
" mutexes, forcing use of threads. Use the 'thread'"
" option to get rid of this warning.\n");
o->use_thread = 1;
ret |= warnings_fatal;
}
#endif
if (o->write_iolog_file && o->read_iolog_file) {
log_err("fio: read iolog overrides write_iolog\n");
free(o->write_iolog_file);
o->write_iolog_file = NULL;
ret |= warnings_fatal;
}
if (o->zone_mode == ZONE_MODE_NONE && o->zone_size) {
log_err("fio: --zonemode=none and --zonesize are not compatible.\n");
ret |= 1;
}
if (o->zone_mode == ZONE_MODE_ZBD && !o->create_serialize) {
log_err("fio: --zonemode=zbd and --create_serialize=0 are not compatible.\n");
ret |= 1;
}
if (o->zone_mode == ZONE_MODE_STRIDED && !o->zone_size) {
log_err("fio: --zonesize must be specified when using --zonemode=strided.\n");
ret |= 1;
}
if (o->zone_mode == ZONE_MODE_NOT_SPECIFIED) {
if (o->zone_size)
o->zone_mode = ZONE_MODE_STRIDED;
else
o->zone_mode = ZONE_MODE_NONE;
}
/*
* Strided zone mode only really works with 1 file.
*/
if (o->zone_mode == ZONE_MODE_STRIDED && o->open_files > 1)
o->zone_mode = ZONE_MODE_NONE;
/*
* If zone_range isn't specified, backward compatibility dictates it
* should be made equal to zone_size.
*/
if (o->zone_mode == ZONE_MODE_STRIDED && !o->zone_range)
o->zone_range = o->zone_size;
/*
* Reads can do overwrites, we always need to pre-create the file
*/
if (td_read(td))
o->overwrite = 1;
for_each_rw_ddir(ddir) {
if (!o->min_bs[ddir])
o->min_bs[ddir] = o->bs[ddir];
if (!o->max_bs[ddir])
o->max_bs[ddir] = o->bs[ddir];
}
o->rw_min_bs = -1;
for_each_rw_ddir(ddir) {
o->rw_min_bs = min(o->rw_min_bs, o->min_bs[ddir]);
}
/*
* For random IO, allow blockalign offset other than min_bs.
*/
for_each_rw_ddir(ddir) {
if (!o->ba[ddir] || !td_random(td))
o->ba[ddir] = o->min_bs[ddir];
}
if ((o->ba[DDIR_READ] != o->min_bs[DDIR_READ] ||
o->ba[DDIR_WRITE] != o->min_bs[DDIR_WRITE] ||
o->ba[DDIR_TRIM] != o->min_bs[DDIR_TRIM]) &&
!o->norandommap) {
log_err("fio: Any use of blockalign= turns off randommap\n");
o->norandommap = 1;
ret |= warnings_fatal;
}
if (!o->file_size_high)
o->file_size_high = o->file_size_low;
if (o->start_delay_high) {
if (!o->start_delay_orig)
o->start_delay_orig = o->start_delay;
o->start_delay = rand_between(&td->delay_state,
o->start_delay_orig,
o->start_delay_high);
}
if (o->norandommap && o->verify != VERIFY_NONE
&& !fixed_block_size(o)) {
log_err("fio: norandommap given for variable block sizes, "
"verify limited\n");
ret |= warnings_fatal;
}
if (o->bs_unaligned && (o->odirect || td_ioengine_flagged(td, FIO_RAWIO)))
log_err("fio: bs_unaligned may not work with raw io\n");
/*
* thinktime_spin must be less than thinktime
*/
if (o->thinktime_spin > o->thinktime)
o->thinktime_spin = o->thinktime;
/*
* The low water mark cannot be bigger than the iodepth
*/
if (o->iodepth_low > o->iodepth || !o->iodepth_low)
o->iodepth_low = o->iodepth;
/*
* If batch number isn't set, default to the same as iodepth
*/
if (o->iodepth_batch > o->iodepth || !o->iodepth_batch)
o->iodepth_batch = o->iodepth;
/*
* If max batch complete number isn't set or set incorrectly,
* default to the same as iodepth_batch_complete_min
*/
if (o->iodepth_batch_complete_min > o->iodepth_batch_complete_max)
o->iodepth_batch_complete_max = o->iodepth_batch_complete_min;
/*
* There's no need to check for in-flight overlapping IOs if the job
* isn't changing data or the maximum iodepth is guaranteed to be 1
* when we are not in offload mode
*/
if (o->serialize_overlap && !(td->flags & TD_F_READ_IOLOG) &&
(!(td_write(td) || td_trim(td)) || o->iodepth == 1) &&
o->io_submit_mode != IO_MODE_OFFLOAD)
o->serialize_overlap = 0;
if (o->nr_files > td->files_index)
o->nr_files = td->files_index;
if (o->open_files > o->nr_files || !o->open_files)
o->open_files = o->nr_files;
if (((o->rate[DDIR_READ] + o->rate[DDIR_WRITE] + o->rate[DDIR_TRIM]) &&
(o->rate_iops[DDIR_READ] + o->rate_iops[DDIR_WRITE] + o->rate_iops[DDIR_TRIM])) ||
((o->ratemin[DDIR_READ] + o->ratemin[DDIR_WRITE] + o->ratemin[DDIR_TRIM]) &&
(o->rate_iops_min[DDIR_READ] + o->rate_iops_min[DDIR_WRITE] + o->rate_iops_min[DDIR_TRIM]))) {
log_err("fio: rate and rate_iops are mutually exclusive\n");
ret |= 1;
}
for_each_rw_ddir(ddir) {
if ((o->rate[ddir] && (o->rate[ddir] < o->ratemin[ddir])) ||
(o->rate_iops[ddir] && (o->rate_iops[ddir] < o->rate_iops_min[ddir]))) {
log_err("fio: minimum rate exceeds rate, ddir %d\n", +ddir);
ret |= 1;
}
}
if (!o->timeout && o->time_based) {
log_err("fio: time_based requires a runtime/timeout setting\n");
o->time_based = 0;
ret |= warnings_fatal;
}
if (o->fill_device && !o->size)
o->size = -1ULL;
if (o->verify != VERIFY_NONE) {
if (td_write(td) && o->do_verify && o->numjobs > 1 &&
(o->filename ||
!(o->unique_filename &&
strstr(o->filename_format, "$jobname") &&
strstr(o->filename_format, "$jobnum") &&
strstr(o->filename_format, "$filenum")))) {
log_info("fio: multiple writers may overwrite blocks "
"that belong to other jobs. This can cause "
"verification failures.\n");
ret |= warnings_fatal;
}
/*
* Warn if verification is requested but no verification of any
* kind can be started due to time constraints
*/
if (td_write(td) && o->do_verify && o->timeout &&
o->time_based && !td_read(td) && !o->verify_backlog) {
log_info("fio: verification read phase will never "
"start because write phase uses all of "
"runtime\n");
ret |= warnings_fatal;
}
if (!fio_option_is_set(o, refill_buffers))
o->refill_buffers = 1;
if (o->max_bs[DDIR_WRITE] != o->min_bs[DDIR_WRITE] &&
!o->verify_interval)
o->verify_interval = o->min_bs[DDIR_WRITE];
/*
* Verify interval must be smaller or equal to the
* write size.
*/
if (o->verify_interval > o->min_bs[DDIR_WRITE])
o->verify_interval = o->min_bs[DDIR_WRITE];
else if (td_read(td) && o->verify_interval > o->min_bs[DDIR_READ])
o->verify_interval = o->min_bs[DDIR_READ];
/*
* Verify interval must be a factor of both min and max
* write size
*/
if (!o->verify_interval ||
(o->min_bs[DDIR_WRITE] % o->verify_interval) ||
(o->max_bs[DDIR_WRITE] % o->verify_interval))
o->verify_interval = gcd(o->min_bs[DDIR_WRITE],
o->max_bs[DDIR_WRITE]);
}
if (o->pre_read) {
if (o->invalidate_cache)
o->invalidate_cache = 0;
if (td_ioengine_flagged(td, FIO_PIPEIO)) {
log_info("fio: cannot pre-read files with an IO engine"
" that isn't seekable. Pre-read disabled.\n");
ret |= warnings_fatal;
}
}
if (o->unit_base == N2S_NONE) {
if (td_ioengine_flagged(td, FIO_BIT_BASED))
o->unit_base = N2S_BITPERSEC;
else
o->unit_base = N2S_BYTEPERSEC;
}
#ifndef CONFIG_FDATASYNC
if (o->fdatasync_blocks) {
log_info("fio: this platform does not support fdatasync()"
" falling back to using fsync(). Use the 'fsync'"
" option instead of 'fdatasync' to get rid of"
" this warning\n");
o->fsync_blocks = o->fdatasync_blocks;
o->fdatasync_blocks = 0;
ret |= warnings_fatal;
}
#endif
#ifdef WIN32
/*
* Windows doesn't support O_DIRECT or O_SYNC with the _open interface,
* so fail if we're passed those flags
*/
if (td_ioengine_flagged(td, FIO_SYNCIO) && (o->odirect || o->sync_io)) {
log_err("fio: Windows does not support direct or non-buffered io with"
" the synchronous ioengines. Use the 'windowsaio' ioengine"
" with 'direct=1' and 'iodepth=1' instead.\n");
ret |= 1;
}
#endif
/*
* For fully compressible data, just zero them at init time.
* It's faster than repeatedly filling it. For non-zero
* compression, we should have refill_buffers set. Set it, unless
* the job file already changed it.
*/
if (o->compress_percentage) {
if (o->compress_percentage == 100) {
o->zero_buffers = 1;
o->compress_percentage = 0;
} else if (!fio_option_is_set(o, refill_buffers)) {
o->refill_buffers = 1;
td->flags |= TD_F_REFILL_BUFFERS;
}
}
/*
* Using a non-uniform random distribution excludes usage of
* a random map
*/
if (o->random_distribution != FIO_RAND_DIST_RANDOM)
o->norandommap = 1;
/*
* If size is set but less than the min block size, complain
*/
if (o->size && o->size < td_min_bs(td)) {
log_err("fio: size too small, must not be less than minimum block size: %llu < %llu\n",
(unsigned long long) o->size, td_min_bs(td));
ret |= 1;
}
/*
* O_ATOMIC implies O_DIRECT
*/
if (o->oatomic)
o->odirect = 1;
/*
* If randseed is set, that overrides randrepeat
*/
if (fio_option_is_set(o, rand_seed))
o->rand_repeatable = 0;
if (td_ioengine_flagged(td, FIO_NOEXTEND) && o->file_append) {
log_err("fio: can't append/extent with IO engine %s\n", td->io_ops->name);
ret |= 1;
}
if (fio_option_is_set(o, gtod_cpu)) {
fio_gtod_init();
fio_gtod_set_cpu(o->gtod_cpu);
fio_gtod_offload = 1;
}
td->loops = o->loops;
if (!td->loops)
td->loops = 1;
if (o->block_error_hist && o->nr_files != 1) {
log_err("fio: block error histogram only available "
"with a single file per job, but %d files "
"provided\n", o->nr_files);
ret |= 1;
}
if (o->disable_lat)
o->lat_percentiles = 0;
if (o->disable_clat)
o->clat_percentiles = 0;
if (o->disable_slat)
o->slat_percentiles = 0;
/*
* Fix these up to be nsec internally
*/
for_each_rw_ddir(ddir)
o->max_latency[ddir] *= 1000ULL;
o->latency_target *= 1000ULL;
/*
* Dedupe working set verifications
*/
if (o->dedupe_percentage && o->dedupe_mode == DEDUPE_MODE_WORKING_SET) {
if (!fio_option_is_set(o, size)) {
log_err("fio: pregenerated dedupe working set "
"requires size to be set\n");
ret |= 1;
} else if (o->nr_files != 1) {
log_err("fio: dedupe working set mode supported with "
"single file per job, but %d files "
"provided\n", o->nr_files);
ret |= 1;
} else if (o->dedupe_working_set_percentage + o->dedupe_percentage > 100) {
log_err("fio: impossible to reach expected dedupe percentage %u "
"since %u percentage of size is reserved to dedupe working set "
"(those are unique pages)\n",
o->dedupe_percentage, o->dedupe_working_set_percentage);
ret |= 1;
}
}
return ret;
}
static void init_rand_file_service(struct thread_data *td)
{
unsigned long nranges = td->o.nr_files << FIO_FSERVICE_SHIFT;
const unsigned int seed = td->rand_seeds[FIO_RAND_FILE_OFF];
if (td->o.file_service_type == FIO_FSERVICE_ZIPF) {
zipf_init(&td->next_file_zipf, nranges, td->zipf_theta, td->random_center, seed);
zipf_disable_hash(&td->next_file_zipf);