add a filecreate engine
authorJosef Bacik <josef@toxicpanda.com>
Fri, 6 Oct 2017 19:43:14 +0000 (15:43 -0400)
committerJens Axboe <axboe@kernel.dk>
Mon, 9 Oct 2017 15:10:01 +0000 (09:10 -0600)
This is for doing empty file creation jobs much like what we do with
fs_mark.  You still need to specify a filesize so that fio will pretend
to do something, but the IO won't actually be done on the file.

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
HOWTO
Makefile
engines/filecreate.c [new file with mode: 0644]
fio.1

diff --git a/HOWTO b/HOWTO
index 8fad2ce6f4d889e8de2013391ee1dad00787681d..df79e2dffb3043e771fa437f6f1845b423a41160 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1797,6 +1797,10 @@ I/O engine
                        absolute or relative. See :file:`engines/skeleton_external.c` for
                        details of writing an external I/O engine.
 
                        absolute or relative. See :file:`engines/skeleton_external.c` for
                        details of writing an external I/O engine.
 
+               **filecreate**
+                       Simply create the files and do no IO to them.  You still need to
+                       set  `filesize` so that all the accounting still occurs, but no
+                       actual IO will be done other than creating the file.
 
 I/O engine specific parameters
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 I/O engine specific parameters
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
index 3764da55085102d8d67a20d533e67cafb91ac295..76243ffb056e5cebf82939d62c66678bc476f0dc 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -42,7 +42,7 @@ SOURCE :=     $(sort $(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 \
                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 \
+               engines/ftruncate.c engines/filecreate.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 \
                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/filecreate.c b/engines/filecreate.c
new file mode 100644 (file)
index 0000000..284aaf3
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * filecreate engine
+ *
+ * IO engine that doesn't do any IO, just creates files and tracks the latency
+ * of the file creation.
+ */
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+
+#include "../fio.h"
+#include "../filehash.h"
+
+static int open_file(struct thread_data *td, struct fio_file *f)
+{
+       struct timespec start, end;
+       int from_hash = 0;
+       int do_lat = !td->o.disable_lat;
+
+       dprint(FD_FILE, "fd open %s\n", f->file_name);
+
+       if (f->filetype != FIO_TYPE_FILE) {
+               log_err("fio: only files are supported fallocate \n");
+               return 1;
+       }
+       if (!strcmp(f->file_name, "-")) {
+               log_err("fio: can't read/write to stdin/out\n");
+               return 1;
+       }
+
+open_again:
+       if (do_lat)
+               fio_gettime(&start, NULL);
+       from_hash = file_lookup_open(f, O_CREAT|O_RDWR);
+       if (do_lat) {
+               unsigned long long nsec;
+
+               fio_gettime(&end, NULL);
+               nsec = ntime_since(&start, &end);
+               add_lat_sample(td, DDIR_WRITE, nsec, 0, 0);
+       }
+
+       if (f->fd == -1) {
+               char buf[FIO_VERROR_SIZE];
+               int e = errno;
+
+               snprintf(buf, sizeof(buf), "open(%s)", f->file_name);
+               td_verror(td, e, buf);
+       }
+
+       if (!from_hash && f->fd != -1) {
+               if (add_file_hash(f)) {
+                       int fio_unused ret;
+
+                       /*
+                        * OK to ignore, we haven't done anything with it
+                        */
+                       ret = generic_close_file(td, f);
+                       goto open_again;
+               }
+       }
+
+       return 0;
+}
+
+static int queue_io(struct thread_data *td, struct io_u fio_unused *io_u)
+{
+       return FIO_Q_COMPLETED;
+}
+
+static struct ioengine_ops ioengine = {
+       .name           = "filecreate",
+       .version        = FIO_IOOPS_VERSION,
+       .open_file      = open_file,
+       .queue          = queue_io,
+       .close_file     = generic_close_file,
+       .flags          = FIO_DISKLESSIO | FIO_SYNCIO | FIO_FAKEIO,
+};
+
+static void fio_init fio_filecreate_register(void)
+{
+       register_ioengine(&ioengine);
+}
+
+static void fio_exit fio_filecreate_unregister(void)
+{
+       unregister_ioengine(&ioengine);
+}
diff --git a/fio.1 b/fio.1
index b943db2289d66c87ced5bd3b7112cf9b580db8ab..68ed3ba457b93bd18abfcce5193b39d003f8edf7 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -1577,6 +1577,10 @@ the engine filename, e.g. `ioengine=external:/tmp/foo.o' to load
 ioengine `foo.o' in `/tmp'. The path can be either
 absolute or relative. See `engines/skeleton_external.c' in the fio source for
 details of writing an external I/O engine.
 ioengine `foo.o' in `/tmp'. The path can be either
 absolute or relative. See `engines/skeleton_external.c' in the fio source for
 details of writing an external I/O engine.
+.TP
+.B filecreate
+Create empty files only.  \fBfilesize\fR still needs to be specified so that fio
+will run and grab latency results, but no IO will actually be done on the files.
 .SS "I/O engine specific parameters"
 In addition, there are some parameters which are only valid when a specific
 \fBioengine\fR is in use. These are used identically to normal parameters,
 .SS "I/O engine specific parameters"
 In addition, there are some parameters which are only valid when a specific
 \fBioengine\fR is in use. These are used identically to normal parameters,