From b5f4d8baefc6eb3e13235b7d9042b7ffecdb23dd Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 20 Mar 2014 08:28:11 -0600 Subject: [PATCH] Unlink after file close MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Sébastien reports: I'm having an issue on windows : unlink=1 is not working (temp file are still there) and it's working fine on unix Looking at the code in close_and_free_files function : [...] if (td->o.unlink && f->filetype == FIO_TYPE_FILE) { dprint(FD_FILE, "free unlink %s\n", f->file_name); unlink(f->file_name); } [...] Unlink() fails because the file is still open : On Solaris, truss shows the following : [...] write(3, "\0\0\0\0\0 ;80\0\0\0\0\0".., 32768) = 32768 unlink("/data/fio/random_rw.0.0") = 0 close(3) = 0 [...] So unlink is called first. I would put this unlinking phase AFTER the remove_file_hash call. Signed-off-by: Jens Axboe --- filesetup.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/filesetup.c b/filesetup.c index c3c0fc4b..9c03a626 100644 --- a/filesetup.c +++ b/filesetup.c @@ -1057,16 +1057,16 @@ void close_and_free_files(struct thread_data *td) dprint(FD_FILE, "close files\n"); for_each_file(td, f, i) { - if (td->o.unlink && f->filetype == FIO_TYPE_FILE) { - dprint(FD_FILE, "free unlink %s\n", f->file_name); - unlink(f->file_name); - } - if (fio_file_open(f)) td_io_close_file(td, f); remove_file_hash(f); + if (td->o.unlink && f->filetype == FIO_TYPE_FILE) { + dprint(FD_FILE, "free unlink %s\n", f->file_name); + unlink(f->file_name); + } + sfree(f->file_name); f->file_name = NULL; axmap_free(f->io_axmap); -- 2.25.1