client/server: various bug fixes
[fio.git] / client.c
index 932c665c1bbcc5fbfbce810d992323c48b44fd63..752b508c73802013f215b0c1fff5627021b6c288 100644 (file)
--- a/client.c
+++ b/client.c
@@ -32,6 +32,7 @@ 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);
 static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd);
+static void handle_iolog(struct fio_client *client, struct cmd_iolog_pdu *pdu);
 
 struct client_ops fio_client_ops = {
        .text           = handle_text,
@@ -42,6 +43,7 @@ struct client_ops fio_client_ops = {
        .start          = handle_start,
        .eta            = display_thread_status,
        .probe          = handle_probe,
+       .iolog          = handle_iolog,
        .eta_msec       = FIO_CLIENT_DEF_ETA_MSEC,
        .client_type    = FIO_CLIENT_TYPE_CLI,
 };
@@ -1003,7 +1005,8 @@ static void handle_job_opt(struct fio_client *client, struct fio_net_cmd *cmd)
                return;
 
        pdu->global = le16_to_cpu(pdu->global);
-       pdu->groupid = le16_to_cpu(pdu->groupid);
+       pdu->truncated = le16_to_cpu(pdu->truncated);
+       pdu->groupid = le32_to_cpu(pdu->groupid);
 
        p = malloc(sizeof(*p));
        p->name = strdup((char *) pdu->name);
@@ -1223,6 +1226,23 @@ static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
        fio_client_dec_jobs_eta(eta, client->ops->eta);
 }
 
+static void handle_iolog(struct fio_client *client, struct cmd_iolog_pdu *pdu)
+{
+       FILE *f;
+
+       printf("got log compressed; %d\n", pdu->compressed);
+
+       f = fopen((const char *) pdu->name, "w");
+       if (!f) {
+               perror("fopen log");
+               return;
+       }
+
+       flush_samples(f, pdu->samples,
+                       pdu->nr_samples * sizeof(struct io_sample));
+       fclose(f);
+}
+
 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
 {
        struct cmd_probe_reply_pdu *probe = (struct cmd_probe_reply_pdu *) cmd->payload;
@@ -1665,12 +1685,13 @@ static void request_client_etas(struct client_ops *ops)
 static int handle_cmd_timeout(struct fio_client *client,
                              struct fio_net_cmd_reply *reply)
 {
+       flist_del(&reply->list);
+       free(reply);
+
        if (reply->opcode != FIO_NET_CMD_SEND_ETA)
                return 1;
 
        log_info("client <%s>: timeout on SEND_ETA\n", client->hostname);
-       flist_del(&reply->list);
-       free(reply);
 
        flist_del_init(&client->eta_list);
        if (client->eta_in_flight) {
@@ -1705,8 +1726,6 @@ static int client_check_cmd_timeout(struct fio_client *client,
 
                log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
                                                fio_server_op(reply->opcode));
-               flist_del(&reply->list);
-               free(reply);
                ret = 1;
        }