[PATCH] When logging to a file, stderr should go both to stderr and file
authorJens Axboe <axboe@suse.de>
Thu, 8 Jun 2006 19:48:46 +0000 (21:48 +0200)
committerJens Axboe <axboe@suse.de>
Thu, 8 Jun 2006 19:48:46 +0000 (21:48 +0200)
fio.c
fio.h
init.c
ioengines.c
log.c
stat.c

diff --git a/fio.c b/fio.c
index c95d7b57deb4ad903ae84d34849fc19bb26f4378..b452c5f03b3934b8b0e40198df525980578735bc 100644 (file)
--- 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) {
        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;
        }
 
                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))) {
        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;
                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 {
        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;
        }
 
                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 {
        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;
        }
 }
                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
        } 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;
 }
 
        td->orig_buffer = NULL;
 }
@@ -952,7 +952,7 @@ static int create_file(struct thread_data *td, unsigned long long size,
                return 0;
 
        if (!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;
        }
                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) {
                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) {
                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;
        }
                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)) {
 
        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;
                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:
                        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;
        }
 
        run_str[td->thread_number - 1] = c;
@@ -1826,7 +1826,7 @@ static void run_threads(void)
                }
 
                if (left) {
                }
 
                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)
                        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) {
                return 1;
 
        if (!thread_number) {
-               fprintf(f_err, "Nothing to do\n");
+               log_err("Nothing to do\n");
                return 1;
        }
 
                return 1;
        }
 
diff --git a/fio.h b/fio.h
index f6c2ee3bd81cd149b7f8da4866e48c32750765b7..2d57227c53cf13a68d15131d55e23376308d9295 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -441,4 +441,13 @@ static inline void fio_sem_up(volatile int volatile *sem)
        (*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
 #endif
diff --git a/init.c b/init.c
index b40437afa84fab9aaaeac099e37088246ce2bcd5..6bf338532d6b528714274f7b243932b5459276cb 100644 (file)
--- 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) {
 
 #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) {
                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
                return 1;
        }
 #endif
@@ -495,7 +495,7 @@ static int str_rw_cb(struct thread_data *td, char *mem)
                return 0;
        }
 
                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;
 }
 
        return 1;
 }
 
@@ -512,7 +512,7 @@ static int str_verify_cb(struct thread_data *td, char *mem)
                return 0;
        }
 
                return 0;
        }
 
-       fprintf(f_err, "fio: verify types: md5, crc32\n");
+       log_err("fio: verify types: md5, crc32\n");
        return 1;
 }
 
        return 1;
 }
 
@@ -529,7 +529,7 @@ static int str_mem_cb(struct thread_data *td, char *mem)
                return 0;
        }
 
                return 0;
        }
 
-       fprintf(f_err, "fio: mem type: malloc, shm, mmap\n");
+       log_err("fio: mem type: malloc, shm, mmap\n");
        return 1;
 }
 
        return 1;
 }
 
@@ -562,7 +562,7 @@ static int str_ioengine_cb(struct thread_data *td, char *str)
                return 0;
        }
 
                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;
 }
 
        return 1;
 }
 
@@ -620,7 +620,7 @@ int parse_jobs_ini(char *file)
 
                        if (!check_int(p, "prio", &prio)) {
 #ifndef FIO_HAVE_IOPRIO
 
                        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
                                ret = 1;
                                break;
 #endif
@@ -630,7 +630,7 @@ int parse_jobs_ini(char *file)
                        }
                        if (!check_int(p, "prioclass", &prioclass)) {
 #ifndef FIO_HAVE_IOPRIO
                        }
                        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
                                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
                        }
                        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
                                ret = 1;
                                break;
 #endif
@@ -835,7 +835,7 @@ int parse_jobs_ini(char *file)
                        }
                        if (!check_strstore(p, "iolog", tmpbuf)) {
                                if (td->write_iolog) {
                        }
                        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;
                                }
                                        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
                                        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;
                        }
                                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
                        }
                        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
                                ret = 1;
                                break;
 #else
@@ -1076,7 +1076,7 @@ int parse_options(int argc, char *argv[])
        parse_cmd_line(argc, argv);
 
        if (!ini_file) {
        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;
        }
                usage(argv[0]);
                return 1;
        }
index c94fcb30c23b87ccea185b88c642081864017111..fe6136f775ad206fd59bd1fedee34345624d769c 100644 (file)
@@ -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)) {
        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;
        }
 
                return EINVAL;
        }
 
@@ -718,7 +718,7 @@ int fio_sgio_init(struct thread_data *td)
                if (ret)
                        return ret;
        } else {
                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;
        }
 
                return 1;
        }
 
diff --git a/log.c b/log.c
index a364e220919eb3ee23185fb128a9de80908884cf..4c7742b28fcde79529a5b405f6c16701054430ec 100644 (file)
--- 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) {
                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)
                        continue;
                }
                if (rw == DDIR_READ)
@@ -130,7 +130,7 @@ int init_iolog(struct thread_data *td)
                else if (rw == DDIR_WRITE)
                        writes++;
                else {
                else if (rw == DDIR_WRITE)
                        writes++;
                else {
-                       fprintf(f_err, "bad ddir: %d\n", rw);
+                       log_err("bad ddir: %d\n", rw);
                        continue;
                }
 
                        continue;
                }
 
@@ -169,7 +169,7 @@ int setup_rate(struct thread_data *td)
                return 0;
 
        if (td->rate < td->ratemin) {
                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;
        }
 
                return -1;
        }
 
diff --git a/stat.c b/stat.c
index cfd27ce79104dc2678e9f80680e76a46006bce27..d70c5ca9c7bcf78baeb9c591da10d6f88e10dc02 100644 (file)
--- 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)) {
                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);
                        return;
                }
                sprintf(foo, "%s", p);