[stgt] [PATCH 8/8] when using eventfd, each time the fd becomes readable, the number of io completions can be read; this number is provided as a 64-bit integer, thus enough space (at least 8 bytes) should be given to read(). This patch adds a comment which explicitely states the above requirement. The actual number of completions in bs_aio is limited by a very small value, thus when reading, a 64-bit variable should be used, then it can be casted to unsigned int and processed as such.

nezhinsky at gmail.com nezhinsky at gmail.com
Wed Apr 25 16:52:21 CEST 2012


From: Alexander Nezhinsky <alexandern at mellanox.com>


Signed-off-by: Alexander Nezhinsky <alexandern at mellanox.com>
---
 usr/bs_aio.c |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/usr/bs_aio.c b/usr/bs_aio.c
index cbd91ba..f8bcf38 100644
--- a/usr/bs_aio.c
+++ b/usr/bs_aio.c
@@ -260,10 +260,13 @@ static void bs_aio_get_completions(int fd, int events, void *data)
 {
 	struct bs_aio_info *info = data;
 	int i, ret;
-	uint64_t ncomplete, nevents;
+	/* read from eventfd returns 8-byte int, fails with the error EINVAL
+	   if the size of the supplied buffer is less than 8 bytes */
+	uint64_t evts_complete;
+	unsigned int ncomplete, nevents;
 
 retry_read:
-	ret = read(info->evt_fd, &ncomplete, sizeof(ncomplete));
+	ret = read(info->evt_fd, &evts_complete, sizeof(evts_complete));
 	if (unlikely(ret < 0)) {
 		eprintf("failed to read AIO completions, %m\n");
 		if (errno == EAGAIN || errno == EINTR)
@@ -271,9 +274,10 @@ retry_read:
 
 		return;
 	}
+	ncomplete = (unsigned int) evts_complete;
 
 	while (ncomplete) {
-		nevents = min_t(long, ncomplete, ARRAY_SIZE(info->io_evts));
+		nevents = min_t(unsigned int, ncomplete, ARRAY_SIZE(info->io_evts));
 retry_getevts:
 		ret = io_getevents(info->ctx, 1, nevents, info->io_evts, NULL);
 		if (likely(ret > 0)) {
@@ -285,7 +289,7 @@ retry_getevts:
 			eprintf("io_getevents failed, err:%d\n", -ret);
 			return;
 		}
-		dprintf("got %ld ioevents out of %ld, pending %d\n",
+		dprintf("got %d ioevents out of %d, pending %d\n",
 			nevents, ncomplete, info->npending);
 
 		for (i = 0; i < nevents; i++)
-- 
1.7.9.6

--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list