diff options
Diffstat (limited to 'test/zdtm/static/cgroup_yard.hook')
-rwxr-xr-x | test/zdtm/static/cgroup_yard.hook | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/test/zdtm/static/cgroup_yard.hook b/test/zdtm/static/cgroup_yard.hook new file mode 100755 index 000000000..7ae53342c --- /dev/null +++ b/test/zdtm/static/cgroup_yard.hook @@ -0,0 +1,70 @@ +#!/usr/bin/env python + +import sys +import os +import subprocess +import tempfile + +yard = "external_yard" + +if sys.argv[1] == "--pre-dump": + ''' + Create external cgroup yard to be passed to CRIU via --cgroup-yard + ''' + os.mkdir(yard) + with open("/proc/self/cgroup") as f: + for line in f: + cgr = line.split(":")[1] + + if cgr == "": + continue + + if cgr.startswith("name="): + ctrl = cgr[len("name="):] + opts = "none," + cgr + else: + ctrl = cgr + opts = cgr + + os.mkdir(yard + "/" + ctrl) + subprocess.check_call(["mount", "-t", "cgroup", "none", yard + "/" + ctrl, "-o", opts]) + +if sys.argv[1] == "--post-restore": + ''' + Clean up the cgroup yard created during `--pre-dump` + ''' + with open("/proc/self/cgroup") as f: + for line in f: + cgr = line.split(":")[1] + + if cgr == "": + continue + + if cgr.startswith("name="): + ctrl = cgr[len("name="):] + else: + ctrl = cgr + + subprocess.check_call(["umount", yard + "/" + ctrl]) + os.rmdir(yard + "/" + ctrl) + os.rmdir(yard) + +if sys.argv[1] in ["--pre-restore", "--clean"]: + ''' + Clean up the leftover cgroups created by the test + ''' + tname = tempfile.mkdtemp() + subprocess.call(["mount", "-t", "cgroup", "none", tname, "-o", "none,name=zdtmtst"]) + + try: + os.rmdir(os.path.join(tname, "subcg00", "subsubcg")) + except: + pass + + try: + os.rmdir(os.path.join(tname, "subcg00")) + except: + pass + + subprocess.call(["umount", tname]) + os.rmdir(tname) |