Skip to content

Commit

Permalink
Add 'allow_mounted_write' option
Browse files Browse the repository at this point in the history
If this isn't set, then fio will abort if a job exists that would write
to a mounted device or partition.

Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
axboe committed May 22, 2015
1 parent aae599b commit e81ecca
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
6 changes: 6 additions & 0 deletions HOWTO
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,12 @@ allow_file_create=bool If true, fio is permitted to create files as part
option is false, then fio will error out if the files it
needs to use don't already exist. Default: true.

allow_mounted_write=bool If this isn't set, fio will abort jobs that
are destructive (eg that write) to what appears to be a
mounted device or partition. This should help catch creating
inadvertently destructive tests, not realizing that the test
will destroy data on the mounted file system. Default: false.

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
Expand Down
24 changes: 24 additions & 0 deletions backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "err.h"
#include "lib/tp.h"
#include "workqueue.h"
#include "lib/mountcheck.h"

static pthread_t helper_thread;
static pthread_mutex_t helper_lock;
Expand Down Expand Up @@ -1895,6 +1896,27 @@ static void do_usleep(unsigned int usecs)
usleep(usecs);
}

static int check_mount_writes(struct thread_data *td)
{
struct fio_file *f;
unsigned int i;

if (!td_write(td) || td->o.allow_mounted_write)
return 0;

for_each_file(td, f, i) {
if (f->filetype != FIO_TYPE_BD)
continue;
if (device_is_mounted(f->file_name))
goto mounted;
}

return 0;
mounted:
log_err("fio: %s appears mounted, and 'allow_mounted_write' isn't set. Aborting.", f->file_name);
return 1;
}

/*
* Main function for kicking off and reaping jobs, as needed.
*/
Expand All @@ -1913,6 +1935,8 @@ static void run_threads(void)

nr_thread = nr_process = 0;
for_each_td(td, i) {
if (check_mount_writes(td))
return;
if (td->o.use_thread)
nr_thread++;
else
Expand Down
6 changes: 6 additions & 0 deletions fio.1
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,12 @@ 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 allow_mounted_write \fR=\fPbool
If this isn't set, fio will abort jobs that are destructive (eg that write)
to what appears to be a mounted device or partition. This should help catch
creating inadvertently destructive tests, not realizing that the test will
destroy data on the mounted file system. Default: false.
.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
Expand Down
6 changes: 6 additions & 0 deletions lib/mountcheck.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef FIO_MOUNT_CHECK_H
#define FIO_MOUNT_CHECK_H

extern int device_is_mounted(const char *);

#endif
11 changes: 11 additions & 0 deletions options.c
Original file line number Diff line number Diff line change
Expand Up @@ -3041,13 +3041,24 @@ struct fio_option fio_options[FIO_MAX_OPTS] = {
},
{
.name = "allow_file_create",
.lname = "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 = "allow_mounted_write",
.lname = "Allow mounted write",
.type = FIO_OPT_BOOL,
.off1 = td_var_offset(allow_mounted_write),
.help = "Allow writes to a mounted partition",
.def = "0",
.category = FIO_OPT_C_FILE,
.group = FIO_OPT_G_FILENAME,
},
{
.name = "pre_read",
.lname = "Pre-read files",
Expand Down
2 changes: 2 additions & 0 deletions thread_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ struct thread_options {
unsigned int per_job_logs;

unsigned int allow_create;
unsigned int allow_mounted_write;
};

#define FIO_TOP_STR_MAX 256
Expand Down Expand Up @@ -509,6 +510,7 @@ struct thread_options_pack {
uint32_t per_job_logs;

uint32_t allow_create;
uint32_t allow_mounted_write;
} __attribute__((packed));

extern void convert_thread_options_to_cpu(struct thread_options *o, struct thread_options_pack *top);
Expand Down

0 comments on commit e81ecca

Please sign in to comment.