engine: add ftruncate ioengine
authorDmitry Monakhov <dmonakhov@openvz.org>
Fri, 7 Apr 2017 04:59:01 +0000 (07:59 +0300)
committerDmitry Monakhov <dmonakhov@openvz.org>
Fri, 7 Apr 2017 04:59:01 +0000 (07:59 +0300)
Currently fio does many things but it still cannot substitute fsx
because it does not support ftruncate. Let's add this.

Makefile
engines/ftruncate.c [new file with mode: 0644]

index 37150c69747cc0db120b027a334199fcdce5a892..66083ffcfd70fc8b4d7f17109b89a4e5fe72c2ed 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -42,6 +42,7 @@ SOURCE :=     $(patsubst $(SRCDIR)/%,%,$(wildcard $(SRCDIR)/crc/*.c)) \
                eta.c verify.c memory.c io_u.c parse.c mutex.c options.c \
                smalloc.c filehash.c profile.c debug.c engines/cpu.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
+               engines/ftruncate.c \
                server.c client.c iolog.c backend.c libfio.c flow.c cconv.c \
                gettime-thread.c helpers.c json.c idletime.c td_error.c \
                profiles/tiobench.c profiles/act.c io_u_queue.c filelock.c \
diff --git a/engines/ftruncate.c b/engines/ftruncate.c
new file mode 100644 (file)
index 0000000..e86dbac
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * ftruncate: ioengine for git://git.kernel.dk/fio.git
+ *
+ * IO engine that does regular truncates to simulate data transfer
+ * as fio ioengine.
+ * DDIR_WRITE does ftruncate
+ *
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/uio.h>
+#include <errno.h>
+#include <assert.h>
+#include <fcntl.h>
+
+#include "../fio.h"
+#include "../filehash.h"
+
+static int fio_ftruncate_queue(struct thread_data *td, struct io_u *io_u)
+{
+       struct fio_file *f = io_u->file;
+       int ret;
+       fio_ro_check(td, io_u);
+
+       if (io_u->ddir != DDIR_WRITE) {
+               io_u->error = EINVAL;
+               return FIO_Q_COMPLETED;
+       }
+       ret = ftruncate(f->fd, io_u->offset);
+
+       if (ret)
+               io_u->error = errno;
+
+       return FIO_Q_COMPLETED;
+}
+
+static struct ioengine_ops ioengine = {
+       .name           = "ftruncate",
+       .version        = FIO_IOOPS_VERSION,
+       .queue          = fio_ftruncate_queue,
+       .open_file      = generic_open_file,
+       .close_file     = generic_close_file,
+       .get_file_size  = generic_get_file_size,
+       .flags          = FIO_SYNCIO | FIO_FAKEIO
+};
+
+static void fio_init fio_syncio_register(void)
+{
+       register_ioengine(&ioengine);
+}
+
+static void fio_exit fio_syncio_unregister(void)
+{
+       unregister_ioengine(&ioengine);
+}