You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2012/08/07 05:21:50 UTC

svn commit: r1370104 - in /incubator/mesos/trunk/src: linux/cgroups.cpp tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh

Author: benh
Date: Tue Aug  7 03:21:50 2012
New Revision: 1370104

URL: http://svn.apache.org/viewvc?rev=1370104&view=rev
Log:
Fixed Linux incompatibility issue in eventfd code (contributed by Jie
Yu, https://reviews.apache.org/r/6423).

Modified:
    incubator/mesos/trunk/src/linux/cgroups.cpp
    incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh

Modified: incubator/mesos/trunk/src/linux/cgroups.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/linux/cgroups.cpp?rev=1370104&r1=1370103&r2=1370104&view=diff
==============================================================================
--- incubator/mesos/trunk/src/linux/cgroups.cpp (original)
+++ incubator/mesos/trunk/src/linux/cgroups.cpp Tue Aug  7 03:21:50 2012
@@ -24,11 +24,6 @@
 #include <sys/syscall.h>
 #include <sys/types.h>
 
-// For older versions of glibc we need to get O_CLOEXEC from
-// linux/fcntl.h, but on some versions that requires sys/types.h to be
-// included _first_.
-#include <linux/fcntl.h>
-
 #include <glog/logging.h>
 
 #include <fstream>
@@ -754,17 +749,48 @@ Try<bool> assignTask(const std::string& 
 
 namespace internal {
 
-#ifndef __NR_eventfd2
-#error "The eventfd2 syscall is unavailable."
-#endif
-
+#ifndef EFD_SEMAPHORE
 #define EFD_SEMAPHORE (1 << 0)
-#define EFD_CLOEXEC O_CLOEXEC
-#define EFD_NONBLOCK O_NONBLOCK
+#endif
+#ifndef EFD_CLOEXEC
+#define EFD_CLOEXEC 02000000
+#endif
+#ifndef EFD_NONBLOCK
+#define EFD_NONBLOCK 04000
+#endif
 
 static int eventfd(unsigned int initval, int flags)
 {
+#ifdef __NR_eventfd2
   return ::syscall(__NR_eventfd2, initval, flags);
+#elif defined(__NR_eventfd)
+  int fd = ::syscall(__NR_eventfd, initval);
+  if (fd == -1) {
+    return -1;
+  }
+
+  // Manually set CLOEXEC and NONBLOCK.
+  if ((flags & EFD_CLOEXEC) != 0) {
+    Try<bool> cloexec = os::cloexec(fd);
+    if (cloexec.isError()) {
+      os::close(fd);
+      return -1;
+    }
+  }
+
+  if ((flags & EFD_NONBLOCK) != 0) {
+    Try<bool> nonblock = os::nonblock(fd);
+    if (nonblock.isError()) {
+      os::close(fd);
+      return -1;
+    }
+  }
+
+  // Return the file descriptor.
+  return fd;
+#else
+#error "The eventfd syscall is not available."
+#endif
 }
 
 
@@ -788,7 +814,7 @@ static Try<int> openNotifier(const std::
                              const Option<std::string>& args =
                                Option<std::string>::none())
 {
-  int efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
+  int efd = internal::eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
   if (efd < 0) {
     return Try<int>::error(
         "Create eventfd failed: " + std::string(strerror(errno)));

Modified: incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh?rev=1370104&r1=1370103&r2=1370104&view=diff
==============================================================================
--- incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh (original)
+++ incubator/mesos/trunk/src/tests/external/CgroupsIsolation/ROOT_CGROUPS_BalloonFramework.sh Tue Aug  7 03:21:50 2012
@@ -26,6 +26,7 @@ fi
 $MESOS_BUILD_DIR/src/mesos-slave \
     --master=localhost:5432 \
     --isolation=cgroups \
+    --cgroups_hierarchy_root=/cgroups \
     --resources="cpus:1;mem:96" \
     > slave.log 2>&1 &
 SLAVE_PID=$!
@@ -57,6 +58,10 @@ echo "Killing master: $MASTER_PID"
 kill $MASTER_PID
 sleep 2
 
+# Cleanup the cgroups hierarchy root
+rmdir /cgroups/*
+umount /cgroups
+
 echo "Exiting"
 # Check whether balloon framework returned the right code
 if [[ $EXIT_CODE -eq 1 ]]; then