[PATCH] 'null' ioengine
[fio.git] / engines / fio-engine-null.c
CommitLineData
a94ea28b
JA
1/*
2 * null engine - doesn't do any transfers. Used to test fio.
3 *
4 */
5#include <stdio.h>
6#include <stdlib.h>
7#include <unistd.h>
8#include <errno.h>
9#include <assert.h>
10
11#include "../fio.h"
12#include "../os.h"
13
14struct null_data {
15 struct io_u *last_io_u;
16};
17
18static int fio_null_getevents(struct thread_data *td, int fio_unused min,
19 int max, struct timespec fio_unused *t)
20{
21 assert(max <= 1);
22
23 if (list_empty(&td->io_u_busylist))
24 return 0;
25
26 return 1;
27}
28
29static struct io_u *fio_null_event(struct thread_data *td, int event)
30{
31 struct null_data *nd = td->io_ops->data;
32
33 assert(event == 0);
34
35 return nd->last_io_u;
36}
37
38static int fio_null_queue(struct thread_data *td, struct io_u *io_u)
39{
40 struct null_data *nd = td->io_ops->data;
41
42 io_u->resid = 0;
43 io_u->error = 0;
44 nd->last_io_u = io_u;
45 return 0;
46}
47
48static void fio_null_cleanup(struct thread_data *td)
49{
50 if (td->io_ops->data) {
51 free(td->io_ops->data);
52 td->io_ops->data = NULL;
53 }
54}
55
56static int fio_null_init(struct thread_data *td)
57{
58 struct null_data *nd = malloc(sizeof(*nd));
59
60 nd->last_io_u = NULL;
61 td->io_ops->data = nd;
62 return 0;
63}
64
65static struct ioengine_ops ioengine = {
66 .name = "null",
67 .version = FIO_IOOPS_VERSION,
68 .init = fio_null_init,
69 .queue = fio_null_queue,
70 .getevents = fio_null_getevents,
71 .event = fio_null_event,
72 .cleanup = fio_null_cleanup,
73 .flags = FIO_SYNCIO,
74};
75
76static void fio_init fio_null_register(void)
77{
78 register_ioengine(&ioengine);
79}
80
81static void fio_exit fio_null_unregister(void)
82{
83 unregister_ioengine(&ioengine);
84}