[PATCH] iotests/108: probe loop device setup

Ilya Leoshkevich posted 1 patch 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20261013182804.103882-1-iii@linux.ibm.com
Maintainers: Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>
tests/qemu-iotests/108 | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] iotests/108: probe loop device setup
Posted by Ilya Leoshkevich 1 month, 1 week ago
Running iotests/108 in a Docker container, that has passwordless sudo
configured, fails with:

    losetup: /home/user/src/qemu/build/scratch/qcow2-file-108/t.qcow2: failed to set up loop device: No such file or directory

because it incorrectly assumes losetup is allowed to do loop device
setup, when in reality it can only list devices.

Fix by probing loop device setup, using the test script as a backing
file. With this, the test is correctly skipped.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
 tests/qemu-iotests/108 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108
index 1de718188aa..adbaaf87095 100755
--- a/tests/qemu-iotests/108
+++ b/tests/qemu-iotests/108
@@ -53,7 +53,8 @@ _supported_os Linux
 _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
 
 # This test either needs sudo -n losetup or FUSE exports to work
-if sudo -n losetup &>/dev/null; then
+if probe_dev=$(sudo -n losetup -r --show -f "$0" 2>/dev/null); then
+    sudo -n losetup -d "$probe_dev"
     loopdev=true
 else
     loopdev=false
-- 
2.56.0
Re: [PATCH] iotests/108: probe loop device setup
Posted by Kevin Wolf 3 weeks, 2 days ago
Am 13.10.2026 um 20:28 hat Ilya Leoshkevich geschrieben:
> Running iotests/108 in a Docker container, that has passwordless sudo
> configured, fails with:
> 
>     losetup: /home/user/src/qemu/build/scratch/qcow2-file-108/t.qcow2: failed to set up loop device: No such file or directory
> 
> because it incorrectly assumes losetup is allowed to do loop device
> setup, when in reality it can only list devices.
> 
> Fix by probing loop device setup, using the test script as a backing
> file. With this, the test is correctly skipped.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>

Won't loop-create-file and fuse-truncate need the same fix?

Maybe we could have a _require_losetup() helper function in common.rc
for the shell-based tests? (Only two at the moment, though I also have a
patch on the list that would add a third one.)

Kevin
Re: [PATCH] iotests/108: probe loop device setup
Posted by Eric Blake 1 month, 1 week ago
On Tue, Oct 13, 2026 at 08:28:00PM +0200, Ilya Leoshkevich wrote:
> Running iotests/108 in a Docker container, that has passwordless sudo
> configured, fails with:
> 
>     losetup: /home/user/src/qemu/build/scratch/qcow2-file-108/t.qcow2: failed to set up loop device: No such file or directory
> 
> because it incorrectly assumes losetup is allowed to do loop device
> setup, when in reality it can only list devices.
> 
> Fix by probing loop device setup, using the test script as a backing
> file. With this, the test is correctly skipped.
> 
> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> ---
>  tests/qemu-iotests/108 | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108
> index 1de718188aa..adbaaf87095 100755
> --- a/tests/qemu-iotests/108
> +++ b/tests/qemu-iotests/108
> @@ -53,7 +53,8 @@ _supported_os Linux
>  _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
>  
>  # This test either needs sudo -n losetup or FUSE exports to work
> -if sudo -n losetup &>/dev/null; then
> +if probe_dev=$(sudo -n losetup -r --show -f "$0" 2>/dev/null); then
> +    sudo -n losetup -d "$probe_dev"

Is 'sudo -n losetup -f' a simpler test?  It prints out the next
/dev/loopN value available only if a mount would succeed, which means
that it is a stronger test than the existing 'sudo -n losetup', but
also does not require a subsequent cleanup.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org
Re: [PATCH] iotests/108: probe loop device setup
Posted by Ilya Leoshkevich 1 month, 1 week ago

