null: style fixup
[fio.git] / engines / null.c
CommitLineData
a94ea28b 1/*
da751ca9
JA
2 * 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.
a94ea28b 6 *
46a67478
DG
7 * It also can act as external C++ engine - compiled with:
8 *
9 * g++ -O2 -g -shared -rdynamic -fPIC -o null.so null.c -DFIO_EXTERNAL_ENGINE
10 *
a94ea28b
JA
11 */
12#include <stdio.h>
13#include <stdlib.h>
14#include <unistd.h>
15#include <errno.h>
16#include <assert.h>
17
18#include "../fio.h"
a94ea28b 19
65afa5f2
JA
20struct null_data {
21 struct io_u **io_us;
22 int queued;
23 int events;
24};
25
26static struct io_u *fio_null_event(struct thread_data *td, int event)
27{
46a67478 28 struct null_data *nd = (struct null_data *) td->io_ops->data;
65afa5f2
JA
29
30 return nd->io_us[event];
31}
32
e7d2e616
JA
33static int fio_null_getevents(struct thread_data *td, unsigned int min_events,
34 unsigned int fio_unused max,
35 struct timespec fio_unused *t)
65afa5f2 36{
46a67478 37 struct null_data *nd = (struct null_data *) td->io_ops->data;
7401c088
JA
38 int ret = 0;
39
40 if (min_events) {
41 ret = nd->events;
42 nd->events = 0;
43 }
65afa5f2 44
65afa5f2
JA
45 return ret;
46}
47
48static int fio_null_commit(struct thread_data *td)
49{
46a67478 50 struct null_data *nd = (struct null_data *) td->io_ops->data;
65afa5f2 51
ed8bd849 52 if (!nd->events) {
46a67478 53#ifndef FIO_EXTERNAL_ENGINE
838bc709 54 io_u_mark_submit(td, nd->queued);
46a67478 55#endif
ed8bd849
JA
56 nd->events = nd->queued;
57 nd->queued = 0;
58 }
59
65afa5f2
JA
60 return 0;
61}
62
f0c48a70 63static int fio_null_queue(struct thread_data *td, struct io_u *io_u)
a94ea28b 64{
46a67478 65 struct null_data *nd = (struct null_data *) td->io_ops->data;
65afa5f2 66
7101d9c2
JA
67 fio_ro_check(td, io_u);
68
65afa5f2
JA
69 if (td->io_ops->flags & FIO_SYNCIO)
70 return FIO_Q_COMPLETED;
ed8bd849
JA
71 if (nd->events)
72 return FIO_Q_BUSY;
65afa5f2
JA
73
74 nd->io_us[nd->queued++] = io_u;
75 return FIO_Q_QUEUED;
a94ea28b
JA
76}
77
b5af8293
JA
78static int fio_null_open(struct thread_data fio_unused *td,
79 struct fio_file fio_unused *f)
80{
81 return 0;
82}
83
65afa5f2
JA
84static void fio_null_cleanup(struct thread_data *td)
85{
46a67478 86 struct null_data *nd = (struct null_data *) td->io_ops->data;
65afa5f2
JA
87
88 if (nd) {
89 if (nd->io_us)
90 free(nd->io_us);
91 free(nd);
65afa5f2
JA
92 }
93}
94
95static int fio_null_init(struct thread_data *td)
96{
46a67478 97 struct null_data *nd = (struct null_data *) malloc(sizeof(*nd));
65afa5f2
JA
98
99 memset(nd, 0, sizeof(*nd));
100
2dc1bbeb 101 if (td->o.iodepth != 1) {
46a67478 102 nd->io_us = (struct io_u **) malloc(td->o.iodepth * sizeof(struct io_u *));
2dc1bbeb 103 memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *));
65afa5f2
JA
104 } else
105 td->io_ops->flags |= FIO_SYNCIO;
106
107 td->io_ops->data = nd;
108 return 0;
109}
110
46a67478 111#ifndef __cplusplus
a94ea28b
JA
112static struct ioengine_ops ioengine = {
113 .name = "null",
114 .version = FIO_IOOPS_VERSION,
a94ea28b 115 .queue = fio_null_queue,
65afa5f2
JA
116 .commit = fio_null_commit,
117 .getevents = fio_null_getevents,
118 .event = fio_null_event,
119 .init = fio_null_init,
120 .cleanup = fio_null_cleanup,
b5af8293 121 .open_file = fio_null_open,
65afa5f2 122 .flags = FIO_DISKLESSIO,
a94ea28b
JA
123};
124
125static void fio_init fio_null_register(void)
126{
127 register_ioengine(&ioengine);
128}
129
130static void fio_exit fio_null_unregister(void)
131{
132 unregister_ioengine(&ioengine);
133}
46a67478
DG
134
135#else
136
137#ifdef FIO_EXTERNAL_ENGINE
138extern "C" {
8d6ecac2
JA
139void get_ioengine(struct ioengine_ops **ioengine_ptr)
140{
46a67478 141 struct ioengine_ops *ioengine;
8d6ecac2 142
46a67478
DG
143 *ioengine_ptr = (struct ioengine_ops *) malloc(sizeof(struct ioengine_ops));
144 ioengine = *ioengine_ptr;
145
146 strcpy(ioengine->name, "cpp_null");
147 ioengine->version = FIO_IOOPS_VERSION;
148 ioengine->queue = fio_null_queue;
149 ioengine->commit = fio_null_commit;
150 ioengine->getevents = fio_null_getevents;
151 ioengine->event = fio_null_event;
152 ioengine->init = fio_null_init;
153 ioengine->cleanup = fio_null_cleanup;
154 ioengine->open_file = fio_null_open;
155 ioengine->flags = FIO_DISKLESSIO;
156}
157}
158#endif /* FIO_EXTERNAL_ENGINE */
159
160#endif /* __cplusplus */