X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=filesetup.c;h=212a126b94aed73c83319763298f573051af4413;hb=c61a3a44b63cf9d0d1d5d511e196ab4f3153341d;hp=aee7ece9da3a8829fedc0884dfff3f0bb00ca182;hpb=e13c3b50a1aa156223b5b9d20ed3d38dd4292479;p=fio.git diff --git a/filesetup.c b/filesetup.c index aee7ece9..212a126b 100644 --- a/filesetup.c +++ b/filesetup.c @@ -65,7 +65,9 @@ static int extend_file(struct thread_data *td, struct fio_file *f) } } - flags = O_WRONLY | O_CREAT; + flags = O_WRONLY; + if (td->o.allow_create) + flags |= O_CREAT; if (new_layout) flags |= O_TRUNC; @@ -76,7 +78,13 @@ static int extend_file(struct thread_data *td, struct fio_file *f) dprint(FD_FILE, "open file %s, flags %x\n", f->file_name, flags); f->fd = open(f->file_name, flags, 0644); if (f->fd < 0) { - td_verror(td, errno, "open"); + int err = errno; + + if (err == ENOENT && !td->o.allow_create) + log_err("fio: file creation disallowed by " + "allow_file_create=0\n"); + else + td_verror(td, err, "open"); return 1; } @@ -259,11 +267,13 @@ error: static unsigned long long get_rand_file_size(struct thread_data *td) { unsigned long long ret, sized; + uint64_t frand_max; unsigned long r; + frand_max = rand_max(&td->file_size_state); r = __rand(&td->file_size_state); sized = td->o.file_size_high - td->o.file_size_low; - ret = (unsigned long long) ((double) sized * (r / (FRAND_MAX + 1.0))); + ret = (unsigned long long) ((double) sized * (r / (frand_max + 1.0))); ret += td->o.file_size_low; ret -= (ret % td->o.rw_min_bs); return ret; @@ -539,7 +549,7 @@ int generic_open_file(struct thread_data *td, struct fio_file *f) } if (td->o.sync_io) flags |= O_SYNC; - if (td->o.create_on_open) + if (td->o.create_on_open && td->o.allow_create) flags |= O_CREAT; skip_flags: if (f->filetype != FIO_TYPE_FILE) @@ -550,7 +560,7 @@ open_again: if (!read_only) flags |= O_RDWR; - if (f->filetype == FIO_TYPE_FILE) + if (f->filetype == FIO_TYPE_FILE && td->o.allow_create) flags |= O_CREAT; if (is_std) @@ -722,7 +732,7 @@ static unsigned long long get_fs_free_counts(struct thread_data *td) fm = flist_entry(n, struct fio_mount, list); flist_del(&fm->list); - sz = get_fs_size(fm->base); + sz = get_fs_free_size(fm->base); if (sz && sz != -1ULL) ret += sz; @@ -1057,6 +1067,16 @@ int init_random_map(struct thread_data *td) blocks = fsize / (unsigned long long) td->o.rw_min_bs; + if (blocks > FRAND32_MAX && + td->o.random_generator == FIO_RAND_GEN_TAUSWORTHE && + !fio_option_is_set(&td->o, random_generator)) { + log_err("fio: file %s exceeds 32-bit tausworthe " + "random generator. Use lfsr or " + "tausworthe64.\n", f->file_name); + td_verror(td, EINVAL, "init file random"); + return 1; + } + if (td->o.random_generator == FIO_RAND_GEN_LFSR) { unsigned long seed;