WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] tapaio check return value from read()

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-unstable] tapaio check return value from read()
From: Xen patchbot-unstable <patchbot-unstable@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 27 Dec 2007 12:00:12 -0800
Delivery-date: Thu, 27 Dec 2007 12:00:19 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1198758538 0
# Node ID 003542d9ab7713ffcecb7a91a2639083b7da4af5
# Parent  9fe92a88912b45c0c44184d7e3b16983bf5aed47
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@xxxxxxxxxxxxx>
---
 tools/blktap/drivers/tapaio.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff -r 9fe92a88912b -r 003542d9ab77 tools/blktap/drivers/tapaio.c
--- a/tools/blktap/drivers/tapaio.c     Thu Dec 27 12:27:34 2007 +0000
+++ b/tools/blktap/drivers/tapaio.c     Thu Dec 27 12:28:58 2007 +0000
@@ -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 *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;
 }

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] tapaio check return value from read(), Xen patchbot-unstable <=