Commit | Line | Data |
---|---|---|
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 JA |
6 | * |
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" | |
a94ea28b | 15 | |
65afa5f2 JA |
16 | struct null_data { |
17 | struct io_u **io_us; | |
18 | int queued; | |
19 | int events; | |
20 | }; | |
21 | ||
22 | static 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 | ||
7401c088 | 29 | static int fio_null_getevents(struct thread_data *td, int min_events, |
65afa5f2 JA |
30 | int fio_unused max, struct timespec fio_unused *t) |
31 | { | |
32 | struct null_data *nd = td->io_ops->data; | |
7401c088 JA |
33 | int ret = 0; |
34 | ||
35 | if (min_events) { | |
36 | ret = nd->events; | |
37 | nd->events = 0; | |
38 | } | |
65afa5f2 | 39 | |
65afa5f2 JA |
40 | return ret; |
41 | } | |
42 | ||
43 | static int fio_null_commit(struct thread_data *td) | |
44 | { | |
45 | struct null_data *nd = td->io_ops->data; | |
46 | ||
ed8bd849 JA |
47 | if (!nd->events) { |
48 | nd->events = nd->queued; | |
49 | nd->queued = 0; | |
50 | } | |
51 | ||
65afa5f2 JA |
52 | return 0; |
53 | } | |
54 | ||
36167d82 | 55 | static int fio_null_queue(struct thread_data fio_unused *td, struct io_u *io_u) |
a94ea28b | 56 | { |
65afa5f2 JA |
57 | struct null_data *nd = td->io_ops->data; |
58 | ||
7101d9c2 JA |
59 | fio_ro_check(td, io_u); |
60 | ||
65afa5f2 JA |
61 | if (td->io_ops->flags & FIO_SYNCIO) |
62 | return FIO_Q_COMPLETED; | |
ed8bd849 JA |
63 | if (nd->events) |
64 | return FIO_Q_BUSY; | |
65afa5f2 JA |
65 | |
66 | nd->io_us[nd->queued++] = io_u; | |
67 | return FIO_Q_QUEUED; | |
a94ea28b JA |
68 | } |
69 | ||
b5af8293 JA |
70 | static int fio_null_open(struct thread_data fio_unused *td, |
71 | struct fio_file fio_unused *f) | |
72 | { | |
73 | return 0; | |
74 | } | |
75 | ||
65afa5f2 JA |
76 | static void fio_null_cleanup(struct thread_data *td) |
77 | { | |
78 | struct null_data *nd = td->io_ops->data; | |
79 | ||
80 | if (nd) { | |
81 | if (nd->io_us) | |
82 | free(nd->io_us); | |
83 | free(nd); | |
84 | td->io_ops->data = NULL; | |
85 | } | |
86 | } | |
87 | ||
88 | static int fio_null_init(struct thread_data *td) | |
89 | { | |
90 | struct null_data *nd = malloc(sizeof(*nd)); | |
91 | ||
92 | memset(nd, 0, sizeof(*nd)); | |
93 | ||
2dc1bbeb JA |
94 | if (td->o.iodepth != 1) { |
95 | nd->io_us = malloc(td->o.iodepth * sizeof(struct io_u *)); | |
96 | memset(nd->io_us, 0, td->o.iodepth * sizeof(struct io_u *)); | |
65afa5f2 JA |
97 | } else |
98 | td->io_ops->flags |= FIO_SYNCIO; | |
99 | ||
100 | td->io_ops->data = nd; | |
101 | return 0; | |
102 | } | |
103 | ||
a94ea28b JA |
104 | static struct ioengine_ops ioengine = { |
105 | .name = "null", | |
106 | .version = FIO_IOOPS_VERSION, | |
a94ea28b | 107 | .queue = fio_null_queue, |
65afa5f2 JA |
108 | .commit = fio_null_commit, |
109 | .getevents = fio_null_getevents, | |
110 | .event = fio_null_event, | |
111 | .init = fio_null_init, | |
112 | .cleanup = fio_null_cleanup, | |
b5af8293 | 113 | .open_file = fio_null_open, |
65afa5f2 | 114 | .flags = FIO_DISKLESSIO, |
a94ea28b JA |
115 | }; |
116 | ||
117 | static void fio_init fio_null_register(void) | |
118 | { | |
119 | register_ioengine(&ioengine); | |
120 | } | |
121 | ||
122 | static void fio_exit fio_null_unregister(void) | |
123 | { | |
124 | unregister_ioengine(&ioengine); | |
125 | } |