summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2020-08-19 13:02:42 -0600
committerJens Axboe <axboe@kernel.dk>2020-08-19 13:02:42 -0600
commite711df54082b5d2d739e9ee3e46a2bc23b1b3c7c (patch)
treea72818a6940905cdc481a191d5aaddeb93b02032
parent4b5da010ac92c99dc455bacc2d60620236528f89 (diff)
downloadfio-e711df54082b5d2d739e9ee3e46a2bc23b1b3c7c.tar.gz
fio-e711df54082b5d2d739e9ee3e46a2bc23b1b3c7c.tar.bz2
file: provider fio_file_free() helper
Since we have two spots, provide a helper to do the freeing. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--file.h1
-rw-r--r--filesetup.c28
-rw-r--r--init.c15
3 files changed, 17 insertions, 27 deletions
diff --git a/file.h b/file.h
index 5e2ef998..493ec04a 100644
--- a/file.h
+++ b/file.h
@@ -231,5 +231,6 @@ extern void fio_file_reset(struct thread_data *, struct fio_file *);
extern bool fio_files_done(struct thread_data *);
extern bool exists_and_not_regfile(const char *);
extern int fio_set_directio(struct thread_data *, struct fio_file *);
+extern void fio_file_free(struct fio_file *);
#endif
diff --git a/filesetup.c b/filesetup.c
index a1c60445..d382fa24 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -1445,6 +1445,19 @@ void close_files(struct thread_data *td)
}
}
+void fio_file_free(struct fio_file *f)
+{
+ if (fio_file_axmap(f))
+ axmap_free(f->io_axmap);
+ if (!fio_file_smalloc(f)) {
+ free(f->file_name);
+ free(f);
+ } else {
+ sfree(f->file_name);
+ sfree(f);
+ }
+}
+
void close_and_free_files(struct thread_data *td)
{
struct fio_file *f;
@@ -1469,20 +1482,7 @@ void close_and_free_files(struct thread_data *td)
}
zbd_close_file(f);
-
- if (!fio_file_smalloc(f))
- free(f->file_name);
- else
- sfree(f->file_name);
- f->file_name = NULL;
- if (fio_file_axmap(f)) {
- axmap_free(f->io_axmap);
- f->io_axmap = NULL;
- }
- if (!fio_file_smalloc(f))
- free(f);
- else
- sfree(f);
+ fio_file_free(f);
}
td->o.filename = NULL;
diff --git a/init.c b/init.c
index 3073c2a0..491b46e6 100644
--- a/init.c
+++ b/init.c
@@ -1735,19 +1735,8 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num,
if (file_alloced) {
if (td_new->files) {
struct fio_file *f;
- for_each_file(td_new, f, i) {
- bool use_smalloc = fio_file_smalloc(f);
- if (f->file_name) {
- if (use_smalloc)
- sfree(f->file_name);
- else
- free(f->file_name);
- }
- if (use_smalloc)
- sfree(f);
- else
- free(f);
- }
+ for_each_file(td_new, f, i)
+ fio_file_free(f);
free(td_new->files);
td_new->files = NULL;
}