forked from xuechendi/fio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.c
2781 lines (2408 loc) · 60.7 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 <fcntl.h>
#include <ctype.h>
#include <string.h>
#include <errno.h>
#include <sys/ipc.h>
#include <sys/types.h>
#include <sys/stat.h>
#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 "oslib/getopt.h"
#include "oslib/strcasestr.h"
#include "crc/test.h"
const char fio_version_string[] = FIO_VERSION;
#define FIO_RANDSEED (0xb1899bedUL)
static char **ini_file;
static int max_jobs = FIO_MAX_JOBS;
static int dump_cmdline;
static long long def_timeout;
static int parse_only;
static struct thread_data def_thread;
struct thread_data *threads = NULL;
static char **job_sections;
static int nr_job_sections;
int exitall_on_terminate = 0;
int exitall_on_terminate_error = 0;
int output_format = FIO_OUTPUT_NORMAL;
int eta_print = FIO_ETA_AUTO;
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;
int is_backend = 0;
int nr_clients = 0;
int log_syslog = 0;
int write_bw_log = 0;
int read_only = 0;
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;
static char cmd_optstr[256];
static int 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 *) "timeout",
.has_arg = required_argument,
.val = 't' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "latency-log",
.has_arg = required_argument,
.val = 'l' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "bandwidth-log",
.has_arg = required_argument,
.val = 'b' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "minimal",
.has_arg = no_argument,
.val = 'm' | FIO_CLIENT_FLAG,
},
{
.name = (char *) "output-format",
.has_arg = optional_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-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',
},
{ .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 *) "idle-prof",
.has_arg = required_argument,
.val = 'I',
},
{
.name = (char *) "status-interval",
.has_arg = required_argument,
.val = 'L',
},
{
.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 = NULL,
},
};
void free_threads_shm(void)
{
if (threads) {
void *tp = threads;
#ifndef CONFIG_NO_SHM
struct shmid_ds sbuf;
threads = NULL;
shmdt(tp);
shmctl(shm_id, IPC_RMID, &sbuf);
shm_id = -1;
#else
threads = NULL;
free(tp);
#endif
}
}
static void free_shm(void)
{
if (threads) {
file_hash_exit();
flow_exit();
fio_debug_jobp = 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);
fio_filelock_exit();
scleanup();
}
/*
* The thread area is shared between the main process and the job
* threads/processes. So setup a shared memory segment that will hold
* all the job info. We use the end of the region for keeping track of
* open files across jobs, for file sharing.
*/
static int setup_thread_area(void)
{
void *hash;
if (threads)
return 0;
/*
* 1024 is too much on some machines, scale max_jobs if
* we get a failure that looks like too large a shm segment
*/
do {
size_t size = max_jobs * sizeof(struct thread_data);
size += file_hash_size;
size += sizeof(unsigned int);
#ifndef CONFIG_NO_SHM
shm_id = shmget(0, size, IPC_CREAT | 0600);
if (shm_id != -1)
break;
if (errno != EINVAL && errno != ENOMEM && errno != ENOSPC) {
perror("shmget");
break;
}
#else
threads = malloc(size);
if (threads)
break;
#endif
max_jobs >>= 1;
} while (max_jobs);
#ifndef CONFIG_NO_SHM
if (shm_id == -1)
return 1;
threads = shmat(shm_id, NULL, 0);
if (threads == (void *) -1) {
perror("shmat");
return 1;
}
#endif
memset(threads, 0, max_jobs * sizeof(struct thread_data));
hash = (void *) threads + max_jobs * sizeof(struct thread_data);
fio_debug_jobp = (void *) hash + file_hash_size;
*fio_debug_jobp = -1;
file_hash_init(hash);
flow_init();
return 0;
}
static void set_cmd_options(struct thread_data *td)
{
struct thread_options *o = &td->o;
if (!o->timeout)
o->timeout = def_timeout;
}
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 fio_dump_options_free(struct thread_data *td)
{
while (!flist_empty(&td->opt_list)) {
struct print_option *p;
p = flist_first_entry(&td->opt_list, struct print_option, list);
flist_del_init(&p->list);
free(p->name);
free(p->value);
free(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(int global, struct thread_data *parent,
int preserve_eo, const char *jobname)
{
struct thread_data *td;
if (global) {
set_cmd_options(&def_thread);
return &def_thread;
}
if (setup_thread_area()) {
log_err("error: failed to setup shm segment\n");
return NULL;
}
if (thread_number >= max_jobs) {
log_err("error: maximum number of jobs (%d) reached.\n",
max_jobs);
return NULL;
}
td = &threads[thread_number++];
*td = *parent;
INIT_FLIST_HEAD(&td->opt_list);
if (parent != &def_thread)
copy_opt_list(td, parent);
td->io_ops = NULL;
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++;
set_cmd_options(td);
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(&threads[td->thread_number - 1], 0, sizeof(*td));
thread_number--;
}
static int __setup_rate(struct thread_data *td, enum fio_ddir ddir)
{
unsigned int 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 = 0;
return 0;
}
static int setup_rate(struct thread_data *td)
{
int ret = 0;
if (td->o.rate[DDIR_READ] || td->o.rate_iops[DDIR_READ])
ret = __setup_rate(td, DDIR_READ);
if (td->o.rate[DDIR_WRITE] || td->o.rate_iops[DDIR_WRITE])
ret |= __setup_rate(td, DDIR_WRITE);
if (td->o.rate[DDIR_TRIM] || td->o.rate_iops[DDIR_TRIM])
ret |= __setup_rate(td, DDIR_TRIM);
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];
}
static unsigned long long get_rand_start_delay(struct thread_data *td)
{
unsigned long long delayrange;
uint64_t frand_max;
unsigned long r;
delayrange = td->o.start_delay_high - td->o.start_delay;
frand_max = rand_max(&td->delay_state);
r = __rand(&td->delay_state);
delayrange = (unsigned long long) ((double) delayrange * (r / (frand_max + 1.0)));
delayrange += td->o.start_delay;
return delayrange;
}
/*
* 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;
#ifndef FIO_HAVE_PSHARED_MUTEX
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;
}
/*
* only really works with 1 file
*/
if (o->zone_size && o->open_files > 1)
o->zone_size = 0;
/*
* If zone_range isn't specified, backward compatibility dictates it
* should be made equal to zone_size.
*/
if (o->zone_size && !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) || td_rw(td))
o->overwrite = 1;
if (!o->min_bs[DDIR_READ])
o->min_bs[DDIR_READ] = o->bs[DDIR_READ];
if (!o->max_bs[DDIR_READ])
o->max_bs[DDIR_READ] = o->bs[DDIR_READ];
if (!o->min_bs[DDIR_WRITE])
o->min_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
if (!o->max_bs[DDIR_WRITE])
o->max_bs[DDIR_WRITE] = o->bs[DDIR_WRITE];
if (!o->min_bs[DDIR_TRIM])
o->min_bs[DDIR_TRIM] = o->bs[DDIR_TRIM];
if (!o->max_bs[DDIR_TRIM])
o->max_bs[DDIR_TRIM] = o->bs[DDIR_TRIM];
o->rw_min_bs = min(o->min_bs[DDIR_READ], o->min_bs[DDIR_WRITE]);
o->rw_min_bs = min(o->min_bs[DDIR_TRIM], o->rw_min_bs);
/*
* For random IO, allow blockalign offset other than min_bs.
*/
if (!o->ba[DDIR_READ] || !td_random(td))
o->ba[DDIR_READ] = o->min_bs[DDIR_READ];
if (!o->ba[DDIR_WRITE] || !td_random(td))
o->ba[DDIR_WRITE] = o->min_bs[DDIR_WRITE];
if (!o->ba[DDIR_TRIM] || !td_random(td))
o->ba[DDIR_TRIM] = o->min_bs[DDIR_TRIM];
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)
o->start_delay = get_rand_start_delay(td);
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->io_ops->flags & 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;
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;
}
if ((o->rate[DDIR_READ] && (o->rate[DDIR_READ] < o->ratemin[DDIR_READ])) ||
(o->rate[DDIR_WRITE] && (o->rate[DDIR_WRITE] < o->ratemin[DDIR_WRITE])) ||
(o->rate[DDIR_TRIM] && (o->rate[DDIR_TRIM] < o->ratemin[DDIR_TRIM])) ||
(o->rate_iops[DDIR_READ] && (o->rate_iops[DDIR_READ] < o->rate_iops_min[DDIR_READ])) ||
(o->rate_iops[DDIR_WRITE] && (o->rate_iops[DDIR_WRITE] < o->rate_iops_min[DDIR_WRITE])) ||
(o->rate_iops[DDIR_TRIM] && (o->rate_iops[DDIR_TRIM] < o->rate_iops_min[DDIR_TRIM]))) {
log_err("fio: minimum rate exceeds rate\n");
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) {
log_info("Multiple writers may overwrite blocks that "
"belong to other jobs. This can cause "
"verification failures.\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];
}
if (o->pre_read) {
o->invalidate_cache = 0;
if (td->io_ops->flags & 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) {
if (td->io_ops->flags & FIO_BIT_BASED)
o->unit_base = 1;
else
o->unit_base = 8;
}
#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->io_ops->flags & FIO_SYNCIO) && (td->o.odirect || td->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;
}
/*
* Using a non-uniform random distribution excludes usage of
* a random map
*/
if (td->o.random_distribution != FIO_RAND_DIST_RANDOM)
td->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 be larger than the IO size: %llu\n", (unsigned long long) o->size);
ret = 1;
}
/*
* O_ATOMIC implies O_DIRECT
*/
if (td->o.oatomic)
td->o.odirect = 1;
/*
* If randseed is set, that overrides randrepeat
*/
if (fio_option_is_set(&td->o, rand_seed))
td->o.rand_repeatable = 0;
if ((td->io_ops->flags & FIO_NOEXTEND) && td->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 (td->o.block_error_hist && td->o.nr_files != 1) {
log_err("fio: block error histogram only available with "
"with a single file per job, but %d files "
"provided\n", td->o.nr_files);
ret = 1;
}
return ret;
}
/*
* This function leaks the buffer
*/
char *fio_uint_to_kmg(unsigned int val)
{
char *buf = malloc(32);
char post[] = { 0, 'K', 'M', 'G', 'P', 'E', 0 };
char *p = post;
do {
if (val & 1023)
break;
val >>= 10;
p++;
} while (*p);
snprintf(buf, 32, "%u%c", val, *p);
return buf;
}
/* External engines are specified by "external:name.o") */
static const char *get_engine_name(const char *str)
{
char *p = strstr(str, ":");
if (!p)
return str;
p++;
strip_blank_front(&p);
strip_blank_end(p);
return p;
}
static int exists_and_not_file(const char *filename)
{
struct stat sb;
if (lstat(filename, &sb) == -1)
return 0;
/* \\.\ is the device namespace in Windows, where every file
* is a device node */
if (S_ISREG(sb.st_mode) && strncmp(filename, "\\\\.\\", 4) != 0)
return 0;
return 1;
}
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, seed);
zipf_disable_hash(&td->next_file_zipf);
} else if (td->o.file_service_type == FIO_FSERVICE_PARETO) {
pareto_init(&td->next_file_zipf, nranges, td->pareto_h, seed);
zipf_disable_hash(&td->next_file_zipf);
} else if (td->o.file_service_type == FIO_FSERVICE_GAUSS) {
gauss_init(&td->next_file_gauss, nranges, td->gauss_dev, seed);
gauss_disable_hash(&td->next_file_gauss);
}
}
static void td_fill_rand_seeds_internal(struct thread_data *td, bool use64)
{
int i;
init_rand_seed(&td->bsrange_state, td->rand_seeds[FIO_RAND_BS_OFF], use64);
init_rand_seed(&td->verify_state, td->rand_seeds[FIO_RAND_VER_OFF], use64);
init_rand_seed(&td->rwmix_state, td->rand_seeds[FIO_RAND_MIX_OFF], false);
if (td->o.file_service_type == FIO_FSERVICE_RANDOM)
init_rand_seed(&td->next_file_state, td->rand_seeds[FIO_RAND_FILE_OFF], use64);
else if (td->o.file_service_type & __FIO_FSERVICE_NONUNIFORM)
init_rand_file_service(td);
init_rand_seed(&td->file_size_state, td->rand_seeds[FIO_RAND_FILE_SIZE_OFF], use64);
init_rand_seed(&td->trim_state, td->rand_seeds[FIO_RAND_TRIM_OFF], use64);
init_rand_seed(&td->delay_state, td->rand_seeds[FIO_RAND_START_DELAY], use64);
init_rand_seed(&td->poisson_state, td->rand_seeds[FIO_RAND_POISSON_OFF], 0);
init_rand_seed(&td->dedupe_state, td->rand_seeds[FIO_DEDUPE_OFF], false);
init_rand_seed(&td->zone_state, td->rand_seeds[FIO_RAND_ZONE_OFF], false);
if (!td_random(td))
return;
if (td->o.rand_repeatable)
td->rand_seeds[FIO_RAND_BLOCK_OFF] = FIO_RANDSEED * td->thread_number;
init_rand_seed(&td->random_state, td->rand_seeds[FIO_RAND_BLOCK_OFF], use64);
for (i = 0; i < DDIR_RWDIR_CNT; i++) {
struct frand_state *s = &td->seq_rand_state[i];
init_rand_seed(s, td->rand_seeds[FIO_RAND_SEQ_RAND_READ_OFF], false);
}
}
void td_fill_rand_seeds(struct thread_data *td)
{
bool use64;
if (td->o.allrand_repeatable) {
unsigned int i;
for (i = 0; i < FIO_RAND_NR_OFFS; i++)
td->rand_seeds[i] = FIO_RANDSEED * td->thread_number
+ i;
}
if (td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE64)
use64 = 1;
else
use64 = 0;
td_fill_rand_seeds_internal(td, use64);
init_rand_seed(&td->buf_state, td->rand_seeds[FIO_RAND_BUF_OFF], use64);
frand_copy(&td->buf_state_prev, &td->buf_state);
}
/*
* Initializes the ioengine configured for a job, if it has not been done so
* already.
*/