]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: create public images by default
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 25 May 2020 20:48:01 +0000 (22:48 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 27 May 2020 06:41:02 +0000 (08:41 +0200)
Let's create new images public by default and then symlink/copy them
into the respective private directories afterwards, not the other way
around. This should fix a nasty race condition in parallel runs where
one tests attempts to copy the backing public image at the same moment
another test is already modifying it.

test/test-functions

index f5a798b4b83cad560a216069873dfa8961cbe979..e4d690a4e9538124f23e49dbebc1b0c0d4fe9c4b 100644 (file)
@@ -678,6 +678,7 @@ cleanup_loopdev() {
     if [ -n "${LOOPDEV}" ]; then
         ddebug "losetup -d $LOOPDEV"
         losetup -d "${LOOPDEV}"
+        unset LOOPDEV
     fi
 }
 
@@ -698,8 +699,7 @@ create_empty_image() {
     rm -f "$IMAGE_PRIVATE" "$IMAGE_PUBLIC"
 
     # Create the blank file to use as a root filesystem
-    truncate -s "${_size}M" "$IMAGE_PRIVATE"
-    ln -vs "$(realpath $IMAGE_PRIVATE)" "$IMAGE_PUBLIC"
+    truncate -s "${_size}M" "$IMAGE_PUBLIC"
 
     LOOPDEV=$(losetup --show -P -f "$IMAGE_PUBLIC")
     [ -b "$LOOPDEV" ] || return 1
@@ -2005,16 +2005,26 @@ test_setup() {
     if [ -e "$IMAGE_PRIVATE" ]; then
         echo "Reusing existing image $IMAGE_PRIVATE → $(realpath $IMAGE_PRIVATE)"
         mount_initdir
-    elif [ -e "$IMAGE_PUBLIC" ]; then
+    else
+        if [ ! -e "$IMAGE_PUBLIC" ]; then
+            # Create the backing public image, but then completely unmount
+            # it and drop the loopback device responsible for it, since we're
+            # going to symlink/copy the image and mount it again from
+            # elsewhere.
+            test_create_image
+            test_setup_cleanup
+            umount_loopback
+            cleanup_loopdev
+        fi
+
         echo "Reusing existing cached image $IMAGE_PUBLIC → $(realpath $IMAGE_PUBLIC)"
         if [ ${TEST_PARALLELIZE} -ne 0 ]; then
             cp -v "$(realpath $IMAGE_PUBLIC)" "$IMAGE_PRIVATE"
         else
             ln -sv "$(realpath $IMAGE_PUBLIC)" "$IMAGE_PRIVATE"
         fi
+
         mount_initdir
-    else
-        test_create_image
     fi
 
     setup_nspawn_root