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 2ada2fb5c [cgroups2] Allow cgroups2::enable() to take in a set.
2ada2fb5c is described below

commit 2ada2fb5cf4d5563f169a6fd8e629ce079a05a4c
Author: None <None>
AuthorDate: Tue May 21 00:30:06 2024 -0400

    [cgroups2] Allow cgroups2::enable() to take in a set.
    
    Modifies the cgroups2::controllers::enable function to take in a set of
    strings for controllers. This helps eliminate the possibility of duplicate
    controllers in the argument, and brings it in line with the
    cgroups2::controllers::disable function
    
    Review: https://reviews.apache.org/r/74981/
---
 src/linux/cgroups2.cpp                     | 4 ++--
 src/linux/cgroups2.hpp                     | 2 +-
 src/slave/main.cpp                         | 6 +++++-
 src/tests/containerizer/cgroups2_tests.cpp | 2 +-
 src/tests/mesos.cpp                        | 5 +++--
 5 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/linux/cgroups2.cpp b/src/linux/cgroups2.cpp
index e9845bb56..9e2ca2207 100644
--- a/src/linux/cgroups2.cpp
+++ b/src/linux/cgroups2.cpp
@@ -128,7 +128,7 @@ struct State
 
   // We don't return errors here because enabling something
   // unknown will fail when writing it back out.
-  void enable(const vector<string>& controllers)
+  void enable(const set<string>& controllers)
   {
     foreach (const string& controller, controllers) {
       enable(controller);
@@ -591,7 +591,7 @@ Try<set<string>> available(const string& cgroup)
 }
 
 
-Try<Nothing> enable(const string& cgroup, const vector<string>& controllers)
+Try<Nothing> enable(const string& cgroup, const set<string>& controllers)
 {
   using State = control::subtree_control::State;
   Try<State> control = cgroups2::control::subtree_control::read(cgroup);
diff --git a/src/linux/cgroups2.hpp b/src/linux/cgroups2.hpp
index 97260c0d6..64254d04f 100644
--- a/src/linux/cgroups2.hpp
+++ b/src/linux/cgroups2.hpp
@@ -119,7 +119,7 @@ Try<std::set<std::string>> available(const std::string& 
cgroup);
 // controllers. Errors if a requested controller is not available.
 Try<Nothing> enable(
     const std::string& cgroup,
-    const std::vector<std::string>& controllers);
+    const std::set<std::string>& controllers);
 
 
 // Disables controllers in the cgroup. No-op if the controller is not enabled.
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index f4e7f3b64..8a0e161ff 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -276,8 +276,12 @@ static Try<Nothing> initializeCgroups2(const slave::Flags& 
flags)
   const vector<string> requestedControllers = strings::tokenize(
       *flags.agent_subsystems, ",");
 
+  const set<string> requestedControllersSet(
+      requestedControllers.begin(), requestedControllers.end());
+
+
   Try<Nothing> enable = cgroups2::controllers::enable(
-      cgroups2::ROOT_CGROUP, requestedControllers);
+      cgroups2::ROOT_CGROUP, requestedControllersSet);
   if (enable.isError()) {
     return Error("Failed to enable the requested cgroup v2 controllers: "
                  + enable.error());
diff --git a/src/tests/containerizer/cgroups2_tests.cpp 
b/src/tests/containerizer/cgroups2_tests.cpp
index e36f99b64..cb1e229f7 100644
--- a/src/tests/containerizer/cgroups2_tests.cpp
+++ b/src/tests/containerizer/cgroups2_tests.cpp
@@ -79,7 +79,7 @@ protected:
 
     Try<Nothing> result = cgroups2::controllers::enable(
         cgroups2::ROOT_CGROUP,
-        vector<string>(to_enable.begin(), to_enable.end()));
+        to_enable);
 
     if (result.isSome()) {
       enabled_controllers = enabled_controllers | to_enable;
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index ffbb30b95..d33c7b477 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -806,8 +806,9 @@ void 
ContainerizerTest<slave::MesosContainerizer>::SetUpCgroupsV2()
       cgroups2::ROOT_CGROUP);
   ASSERT_SOME(_controllers);
   subsystems = *_controllers;
-  vector<string> controllers(std::make_move_iterator(_controllers->begin()),
-                             std::make_move_iterator(_controllers->end()));
+  set<string> controllers(
+      std::make_move_iterator(_controllers->begin()),
+      std::make_move_iterator(_controllers->end()));
 
   // Enable all of the controllers inside of the test root cgroup so they
   // are accessible from the child container cgroups.

Reply via email to