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 cpp_null null.c -DFIO_EXTERNAL_ENGINE
13 * LD_LIBRARY_PATH=./engines ./fio examples/cpp_null.fio
27 static struct io_u *null_event(struct null_data *nd, int event)
29 return nd->io_us[event];
32 static int null_getevents(struct null_data *nd, unsigned int min_events,
33 unsigned int fio_unused max,
34 const struct timespec fio_unused *t)
46 static int null_commit(struct thread_data *td, struct null_data *nd)
49 #ifndef FIO_EXTERNAL_ENGINE
50 io_u_mark_submit(td, nd->queued);
52 nd->events = nd->queued;
59 static enum fio_q_status null_queue(struct thread_data *td,
60 struct null_data *nd, struct io_u *io_u)
62 fio_ro_check(td, io_u);
64 if (td->io_ops->flags & FIO_SYNCIO)
65 return FIO_Q_COMPLETED;
69 nd->io_us[nd->queued++] = io_u;
73 static int null_open(struct null_data fio_unused *nd,
74 struct fio_file fio_unused *f)
79 static void null_cleanup(struct null_data *nd)
87 static struct null_data *null_init(struct thread_data *td)
89 struct null_data *nd = (struct null_data *) malloc(sizeof(*nd));
91 memset(nd, 0, sizeof(*nd));
93 if (td->o.iodepth != 1) {
94 nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *));
95 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
97 td->io_ops->flags |= FIO_SYNCIO;
104 static struct io_u *fio_null_event(struct thread_data *td, int event)
106 return null_event(td->io_ops_data, event);
109 static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
110 unsigned int max, const struct timespec *t)
112 struct null_data *nd = td->io_ops_data;
113 return null_getevents(nd, min_events, max, t);
116 static int fio_null_commit(struct thread_data *td)
118 return null_commit(td, td->io_ops_data);
121 static enum fio_q_status fio_null_queue(struct thread_data *td,
124 return null_queue(td, td->io_ops_data, io_u);
127 static int fio_null_open(struct thread_data *td, struct fio_file *f)
129 return null_open(td->io_ops_data, f);
132 static void fio_null_cleanup(struct thread_data *td)
134 null_cleanup(td->io_ops_data);
137 static int fio_null_init(struct thread_data *td)
139 td->io_ops_data = null_init(td);
140 assert(td->io_ops_data);
144 static struct ioengine_ops ioengine = {
146 .version = FIO_IOOPS_VERSION,
147 .queue = fio_null_queue,
148 .commit = fio_null_commit,
149 .getevents = fio_null_getevents,
150 .event = fio_null_event,
151 .init = fio_null_init,
152 .cleanup = fio_null_cleanup,
153 .open_file = fio_null_open,
154 .flags = FIO_DISKLESSIO | FIO_FAKEIO,
157 static void fio_init fio_null_register(void)
159 register_ioengine(&ioengine);
162 static void fio_exit fio_null_unregister(void)
164 unregister_ioengine(&ioengine);
169 #ifdef FIO_EXTERNAL_ENGINE
172 NullData(struct thread_data *td)
174 impl_ = null_init(td);
183 static NullData *get(struct thread_data *td)
185 return reinterpret_cast<NullData *>(td->io_ops_data);
188 io_u *fio_null_event(struct thread_data *, int event)
190 return null_event(impl_, event);
193 int fio_null_getevents(struct thread_data *, unsigned int min_events,
194 unsigned int max, const struct timespec *t)
196 return null_getevents(impl_, min_events, max, t);
199 int fio_null_commit(struct thread_data *td)
201 return null_commit(td, impl_);
204 int fio_null_queue(struct thread_data *td, struct io_u *io_u)
206 return null_queue(td, impl_, io_u);
209 int fio_null_open(struct thread_data *, struct fio_file *f)
211 return null_open(impl_, f);
215 struct null_data *impl_;
220 static struct io_u *fio_null_event(struct thread_data *td, int event)
222 return NullData::get(td)->fio_null_event(td, event);
225 static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
226 unsigned int max, const struct timespec *t)
228 return NullData::get(td)->fio_null_getevents(td, min_events, max, t);
231 static int fio_null_commit(struct thread_data *td)
233 return NullData::get(td)->fio_null_commit(td);
236 static int fio_null_queue(struct thread_data *td, struct io_u *io_u)
238 return NullData::get(td)->fio_null_queue(td, io_u);
241 static int fio_null_open(struct thread_data *td, struct fio_file *f)
243 return NullData::get(td)->fio_null_open(td, f);
246 static int fio_null_init(struct thread_data *td)
248 td->io_ops_data = new NullData(td);
252 static void fio_null_cleanup(struct thread_data *td)
254 delete NullData::get(td);
257 static struct ioengine_ops ioengine;
258 void get_ioengine(struct ioengine_ops **ioengine_ptr)
260 *ioengine_ptr = &ioengine;
262 ioengine.name = "cpp_null";
263 ioengine.version = FIO_IOOPS_VERSION;
264 ioengine.queue = fio_null_queue;
265 ioengine.commit = fio_null_commit;
266 ioengine.getevents = fio_null_getevents;
267 ioengine.event = fio_null_event;
268 ioengine.init = fio_null_init;
269 ioengine.cleanup = fio_null_cleanup;
270 ioengine.open_file = fio_null_open;
271 ioengine.flags = FIO_DISKLESSIO | FIO_FAKEIO;
274 #endif /* FIO_EXTERNAL_ENGINE */
276 #endif /* __cplusplus */