- try:
- f=open('/sys/fs/cgroup/freezer/libvirt/lxc/%s/tasks'%(slice_name),'w')
- f.write(str(os.getpid()))
- # note: we need to call f.close() explicitly, or we'll get an exception in
- # the object destructor, which will not be caught
- f.close()
- except:
- print "Error adding task to freezer cgroup. Slice is probably frozen: %s" % slice_name
- exit(1)
+ # Enter cgroups
+ current_cgroup = ''
+ for subsystem in ['cpuset', 'memory', 'blkio', 'cpuacct', 'cpuacct,cpu', 'freezer']:
+ try:
+ current_cgroup = subsystem
+
+ # There seems to be a bug in the cgroup schema: cpuacct,cpu can become cpu,cpuacct
+ # We need to handle both
+ task_path_alt = None
+ try:
+ subsystem_comps = subsystem.split(',')
+ subsystem_comps.reverse()
+ subsystem_alt = ','.join(subsystem_comps)
+ tasks_path_alt = [sysfs_root, subsystem_alt,
+ subdirs[subsystem], 'tasks']
+ except Exception as e:
+ pass
+
+ tasks_path = [sysfs_root, subsystem, subdirs[subsystem], 'tasks']
+ tasks_path_str = '/'.join(tasks_path)
+
+ try:
+ f = open(tasks_path_str, 'w')
+ except:
+ tasks_path_alt_str = '/'.join(tasks_path_alt)
+ f = open(tasks_path_alt_str, 'w')
+
+ f.write(str(os.getpid()))
+ if (subsystem == 'freezer'):
+ f.close()
+
+ except Exception as e:
+ if (subsystem not in subdirs):
+ pass
+ else:
+ if debug:
+ print(e)
+ print("Error assigning cgroup %s (pid=%s) for slice %s" %
+ (current_cgroup, driver_pid, slice_name))
+ exit(1)