client: duplicate arguments to "empty" clients
authorJens Axboe <axboe@kernel.dk>
Mon, 10 Oct 2011 19:11:09 +0000 (21:11 +0200)
committerJens Axboe <axboe@kernel.dk>
Mon, 10 Oct 2011 19:11:09 +0000 (21:11 +0200)
Now you can do:

fio --client=host1 --client=host2 --arg1 --arg2 --arg3

and arg1,2,3 are passed to both clients. If you do:

fio --client=host1 --arg1 --client=host2 --arg2 --arg3

then arg1 is passed to host1, while arg2,3 are passed to host2.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
client.c

index 097fcc57adfc763afdeb361d16d38dc77d9ad011..358903bb1f29bff18df48b67c189e38c7d05149f 100644 (file)
--- a/client.c
+++ b/client.c
@@ -28,6 +28,7 @@ struct client_eta {
 struct fio_client {
        struct flist_head list;
        struct flist_head hash_list;
+       struct flist_head arg_list;
        struct sockaddr_in addr;
        struct sockaddr_un addr_un;
        char *hostname;
@@ -61,6 +62,8 @@ enum {
 static FLIST_HEAD(client_list);
 static FLIST_HEAD(eta_list);
 
+static FLIST_HEAD(arg_list);
+
 #define FIO_CLIENT_HASH_BITS   7
 #define FIO_CLIENT_HASH_SZ     (1 << FIO_CLIENT_HASH_BITS)
 #define FIO_CLIENT_HASH_MASK   (FIO_CLIENT_HASH_SZ - 1)
@@ -143,22 +146,47 @@ static void __fio_client_add_cmd_option(struct fio_client *client,
 void fio_client_add_cmd_option(void *cookie, const char *opt)
 {
        struct fio_client *client = cookie;
+       struct flist_head *entry;
 
        if (!client || !opt)
                return;
 
        __fio_client_add_cmd_option(client, opt);
+
+       /*
+        * Duplicate arguments to shared client group
+        */
+       flist_for_each(entry, &arg_list) {
+               client = flist_entry(entry, struct fio_client, arg_list);
+
+               __fio_client_add_cmd_option(client, opt);
+       }
 }
 
 int fio_client_add(const char *hostname, void **cookie)
 {
+       struct fio_client *existing = *cookie;
        struct fio_client *client;
 
+       if (existing) {
+               /*
+                * We always add our "exec" name as the option, hence 1
+                * means empty.
+                */
+               if (existing->argc == 1)
+                       flist_add_tail(&existing->arg_list, &arg_list);
+               else {
+                       while (!flist_empty(&arg_list))
+                               flist_del_init(arg_list.next);
+               }
+       }
+
        client = malloc(sizeof(*client));
        memset(client, 0, sizeof(*client));
 
        INIT_FLIST_HEAD(&client->list);
        INIT_FLIST_HEAD(&client->hash_list);
+       INIT_FLIST_HEAD(&client->arg_list);
        INIT_FLIST_HEAD(&client->eta_list);
 
        if (fio_server_parse_string(hostname, &client->hostname,