client: continue support for multiple connections
authorJens Axboe <axboe@kernel.dk>
Sat, 1 Oct 2011 18:24:21 +0000 (12:24 -0600)
committerJens Axboe <axboe@kernel.dk>
Sat, 1 Oct 2011 18:24:21 +0000 (12:24 -0600)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
client.c
fio.c
fio.h
init.c
server.h

index 368ad9e7bed81a9ac550fc1eb7f5efef182c65c3..054043d4eb423f913009644434c062fe77b0959b 100644 (file)
--- a/client.c
+++ b/client.c
@@ -26,7 +26,6 @@ struct fio_client {
 };
 
 static FLIST_HEAD(client_list);
-static unsigned int nr_clients;
 
 static struct fio_client *find_client_by_fd(int fd)
 {
@@ -43,6 +42,7 @@ static struct fio_client *find_client_by_fd(int fd)
        return NULL;
 }
 
+#if 0
 static struct fio_client *find_client_by_name(const char *name)
 {
        struct fio_client *client;
@@ -57,6 +57,7 @@ static struct fio_client *find_client_by_name(const char *name)
 
        return NULL;
 }
+#endif
 
 static void remove_client(struct fio_client *client)
 {
@@ -67,21 +68,30 @@ static void remove_client(struct fio_client *client)
        free(client);
 }
 