On 10/13/26 20:53, Eric Blake wrote:
> On Tue, Oct 13, 2026 at 08:28:00PM +0200, Ilya Leoshkevich wrote:
>> Running iotests/108 in a Docker container, that has passwordless sudo
>> configured, fails with:
>>
>>      losetup: /home/user/src/qemu/build/scratch/qcow2-file-108/t.qcow2: failed to set up loop device: No such file or directory
>>
>> because it incorrectly assumes losetup is allowed to do loop device
>> setup, when in reality it can only list devices.
>>
>> Fix by probing loop device setup, using the test script as a backing
>> file. With this, the test is correctly skipped.
>>
>> Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
>> ---
>>   tests/qemu-iotests/108 | 3 ++-
>>   1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108
>> index 1de718188aa..adbaaf87095 100755
>> --- a/tests/qemu-iotests/108
>> +++ b/tests/qemu-iotests/108
>> @@ -53,7 +53,8 @@ _supported_os Linux
>>   _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
>>   
>>   # This test either needs sudo -n losetup or FUSE exports to work
>> -if sudo -n losetup &>/dev/null; then
>> +if probe_dev=$(sudo -n losetup -r --show -f "$0" 2>/dev/null); then
>> +    sudo -n losetup -d "$probe_dev"
> 
> Is 'sudo -n losetup -f' a simpler test?  It prints out the next
> /dev/loopN value available only if a mount would succeed, which means
> that it is a stronger test than the existing 'sudo -n losetup', but
> also does not require a subsequent cleanup.

I don't think 'losetup -f' attempts a mount, since it works fine without
privileges:

$ id -u
1000
$ losetup -f
/dev/loop0
$ losetup -r -f /bin/true
losetup: /bin/true: failed to set up loop device: Permission denied

A quick glance at the source code [1] seems to confirm this: the
iterator is immediately discarded after finding a free device name.
The loop-control logic above looks similar.

[1] 
https://github.com/util-linux/util-linux/blob/v2.42.4/lib/loopdev.c#L1760
Re: [PATCH] iotests/108: probe loop device setup
Posted by Eric Blake 1 month, 1 week ago
On Tue, Oct 13, 2026 at 09:08:17PM +0200, Ilya Leoshkevich wrote:
> 
> 
> On 10/13/26 20:53, Eric Blake wrote:
> > On Tue, Oct 13, 2026 at 08:28:00PM +0200, Ilya Leoshkevich wrote:
> > > Running iotests/108 in a Docker container, that has passwordless sudo
> > > configured, fails with:
> > > 
> > >      losetup: /home/user/src/qemu/build/scratch/qcow2-file-108/t.qcow2: failed to set up loop device: No such file or directory
> > > 
> > > because it incorrectly assumes losetup is allowed to do loop device
> > > setup, when in reality it can only list devices.
> > > 
> > > Fix by probing loop device setup, using the test script as a backing
> > > file. With this, the test is correctly skipped.
> > > 
> > > Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
> > > ---
> > >   tests/qemu-iotests/108 | 3 ++-
> > >   1 file changed, 2 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/tests/qemu-iotests/108 b/tests/qemu-iotests/108
> > > index 1de718188aa..adbaaf87095 100755
> > > --- a/tests/qemu-iotests/108
> > > +++ b/tests/qemu-iotests/108
> > > @@ -53,7 +53,8 @@ _supported_os Linux
> > >   _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
> > >   # This test either needs sudo -n losetup or FUSE exports to work
> > > -if sudo -n losetup &>/dev/null; then
> > > +if probe_dev=$(sudo -n losetup -r --show -f "$0" 2>/dev/null); then
> > > +    sudo -n losetup -d "$probe_dev"
> > 
> > Is 'sudo -n losetup -f' a simpler test?  It prints out the next
> > /dev/loopN value available only if a mount would succeed, which means
> > that it is a stronger test than the existing 'sudo -n losetup', but
> > also does not require a subsequent cleanup.
> 
> I don't think 'losetup -f' attempts a mount, since it works fine without
> privileges:
> 
> $ id -u
> 1000
> $ losetup -f
> /dev/loop0
> $ losetup -r -f /bin/true
> losetup: /bin/true: failed to set up loop device: Permission denied

Thanks for testing. In that case, I think your longer version is reasonable.

Reviewed-by: Eric Blake <eblake@redhat.com>

> 
> A quick glance at the source code [1] seems to confirm this: the
> iterator is immediately discarded after finding a free device name.
> The loop-control logic above looks similar.
> 
> [1]
> https://github.com/util-linux/util-linux/blob/v2.42.4/lib/loopdev.c#L1760
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.
Virtualization:  qemu.org | libguestfs.org