From 9af6c387191423eefee821e4087987350eaa5e6a Mon Sep 17 00:00:00 2001 From: Vincent Fu Date: Mon, 6 Nov 2023 13:41:53 -0500 Subject: [PATCH] client/server: enable per_job_logs option 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 --- client.c | 18 ++++++++++++++---- server.c | 1 + server.h | 3 ++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/client.c b/client.c index 345fa910..699a2e5b 100644 --- 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; diff --git a/server.c b/server.c index 27332e32..06eac584 100644 --- 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; diff --git a/server.h b/server.h index ad706118..0eb594ce 100644 --- 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]; }; -- 2.25.1