Skip to content

Commit 6779992

Browse files
committed
CA-405215: attach tapdisk pid to correct cgroup path
it works on both cgroup v1 and v2 Signed-off-by: Chunjie Zhu <chunjie.zhu@cloud.com>
1 parent 517cf37 commit 6779992

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

libs/sm/blktap2.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -758,14 +758,23 @@ def launch_from_arg(cls, arg):
758758

759759
@staticmethod
760760
def cgclassify(pid):
761-
762-
# We dont provide any <controllers>:<path>
763-
# so cgclassify uses /etc/cgrules.conf which
764-
# we have configured in the spec file.
765-
cmd = ["cgclassify", str(pid)]
766761
try:
767-
util.pread2(cmd)
768-
except util.CommandException as e:
762+
# We dont provide any <controllers>:<path>
763+
# so cgclassify uses /etc/cgrules.conf which
764+
# we have configured in the spec file.
765+
cmd = ["cgclassify", str(pid)]
766+
try:
767+
util.pread2(cmd)
768+
except util.CommandException as e:
769+
util.logException(e)
770+
# cgroup-v2 path
771+
cmd = ["cgcreate", "-g", "cpu:vm.slice/tapdisk"]
772+
util.pread2(cmd)
773+
cgroup_slice_dir = os.path.join("/sys/fs/cgroup", "vm.slice", "tapdisk")
774+
procs_file = os.path.join(cgroup_slice_dir, "cgroup.procs")
775+
with open(procs_file, 'w') as f:
776+
f.write(str(pid))
777+
except Exception as e:
769778
util.logException(e)
770779

771780
@classmethod

tests/test_blktap2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ def test_cgclassify_normal_call(self, mock_pread2):
4747
def test_cgclassify_exception_swallow(self, mock_log, mock_pread2):
4848
mock_pread2.side_effect = util.CommandException(999)
4949
blktap2.Tapdisk.cgclassify(123)
50-
mock_pread2.assert_called_with(['cgclassify', '123'])
51-
self.assertEqual(mock_log.call_count, 1)
50+
mock_pread2.assert_called_with(['cgcreate', '-g', 'cpu:vm.slice/tapdisk'])
51+
self.assertEqual(mock_log.call_count, 2)
5252

5353
@mock.patch('sm.blktap2.Tapdisk.cgclassify')
5454
def test_cgclassify_called_by_launch_on_tap(self, mock_cgclassify):

0 commit comments

Comments
 (0)