From 3b70d7e51e0b672a8b337c57c8faf865c0b7f415 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 8 Jun 2006 21:48:46 +0200 Subject: [PATCH] [PATCH] When logging to a file, stderr should go both to stderr and file --- fio.c | 26 +++++++++++++------------- fio.h | 9 +++++++++ init.c | 26 +++++++++++++------------- ioengines.c | 4 ++-- log.c | 6 +++--- stat.c | 2 +- 6 files changed, 41 insertions(+), 32 deletions(-) diff --git a/fio.c b/fio.c index c95d7b57..b452c5f0 100644 --- a/fio.c +++ b/fio.c @@ -287,8 +287,8 @@ static int verify_io_u_crc32(struct verify_header *hdr, struct io_u *io_u) c = crc32(p, hdr->len - sizeof(*hdr)); if (c != hdr->crc32) { - fprintf(f_err, "crc32: verify failed at %llu/%u\n", io_u->offset, io_u->buflen); - fprintf(f_err, "crc32: wanted %lx, got %lx\n", hdr->crc32, c); + log_err("crc32: verify failed at %llu/%u\n", io_u->offset, io_u->buflen); + log_err("crc32: wanted %lx, got %lx\n", hdr->crc32, c); return 1; } @@ -305,7 +305,7 @@ static int verify_io_u_md5(struct verify_header *hdr, struct io_u *io_u) md5_update(&md5_ctx, p, hdr->len - sizeof(*hdr)); if (memcmp(hdr->md5_digest, md5_ctx.hash, sizeof(md5_ctx.hash))) { - fprintf(f_err, "md5: verify failed at %llu/%u\n", io_u->offset, io_u->buflen); + log_err("md5: verify failed at %llu/%u\n", io_u->offset, io_u->buflen); hexdump(hdr->md5_digest, sizeof(hdr->md5_digest)); hexdump(md5_ctx.hash, sizeof(md5_ctx.hash)); return 1; @@ -327,7 +327,7 @@ static int verify_io_u(struct io_u *io_u) else if (hdr->verify_type == VERIFY_CRC32) ret = verify_io_u_crc32(hdr, io_u); else { - fprintf(f_err, "Bad verify type %d\n", hdr->verify_type); + log_err("Bad verify type %d\n", hdr->verify_type); ret = 1; } @@ -851,7 +851,7 @@ static int init_io(struct thread_data *td) else if (td->io_engine == FIO_SPLICEIO) return fio_spliceio_init(td); else { - fprintf(f_err, "bad io_engine %d\n", td->io_engine); + log_err("bad io_engine %d\n", td->io_engine); return 1; } } @@ -878,7 +878,7 @@ static void cleanup_io_u(struct thread_data *td) } else if (td->mem_type == MEM_MMAP) munmap(td->orig_buffer, td->orig_buffer_size); else - fprintf(f_err, "Bad memory type %d\n", td->mem_type); + log_err("Bad memory type %d\n", td->mem_type); td->orig_buffer = NULL; } @@ -952,7 +952,7 @@ static int create_file(struct thread_data *td, unsigned long long size, return 0; if (!size) { - fprintf(f_err, "Need size for create\n"); + log_err("Need size for create\n"); td_verror(td, EINVAL); return 1; } @@ -1068,13 +1068,13 @@ static int get_file_size(struct thread_data *td) return ret; if (td->file_offset > td->real_file_size) { - fprintf(f_err, "%s: offset extends end (%Lu > %Lu)\n", td->name, td->file_offset, td->real_file_size); + log_err("%s: offset extends end (%Lu > %Lu)\n", td->name, td->file_offset, td->real_file_size); return 1; } td->io_size = td->file_size; if (td->io_size == 0) { - fprintf(f_err, "%s: no io blocks\n", td->name); + log_err("%s: no io blocks\n", td->name); td_verror(td, EINVAL); return 1; } @@ -1253,7 +1253,7 @@ static int switch_ioscheduler(struct thread_data *td) sprintf(tmp2, "[%s]", td->ioscheduler); if (!strstr(tmp, tmp2)) { - fprintf(f_err, "fio: io scheduler %s not found\n", td->ioscheduler); + log_err("fio: io scheduler %s not found\n", td->ioscheduler); td_verror(td, EINVAL); fclose(f); return 1; @@ -1461,7 +1461,7 @@ static void check_str_update(struct thread_data *td) c = 'P'; break; default: - fprintf(f_err, "state %d\n", td->runstate); + log_err("state %d\n", td->runstate); } run_str[td->thread_number - 1] = c; @@ -1826,7 +1826,7 @@ static void run_threads(void) } if (left) { - fprintf(f_err, "fio: %d jobs failed to start\n", left); + log_err("fio: %d jobs failed to start\n", left); for (i = 0; i < this_jobs; i++) { td = map[i]; if (!td) @@ -1876,7 +1876,7 @@ int main(int argc, char *argv[]) return 1; if (!thread_number) { - fprintf(f_err, "Nothing to do\n"); + log_err("Nothing to do\n"); return 1; } diff --git a/fio.h b/fio.h index f6c2ee3b..2d57227c 100644 --- a/fio.h +++ b/fio.h @@ -441,4 +441,13 @@ static inline void fio_sem_up(volatile int volatile *sem) (*sem)++; } +/* + * If logging output to a file, stderr should go to both stderr and f_err + */ +#define log_err(args...) do { \ + fprintf(f_err, ##args); \ + if (f_err != stderr) \ + fprintf(stderr, ##args); \ + } while (0) + #endif diff --git a/init.c b/init.c index b40437af..6bf33853 100644 --- a/init.c +++ b/init.c @@ -91,13 +91,13 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) #ifndef FIO_HAVE_LIBAIO if (td->io_engine == FIO_LIBAIO) { - fprintf(f_err, "Linux libaio not available\n"); + log_err("Linux libaio not available\n"); return 1; } #endif #ifndef FIO_HAVE_POSIXAIO if (td->io_engine == FIO_POSIXAIO) { - fprintf(f_err, "posix aio not available\n"); + log_err("posix aio not available\n"); return 1; } #endif @@ -495,7 +495,7 @@ static int str_rw_cb(struct thread_data *td, char *mem) return 0; } - fprintf(f_err, "fio: data direction: read, write, randread, randwrite, rw, randrw\n"); + log_err("fio: data direction: read, write, randread, randwrite, rw, randrw\n"); return 1; } @@ -512,7 +512,7 @@ static int str_verify_cb(struct thread_data *td, char *mem) return 0; } - fprintf(f_err, "fio: verify types: md5, crc32\n"); + log_err("fio: verify types: md5, crc32\n"); return 1; } @@ -529,7 +529,7 @@ static int str_mem_cb(struct thread_data *td, char *mem) return 0; } - fprintf(f_err, "fio: mem type: malloc, shm, mmap\n"); + log_err("fio: mem type: malloc, shm, mmap\n"); return 1; } @@ -562,7 +562,7 @@ static int str_ioengine_cb(struct thread_data *td, char *str) return 0; } - fprintf(f_err, "fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice\n"); + log_err("fio: ioengine: { linuxaio, aio, libaio }, posixaio, sync, mmap, sgio, splice\n"); return 1; } @@ -620,7 +620,7 @@ int parse_jobs_ini(char *file) if (!check_int(p, "prio", &prio)) { #ifndef FIO_HAVE_IOPRIO - fprintf(f_err, "io priorities not available\n"); + log_err("io priorities not available\n"); ret = 1; break; #endif @@ -630,7 +630,7 @@ int parse_jobs_ini(char *file) } if (!check_int(p, "prioclass", &prioclass)) { #ifndef FIO_HAVE_IOPRIO - fprintf(f_err, "io priorities not available\n"); + log_err("io priorities not available\n"); ret = 1; break; #else @@ -662,7 +662,7 @@ int parse_jobs_ini(char *file) } if (!check_int(p, "cpumask", &cpu)) { #ifndef FIO_HAVE_CPU_AFFINITY - fprintf(f_err, "cpu affinity not available\n"); + log_err("cpu affinity not available\n"); ret = 1; break; #endif @@ -835,7 +835,7 @@ int parse_jobs_ini(char *file) } if (!check_strstore(p, "iolog", tmpbuf)) { if (td->write_iolog) { - fprintf(f_err, "fio: read iolog overrides given write_iolog\n"); + log_err("fio: read iolog overrides given write_iolog\n"); free(td->iolog_file); td->write_iolog = 0; } @@ -849,7 +849,7 @@ int parse_jobs_ini(char *file) td->iolog_file = strdup(tmpbuf); td->write_iolog = 1; } else - fprintf(f_err, "fio: read iolog overrides given write_iolog\n"); + log_err("fio: read iolog overrides given write_iolog\n"); fgetpos(f, &off); continue; } @@ -865,7 +865,7 @@ int parse_jobs_ini(char *file) } if (!check_strstore(p, "ioscheduler", tmpbuf)) { #ifndef FIO_HAVE_IOSCHED_SWITCH - fprintf(f_err, "io scheduler switching not available\n"); + log_err("io scheduler switching not available\n"); ret = 1; break; #else @@ -1076,7 +1076,7 @@ int parse_options(int argc, char *argv[]) parse_cmd_line(argc, argv); if (!ini_file) { - fprintf(f_err, "Need job file\n"); + log_err("Need job file\n"); usage(argv[0]); return 1; } diff --git a/ioengines.c b/ioengines.c index c94fcb30..fe6136f7 100644 --- a/ioengines.c +++ b/ioengines.c @@ -610,7 +610,7 @@ static int fio_sgio_prep(struct thread_data *td, struct io_u *io_u) int nr_blocks, lba; if (io_u->buflen & (sd->bs - 1)) { - fprintf(f_err, "read/write not sector aligned\n"); + log_err("read/write not sector aligned\n"); return EINVAL; } @@ -718,7 +718,7 @@ int fio_sgio_init(struct thread_data *td) if (ret) return ret; } else { - fprintf(f_err, "ioengine sgio only works on block devices\n"); + log_err("ioengine sgio only works on block devices\n"); return 1; } diff --git a/log.c b/log.c index a364e220..4c7742b2 100644 --- a/log.c +++ b/log.c @@ -122,7 +122,7 @@ int init_iolog(struct thread_data *td) struct io_piece *ipo; if (sscanf(p, "%d,%llu,%u", &rw, &offset, &bytes) != 3) { - fprintf(f_err, "bad iolog: %s\n", p); + log_err("bad iolog: %s\n", p); continue; } if (rw == DDIR_READ) @@ -130,7 +130,7 @@ int init_iolog(struct thread_data *td) else if (rw == DDIR_WRITE) writes++; else { - fprintf(f_err, "bad ddir: %d\n", rw); + log_err("bad ddir: %d\n", rw); continue; } @@ -169,7 +169,7 @@ int setup_rate(struct thread_data *td) return 0; if (td->rate < td->ratemin) { - fprintf(f_err, "min rate larger than nominal rate\n"); + log_err("min rate larger than nominal rate\n"); return -1; } diff --git a/stat.c b/stat.c index cfd27ce7..d70c5ca9 100644 --- a/stat.c +++ b/stat.c @@ -233,7 +233,7 @@ void init_disk_util(struct thread_data *td) p = dirname(foo); sprintf(tmp, "%s/queue", p); if (stat(tmp, &st)) { - fprintf(f_err, "unknown sysfs layout\n"); + log_err("unknown sysfs layout\n"); return; } sprintf(foo, "%s", p); -- 2.25.1