-int fio_client_connect(const char *host)
+void fio_client_add(const char *hostname)
 {
        struct fio_client *client;
-       int fd;
 
        client = malloc(sizeof(*client));
+       memset(client, 0, sizeof(*client));
+       client->hostname = strdup(hostname);
+       client->fd = -1;
+       flist_add(&client->list, &client_list);
+       nr_clients++;
+}
+
+static int fio_client_connect(struct fio_client *client)
+{
+       int fd;
 
        memset(&client->addr, 0, sizeof(client->addr));
        client->addr.sin_family = AF_INET;
        client->addr.sin_port = htons(fio_net_port);
 
-       if (inet_aton(host, &client->addr.sin_addr) != 1) {
+       if (inet_aton(client->hostname, &client->addr.sin_addr) != 1) {
                struct hostent *hent;
 
-               hent = gethostbyname(host);
+               hent = gethostbyname(client->hostname);
                if (!hent) {
                        log_err("fio: gethostbyname: %s\n", strerror(errno));
                        return 1;
@@ -103,13 +113,27 @@ int fio_client_connect(const char *host)
                return 1;
        }
 
-       client->hostname = strdup(host);
-       flist_add(&client->list, &client_list);
-       nr_clients++;
        client->fd = fd;
        return 0;
 }
 
+int fio_clients_connect(void)
+{
+       struct fio_client *client;
+       struct flist_head *entry, *tmp;
+       int ret;
+
+       flist_for_each_safe(entry, tmp, &client_list) {
+               client = flist_entry(entry, struct fio_client, list);
+
+               ret = fio_client_connect(client);
+               if (ret)
+                       remove_client(client);
+       }
+
+       return !nr_clients;
+}
+
 static int send_file_buf(struct fio_client *client, char *buf, off_t size)
 {
        return fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, size);
@@ -119,20 +143,13 @@ static int send_file_buf(struct fio_client *client, char *buf, off_t size)
  * Send file contents to server backend. We could use sendfile(), but to remain
  * more portable lets just read/write the darn thing.
  */
-int fio_client_send_ini(const char *hostname, const char *filename)
+static int fio_client_send_ini(struct fio_client *client, const char *filename)
 {
-       struct fio_client *client;
        struct stat sb;
        char *p, *buf;
        off_t len;
        int fd, ret;
 
-       client = find_client_by_name(hostname);
-       if (!client) {
-               log_err("fio: can't find client for host %s\n", hostname);
-               return 1;
-       }
-
        fd = open(filename, O_RDONLY);
        if (fd < 0) {
                log_err("fio: job file open: %s\n", strerror(errno));
@@ -167,6 +184,21 @@ int fio_client_send_ini(const char *hostname, const char *filename)
        return ret;
 }
 
+int fio_clients_send_ini(const char *filename)
+{
+       struct fio_client *client;
+       struct flist_head *entry, *tmp;
+
+       flist_for_each_safe(entry, tmp, &client_list) {
+               client = flist_entry(entry, struct fio_client, list);
+
+               if (fio_client_send_ini(client, filename))
+                       remove_client(client);
+       }
+
+       return !nr_clients;
+}
+
 static int handle_client(struct fio_client *client)
 {
        struct fio_net_cmd *cmd;
diff --git a/fio.c b/fio.c
index bd566e8eb7749c236652cf968cbd5444e539c2fb..0f12888464347667ba48bf5734dd4d5450959c23 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1694,7 +1694,7 @@ static void run_threads(void)
 
 int exec_run(void)
 {
-       if (is_client)
+       if (nr_clients)
                return fio_handle_clients();
        if (exec_profile && load_profile(exec_profile))
                return 1;
diff --git a/fio.h b/fio.h
index e46a1a353507f057a7fbf7cf80d4e77129c0dcb6..a6ef937dea7f1f240e1fbf2f31a17535ef8a2de1 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -652,7 +652,7 @@ extern enum fio_cs fio_clock_source;
 extern int warnings_fatal;
 extern int terse_version;
 extern int is_backend;
-extern int is_client;
+extern int nr_clients;
 
 extern struct thread_data *threads;
 
diff --git a/init.c b/init.c
index 19f94e59ce6af5d51fb31b164bb3c97b7db6e8a7..1dcb4904da330dd090cba383dcce9c1471b6e523 100644 (file)
--- a/init.c
+++ b/init.c
@@ -46,8 +46,7 @@ char *exec_profile = NULL;
 int warnings_fatal = 0;
 int terse_version = 2;
 int is_backend = 0;
-int is_client = 0;
-char *client;
+int nr_clients = 0;
 
 int write_bw_log = 0;
 int read_only = 0;
@@ -1309,7 +1308,7 @@ static int parse_cmd_line(int argc, char *argv[])
                        }
                        break;
                case 'S':
-                       if (is_client) {
+                       if (nr_clients) {
                                log_err("fio: can't be both client and server\n");
                                do_exit++;
                                exit_val = 1;
@@ -1327,8 +1326,7 @@ static int parse_cmd_line(int argc, char *argv[])
                                exit_val = 1;
                                break;
                        }
-                       is_client = 1;
-                       client = strdup(optarg);
+                       fio_client_add(optarg);
                        break;
                default:
                        do_exit++;
@@ -1340,7 +1338,7 @@ static int parse_cmd_line(int argc, char *argv[])
        if (do_exit)
                exit(exit_val);
 
-       if (is_client && fio_client_connect(client)) {
+       if (nr_clients && fio_clients_connect()) {
                do_exit++;
                exit_val = 1;
                return 1;
@@ -1384,8 +1382,8 @@ int parse_options(int argc, char *argv[])
        for (i = 0; i < job_files; i++) {
                if (fill_def_thread())
                        return 1;
-               if (is_client) {
-                       if (fio_client_send_ini(client, ini_file[i]))
+               if (nr_clients) {
+                       if (fio_clients_send_ini(ini_file[i]))
                                return 1;
                } else {
                        if (parse_jobs_ini(ini_file[i], 0, i))
@@ -1402,7 +1400,7 @@ int parse_options(int argc, char *argv[])
                        return 0;
                if (exec_profile)
                        return 0;
-               if (is_backend || is_client)
+               if (is_backend || nr_clients)
                        return 0;
 
                log_err("No jobs(s) defined\n\n");
index 0f57ae85cf0994338c4958a1f8a94fecfc74c5f0..8e6852a528c22b3ec63bb6cf0a466c85a59c426e 100644 (file)
--- a/server.h
+++ b/server.h
@@ -43,9 +43,10 @@ extern int fio_server_text_output(const char *, unsigned int len);
 extern int fio_server_log(const char *format, ...);
 extern int fio_net_send_cmd(int, uint16_t, const char *, off_t);
 
-extern int fio_client_connect(const char *);
-extern int fio_client_send_ini(const char *, const char *);
+extern int fio_clients_connect(void);
+extern int fio_clients_send_ini(const char *);
 extern int fio_handle_clients(void);
+extern void fio_client_add(const char *);
 
 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);