Dump actual filename in failure to open
[fio.git] / filesetup.c
index 08155db1ac256d238175dd96d56afc050e455538..daae33ff47e36e2357082721f26c93ea82e7ef9d 100644 (file)
@@ -157,8 +157,14 @@ static int create_files(struct thread_data *td)
 
                if (f->filetype != FIO_TYPE_FILE)
                        continue;
+               if (!total_file_size)
+                       continue;
 
                if (f->flags & FIO_FILE_EXISTS) {
+                       if ((f->file_size > td->o.size / td->o.nr_files) ||
+                           !f->file_size)
+                               f->file_size = td->o.size / td->o.nr_files;
+
                        s = f->file_size;
                        if (s > total_file_size)
                                s = total_file_size;
@@ -172,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);
@@ -378,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)
@@ -520,8 +529,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;