Fixup data-direction to name translation
authorJens Axboe <axboe@fb.com>
Wed, 17 Sep 2014 02:07:59 +0000 (20:07 -0600)
committerJens Axboe <axboe@fb.com>
Wed, 17 Sep 2014 02:07:59 +0000 (20:07 -0600)
We had two of them, and they were both wrong since trim got
introduced. Replace by a single implementation in io_ddir.h,
right where it's defined.

Reported-by: Elliott, Robert <Elliott@hp.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
io_ddir.h
io_u.c
iolog.c

index eb25c5002a8f623c9d63db8458120fb26d10c22c..a23ea626be83d9877a3c670719e7b3ef160124a4 100644 (file)
--- a/io_ddir.h
+++ b/io_ddir.h
@@ -10,9 +10,21 @@ enum fio_ddir {
        DDIR_DATASYNC,
        DDIR_SYNC_FILE_RANGE,
        DDIR_WAIT,
+       DDIR_LAST,
        DDIR_INVAL = -1,
 };
 
+static inline const char *io_ddir_name(enum fio_ddir ddir)
+{
+       const char *name[] = { "read", "write", "trim", "sync", "datasync",
+                               "sync_file_range", "write", };
+
+       if (ddir < DDIR_LAST)
+               return name[ddir];
+
+       return "invalid";
+}
+
 enum td_ddir {
        TD_DDIR_READ            = 1 << 0,
        TD_DDIR_WRITE           = 1 << 1,
diff --git a/io_u.c b/io_u.c
index be2f242a6e2bce92c7225aff1cf462762c1d3998..2adaf258d3912bc33599ca550079f9769c3f70e8 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -1528,8 +1528,6 @@ err_put:
 void io_u_log_error(struct thread_data *td, struct io_u *io_u)
 {
        enum error_type_bit eb = td_error_type(io_u->ddir, io_u->error);
-       const char *msg[] = { "read", "write", "sync", "datasync",
-                               "sync_file_range", "wait", "trim" };
 
        if (td_non_fatal_error(td, eb, io_u->error) && !td->o.error_dump)
                return;
@@ -1541,7 +1539,7 @@ void io_u_log_error(struct thread_data *td, struct io_u *io_u)
 
        log_err(": %s\n", strerror(io_u->error));
 
-       log_err("     %s offset=%llu, buflen=%lu\n", msg[io_u->ddir],
+       log_err("     %s offset=%llu, buflen=%lu\n", io_ddir_name(io_u->ddir),
                                        io_u->offset, io_u->xfer_buflen);
 
        if (!td->error)
diff --git a/iolog.c b/iolog.c
index f9e835d4b087aa17755d41f76a59d6cf0bb95c7e..ef8b84145db0e14f808bdb53539184011b44975b 100644 (file)
--- a/iolog.c
+++ b/iolog.c
@@ -30,17 +30,12 @@ void queue_io_piece(struct thread_data *td, struct io_piece *ipo)
 
 void log_io_u(struct thread_data *td, struct io_u *io_u)
 {
-       const char *act[] = { "read", "write", "sync", "datasync",
-                               "sync_file_range", "wait", "trim" };
-
-       assert(io_u->ddir <= 6);
-
        if (!td->o.write_iolog_file)
                return;
 
        fprintf(td->iolog_f, "%s %s %llu %lu\n", io_u->file->file_name,
-                                               act[io_u->ddir], io_u->offset,
-                                               io_u->buflen);
+                                               io_ddir_name(io_u->ddir),
+                                               io_u->offset, io_u->buflen);
 }
 
 void log_file(struct thread_data *td, struct fio_file *f,