Commit | Line | Data |
---|---|---|
a467027e DM |
1 | /* |
2 | * ftruncate: ioengine for git://git.kernel.dk/fio.git | |
3 | * | |
4 | * IO engine that does regular truncates to simulate data transfer | |
5 | * as fio ioengine. | |
6 | * DDIR_WRITE does ftruncate | |
7 | * | |
8 | */ | |
a467027e | 9 | #include <errno.h> |
3d2d14bc | 10 | #include <unistd.h> |
a467027e DM |
11 | |
12 | #include "../fio.h" | |
a467027e | 13 | |
d3b07186 BVA |
14 | static enum fio_q_status |
15 | fio_ftruncate_queue(struct thread_data *td, struct io_u *io_u) | |
a467027e DM |
16 | { |
17 | struct fio_file *f = io_u->file; | |
18 | int ret; | |
19 | fio_ro_check(td, io_u); | |
20 | ||
21 | if (io_u->ddir != DDIR_WRITE) { | |
22 | io_u->error = EINVAL; | |
23 | return FIO_Q_COMPLETED; | |
24 | } | |
25 | ret = ftruncate(f->fd, io_u->offset); | |
26 | ||
27 | if (ret) | |
28 | io_u->error = errno; | |
29 | ||
30 | return FIO_Q_COMPLETED; | |
31 | } | |
32 | ||
33 | static struct ioengine_ops ioengine = { | |
34 | .name = "ftruncate", | |
35 | .version = FIO_IOOPS_VERSION, | |
36 | .queue = fio_ftruncate_queue, | |
37 | .open_file = generic_open_file, | |
38 | .close_file = generic_close_file, | |
39 | .get_file_size = generic_get_file_size, | |
40 | .flags = FIO_SYNCIO | FIO_FAKEIO | |
41 | }; | |
42 | ||
43 | static void fio_init fio_syncio_register(void) | |
44 | { | |
45 | register_ioengine(&ioengine); | |
46 | } | |
47 | ||
48 | static void fio_exit fio_syncio_unregister(void) | |
49 | { | |
50 | unregister_ioengine(&ioengine); | |
51 | } |