Add more job info

Adds a specific command to be sent when a job is received by
the backend. Helps fill out the GUI fields for job values.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/client.c b/client.c
index d801236..a84b92c 100644
--- a/client.c
+++ b/client.c
@@ -911,6 +911,11 @@
 		handle_stop(client, cmd);
 		free(cmd);
 		break;
+	case FIO_NET_CMD_ADD_JOB:
+		if (ops->add_job)
+			ops->add_job(client, cmd);
+		free(cmd);
+		break;
 	default:
 		log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode));
 		free(cmd);
diff --git a/client.h b/client.h
index 0071484..ea29789 100644
--- a/client.h
+++ b/client.h
@@ -48,20 +48,14 @@
 
 typedef void (*client_text_op_func)(struct fio_client *client,
 		FILE *f, __u16 pdu_len, const char *buf);
-
 typedef void (*client_disk_util_op_func)(struct fio_client *client, struct fio_net_cmd *cmd);
-
 typedef void (*client_thread_status_op)(struct fio_net_cmd *cmd);
-
 typedef void (*client_group_stats_op)(struct fio_net_cmd *cmd);
-
 typedef void (*client_eta_op)(struct fio_client *client, struct fio_net_cmd *cmd);
-
 typedef void (*client_probe_op)(struct fio_client *client, struct fio_net_cmd *cmd);
-
 typedef void (*client_thread_status_display_op)(char *status_message, double perc);
-
 typedef void (*client_quit_op)(struct fio_client *);
+typedef void (*client_add_job_op)(struct fio_client *, struct fio_net_cmd *);
 
 struct client_ops {
 	client_text_op_func text_op;
@@ -71,6 +65,7 @@
 	client_eta_op eta;
 	client_probe_op probe;
 	client_quit_op quit;
+	client_add_job_op add_job;
 	int stay_connected;
 };
 
@@ -98,6 +93,5 @@
 extern int fio_client_add(const char *, void **);
 extern struct fio_client *fio_client_add_explicit(const char *, int, int);
 extern void fio_client_add_cmd_option(void *, const char *);
-
 #endif
 
diff --git a/gfio.c b/gfio.c
index 848e511..20831c8 100644
--- a/gfio.c
+++ b/gfio.c
@@ -59,6 +59,10 @@
 };
 
 struct eta_widget {
+	GtkWidget *name;
+	GtkWidget *iotype;
+	GtkWidget *ioengine;
+	GtkWidget *iodepth;
 	GtkWidget *jobs;
 	GtkWidget *files;
 	GtkWidget *read_bw;
@@ -117,6 +121,7 @@
 static void gfio_text_op(struct fio_client *client,
                 FILE *f, __u16 pdu_len, const char *buf)
 {
+#if 0
 	GtkTextBuffer *buffer;
 	GtkTextIter end;
 
@@ -127,6 +132,9 @@
 	gdk_threads_leave();
 	gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(ui.textview),
 					&end, 0.0, FALSE, 0.0,0.0);
+#else
+	fio_client_ops.text_op(client, f, pdu_len, buf);
+#endif
 }
 
 static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd)
@@ -286,6 +294,32 @@
 	gfio_set_connected(ui, 0);
 }
 
+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 gui *ui = client->client_data;
+	char tmp[8];
+	int i;
+
+	p->iodepth		= le32_to_cpu(p->iodepth);
+	p->rw			= le32_to_cpu(p->rw);
+
+	for (i = 0; i < 2; i++) {
+		p->min_bs[i] 	= le32_to_cpu(p->min_bs[i]);
+		p->max_bs[i]	= le32_to_cpu(p->max_bs[i]);
+	}
+
+	p->numjobs		= le32_to_cpu(p->numjobs);
+	p->group_reporting	= le32_to_cpu(p->group_reporting);
+
+	gtk_label_set_text(GTK_LABEL(ui->eta.name), (gchar *) p->jobname);
+	gtk_label_set_text(GTK_LABEL(ui->eta.iotype), ddir_str(p->rw));
+	gtk_label_set_text(GTK_LABEL(ui->eta.ioengine), (gchar *) p->ioengine);
+
+	sprintf(tmp, "%u", p->iodepth);
+	gtk_label_set_text(GTK_LABEL(ui->eta.iodepth), tmp);
+}
+
 struct client_ops gfio_client_ops = {
 	.text_op		= gfio_text_op,
 	.disk_util		= gfio_disk_util_op,
@@ -294,6 +328,7 @@
 	.eta			= gfio_eta_op,
 	.probe			= gfio_probe_op,
 	.quit			= gfio_quit_op,
+	.add_job		= gfio_add_job_op,
 	.stay_connected		= 1,
 };
 
@@ -694,6 +729,11 @@
 
 	probe_box = gtk_hbox_new(FALSE, 3);
 	gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
+
+	ui->eta.name = new_info_label_in_frame(probe_box, "Name");
+	ui->eta.iotype = new_info_label_in_frame(probe_box, "IO");
+	ui->eta.ioengine = new_info_label_in_frame(probe_box, "IO Engine");
+	ui->eta.iodepth = new_info_label_in_frame(probe_box, "IO Depth");
 	ui->eta.jobs = new_info_label_in_frame(probe_box, "Jobs");
 	ui->eta.files = new_info_label_in_frame(probe_box, "Open files");
 
@@ -701,15 +741,22 @@
 	gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
 	ui->eta.read_bw = new_info_label_in_frame(probe_box, "Read BW");
 	ui->eta.read_iops = new_info_label_in_frame(probe_box, "IOPS");
