tests/qemu-iotests/108 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
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
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
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
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
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
© 2016 - 2026 Red Hat, Inc.