Make file structures dynamically allocated
Current td->files is an array of files, make it an array of pointers
instead and allocate individual file structures on the fly. This is
a preparation patch for file sharing.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/engines/sg.c b/engines/sg.c
index c50ad55..72bbc4e 100644
--- a/engines/sg.c
+++ b/engines/sg.c
@@ -277,7 +277,7 @@
int ret;
io_u = __get_io_u(td);
- io_u->file = &td->files[0];
+ io_u->file = td->files[0];
assert(io_u);
hdr = &io_u->hdr;
diff --git a/filesetup.c b/filesetup.c
index c0403d2..483226a 100644
--- a/filesetup.c
+++ b/filesetup.c
@@ -585,12 +585,14 @@
dprint(FD_FILE, "add file %s\n", fname);
- td->files = realloc(td->files, (cur_files + 1) * sizeof(*f));
-
- f = &td->files[cur_files];
+ f = malloc(sizeof(*f));
memset(f, 0, sizeof(*f));
f->fd = -1;
+ td->files = realloc(td->files, (cur_files + 1) * sizeof(f));
+
+ td->files[cur_files] = f;
+
/*
* init function, io engine may not be loaded yet
*/
diff --git a/fio.h b/fio.h
index 9281934..ca35ffc 100644
--- a/fio.h
+++ b/fio.h
@@ -498,7 +498,7 @@
int thread_number;
int groupid;
struct thread_stat ts;
- struct fio_file *files;
+ struct fio_file **files;
unsigned int files_index;
unsigned int nr_open_files;
unsigned int nr_done_files;
@@ -941,7 +941,7 @@
#define for_each_td(td, i) \
for ((i) = 0, (td) = &threads[0]; (i) < (int) thread_number; (i)++, (td)++)
#define for_each_file(td, f, i) \
- for ((i) = 0, (f) = &(td)->files[0]; (i) < (td)->o.nr_files; (i)++, (f)++)
+ for ((i) = 0, (f) = (td)->files[0]; (i) < (td)->o.nr_files; (i)++, (f)++)
#define fio_assert(td, cond) do { \
if (!(cond)) { \
diff --git a/io_u.c b/io_u.c
index 0ffae29..0f455cf 100644
--- a/io_u.c
+++ b/io_u.c
@@ -561,7 +561,7 @@
long r = os_random_long(&td->next_file_state);
fno = (unsigned int) ((double) td->o.nr_files * (r / (RAND_MAX + 1.0)));
- f = &td->files[fno];
+ f = td->files[fno];
if (f->flags & FIO_FILE_DONE)
continue;
@@ -582,7 +582,7 @@
struct fio_file *f;
do {
- f = &td->files[td->next_file];
+ f = td->files[td->next_file];
td->next_file++;
if (td->next_file >= td->o.nr_files)
diff --git a/log.c b/log.c
index 8754eb0..f6fbaeb 100644
--- a/log.c
+++ b/log.c
@@ -65,7 +65,7 @@
* invalid ddir, this is a file action
*/
if (ipo->ddir == DDIR_INVAL) {
- struct fio_file *f = &td->files[ipo->fileno];
+ struct fio_file *f = td->files[ipo->fileno];
if (ipo->file_action == FIO_LOG_OPEN_FILE) {
assert(!td_io_open_file(td, f));
@@ -81,7 +81,7 @@
io_u->offset = ipo->offset;
io_u->buflen = ipo->len;
io_u->ddir = ipo->ddir;
- io_u->file = &td->files[ipo->fileno];
+ io_u->file = td->files[ipo->fileno];
get_file(io_u->file);
dprint(FD_IO, "iolog: get %llu/%lu/%s\n", io_u->offset,