File truncation and extend fixes
authorJens Axboe <jens.axboe@oracle.com>
Mon, 12 Mar 2007 08:25:55 +0000 (09:25 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Mon, 12 Mar 2007 08:25:55 +0000 (09:25 +0100)
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
engines/mmap.c
filesetup.c
fio.h

index 27d5d25515f2016526cbca985e8bf98bc356e326..bb4a81a5a54f8eb2c3a047f866b624deea39cc7a 100644 (file)
@@ -42,28 +42,6 @@ static int fio_mmapio_queue(struct thread_data *td, struct io_u *io_u)
        return FIO_Q_COMPLETED;
 }
 
-static int fio_mmapio_init(struct thread_data *td)
-{
-       struct fio_file *f;
-       int i;
-
-       if (!td_write(td))
-               return 0;
-
-       /*
-        * We need to truncate the files to the right size, if
-        * we are writing to it.
-        */
-       for_each_file(td, f, i) {
-               if (ftruncate(f->fd, f->file_size) < 0) {
-                       td_verror(td, errno, "ftruncate");
-                       return 1;
-               }
-       }
-
-       return 0;
-}
-
 static int fio_mmapio_open(struct thread_data *td, struct fio_file *f)
 {
        int ret, flags;
@@ -107,9 +85,7 @@ static int fio_mmapio_open(struct thread_data *td, struct fio_file *f)
        return 0;
 
 err:
-       if (f->mmap)
-               munmap(f->mmap, f->file_size);
-       generic_close_file(td, f);
+       td->io_ops->close_file(td, f);
        return 1;
 }
 
@@ -120,16 +96,16 @@ static void fio_mmapio_close(struct thread_data fio_unused *td,
                munmap(f->mmap, f->file_size);
                f->mmap = NULL;
        }
+       generic_close_file(td, f);
 }
 
 static struct ioengine_ops ioengine = {
        .name           = "mmap",
        .version        = FIO_IOOPS_VERSION,
        .queue          = fio_mmapio_queue,
-       .init           = fio_mmapio_init,
        .open_file      = fio_mmapio_open,
        .close_file     = fio_mmapio_close,
-       .flags          = FIO_SYNCIO,
+       .flags          = FIO_SYNCIO | FIO_NOEXTEND,
 };
 
 static void fio_init fio_mmapio_register(void)
index 49c4504f883714198326fa173852fc00c87fc8ac..a85c08f631c291faaba8b0e228df11e036eadacb 100644 (file)
@@ -98,7 +98,7 @@ err:
 static int create_files(struct thread_data *td)
 {
        struct fio_file *f;
-       int i, err, need_create;
+       int i, err, need_create, can_extend;
 
        for_each_file(td, f, i)
                f->file_size = td->total_file_size / td->nr_files;
@@ -106,7 +106,8 @@ static int create_files(struct thread_data *td)
        /*
         * unless specifically asked for overwrite, let normal io extend it
         */
-       if (!td->overwrite)
+       can_extend = !td->overwrite && !(td->io_ops->flags & FIO_NOEXTEND);
+       if (can_extend)
                return 0;
 
        need_create = 0;
@@ -114,7 +115,7 @@ static int create_files(struct thread_data *td)
                for_each_file(td, f, i) {
                        int file_there = !file_ok(td, f);
 
-                       if (file_there && td_write(td) && !td->overwrite) {
+                       if (file_there && td_write(td) && !can_extend) {
                                unlink(f->file_name);
                                file_there = 0;
                        }
@@ -225,8 +226,6 @@ int file_invalidate_cache(struct thread_data *td, struct fio_file *f)
 {
        int ret = 0;
 
-       if (!td->invalidate_cache)
-               return 0;
        if (td->odirect)
                return 0;
 
@@ -268,12 +267,8 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
        if (td_write(td) || td_rw(td)) {
                flags |= O_RDWR;
 
-               if (td->filetype == FIO_TYPE_FILE) {
-                       if (!td->overwrite)
-                               flags |= O_TRUNC;
-
+               if (td->filetype == FIO_TYPE_FILE)
                        flags |= O_CREAT;
-               }
 
                f->fd = open(f->file_name, flags, 0600);
        } else {
@@ -297,7 +292,7 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
        if (get_file_size(td, f))
                goto err;
 
-       if (file_invalidate_cache(td, f))
+       if (td->invalidate_cache && file_invalidate_cache(td, f))
                goto err;
 
        if (!td_random(td)) {
diff --git a/fio.h b/fio.h
index 41a1790dee686e8837c77531e1d249cac2647513..b085cd1e03d6f593c25eaca266cc2f8d066f3ade 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -214,6 +214,7 @@ enum fio_ioengine_flags {
        FIO_SYNCIO      = 1 << 0,       /* io engine has synchronous ->queue */
        FIO_RAWIO       = 1 << 1,       /* some sort of direct/raw io */
        FIO_DISKLESSIO  = 1 << 2,       /* no disk involved */
+       FIO_NOEXTEND    = 1 << 3,       /* engine can't extend file */
 };
 
 /*