Merge branch 'wip-rbd-engine-tweaks' of https://github.com/dillaman/fio
[fio.git] / filesetup.c
index 8a4091fcc25420325f6bb1779dfffa0853f8ee2e..d3c370ca49613805876d70e252d61f6b1b806e44 100644 (file)
@@ -231,13 +231,12 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
                                                break;
                                        log_info("fio: ENOSPC on laying out "
                                                 "file, stopping\n");
-                                       break;
                                }
                                td_verror(td, errno, "write");
                        } else
                                td_verror(td, EIO, "write");
 
-                       break;
+                       goto err;
                }
        }
 
@@ -655,8 +654,7 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
                }
                flags |= OS_O_DIRECT | FIO_O_ATOMIC;
        }
-       if (td->o.sync_io)
-               flags |= O_SYNC;
+       flags |= td->o.sync_io;
        if (td->o.create_on_open && td->o.allow_create)
                flags |= O_CREAT;
 skip_flags:
@@ -1139,6 +1137,8 @@ int setup_files(struct thread_data *td)
                if (f->io_size == -1ULL)
                        total_size = -1ULL;
                else {
+                       uint64_t io_size;
+
                         if (o->size_percent && o->size_percent != 100) {
                                uint64_t file_size;
 
@@ -1150,7 +1150,14 @@ int setup_files(struct thread_data *td)
 
                                f->io_size -= (f->io_size % td_min_bs(td));
                        }
-                       total_size += f->io_size;
+
+                       io_size = f->io_size;
+                       if (o->io_size_percent && o->io_size_percent != 100) {
+                               io_size *= o->io_size_percent;
+                               io_size /= 100;
+                       }
+
+                       total_size += io_size;
                }
 
                if (f->filetype == FIO_TYPE_FILE &&
@@ -1192,7 +1199,7 @@ int setup_files(struct thread_data *td)
                o->size = total_size;
 
        if (o->size < td_min_bs(td)) {
-               log_err("fio: blocksize too large for data set\n");
+               log_err("fio: blocksize is larger than data set range\n");
                goto err_out;
        }
 
@@ -1268,7 +1275,7 @@ done:
        td_restore_runstate(td, old_state);
 
        if (td->o.zone_mode == ZONE_MODE_ZBD) {
-               err = zbd_init(td);
+               err = zbd_setup_files(td);
                if (err)
                        goto err_out;
        }
@@ -1445,11 +1452,23 @@ void close_files(struct thread_data *td)
        }
 }
 
+void fio_file_free(struct fio_file *f)
+{
+       if (fio_file_axmap(f))
+               axmap_free(f->io_axmap);
+       if (!fio_file_smalloc(f)) {
+               free(f->file_name);
+               free(f);
+       } else {
+               sfree(f->file_name);
+               sfree(f);
+       }
+}
+
 void close_and_free_files(struct thread_data *td)
 {
        struct fio_file *f;
        unsigned int i;
-       bool use_free = td_ioengine_flagged(td, FIO_NOFILEHASH);
 
        dprint(FD_FILE, "close files\n");
 
@@ -1469,21 +1488,8 @@ void close_and_free_files(struct thread_data *td)
                        td_io_unlink_file(td, f);
                }
 
-               zbd_free_zone_info(f);
-
-               if (use_free)
-                       free(f->file_name);
-               else
-                       sfree(f->file_name);
-               f->file_name = NULL;
-               if (fio_file_axmap(f)) {
-                       axmap_free(f->io_axmap);
-                       f->io_axmap = NULL;
-               }
-               if (use_free)
-                       free(f);
-               else
-                       sfree(f);
+               zbd_close_file(f);
+               fio_file_free(f);
        }
 
        td->o.filename = NULL;
@@ -1609,6 +1615,8 @@ static struct fio_file *alloc_new_file(struct thread_data *td)
        f->fd = -1;
        f->shadow_fd = -1;
        fio_file_reset(td, f);
+       if (!td_ioengine_flagged(td, FIO_NOFILEHASH))
+               fio_file_set_smalloc(f);
        return f;
 }