client/server: zlib error code fixup
[fio.git] / client.c
index c49e9a198455d72fabe318841f0f8022add89a1e..678a62753021035568cec1fb54ac1f23e8d7bcca 100644 (file)
--- a/client.c
+++ b/client.c
@@ -963,6 +963,7 @@ static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
        unsigned long total;
        z_stream stream;
        void *p;
+       int i;
 
        stream.zalloc = Z_NULL;
        stream.zfree = Z_NULL;
@@ -974,17 +975,20 @@ static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
                return NULL;
 
        /*
-        * Everything beyond the first entry is compressed.
+        * Get header first, it's not compressed
         */
        nr_samples = le32_to_cpu(pdu->nr_samples);
 
-       total = sizeof(*pdu) + nr_samples * sizeof(struct io_sample);
-       ret = malloc(total);
+       total = nr_samples * sizeof(struct io_sample);
+       ret = malloc(total + sizeof(*pdu));
        ret->nr_samples = nr_samples;
-       p = (void *) ret + sizeof(pdu->nr_samples);
+       ret->log_type = le32_to_cpu(pdu->log_type);
+       strcpy((char *) ret->name, (char *) pdu->name);
+
+       p = (void *) ret + sizeof(*pdu);
 
-       stream.avail_in = cmd->pdu_len - sizeof(pdu->nr_samples);
-       stream.next_in = (void *) pdu + sizeof(pdu->nr_samples);
+       stream.avail_in = cmd->pdu_len - sizeof(*pdu);
+       stream.next_in = (void *) pdu + sizeof(*pdu);
        while (stream.avail_in) {
                unsigned int this_chunk = 65536;
                unsigned int this_len;
@@ -996,8 +1000,11 @@ static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
                stream.avail_out = this_chunk;
                stream.next_out = p;
                err = inflate(&stream, Z_NO_FLUSH);
-               if (err != Z_OK) {
+               /* may be Z_OK, or Z_STREAM_END */
+               if (err < 0) {
                        log_err("fio: inflate error %d\n", err);
+                       free(ret);
+                       ret = NULL;
                        goto out;
                }
 
@@ -1006,7 +1013,15 @@ static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
                total -= this_len;
        }
 
-       ret->log_type = cpu_to_le32(ret->log_type);
+       for (i = 0; i < ret->nr_samples; i++) {
+               struct io_sample *s = &ret->samples[i];
+
+               s->time = le64_to_cpu(s->time);
+               s->val  = le64_to_cpu(s->val);
+               s->ddir = le32_to_cpu(s->ddir);
+               s->bs   = le32_to_cpu(s->bs);
+       }
+
 out:
        inflateEnd(&stream);
        return ret;