gfio: add gerror.c for reporting errors
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/Makefile b/Makefile
index 4b87ca6..2b20a29 100644
--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,7 @@
OBJS = $(SOURCE:.c=.o)
FIO_OBJS = $(OBJS) fio.o
-GFIO_OBJS = $(OBJS) gfio.o graph.o tickmarks.o ghelpers.o goptions.o
+GFIO_OBJS = $(OBJS) gfio.o graph.o tickmarks.o ghelpers.o goptions.o gerror.o
T_SMALLOC_OBJS = t/stest.o
T_SMALLOC_OBJS += mutex.o smalloc.o t/log.o
@@ -110,6 +110,9 @@
ghelpers.o: ghelpers.c ghelpers.h
$(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c ghelpers.c
+gerror.o: gerror.c gerror.h
+ $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c gerror.c
+
gfio.o: gfio.c ghelpers.c
$(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c gfio.c
diff --git a/gerror.c b/gerror.c
new file mode 100644
index 0000000..82e0dd2
--- /dev/null
+++ b/gerror.c
@@ -0,0 +1,60 @@
+#include <locale.h>
+#include <malloc.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include <gtk/gtk.h>
+
+#include "gfio.h"
+#include "gerror.h"
+
+static void on_info_bar_response(GtkWidget *widget, gint response,
+ gpointer data)
+{
+ struct gui *ui = (struct gui *) data;
+
+ if (response == GTK_RESPONSE_OK) {
+ gtk_widget_destroy(widget);
+ ui->error_info_bar = NULL;
+ }
+}
+
+static void report_error(struct gui_entry *ge, GError *error)
+{
+ struct gui *ui = ge->ui;
+
+ if (ui->error_info_bar == NULL) {
+ ui->error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
+ GTK_RESPONSE_OK,
+ NULL);
+ g_signal_connect(ui->error_info_bar, "response", G_CALLBACK(on_info_bar_response), ui);
+ gtk_info_bar_set_message_type(GTK_INFO_BAR(ui->error_info_bar),
+ GTK_MESSAGE_ERROR);
+
+ ui->error_label = gtk_label_new(error->message);
+ GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui->error_info_bar));
+ gtk_container_add(GTK_CONTAINER(container), ui->error_label);
+
+ gtk_box_pack_start(GTK_BOX(ui->vbox), ui->error_info_bar, FALSE, FALSE, 0);
+ gtk_widget_show_all(ui->vbox);
+ } else {
+ char buffer[256];
+ snprintf(buffer, sizeof(buffer), "Failed to open file.");
+ gtk_label_set(GTK_LABEL(ui->error_label), buffer);
+ }
+}
+
+void gfio_report_error(struct gui_entry *ge, const char *format, ...)
+{
+ va_list args;
+ GError *error;
+
+ va_start(args, format);
+ error = g_error_new_valist(g_quark_from_string("fio"), 1, format, args);
+ va_end(args);
+
+ report_error(ge, error);
+ g_error_free(error);
+}
+
+
diff --git a/gerror.h b/gerror.h
new file mode 100644
index 0000000..69b1219
--- /dev/null
+++ b/gerror.h
@@ -0,0 +1,6 @@
+#ifndef GFIO_ERROR_H
+#define GFIO_ERROR_H
+
+extern void gfio_report_error(struct gui_entry *ge, const char *format, ...);
+
+#endif
diff --git a/gfio.c b/gfio.c
index 9385159..4bee83b 100644
--- a/gfio.c
+++ b/gfio.c
@@ -33,6 +33,7 @@
#include "gfio.h"
#include "ghelpers.h"
#include "goptions.h"
+#include "gerror.h"
#include "graph.h"
static int gfio_server_running;
@@ -76,7 +77,6 @@
static void gfio_update_thread_status(struct gui_entry *ge, char *status_message, double perc);
static void gfio_update_thread_status_all(struct gui *ui, char *status_message, double perc);
-static void report_error(struct gui_entry *ge, GError *error);
static struct graph *setup_iops_graph(void)
{
@@ -1798,16 +1798,13 @@
static int send_job_file(struct gui_entry *ge)
{
struct gfio_client *gc = ge->client;
- GError *error;
int ret = 0;
ret = fio_client_send_ini(gc->client, ge->job_file);
if (!ret)
return 0;
- error = g_error_new(g_quark_from_string("fio"), 1, "Failed to send file %s: %s\n", ge->job_file, strerror(-ret));
- report_error(ge, error);
- g_error_free(error);
+ gfio_report_error(ge, "Failed to send file %s: %s\n", ge->job_file, strerror(-ret));
return 1;
}
@@ -1999,19 +1996,6 @@
gfio_set_client(gc, client);
}
-static void gfio_report_error(struct gui_entry *ge, const char *format, ...)
-{
- va_list args;
- GError *error;
-
- va_start(args, format);
- error = g_error_new_valist(g_quark_from_string("fio"), 1, format, args);
- va_end(args);
-
- report_error(ge, error);
- g_error_free(error);
-}
-
static void connect_clicked(GtkWidget *widget, gpointer data)
{
struct gui_entry *ge = data;
@@ -2053,11 +2037,7 @@
pthread_create(&ge->ui->t, NULL, job_thread, ge->ui);
gfio_set_state(ge, GE_STATE_CONNECTED);
} else {
- GError *error;
-
- error = g_error_new(g_quark_from_string("fio"), 1, "Failed to connect to %s: %s\n", ge->client->client->hostname, strerror(-ret));
- report_error(ge, error);
- g_error_free(error);
+ gfio_report_error(ge, "Failed to connect to %s: %s\n", ge->client->client->hostname, strerror(-ret));
}
} else {
fio_client_terminate(gc->client);
@@ -2074,42 +2054,6 @@
gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_START], 1);
}
-static void on_info_bar_response(GtkWidget *widget, gint response,
- gpointer data)
-{
- struct gui *ui = (struct gui *) data;
-
- if (response == GTK_RESPONSE_OK) {
- gtk_widget_destroy(widget);
- ui->error_info_bar = NULL;
- }
-}
-
-static void report_error(struct gui_entry *ge, GError *error)
-{
- struct gui *ui = ge->ui;
-
- if (ui->error_info_bar == NULL) {
- ui->error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
- GTK_RESPONSE_OK,
- NULL);
- g_signal_connect(ui->error_info_bar, "response", G_CALLBACK(on_info_bar_response), ui);
- gtk_info_bar_set_message_type(GTK_INFO_BAR(ui->error_info_bar),
- GTK_MESSAGE_ERROR);
-
- ui->error_label = gtk_label_new(error->message);
- GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui->error_info_bar));
- gtk_container_add(GTK_CONTAINER(container), ui->error_label);
-
- gtk_box_pack_start(GTK_BOX(ui->vbox), ui->error_info_bar, FALSE, FALSE, 0);
- gtk_widget_show_all(ui->vbox);
- } else {
- char buffer[256];
- snprintf(buffer, sizeof(buffer), "Failed to open file.");
- gtk_label_set(GTK_LABEL(ui->error_label), buffer);
- }
-}
-
static GtkWidget *new_client_page(struct gui_entry *ge);
static struct gui_entry *alloc_new_gui_entry(struct gui *ui)
@@ -2240,7 +2184,6 @@
static int do_file_open(struct gui_entry *ge, const gchar *uri)
{
struct fio_client *client;
- GError *error;
assert(!ge->job_file);
@@ -2253,11 +2196,9 @@
return 0;
}
- error = g_error_new(g_quark_from_string("fio"), 1, "Failed to add client %s", ge->host);
+ gfio_report_error(ge, "Failed to add client %s\n", ge->host);
free(ge->host);
ge->host = NULL;
- report_error(ge, error);
- g_error_free(error);
return 1;
}
diff --git a/gfio.h b/gfio.h
index dc810a6..6760675 100644
--- a/gfio.h
+++ b/gfio.h
@@ -3,6 +3,9 @@
#include <gtk/gtk.h>
+#include "flist.h"
+#include "stat.h"
+#include "thread_options.h"
#include "ghelpers.h"
struct probe_widget {
diff --git a/ioengine.h b/ioengine.h
index 9392bbd..b4bc22b 100644
--- a/ioengine.h
+++ b/ioengine.h
@@ -1,7 +1,10 @@
#ifndef FIO_IOENGINE_H
#define FIO_IOENGINE_H
+#include "compiler/compiler.h"
+#include "io_ddir.h"
#include "debug.h"
+#include "file.h"
#define FIO_IOOPS_VERSION 13
@@ -16,6 +19,8 @@
IO_U_F_VER_LIST = 1 << 7,
};
+struct thread_data;
+
/*
* The io unit
*/