-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
loop: Detect a race condition between loop detach and open
When one process opens a loop device partition and another process detaches it, there will be a race condition due to which stale loop partitions are created causing IO errors. This test will detect the race. Signed-off-by: Gulam Mohamed <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> [Shin'ichiro: moved $TMPDIR reference into test()] Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
- Loading branch information
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/bin/bash | ||
# SPDX-License-Identifier: GPL-3.0+ | ||
# Copyright (C) 2024, Oracle and/or its affiliates. | ||
# | ||
# Test to detect a race between loop detach and loop open which creates | ||
# stale loop partitions when one process opens the loop partition and | ||
# another process detaches the loop device. | ||
# | ||
. tests/loop/rc | ||
DESCRIPTION="check stale loop partition" | ||
TIMED=1 | ||
|
||
requires() { | ||
_have_program parted | ||
_have_program mkfs.xfs | ||
} | ||
|
||
create_loop() { | ||
while true | ||
do | ||
loop_device="$(losetup --partscan --find --show "${image_file}")" | ||
blkid /dev/loop0p1 >& /dev/null | ||
done | ||
} | ||
|
||
detach_loop() { | ||
while true | ||
do | ||
if [ -e /dev/loop0 ]; then | ||
losetup --detach /dev/loop0 >& /dev/null | ||
fi | ||
done | ||
} | ||
|
||
test() { | ||
echo "Running ${TEST_NAME}" | ||
local loop_device | ||
local create_pid | ||
local detach_pid | ||
local image_file="$TMPDIR/loopImg" | ||
|
||
truncate --size 1G "${image_file}" | ||
parted --align none --script "${image_file}" mklabel gpt | ||
loop_device="$(losetup --partscan --find --show "${image_file}")" | ||
parted --align none --script "${loop_device}" mkpart primary 64s 109051s | ||
|
||
udevadm settle | ||
|
||
if [ ! -e "${loop_device}" ]; then | ||
return 1 | ||
fi | ||
|
||
mkfs.xfs --force "${loop_device}p1" >& /dev/null | ||
losetup --detach "${loop_device}" >& /dev/null | ||
|
||
create_loop & | ||
create_pid=$! | ||
detach_loop & | ||
detach_pid=$! | ||
|
||
sleep "${TIMEOUT:-90}" | ||
{ | ||
kill -9 $create_pid | ||
kill -9 $detach_pid | ||
wait | ||
sleep 1 | ||
} 2>/dev/null | ||
|
||
losetup --detach-all >& /dev/null | ||
if _dmesg_since_test_start | grep --quiet "partition scan of loop0 failed (rc=-16)"; then | ||
echo "Fail" | ||
fi | ||
echo "Test complete" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Running loop/010 | ||
Test complete |