Overwrite fix
[fio.git] / filesetup.c
index af14c6760566e53a786ce46a1ba78996edd9505e..48b034a6b4f83d4913e94a19a72611e8d1755e80 100644 (file)
@@ -98,7 +98,7 @@ err:
 static int create_files(struct thread_data *td)
 {
        struct fio_file *f;
-       int i, err, need_create;
+       int i, err, need_create, can_extend;
 
        for_each_file(td, f, i)
                f->file_size = td->total_file_size / td->nr_files;
@@ -106,7 +106,8 @@ static int create_files(struct thread_data *td)
        /*
         * unless specifically asked for overwrite, let normal io extend it
         */
-       if (!td->overwrite)
+       can_extend = !td->overwrite && !(td->io_ops->flags & FIO_NOEXTEND);
+       if (can_extend)
                return 0;
 
        need_create = 0;
@@ -225,8 +226,6 @@ int file_invalidate_cache(struct thread_data *td, struct fio_file *f)
 {
        int ret = 0;
 
-       if (!td->invalidate_cache)
-               return 0;
        if (td->odirect)
                return 0;
 
@@ -268,12 +267,8 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
        if (td_write(td) || td_rw(td)) {
                flags |= O_RDWR;
 
-               if (td->filetype == FIO_TYPE_FILE) {
-                       if (!td->overwrite)
-                               flags |= O_TRUNC;
-
+               if (td->filetype == FIO_TYPE_FILE)
                        flags |= O_CREAT;
-               }
 
                f->fd = open(f->file_name, flags, 0600);
        } else {
@@ -297,7 +292,7 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
        if (get_file_size(td, f))
                goto err;
 
-       if (file_invalidate_cache(td, f))
+       if (td->invalidate_cache && file_invalidate_cache(td, f))
                goto err;
 
        if (!td_random(td)) {
@@ -401,6 +396,9 @@ void close_files(struct thread_data *td)
                }
 
                td_io_close_file(td, f);
+
+               if (f->file_map)
+                       free(f->file_map);
        }
 
        td->filename = NULL;