aboutsummaryrefslogtreecommitdiffstats
path: root/tools/blktap
diff options
context:
space:
mode:
authorKeir Fraser <keir.fraser@citrix.com>2007-12-27 12:28:58 +0000
committerKeir Fraser <keir.fraser@citrix.com>2007-12-27 12:28:58 +0000
commitfa7a56b7fa6b5c3eab8d08e605937b58e03cd1ac (patch)
treeed1e402eabbb767a93c7aafad3711b471a8e1adc /tools/blktap
parent819571016f4c308fadd16fb9a893441ac8d077b6 (diff)
downloadxen-fa7a56b7fa6b5c3eab8d08e605937b58e03cd1ac.tar.gz
xen-fa7a56b7fa6b5c3eab8d08e605937b58e03cd1ac.tar.bz2
xen-fa7a56b7fa6b5c3eab8d08e605937b58e03cd1ac.zip
tapaio check return value from read()
In tools/blktap/drivers/tapaio.c there is a call to read(2) whose return value is not checked. The attached patch attempts to do something vaguely sensible in cases of error. Fully comprehensive error handling in this area would be quite tough to introduce now but at least with this change when things go wrong you stand a chance of getting some information about what happened. Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/blktap')
-rw-r--r--tools/blktap/drivers/tapaio.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/tools/blktap/drivers/tapaio.c b/tools/blktap/drivers/tapaio.c
index ed15436457..a5c8bc74a0 100644
--- a/tools/blktap/drivers/tapaio.c
+++ b/tools/blktap/drivers/tapaio.c
@@ -30,6 +30,8 @@
#include "tapaio.h"
#include "tapdisk.h"
#include <unistd.h>
+#include <errno.h>
+#include <string.h>
/**
* We used a kernel patch to return an fd associated with the AIO context
@@ -149,8 +151,22 @@ tap_aio_get_events(tap_aio_context_t *ctx)
if (!ctx->poll_in_thread)
nr_events = io_getevents(ctx->aio_ctx, 1,
ctx->max_aio_events, ctx->aio_events, NULL);
- else
- read(ctx->completion_fd[0], &nr_events, sizeof(nr_events));
+ else {
+ int r;
+ r = read(ctx->completion_fd[0], &nr_events, sizeof(nr_events));
+ if (r < 0) {
+ if (errno == EAGAIN || errno == EINTR)
+ return 0;
+ /* This is pretty bad, we'll probably spin */
+ DPRINTF("Aargh, read completion_fd failed: %s",
+ strerror(errno));
+ } else if (r != sizeof(nr_events)) {
+ /* Should never happen because sizeof(nr_events)
+ * fits in the guaranteed atomic pipe write size.
+ * Blundering on is slightly nicer than asserting */
+ DPRINTF("Aargh, read completion_fd short read %d", r);
+ }
+ }
return nr_events;
}