Skip to content

Commit e70d901

Browse files
committed
wrapper: chown tasks file in net_cls cgroup
When `cgexec` starts it is already running under modified UID/GID (at least on RHV host). We need to change ownership of `tasks` file so that `cgexec` can write into it. Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
1 parent 676154f commit e70d901

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

wrapper/virt-v2v-wrapper.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,10 @@ def set_network_limit(self, limit):
12831283
return self._tc.set_limit(limit)
12841284

12851285
def _prepare_net_cls(self):
1286-
self._tc = TcController(self._host.get_tag())
1286+
self._tc = TcController(
1287+
self._host.get_tag(),
1288+
self._host.get_uid(),
1289+
self._host.get_gid())
12871290
return self._tc.cgroup
12881291

12891292
def _systemd_return_code(self):
@@ -1322,10 +1325,11 @@ def class_id_to_hex(class_id):
13221325
minor = int(parts[1], base=16)
13231326
return '0x{:04x}{:04x}'.format(major, minor)
13241327

1325-
def __init__(self, tag):
1328+
def __init__(self, tag, uid, gid):
13261329
self._cgroup = 'v2v-conversion/%s' % tag
13271330
self._class_id = None
13281331
self._interfaces = []
1332+
self._owner = (uid, gid)
13291333
self._prepare()
13301334

13311335
@property
@@ -1367,6 +1371,10 @@ def _prepare_cgroup(self):
13671371
cgroup_dir = '/sys/fs/cgroup/net_cls/%s' % self._cgroup
13681372
atexit_command(['/usr/bin/rmdir', '-p', cgroup_dir])
13691373
os.makedirs(cgroup_dir)
1374+
# Change ownership of 'tasks' file so cgexec can write into it
1375+
os.chown(
1376+
os.path.join(cgroup_dir, 'tasks'),
1377+
self._owner[0], self._owner[1])
13701378
# Store class ID
13711379
if self._class_id is not None:
13721380
with open(os.path.join(cgroup_dir, 'net_cls.classid'), 'w') as f:

0 commit comments

Comments
 (0)