Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions libs/sm/blktap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,14 +758,23 @@ def launch_from_arg(cls, arg):

@staticmethod
def cgclassify(pid):

# We dont provide any <controllers>:<path>
# so cgclassify uses /etc/cgrules.conf which
# we have configured in the spec file.
cmd = ["cgclassify", str(pid)]
try:
util.pread2(cmd)
except util.CommandException as e:
# We dont provide any <controllers>:<path>
# so cgclassify uses /etc/cgrules.conf which
# we have configured in the spec file.
cmd = ["cgclassify", str(pid)]
try:
util.pread2(cmd)
except util.CommandException as e:
util.logException(e)
# cgroup-v2 path
cmd = ["cgcreate", "-g", "cpu:vm.slice/tapdisk"]
util.pread2(cmd)
cgroup_slice_dir = os.path.join("/sys/fs/cgroup", "vm.slice", "tapdisk")
procs_file = os.path.join(cgroup_slice_dir, "cgroup.procs")
with open(procs_file, 'w') as f:
f.write(str(pid))
except Exception as e:
util.logException(e)

@classmethod
Expand Down
4 changes: 2 additions & 2 deletions tests/test_blktap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def test_cgclassify_normal_call(self, mock_pread2):
def test_cgclassify_exception_swallow(self, mock_log, mock_pread2):
mock_pread2.side_effect = util.CommandException(999)
blktap2.Tapdisk.cgclassify(123)
mock_pread2.assert_called_with(['cgclassify', '123'])
self.assertEqual(mock_log.call_count, 1)
mock_pread2.assert_called_with(['cgcreate', '-g', 'cpu:vm.slice/tapdisk'])
self.assertEqual(mock_log.call_count, 2)

@mock.patch('sm.blktap2.Tapdisk.cgclassify')
def test_cgclassify_called_by_launch_on_tap(self, mock_cgclassify):
Expand Down
Loading