Commit | Line | Data |
---|---|---|
cc47f094 | 1 | /* |
2 | * glusterfs engine | |
3 | * | |
4 | * IO engine using Glusterfs's gfapi sync interface | |
5 | * | |
6 | */ | |
7 | ||
8 | #include "gfapi.h" | |
9 | ||
710bf9c5 | 10 | #define LAST_POS(f) ((f)->engine_pos) |
cc47f094 | 11 | static int fio_gf_prep(struct thread_data *td, struct io_u *io_u) |
12 | { | |
13 | struct fio_file *f = io_u->file; | |
565e784d | 14 | struct gf_data *g = td->io_ops_data; |
cc47f094 | 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 | ||
d3b07186 | 32 | static enum fio_q_status fio_gf_queue(struct thread_data *td, struct io_u *io_u) |
cc47f094 | 33 | { |
565e784d | 34 | struct gf_data *g = td->io_ops_data; |
b29c813f JA |
35 | int ret = 0; |
36 | ||
5fff9543 | 37 | dprint(FD_FILE, "fio queue len %llu\n", io_u->xfer_buflen); |
b29c813f JA |
38 | fio_ro_check(td, io_u); |
39 | ||
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); | |
656955eb | 44 | else if (io_u->ddir == DDIR_SYNC) |
ce4d13ca JA |
45 | #if defined(CONFIG_GF_NEW_API) |
46 | ret = glfs_fsync(g->fd, NULL, NULL); | |
47 | #else | |
656955eb | 48 | ret = glfs_fsync(g->fd); |
ce4d13ca | 49 | #endif |
656955eb | 50 | else if (io_u->ddir == DDIR_DATASYNC) |
ce4d13ca JA |
51 | #if defined(CONFIG_GF_NEW_API) |
52 | ret = glfs_fdatasync(g->fd, NULL, NULL); | |
53 | #else | |
656955eb | 54 | ret = glfs_fdatasync(g->fd); |
ce4d13ca | 55 | #endif |
b29c813f JA |
56 | else { |
57 | log_err("unsupported operation.\n"); | |
d9bac1c6 BVA |
58 | io_u->error = EINVAL; |
59 | return FIO_Q_COMPLETED; | |
b29c813f | 60 | } |
5fff9543 | 61 | dprint(FD_FILE, "fio len %llu ret %d\n", io_u->xfer_buflen, ret); |
b29c813f JA |
62 | if (io_u->file && ret >= 0 && ddir_rw(io_u->ddir)) |
63 | LAST_POS(io_u->file) = io_u->offset + ret; | |
64 | ||
65 | if (ret != (int)io_u->xfer_buflen) { | |
66 | if (ret >= 0) { | |
67 | io_u->resid = io_u->xfer_buflen - ret; | |
68 | io_u->error = 0; | |
69 | return FIO_Q_COMPLETED; | |
70 | } else | |
71 | io_u->error = errno; | |
72 | } | |
73 | ||
74 | if (io_u->error) { | |
75 | log_err("IO failed.\n"); | |
76 | td_verror(td, io_u->error, "xfer"); | |
77 | } | |
78 | ||
79 | return FIO_Q_COMPLETED; | |
cc47f094 | 80 | |
81 | } | |
82 | ||
83 | static struct ioengine_ops ioengine = { | |
b29c813f JA |
84 | .name = "gfapi", |
85 | .version = FIO_IOOPS_VERSION, | |
86 | .init = fio_gf_setup, | |
87 | .cleanup = fio_gf_cleanup, | |
88 | .prep = fio_gf_prep, | |
89 | .queue = fio_gf_queue, | |
90 | .open_file = fio_gf_open_file, | |
91 | .close_file = fio_gf_close_file, | |
38ef9c90 | 92 | .unlink_file = fio_gf_unlink_file, |
b29c813f JA |
93 | .get_file_size = fio_gf_get_file_size, |
94 | .options = gfapi_options, | |
cc47f094 | 95 | .option_struct_size = sizeof(struct gf_options), |
b29c813f | 96 | .flags = FIO_SYNCIO | FIO_DISKLESSIO, |
cc47f094 | 97 | }; |
98 | ||
99 | static void fio_init fio_gf_register(void) | |
100 | { | |
b29c813f | 101 | register_ioengine(&ioengine); |
cc47f094 | 102 | } |
103 | ||
104 | static void fio_exit fio_gf_unregister(void) | |
105 | { | |
b29c813f | 106 | unregister_ioengine(&ioengine); |
cc47f094 | 107 | } |