init: add semantics for all types of backends running
authorLuis Chamberlain <mcgrof@kernel.org>
Tue, 21 Aug 2018 18:15:39 +0000 (12:15 -0600)
committerLuis Chamberlain <mcgrof@kernel.org>
Thu, 23 Aug 2018 17:02:35 +0000 (11:02 -0600)
Commit 67a176fc7 ("Fix segfault with client/server and minimal output")
addressed a segfault but it wasn't very clear *why* the fix was needed.
The reason it was needed is that the disk util and its respective
semaphore are only initialized when setup_disk_util() is called, this
happens upon fio_backend() calls. That is, either we have a dedicated
backend or have initiated a backend for the localhost due to some local
work. And show_thread_status() is currently called from a complete
client setup -- handle_ts() calls show_thread_status(), and a client
does not collect any local disk data, it receives this from the backend.
As such, the semaphore won't be setup in a client setup and this is why
we segfault here.

We can enable show_thread_status() then only if any type of backend is
running, however there is are no semantics currently which enable us to
query for this. Add such semantics and replace the previous check with
a check for if fio_backend() was ever called. This will make it clearer.

Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
backend.c
diskutil.c
fio.h
init.c
stat.c

index 36bde6a587535635ee9d1dcef6c0bc0c5160f772..8fec1ce3141f4f5b3f910784c75f5f6a200c88d9 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -2481,6 +2481,8 @@ int fio_backend(struct sk_out *sk_out)
        }
 
        startup_sem = fio_sem_init(FIO_SEM_LOCKED);
+       if (!sk_out)
+               is_local_backend = true;
        if (startup_sem == NULL)
                return 1;
 
index 5b4eb46dfe46990d091f135bed3c1f9ba10eb67e..7be4c022431e1a0b823332f233d0159f07876ba4 100644 (file)
@@ -701,7 +701,7 @@ void show_disk_util(int terse, struct json_object *parent,
        struct disk_util *du;
        bool do_json;
 
-       if (!disk_util_sem)
+       if (!is_running_backend())
                return;
 
        fio_sem_down(disk_util_sem);
diff --git a/fio.h b/fio.h
index b58057f72009f9df12fa01879ef4f7df6732a1ef..83654bbbf0411d4c944b85a8e01a915d65605661 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -522,6 +522,7 @@ extern int fio_clock_source_set;
 extern int warnings_fatal;
 extern int terse_version;
 extern int is_backend;
+extern int is_local_backend;
 extern int nr_clients;
 extern int log_syslog;
 extern int status_interval;
@@ -534,6 +535,11 @@ extern char *aux_path;
 
 extern struct thread_data *threads;
 
+static inline bool is_running_backend(void)
+{
+       return is_backend || is_local_backend;
+}
+
 extern bool eta_time_within_slack(unsigned int time);
 
 static inline void fio_ro_check(const struct thread_data *td, struct io_u *io_u)
diff --git a/init.c b/init.c
index 06f69719328f575c12c0a2886ef64e9b256d4236..3ed57570c7e09e72f138d87536fc93c03f28b5fa 100644 (file)
--- a/init.c
+++ b/init.c
@@ -63,6 +63,7 @@ char *exec_profile = NULL;
 int warnings_fatal = 0;
 int terse_version = 3;
 int is_backend = 0;
+int is_local_backend = 0;
 int nr_clients = 0;
 int log_syslog = 0;
 
diff --git a/stat.c b/stat.c
index edf9ecf6a0760804247fbdc3c8f90499fb009e06..6cb704eb11bba6e186f0947f2b7d625b5358d341 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1205,7 +1205,7 @@ static void show_thread_status_terse_all(struct thread_stat *ts,
                log_buf(out, ";%3.2f%%", io_u_lat_m[i]);
 
        /* disk util stats, if any */
-       if (ver >= 3)
+       if (ver >= 3 && is_running_backend())
                show_disk_util(1, NULL, out);
 
        /* Additional output if continue_on_error set - default off*/