This is an automated email from the ASF dual-hosted git repository.

bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git


The following commit(s) were added to refs/heads/master by this push:
     new 7996677c4 [cgroups2] Add enabled() to check if cgroups2 is available 
on the host.
7996677c4 is described below

commit 7996677c43b6f215de6069db1402180c1c4efbd9
Author: Devin Leamy <[email protected]>
AuthorDate: Mon Feb 26 14:27:23 2024 -0500

    [cgroups2] Add enabled() to check if cgroups2 is available on the host.
    
    Introduces the cgroups2 namespace and enabled() function to check if
    cgroups2 is supported by the host. To be supported:
      1. The cgroup2 file system type must be supported.
      2. The host must be a linux machine.
    
    Review: https://reviews.apache.org/r/74870/
---
 src/linux/cgroups2.cpp | 19 +++++++++++++++++++
 src/linux/cgroups2.hpp |  7 +++++++
 2 files changed, 26 insertions(+)

diff --git a/src/linux/cgroups2.cpp b/src/linux/cgroups2.cpp
index 2b9ae0318..6beb8dd2c 100644
--- a/src/linux/cgroups2.cpp
+++ b/src/linux/cgroups2.cpp
@@ -14,4 +14,23 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
+#include <string>
+
+#include <stout/try.hpp>
+
 #include "linux/cgroups2.hpp"
+#include "linux/fs.hpp"
+
+using std::string;
+
+namespace cgroups2 {
+
+// Name of the cgroupv2 filesystem as found in /proc/filesystems.
+const string FILE_SYSTEM = "cgroup2";
+
+bool enabled() {
+  Try<bool> supported = mesos::internal::fs::supported(cgroups2::FILE_SYSTEM);
+  return supported.isSome() && *supported;
+}
+
+} // namespace cgroups2
diff --git a/src/linux/cgroups2.hpp b/src/linux/cgroups2.hpp
index ab1e4be3c..833960d30 100644
--- a/src/linux/cgroups2.hpp
+++ b/src/linux/cgroups2.hpp
@@ -17,4 +17,11 @@
 #ifndef __CGROUPS_V2_HPP__
 #define __CGROUPS_V2_HPP__
 
+namespace cgroups2 {
+
+// Checks if cgroups2 is available on the system.
+bool enabled();
+
+} // namespace cgroups2
+
 #endif // __CGROUPS_V2_HPP__
\ No newline at end of file

Reply via email to