client/server: enable per_job_logs option
authorVincent Fu <vincent.fu@samsung.com>
Mon, 6 Nov 2023 18:41:53 +0000 (13:41 -0500)
committerVincent Fu <vincent.fu@samsung.com>
Mon, 6 Nov 2023 18:41:53 +0000 (13:41 -0500)
On the client side log files were being overwritten when per_job_logs
was set to false because of the flags used when log files were opened.
Add per_job_logs to the on-wire protocol so that the client can adjust
the flags and open files in append mode when per_job_logs is set to
false.

Fixes: https://github.com/axboe/fio/issues/1032

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
client.c
server.c
server.h

index 345fa9101bdaf1dd210d690ee33b4749086d24f1..699a2e5b981e4dd7532f48d56c861273eb9cb6c3 100644 (file)
--- a/client.c
+++ b/client.c
@@ -1452,10 +1452,13 @@ static int fio_client_handle_iolog(struct fio_client *client,
        if (store_direct) {
                ssize_t wrote;
                size_t sz;
-               int fd;
+               int fd, flags;
 
-               fd = open((const char *) log_pathname,
-                               O_WRONLY | O_CREAT | O_TRUNC, 0644);
+               if (pdu->per_job_logs)
+                       flags = O_WRONLY | O_CREAT | O_TRUNC;
+               else
+                       flags = O_WRONLY | O_CREAT | O_APPEND;
+               fd = open((const char *) log_pathname, flags, 0644);
                if (fd < 0) {
                        log_err("fio: open log %s: %s\n",
                                log_pathname, strerror(errno));
@@ -1476,7 +1479,13 @@ static int fio_client_handle_iolog(struct fio_client *client,
                ret = 0;
        } else {
                FILE *f;
-               f = fopen((const char *) log_pathname, "w");
+               const char *mode;
+
+               if (pdu->per_job_logs)
+                       mode = "w";
+               else
+                       mode = "a";
+               f = fopen((const char *) log_pathname, mode);
                if (!f) {
                        log_err("fio: fopen log %s : %s\n",
                                log_pathname, strerror(errno));
@@ -1695,6 +1704,7 @@ static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd,
        ret->log_offset         = le32_to_cpu(ret->log_offset);
        ret->log_prio           = le32_to_cpu(ret->log_prio);
        ret->log_hist_coarseness = le32_to_cpu(ret->log_hist_coarseness);
+       ret->per_job_logs       = le32_to_cpu(ret->per_job_logs);
 
        if (*store_direct)
                return ret;
index 27332e326e9b8db29c37084fe13d04d6535ad73d..06eac5840fb7428d8bd9ee7e769010101129f186 100644 (file)
--- a/server.c
+++ b/server.c
@@ -2260,6 +2260,7 @@ int fio_send_iolog(struct thread_data *td, struct io_log *log, const char *name)
                .thread_number          = cpu_to_le32(td->thread_number),
                .log_type               = cpu_to_le32(log->log_type),
                .log_hist_coarseness    = cpu_to_le32(log->hist_coarseness),
+               .per_job_logs           = cpu_to_le32(td->o.per_job_logs),
        };
        struct sk_entry *first;
        struct flist_head *entry;
index ad7061184b6c113f5871fdc8815061d82aaaebe5..0eb594ce857aa838a64b7d37e5d424fc50fd4512 100644 (file)
--- a/server.h
+++ b/server.h
@@ -51,7 +51,7 @@ struct fio_net_cmd_reply {
 };
 
 enum {
-       FIO_SERVER_VER                  = 101,
+       FIO_SERVER_VER                  = 102,
 
        FIO_SERVER_MAX_FRAGMENT_PDU     = 1024,
        FIO_SERVER_MAX_CMD_MB           = 2048,
@@ -198,6 +198,7 @@ struct cmd_iolog_pdu {
        uint32_t log_offset;
        uint32_t log_prio;
        uint32_t log_hist_coarseness;
+       uint32_t per_job_logs;
        uint8_t name[FIO_NET_NAME_MAX];
        struct io_sample samples[0];
 };