[PATCH] Non-overwrite random write fix
[fio.git] / filesetup.c
index 21854a9739747bb1f5bd16d95e034116d5b7c170..75288706cdd2e09a8aa138a67d2d671668557e08 100644 (file)
@@ -117,14 +117,19 @@ static int create_files(struct thread_data *td)
        }
 
        temp_stall_ts = 1;
-       fprintf(f_out, "%s: Laying out IO file(s) (%d x %LuMiB == %LuMiB)\n",
+       fprintf(f_out, "%s: Laying out IO file(s) (%u x %LuMiB == %LuMiB)\n",
                                td->name, td->nr_uniq_files,
                                (td->total_file_size >> 20) / td->nr_uniq_files,
                                td->total_file_size >> 20);
 
        err = 0;
        for_each_file(td, f, i) {
+               /*
+                * Only unlink files that we created.
+                */
+               f->unlink = 0;
                if (file_ok(td, f)) {
+                       f->unlink = td->unlink;
                        err = create_file(td, f);
                        if (err)
                                break;
@@ -149,9 +154,9 @@ static int file_size(struct thread_data *td, struct fio_file *f)
 
                if (!f->file_size || f->file_size > f->real_file_size)
                        f->file_size = f->real_file_size;
-       }
+       } else
+               f->real_file_size = f->file_size;
 
-       f->file_size -= f->file_offset;
        return 0;
 }
 
@@ -434,7 +439,7 @@ void close_files(struct thread_data *td)
        int i;
 
        for_each_file(td, f, i) {
-               if (!td->filename && td->unlink &&
+               if (!td->filename && f->unlink &&
                    td->filetype == FIO_TYPE_FILE) {
                        unlink(f->file_name);
                        free(f->file_name);