X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=init.c;h=e794b3720c3dc1813c7018bd86e586bfa8dc4697;hp=cf00bb1abc1e58dafe3d24a6b48845489c99cc75;hb=9c60ce649d3f976d196709d4399bb7c540ce97b5;hpb=7837213b66e20a8d91e7069f5823852f42c41440 diff --git a/init.c b/init.c index cf00bb1a..e794b372 100644 --- a/init.c +++ b/init.c @@ -97,7 +97,7 @@ static struct fio_option options[] = { { .ival = "randwrite", .oval = TD_DDIR_RANDWRITE, .help = "Random write", - }, + }, { .ival = "rw", .oval = TD_DDIR_RW, .help = "Sequential read and write mix", @@ -183,7 +183,14 @@ static struct fio_option options[] = { .name = "size", .type = FIO_OPT_STR_VAL, .off1 = td_var_offset(total_file_size), - .help = "Size of device or file", + .help = "Total size of device or files", + }, + { + .name = "filesize", + .type = FIO_OPT_STR_VAL, + .off1 = td_var_offset(file_size_low), + .off2 = td_var_offset(file_size_high), + .help = "Size of individual files", }, { .name = "bs", @@ -355,7 +362,7 @@ static struct fio_option options[] = { .name = "verify", .type = FIO_OPT_STR, .off1 = td_var_offset(verify), - .help = "Verify sum function", + .help = "Verify data written", .def = "0", .posval = { { .ival = "0", @@ -696,7 +703,7 @@ static struct option long_options[FIO_JOB_OPTS + FIO_CMD_OPTS] = { static int def_timeout = 0; -static char fio_version_string[] = "fio 1.14"; +static char fio_version_string[] = "fio 1.14a"; static char **ini_file; static int max_jobs = MAX_JOBS; @@ -801,6 +808,9 @@ static void fixup_options(struct thread_data *td) td->rw_min_bs = min(td->min_bs[DDIR_READ], td->min_bs[DDIR_WRITE]); + if (!td->file_size_high) + td->file_size_high = td->file_size_low; + if (td_read(td) && !td_rw(td)) td->verify = 0; @@ -880,6 +890,78 @@ static const char *get_engine_name(const char *str) return p; } +static int exists_and_not_file(const char *filename) +{ + struct stat sb; + + if (lstat(filename, &sb) == -1) + return 0; + + if (S_ISREG(sb.st_mode)) + return 0; + + return 1; +} + +/* + * Initialize the various random states we need (random io, block size ranges, + * read/write mix, etc). + */ +static int init_random_state(struct thread_data *td) +{ + unsigned long seeds[6]; + int fd, num_maps, blocks; + struct fio_file *f; + unsigned int i; + + fd = open("/dev/urandom", O_RDONLY); + if (fd == -1) { + td_verror(td, errno, "open"); + return 1; + } + + if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) { + td_verror(td, EIO, "read"); + close(fd); + return 1; + } + + close(fd); + + os_random_seed(seeds[0], &td->bsrange_state); + os_random_seed(seeds[1], &td->verify_state); + os_random_seed(seeds[2], &td->rwmix_state); + + if (td->file_service_type == FIO_FSERVICE_RANDOM) + os_random_seed(seeds[3], &td->next_file_state); + + os_random_seed(seeds[5], &td->file_size_state); + + if (!td_random(td)) + return 0; + + if (td->rand_repeatable) + seeds[4] = FIO_RANDSEED * td->thread_number; + + if (!td->norandommap) { + for_each_file(td, f, i) { + blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs; + num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP; + f->file_map = malloc(num_maps * sizeof(long)); + if (!f->file_map) { + log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n"); + return 1; + } + f->num_maps = num_maps; + memset(f->file_map, 0, num_maps * sizeof(long)); + } + } + + os_random_seed(seeds[4], &td->random_state); + return 0; +} + + /* * Adds a job to the list of things todo. Sanitizes the various options * to make sure we don't have conflicts, and initializes various @@ -893,7 +975,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) struct fio_file *f; const char *engine; char fname[PATH_MAX]; - int numjobs; + int numjobs, file_alloced; /* * the def_thread is just for options, it's not a real job @@ -916,14 +998,15 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) if (td->odirect) td->io_ops->flags |= FIO_RAWIO; + file_alloced = 0; if (!td->filename && !td->files_index) { - td->filename = strdup(jobname); + file_alloced = 1; - if (td->nr_files == 1) - add_file(td, td->filename); + if (td->nr_files == 1 && exists_and_not_file(jobname)) + add_file(td, jobname); else { for (i = 0; i < td->nr_files; i++) { - sprintf(fname, "%s.%d.%d", td->filename, td->thread_number, i); + sprintf(fname, "%s.%d.%d", jobname, td->thread_number, i); add_file(td, fname); } } @@ -952,6 +1035,9 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) td->groupid = groupid; prev_group_jobs++; + if (init_random_state(td)) + goto err; + if (setup_rate(td)) goto err; @@ -1001,6 +1087,13 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) td_new->numjobs = 1; td_new->stonewall = 0; + + if (file_alloced) { + td_new->filename = NULL; + td_new->files_index = 0; + td_new->files = NULL; + } + job_add_num = numjobs - 1; if (add_job(td_new, jobname, job_add_num)) @@ -1018,65 +1111,6 @@ err: return -1; } -/* - * Initialize the various random states we need (random io, block size ranges, - * read/write mix, etc). - */ -int init_random_state(struct thread_data *td) -{ - unsigned long seeds[5]; - int fd, num_maps, blocks; - struct fio_file *f; - unsigned int i; - - if (td->io_ops->flags & FIO_DISKLESSIO) - return 0; - - fd = open("/dev/urandom", O_RDONLY); - if (fd == -1) { - td_verror(td, errno, "open"); - return 1; - } - - if (read(fd, seeds, sizeof(seeds)) < (int) sizeof(seeds)) { - td_verror(td, EIO, "read"); - close(fd); - return 1; - } - - close(fd); - - os_random_seed(seeds[0], &td->bsrange_state); - os_random_seed(seeds[1], &td->verify_state); - os_random_seed(seeds[2], &td->rwmix_state); - - if (td->file_service_type == FIO_FSERVICE_RANDOM) - os_random_seed(seeds[3], &td->next_file_state); - - if (!td_random(td)) - return 0; - - if (td->rand_repeatable) - seeds[4] = FIO_RANDSEED * td->thread_number; - - if (!td->norandommap) { - for_each_file(td, f, i) { - blocks = (f->real_file_size + td->rw_min_bs - 1) / td->rw_min_bs; - num_maps = (blocks + BLOCKS_PER_MAP-1)/ BLOCKS_PER_MAP; - f->file_map = malloc(num_maps * sizeof(long)); - if (!f->file_map) { - log_err("fio: failed allocating random map. If running a large number of jobs, try the 'norandommap' option\n"); - return 1; - } - f->num_maps = num_maps; - memset(f->file_map, 0, num_maps * sizeof(long)); - } - } - - os_random_seed(seeds[4], &td->random_state); - return 0; -} - static void fill_cpu_mask(os_cpu_mask_t cpumask, int cpu) { #ifdef FIO_HAVE_CPU_AFFINITY