Unify and fixup error handling
authorJens Axboe <jens.axboe@oracle.com>
Sun, 18 Feb 2007 06:47:14 +0000 (07:47 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Sun, 18 Feb 2007 06:47:14 +0000 (07:47 +0100)
First step in getting ->queue() and ->getevents() handled in
a more sane fashion.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
engines/libaio.c
engines/net.c
engines/sg.c
engines/splice.c
engines/sync.c
fio.c

index ba8c49df6583ddf7051e215f9da46c968d3b34aa..cb488efb1b5acbbd524bbc25914f40b86ea772e7 100644 (file)
@@ -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;
index 4f070f959d99b36ef1d3bf000c4f1a65155f4d24..381c731c9bf3892c9261aabcb45bf0d5812f21a2 100644 (file)
@@ -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;
index 27139760ba5bd14354c0e8a6e8c5bec666938463..f955c20a74ca770f3a69b6d06361e0ca0cb3c485 100644 (file)
@@ -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;
        }
 
index f55e5c0703273357781f4af7e548ba2be629d94a..5c4411cce3bcdfdecdfe3f40a5b2e0d3530fd66a 100644 (file)
@@ -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;
index 6a5b7d391ed206a465f8b2d1cbd7fcf550305c8f..5cf73662ad6dcc9f1e9893f12e34a3669d6e5124 100644 (file)
@@ -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 eb857afc690f4d794dfcbfa74f42b61d2986e0b9..3e55f92b31f49199f444ac62c5ce87890c7d85f6 100644 (file)
--- 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;