[PATCH] xfstests: fix async io error handling in fsx
Felix Blyakher
felixb at sgi.com
Mon Mar 30 00:30:50 CDT 2009
The result of async io returned in the event.res in addition to
the number of bytes read/written provides negated error
number. The broken libaio defines event.res as unsigned
while the same structure in ithe kernel defines it as signed.
The kernel indeed treat it as signed, and returns the
negated error number. Till libaio is fixed we provide
the signed long temp var.
Also set errno for each error condition in aio_rw, as the
caller is not aio aware and expects ret(-1)+errno by the
traditional libc convention.
Signed-off-by: Felix Blyakher <felixb at sgi.com>
---
ltp/fsx.c | 34 ++++++++++++++++++++++++++++------
1 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/ltp/fsx.c b/ltp/fsx.c
index ebe5324..81402be 100644
--- a/ltp/fsx.c
+++ b/ltp/fsx.c
@@ -976,19 +976,41 @@ __aio_rw(int rw, int fd, char *buf, unsigned len, unsigned offset)
fprintf(stderr, "errcode=%d\n", ret);
fprintf(stderr, "aio_rw: io_submit failed: %s\n",
strerror(ret));
- return(-1);
+ errno = -ret;
+ return -1;
}
ret = io_getevents(io_ctx, 1, 1, &event, &ts);
if (ret != 1) {
- fprintf(stderr, "errcode=%d\n", ret);
- fprintf(stderr, "aio_rw: io_getevents failed: %s\n",
- strerror(ret));
+ if (ret == 0)
+ fprintf(stderr, "aio_rw: no events available\n");
+ else {
+ fprintf(stderr, "errcode=%d\n", -ret);
+ fprintf(stderr, "aio_rw: io_getevents failed: %s\n",
+ strerror(-ret));
+ }
+ errno = -ret;
return -1;
}
if (len != event.res) {
- fprintf(stderr, "bad read length: %lu instead of %u\n",
- event.res, len);
+ /*
+ * The b0rked libaio defines event.res as signed.
+ * However the kernel strucuture has it unsigned,
+ * and it's used to pass negated error value.
+ * Till the library is fixed use the temp var.
+ */
+ long res = (long)event.res;
+ if (res >= 0)
+ fprintf(stderr, "bad io length: %lu instead of %u\n",
+ res, len);
+ else {
+ fprintf(stderr, "errcode=%d\n", -res);
+ fprintf(stderr, "aio_rw: async io failed: %s\n",
+ strerror(-res));
+ errno = -res;
+ return -1;
+ }
+
}
return event.res;
}
--
1.5.4.rc3
More information about the xfs
mailing list