Define SIGUSR1 to inform fio to dump run stats while continuing to run
[fio.git] / client.c
index 8c85d2b5c6a673f433f2930fbb41c6a70e8b354b..ee6765ed7adf9671c5cc131909e80ebe2e5abdff 100644 (file)
--- a/client.c
+++ b/client.c
@@ -37,6 +37,7 @@ struct fio_client {
        char *hostname;
        int port;
        int fd;
+       unsigned int refs;
 
        char *name;
 
@@ -119,8 +120,10 @@ static struct fio_client *find_client_by_fd(int fd)
        flist_for_each(entry, &client_hash[bucket]) {
                client = flist_entry(entry, struct fio_client, hash_list);
 
-               if (client->fd == fd)
+               if (client->fd == fd) {
+                       client->refs++;
                        return client;
+               }
        }
 
        return NULL;
@@ -128,6 +131,11 @@ static struct fio_client *find_client_by_fd(int fd)
 
 static void remove_client(struct fio_client *client)
 {
+       assert(client->refs);
+
+       if (--client->refs)
+               return;
+
        dprint(FD_NET, "client: removed <%s>\n", client->hostname);
        flist_del(&client->list);
 
@@ -149,6 +157,11 @@ static void remove_client(struct fio_client *client)
        sum_stat_clients--;
 }
 
+static void put_client(struct fio_client *client)
+{
+       remove_client(client);
+}
+
 static void __fio_client_add_cmd_option(struct fio_client *client,
                                        const char *opt)
 {
@@ -215,6 +228,7 @@ int fio_client_add(const char *hostname, void **cookie)
                return -1;
 
        client->fd = -1;
+       client->refs = 1;
 
        __fio_client_add_cmd_option(client, "fio");
 
@@ -330,6 +344,11 @@ static void sig_int(int sig)
        fio_clients_terminate();
 }
 
+static void sig_show_status(int sig)
+{
+       show_running_run_stats();
+}
+
 static void client_signal_handler(void)
 {
        struct sigaction act;
@@ -343,6 +362,11 @@ static void client_signal_handler(void)
        act.sa_handler = sig_int;
        act.sa_flags = SA_RESTART;
        sigaction(SIGTERM, &act, NULL);
+
+       memset(&act, 0, sizeof(act));
+       act.sa_handler = sig_show_status;
+       act.sa_flags = SA_RESTART;
+       sigaction(SIGUSR1, &act, NULL);
 }
 
 static void probe_client(struct fio_client *client)
@@ -1055,6 +1079,7 @@ int fio_handle_clients(void)
                                retval = 1;
                        } else if (client->error)
                                retval = 1;
+                       put_client(client);
                }
        }