From: Ian Jackson Subject: [PATCH] tapaio check return value from read() Date: Fri, 21 Dec 2007 16:17:25 +0000 Message-ID: <18283.59157.414731.885916@mariner.uk.xensource.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="OSW0SImveJ" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --OSW0SImveJ Content-Type: text/plain; charset=us-ascii Content-Description: message body text Content-Transfer-Encoding: 7bit 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. Ian. Signed-off-by: Ian Jackson --OSW0SImveJ Content-Type: text/plain Content-Description: tap_aio_get_events read() error check Content-Disposition: inline; filename="xen-tapaio-errorhandling.patch" Content-Transfer-Encoding: 7bit diff -r 9d447ba0c99a tools/blktap/drivers/tapaio.c --- a/tools/blktap/drivers/tapaio.c Wed Dec 19 10:11:54 2007 +0000 +++ b/tools/blktap/drivers/tapaio.c Wed Dec 19 15:09:59 2007 +0000 @@ -30,6 +30,8 @@ #include "tapaio.h" #include "tapdisk.h" #include +#include +#include /** * 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 *ct 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; } --OSW0SImveJ Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --OSW0SImveJ--