From: Jens Axboe Date: Tue, 11 Sep 2007 18:02:05 +0000 (+0200) Subject: Add --readonly option X-Git-Tag: fio-1.17.2~23 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=724e4435c1374e97309b122429ad9291744966c0;ds=sidebyside Add --readonly option Suggested by Valerie Henson. It can be used as an extra safety guard against accidentically turning on a write setting. See README. Signed-off-by: Jens Axboe --- diff --git a/README b/README index 76aa22d6..b7fc96b6 100644 --- a/README +++ b/README @@ -71,12 +71,19 @@ $ fio --help Print this page --cmdhelp=cmd Print command help, "all" for all of them --showcmd Turn a job file into command line options + --readonly Turn on safety read-only checks Any parameters following the options will be assumed to be job files, unless they match a job file parameter. You can add as many as you want, each job file will be regarded as a separate group and fio will stonewall its execution. +The --readonly switch is an extra safety guard to prevent accidentically +turning on a write setting when that is not desired. Fio will only write +if rw=write/randwrite/rw/randrw is given, but this extra safety net can +be used as an extra precaution. It will also enable a write check in the +io engine core to prevent an accidental write due to a fio bug. + Job file -------- diff --git a/init.c b/init.c index f3cb9ad6..2a1ee149 100644 --- a/init.c +++ b/init.c @@ -24,6 +24,7 @@ static char fio_version_string[] = "fio 1.17.1"; static char **ini_file; static int max_jobs = MAX_JOBS; static int dump_cmdline; +static int read_only; struct thread_data def_thread; struct thread_data *threads = NULL; @@ -89,7 +90,12 @@ static struct option long_options[FIO_NR_OPTIONS] = { { .name = "showcmd", .has_arg = no_argument, - .val = 's' + .val = 's', + }, + { + .name = "readonly", + .has_arg = no_argument, + .val = 'r', }, { .name = NULL, @@ -180,6 +186,11 @@ static int fixup_options(struct thread_data *td) { struct thread_options *o = &td->o; + if (read_only && td_write(td)) { + log_err("fio: job <%s> has write bit set, but fio is in read-only mode\n", td->o.name); + return 1; + } + if (o->rwmix[DDIR_READ] + o->rwmix[DDIR_WRITE] > 100) o->rwmix[DDIR_WRITE] = 100 - o->rwmix[DDIR_READ]; @@ -768,6 +779,9 @@ static int parse_cmd_line(int argc, char *argv[]) case 's': dump_cmdline = 1; break; + case 'r': + read_only = 1; + break; case 'v': printf("%s\n", fio_version_string); exit(0); diff --git a/ioengines.c b/ioengines.c index 8cdabe6f..8e6fae22 100644 --- a/ioengines.c +++ b/ioengines.c @@ -187,6 +187,8 @@ int td_io_queue(struct thread_data *td, struct io_u *io_u) assert(io_u->file->flags & FIO_FILE_OPEN); + assert(!(io_u->ddir == DDIR_WRITE && !td_write(td))); + io_u->error = 0; io_u->resid = 0;