[PATCH] File close fix
[fio.git] / filesetup.c
index 0b9564044d14135d662363219471c674c2670714..705eb4a90cb3b12a2b98802718a1d5c3584c7ac5 100644 (file)
@@ -49,12 +49,12 @@ static int create_file(struct thread_data *td, struct fio_file *f)
                goto err;
        }
 
-       b = malloc(td->max_bs);
-       memset(b, 0, td->max_bs);
+       b = malloc(td->max_bs[DDIR_WRITE]);
+       memset(b, 0, td->max_bs[DDIR_WRITE]);
 
        left = f->file_size;
        while (left && !td->terminate) {
-               bs = td->max_bs;
+               bs = td->max_bs[DDIR_WRITE];
                if (bs > left)
                        bs = left;
 
@@ -93,15 +93,14 @@ static int create_files(struct thread_data *td)
        struct fio_file *f;
        int i, err, need_create;
 
+       for_each_file(td, f, i)
+               f->file_size = td->total_file_size / td->nr_files;
+
        /*
         * unless specifically asked for overwrite, let normal io extend it
         */
-       if (!td->overwrite) {
-               for_each_file(td, f, i)
-                       f->file_size = td->total_file_size / td->nr_files;
-
+       if (!td->overwrite)
                return 0;
-       }
 
        need_create = 0;
        if (td->filetype == FIO_TYPE_FILE)
@@ -409,22 +408,22 @@ void close_files(struct thread_data *td)
 
        for_each_file(td, f, i) {
                if (f->fd != -1) {
-                       if (td->unlink && td->filetype == FIO_TYPE_FILE &&
-                           td->filename) {
-                               unlink(f->file_name);
-                               td->filename = NULL;
-                       }
-                       free(f->file_name);
-                       f->file_name = NULL;
+                       file_invalidate_cache(td, f);
                        close(f->fd);
                        f->fd = -1;
                }
+               if (td->unlink && td->filetype == FIO_TYPE_FILE) {
+                       unlink(f->file_name);
+                       free(f->file_name);
+                       f->file_name = NULL;
+               }
                if (f->mmap) {
                        munmap(f->mmap, f->file_size);
                        f->mmap = NULL;
                }
        }
 
+       td->filename = NULL;
        free(td->files);
        td->files = NULL;
        td->nr_files = 0;