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
30 static struct io_u *null_event(struct null_data *nd, int event)
32 return nd->io_us[event];
35 static int null_getevents(struct null_data *nd, unsigned int min_events,
36 unsigned int fio_unused max,
37 const struct timespec fio_unused *t)
49 static int null_commit(struct thread_data *td, struct null_data *nd)
52 #ifndef FIO_EXTERNAL_ENGINE
53 io_u_mark_submit(td, nd->queued);
55 nd->events = nd->queued;
62 static int null_queue(struct thread_data *td, struct null_data *nd,
65 fio_ro_check(td, io_u);
67 if (td->io_ops->flags & FIO_SYNCIO)
68 return FIO_Q_COMPLETED;
72 nd->io_us[nd->queued++] = io_u;
76 static int null_open(struct null_data fio_unused *nd,
77 struct fio_file fio_unused *f)
82 static void null_cleanup(struct null_data *nd)
90 static struct null_data *null_init(struct thread_data *td)
92 struct null_data *nd = (struct null_data *) malloc(sizeof(*nd));
94 memset(nd, 0, sizeof(*nd));
96 if (td->o.iodepth != 1) {
97 nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *));
98 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
100 td->io_ops->flags |= FIO_SYNCIO;
107 static struct io_u *fio_null_event(struct thread_data *td, int event)
109 return null_event((struct null_data *)td->io_ops_data, event);
112 static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
113 unsigned int max, const struct timespec *t)
115 struct null_data *nd = (struct null_data *)td->io_ops_data;
116 return null_getevents(nd, min_events, max, t);
119 static int fio_null_commit(struct thread_data *td)
121 return null_commit(td, (struct null_data *)td->io_ops_data);
124 static int fio_null_queue(struct thread_data *td, struct io_u *io_u)
126 return null_queue(td, (struct null_data *)td->io_ops_data, io_u);
129 static int fio_null_open(struct thread_data *td, struct fio_file *f)
131 return null_open((struct null_data *)td->io_ops_data, f);
134 static void fio_null_cleanup(struct thread_data *td)
136 null_cleanup((struct null_data *)td->io_ops_data);
139 static int fio_null_init(struct thread_data *td)
141 td->io_ops_data = null_init(td);
142 assert(td->io_ops_data);
146 static struct ioengine_ops ioengine = {
148 .version = FIO_IOOPS_VERSION,
149 .queue = fio_null_queue,
150 .commit = fio_null_commit,
151 .getevents = fio_null_getevents,
152 .event = fio_null_event,
153 .init = fio_null_init,
154 .cleanup = fio_null_cleanup,
155 .open_file = fio_null_open,
156 .flags = FIO_DISKLESSIO | FIO_FAKEIO,
159 static void fio_init fio_null_register(void)
161 register_ioengine(&ioengine);
164 static void fio_exit fio_null_unregister(void)
166 unregister_ioengine(&ioengine);
171 #ifdef FIO_EXTERNAL_ENGINE
174 NullData(struct thread_data *td)
176 impl_ = null_init(td);
185 static NullData *get(struct thread_data *td)
187 return reinterpret_cast<NullData *>(td->io_ops_data);
190 io_u *fio_null_event(struct thread_data *, int event)
192 return null_event(impl_, event);
195 int fio_null_getevents(struct thread_data *, unsigned int min_events,
196 unsigned int max, const struct timespec *t)
198 return null_getevents(impl_, min_events, max, t);
201 int fio_null_commit(struct thread_data *td)
203 return null_commit(td, impl_);
206 int fio_null_queue(struct thread_data *td, struct io_u *io_u)
208 return null_queue(td, impl_, io_u);
211 int fio_null_open(struct thread_data *, struct fio_file *f)
213 return null_open(impl_, f);
217 struct null_data *impl_;
222 static struct io_u *fio_null_event(struct thread_data *td, int event)
224 return NullData::get(td)->fio_null_event(td, event);
227 static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
228 unsigned int max, const struct timespec *t)
230 return NullData::get(td)->fio_null_getevents(td, min_events, max, t);
233 static int fio_null_commit(struct thread_data *td)
235 return NullData::get(td)->fio_null_commit(td);
238 static int fio_null_queue(struct thread_data *td, struct io_u *io_u)
240 return NullData::get(td)->fio_null_queue(td, io_u);
243 static int fio_null_open(struct thread_data *td, struct fio_file *f)
245 return NullData::get(td)->fio_null_open(td, f);
248 static int fio_null_init(struct thread_data *td)
250 td->io_ops_data = new NullData(td);
254 static void fio_null_cleanup(struct thread_data *td)
256 delete NullData::get(td);
259 static struct ioengine_ops ioengine;
260 void get_ioengine(struct ioengine_ops **ioengine_ptr)
262 *ioengine_ptr = &ioengine;
264 ioengine.name = "cpp_null";
265 ioengine.version = FIO_IOOPS_VERSION;
266 ioengine.queue = fio_null_queue;
267 ioengine.commit = fio_null_commit;
268 ioengine.getevents = fio_null_getevents;
269 ioengine.event = fio_null_event;
270 ioengine.init = fio_null_init;
271 ioengine.cleanup = fio_null_cleanup;
272 ioengine.open_file = fio_null_open;
273 ioengine.flags = FIO_DISKLESSIO | FIO_FAKEIO;
276 #endif /* FIO_EXTERNAL_ENGINE */
278 #endif /* __cplusplus */