Add 'allow_file_create' option
authorJens Axboe <axboe@fb.com>
Tue, 12 May 2015 15:31:32 +0000 (11:31 -0400)
committerJens Axboe <axboe@fb.com>
Tue, 12 May 2015 15:31:32 +0000 (11:31 -0400)
For running certain jobs, it's convenient to tell fio that you never
want it to create files. On Linux, this prevents filling up /dev
with data for cases where the specified block device isn't available.

Signed-off-by: Jens Axboe <axboe@fb.com>
HOWTO
cconv.c
filesetup.c
fio.1
options.c
server.h
thread_options.h

diff --git a/HOWTO b/HOWTO
index 406cfca0d3ba855e5261878d66ae9fcd7c976723..74475129fd417f85c083872b27d8d0486f88936a 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1199,6 +1199,11 @@ create_only=bool If true, fio will only run the setup phase of the job.
                        that will be done. The actual job contents are not
                        executed.
 
+allow_file_create=bool If true, fio is permitted to create files as part
+               of its workload. This is the default behavior. If this
+               option is false, then fio will error out if the files it
+               needs to use don't already exist. Default: true.
+
 pre_read=bool  If this is given, files will be pre-read into memory before
                starting the given IO operation. This will also clear
                the 'invalidate' flag, since it is pointless to pre-read
diff --git a/cconv.c b/cconv.c
index bc9edb2df2b5b83c4c7e58995117df77a48ed0e9..b0becb8b96691b17508f0f219564db14f3634ffd 100644 (file)
--- a/cconv.c
+++ b/cconv.c
@@ -72,6 +72,7 @@ void convert_thread_options_to_cpu(struct thread_options *o,
        string_to_cpu(&o->profile, top->profile);
        string_to_cpu(&o->cgroup, top->cgroup);
 
+       o->allow_create = le32_to_cpu(top->allow_create);
        o->td_ddir = le32_to_cpu(top->td_ddir);
        o->rw_seq = le32_to_cpu(top->rw_seq);
        o->kb_base = le32_to_cpu(top->kb_base);
@@ -288,6 +289,7 @@ void convert_thread_options_to_net(struct thread_options_pack *top,
        string_to_net(top->profile, o->profile);
        string_to_net(top->cgroup, o->cgroup);
 
+       top->allow_create = cpu_to_le32(o->allow_create);
        top->td_ddir = cpu_to_le32(o->td_ddir);
        top->rw_seq = cpu_to_le32(o->rw_seq);
        top->kb_base = cpu_to_le32(o->kb_base);
index aee7ece9da3a8829fedc0884dfff3f0bb00ca182..cf8ae94c86b83c516411396b336f720e5ab03931 100644 (file)
@@ -65,7 +65,9 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
                }
        }
 
-       flags = O_WRONLY | O_CREAT;
+       flags = O_WRONLY;
+       if (td->o.allow_create)
+               flags |= O_CREAT;
        if (new_layout)
                flags |= O_TRUNC;
 
@@ -76,7 +78,13 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
        dprint(FD_FILE, "open file %s, flags %x\n", f->file_name, flags);
        f->fd = open(f->file_name, flags, 0644);
        if (f->fd < 0) {
-               td_verror(td, errno, "open");
+               int err = errno;
+
+               if (err == ENOENT && !td->o.allow_create)
+                       log_err("fio: file creation disallowed by "
+                                       "allow_file_create=0\n");
+               else
+                       td_verror(td, err, "open");
                return 1;
        }
 
@@ -539,7 +547,7 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
        }
        if (td->o.sync_io)
                flags |= O_SYNC;
-       if (td->o.create_on_open)
+       if (td->o.create_on_open && td->o.allow_create)
                flags |= O_CREAT;
 skip_flags:
        if (f->filetype != FIO_TYPE_FILE)
@@ -550,7 +558,7 @@ open_again:
                if (!read_only)
                        flags |= O_RDWR;
 
-               if (f->filetype == FIO_TYPE_FILE)
+               if (f->filetype == FIO_TYPE_FILE && td->o.allow_create)
                        flags |= O_CREAT;
 
                if (is_std)
diff --git a/fio.1 b/fio.1
index 6c4e5c8f16ad492be550ff73f4b291b077ec113d..d5e5536b8fc59b5a4beb472154ee0a2054762c1b 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -1075,6 +1075,11 @@ If true, fio will only run the setup phase of the job. If files need to be
 laid out or updated on disk, only that will be done. The actual job contents
 are not executed.
 .TP
+.BI allow_file_create \fR=\fPbool
+If true, fio is permitted to create files as part of its workload. This is
+the default behavior. If this option is false, then fio will error out if the
+files it needs to use don't already exist. Default: true.
+.TP
 .BI pre_read \fR=\fPbool
 If this is given, files will be pre-read into memory before starting the given
 IO operation. This will also clear the \fR \fBinvalidate\fR flag, since it is
index 5c6ec2321bd13819742ed9056318a222a51f88d3..ce1d11ef8616d669ed6a2bc8758c7f36edee23c2 100644 (file)
--- a/options.c
+++ b/options.c
@@ -3039,6 +3039,15 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
                .category = FIO_OPT_C_FILE,
                .def    = "0",
        },
+       {
+               .name   = "allow_file_create",
+               .type   = FIO_OPT_BOOL,
+               .off1   = td_var_offset(allow_create),
+               .help   = "Permit fio to create files, if they don't exist",
+               .def    = "1",
+               .category = FIO_OPT_C_FILE,
+               .group  = FIO_OPT_G_FILENAME,
+       },
        {
                .name   = "pre_read",
                .lname  = "Pre-read files",
index b0cea150233e98e8f0838c24510b74e35db459a5..b94c22183c9d5605ce20ee875cca0a95615e389c 100644 (file)
--- a/server.h
+++ b/server.h
@@ -38,7 +38,7 @@ struct fio_net_cmd_reply {
 };
 
 enum {
-       FIO_SERVER_VER                  = 44,
+       FIO_SERVER_VER                  = 45,
 
        FIO_SERVER_MAX_FRAGMENT_PDU     = 1024,
        FIO_SERVER_MAX_CMD_MB           = 2048,
index f967a8a10aa4fc4da5212b48eabf4c427b3fc999..aed39c80f46420458897829bec627137880de988 100644 (file)
@@ -270,6 +270,8 @@ struct thread_options {
        unsigned int replay_scale;
 
        unsigned int per_job_logs;
+
+       unsigned int allow_create;
 };
 
 #define FIO_TOP_STR_MAX                256
@@ -505,6 +507,8 @@ struct thread_options_pack {
        uint32_t replay_scale;
 
        uint32_t per_job_logs;
+
+       uint32_t allow_create;
 } __attribute__((packed));
 
 extern void convert_thread_options_to_cpu(struct thread_options *o, struct thread_options_pack *top);