2 * falloc: ioengine for git://git.kernel.dk/fio.git
4 * IO engine that does regular fallocate to simulate data transfer
6 * DDIR_READ does fallocate(,mode = FALLOC_FL_KEEP_SIZE,)
7 * DDIR_WRITE does fallocate(,mode = 0) : fallocate with size extension
8 * DDIR_TRIM does fallocate(,mode = FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)
16 #include "../filehash.h"
19 * generic_open_file is not appropriate because does not allow to perform
22 static int open_file(struct thread_data *td, struct fio_file *f)
26 dprint(FD_FILE, "fd open %s\n", f->file_name);
28 if (f->filetype != FIO_TYPE_FILE) {
29 log_err("fio: only files are supported fallocate \n");
32 if (!strcmp(f->file_name, "-")) {
33 log_err("fio: can't read/write to stdin/out\n");
38 from_hash = file_lookup_open(f, O_CREAT|O_RDWR);
41 char buf[FIO_VERROR_SIZE];
44 snprintf(buf, sizeof(buf), "open(%s)", f->file_name);
45 td_verror(td, e, buf);
48 if (!from_hash && f->fd != -1) {
49 if (add_file_hash(f)) {
53 * OK to ignore, we haven't done anything with it
55 ret = generic_close_file(td, f);
63 #ifndef FALLOC_FL_KEEP_SIZE
64 #define FALLOC_FL_KEEP_SIZE 0x01 /* default is extend size */
66 #ifndef FALLOC_FL_PUNCH_HOLE
67 #define FALLOC_FL_PUNCH_HOLE 0x02 /* de-allocates range */
70 static enum fio_q_status fio_fallocate_queue(struct thread_data *td,
73 struct fio_file *f = io_u->file;
77 fio_ro_check(td, io_u);
79 if (io_u->ddir == DDIR_READ)
80 flags = FALLOC_FL_KEEP_SIZE;
81 else if (io_u->ddir == DDIR_WRITE)
83 else if (io_u->ddir == DDIR_TRIM)
84 flags = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
86 ret = fallocate(f->fd, flags, io_u->offset, io_u->xfer_buflen);
91 return FIO_Q_COMPLETED;
94 static struct ioengine_ops ioengine = {
96 .version = FIO_IOOPS_VERSION,
97 .queue = fio_fallocate_queue,
98 .open_file = open_file,
99 .close_file = generic_close_file,
100 .get_file_size = generic_get_file_size,
104 static void fio_init fio_syncio_register(void)
106 register_ioengine(&ioengine);
109 static void fio_exit fio_syncio_unregister(void)
111 unregister_ioengine(&ioengine);