filesetup: print warning if chosen random generator can't cover range
[fio.git] / filesetup.c
index aee7ece9da3a8829fedc0884dfff3f0bb00ca182..51efdf768d3068b1ac6a895b03adfaa4678f54c6 100644 (file)
@@ -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)
@@ -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;