Remove/Move Linux specific sysfs_root field from thread_data
authorTomohiro Kusumi <tkusumi@tuxera.com>
Mon, 23 Jan 2017 15:13:11 +0000 (00:13 +0900)
committerJens Axboe <axboe@fb.com>
Mon, 23 Jan 2017 15:26:12 +0000 (08:26 -0700)
struct thread_data is better without having a Linux specific field
(even if sysfs_root is simply unused on non Linux environment) given
that other Linux specific code such as diskutil/cgroup/blktrace/etc
are compiled only on Linux.

This commit uses td->files[0]->du->sysfs_root instead of td->sysfs_root,
but results the same from the way diskutil is currently implemented.
Besides being platform independent, it's also better in terms of data
structure since sysfs_root isn't always per-td attribute as mentioned
below.

For example, when N(>1) files are specified via filename= option
(e.g. filename=/dev/sdb:/dev/sdc for N=2), td:files is 1:N, therefore
td:du and td:du->sysfs_root are also 1:N in case of /dev/sdb:/dev/sdc,
however td:td->sysfs_root is obviously 1:1 which in this case means
td->sysfs_root is sysfs root for /dev/sdb (regardless of other files)
from the way td->sysfs_root is set only if it hasn't yet been set.

In other words, if filename=/dev/sdb:/dev/sdc is given, ioscheduler=
option only works against /dev/sdb, which could be different from what
users would expect, but this commit just removes sysfs_root from
struct thread_data without any functional change.

Signed-off-by: Tomohiro Kusumi <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c
diskutil.c
filesetup.c
fio.h

index 27e36bb0ae23e9cb1cf32c5c2840429edf6ebd5d..1c1f2f9a1e603c084160165eb6596945de344d7a 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1261,6 +1261,10 @@ static int init_io_u(struct thread_data *td)
        return 0;
 }
 
+/*
+ * This function is Linux specific.
+ * FIO_HAVE_IOSCHED_SWITCH enabled currently means it's Linux.
+ */
 static int switch_ioscheduler(struct thread_data *td)
 {
 #ifdef FIO_HAVE_IOSCHED_SWITCH
@@ -1271,7 +1275,8 @@ static int switch_ioscheduler(struct thread_data *td)
        if (td_ioengine_flagged(td, FIO_DISKLESSIO))
                return 0;
 
-       sprintf(tmp, "%s/queue/scheduler", td->sysfs_root);
+       assert(td->files && td->files[0]);
+       sprintf(tmp, "%s/queue/scheduler", td->files[0]->du->sysfs_root);
 
        f = fopen(tmp, "r+");
        if (!f) {
index c34841a2af2c379b10b47b162ef79e99fd88a040..c3bcec928ac29a6a2b753b3ccf2eaeb583a29dab 100644 (file)
@@ -431,9 +431,6 @@ static struct disk_util *__init_per_file_disk_util(struct thread_data *td,
                sprintf(path, "%s", tmp);
        }
 
-       if (td->o.ioscheduler && !td->sysfs_root)
-               td->sysfs_root = strdup(path);
-
        return disk_util_add(td, majdev, mindev, path);
 }
 
@@ -452,12 +449,8 @@ static struct disk_util *init_per_file_disk_util(struct thread_data *td,
                        mindev);
 
        du = disk_util_exists(majdev, mindev);
-       if (du) {
-               if (td->o.ioscheduler && !td->sysfs_root)
-                       td->sysfs_root = strdup(du->sysfs_root);
-
+       if (du)
                return du;
-       }
 
        /*
         * for an fs without a device, we will repeatedly stat through
index 4aaa903576bbe04dccdfc69e0088c8cd79cf2e76..eb28826698811058a317fa6544b92bd8f388a368 100644 (file)
@@ -1208,7 +1208,6 @@ void close_and_free_files(struct thread_data *td)
        td->o.filename = NULL;
        free(td->files);
        free(td->file_locks);
-       free(td->sysfs_root);
        td->files_index = 0;
        td->files = NULL;
        td->file_locks = NULL;
diff --git a/fio.h b/fio.h
index 14950fc89e3ab2009ee9f52c27377b1f0ee2ade2..19ac0af1f9a6ff68adf6cbdc01d04bbbb9ab8526 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -205,8 +205,6 @@ struct thread_data {
        void *iolog_buf;
        FILE *iolog_f;
 
-       char *sysfs_root;
-
        unsigned long rand_seeds[FIO_RAND_NR_OFFS];
 
        struct frand_state bsrange_state;