Skip to contentSkip to conversation

aio-posix: Don't use epoll if epoll_create1 not available

PATCH In review Fam Zheng 2 participants 2 messages Feb 23, 2016

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH 1/1 aio-posix: Don't use epoll if epoll_create1 not available

---
 aio-posix.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
aio-posix.c +5 -3
index fa7f8ab..97e5a0c 100644
@@ -18,7 +18,9 @@
 #include "block/block.h"
 #include "qemu/queue.h"
 #include "qemu/sockets.h"
-#ifdef CONFIG_EPOLL
+
+#if defined(CONFIG_EPOLL) && defined(CONFIG_EPOLL_CREATE1)
+#define USE_EPOLL 1
 #include <sys/epoll.h>
 #endif
 
@@ -33,7 +35,7 @@ struct AioHandler
     QLIST_ENTRY(AioHandler) node;
 };
 
-#ifdef CONFIG_EPOLL
+#ifdef USE_EPOLL
 
 /* The fd number threashold to switch to epoll */
 #define EPOLL_ENABLE_THRESHOLD 64
@@ -483,7 +485,7 @@ bool aio_poll(AioContext *ctx, bool blocking)
 
 void aio_context_setup(AioContext *ctx, Error **errp)
 {
-#ifdef CONFIG_EPOLL
+#ifdef USE_EPOLL
     assert(!ctx->epollfd);
     ctx->epollfd = epoll_create1(EPOLL_CLOEXEC);
     if (ctx->epollfd == -1) {
Signature · 1 line
2.4.3
#1 lore raw
Quoted 11 lines · Fam Zheng
---
 aio-posix.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
aio-posix.c +0 -0
index fa7f8ab..97e5a0c 100644

aio-posix.c line 23

Quoted 7 lines
aio-posix.c +3 -1
@@ -18,7 +18,9 @@
 #include "block/block.h"
 #include "qemu/queue.h"
 #include "qemu/sockets.h"
-#ifdef CONFIG_EPOLL
+
+#if defined(CONFIG_EPOLL) && defined(CONFIG_EPOLL_CREATE1)
+#define USE_EPOLL 1

Other Linux syscalls with multiple versions for CLOEXEC support tend to be wrapped in util/osdep.c. When CLOEXEC isn't available they just skip it rather than manually adding the flag using fcntl(2).

The following function is added:

  int qemu_epoll_create(void)
  {
  #if defined(CONFIG_EPOLL_CREATE1)
      return epoll_create1(EPOLL_CLOEXEC);
  #elif defined(CONFIG_EPOLL)
      return epoll_create(1);
  #else
      return -ENOSYS;
  #endif
  }

Now the rest of QEMU can rely on just CONFIG_EPOLL.

Even if you don't want to add qemu_epoll_create(), please keep things simple by doing just s/CONFIG_EPOLL/CONFIG_EPOLL_CREATE1/ in aio-posix.c. That way USE_EPOLL isn't needed. It's confusing to have multiple preprocessor definitions related to epoll.