blob: 823d40def272c820a2d635b994483af94a61b014 [file] [log] [blame]
Jens Axboea94ea282006-11-24 12:37:34 +01001/*
Jens Axboeda751ca2007-03-14 10:59:33 +01002 * null engine
3 *
4 * IO engine that doesn't do any real IO transfers, it just pretends to.
5 * The main purpose is to test fio itself.
Jens Axboea94ea282006-11-24 12:37:34 +01006 *
7 */
8#include <stdio.h>
9#include <stdlib.h>
10#include <unistd.h>
11#include <errno.h>
12#include <assert.h>
13
14#include "../fio.h"
Jens Axboea94ea282006-11-24 12:37:34 +010015
Jens Axboe65afa5f2007-03-09 13:23:14 +010016struct null_data {
17 struct io_u **io_us;
18 int queued;
19 int events;
20};
21
22static struct io_u *fio_null_event(struct thread_data *td, int event)
23{
24 struct null_data *nd = td->io_ops->data;
25
26 return nd->io_us[event];
27}
28
Jens Axboe7401c082007-03-09 13:45:11 +010029static int fio_null_getevents(struct thread_data *td, int min_events,
Jens Axboe65afa5f2007-03-09 13:23:14 +010030 int fio_unused max, struct timespec fio_unused *t)
31{
32 struct null_data *nd = td->io_ops->data;
Jens Axboe7401c082007-03-09 13:45:11 +010033 int ret = 0;
34
35 if (min_events) {
36 ret = nd->events;
37 nd->events = 0;
38 }
Jens Axboe65afa5f2007-03-09 13:23:14 +010039
Jens Axboe65afa5f2007-03-09 13:23:14 +010040 return ret;
41}
42
43static int fio_null_commit(struct thread_data *td)
44{
45 struct null_data *nd = td->io_ops->data;
46
Jens Axboeed8bd842007-03-27 09:56:08 +020047 if (!nd->events) {
48 nd->events = nd->queued;
49 nd->queued = 0;
50 }
51
Jens Axboe65afa5f2007-03-09 13:23:14 +010052 return 0;
53}
54
Jens Axboe36167d82007-02-18 05:41:31 +010055static int fio_null_queue(struct thread_data fio_unused *td, struct io_u *io_u)
Jens Axboea94ea282006-11-24 12:37:34 +010056{
Jens Axboe65afa5f2007-03-09 13:23:14 +010057 struct null_data *nd = td->io_ops->data;
58
59 if (td->io_ops->flags & FIO_SYNCIO)
60 return FIO_Q_COMPLETED;
Jens Axboeed8bd842007-03-27 09:56:08 +020061 if (nd->events)
62 return FIO_Q_BUSY;
Jens Axboe65afa5f2007-03-09 13:23:14 +010063
64 nd->io_us[nd->queued++] = io_u;
65 return FIO_Q_QUEUED;
Jens Axboea94ea282006-11-24 12:37:34 +010066}
67
Jens Axboeb5af8292007-03-08 12:43:13 +010068static int fio_null_open(struct thread_data fio_unused *td,
69 struct fio_file fio_unused *f)
70{
71 return 0;
72}
73
Jens Axboe65afa5f2007-03-09 13:23:14 +010074static void fio_null_cleanup(struct thread_data *td)
75{
76 struct null_data *nd = td->io_ops->data;
77
78 if (nd) {
79 if (nd->io_us)
80 free(nd->io_us);
81 free(nd);
82 td->io_ops->data = NULL;
83 }
84}
85
86static int fio_null_init(struct thread_data *td)
87{
88 struct null_data *nd = malloc(sizeof(*nd));
89
90 memset(nd, 0, sizeof(*nd));
91
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010092 if (td->o.iodepth != 1) {
93 nd->io_us = malloc(td->o.iodepth * sizeof(struct io_u *));
94 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
Jens Axboe65afa5f2007-03-09 13:23:14 +010095 } else
96 td->io_ops->flags |= FIO_SYNCIO;
97
98 td->io_ops->data = nd;
99 return 0;
100}
101
Jens Axboea94ea282006-11-24 12:37:34 +0100102static struct ioengine_ops ioengine = {
103 .name = "null",
104 .version = FIO_IOOPS_VERSION,
Jens Axboea94ea282006-11-24 12:37:34 +0100105 .queue = fio_null_queue,
Jens Axboe65afa5f2007-03-09 13:23:14 +0100106 .commit = fio_null_commit,
107 .getevents = fio_null_getevents,
108 .event = fio_null_event,
109 .init = fio_null_init,
110 .cleanup = fio_null_cleanup,
Jens Axboeb5af8292007-03-08 12:43:13 +0100111 .open_file = fio_null_open,
Jens Axboe65afa5f2007-03-09 13:23:14 +0100112 .flags = FIO_DISKLESSIO,
Jens Axboea94ea282006-11-24 12:37:34 +0100113};
114
115static void fio_init fio_null_register(void)
116{
117 register_ioengine(&ioengine);
118}
119
120static void fio_exit fio_null_unregister(void)
121{
122 unregister_ioengine(&ioengine);
123}