You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2011/10/25 08:16:14 UTC

svn commit: r1188525 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/platform/linux/ControlGroups.java native/Makefile.unx.in native/configure native/os/linux/cgroup.c

Author: mturk
Date: Tue Oct 25 06:16:13 2011
New Revision: 1188525

URL: http://svn.apache.org/viewvc?rev=1188525&view=rev
Log:
Add initial stub for Linux ControlGroups

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/ControlGroups.java   (with props)
    commons/sandbox/runtime/trunk/src/main/native/os/linux/cgroup.c   (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/configure

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/ControlGroups.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/ControlGroups.java?rev=1188525&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/ControlGroups.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/ControlGroups.java Tue Oct 25 06:16:13 2011
@@ -0,0 +1,78 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime.platform.linux;
+
+import org.apache.commons.runtime.SystemException;
+import org.apache.commons.runtime.UnsupportedOperatingSystemException;
+
+/**
+ * Low level interface to Linux libcgroups.so.
+ */
+public class ControlGroups
+{
+
+    private ControlGroups()
+    {
+        // No instance
+    }
+    private static final String  SONAME = "libcgroup.so";
+    private static final Object  lock;
+    private static       boolean loaded = false;
+
+    static {
+        lock = new Object();
+        try {
+            if (enabled0()) {
+                loaded = load0(SONAME);
+            }
+
+        } catch (Exception e) {
+            // Ignore at startup
+        }
+    }
+    /*
+     * Return true if libaio if supported
+     * @param type OS type to test.
+     */
+    private static native boolean   load0(String soname)
+        throws SystemException;
+    private static native boolean   enabled0();
+        
+    /**
+     * Check if {@code Gontrol Groups} are supported.
+     *
+     * @return {@code true} if  {@code libcgroup} support is enabled.
+     * @throws OperatingSystemException if we have error
+     * @throws UnsupportedOperatingSystemException if not running on
+     *          {@code Linux} operating system.
+     */
+    public static boolean  isEnabled()
+        throws SystemException, UnsupportedOperatingSystemException
+    {
+        try {
+            synchronized(lock) {
+                if (enabled0())
+                    return loaded;
+                else
+                    return false;
+            }
+        } catch (UnsatisfiedLinkError e) {
+            throw new UnsupportedOperatingSystemException();
+        }
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/platform/linux/ControlGroups.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1188525&r1=1188524&r2=1188525&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Tue Oct 25 06:16:13 2011
@@ -96,6 +96,7 @@ HPUX_SOURCES=\
 	$(TOPDIR)/os/hpux/os.c
 LINUX_SOURCES=\
 	$(TOPDIR)/os/linux/aio.c \
+	$(TOPDIR)/os/linux/cgroup.c \
 	$(TOPDIR)/os/linux/epoll.c \
 	$(TOPDIR)/os/linux/misc.c \
 	$(TOPDIR)/os/linux/sendfile.c \

Modified: commons/sandbox/runtime/trunk/src/main/native/configure
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/configure?rev=1188525&r1=1188524&r2=1188525&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/configure (original)
+++ commons/sandbox/runtime/trunk/src/main/native/configure Tue Oct 25 06:16:13 2011
@@ -118,6 +118,7 @@ has_shared_version=no
 has_zlib_asm=yes
 has_openssl=no
 has_libaio_static=yes
+has_libcgroup_static=yes
 has_openssl_static=yes
 has_openssl_runtime=no
 openssl_home="$OPENSSL_HOME"
@@ -1223,6 +1224,7 @@ else
 fi
 
 have_libaio_static=0
+have_libcgroup_static=0
 if [ ".$host" = ".linux" ]; then
     have_libaio=`have_include libaio`
     if [ ".$have_libaio" = .1 ]; then
@@ -1231,8 +1233,16 @@ if [ ".$host" = ".linux" ]; then
             test ".$have_libaio_static" = .1 && varadds ldflags -laio
         fi
     fi
+    have_libcgroup=`have_include libcgroup`
+    if [ ".$have_libcgroup" = .1 ]; then
+        if [ ".$has_libcgroup_static" = .yes ]; then
+            have_libcgroup_static=`have_library cgroup`
+            test ".$have_libcgroup_static" = .1 && varadds ldflags -lcgroup
+        fi
+    fi
 else
     have_libaio=0
+    have_libcgroup=0
 fi
 
 have_posixsem=`have_sem_open`
@@ -1480,6 +1490,8 @@ extern "C" {
 
 #define HAVE_LIBAIO             $have_libaio
 #define HAVE_LIBAIO_STATIC      $have_libaio_static
+#define HAVE_LIBCGROUP          $have_libcgroup
+#define HAVE_LIBCGROUP_STATIC   $have_libcgroup_static
 #define HAVE_OPENSSL            $have_openssl
 #define HAVE_OPENSSL_STATIC     $have_openssl_static
 #define HAVE_FIPS               $have_fips

Added: commons/sandbox/runtime/trunk/src/main/native/os/linux/cgroup.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/linux/cgroup.c?rev=1188525&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/linux/cgroup.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/os/linux/cgroup.c Tue Oct 25 06:16:13 2011
@@ -0,0 +1,93 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "acr/jniapi.h"
+#include "acr/string.h"
+#include "arch_opts.h"
+
+#if HAVE_LIBCGROUP
+#include <libcgroup.h>
+
+#if !HAVE_LIBCGROUP_STATIC
+
+#define CGROUP_FPLOAD(fN)                                       \
+    fname  = #fN;                                               \
+    GRPapi.fp##fN = dlsym(libcgroupdso, fname);                 \
+    if (GRPapi.fp##fN == 0) goto failed
+
+#define CGROUP_NAME(fN) GRPapi.fp##fN
+#define CGROUP_CALL(fN) (*CGROUP_NAME(fN))
+
+struct GRPAPIst {
+    /* library wrappers */
+    int                 (*fpcgroup_init)(void);
+
+    void                (*fpNULL)(void);    
+};
+
+static struct GRPAPIst GRPapi;
+static void           *libcgroupdso = 0;
+
+ACR_OS_EXPORT(jboolean, linux, ControlGroups, load0)(JNI_STDARGS, jstring soname)
+{
+    const char *fname = "";
+
+    if (libcgroupdso != 0)
+        return  JNI_TRUE;
+    /* Must be synchronized! */
+    memset(&GRPapi, 0, sizeof(GRPapi));
+    WITH_CSTR(soname) {
+        if ((libcgroupdso = dlopen(J2S(soname), RTLD_NOW | RTLD_GLOBAL)) == 0)
+            ACR_THROW_SYS_ERRNO();
+    } DONE_WITH_STR(soname);
+    if (libcgroupdso == 0)
+        return  JNI_FALSE;
+    CGROUP_FPLOAD(cgroup_init);
+    
+    return JNI_TRUE;
+failed:
+    dlclose(libcgroupdso);
+    libcgroupdso = 0;
+    AcrThrowEx(env, ACR_EX_ENOENT, "Cannot find libcgroup::%s()", fname);
+    return JNI_TRUE;
+}
+
+int cgroup_init()
+{
+    return CGROUP_CALL(cgroup_init)();
+}
+
+#else
+ACR_OS_EXPORT(jboolean, linux, ControlGroups, load0)(JNI_STDARGS)
+{
+    return JNI_TRUE;
+}
+
+#endif /* HAVE_LIBCGROUP_STATIC */
+
+ACR_OS_EXPORT(jboolean, linux, ControlGroups, enabled0)(JNI_STDARGS)
+{
+    return JNI_TRUE;
+}
+
+
+#else /* HAVE_LIBCGROUP */
+ACR_OS_EXPORT(jboolean, linux, ControlGroups, enabled0)(JNI_STDARGS)
+{
+    return JNI_FALSE;
+}
+
+#endif

Propchange: commons/sandbox/runtime/trunk/src/main/native/os/linux/cgroup.c
------------------------------------------------------------------------------
    svn:eol-style = native