[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mesos-commits
Subject:    (mesos) branch master updated: [cgroups2] Introduces cgroups2::exists to check if a cgroup exists.
From:       bmahler () apache ! org
Date:       2024-03-19 20:27:58
Message-ID: 171088007841.1029439.1682300466138839215 () gitbox2-he-fi ! apache ! org
[Download RAW message or body]

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 442a1397f [cgroups2] Introduces cgroups2::exists to check if a cgroup exists.
442a1397f is described below

commit 442a1397fa4872164806415c7f7cd80efd288070
Author: Devin Leamy <dleamy@twitter.com>
AuthorDate: Tue Mar 19 19:37:48 2024 +0000

    [cgroups2] Introduces cgroups2::exists to check if a cgroup exists.
    
    If you call `cgroups2::destroy` on a cgroup that does not exist, it
    will throw an error. This is expected. However, it means that the
    caller needs to know whether a cgroup exists. This PR introduces
    `cgroups2::exists`, allowing the caller find out if a cgroup exists.
    
    This is useful, for example, for test fixtures where cgroups
    from a previous run of a test may or may not be cleaned up, depending
    on whether or not the test was successful.
---
 src/linux/cgroups2.cpp | 13 +++++++++----
 src/linux/cgroups2.hpp |  4 ++++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/src/linux/cgroups2.cpp b/src/linux/cgroups2.cpp
index e5011e23c..e599c8c62 100644
--- a/src/linux/cgroups2.cpp
+++ b/src/linux/cgroups2.cpp
@@ -243,6 +243,12 @@ Try<Nothing> unmount()
 }
 
 
+bool exists(const string& cgroup)
+{
+  return os::exists(path::join(MOUNT_POINT, cgroup));
+}
+
+
 Try<Nothing> create(const string& cgroup, bool recursive)
 {
   const string absolutePath = path::join(MOUNT_POINT, cgroup);
@@ -259,12 +265,11 @@ Try<Nothing> create(const string& cgroup, bool recursive)
 
 Try<Nothing> destroy(const string& cgroup)
 {
-  const string absolutePath = path::join(MOUNT_POINT, cgroup);
-
-  if (!os::exists(absolutePath)) {
-    return Error("There does not exist a cgroup at '" + absolutePath + "'");
+  if (!cgroups2::exists(cgroup)) {
+    return Error("Cgroup '" + cgroup + "' does not exist");
   }
 
+  const string absolutePath = path::join(MOUNT_POINT, cgroup);
   Try<Nothing> rmdir = os::rmdir(absolutePath, false);
   if (rmdir.isError()) {
     return Error("Failed to remove directory '" + absolutePath + "': "
diff --git a/src/linux/cgroups2.hpp b/src/linux/cgroups2.hpp
index a1f0a66d5..35519cc60 100644
--- a/src/linux/cgroups2.hpp
+++ b/src/linux/cgroups2.hpp
@@ -50,6 +50,10 @@ Try<bool> mounted();
 Try<Nothing> unmount();
 
 
+// Check if a cgroup exists.
+bool exists(const std::string& cgroup);
+
+
 // Creates a cgroup off of the base hierarchy, i.e. /sys/fs/cgroup/<cgroup>.
 // cgroup can be a nested cgroup (e.g. foo/bar/baz). If cgroup is a nested
 // cgroup and the parent cgroups do not exist, an error will be returned unless

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic