mmap IO engine cannot extend a file
authorJens Axboe <jens.axboe@oracle.com>
Tue, 20 Feb 2007 18:49:57 +0000 (19:49 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Tue, 20 Feb 2007 18:49:57 +0000 (19:49 +0100)
We need to ftruncate it to the wanted size first, or the mmap
write will terminate with SIGBUS.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
engines/mmap.c

index d32fe969832009d871cb9956b0950ef6413d2a29..08bbd991463d4e8546ea40a31d14b9213ffd0d11 100644 (file)
@@ -42,10 +42,33 @@ static int fio_mmapio_queue(struct thread_data *td, struct io_u *io_u)
        return FIO_Q_COMPLETED;
 }
 
        return FIO_Q_COMPLETED;
 }
 
+static int fio_mmapio_init(struct thread_data *td)
+{
+       struct fio_file *f;
+       int i;
+
+       if (td->ddir == DDIR_READ && !td_rw(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);
+                       return 1;
+               }
+       }
+
+       return 0;
+}
+
 static struct ioengine_ops ioengine = {
        .name           = "mmap",
        .version        = FIO_IOOPS_VERSION,
        .queue          = fio_mmapio_queue,
 static struct ioengine_ops ioengine = {
        .name           = "mmap",
        .version        = FIO_IOOPS_VERSION,
        .queue          = fio_mmapio_queue,
+       .init           = fio_mmapio_init,
        .flags          = FIO_SYNCIO | FIO_MMAPIO,
 };
 
        .flags          = FIO_SYNCIO | FIO_MMAPIO,
 };