From: Gulam Mohamed <gulam.mohamed@oracle.com>
To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: axboe@kernel.dk, shinichiro.kawasaki@wdc.com,
chaitanyak@nvidia.com, hch@lst.de
Subject: [PATCH 2/2] loop: Test to detect a race condition between loop detach and open
Date: Tue, 21 May 2024 22:42:49 +0000 [thread overview]
Message-ID: <20240521224249.7389-2-gulam.mohamed@oracle.com> (raw)
In-Reply-To: <20240521224249.7389-1-gulam.mohamed@oracle.com>
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 <gulam.mohamed@oracle.com>
---
tests/loop/010 | 90 ++++++++++++++++++++++++++++++++++++++++++++++
tests/loop/010.out | 2 ++
2 files changed, 92 insertions(+)
create mode 100755 tests/loop/010
create mode 100644 tests/loop/010.out
diff --git a/tests/loop/010 b/tests/loop/010
new file mode 100755
index 000000000000..ea93a120d51a
--- /dev/null
+++ b/tests/loop/010
@@ -0,0 +1,90 @@
+#!/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
+}
+
+image_file="/tmp/loopImg"
+line1="partition scan of loop0 failed (rc=-16)"
+
+function create_loop()
+{
+ while [ 1 ]
+ do
+ loop_device="$(losetup -P -f --show "${image_file}")"
+ blkid /dev/loop0p1 >> /dev/null 2>&1
+ done
+}
+
+function detach_loop()
+{
+ while [ 1 ]
+ do
+ if [ -e /dev/loop0 ]; then
+ losetup -d /dev/loop0 > /dev/null 2>&1
+ fi
+ done
+}
+
+test() {
+ echo "Running ${TEST_NAME}"
+ local failure="/tmp/failure"
+ touch $failure
+ echo 0 > $failure
+ dmesg -c > /dev/null 2>&1
+
+ truncate -s 2G "${image_file}"
+ parted -a none -s "${image_file}" mklabel gpt
+ loop_device="$(losetup -P -f --show "${image_file}")"
+ parted -a none -s "${loop_device}" mkpart primary 64s 109051s
+
+ udevadm settle
+ if [ ! -e "${loop_device}" ]; then
+ return 1
+ fi
+
+ mkfs.xfs -f "${loop_device}p1" > /dev/null 2>&1
+
+ losetup -d "${loop_device}" > /dev/null 2>&1
+
+ create_loop &
+ create_pid=$!
+ detach_loop &
+ detach_pid=$!
+
+ sleep "${TIMEOUT:-180}"
+ {
+ kill -9 $create_pid
+ kill -9 $detach_pid
+ wait
+ sleep 1
+ } 2>/dev/null
+
+ losetup -D > /dev/null 2>&1
+ dmesg | while IFS= read -r line2
+ do
+ match=$(echo "$line2" | grep -o "$line1")
+ if [ "$line1" == "$match" ]; then
+ echo 1 > "/tmp/failure"
+ break
+ fi
+ done
+ failed=$(cat $failure)
+ if [ $failed -eq 0 ]; then
+ echo "Test complete"
+ else
+ echo "Test failed"
+ fi
+ rm -f $failure
+}
diff --git a/tests/loop/010.out b/tests/loop/010.out
new file mode 100644
index 000000000000..64a6aee00b8a
--- /dev/null
+++ b/tests/loop/010.out
@@ -0,0 +1,2 @@
+Running loop/010
+Test complete
--
2.39.3
next prev parent reply other threads:[~2024-05-21 22:42 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-21 22:42 [PATCH V2 for-6.10/block 1/2] loop: Fix a race between loop detach and loop open Gulam Mohamed
2024-05-21 22:42 ` Gulam Mohamed [this message]
2024-05-23 8:12 ` [PATCH 2/2] loop: Test to detect a race condition between loop detach and open Christoph Hellwig
2024-05-23 11:14 ` Shinichiro Kawasaki
2024-05-27 9:56 ` [PATCH blktests] " Gulam Mohamed
2024-05-22 1:39 ` [PATCH V2 for-6.10/block 1/2] loop: Fix a race between loop detach and loop open Jens Axboe
2024-05-22 2:31 ` Yu Kuai
2024-05-22 19:12 ` Gulam Mohamed
2024-05-23 1:13 ` Yu Kuai
2024-05-22 19:11 ` Gulam Mohamed
2024-05-23 8:12 ` Christoph Hellwig
2024-05-23 18:39 ` Gulam Mohamed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240521224249.7389-2-gulam.mohamed@oracle.com \
--to=gulam.mohamed@oracle.com \
--cc=axboe@kernel.dk \
--cc=chaitanyak@nvidia.com \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shinichiro.kawasaki@wdc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox