zdtm: fix TOCTOU race creating criu.tree directory

When running tests in parallel (-p 2) with GCOV=1, multiple
forked processes race to create ../criu.tree. The check-then-
create pattern (os.access + os.mkdir) allows two processes to
both see the directory as missing and then both attempt mkdir,
causing FileExistsError in the second process.

Replace with os.makedirs(exist_ok=True) which handles the race
atomically.

Assisted-by: Claude:claude-opus-4-6
Signed-off-by: Adrian Reber <areber@redhat.com>
This commit is contained in:
Adrian Reber 2026-03-17 12:54:30 +00:00 committed by Andrei Vagin
parent 010a346c67
commit 33e340bed4

View file

@ -2018,9 +2018,7 @@ def do_run_test(tname, tdesc, flavs, opts):
# to it. Without this, those mounts propagate into the source and
# become MNT_LOCKED inside the user namespace, causing
# open_tree(OPEN_TREE_CLONE) to return EINVAL on restore.
if not os.access("../criu.tree", os.F_OK):
os.mkdir("../criu.tree")
os.chmod("../criu.tree", 0o700)
os.makedirs("../criu.tree", mode=0o700, exist_ok=True)
subprocess.check_call(["mount", "--bind", "--make-private", "..", "../criu.tree"])
tcname = tname.split('/')[0]
tclass = test_classes.get(tcname, None)