Start of functional client
authorJens Axboe <axboe@kernel.dk>
Fri, 30 Sep 2011 23:00:42 +0000 (17:00 -0600)
committerJens Axboe <axboe@kernel.dk>
Fri, 30 Sep 2011 23:00:42 +0000 (17:00 -0600)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
client.c
eta.c
fio.c
fio.h
init.c
server.c
server.h

index c94ccf3fa213ff50c6bfcf9792c9e617bb742cf9..6aaad0193d2b6d272bcfb31afb20bf421a278ad0 100644 (file)
--- a/client.c
+++ b/client.c
@@ -70,9 +70,6 @@ static int send_file_buf(char *buf, off_t size)
 
        fio_net_cmd_crc(cmd);
 
 
        fio_net_cmd_crc(cmd);
 
-       printf("cmd crc %x, pdu crc %x\n", cmd->cmd_crc32, cmd->pdu_crc32);
-       printf("job %x\n", cmd->opcode);
-
        ret = fio_send_data(fio_client_fd, cmd, sizeof(*cmd) + size);
        free(cmd);
        return ret;
        ret = fio_send_data(fio_client_fd, cmd, sizeof(*cmd) + size);
        free(cmd);
        return ret;
@@ -122,3 +119,27 @@ int fio_client_send_ini(const char *filename)
        free(buf);
        return ret;
 }
        free(buf);
        return ret;
 }
+
+int fio_handle_clients(void)
+{
+       struct fio_net_cmd *cmd;
+
+       while (!exit_backend) {
+               cmd = fio_net_cmd_read(fio_client_fd);
+
+               if (cmd->opcode == FIO_NET_CMD_ACK) {
+                       free(cmd);
+                       continue;
+               }
+               if (cmd->opcode != FIO_NET_CMD_TEXT) {
+                       printf("non text: %d\n", cmd->opcode);
+                       free(cmd);
+                       continue;
+               }
+               printf("%s", cmd->payload);
+               fflush(stdout);
+               free(cmd);
+       }
+
+       return 0;
+}
diff --git a/eta.c b/eta.c
index d93bf1a16f80ff51f9b025149568f3a199472970..fc0292f3d7ac6c2e9b4ef5da5ecd29397572a274 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -249,6 +249,7 @@ void print_thread_status(void)
        static unsigned int rate[2], iops[2];
        static int linelen_last;
        static int eta_good;
        static unsigned int rate[2], iops[2];
        static int linelen_last;
        static int eta_good;
+       char output[512], *p = output;
        int i2p = 0;
 
        if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER)
        int i2p = 0;
 
        if (temp_stall_ts || terse_output || eta_print == FIO_ETA_NEVER)
@@ -355,17 +356,17 @@ void print_thread_status(void)
        if (!nr_running && !nr_pending)
                return;
 
        if (!nr_running && !nr_pending)
                return;
 
-       printf("Jobs: %d (f=%d)", nr_running, files_open);
+       p += sprintf(p, "Jobs: %d (f=%d)", nr_running, files_open);
        if (m_rate || t_rate) {
                char *tr, *mr;
 
                mr = num2str(m_rate, 4, 0, i2p);
                tr = num2str(t_rate, 4, 0, i2p);
        if (m_rate || t_rate) {
                char *tr, *mr;
 
                mr = num2str(m_rate, 4, 0, i2p);
                tr = num2str(t_rate, 4, 0, i2p);
-               printf(", CR=%s/%s KB/s", tr, mr);
+               p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
                free(tr);
                free(mr);
        } else if (m_iops || t_iops)
                free(tr);
                free(mr);
        } else if (m_iops || t_iops)
