gfio: improve stop handling
authorJens Axboe <axboe@kernel.dk>
Thu, 8 Mar 2012 09:51:36 +0000 (10:51 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 8 Mar 2012 09:51:36 +0000 (10:51 +0100)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
client.c
client.h
gfio.c

index 7267333d3128017e09d67ef7af8fa23db6a26951..40e5be2ec7fbd834e9338d1aec46ebbdc9ed8f5e 100644 (file)
--- a/client.c
+++ b/client.c
@@ -26,12 +26,14 @@ static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd);
 static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd);
 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd);
 static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd);
+static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd);
 
 struct client_ops fio_client_ops = {
        .text_op        = handle_text,
        .disk_util      = handle_du,
        .thread_status  = handle_ts,
        .group_stats    = handle_gs,
+       .stop           = handle_stop,
        .eta            = display_thread_status,
        .probe          = handle_probe,
 };
@@ -853,15 +855,17 @@ static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
 
 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
 {
-       struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
-
-       client->state = Client_stopped;
-       client->error = le32_to_cpu(pdu->error);
-
        if (client->error)
                log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
 }
 
+static void convert_stop(struct fio_net_cmd *cmd)
+{
+       struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
+
+       pdu->error = le32_to_cpu(pdu->error);
+}
+
 static void convert_text(struct fio_net_cmd *cmd)
 {
        struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
@@ -949,10 +953,16 @@ int fio_handle_client(struct fio_client *client)
                handle_start(client, cmd);
                free(cmd);
                break;
-       case FIO_NET_CMD_STOP:
-               handle_stop(client, cmd);
+       case FIO_NET_CMD_STOP: {
+               struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
+
+               convert_stop(cmd);
+               client->state = Client_stopped;
+               client->error = pdu->error;
+               ops->stop(client, cmd);
                free(cmd);
                break;
+               }
        case FIO_NET_CMD_ADD_JOB:
                if (ops->add_job)
                        ops->add_job(client, cmd);
index 213987ca4511df538ca383082ed6e0b33eea34eb..eccac9228849b81161700ce193dbe84e31ceb1ae 100644 (file)
--- a/client.h
+++ b/client.h
@@ -59,6 +59,7 @@ typedef void (*client_thread_status_display_op)(char *status_message, double per
 typedef void (*client_quit_op)(struct fio_client *);
 typedef void (*client_add_job_op)(struct fio_client *, struct fio_net_cmd *);
 typedef void (*client_timed_out)(struct fio_client *);
+typedef void (*client_stop_op)(struct fio_client *, struct fio_net_cmd *);
 
 struct client_ops {
        client_text_op_func text_op;
@@ -70,6 +71,7 @@ struct client_ops {
        client_quit_op quit;
        client_add_job_op add_job;
        client_timed_out timed_out;
+       client_stop_op stop;
        int stay_connected;
 };
 
diff --git a/gfio.c b/gfio.c
index 21f5fd9cb6d6fe8035d939cc0ead3b30d618489b..2c9a125d48294a60c43f933f29b95bfc4a9b426e 100644 (file)
--- a/gfio.c
+++ b/gfio.c
@@ -23,6 +23,7 @@
  */
 #include <locale.h>
 #include <malloc.h>
+#include <string.h>
 
 #include <glib.h>
 #include <cairo.h>
@@ -35,6 +36,7 @@ static int gfio_server_running;
 static const char *gfio_graph_font;
 
 static void gfio_update_thread_status(char *status_message, double perc);
+static void view_log(GtkWidget *w, gpointer data);
 
 #define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
 
@@ -121,6 +123,7 @@ struct gfio_client {
        struct gui *ui;
        GtkWidget *results_widget;
        GtkWidget *disk_util_frame;
+       GtkWidget *err_entry;
 };
 
 static void setup_iops_graph(struct gui *ui)
@@ -859,7 +862,7 @@ static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts,
        entry_set_int_value(entry, ts->groupid);
        entry = new_info_entry_in_frame(box, "Jobs");
        entry_set_int_value(entry, ts->members);
-       entry = new_info_entry_in_frame(box, "Error");
+       gc->err_entry = entry = new_info_entry_in_frame(box, "Error");
        entry_set_int_value(entry, ts->error);
        entry = new_info_entry_in_frame(box, "PID");
        entry_set_int_value(entry, ts->pid);
@@ -899,6 +902,9 @@ static void gfio_text_op(struct fio_client *client, struct fio_net_cmd *cmd)
        gtk_list_store_set(gc->ui->log_model, &iter, 2, p->level, -1);
        gtk_list_store_set(gc->ui->log_model, &iter, 3, p->buf, -1);
 
+       if (p->level == FIO_LOG_ERR)
+               view_log(NULL, (gpointer) gc->ui);
+
        gdk_threads_leave();
 }
 
@@ -1257,6 +1263,20 @@ static void gfio_client_timed_out(struct fio_client *client)
        gdk_threads_leave();
 }
 
+static void gfio_client_stop(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct gfio_client *gc = client->client_data;
+
+       gdk_threads_enter();
+
+       gfio_set_connected(gc->ui, 0);
+
+       if (gc->err_entry)
+               entry_set_int_value(gc->err_entry, client->error);
+
+       gdk_threads_leave();
+}
+
 struct client_ops gfio_client_ops = {
        .text_op                = gfio_text_op,
        .disk_util              = gfio_disk_util_op,
@@ -1267,6 +1287,7 @@ struct client_ops gfio_client_ops = {
        .quit                   = gfio_quit_op,
        .add_job                = gfio_add_job_op,
        .timed_out              = gfio_client_timed_out,
+       .stop                   = gfio_client_stop,
        .stay_connected         = 1,
 };