Add --aux-path support
authorJens Axboe <axboe@fb.com>
Thu, 20 Aug 2015 19:02:05 +0000 (12:02 -0700)
committerJens Axboe <axboe@fb.com>
Thu, 20 Aug 2015 19:02:05 +0000 (12:02 -0700)
For certain files, fio just stores them in the current working
directory. This can create a bit of a mess. These files might
be verification dump files, or verification state saves.

Add --aux-path to enable storing these files in an arbitrary
directory instead.

Signed-off-by: Jens Axboe <axboe@fb.com>
README
backend.c
client.c
fio.h
init.c
verify.c
verify.h

diff --git a/README b/README
index ed8545b..9d0863d 100644 (file)
--- a/README
+++ b/README
@@ -183,6 +183,7 @@ $ fio
        --trigger-timeout=t     Execute trigger af this time
        --trigger=cmd           Set this command as local trigger
        --trigger-remote=cmd    Set this command as remote trigger
+       --aux-path=path         Use this path for fio state generated files
 
 
 Any parameters following the options will be assumed to be job files,
index 76994d9..d41c742 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1638,16 +1638,8 @@ static void *thread_main(void *data)
        td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
 
        if (td->o.verify_state_save && !(td->flags & TD_F_VSTATE_SAVED) &&
-           (td->o.verify != VERIFY_NONE && td_write(td))) {
-               struct all_io_list *state;
-               size_t sz;
-
-               state = get_all_io_list(td->thread_number, &sz);
-               if (state) {
-                       __verify_save_state(state, "local");
-                       free(state);
-               }
-       }
+           (td->o.verify != VERIFY_NONE && td_write(td)))
+               verify_save_state(td->thread_number);
 
        fio_unpin_memory(td);
 
@@ -1897,7 +1889,7 @@ void check_trigger_file(void)
                if (nr_clients)
                        fio_clients_send_trigger(trigger_remote_cmd);
                else {
-                       verify_save_state();
+                       verify_save_state(IO_LIST_ALL);
                        fio_terminate_threads(TERMINATE_ALL);
                        exec_trigger(trigger_cmd);
                }
index 110a01b..147ee38 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1497,9 +1497,15 @@ int fio_handle_client(struct fio_client *client)
                break;
        case FIO_NET_CMD_VTRIGGER: {
                struct all_io_list *pdu = (struct all_io_list *) cmd->payload;
-               char buf[64];
+               char buf[128];
+               int off = 0;
 
-               __verify_save_state(pdu, server_name(client, buf, sizeof(buf)));
+               if (aux_path) {
+                       strcpy(buf, aux_path);
+                       off = strlen(buf);
+               }
+
+               __verify_save_state(pdu, server_name(client, &buf[off], sizeof(buf) - off));
                exec_trigger(trigger_cmd);
                break;
                }
diff --git a/fio.h b/fio.h
index 17bc02b..53d8256 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -434,6 +434,7 @@ extern char *trigger_file;
 extern char *trigger_cmd;
 extern char *trigger_remote_cmd;
 extern long long trigger_timeout;
+extern char *aux_path;
 
 extern struct thread_data *threads;
 
diff --git a/init.c b/init.c
index 6d8dcff..7261248 100644 (file)
--- a/init.c
+++ b/init.c
@@ -69,6 +69,8 @@ long long trigger_timeout = 0;
 char *trigger_cmd = NULL;
 char *trigger_remote_cmd = NULL;
 
+char *aux_path = NULL;
+
 static int prev_group_jobs;
 
 unsigned long fio_debug = 0;
@@ -266,6 +268,11 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
                .has_arg        = required_argument,
                .val            = 'J',
        },
+       {
+               .name           = (char *) "aux-path",
+               .has_arg        = required_argument,
+               .val            = 'K',
+       },
        {
                .name           = NULL,
        },
@@ -1793,6 +1800,7 @@ static void usage(const char *name)
        printf("  --trigger-timeout=t\tExecute trigger af this time\n");
        printf("  --trigger=cmd\t\tSet this command as local trigger\n");
        printf("  --trigger-remote=cmd\tSet this command as remote trigger\n");
+       printf("  --aux-path=path\tUse this path for fio state generated files\n");
        printf("\nFio was written by Jens Axboe <jens.axboe@oracle.com>");
        printf("\n                   Jens Axboe <jaxboe@fusionio.com>");
        printf("\n                   Jens Axboe <axboe@fb.com>\n");
@@ -2383,6 +2391,11 @@ int parse_cmd_line(int argc, char *argv[], int client_type)
                                free(trigger_remote_cmd);
                        trigger_remote_cmd = strdup(optarg);
                        break;
+               case 'K':
+                       if (aux_path)
+                               free(aux_path);
+                       aux_path = strdup(optarg);
+                       break;
                case 'B':
                        if (check_str_time(optarg, &trigger_timeout, 1)) {
                                log_err("fio: failed parsing time %s\n", optarg);
index f833e85..3e92d15 100644 (file)
--- a/verify.c
+++ b/verify.c
@@ -231,8 +231,11 @@ static void dump_buf(char *buf, unsigned int len, unsigned long long offset,
 
        ptr = strdup(f->file_name);
 
-       fname[DUMP_BUF_SZ - 1] = '\0';
-       strncpy(fname, basename(ptr), DUMP_BUF_SZ - 1);
+       memset(fname, 0, sizeof(fname));
+       if (aux_path)
+               sprintf(fname, "%s%s", aux_path, FIO_OS_PATH_SEPARATOR);
+
+       strncpy(fname + strlen(fname), basename(ptr), buf_left - 1);
 
        buf_left -= strlen(fname);
        if (buf_left <= 0) {
@@ -1477,14 +1480,21 @@ void __verify_save_state(struct all_io_list *state, const char *prefix)
        }
 }
 
-void verify_save_state(void)
+void verify_save_state(int mask)
 {
        struct all_io_list *state;
        size_t sz;
 
-       state = get_all_io_list(IO_LIST_ALL, &sz);
+       state = get_all_io_list(mask, &sz);
        if (state) {
-               __verify_save_state(state, "local");
+               char prefix[PATH_MAX];
+
+               if (aux_path)
+                       sprintf(aux_path, "%s%slocal", aux_path, FIO_OS_PATH_SEPARATOR);
+               else
+                       strcpy(aux_path, "local");
+
+               __verify_save_state(state, prefix);
                free(state);
        }
 }
index c37b1d5..8305eeb 100644 (file)
--- a/verify.h
+++ b/verify.h
@@ -145,7 +145,7 @@ struct verify_state_hdr {
 #define IO_LIST_ALL            0xffffffff
 extern struct all_io_list *get_all_io_list(int, size_t *);
 extern void __verify_save_state(struct all_io_list *, const char *);
-extern void verify_save_state(void);
+extern void verify_save_state(int mask);
 extern int verify_load_state(struct thread_data *, const char *);
 extern void verify_free_state(struct thread_data *);
 extern int verify_state_should_stop(struct thread_data *, struct io_u *);