-               printf(", CR=%d/%d IOPS", t_iops, m_iops);
+               p += sprintf(p, ", CR=%d/%d IOPS", t_iops, m_iops);
        if (eta_sec != INT_MAX && nr_running) {
                char perc_str[32];
                char *iops_str[2];
        if (eta_sec != INT_MAX && nr_running) {
                char perc_str[32];
                char *iops_str[2];
@@ -386,11 +387,12 @@ void print_thread_status(void)
                iops_str[0] = num2str(iops[0], 4, 1, 0);
                iops_str[1] = num2str(iops[1], 4, 1, 0);
 
                iops_str[0] = num2str(iops[0], 4, 1, 0);
                iops_str[1] = num2str(iops[1], 4, 1, 0);
 
-               l = printf(": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]",
+               l = sprintf(p, ": [%s] [%s] [%s/%s /s] [%s/%s iops] [eta %s]",
                                 run_str, perc_str, rate_str[0], rate_str[1],
                                 iops_str[0], iops_str[1], eta_str);
                                 run_str, perc_str, rate_str[0], rate_str[1],
                                 iops_str[0], iops_str[1], eta_str);
+               p += l;
                if (l >= 0 && l < linelen_last)
                if (l >= 0 && l < linelen_last)
-                       printf("%*s", linelen_last - l, "");
+                       p += sprintf(p, "%*s", linelen_last - l, "");
                linelen_last = l;
 
                free(rate_str[0]);
                linelen_last = l;
 
                free(rate_str[0]);
@@ -398,8 +400,13 @@ void print_thread_status(void)
                free(iops_str[0]);
                free(iops_str[1]);
        }
                free(iops_str[0]);
                free(iops_str[1]);
        }
-       printf("\r");
-       fflush(stdout);
+       p += sprintf(p, "\r");
+
+       if (!is_backend) {
+               printf("%s", output);
+               fflush(stdout);
+       } else
+               fio_server_text_output(output, p - output);
 }
 
 void print_status_init(int thr_number)
 }
 
 void print_status_init(int thr_number)
diff --git a/fio.c b/fio.c
index a15080b4a26e89bebea6edf5def458e701e0cddd..bd566e8eb7749c236652cf968cbd5444e539c2fb 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -139,9 +139,7 @@ static void *disk_thread_main(void *data)
                if (!threads)
                        break;
                update_io_ticks();
                if (!threads)
                        break;
                update_io_ticks();
-
-               if (!is_backend)
-                       print_thread_status();
+               print_thread_status();
        }
 
        return NULL;
        }
 
        return NULL;
