+ struct cmd_iolog_pdu *pdu = (struct cmd_iolog_pdu *) cmd->payload;
+ struct cmd_iolog_pdu *ret;
+ uint64_t i;
+ int compressed;
+ void *samples;
+
+ *store_direct = false;
+
+ /*
+ * Convert if compressed and we support it. If it's not
+ * compressed, we need not do anything.
+ */
+ compressed = le32_to_cpu(pdu->compressed);
+ if (compressed == XMIT_COMPRESSED) {
+#ifndef CONFIG_ZLIB
+ log_err("fio: server sent compressed data by mistake\n");
+ return NULL;
+#endif
+ ret = convert_iolog_gz(cmd, pdu);
+ printf("compressed iolog, %p\n", ret);
+ if (!ret) {
+ log_err("fio: failed decompressing log\n");
+ return NULL;
+ }
+ } else if (compressed == STORE_COMPRESSED) {
+ *store_direct = true;
+ ret = pdu;
+ } else
+ ret = pdu;
+
+ ret->nr_samples = le64_to_cpu(ret->nr_samples);
+ ret->thread_number = le32_to_cpu(ret->thread_number);
+ ret->log_type = le32_to_cpu(ret->log_type);
+ ret->compressed = le32_to_cpu(ret->compressed);
+ ret->log_offset = le32_to_cpu(ret->log_offset);
+
+ if (*store_direct)
+ return ret;
+
+ samples = &ret->samples[0];
+ for (i = 0; i < ret->nr_samples; i++) {
+ struct io_sample *s;
+
+ s = __get_sample(samples, ret->log_offset, 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);
+
+ if (ret->log_offset) {
+ struct io_sample_offset *so = (void *) s;
+
+ so->offset = le64_to_cpu(so->offset);
+ }
+ }
+
+ return ret;
+}
+
+static void sendfile_reply(int fd, struct cmd_sendfile_reply *rep,
+ size_t size, uint64_t tag)
+{
+ rep->error = cpu_to_le32(rep->error);
+ fio_net_send_cmd(fd, FIO_NET_CMD_SENDFILE, rep, size, &tag, NULL);
+}
+
+static int fio_send_file(struct fio_client *client, struct cmd_sendfile *pdu,
+ uint64_t tag)
+{
+ struct cmd_sendfile_reply *rep;
+ struct stat sb;
+ size_t size;
+ int fd;
+
+ size = sizeof(*rep);
+ rep = malloc(size);
+
+ if (stat((char *)pdu->path, &sb) < 0) {
+fail:
+ rep->error = errno;
+ sendfile_reply(client->fd, rep, size, tag);
+ free(rep);
+ return 1;
+ }
+
+ size += sb.st_size;
+ rep = realloc(rep, size);
+ rep->size = cpu_to_le32((uint32_t) sb.st_size);
+
+ fd = open((char *)pdu->path, O_RDONLY);
+ if (fd == -1 )
+ goto fail;
+
+ rep->error = read_data(fd, &rep->data, sb.st_size);
+ sendfile_reply(client->fd, rep, size, tag);
+ free(rep);
+ close(fd);
+ return 0;
+}
+
+int fio_handle_client(struct fio_client *client)
+{
+ struct client_ops *ops = client->ops;