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 extention
8 * DDIR_TRIM does fallocate(,mode = FALLOC_FL_KEEP_SIZE | FALLOC_FL_PUNCH_HOLE)
20 #include "../filehash.h"
23 * generic_open_file is not appropriate because does not allow to perform
26 int open_file(struct thread_data *td, struct fio_file *f)
30 dprint(FD_FILE, "fd open %s\n", f->file_name);
32 if (f->filetype != FIO_TYPE_FILE) {
33 log_err("fio: only files are supported fallocate \n");
36 if (!strcmp(f->file_name, "-")) {
37 log_err("fio: can't read/write to stdin/out\n");
42 from_hash = file_lookup_open(f, O_CREAT|O_RDWR);
45 char buf[FIO_VERROR_SIZE];
47 snprintf(buf, sizeof(buf) - 1, "open(%s)", f->file_name);
48 td_verror(td, __e, buf);
51 if (!from_hash && f->fd != -1) {
52 if (add_file_hash(f)) {
56 * OK to ignore, we haven't done anything with it
58 ret = generic_close_file(td, f);
66 #ifndef FALLOC_FL_KEEP_SIZE
67 #define FALLOC_FL_KEEP_SIZE 0x01 /* default is extend size */
69 #ifndef FALLOC_FL_PUNCH_HOLE
70 #define FALLOC_FL_PUNCH_HOLE 0x02 /* de-allocates range */
72 static int fio_fallocate_queue(struct thread_data *td, struct io_u *io_u)
74 struct fio_file *f = io_u->file;
78 fio_ro_check(td, io_u);
80 if (io_u->ddir == DDIR_READ)
81 flags = FALLOC_FL_KEEP_SIZE;
82 else if (io_u->ddir == DDIR_WRITE)
84 else if (io_u->ddir == DDIR_TRIM)
85 flags = FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE;
87 ret = fallocate(f->fd, flags, io_u->offset, io_u->xfer_buflen);
92 return FIO_Q_COMPLETED;
95 static struct ioengine_ops ioengine = {
97 .version = FIO_IOOPS_VERSION,
98 .queue = fio_fallocate_queue,
99 .open_file = open_file,
100 .close_file = generic_close_file,
101 .get_file_size = generic_get_file_size,
105 static void fio_init fio_syncio_register(void)
107 register_ioengine(&ioengine);
110 static void fio_exit fio_syncio_unregister(void)
112 unregister_ioengine(&ioengine);