Add ->invalidate() IO engine ops
authorJens Axboe <axboe@fb.com>
Tue, 20 May 2014 01:57:05 +0000 (19:57 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 20 May 2014 01:57:05 +0000 (19:57 -0600)
Allow IO engines to plug in their own invalidate cache handler.
This fixes an issue on rbd, where we attempt to invalidate the
cache, but fail because it's not a valid file descriptor.

Reported-by: xan.peng@gmail.com
Signed-off-by: Jens Axboe <axboe@fb.com>
engines/rbd.c
filesetup.c
ioengine.h

index dc6e7db674ba38c6252a61fde337f061938f0555..d006123036545b5df33271106239746f40d59be0 100644 (file)
@@ -404,6 +404,11 @@ static int fio_rbd_open(struct thread_data *td, struct fio_file *f)
        return 0;
 }
 
        return 0;
 }
 
+static int fio_rbd_invalidate(struct thread_data *td, struct fio_file *f)
+{
+       return 0;
+}
+
 static void fio_rbd_io_u_free(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_rbd_iou *o = io_u->engine_data;
 static void fio_rbd_io_u_free(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_rbd_iou *o = io_u->engine_data;
@@ -426,19 +431,20 @@ static int fio_rbd_io_u_init(struct thread_data *td, struct io_u *io_u)
 }
 
 static struct ioengine_ops ioengine = {
 }
 
 static struct ioengine_ops ioengine = {
-       .name               = "rbd",
-       .version            = FIO_IOOPS_VERSION,
-       .setup              = fio_rbd_setup,
-       .init               = fio_rbd_init,
-       .queue              = fio_rbd_queue,
-       .getevents          = fio_rbd_getevents,
-       .event              = fio_rbd_event,
-       .cleanup            = fio_rbd_cleanup,
-       .open_file          = fio_rbd_open,
-       .options            = options,
-       .io_u_init          = fio_rbd_io_u_init,
-       .io_u_free          = fio_rbd_io_u_free,
-       .option_struct_size = sizeof(struct rbd_options),
+       .name                   = "rbd",
+       .version                = FIO_IOOPS_VERSION,
+       .setup                  = fio_rbd_setup,
+       .init                   = fio_rbd_init,
+       .queue                  = fio_rbd_queue,
+       .getevents              = fio_rbd_getevents,
+       .event                  = fio_rbd_event,
+       .cleanup                = fio_rbd_cleanup,
+       .open_file              = fio_rbd_open,
+       .invalidate             = fio_rbd_invalidate,
+       .options                = options,
+       .io_u_init              = fio_rbd_io_u_init,
+       .io_u_free              = fio_rbd_io_u_free,
+       .option_struct_size     = sizeof(struct rbd_options),
 };
 
 static void fio_init fio_rbd_register(void)
 };
 
 static void fio_init fio_rbd_register(void)
index ad7fb8551da7b87889e3e0ec5d087089e918b5fd..84eaed68c230520f47bd2853cb20225c078938ef 100644 (file)
@@ -401,7 +401,9 @@ static int __file_invalidate_cache(struct thread_data *td, struct fio_file *f,
        dprint(FD_IO, "invalidate cache %s: %llu/%llu\n", f->file_name, off,
                                                                len);
 
        dprint(FD_IO, "invalidate cache %s: %llu/%llu\n", f->file_name, off,
                                                                len);
 
-       if (f->mmap_ptr) {
+       if (td->io_ops->invalidate)
+               ret = td->io_ops->invalidate(td, f);
+       else if (f->mmap_ptr) {
                ret = posix_madvise(f->mmap_ptr, f->mmap_sz, POSIX_MADV_DONTNEED);
 #ifdef FIO_MADV_FREE
                if (f->filetype == FIO_TYPE_BD)
                ret = posix_madvise(f->mmap_ptr, f->mmap_sz, POSIX_MADV_DONTNEED);
 #ifdef FIO_MADV_FREE
                if (f->filetype == FIO_TYPE_BD)
index 6e3c717f185414bfd20342d30635eaa60da78197..37bf5fce125e0e9e265b9137cf63dc9b0eb406fa 100644 (file)
@@ -15,7 +15,7 @@
 #include <guasi.h>
 #endif
 
 #include <guasi.h>
 #endif
 
-#define FIO_IOOPS_VERSION      18
+#define FIO_IOOPS_VERSION      19
 
 enum {
        IO_U_F_FREE             = 1 << 0,
 
 enum {
        IO_U_F_FREE             = 1 << 0,
@@ -143,6 +143,7 @@ struct ioengine_ops {
        void (*cleanup)(struct thread_data *);
        int (*open_file)(struct thread_data *, struct fio_file *);
        int (*close_file)(struct thread_data *, struct fio_file *);
        void (*cleanup)(struct thread_data *);
        int (*open_file)(struct thread_data *, struct fio_file *);
        int (*close_file)(struct thread_data *, struct fio_file *);
+       int (*invalidate)(struct thread_data *, struct fio_file *);
        int (*get_file_size)(struct thread_data *, struct fio_file *);
        void (*terminate)(struct thread_data *);
        int (*io_u_init)(struct thread_data *, struct io_u *);
        int (*get_file_size)(struct thread_data *, struct fio_file *);
        void (*terminate)(struct thread_data *);
        int (*io_u_init)(struct thread_data *, struct io_u *);