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 \
10 * -include ../config-host.h -DFIO_EXTERNAL_ENGINE
14 * LD_LIBRARY_PATH=./engines ./fio examples/cpp_null.fio
28 static struct io_u *null_event(struct null_data *nd, int event)
30 return nd->io_us[event];
33 static int null_getevents(struct null_data *nd, unsigned int min_events,
34 unsigned int fio_unused max,
35 const struct timespec fio_unused *t)
47 static int null_commit(struct thread_data *td, struct null_data *nd)
50 #ifndef FIO_EXTERNAL_ENGINE
51 io_u_mark_submit(td, nd->queued);
53 nd->events = nd->queued;
60 static enum fio_q_status null_queue(struct thread_data *td,
61 struct null_data *nd, struct io_u *io_u)
63 fio_ro_check(td, io_u);
65 if (td->io_ops->flags & FIO_SYNCIO)
66 return FIO_Q_COMPLETED;
70 nd->io_us[nd->queued++] = io_u;
74 static int null_open(struct null_data fio_unused *nd,
75 struct fio_file fio_unused *f)
80 static void null_cleanup(struct null_data *nd)
88 static struct null_data *null_init(struct thread_data *td)
90 struct null_data *nd = (struct null_data *) malloc(sizeof(*nd));
92 memset(nd, 0, sizeof(*nd));
94 if (td->o.iodepth != 1) {
95 nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *));
96 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
98 td->io_ops->flags |= FIO_SYNCIO;
105 static struct io_u *fio_null_event(struct thread_data *td, int event)
107 return null_event(td->io_ops_data, event);
110 static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
111 unsigned int max, const struct timespec *t)
113 struct null_data *nd = td->io_ops_data;
114 return null_getevents(nd, min_events, max, t);
117 static int fio_null_commit(struct thread_data *td)
119 return null_commit(td, td->io_ops_data);
122 static enum fio_q_status fio_null_queue(struct thread_data *td,
125 return null_queue(td, td->io_ops_data, io_u);
128 static int fio_null_open(struct thread_data *td, struct fio_file *f)
130 return null_open(td->io_ops_data, f);
133 static void fio_null_cleanup(struct thread_data *td)
135 null_cleanup(td->io_ops_data);
138 static int fio_null_init(struct thread_data *td)
140 td->io_ops_data = null_init(td);
141 assert(td->io_ops_data);
145 static struct ioengine_ops ioengine = {
147 .version = FIO_IOOPS_VERSION,
148 .queue = fio_null_queue,
149 .commit = fio_null_commit,
150 .getevents = fio_null_getevents,
151 .event = fio_null_event,
152 .init = fio_null_init,
153 .cleanup = fio_null_cleanup,
154 .open_file = fio_null_open,
155 .flags = FIO_DISKLESSIO | FIO_FAKEIO,
158 static void fio_init fio_null_register(void)
160 register_ioengine(&ioengine);
163 static void fio_exit fio_null_unregister(void)
165 unregister_ioengine(&ioengine);
170 #ifdef FIO_EXTERNAL_ENGINE
173 NullData(struct thread_data *td)
175 impl_ = null_init(td);
184 static NullData *get(struct thread_data *td)
186 return reinterpret_cast<NullData *>(td->io_ops_data);
189 io_u *fio_null_event(struct thread_data *, int event)
191 return null_event(impl_, event);
194 int fio_null_getevents(struct thread_data *, unsigned int min_events,
195 unsigned int max, const struct timespec *t)
197 return null_getevents(impl_, min_events, max, t);
200 int fio_null_commit(struct thread_data *td)
202 return null_commit(td, impl_);
205 fio_q_status fio_null_queue(struct thread_data *td, struct io_u *io_u)
207 return null_queue(td, impl_, io_u);
210 int fio_null_open(struct thread_data *, struct fio_file *f)
212 return null_open(impl_, f);
216 struct null_data *impl_;
221 static struct io_u *fio_null_event(struct thread_data *td, int event)
223 return NullData::get(td)->fio_null_event(td, event);
226 static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
227 unsigned int max, const struct timespec *t)
229 return NullData::get(td)->fio_null_getevents(td, min_events, max, t);
232 static int fio_null_commit(struct thread_data *td)
234 return NullData::get(td)->fio_null_commit(td);
237 static fio_q_status fio_null_queue(struct thread_data *td, struct io_u *io_u)
239 return NullData::get(td)->fio_null_queue(td, io_u);
242 static int fio_null_open(struct thread_data *td, struct fio_file *f)
244 return NullData::get(td)->fio_null_open(td, f);
247 static int fio_null_init(struct thread_data *td)
249 td->io_ops_data = new NullData(td);
253 static void fio_null_cleanup(struct thread_data *td)
255 delete NullData::get(td);
258 static struct ioengine_ops ioengine;
259 void get_ioengine(struct ioengine_ops **ioengine_ptr)
261 *ioengine_ptr = &ioengine;
263 ioengine.name = "cpp_null";
264 ioengine.version = FIO_IOOPS_VERSION;
265 ioengine.queue = fio_null_queue;
266 ioengine.commit = fio_null_commit;
267 ioengine.getevents = fio_null_getevents;
268 ioengine.event = fio_null_event;
269 ioengine.init = fio_null_init;
270 ioengine.cleanup = fio_null_cleanup;
271 ioengine.open_file = fio_null_open;
272 ioengine.flags = FIO_DISKLESSIO | FIO_FAKEIO;
275 #endif /* FIO_EXTERNAL_ENGINE */
277 #endif /* __cplusplus */