diff mbox series

[2/2] generic/563: create the loop dev with the same block size as the scratch dev

Message ID 20231022215529.2202150-3-tytso@mit.edu (mailing list archive)
State New, archived
Headers show
Series Fix test failures caused by storage devcies with 4k sectors | expand

Commit Message

Theodore Ts'o Oct. 22, 2023, 9:55 p.m. UTC
The generic/563 test creates the loop device using $SCRATCH_DEV
directly.  We need to create the loop device with the same logical
block size.  Otherwise, the loop device will always be created with
the default logical block size of 512, and if its underlying backing
store has a different logical block size, then mkfs may create a file
system in the loop device that will fail to mount.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
 common/rc         | 10 ++++++++--
 tests/generic/563 |  2 +-
 2 files changed, 9 insertions(+), 3 deletions(-)

Comments

Darrick J. Wong Oct. 23, 2023, 3:54 p.m. UTC | #1
On Sun, Oct 22, 2023 at 05:55:29PM -0400, Theodore Ts'o wrote:
> The generic/563 test creates the loop device using $SCRATCH_DEV
> directly.  We need to create the loop device with the same logical
> block size.  Otherwise, the loop device will always be created with
> the default logical block size of 512, and if its underlying backing
> store has a different logical block size, then mkfs may create a file
> system in the loop device that will fail to mount.
> 
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>

Looks fine to me,
Reviewed-by: Darrick J. Wong <djwong@kernel.org>

--D

> ---
>  common/rc         | 10 ++++++++--
>  tests/generic/563 |  2 +-
>  2 files changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/common/rc b/common/rc
> index 8d7179567..01f065a9f 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -4246,9 +4246,15 @@ _require_userns()
>  
>  _create_loop_device()
>  {
> -	local file=$1 dev
> -	dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
> +	local file=$1
> +	local blocksize=$2
> +	local dev
> +
> +	if [ -n "$blocksize" ]; then
> +		blocksize="-b $blocksize"
> +	fi
>  
> +	dev=`losetup -f $blocksize --show $file` || _fail "Cannot assign $file to a loop device"
>  	# Try to enable asynchronous directio mode on the loopback device so
>  	# that writeback started by a filesystem mounted on the loop device
>  	# won't be throttled by buffered writes to the lower filesystem.  This
> diff --git a/tests/generic/563 b/tests/generic/563
> index f98c6e42b..7e6bab49e 100755
> --- a/tests/generic/563
> +++ b/tests/generic/563
> @@ -89,7 +89,7 @@ reset()
>  
>  # cgroup I/O accounting doesn't work on partitions. Use a loop device to rule
>  # that out.
> -LOOP_DEV=$(_create_loop_device $SCRATCH_DEV)
> +LOOP_DEV=$(_create_loop_device $SCRATCH_DEV $(blockdev --getss $SCRATCH_DEV))
>  smajor=$((0x`stat -L -c %t $LOOP_DEV`))
>  sminor=$((0x`stat -L -c %T $LOOP_DEV`))
>  
> -- 
> 2.31.0
>
diff mbox series

Patch

diff --git a/common/rc b/common/rc
index 8d7179567..01f065a9f 100644
--- a/common/rc
+++ b/common/rc
@@ -4246,9 +4246,15 @@  _require_userns()
 
 _create_loop_device()
 {
-	local file=$1 dev
-	dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
+	local file=$1
+	local blocksize=$2
+	local dev
+
+	if [ -n "$blocksize" ]; then
+		blocksize="-b $blocksize"
+	fi
 
+	dev=`losetup -f $blocksize --show $file` || _fail "Cannot assign $file to a loop device"
 	# Try to enable asynchronous directio mode on the loopback device so
 	# that writeback started by a filesystem mounted on the loop device
 	# won't be throttled by buffered writes to the lower filesystem.  This
diff --git a/tests/generic/563 b/tests/generic/563
index f98c6e42b..7e6bab49e 100755
--- a/tests/generic/563
+++ b/tests/generic/563
@@ -89,7 +89,7 @@  reset()
 
 # cgroup I/O accounting doesn't work on partitions. Use a loop device to rule
 # that out.
-LOOP_DEV=$(_create_loop_device $SCRATCH_DEV)
+LOOP_DEV=$(_create_loop_device $SCRATCH_DEV $(blockdev --getss $SCRATCH_DEV))
 smajor=$((0x`stat -L -c %t $LOOP_DEV`))
 sminor=$((0x`stat -L -c %T $LOOP_DEV`))