Fix bug with numjobs > 1, directory and filename given
[fio.git] / filesetup.c
index 7828dc25c751c705f729d411766404d77e5d5eaa..f6e2a19c19b74a0fa175b710440c699712344466 100644 (file)
@@ -178,7 +178,7 @@ static int create_files(struct thread_data *td)
         * unless specifically asked for overwrite, let normal io extend it
         */
        can_extend = !td->o.overwrite && !(td->io_ops->flags & FIO_NOEXTEND);
-       if (can_extend) {
+       if (can_extend && new_files) {
                for_each_file(td, f, i) {
                        if (fill_file_size(td, f, &total_file_size, new_files)) {
                                log_info("fio: limited to %d files\n", i);
@@ -384,9 +384,12 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
        }
 
        if (f->fd == -1) {
+               char buf[FIO_VERROR_SIZE];
                int __e = errno;
 
-               td_verror(td, __e, "open");
+               snprintf(buf, sizeof(buf) - 1, "open(%s)", f->file_name);
+
+               td_verror(td, __e, buf);
                if (__e == EINVAL && td->o.odirect)
                        log_err("fio: destination does not support O_DIRECT\n");
                if (__e == EMFILE)
@@ -400,6 +403,9 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
        if (td->o.invalidate_cache && file_invalidate_cache(td, f))
                goto err;
 
+       if (!td->o.fadvise_hint)
+               return 0;
+
        if (!td_random(td)) {
                if (fadvise(f->fd, f->file_offset, f->file_size, POSIX_FADV_SEQUENTIAL) < 0) {
                        td_verror(td, errno, "fadvise");
@@ -526,8 +532,10 @@ void close_files(struct thread_data *td)
 
                td_io_close_file(td, f);
 
-               if (f->file_map)
+               if (f->file_map) {
                        free(f->file_map);
+                       f->file_map = NULL;
+               }
        }
 
        td->o.filename = NULL;
@@ -561,14 +569,21 @@ static void get_file_type(struct fio_file *f)
 void add_file(struct thread_data *td, const char *fname)
 {
        int cur_files = td->files_index;
+       char file_name[PATH_MAX];
        struct fio_file *f;
+       int len = 0;
 
        td->files = realloc(td->files, (cur_files + 1) * sizeof(*f));
 
        f = &td->files[cur_files];
        memset(f, 0, sizeof(*f));
        f->fd = -1;
-       f->file_name = strdup(fname);
+
+       if (td->o.directory)
+               len = sprintf(file_name, "%s/", td->o.directory);
+
+       sprintf(file_name + len, "%s", fname);
+       f->file_name = strdup(file_name);
 
        get_file_type(f);