gfio: start of per-job option edit

Currently we don't properly handle job files with multiple
job entries in them, each one just overwrites the last.
Start tracking all of them.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/gclient.c b/gclient.c
index c4be172..31dbb68 100644
--- a/gclient.c
+++ b/gclient.c
@@ -550,18 +550,29 @@
 	gdk_threads_leave();
 }
 
+static struct thread_options *gfio_client_add_job(struct gfio_client *gc,
+			struct thread_options_pack *top)
+{
+	struct gfio_client_options *gco;
+
+	gco = calloc(1, sizeof(*gco));
+	convert_thread_options_to_cpu(&gco->o, top);
+	flist_add_tail(&gco->list, &gc->o_list);
+	return &gco->o;
+}
+
 static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd)
 {
 	struct cmd_add_job_pdu *p = (struct cmd_add_job_pdu *) cmd->payload;
 	struct gfio_client *gc = client->client_data;
-	struct thread_options *o = &gc->o;
 	struct gui_entry *ge = gc->ge;
+	struct thread_options *o;
 	char *c1, *c2, *c3, *c4;
 	char tmp[80];
 
 	p->thread_number = le32_to_cpu(p->thread_number);
 	p->groupid = le32_to_cpu(p->groupid);
-	convert_thread_options_to_cpu(o, &p->top);
+	o = gfio_client_add_job(gc, &p->top);
 
 	gdk_threads_enter();
 
diff --git a/gfio.c b/gfio.c
index 6f313ed..d200ade 100644
--- a/gfio.c
+++ b/gfio.c
@@ -616,14 +616,22 @@
 
 static void gfio_client_added(struct gui_entry *ge, struct fio_client *client)
 {
+	struct gfio_client_options *gco;
 	struct gfio_client *gc;
 
-	gc = malloc(sizeof(*gc));
-	memset(gc, 0, sizeof(*gc));
-	options_default_fill(&gc->o);
+	gc = calloc(1, sizeof(*gc));
+	INIT_FLIST_HEAD(&gc->o_list);
 	gc->ge = ge;
 	ge->client = gc;
 	gfio_set_client(gc, client);
+
+	/*
+	 * Just add a default set of options, need to consider how best
+	 * to handle this
+	 */
+	gco = calloc(1, sizeof(*gco));
+	options_default_fill(&gco->o);
+	flist_add_tail(&gco->list, &gc->o_list);
 }
 
 static void connect_clicked(GtkWidget *widget, gpointer data)
@@ -1016,7 +1024,7 @@
 
 	ge = get_ge_from_cur_tab(ui);
 	if (ge && ge->client)
-		gopt_get_options_window(ui->window, &ge->client->o);
+		gopt_get_options_window(ui->window, ge->client);
 }
 
 static void start_job_entry(GtkWidget *w, gpointer data)
diff --git a/gfio.h b/gfio.h
index b8de680..854f7ad 100644
--- a/gfio.h
+++ b/gfio.h
@@ -136,11 +136,16 @@
 	struct thread_stat ts;
 };
 
+struct gfio_client_options {
+	struct flist_head list;
+	struct thread_options o;
+};
+
 struct gfio_client {
 	struct gui_entry *ge;
 	struct fio_client *client;
 	GtkWidget *err_entry;
-	struct thread_options o;
+	struct flist_head o_list;
 
 	struct end_results *results;
 	unsigned int nr_results;
diff --git a/goptions.c b/goptions.c
index 49da001..202b0d2 100644
--- a/goptions.c
+++ b/goptions.c
@@ -856,10 +856,21 @@
 	} while (1);
 }
 
-void gopt_get_options_window(GtkWidget *window, struct thread_options *o)
+void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc)
 {
 	GtkWidget *dialog, *notebook;
 	GtkWidget *vboxes[__FIO_OPT_C_NR];
+	struct gfio_client_options *gco;
+	struct thread_options *o;
+
+	/*
+	 * Just choose the first item, we need to make each options
+	 * entry the main notebook, with the below options view as
+	 * a sub-notebook
+	 */
+	assert(!flist_empty(&gc->o_list));
+	gco = flist_entry(gc->o_list.next, struct gfio_client_options, list);
+	o = &gco->o;
 
 	dialog = gtk_dialog_new_with_buttons("Fio options",
 			GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT,
diff --git a/goptions.h b/goptions.h
index 4b40942..e70a86d 100644
--- a/goptions.h
+++ b/goptions.h
@@ -1,6 +1,6 @@
 #ifndef GFIO_OPTIONS_H
 #define GFIO_OPTIONS_H
 
-void gopt_get_options_window(GtkWidget *window, struct thread_options *o);
+void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc);
 
 #endif