Remove gotos from read_iolog_get()
[fio.git] / engines / skeleton_external.c
CommitLineData
da51c050
JA
1/*
2 * Skeleton for a sample external io engine
3 *
4 * Should be compiled with:
5 *
6 * gcc -Wall -O2 -g -shared -rdynamic -fPIC -o engine.o engine.c
7 *
8 */
9#include <stdio.h>
10#include <stdlib.h>
11#include <unistd.h>
12#include <errno.h>
13#include <assert.h>
14
15#include "../fio.h"
da51c050
JA
16
17/*
18 * The core of the module is identical to the ones included with fio,
19 * read those. You cannot use register_ioengine() and unregister_ioengine()
20 * for external modules, they should be gotten through dlsym()
21 */
22
830a78b0
JA
23/*
24 * The ->event() hook is called to match an event number with an io_u.
25 * After the core has called ->getevents() and it has returned eg 3,
26 * the ->event() hook must return the 3 events that have completed for
27 * subsequent calls to ->event() with [0-2]. Required.
28 */
29static struct io_u *fio_skeleton_event(struct thread_data *td, int event)
30{
31 return NULL;
32}
33
34/*
35 * The ->getevents() hook is used to reap completion events from an async
36 * io engine. It returns the number of completed events since the last call,
37 * which may then be retrieved by calling the ->event() hook with the event
38 * numbers. Required.
39 */
40static int fio_skeleton_getevents(struct thread_data *td, int min, int max,
41 struct timespec *t)
42{
43 return 0;
44}
45
46/*
47 * The ->cancel() hook attempts to cancel the io_u. Only relevant for
48 * async io engines, and need not be supported.
49 */
50static int fio_skeleton_cancel(struct thread_data *td, struct io_u *io_u)
51{
52 return 0;
53}
54
55/*
56 * The ->queue() hook is responsible for initiating io on the io_u
57 * being passed in. If the io engine is a synchronous one, io may complete
58 * before ->queue() returns. Required.
e2a26d2c
JA
59 *
60 * The io engine must transfer in the direction noted by io_u->ddir
61 * to the buffer pointed to by io_u->xfer_buf for as many bytes as
62 * io_u->xfer_buflen. Residual data count may be set in io_u->residual
36167d82 63 * for a short read/write.
830a78b0
JA
64 */
65static int fio_skeleton_queue(struct thread_data *td, struct io_u *io_u)
66{
36167d82
JA
67 /*
68 * Could return FIO_Q_QUEUED for a queued request,
69 * FIO_Q_COMPLETED for a completed request, and FIO_Q_BUSY
70 * if we could queue no more at this point (you'd have to
71 * define ->commit() to handle that.
72 */
73 return FIO_Q_COMPLETED;
830a78b0
JA
74}
75
76/*
77 * The ->prep() function is called for each io_u prior to being submitted
78 * with ->queue(). This hook allows the io engine to perform any
34403fb1 79 * preparatory actions on the io_u, before being submitted. Not required.
830a78b0
JA
80 */
81static int fio_skeleton_prep(struct thread_data *td, struct io_u *io_u)
82{
83 return 0;
84}
85
86/*
87 * The init function is called once per thread/process, and should set up
88 * any structures that this io engine requires to keep track of io. Not
89 * required.
90 */
91static int fio_skeleton_init(struct thread_data *td)
92{
93 return 0;
94}
95
96/*
97 * This is paired with the ->init() funtion and is called when a thread is
98 * done doing io. Should tear down anything setup by the ->init() function.
99 * Not required.
100 */
101static void fio_skeleton_cleanup(struct thread_data *td)
102{
103}
104
b5af8293
JA
105/*
106 * Hook for opening the given file. Unless the engine has special
107 * needs, it usually just provides generic_file_open() as the handler.
108 */
109static int fio_skeleton_open(struct thread_data *td, struct fio_file *f)
110{
111 return generic_file_open(td, f);
112}
113
114/*
115 * Hook for closing a file. See fio_skeleton_open().
116 */
117static int fio_skeleton_close(struct thread_data *td, struct fio_file *f)
118{
119 generic_file_close(td, f);
120}
121
da51c050
JA
122/*
123 * Note that the structure is exported, so that fio can get it via
124 * dlsym(..., "ioengine");
125 */
126struct ioengine_ops ioengine = {
127 .name = "engine_name",
128 .version = FIO_IOOPS_VERSION,
129 .init = fio_skeleton_init,
130 .prep = fio_skeleton_prep,
131 .queue = fio_skeleton_queue,
830a78b0 132 .cancel = fio_skeleton_cancel,
da51c050
JA
133 .getevents = fio_skeleton_getevents,
134 .event = fio_skeleton_event,
135 .cleanup = fio_skeleton_cleanup,
b5af8293
JA
136 .open_file = fio_skeleton_open,
137 .close_file = fio_skeleton_close,
da51c050 138};