Skip to content

Commit 438ba33

Browse files
authored
Merge pull request #8588 from sfayer/fix_cgroup2path
[int] Find writable cgroup2 in tree
2 parents 330a838 + 58d0a9d commit 438ba33

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

src/DIRAC/Core/Utilities/CGroups2.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
import functools
66
import subprocess
7+
from pathlib import Path
78
from DIRAC import S_OK, S_ERROR, gLogger
89
from DIRAC.Core.Utilities.DIRACSingleton import DIRACSingleton
910
from DIRAC.Core.Utilities import Subprocess
@@ -102,11 +103,29 @@ def filt(line):
102103
return line[4:]
103104
return False
104105

105-
if not (root_path := self._detect_root()):
106+
if not (root_name := self._detect_root()):
106107
raise RuntimeError("Failed to find cgroup mount point")
107108
if not (cur_group := self._filter_file(self.FILE_CUR_CGROUP, filt)):
108109
raise RuntimeError("Failed to find current cgroup")
109-
self._cgroup_path = os.path.join(root_path, cur_group)
110+
root_path = Path(root_name)
111+
search_path = root_path / cur_group
112+
# Work up from the search path until we find a writable directory
113+
num = 0
114+
while search_path.is_relative_to(root_path):
115+
num += 1
116+
if num > 10:
117+
# We've tried 10 levels of tree! There might be an oddity here
118+
# where we're stuck in a loop (perhaps we somehow got all the
119+
# way up to "/" and are just looping on that?)
120+
raise RuntimeError("Writeable cgroup search exceeded limit")
121+
if os.access(search_path, os.W_OK):
122+
# We found an entry in the tree that we can write to
123+
self._cgroup_path = str(search_path)
124+
return
125+
search_path = search_path.parent
126+
# We've now left the cgroup mount point and didn't find a writeable dir
127+
# There probably isn't any delegation enabled
128+
raise RuntimeError("Failed to find a writeable cgroup")
110129

111130
def _create_group(self, group_name, isolate_oom=True):
112131
"""Creates a new group.

0 commit comments

Comments
 (0)