file: provider fio_file_free() helper
authorJens Axboe <axboe@kernel.dk>
Wed, 19 Aug 2020 19:02:42 +0000 (13:02 -0600)
committerJens Axboe <axboe@kernel.dk>
Wed, 19 Aug 2020 19:02:42 +0000 (13:02 -0600)
Since we have two spots, provide a helper to do the freeing.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
file.h
filesetup.c
init.c

diff --git a/file.h b/file.h
index 5e2ef99851a2f33308c4cb96a8bcf7af64923233..493ec04a6677e90f6c0d0182e0b082b31302451f 100644 (file)
--- 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
index a1c60445cc1bb4863ece64c8be935d68f3da91d1..d382fa24195331c10c2b1cf015ee3007524f7853 100644 (file)
@@ -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 3073c2a0f52caeb79197a56f8e1e506e0c864dcd..491b46e6c70c3d0c319e4bf8d06fecf0233a8c55 100644 (file)
--- 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;
                        }