From: Jens Axboe Date: Sat, 1 Mar 2008 17:04:31 +0000 (+0100) Subject: Make file structures dynamically allocated X-Git-Tag: fio-1.20-rc1~24 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=126d65c6fc97d6acdc568aa5a969c012018daf15;hp=4c3ecec4160909d7eba4acf1a07a8a0cd36a6365 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 --- diff --git a/engines/sg.c b/engines/sg.c index c50ad55d..72bbc4e8 100644 --- a/engines/sg.c +++ b/engines/sg.c @@ -277,7 +277,7 @@ static int fio_sgio_get_bs(struct thread_data *td, unsigned int *bs) 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 c0403d2a..483226ae 100644 --- a/filesetup.c +++ b/filesetup.c @@ -585,12 +585,14 @@ int add_file(struct thread_data *td, const char *fname) 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 92819349..ca35ffcd 100644 --- a/fio.h +++ b/fio.h @@ -498,7 +498,7 @@ struct thread_data { 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 @@ extern void close_ioengine(struct thread_data *); #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 0ffae29c..0f455cfd 100644 --- a/io_u.c +++ b/io_u.c @@ -561,7 +561,7 @@ static struct fio_file *get_next_file_rand(struct thread_data *td, int goodf, 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 @@ static struct fio_file *get_next_file_rr(struct thread_data *td, int goodf, 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 8754eb05..f6fbaeb2 100644 --- a/log.c +++ b/log.c @@ -65,7 +65,7 @@ int read_iolog_get(struct thread_data *td, struct io_u *io_u) * 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 @@ int read_iolog_get(struct thread_data *td, struct io_u *io_u) 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,