From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: Bart Van Assche <bvanassche@acm.org>
Cc: linux-block@vger.kernel.org
Subject: Re: [PATCH blktests] loop/014: Add test for backing file on loop device partition
Date: Mon, 24 Aug 2026 19:55:06 +0900 [thread overview]
Message-ID: <aowhot0Y6jXYjeMY@shinhome> (raw)
In-Reply-To: <20260820200034.3849080-1-bvanassche@acm.org>
On Aug 20, 2026 / 13:00, Bart Van Assche wrote:
> Add a new loop driver test that verifies that attempting to set the
> backing file of a loop device to a file located on a filesystem on one of
> the same loop device's partitions fails as expected by triggering the
> kernel function loop_validate_file().
>
> Modify src/loop_change_fd.c to accept a -r option to open the loop device
> and backing file in read-only mode (O_RDONLY).
>
> The test performs the following steps:
> - Create a 1 GB image file ($TMPDIR/img).
> - Instantiate a loop device for the image file with partition scanning
> enabled.
> - Create two partitions of equal size on that loop device.
> - Format the second partition with the ext4 filesystem and mount it.
> - Create a 1 GB file on the mounted filesystem.
> - Unmount the filesystem, detach the loop device, and re-instantiate it in
> read-only mode.
> - Mount the partition read-only.
> - Use src/loop_change_fd -r to attempt to change the backing file
> descriptor of the loop device to the file on its own partition via
> LOOP_CHANGE_FD, and verify that loop_validate_file() rejects it.
> - Clean up by unmounting the filesystem and detaching the loop device.
>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Thanks for the patch. Overall, it looks good to me. I ran the test using the
kernel at the current Linus master branch tip, and confirmed the test case
recreates the failrue, and the kernel side fix patch avoids the failure [1].
Good.
[1] https://lore.kernel.org/linux-block/0c8a65b8870b2ef09119093b485e37896b80e2a4.1787255652.git.bvanassche@acm.org/
Please find two nit comments in line below. They are not a big deal. If you
want, I can fold-in the changes when I apply this patch after the kernel side
fix get upstreamed.
> diff --git a/tests/loop/014 b/tests/loop/014
> new file mode 100755
> index 000000000000..5814b8148a26
> --- /dev/null
> +++ b/tests/loop/014
> @@ -0,0 +1,107 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-3.0+
> +# Copyright (C) 2026 Google LLC
> +#
> +# Verify that attempting to change a loop device's backing file (via
> +# LOOP_CHANGE_FD) to a file on a filesystem residing on one of its own
> +# partitions triggers the kernel function loop_validate_file() and fails.
I think the kernel side fix commit should be mentioned here.
> +
> +. tests/loop/rc
> +
> +DESCRIPTION="trigger loop_validate_file() when changing backing file to own partition"
> +QUICK=1
> +
> +loop_device=
> +mount_dir=
> +
> +requires() {
> + _have_program mkfs.ext4
> + _have_program parted
> + _have_src_program loop_change_fd
> +}
> +
> +cleanup() {
> + if [[ -n "$mount_dir" ]]; then
> + umount "$mount_dir" &>/dev/null
> + fi
> + if [[ -n "$loop_device" ]]; then
> + losetup --detach "$loop_device" &>/dev/null
> + fi
> +}
> +
> +test() {
> + echo "Running ${TEST_NAME}"
> + _register_test_cleanup cleanup
> +
> + mount_dir="$TMPDIR/mnt"
> +
> + truncate -s 1G "$TMPDIR/img"
Nit: I suggest the long option "--size=1G" instead of the short option "-s 1G".
Same for mkdir -p option and mount -t option.
prev parent reply other threads:[~2026-08-24 10:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 20:00 [PATCH blktests] loop/014: Add test for backing file on loop device partition Bart Van Assche
2026-08-24 10:55 ` Shin'ichiro Kawasaki [this message]
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=aowhot0Y6jXYjeMY@shinhome \
--to=shinichiro.kawasaki@wdc.com \
--cc=bvanassche@acm.org \
--cc=linux-block@vger.kernel.org \
/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