+	ui->eta.write_bw = new_info_label_in_frame(probe_box, "Write BW");
+	ui->eta.write_iops = new_info_label_in_frame(probe_box, "IOPS");
+
+	/*
+	 * Only add this if we have a commit rate
+	 */
+#if 0
+	probe_box = gtk_hbox_new(FALSE, 3);
+	gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
+
 	ui->eta.cr_bw = new_info_label_in_frame(probe_box, "Commit BW");
 	ui->eta.cr_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
 
-	probe_box = gtk_hbox_new(FALSE, 3);
-	gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
-	ui->eta.write_bw = new_info_label_in_frame(probe_box, "Write BW");
-	ui->eta.write_iops = new_info_label_in_frame(probe_box, "IOPS");
 	ui->eta.cw_bw = new_info_label_in_frame(probe_box, "Commit BW");
 	ui->eta.cw_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
+#endif
 
 	/*
 	 * Add a text box for text op messages 
diff --git a/init.c b/init.c
index 2bdc71f..f1446ca 100644
--- a/init.c
+++ b/init.c
@@ -737,8 +737,6 @@
  */
 static int add_job(struct thread_data *td, const char *jobname, int job_add_num)
 {
-	const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
-				   "randread", "randwrite", "randrw" };
 	unsigned int i;
 	char fname[PATH_MAX];
 	int numjobs, file_alloced;
@@ -850,6 +848,9 @@
 
 	if (!terse_output) {
 		if (!job_add_num) {
+			if (is_backend)
+				fio_server_send_add_job(&td->o, td->io_ops->name);
+
 			if (!strcmp(td->io_ops->name, "cpuio")) {
 				log_info("%s: ioengine=cpu, cpuload=%u,"
 					 " cpucycle=%u\n", td->o.name,
@@ -866,7 +867,7 @@
 				log_info("%s: (g=%d): rw=%s, bs=%s-%s/%s-%s,"
 					 " ioengine=%s, iodepth=%u\n",
 						td->o.name, td->groupid,
-						ddir_str[td->o.td_ddir],
+						ddir_str(td->o.td_ddir),
 						c1, c2, c3, c4,
 						td->io_ops->name,
 						td->o.iodepth);
diff --git a/io_ddir.h b/io_ddir.h
index b234256..908101a 100644
--- a/io_ddir.h
+++ b/io_ddir.h
@@ -39,4 +39,12 @@
 	return ddir == DDIR_READ || ddir == DDIR_WRITE;
 }
 
+static inline const char *ddir_str(enum fio_ddir ddir)
+{
+	const char *ddir_str[] = { NULL, "read", "write", "rw", NULL,
+				   "randread", "randwrite", "randrw" };
+
+	return ddir_str[ddir];
+}
+
 #endif
diff --git a/server.c b/server.c
index a2db9dd..490c277 100644
--- a/server.c
+++ b/server.c
@@ -52,6 +52,7 @@
 	"STOP",
 	"DISK_UTIL",
 	"RUN",
+	"ADD_JOB",
 };
 
 const char *fio_server_op(unsigned int op)
@@ -801,6 +802,28 @@
 	}
 }
 
+void fio_server_send_add_job(struct thread_options *o, const char *ioengine)
+{
+	struct cmd_add_job_pdu pdu;
+	int i;
+
+	strcpy((char *) pdu.jobname, o->name);
+	strcpy((char *) pdu.ioengine, ioengine);
+
+	pdu.iodepth		= cpu_to_le32(o->iodepth);
+	pdu.rw			= cpu_to_le32(o->td_ddir);
+
+	for (i = 0; i < 2; i++) {
+		pdu.min_bs[i]	= cpu_to_le32(o->min_bs[i]);
+		pdu.max_bs[i]	= cpu_to_le32(o->max_bs[i]);
+	}
+
+	pdu.numjobs		= cpu_to_le32(o->numjobs);
+	pdu.group_reporting	= cpu_to_le32(o->group_reporting);
+
+	fio_net_send_cmd(server_fd, FIO_NET_CMD_ADD_JOB, &pdu, sizeof(pdu), 0);
+}
+
 int fio_server_log(const char *format, ...)
 {
 	char buffer[1024];
diff --git a/server.h b/server.h
index d17c0ce..5c7c8db 100644
--- a/server.h
+++ b/server.h
@@ -38,7 +38,7 @@
 };
 
 enum {
-	FIO_SERVER_VER		= 7,
+	FIO_SERVER_VER		= 8,
 
 	FIO_SERVER_MAX_PDU	= 1024,
 
@@ -56,7 +56,8 @@
 	FIO_NET_CMD_STOP	= 12,
 	FIO_NET_CMD_DU		= 13,
 	FIO_NET_CMD_RUN		= 14,
-	FIO_NET_CMD_NR		= 15,
+	FIO_NET_CMD_ADD_JOB	= 15,
+	FIO_NET_CMD_NR		= 16,
 
 	FIO_NET_CMD_F_MORE	= 1UL << 0,
 
@@ -106,6 +107,17 @@
 	uint32_t error;
 };
 
+struct cmd_add_job_pdu {
+	uint8_t jobname[32];
+	uint8_t ioengine[32];
+	uint32_t iodepth;
+	uint32_t rw;
+	uint32_t min_bs[2];
+	uint32_t max_bs[2];
+	uint32_t numjobs;
+	uint32_t group_reporting;
+};
+
 extern int fio_start_server(char *);
 extern int fio_server_text_output(const char *, size_t);
 extern int fio_server_log(const char *format, ...);
@@ -129,6 +141,9 @@
 extern void fio_net_cmd_crc(struct fio_net_cmd *);
 extern struct fio_net_cmd *fio_net_recv_cmd(int sk);
 
+struct thread_options;
+extern void fio_server_send_add_job(struct thread_options *, const char *);
+
 extern int exit_backend;
 extern int fio_net_port;