From 22819ec237297fc39435ed566bee01a4225bfb39 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Sun, 18 Feb 2007 07:47:14 +0100 Subject: [PATCH] Unify and fixup error handling First step in getting ->queue() and ->getevents() handled in a more sane fashion. Signed-off-by: Jens Axboe --- engines/libaio.c | 7 ++----- engines/net.c | 2 +- engines/sg.c | 10 +++++----- engines/splice.c | 2 +- engines/sync.c | 2 +- fio.c | 13 +++++++------ 6 files changed, 17 insertions(+), 19 deletions(-) diff --git a/engines/libaio.c b/engines/libaio.c index ba8c49df..cb488efb 100644 --- a/engines/libaio.c +++ b/engines/libaio.c @@ -62,10 +62,7 @@ static int fio_libaio_getevents(struct thread_data *td, int min, int max, break; } while (1); - if (r < 0) - r = -r; - - return (int) r; + return r; } static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u) @@ -91,7 +88,7 @@ static int fio_libaio_queue(struct thread_data *td, struct io_u *io_u) * requests to flush first. */ if (fsync(io_u->file->fd) < 0) - ret = errno; + ret = -errno; else ret = FIO_Q_COMPLETED; break; diff --git a/engines/net.c b/engines/net.c index 4f070f95..381c731c 100644 --- a/engines/net.c +++ b/engines/net.c @@ -63,7 +63,7 @@ static int fio_netio_queue(struct thread_data *td, struct io_u *io_u) ret = 0; /* must be a SYNC */ if (ret != (int) io_u->xfer_buflen) { - if (ret > 0) { + if (ret >= 0) { io_u->resid = io_u->xfer_buflen - ret; io_u->error = 0; return FIO_Q_COMPLETED; diff --git a/engines/sg.c b/engines/sg.c index 27139760..f955c20a 100644 --- a/engines/sg.c +++ b/engines/sg.c @@ -95,9 +95,9 @@ static int fio_sgio_getevents(struct thread_data *td, int min, int max, ret = poll(sd->pfds, td->nr_files, -1); if (ret < 0) { - td_verror(td, errno); if (!r) - r = -1; + r = -errno; + td_verror(td, errno); break; } else if (!ret) continue; @@ -117,8 +117,8 @@ re_read: if (ret < 0) { if (errno == EAGAIN) continue; + r = -errno; td_verror(td, errno); - r = -1; break; } else if (ret) { p += ret; @@ -162,7 +162,7 @@ static int fio_sgio_ioctl_doio(struct thread_data *td, ret = ioctl(f->fd, SG_IO, hdr); if (ret < 0) - return ret; + return -errno; return FIO_Q_COMPLETED; } @@ -179,7 +179,7 @@ static int fio_sgio_rw_doio(struct fio_file *f, struct io_u *io_u, int sync) if (sync) { ret = read(f->fd, hdr, sizeof(*hdr)); if (ret < 0) - return errno; + return -errno; return FIO_Q_COMPLETED; } diff --git a/engines/splice.c b/engines/splice.c index f55e5c07..5c4411cc 100644 --- a/engines/splice.c +++ b/engines/splice.c @@ -116,7 +116,7 @@ static int fio_spliceio_queue(struct thread_data *td, struct io_u *io_u) ret = fsync(io_u->file->fd); if (ret != (int) io_u->xfer_buflen) { - if (ret > 0) { + if (ret >= 0) { io_u->resid = io_u->xfer_buflen - ret; io_u->error = 0; return FIO_Q_COMPLETED; diff --git a/engines/sync.c b/engines/sync.c index 6a5b7d39..5cf73662 100644 --- a/engines/sync.c +++ b/engines/sync.c @@ -41,7 +41,7 @@ static int fio_syncio_queue(struct thread_data *td, struct io_u *io_u) ret = fsync(f->fd); if (ret != (int) io_u->xfer_buflen) { - if (ret > 0) { + if (ret >= 0) { io_u->resid = io_u->xfer_buflen - ret; io_u->error = 0; return FIO_Q_COMPLETED; diff --git a/fio.c b/fio.c index eb857afc..3e55f92b 100644 --- a/fio.c +++ b/fio.c @@ -229,7 +229,7 @@ static int fio_io_sync(struct thread_data *td, struct fio_file *f) } else if (ret == FIO_Q_QUEUED) { ret = td_io_getevents(td, 1, td->cur_depth, NULL); if (ret < 0) { - td_verror(td, ret); + td_verror(td, -ret); return 1; } @@ -298,7 +298,7 @@ requeue: switch (ret) { case FIO_Q_COMPLETED: if (io_u->error) - ret = io_u->error; + ret = -io_u->error; if (io_u->xfer_buflen != io_u->resid && io_u->resid) { int bytes = io_u->xfer_buflen - io_u->resid; @@ -318,7 +318,7 @@ requeue: break; default: assert(ret < 0); - td_verror(td, ret); + td_verror(td, -ret); break; } @@ -346,9 +346,10 @@ requeue: * verification on them through the callback handler */ ret = td_io_getevents(td, min_events, td->cur_depth, timeout); - if (ret < 0) + if (ret < 0) { + td_verror(td, -ret); break; - else if (!ret) + } else if (!ret) continue; init_icd(&icd, verify_io_u, ret); @@ -473,7 +474,7 @@ requeue: ret = td_io_getevents(td, min_evts, td->cur_depth, timeout); if (ret < 0) { - td_verror(td, ret); + td_verror(td, -ret); break; } else if (!ret) continue; -- 2.25.1