4 * IO engine that doesn't do any real IO transfers, it just pretends to.
5 * The main purpose is to test fio itself.
7 * It also can act as external C++ engine - compiled with:
9 * g++ -O2 -g -shared -rdynamic -fPIC -o null.so null.c -DFIO_EXTERNAL_ENGINE
26 static struct io_u *fio_null_event(struct thread_data *td, int event)
28 struct null_data *nd = (struct null_data *) td->io_ops->data;
30 return nd->io_us[event];
33 static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
34 unsigned int fio_unused max,
35 struct timespec fio_unused *t)
37 struct null_data *nd = (struct null_data *) td->io_ops->data;
48 static int fio_null_commit(struct thread_data *td)
50 struct null_data *nd = (struct null_data *) td->io_ops->data;
53 #ifndef FIO_EXTERNAL_ENGINE
54 io_u_mark_submit(td, nd->queued);
56 nd->events = nd->queued;
63 static int fio_null_queue(struct thread_data *td, struct io_u *io_u)
65 struct null_data *nd = (struct null_data *) td->io_ops->data;
67 fio_ro_check(td, io_u);
69 if (td->io_ops->flags & FIO_SYNCIO)
70 return FIO_Q_COMPLETED;
74 nd->io_us[nd->queued++] = io_u;
78 static int fio_null_open(struct thread_data fio_unused *td,
79 struct fio_file fio_unused *f)
84 static void fio_null_cleanup(struct thread_data *td)
86 struct null_data *nd = (struct null_data *) td->io_ops->data;
95 static int fio_null_init(struct thread_data *td)
97 struct null_data *nd = (struct null_data *) malloc(sizeof(*nd));
99 memset(nd, 0, sizeof(*nd));
101 if (td->o.iodepth != 1) {
102 nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *));
103 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
105 td->io_ops->flags |= FIO_SYNCIO;
107 td->io_ops->data = nd;
112 static struct ioengine_ops ioengine = {
114 .version = FIO_IOOPS_VERSION,
115 .queue = fio_null_queue,
116 .commit = fio_null_commit,
117 .getevents = fio_null_getevents,
118 .event = fio_null_event,
119 .init = fio_null_init,
120 .cleanup = fio_null_cleanup,
121 .open_file = fio_null_open,
122 .flags = FIO_DISKLESSIO,
125 static void fio_init fio_null_register(void)
127 register_ioengine(&ioengine);
130 static void fio_exit fio_null_unregister(void)
132 unregister_ioengine(&ioengine);
137 #ifdef FIO_EXTERNAL_ENGINE
139 void get_ioengine(struct ioengine_ops **ioengine_ptr)
141 struct ioengine_ops *ioengine;
143 *ioengine_ptr = (struct ioengine_ops *) malloc(sizeof(struct ioengine_ops));
144 ioengine = *ioengine_ptr;
146 strcpy(ioengine->name, "cpp_null");
147 ioengine->version = FIO_IOOPS_VERSION;
148 ioengine->queue = fio_null_queue;
149 ioengine->commit = fio_null_commit;
150 ioengine->getevents = fio_null_getevents;
151 ioengine->event = fio_null_event;
152 ioengine->init = fio_null_init;
153 ioengine->cleanup = fio_null_cleanup;
154 ioengine->open_file = fio_null_open;
155 ioengine->flags = FIO_DISKLESSIO;
158 #endif /* FIO_EXTERNAL_ENGINE */
160 #endif /* __cplusplus */