Merge branch 'client-unique-log-names' of https://github.com/bengland2/fio into log...
authorJens Axboe <axboe@fb.com>
Fri, 16 Sep 2016 15:26:30 +0000 (09:26 -0600)
committerJens Axboe <axboe@fb.com>
Fri, 16 Sep 2016 15:26:30 +0000 (09:26 -0600)
1  2 
client.c

diff --combined client.c
index c8069a0159acb64929be53c75974698d78d5047e,82db502028d9f5b488ca31750299946d3f30440e..4121ea5f4f17df7a9565570bcbb51816ae0229fb
+++ b/client.c
@@@ -1183,7 -1183,7 +1183,7 @@@ void fio_client_sum_jobs_eta(struct job
        strcpy((char *) dst->run_str, (char *) je->run_str);
  }
  
 -static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
 +static bool remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
  {
        struct fio_net_cmd_reply *reply = NULL;
        struct flist_head *entry;
  
        if (!reply) {
                log_err("fio: client: unable to find matching tag (%llx)\n", (unsigned long long) cmd->tag);
 -              return;
 +              return false;
        }
  
        flist_del(&reply->list);
        cmd->tag = reply->saved_tag;
        free(reply);
 +      return true;
  }
  
  int fio_client_wait_for_reply(struct fio_client *client, uint64_t tag)
@@@ -1295,6 -1294,7 +1295,7 @@@ static int fio_client_handle_iolog(stru
  {
        struct cmd_iolog_pdu *pdu;
        bool store_direct;
+       char *log_pathname;
  
        pdu = convert_iolog(cmd, &store_direct);
        if (!pdu) {
                return 1;
        }
  
+         /* allocate buffer big enough for next sprintf() call */
+       log_pathname = malloc( 10 + 
+                       strlen((char * )pdu->name) + 
+                       strlen(client->hostname));
+       if (!log_pathname) {
+               log_err("fio: memory allocation of unique pathname failed");
+               return -1;
+       }
+       /* generate a unique pathname for the log file using hostname */
+       sprintf(log_pathname, "%s.%s", pdu->name, client->hostname);
        if (store_direct) {
                ssize_t ret;
                size_t sz;
                int fd;
  
-               fd = open((const char *) pdu->name,
+               fd = open((const char *) log_pathname,
                                O_WRONLY | O_CREAT | O_TRUNC, 0644);
                if (fd < 0) {
-                       log_err("fio: open log: %s\n", strerror(errno));
+                       log_err("fio: open log %s: %s\n", 
+                               log_pathname, strerror(errno));
                        return 1;
                }
  
                return 0;
        } else {
                FILE *f;
-               f = fopen((const char *) pdu->name, "w");
+               f = fopen((const char *) log_pathname, "w");
                if (!f) {
-                       log_err("fio: fopen log: %s\n", strerror(errno));
+                       log_err("fio: fopen log %s : %s\n", 
+                               log_pathname, strerror(errno));
                        return 1;
                }
  
@@@ -1654,8 -1666,7 +1667,8 @@@ int fio_handle_client(struct fio_clien
        case FIO_NET_CMD_ETA: {
                struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
  
 -              remove_reply_cmd(client, cmd);
 +              if (!remove_reply_cmd(client, cmd))
 +                      break;
                convert_jobs_eta(je);
                handle_eta(client, cmd);
                break;