[PATCH 1/2] common/rc: add argument to _create_loop_device() to specify device size

Shin'ichiro Kawasaki <[email protected]> Sat, 25 Jul 2026 16:04:11 +0900
Newsgroups org.kernel.vger.fstests,org.kernel.vger.linux-xfs
Message-ID <[email protected]>
Currently, _create_loop_device() does not specify the --sizelimit option
to the losetup command. As a result, the loop device has the same size
as the backing file or device. To allow controlling the loop device
size, add a third optional argument to _create_loop_device(). Also,
modify _create_loop_device_like_bdev() to pass its third argument to
_create_loop_device().

Signed-off-by: Shin'ichiro Kawasaki <[email protected]>
---
 common/rc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/common/rc b/common/rc
index 336441c7..4be9e719 100644
--- a/common/rc
+++ b/common/rc
@@ -4610,11 +4610,13 @@ _create_loop_device()
 {
 	local file="$1"
 	local blksize="$2"
+	local sizelimit="$3"
 	local dev
 	local dio_args="--direct-io=on"
 	local args
 
 	test -n "$blksize" && args="--sector-size=$blksize"
+	test -n "$sizelimit" && args+=" --sizelimit=$sizelimit"
 
 	# Try to enable asynchronous directio mode on the loopback device so
 	# that writeback started by a filesystem mounted on the loop device
@@ -4650,7 +4652,8 @@ _create_loop_device_like_bdev()
 
 	blksize="$(blockdev --getss "$bdev")"
 
-	_create_loop_device "$file" "$blksize"
+	shift 2
+	_create_loop_device "$file" "$blksize" "$@"
 }
 
 _destroy_loop_device()
-- 
2.54.0