@@ -1696,6 +1694,8 @@ static void run_threads(void)
 
 int exec_run(void)
 {
 
 int exec_run(void)
 {
+       if (is_client)
+               return fio_handle_clients();
        if (exec_profile && load_profile(exec_profile))
                return 1;
 
        if (exec_profile && load_profile(exec_profile))
                return 1;
 
diff --git a/fio.h b/fio.h
index d36ee165fef022ac15834d9969b95698e4b690b3..e46a1a353507f057a7fbf7cf80d4e77129c0dcb6 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -35,6 +35,7 @@ struct thread_data;
 #include "time.h"
 #include "lib/getopt.h"
 #include "lib/rand.h"
 #include "time.h"
 #include "lib/getopt.h"
 #include "lib/rand.h"
+#include "server.h"
 
 #ifdef FIO_HAVE_GUASI
 #include <guasi.h>
 
 #ifdef FIO_HAVE_GUASI
 #include <guasi.h>
@@ -651,6 +652,7 @@ extern enum fio_cs fio_clock_source;
 extern int warnings_fatal;
 extern int terse_version;
 extern int is_backend;
 extern int warnings_fatal;
 extern int terse_version;
 extern int is_backend;
+extern int is_client;
 
 extern struct thread_data *threads;
 
 
 extern struct thread_data *threads;
 
diff --git a/init.c b/init.c
index 088e814ee2ff445f874f5c5b6e3a20e62995b999..28852fb7005d0bdce3e2e14e6dd62d94e40721e8 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1412,7 +1412,7 @@ int parse_options(int argc, char *argv[])
                        return 0;
                if (exec_profile)
                        return 0;
                        return 0;
                if (exec_profile)
                        return 0;
-               if (is_backend)
+               if (is_backend || is_client)
                        return 0;
 
                log_err("No jobs(s) defined\n\n");
                        return 0;
 
                log_err("No jobs(s) defined\n\n");
index f393873f44486f949ff397408a31cdd53e431a07..1749e7365bb446076366ad50f6a0db4c8a7be81d 100644 (file)
--- a/server.c
+++ b/server.c
@@ -24,6 +24,8 @@ static char *job_buf;
 static unsigned int job_cur_len;
 static unsigned int job_max_len;
 
 static unsigned int job_cur_len;
 static unsigned int job_max_len;
 
+static int server_fd;
+
 int fio_send_data(int sk, const void *p, unsigned int len)
 {
        do {
 int fio_send_data(int sk, const void *p, unsigned int len)
 {
        do {
@@ -106,7 +108,7 @@ static int verify_convert_cmd(struct fio_net_cmd *cmd)
        return 0;
 }
 
        return 0;
 }
 
-static struct fio_net_cmd *read_command(int sk)
+struct fio_net_cmd *fio_net_cmd_read(int sk)
 {
        struct fio_net_cmd cmd, *ret = NULL;
        uint32_t crc;
 {
        struct fio_net_cmd cmd, *ret = NULL;
        uint32_t crc;
@@ -242,7 +244,7 @@ static int handle_connection(int sk)
 
        /* read forever */
        while (!exit_backend) {
 
        /* read forever */
        while (!exit_backend) {
-               cmd = read_command(sk);
+               cmd = fio_net_cmd_read(sk);
                if (!cmd) {
                        ret = 1;
                        break;
                if (!cmd) {
                        ret = 1;
                        break;
@@ -301,8 +303,11 @@ again:
                return -1;
        }
 
                return -1;
        }
 
+       server_fd = sk;
+
        exitval = handle_connection(sk);
 
        exitval = handle_connection(sk);
 
+       server_fd = -1;
        close(sk);
 
        if (!exit_backend)
        close(sk);
 
        if (!exit_backend)
@@ -361,3 +366,19 @@ int fio_server(void)
        close(sk);
        return ret;
 }
        close(sk);
        return ret;
 }
+
+void fio_server_text_output(const char *buf, unsigned int len)
+{
+       struct fio_net_cmd *cmd;
+
+       cmd = malloc(sizeof(*cmd) + len);
+       fio_init_net_cmd(cmd);
+       cmd->opcode     = cpu_to_le16(FIO_NET_CMD_TEXT);
+       cmd->pdu_len    = cpu_to_le32(len);
+       memcpy(&cmd->payload, buf, len);
+
+       fio_net_cmd_crc(cmd);
+
+       fio_send_data(server_fd, cmd, sizeof(*cmd) + len);
+       free(cmd);
+}
index 51a84176c38c01f5485ff5cac533c8ffc1a3e92f..c2cb9942774b8a3c11b4e930d560300b3df2ffa7 100644 (file)
--- a/server.h
+++ b/server.h
@@ -30,16 +30,20 @@ enum {
        FIO_NET_CMD_JOB_END     = 3,
        FIO_NET_CMD_ACK         = 4,
        FIO_NET_CMD_NAK         = 5,
        FIO_NET_CMD_JOB_END     = 3,
        FIO_NET_CMD_ACK         = 4,
        FIO_NET_CMD_NAK         = 5,
+       FIO_NET_CMD_TEXT        = 6,
 };
 
 extern int fio_server(void);
 };
 
 extern int fio_server(void);
+extern void fio_server_text_output(const char *, unsigned int len);
 
 extern int fio_client_connect(const char *);
 extern int fio_client_send_ini(const char *);
 
 extern int fio_client_connect(const char *);
 extern int fio_client_send_ini(const char *);
+extern int fio_handle_clients(void);
 
 extern int fio_recv_data(int sk, void *p, unsigned int len);
 extern int fio_send_data(int sk, const void *p, unsigned int len);
 extern void fio_net_cmd_crc(struct fio_net_cmd *);
 
 extern int fio_recv_data(int sk, void *p, unsigned int len);
 extern int fio_send_data(int sk, const void *p, unsigned int len);
 extern void fio_net_cmd_crc(struct fio_net_cmd *);
+extern struct fio_net_cmd *fio_net_cmd_read(int sk);
 
 extern int exit_backend;
 extern int fio_net_port;
 
 extern int exit_backend;
 extern int fio_net_port;