X-Git-Url: https://git.kernel.dk/?a=blobdiff_plain;f=fio.c;h=774b160c969337b2ad28b8c852479d4cf6e2f0ae;hb=fab6aa719b7fa80a720f716dc1660165c2f844e9;hp=10625f26afd25fd54d72bb896a17c075f0681401;hpb=24868cabfee01b938a708337ac2087470490b665;p=fio.git diff --git a/fio.c b/fio.c index 10625f26..774b160c 100644 --- a/fio.c +++ b/fio.c @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -46,6 +47,7 @@ int temp_stall_ts; static volatile int startup_sem; static volatile int fio_abort; +static int exit_value; struct io_log *agg_io_log[2]; @@ -381,7 +383,7 @@ static void do_io(struct thread_data *td) td_set_runstate(td, TD_RUNNING); - while (td->this_io_bytes[td->ddir] < td->io_size) { + while ((td->this_io_bytes[0] + td->this_io_bytes[1]) < td->io_size) { struct timespec *timeout; int min_evts = 0; struct io_u *io_u; @@ -398,7 +400,6 @@ static void do_io(struct thread_data *td) break; memcpy(&s, &io_u->start_time, sizeof(s)); - requeue: ret = td_io_queue(td, io_u); if (ret) { @@ -411,7 +412,6 @@ requeue: io_u->xfer_buf += ret; goto requeue; } else { - td_verror(td, io_u->error); put_io_u(td, io_u); break; } @@ -755,33 +755,36 @@ static void *thread_main(void *data) terminate_threads(td->groupid, 0); err: + if (td->error) + printf("fio: pid=%d, err=%d/%s\n", td->pid, td->error, td->verror); close_files(td); close_ioengine(td); cleanup_io_u(td); td_set_runstate(td, TD_EXITED); - return NULL; - + return (void *) td->error; } /* * We cannot pass the td data into a forked process, so attach the td and * pass it to the thread worker. */ -static void *fork_main(int shmid, int offset) +static int fork_main(int shmid, int offset) { struct thread_data *td; - void *data; + void *data, *ret; data = shmat(shmid, NULL, 0); if (data == (void *) -1) { + int __err = errno; + perror("shmat"); - return NULL; + return __err; } td = data + offset * sizeof(struct thread_data); - thread_main(td); + ret = thread_main(td); shmdt(data); - return NULL; + return (int) ret; } /* @@ -790,7 +793,7 @@ static void *fork_main(int shmid, int offset) static void reap_threads(int *nr_running, int *t_rate, int *m_rate) { struct thread_data *td; - int i, cputhreads, pending; + int i, cputhreads, pending, status, ret; /* * reap exited threads (TD_EXITED -> TD_REAPED) @@ -804,6 +807,22 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate) if (td->io_ops && td->io_ops->flags & FIO_CPUIO) cputhreads++; + if (td->runstate < TD_EXITED) { + /* + * check if someone quit or got killed in an unusual way + */ + ret = waitpid(td->pid, &status, WNOHANG); + if (ret < 0) + perror("waitpid"); + else if ((ret == td->pid) && WIFSIGNALED(status)) { + int sig = WTERMSIG(status); + + log_err("fio: pid=%d, got signal=%d\n", td->pid, sig); + td_set_runstate(td, TD_REAPED); + goto reaped; + } + } + if (td->runstate != TD_EXITED) { if (td->runstate < TD_RUNNING) pending++; @@ -811,6 +830,9 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate) continue; } + if (td->error) + exit_value++; + td_set_runstate(td, TD_REAPED); if (td->use_thread) { @@ -818,9 +840,19 @@ static void reap_threads(int *nr_running, int *t_rate, int *m_rate) if (pthread_join(td->thread, (void *) &ret)) perror("thread_join"); - } else - waitpid(td->pid, NULL, 0); + } else { + int status; + + ret = waitpid(td->pid, &status, 0); + if (ret < 0) + perror("waitpid"); + if (WIFEXITED(status) && WEXITSTATUS(status)) { + if (!exit_value) + exit_value++; + } + } +reaped: (*nr_running)--; (*m_rate) -= td->ratemin; (*t_rate) -= td->rate; @@ -869,6 +901,9 @@ static void run_threads(void) * client data interspersed on disk */ if (setup_files(td)) { + exit_value++; + if (td->error) + log_err("fio: pid=%d, err=%d/%s\n", td->pid, td->error, td->verror); td_set_runstate(td, TD_REAPED); todo--; } @@ -925,8 +960,9 @@ static void run_threads(void) if (fork()) fio_sem_down(&startup_sem); else { - fork_main(shm_id, i); - exit(0); + int ret = fork_main(shm_id, i); + + exit(ret); } } } @@ -1005,6 +1041,13 @@ int main(int argc, char *argv[]) { long ps; + /* + * We need locale for number printing, if it isn't set then just + * go with the US format. + */ + if (!getenv("LC_NUMERIC")) + setlocale(LC_NUMERIC, "en_US"); + if (parse_options(argc, argv)) return 1; @@ -1038,5 +1081,5 @@ int main(int argc, char *argv[]) } } - return 0; + return exit_value; }