sg engine: IO should be done sync of O_SYNC and O_DIRECT
[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 */
e7d2e616
JA
40static int fio_skeleton_getevents(struct thread_data *td, unsigned int min,
41 unsigned int max, struct timespec *t)
830a78b0
JA
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{
7101d9c2
JA
67 /*
68 * Double sanity check to catch errant write on a readonly setup
69 */
70 fio_ro_check(td, io_u);
71
36167d82
JA
72 /*
73 * Could return FIO_Q_QUEUED for a queued request,
74 * FIO_Q_COMPLETED for a completed request, and FIO_Q_BUSY
75 * if we could queue no more at this point (you'd have to
76 * define ->commit() to handle that.
77 */
78 return FIO_Q_COMPLETED;
830a78b0
JA
79}
80
81/*
82 * The ->prep() function is called for each io_u prior to being submitted
83 * with ->queue(). This hook allows the io engine to perform any
34403fb1 84 * preparatory actions on the io_u, before being submitted. Not required.
830a78b0
JA
85 */
86static int fio_skeleton_prep(struct thread_data *td, struct io_u *io_u)
87{
88 return 0;
89}
90
91/*
92 * The init function is called once per thread/process, and should set up
93 * any structures that this io engine requires to keep track of io. Not
94 * required.
95 */
96static int fio_skeleton_init(struct thread_data *td)
97{
98 return 0;
99}
100
101/*
102 * This is paired with the ->init() funtion and is called when a thread is
103 * done doing io. Should tear down anything setup by the ->init() function.
104 * Not required.
105 */
106static void fio_skeleton_cleanup(struct thread_data *td)
107{
108}
109
b5af8293
JA
110/*
111 * Hook for opening the given file. Unless the engine has special
112 * needs, it usually just provides generic_file_open() as the handler.
113 */
114static int fio_skeleton_open(struct thread_data *td, struct fio_file *f)
115{
116 return generic_file_open(td, f);
117}
118
119/*
120 * Hook for closing a file. See fio_skeleton_open().
121 */
122static int fio_skeleton_close(struct thread_data *td, struct fio_file *f)
123{
124 generic_file_close(td, f);
125}
126
da51c050
JA
127/*
128 * Note that the structure is exported, so that fio can get it via
129 * dlsym(..., "ioengine");
130 */
131struct ioengine_ops ioengine = {
132 .name = "engine_name",
133 .version = FIO_IOOPS_VERSION,
134 .init = fio_skeleton_init,
135 .prep = fio_skeleton_prep,
136 .queue = fio_skeleton_queue,
830a78b0 137 .cancel = fio_skeleton_cancel,
da51c050
JA
138 .getevents = fio_skeleton_getevents,
139 .event = fio_skeleton_event,
140 .cleanup = fio_skeleton_cleanup,
b5af8293
JA
141 .open_file = fio_skeleton_open,
142 .close_file = fio_skeleton_close,
da51c050 143};