Add nr parameter to file_service_type
authorJens Axboe <jens.axboe@oracle.com>
Mon, 12 Mar 2007 10:44:28 +0000 (11:44 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Mon, 12 Mar 2007 10:44:28 +0000 (11:44 +0100)
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>
HOWTO
fio.h
init.c
io_u.c

diff --git a/HOWTO b/HOWTO
index 1374d05e23d5b2d9f047826c45043f2587d11fb9..f9e3fc708530c7b963d00035a749869771d6f4f2 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -265,6 +265,11 @@ file_service_type=str  Defines how fio decides which file from a job to
                        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 a60be104c249a1028339577ef3c52afb7a77f98d..9d190b14a175d05c03144e93b796548697b52141 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -473,6 +473,13 @@ struct thread_data {
         */
        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 2129882f5309ccdaea91fe737e8f01132ed2b3e1..eee23359afc68d209366d7f95cb1c5242de111bf 100644 (file)
--- a/init.c
+++ b/init.c
@@ -30,6 +30,7 @@ static int str_prioclass_cb(void *, unsigned int *);
 #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 @@ static struct fio_option options[] = {
        {
                .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 @@ static int is_empty_or_comment(char *line)
 /*
  * 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 @@ static int str_mem_cb(void *data, const char *mem)
        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 @@ static int str_cpumask_cb(void *data, unsigned int *val)
        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 e283e7276a84ca75b6a11de4d3c40d9dcd93e716..c9a344f27aff5ebcb4a405a34e2da72d0b0b0d4a 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -368,13 +368,23 @@ static struct fio_file *get_next_file_rr(struct thread_data *td)
 
 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)