Add nr parameter to file_service_type
Right now we switch for every IO, add a postfix that allows to switch
for every 'x' number of ios.
Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
diff --git a/HOWTO b/HOWTO
index 1374d05..f9e3fc7 100644
--- a/HOWTO
+++ b/HOWTO
@@ -265,6 +265,11 @@
roundrobin Round robin over open files. This
is the default.
+ The string can have a number appended, indicating how
+ often to switch to a new file. So if option random:4 is
+ given, fio will switch to a new random file after 4 ios
+ have been issued.
+
ioengine=str Defines how the job issues io to the file. The following
types are defined:
diff --git a/fio.h b/fio.h
index a60be10..9d190b1 100644
--- a/fio.h
+++ b/fio.h
@@ -473,6 +473,13 @@
*/
struct timeval timeout_end;
struct itimerval timer;
+
+ /*
+ * for fileservice, how often to switch to a new file
+ */
+ unsigned int file_service_nr;
+ unsigned int file_service_left;
+ struct fio_file *file_service_file;
};
/*
diff --git a/init.c b/init.c
index 2129882..eee2335 100644
--- a/init.c
+++ b/init.c
@@ -30,6 +30,7 @@
#endif
static int str_exitall_cb(void);
static int str_cpumask_cb(void *, unsigned int *);
+static int str_fst_cb(void *, const char *);
#define __stringify_1(x) #x
#define __stringify(x) __stringify_1(x)
@@ -190,6 +191,7 @@
{
.name = "file_service_type",
.type = FIO_OPT_STR,
+ .cb = str_fst_cb,
.off1 = td_var_offset(file_service_type),
.help = "How to select which file to service next",
.def = "roundrobin",
@@ -1048,7 +1050,7 @@
/*
* Check if mmap/mmaphuge has a :/foo/bar/file at the end. If so, return that.
*/
-static char *get_mmap_file(const char *str)
+static char *get_opt_postfix(const char *str)
{
char *p = strstr(str, ":");
@@ -1066,7 +1068,7 @@
struct thread_data *td = data;
if (td->mem_type == MEM_MMAPHUGE || td->mem_type == MEM_MMAP) {
- td->mmapfile = get_mmap_file(mem);
+ td->mmapfile = get_opt_postfix(mem);
if (td->mem_type == MEM_MMAPHUGE && !td->mmapfile) {
log_err("fio: mmaphuge:/path/to/file\n");
return 1;
@@ -1114,6 +1116,18 @@
return 0;
}
+static int str_fst_cb(void *data, const char *str)
+{
+ struct thread_data *td = data;
+ char *nr = get_opt_postfix(str);
+
+ td->file_service_nr = 1;
+ if (nr)
+ td->file_service_nr = atoi(nr);
+
+ return 0;
+}
+
/*
* This is our [ini] type file parser.
*/
diff --git a/io_u.c b/io_u.c
index e283e72..c9a344f 100644
--- a/io_u.c
+++ b/io_u.c
@@ -368,13 +368,23 @@
static struct fio_file *get_next_file(struct thread_data *td)
{
+ struct fio_file *f;
+
if (!td->nr_open_files)
return NULL;
+ f = td->file_service_file;
+ if (f && f->open && td->file_service_left--)
+ return f;
+
if (td->file_service_type == FIO_FSERVICE_RR)
- return get_next_file_rr(td);
+ f = get_next_file_rr(td);
else
- return get_next_file_rand(td);
+ f = get_next_file_rand(td);
+
+ td->file_service_file = f;
+ td->file_service_left = td->file_service_nr - 1;
+ return f;
}
struct io_u *__get_io_u(struct thread_data *td)