grub-fs-tester: fix losetup race
cover grub-fs-tester: fix losetup race
On a build server where other jobs are making use of loop devices, we occasionally see GRUB's filesystem tests failing with errors like:
losetup: /tmp/tmp.uMgVEh1vvn/ext2_old_256_1024_1_0.img: failed to set up loop device: Device or resource busy
This is because grub-fs-tester runs losetup --find to get a free loop device, then runs losetup $LODEVICE $FILE to use it. In between the two invocations, something else may have started using the free device.
It's easy to reproduce this by running a script like this at the same time as a fs test:
while true; do
x=$(losetup --find --show /path/to/a/file)
losetup -d $x
doneThe fix is to ask losetup to attach the file to a free loop device, and print that device to stdout, in a single invocation. (losetup internally has a retry loop.)
Will Thompson (1):
grub-fs-tester: fix losetup race
tests/util/grub-fs-tester.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/1 grub-fs-tester: fix losetup race
If something else on the system is using loopback devices, then the device that's free at the call to losetup -f may not be free in the following call to try to use it. Instead, find and use the first free loopback device in a single call to losetup.
--- tests/util/grub-fs-tester.in | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tests/util/grub-fs-tester.in +1 -2
@@ -616,9 +616,8 @@ for LOGSECSIZE in $(range "$MINLOGSECSIZE" "$MAXLOGSECSIZE" 1); do mkdir -p "$MNTPOINTRO" for i in $(range 0 $((NDEVICES-1)) 1); do dd if=/dev/zero of="$FSIMAGEP${i}.img" count=1 bs=1 seek=$((DISKSIZE-1)) &> /dev/null - LODEVICE="$(losetup -f)" + LODEVICE=$(losetup --find --show "$FSIMAGEP${i}.img") LODEVICES="$LODEVICES $LODEVICE" - losetup "$LODEVICE" "$FSIMAGEP${i}.img" if test "$i" = 0; then MOUNTDEVICE="$LODEVICE" fi
Signature · 1 line
2.17.1
Quoted 4 lines · Will Thompson
If something else on the system is using loopback devices, then the device that's free at the call to
losetup -fmay not be free in the following call to try to use it. Instead, find and use the first free loopback device in a single call to losetup.
In general LGTM except lack of SOB. I can add it (Signed-off-by: Will Thompson <[email protected]>) before committing if you are OK with that. Next time please do not forget about that.
Daniel
Quoted 10 lines · On Wed, 20 Jun 2018 at 10:33 Daniel Kiper <[email protected]> wrote:
Quoted 4 lines · Will Thompson
If something else on the system is using loopback devices, then the device that's free at the call to
losetup -fmay not be free in the following call to try to use it. Instead, find and use the first free loopback device in a single call to losetup.In general LGTM except lack of SOB. I can add it (Signed-off-by: Will Thompson <[email protected]>) before committing if you are OK with that. Next time please do not forget about that.
That's fine by me – I'll include it in the submitted patch in future. Thanks!