iolog: Ignore re-add/re-open with replay_redirect
authorSitsofe Wheeler <sitsofe@yahoo.com>
Mon, 12 Dec 2016 12:11:39 +0000 (12:11 +0000)
committerSitsofe Wheeler <sitsofe@yahoo.com>
Mon, 12 Dec 2016 12:13:28 +0000 (12:13 +0000)
The HOWTO entry for replay_redirect says:
"Replay_redirect causes all IOPS to be replayed onto
the single specified device regardless of the device it was
recorded from. i.e. replay_redirect=/dev/sdc would cause all
IO in the blktrace or iolog to be replayed onto /dev/sdc.
This means multiple devices will be replayed onto a single
device, if the trace contains multiple devices."

Unfortunately trying to replay the following iolog (saved as
redirtest.fiolog):
fio version 2 iolog
/dev/sdb add
/dev/sdc add
/dev/sdb open
/dev/sdc open
/dev/sdb read 0 512
/dev/sdc read 512 512
/dev/sdb close
/dev/sdc close

with an fio line like
fio --name=redirtest --replay_redirect=/dev/nullb0 --read_iolog=redirtest.fiolog
winds up hitting this assertion:
fio: ioengines.c:413: td_io_open_file: Assertion `!fio_file_open(f)' failed.
which occurs because after redirection is applied /dev/nullb0 is added and
opened twice.

Fix this by ignoring subsequent adds or opens for the same file during
iolog replay setup when replay_redirect is in effect.

Signed-off-by: Sitsofe Wheeler <sitsofe@yahoo.com>
iolog.c

diff --git a/iolog.c b/iolog.c
index 2bc3e3a1ca9961d0d2ac1f88fb40f0afcafe18b7..0c3382d37371ee60ebaba0709ce053c7b64243e5 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -109,6 +109,11 @@ static int ipo_special(struct thread_data *td, struct io_piece *ipo)
 
        switch (ipo->file_action) {
        case FIO_LOG_OPEN_FILE:
 
        switch (ipo->file_action) {
        case FIO_LOG_OPEN_FILE:
+               if (td->o.replay_redirect && fio_file_open(f)) {
+                       dprint(FD_FILE, "iolog: ignoring re-open of file %s\n",
+                                       f->file_name);
+                       break;
+               }
                ret = td_io_open_file(td, f);
                if (!ret)
                        break;
                ret = td_io_open_file(td, f);
                if (!ret)
                        break;
@@ -396,8 +401,14 @@ static int read_iolog2(struct thread_data *td, FILE *f)
                } else if (r == 2) {
                        rw = DDIR_INVAL;
                        if (!strcmp(act, "add")) {
                } else if (r == 2) {
                        rw = DDIR_INVAL;
                        if (!strcmp(act, "add")) {
-                               fileno = add_file(td, fname, 0, 1);
-                               file_action = FIO_LOG_ADD_FILE;
+                               if (td->o.replay_redirect &&
+                                   get_fileno(td, fname) != -1) {
+                                       dprint(FD_FILE, "iolog: ignoring"
+                                               " re-add of file %s\n", fname);
+                               } else {
+                                       fileno = add_file(td, fname, 0, 1);
+                                       file_action = FIO_LOG_ADD_FILE;
+                               }
                                continue;
                        } else if (!strcmp(act, "open")) {
                                fileno = get_fileno(td, fname);
                                continue;
                        } else if (!strcmp(act, "open")) {
                                fileno = get_fileno(td, fname);