Add new net command for text logging

Encapsulate the text in a payload, that also includes the
logging level and the time the event took place. The text
client will do as it always has done, but the gui client
can now do proper logging and knows if this is debug/info
or error messages.

No functional change in the GUI.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/client.c b/client.c
index feb1eba..ff3983b 100644
--- a/client.c
+++ b/client.c
@@ -21,29 +21,15 @@
 #include "flist.h"
 #include "hash.h"
 
-static void fio_client_text_op(struct fio_client *client,
-		FILE *f, __u16 pdu_len, const char *buf)
-{
-	const char *name;
-	int fio_unused ret;
-
-	name = client->name ? client->name : client->hostname;
-
-	if (!client->skip_newline)
-		fprintf(f, "<%s> ", name);
-	ret = fwrite(buf, pdu_len, 1, f);
-	fflush(f);
-	client->skip_newline = strchr(buf, '\n') == NULL;
-}
-
 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd);
 static void handle_ts(struct fio_net_cmd *cmd);
 static void handle_gs(struct fio_net_cmd *cmd);
 static void handle_eta(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);
 
 struct client_ops fio_client_ops = {
-	.text_op	= fio_client_text_op,
+	.text_op	= handle_text,
 	.disk_util	= handle_du,
 	.thread_status	= handle_ts,
 	.group_stats	= handle_gs,
@@ -698,6 +684,23 @@
 	dus->msec		= le64_to_cpu(dus->msec);
 }
 
+static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+	struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
+	const char *buf = (const char *) pdu->buf;
+	const char *name;
+	int fio_unused ret;
+
+	name = client->name ? client->name : client->hostname;
+
+	if (!client->skip_newline)
+		fprintf(f_out, "<%s> ", name);
+	ret = fwrite(buf, pdu->buf_len, 1, f_out);
+	fflush(f_out);
+	client->skip_newline = strchr(buf, '\n') == NULL;
+}
+
+
 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
 {
 	struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
@@ -851,6 +854,16 @@
 		log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
 }
 
+static void convert_text(struct fio_net_cmd *cmd)
+{
+	struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
+
+	pdu->level	= le32_to_cpu(pdu->level);
+	pdu->buf_len	= le32_to_cpu(pdu->buf_len);
+	pdu->log_sec	= le64_to_cpu(pdu->log_sec);
+	pdu->log_usec	= le64_to_cpu(pdu->log_usec);
+}
+
 int fio_handle_client(struct fio_client *client, struct client_ops *ops)
 {
 	struct fio_net_cmd *cmd;
@@ -871,12 +884,11 @@
 		remove_client(client);
 		free(cmd);
 		break;
-	case FIO_NET_CMD_TEXT: {
-		const char *buf = (const char *) cmd->payload;
-		ops->text_op(client, f_out, cmd->pdu_len, buf);
+	case FIO_NET_CMD_TEXT:
+		convert_text(cmd);
+		ops->text_op(client, cmd);
 		free(cmd);
 		break;
-		}
 	case FIO_NET_CMD_DU:
 		ops->disk_util(client, cmd);
 		free(cmd);