chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 1 | /* |
| 2 | * glusterfs engine |
| 3 | * |
| 4 | * IO engine using Glusterfs's gfapi sync interface |
| 5 | * |
| 6 | */ |
| 7 | |
| 8 | #include "gfapi.h" |
| 9 | |
| 10 | #define LAST_POS(f) ((f)->engine_data) |
| 11 | static int fio_gf_prep(struct thread_data *td, struct io_u *io_u) |
| 12 | { |
| 13 | struct fio_file *f = io_u->file; |
| 14 | struct gf_data *g = td->io_ops->data; |
| 15 | |
| 16 | dprint(FD_FILE, "fio prep\n"); |
| 17 | |
| 18 | if (!ddir_rw(io_u->ddir)) |
| 19 | return 0; |
| 20 | |
| 21 | if (LAST_POS(f) != -1ULL && LAST_POS(f) == io_u->offset) |
| 22 | return 0; |
| 23 | |
| 24 | if (glfs_lseek(g->fd, io_u->offset, SEEK_SET) < 0) { |
| 25 | td_verror(td, errno, "lseek"); |
| 26 | return 1; |
| 27 | } |
| 28 | |
| 29 | return 0; |
| 30 | } |
| 31 | |
| 32 | static int fio_gf_queue(struct thread_data *td, struct io_u *io_u) |
| 33 | { |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 34 | struct gf_data *g = td->io_ops->data; |
| 35 | int ret = 0; |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 36 | |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 37 | dprint(FD_FILE, "fio queue len %lu\n", io_u->xfer_buflen); |
| 38 | fio_ro_check(td, io_u); |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 39 | |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 40 | if (io_u->ddir == DDIR_READ) |
| 41 | ret = glfs_read(g->fd, io_u->xfer_buf, io_u->xfer_buflen, 0); |
| 42 | else if (io_u->ddir == DDIR_WRITE) |
| 43 | ret = glfs_write(g->fd, io_u->xfer_buf, io_u->xfer_buflen, 0); |
| 44 | else { |
| 45 | log_err("unsupported operation.\n"); |
| 46 | return -EINVAL; |
| 47 | } |
| 48 | dprint(FD_FILE, "fio len %lu ret %d\n", io_u->xfer_buflen, ret); |
| 49 | if (io_u->file && ret >= 0 && ddir_rw(io_u->ddir)) |
| 50 | LAST_POS(io_u->file) = io_u->offset + ret; |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 51 | |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 52 | if (ret != (int)io_u->xfer_buflen) { |
| 53 | if (ret >= 0) { |
| 54 | io_u->resid = io_u->xfer_buflen - ret; |
| 55 | io_u->error = 0; |
| 56 | return FIO_Q_COMPLETED; |
| 57 | } else |
| 58 | io_u->error = errno; |
| 59 | } |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 60 | |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 61 | if (io_u->error) { |
| 62 | log_err("IO failed.\n"); |
| 63 | td_verror(td, io_u->error, "xfer"); |
| 64 | } |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 65 | |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 66 | return FIO_Q_COMPLETED; |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 67 | |
| 68 | } |
| 69 | |
| 70 | static struct ioengine_ops ioengine = { |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 71 | .name = "gfapi", |
| 72 | .version = FIO_IOOPS_VERSION, |
| 73 | .init = fio_gf_setup, |
| 74 | .cleanup = fio_gf_cleanup, |
| 75 | .prep = fio_gf_prep, |
| 76 | .queue = fio_gf_queue, |
| 77 | .open_file = fio_gf_open_file, |
| 78 | .close_file = fio_gf_close_file, |
Castor Fu | 9187a26 | 2014-08-19 09:28:53 -0700 | [diff] [blame^] | 79 | .unlink_file = fio_gf_unlink_file, |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 80 | .get_file_size = fio_gf_get_file_size, |
| 81 | .options = gfapi_options, |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 82 | .option_struct_size = sizeof(struct gf_options), |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 83 | .flags = FIO_SYNCIO | FIO_DISKLESSIO, |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | static void fio_init fio_gf_register(void) |
| 87 | { |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 88 | register_ioengine(&ioengine); |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void fio_exit fio_gf_unregister(void) |
| 92 | { |
Jens Axboe | 3b66546 | 2014-05-19 10:12:56 -0600 | [diff] [blame] | 93 | unregister_ioengine(&ioengine); |
chenh | cb92c7f | 2014-04-02 13:01:01 -0400 | [diff] [blame] | 94 | } |