]> git-server-git.apps.pok.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
xfs/259: try to force loop device block size
authorDarrick J. Wong <djwong@kernel.org>
Tue, 29 Jul 2025 20:10:19 +0000 (13:10 -0700)
committerZorro Lang <zlang@kernel.org>
Fri, 1 Aug 2025 20:19:02 +0000 (04:19 +0800)
Starting with 6.15-rc1, loop devices created with directio mode enabled
will set their logical block size to whatever STATX_DIO_ALIGN on the
host filesystem reports.  If you want fstests to set up loop devices in
directio mode and TEST_DEV is a block device with 4k sectors, this will
cause conflicts with this test's usage of mkfs with different block
sizes.  Enhance the existing _create_loop_device so that tests can force
the loop device block size to 512 bytes, which is implied by scenarios
such as "device size is 4T - 2048 bytes".

Also fix xfs/078 which simply needs the blocksize to be set.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Zorro Lang <zlang@kernel.org>
common/rc
tests/xfs/078
tests/xfs/259
tests/xfs/613

index b9292a784e429b8b6164b10db5b841045c4f5e53..66c8e0794bd56be56edb5f543bc34ebbb386fda5 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -4571,17 +4571,31 @@ _require_userns()
        $here/src/nsexec -U true 2>/dev/null || _notrun "userns not supported by this kernel"
 }
 
+# Create a loop device from a given file and configure it to support IOs
+# aligned to the specified block size, if provided.
 _create_loop_device()
 {
-       local file=$1 dev
-       dev=`losetup -f --show $file` || _fail "Cannot assign $file to a loop device"
+       local file="$1"
+       local blksize="$2"
+       local dev
+       local dio_args="--direct-io=on"
+       local args
+
+       test -n "$blksize" && args="--sector-size=$blksize"
 
        # 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
        # is a performance optimization for tests that want to write a lot of
        # data, so it isn't required to work.
-       test -b "$dev" && losetup --direct-io=on $dev 2> /dev/null
+       #
+       # Starting with 6.15-rc1 the kernel will set the loop device's sector
+       # size to the directio alignment of the underlying fs, so if we want to
+       # use our own sector size, we need to specify that at creation time.
+       if ! dev="$(losetup $dio_args $args -f --show $file 2>/dev/null)"; then
+               dev="$(losetup $args -f --show $file)" || \
+                       _fail "Cannot assign $file to a loop device ($args)"
+       fi
 
        echo $dev
 }
index 0d3c2eb23e51cee52d190bc48fb0c508941b3416..6057aeea12abe936a6dbe0fc2c7510a39bde8476 100755 (executable)
@@ -55,7 +55,7 @@ _grow_loop()
        agsize=$5
 
        $XFS_IO_PROG -f -c "truncate $original" $LOOP_IMG
-       loop_dev=`_create_loop_device $LOOP_IMG`
+       loop_dev=`_create_loop_device $LOOP_IMG $bsize`
 
        dparam=""
        if [ -n "$agsize" ]; then
@@ -73,7 +73,7 @@ _grow_loop()
        echo "*** extend loop file"
        _destroy_loop_device $loop_dev
        $XFS_IO_PROG -c "pwrite $new_size $bsize" $LOOP_IMG | _filter_io
-       loop_dev=`_create_loop_device $LOOP_IMG`
+       loop_dev=`_create_loop_device $LOOP_IMG $bsize`
        echo "*** mount loop filesystem"
        _mount $loop_dev $LOOP_MNT
 
index e367d35acc395661e593cb42ffe0201d1b7ff013..b333ac02964b25c902232761038fdb17a6d90458 100755 (executable)
@@ -41,7 +41,7 @@ for del in $sizes_to_check; do
                ddseek=$(_math "$four_TB - $del")
                rm -f "$testfile"
                truncate -s $ddseek "$testfile"
-               loop_dev=$(_create_loop_device $testfile)
+               loop_dev=$(_create_loop_device $testfile 512)
                $MKFS_XFS_PROG -l size=32m -b size=$bs $loop_dev >> $seqres.full || \
                        echo "mkfs failed!"
                sync
index c034ef60d28bad2d521a5400434c67d93385608e..9b27a7c1f2c23f7ffb1340e4faf6933722cc07b0 100755 (executable)
@@ -36,7 +36,8 @@ LOOP_MNT=$TEST_DIR/$seq.mnt
 
 echo "** create loop device"
 $XFS_IO_PROG -f -c "truncate 32g" $LOOP_IMG
-loop_dev=`_create_loop_device $LOOP_IMG`
+# 512b sector size needed for v1 log
+loop_dev=`_create_loop_device $LOOP_IMG 512`
 
 echo "** create loop mount point"
 rmdir $LOOP_MNT 2>/dev/null