[PATCH Various fixes
authorJens Axboe <jens.axboe@oracle.com>
Wed, 18 Oct 2006 12:10:42 +0000 (14:10 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Wed, 18 Oct 2006 12:10:42 +0000 (14:10 +0200)
- Multiple files fixes
- Fix for unaligned io issued for raw io

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
engines/fio-engine-sg.c
filesetup.c
fio.c
fio.h
init.c

index 0db5ca93ba48da4df51cdee77ec2409e855bf2ed..5337068bbb992d828d3e30e9a1b2979fdb41e85f 100644 (file)
@@ -326,5 +326,5 @@ struct ioengine_ops ioengine = {
        .event          = fio_sgio_event,
        .cleanup        = fio_sgio_cleanup,
        .sync           = fio_sgio_sync,
-       .flags          = FIO_SYNCIO,
+       .flags          = FIO_SYNCIO | FIO_RAWIO,
 };
index adfe940d1a0b89e1a09d7353dcea2ab28ab73b8c..e1afeb9a4bf552ff3b8fad4060f22ffdb6a9e696 100644 (file)
@@ -12,9 +12,21 @@ static int create_file(struct thread_data *td, struct fio_file *f)
 {
        unsigned long long left;
        unsigned int bs;
+       struct stat st;
        char *b;
        int r;
 
+       if (td->filetype != FIO_TYPE_FILE)
+               return 0;
+
+       if (stat(f->file_name, &st) == -1) {
+               if (!td->create_file) {
+                       td_verror(td, ENOENT);
+                       return 1;
+               }
+       } else if (st.st_size >= (off_t) f->file_size)
+               return 0;
+
        f->fd = open(f->file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644);
        if (f->fd < 0) {
                td_verror(td, errno);
@@ -95,6 +107,7 @@ static int create_files(struct thread_data *td)
        for_each_file(td, f, i) {
                f->file_size = td->total_file_size / td->nr_files;
                err = create_file(td, f);
+               if (err)
                        break;
 
                td->io_size += f->file_size;
@@ -267,26 +280,8 @@ static int setup_files_plain(struct thread_data *td)
 
 static int setup_file(struct thread_data *td, struct fio_file *f)
 {
-       struct stat st;
        int flags = 0;
 
-       if (stat(f->file_name, &st) == -1) {
-               if (errno != ENOENT) {
-                       td_verror(td, errno);
-                       return 1;
-               }
-               if (!td->create_file) {
-                       td_verror(td, ENOENT);
-                       return 1;
-               }
-               if (create_file(td, f))
-                       return 1;
-       } else if (td->filetype == FIO_TYPE_FILE &&
-                  st.st_size < (off_t) f->file_size) {
-               if (create_file(td, f))
-                       return 1;
-       }
-
        if (td->odirect)
                flags |= OS_O_DIRECT;
 
diff --git a/fio.c b/fio.c
index dc228a8764f11e667f8bdfd04d854d3fd5d0d15a..405346b6f310788728b4223d96ba9b5d7d9aa046 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -219,8 +219,16 @@ static unsigned int get_next_buflen(struct thread_data *td)
                buflen = (buflen + td->min_bs - 1) & ~(td->min_bs - 1);
        }
 
-       if (buflen > td->io_size - td->this_io_bytes[td->ddir])
+       if (buflen > td->io_size - td->this_io_bytes[td->ddir]) {
+               /*
+                * if using direct/raw io, we may not be able to
+                * shrink the size. so just fail it.
+                */
+               if (td->io_ops->flags & FIO_RAWIO)
+                       return 0;
+
                buflen = td->io_size - td->this_io_bytes[td->ddir];
+       }
 
        return buflen;
 }
@@ -526,8 +534,14 @@ static struct io_u *get_io_u(struct thread_data *td, struct fio_file *f)
                return NULL;
        }
 
-       if (io_u->buflen + io_u->offset > f->file_size)
+       if (io_u->buflen + io_u->offset > f->file_size) {
+               if (td->io_ops->flags & FIO_RAWIO) {
+                       put_io_u(td, io_u);
+                       return NULL;
+               }
+
                io_u->buflen = f->file_size - io_u->offset;
+       }
 
        if (!io_u->buflen) {
                put_io_u(td, io_u);
@@ -577,11 +591,21 @@ static int get_next_verify(struct thread_data *td, struct io_u *io_u)
 
 static struct fio_file *get_next_file(struct thread_data *td)
 {
-       struct fio_file *f = &td->files[td->next_file];
+       int old_next_file = td->next_file;
+       struct fio_file *f;
+
+       do {
+               f = &td->files[td->next_file];
+
+               td->next_file++;
+               if (td->next_file >= td->nr_files)
+                       td->next_file = 0;
+
+               if (f->fd != -1)
+                       break;
 
-       td->next_file++;
-       if (td->next_file >= td->nr_files)
-               td->next_file = 0;
+               f = NULL;
+       } while (td->next_file != old_next_file);
 
        return f;
 }
diff --git a/fio.h b/fio.h
index 915c0b5365417b33097accc8bcee8b14b37c5941..4be037e933ce9b490810f3a9be21df6e8fe2043b 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -131,6 +131,7 @@ enum fio_ioengine_flags {
        FIO_SYNCIO      = 1 << 0,
        FIO_CPUIO       = 1 << 1,
        FIO_MMAPIO      = 1 << 2,
+       FIO_RAWIO       = 1 << 3,
 };
 
 struct fio_file {
@@ -150,6 +151,8 @@ struct fio_file {
 
        unsigned long *file_map;
        unsigned int num_maps;
+
+       int fileno;
 };
 
 /*
@@ -504,6 +507,6 @@ extern void close_ioengine(struct thread_data *);
 #define fio_unused     __attribute((__unused__))
 
 #define for_each_file(td, f, i)        \
-       for ((i) = 0, (f) = &(td)->files[(i)]; (i) < (td)->nr_files; (i)++, (f) = &(td)->files[(i)])
+       for ((i) = 0, (f) = &(td)->files[0]; (i) < (td)->nr_files; (i)++, (f) = &(td)->files[(i)])
 
 #endif
diff --git a/init.c b/init.c
index 967f0b50589d1fe431599fba7f6a6c1e35645012..20dd625dfe3bb1a77b1209916f7b7dc754a19a37 100644 (file)
--- a/init.c
+++ b/init.c
@@ -163,6 +163,9 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                        td->filetype = FIO_TYPE_CHAR;
        }
 
+       if (td->odirect)
+               td->io_ops->flags |= FIO_RAWIO;
+
        if (td->filetype == FIO_TYPE_FILE) {
                char tmp[PATH_MAX];
                int len = 0;
@@ -176,6 +179,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
                for_each_file(td, f, i) {
                        memset(f, 0, sizeof(*f));
                        f->fd = -1;
+                       f->fileno = i;
 
                        sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i);
                        f->file_name = strdup(tmp);