Make file structures dynamically allocated
authorJens Axboe <jens.axboe@oracle.com>
Sat, 1 Mar 2008 17:04:31 +0000 (18:04 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Sat, 1 Mar 2008 17:04:31 +0000 (18:04 +0100)
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>
engines/sg.c
filesetup.c
fio.h
io_u.c
log.c

index c50ad55d764ee3a408f09bbe3637c5eac81ea39c..72bbc4e82b99c9d8666f4c875fb0c1bf6f95d8e8 100644 (file)
@@ -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);
        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;
        assert(io_u);
 
        hdr = &io_u->hdr;
index c0403d2a801e863df927ed87a2a935161c7cb394..483226ae56e5d488d4601a14c1ba29b93f91d360 100644 (file)
@@ -585,12 +585,14 @@ int add_file(struct thread_data *td, const char *fname)
 
        dprint(FD_FILE, "add file %s\n", 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;
 
        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
         */
        /*
         * init function, io engine may not be loaded yet
         */
diff --git a/fio.h b/fio.h
index 92819349dabedde6c95d69d8f843edb1a1078d11..ca35ffcd5e7884c8fce02f9ad741b45bb8a67e10 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -498,7 +498,7 @@ struct thread_data {
        int thread_number;
        int groupid;
        struct thread_stat ts;
        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;
        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)        \
 #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)) {                  \
 
 #define fio_assert(td, cond)   do {    \
        if (!(cond)) {                  \
diff --git a/io_u.c b/io_u.c
index 0ffae29c9f035a2d387ad00b0ae7d882ac0515b3..0f455cfd916d7ac5c8c6b3a69f7d83f66c8a24a3 100644 (file)
--- 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)));
                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;
 
                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 {
        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)
 
                td->next_file++;
                if (td->next_file >= td->o.nr_files)
diff --git a/log.c b/log.c
index 8754eb051a1ecfb3ba38290b8d88d5a6bb547c8a..f6fbaeb26c7e1c023055ada3252bf59201cc32c1 100644 (file)
--- 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) {
                 * 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));
 
                        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->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,
                get_file(io_u->file);
 
                dprint(FD_IO, "iolog: get %llu/%lu/%s\n", io_u->offset,