filesetup: ensure that we catch a file flagged for extend
[fio.git] / filesetup.c
index 75136ff32fcc7e4409746a981d09f12b79313aef..f32d874c66c86e35b1fcba0b9d16be09102bcd5b 100644 (file)
@@ -264,7 +264,7 @@ error:
        return ret;
 }
 
-static unsigned long long get_rand_file_size(struct thread_data *td)
+unsigned long long get_rand_file_size(struct thread_data *td)
 {
        unsigned long long ret, sized;
        uint64_t frand_max;
@@ -329,7 +329,7 @@ static int char_size(struct thread_data *td, struct fio_file *f)
        int r;
 
        if (td->io_ops->open_file(td, f)) {
-               log_err("fio: failed opening blockdev %s for size check\n",
+               log_err("fio: failed opening chardev %s for size check\n",
                        f->file_name);
                return 1;
        }
@@ -414,7 +414,7 @@ static int __file_invalidate_cache(struct thread_data *td, struct fio_file *f,
                        errval = ret;
        } else if (f->filetype == FIO_TYPE_FILE) {
                ret = posix_fadvise(f->fd, off, len, POSIX_FADV_DONTNEED);
-               if (ret < 0)
+               if (ret)
                        errval = ret;
        } else if (f->filetype == FIO_TYPE_BD) {
                int retry_count = 0;
@@ -809,6 +809,7 @@ int setup_files(struct thread_data *td)
         */
        total_size = 0;
        for_each_file(td, f, i) {
+               f->fileno = i;
                if (f->real_file_size == -1ULL)
                        total_size = -1ULL;
                else
@@ -889,19 +890,22 @@ int setup_files(struct thread_data *td)
                if (f->io_size == -1ULL)
                        total_size = -1ULL;
                else {
-                        if (o->size_percent)
-                                f->io_size = (f->io_size * o->size_percent) / 100;
+                        if (o->size_percent) {
+                               f->io_size = (f->io_size * o->size_percent) / 100;
+                               f->io_size -= (f->io_size % td_min_bs(td));
+                       }
                        total_size += f->io_size;
                }
 
                if (f->filetype == FIO_TYPE_FILE &&
                    (f->io_size + f->file_offset) > f->real_file_size &&
                    !(td->io_ops->flags & FIO_DISKLESSIO)) {
-                       if (!o->create_on_open) {
-                               need_extend++;
+                       if (!o->create_on_open)
                                extend_size += (f->io_size + f->file_offset);
-                       else
+                       else
                                f->real_file_size = f->io_size + f->file_offset;
+
+                       need_extend++;
                        fio_file_set_extend(f);
                }
        }
@@ -1218,10 +1222,12 @@ static void get_file_type(struct fio_file *f)
        else
                f->filetype = FIO_TYPE_FILE;
 
+#ifdef WIN32
        /* \\.\ is the device namespace in Windows, where every file is
         * a block device */
        if (strncmp(f->file_name, "\\\\.\\", 4) == 0)
                f->filetype = FIO_TYPE_BD;
+#endif
 
        if (!stat(f->file_name, &sb)) {
                if (S_ISBLK(sb.st_mode))
@@ -1328,7 +1334,8 @@ int add_file(struct thread_data *td, const char *fname, int numjob, int inc)
        dprint(FD_FILE, "add file %s\n", fname);
 
        if (td->o.directory)
-               len = set_name_idx(file_name, PATH_MAX, td->o.directory, numjob);
+               len = set_name_idx(file_name, PATH_MAX, td->o.directory, numjob,
+                                       td->o.unique_filename);
 
        sprintf(file_name + len, "%s", fname);