[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.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>


Signed-off-by: Alexander Nezhinsky <alexandern@xxxxxxxxxxxx>
---
 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@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux SCSI]     [Linux RAID]     [Linux Clusters]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]

  Powered by Linux