]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-repart: use cryptsetup and losetup autoclose
authorLuca Boccassi <luca.boccassi@microsoft.com>
Fri, 9 Apr 2021 09:56:13 +0000 (10:56 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 11 Apr 2021 14:50:31 +0000 (23:50 +0900)
The test occasionally fails as the umount is not yet completed when
cryptsetup close is invoked.
Both cryptsetup and losetup have supported deferred cleanup for some
time now, so use it instead to avoid races.

++ losetup -P --show --find /tmp/test-repart.dMOfYQ8UUF/zzz
+ LOOP=/dev/loop6
+ VOLUME=test-repart-11882
+ touch /tmp/test-repart.dMOfYQ8UUF/empty-password
+ cryptsetup open --type=luks2 --key-file=/tmp/test-repart.dMOfYQ8UUF/empty*** test-repart-11882
+ mkdir /tmp/test-repart.dMOfYQ8UUF/mount
+ mount -t ext4 /dev/mapper/test-repart-11882 /tmp/test-repart.dMOfYQ8UUF/mount
+ diff -r /tmp/test-repart.dMOfYQ8UUF/mount/def /tmp/test-repart.dMOfYQ8UUF/definitions
+ umount /tmp/test-repart.dMOfYQ8UUF/mount
+ cryptsetup close test-repart-11882
Device test-repart-11882 is still in use.
+ rm -rf /tmp/test-repart.dMOfYQ8UUF

src/partition/test-repart.sh

index d21865dd6470d4b8b7418e0b1e968fb29732e5ef..3696c3cbd6fbbac34efbb9a16de513625aed49f2 100755 (executable)
@@ -200,10 +200,11 @@ EOF
     cryptsetup open --type=luks2 --key-file=$D/empty-password ${LOOP}p7 $VOLUME
     mkdir $D/mount
     mount -t ext4 /dev/mapper/$VOLUME $D/mount
+    # Use deferred closing on the mapper and autoclear on the loop, so they are cleaned up on umount
+    cryptsetup close --deferred $VOLUME
+    losetup -d $LOOP
     diff -r $D/mount/def $D/definitions > /dev/null
     umount $D/mount
-    cryptsetup close $VOLUME
-    losetup -d $LOOP
 else
     echo "### Skipping Format=/Encrypt=/CopyFiles= test, lacking privileges or missing cryptsetup/diff/losetup"
 fi