blob: 85d6847e18388eee2822f7b7cf38b7d230b5ec27 [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 Axboee7d2e612007-12-11 10:49:39 +010029static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
30 unsigned int fio_unused max,
31 struct timespec fio_unused *t)
Jens Axboe65afa5f2007-03-09 13:23:14 +010032{
33 struct null_data *nd = td->io_ops->data;
Jens Axboe7401c082007-03-09 13:45:11 +010034 int ret = 0;
35
36 if (min_events) {
37 ret = nd->events;
38 nd->events = 0;
39 }
Jens Axboe65afa5f2007-03-09 13:23:14 +010040
Jens Axboe65afa5f2007-03-09 13:23:14 +010041 return ret;
42}
43
44static int fio_null_commit(struct thread_data *td)
45{
46 struct null_data *nd = td->io_ops->data;
47
Jens Axboeed8bd842007-03-27 09:56:08 +020048 if (!nd->events) {
49 nd->events = nd->queued;
50 nd->queued = 0;
51 }
52
Jens Axboe65afa5f2007-03-09 13:23:14 +010053 return 0;
54}
55
Jens Axboe36167d82007-02-18 05:41:31 +010056static int fio_null_queue(struct thread_data fio_unused *td, struct io_u *io_u)
Jens Axboea94ea282006-11-24 12:37:34 +010057{
Jens Axboe65afa5f2007-03-09 13:23:14 +010058 struct null_data *nd = td->io_ops->data;
59
Jens Axboe7101d9c2007-09-12 13:12:39 +020060 fio_ro_check(td, io_u);
61
Jens Axboe65afa5f2007-03-09 13:23:14 +010062 if (td->io_ops->flags & FIO_SYNCIO)
63 return FIO_Q_COMPLETED;
Jens Axboeed8bd842007-03-27 09:56:08 +020064 if (nd->events)
65 return FIO_Q_BUSY;
Jens Axboe65afa5f2007-03-09 13:23:14 +010066
67 nd->io_us[nd->queued++] = io_u;
68 return FIO_Q_QUEUED;
Jens Axboea94ea282006-11-24 12:37:34 +010069}
70
Jens Axboeb5af8292007-03-08 12:43:13 +010071static int fio_null_open(struct thread_data fio_unused *td,
72 struct fio_file fio_unused *f)
73{
74 return 0;
75}
76
Jens Axboe65afa5f2007-03-09 13:23:14 +010077static void fio_null_cleanup(struct thread_data *td)
78{
79 struct null_data *nd = td->io_ops->data;
80
81 if (nd) {
82 if (nd->io_us)
83 free(nd->io_us);
84 free(nd);
85 td->io_ops->data = NULL;
86 }
87}
88
89static int fio_null_init(struct thread_data *td)
90{
91 struct null_data *nd = malloc(sizeof(*nd));
92
93 memset(nd, 0, sizeof(*nd));
94
Jens Axboe2dc1bbe2007-03-15 15:01:33 +010095 if (td->o.iodepth != 1) {
96 nd->io_us = malloc(td->o.iodepth * sizeof(struct io_u *));
97 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
Jens Axboe65afa5f2007-03-09 13:23:14 +010098 } else
99 td->io_ops->flags |= FIO_SYNCIO;
100
101 td->io_ops->data = nd;
102 return 0;
103}
104
Jens Axboea94ea282006-11-24 12:37:34 +0100105static struct ioengine_ops ioengine = {
106 .name = "null",
107 .version = FIO_IOOPS_VERSION,
Jens Axboea94ea282006-11-24 12:37:34 +0100108 .queue = fio_null_queue,
Jens Axboe65afa5f2007-03-09 13:23:14 +0100109 .commit = fio_null_commit,
110 .getevents = fio_null_getevents,
111 .event = fio_null_event,
112 .init = fio_null_init,
113 .cleanup = fio_null_cleanup,
Jens Axboeb5af8292007-03-08 12:43:13 +0100114 .open_file = fio_null_open,
Jens Axboe65afa5f2007-03-09 13:23:14 +0100115 .flags = FIO_DISKLESSIO,
Jens Axboea94ea282006-11-24 12:37:34 +0100116};
117
118static void fio_init fio_null_register(void)
119{
120 register_ioengine(&ioengine);
121}
122
123static void fio_exit fio_null_unregister(void)
124{
125 unregister_ioengine(&ioengine);
126}