Jens Axboe | da51c05 | 2006-11-07 16:02:11 +0100 | [diff] [blame] | 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" |
Jens Axboe | da51c05 | 2006-11-07 16:02:11 +0100 | [diff] [blame] | 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 | |
| 23 | /* |
Jens Axboe | 830a78b | 2006-11-08 09:58:59 +0100 | [diff] [blame] | 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 | */ |
| 29 | static 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 | */ |
Jens Axboe | e7d2e61 | 2007-12-11 10:49:39 +0100 | [diff] [blame] | 40 | static int fio_skeleton_getevents(struct thread_data *td, unsigned int min, |
| 41 | unsigned int max, struct timespec *t) |
Jens Axboe | 830a78b | 2006-11-08 09:58:59 +0100 | [diff] [blame] | 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 | */ |
| 50 | static 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. |
Jens Axboe | e2a26d2 | 2007-02-06 20:17:21 +0100 | [diff] [blame] | 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 |
Bruce Cran | 03e20d6 | 2011-01-02 20:14:54 +0100 | [diff] [blame] | 62 | * io_u->xfer_buflen. Residual data count may be set in io_u->resid |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 63 | * for a short read/write. |
Jens Axboe | 830a78b | 2006-11-08 09:58:59 +0100 | [diff] [blame] | 64 | */ |
| 65 | static int fio_skeleton_queue(struct thread_data *td, struct io_u *io_u) |
| 66 | { |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 67 | /* |
Jens Axboe | 7101d9c | 2007-09-12 13:12:39 +0200 | [diff] [blame] | 68 | * Double sanity check to catch errant write on a readonly setup |
| 69 | */ |
| 70 | fio_ro_check(td, io_u); |
| 71 | |
| 72 | /* |
Jens Axboe | 36167d8 | 2007-02-18 05:41:31 +0100 | [diff] [blame] | 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; |
Jens Axboe | 830a78b | 2006-11-08 09:58:59 +0100 | [diff] [blame] | 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 |
Jens Axboe | 34403fb | 2007-03-02 21:43:25 +0100 | [diff] [blame] | 84 | * preparatory actions on the io_u, before being submitted. Not required. |
Jens Axboe | 830a78b | 2006-11-08 09:58:59 +0100 | [diff] [blame] | 85 | */ |
| 86 | static 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 | */ |
| 96 | static 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 | */ |
| 106 | static void fio_skeleton_cleanup(struct thread_data *td) |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | /* |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 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 | */ |
| 114 | static 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 | */ |
| 122 | static int fio_skeleton_close(struct thread_data *td, struct fio_file *f) |
| 123 | { |
| 124 | generic_file_close(td, f); |
| 125 | } |
| 126 | |
| 127 | /* |
Jens Axboe | da51c05 | 2006-11-07 16:02:11 +0100 | [diff] [blame] | 128 | * Note that the structure is exported, so that fio can get it via |
| 129 | * dlsym(..., "ioengine"); |
| 130 | */ |
| 131 | struct 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, |
Jens Axboe | 830a78b | 2006-11-08 09:58:59 +0100 | [diff] [blame] | 137 | .cancel = fio_skeleton_cancel, |
Jens Axboe | da51c05 | 2006-11-07 16:02:11 +0100 | [diff] [blame] | 138 | .getevents = fio_skeleton_getevents, |
| 139 | .event = fio_skeleton_event, |
| 140 | .cleanup = fio_skeleton_cleanup, |
Jens Axboe | b5af829 | 2007-03-08 12:43:13 +0100 | [diff] [blame] | 141 | .open_file = fio_skeleton_open, |
| 142 | .close_file = fio_skeleton_close, |
Jens Axboe | da51c05 | 2006-11-07 16:02:11 +0100 | [diff] [blame] | 143 | }; |