iotests/108: probe loop device setup
PATCH 1/1 iotests/108: probe loop device setup
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.
--- tests/qemu-iotests/108 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qemu-iotests/108 +2 -1
@@ -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
Signature · 1 line
2.56.0
Quoted 21 lines · Ilya Leoshkevich
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 directorybecause 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 <[email protected]>--- tests/qemu-iotests/108 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tests/qemu-iotests/108 +0
-0
tests/qemu-iotests/108 _supported_os Linux · line 57
Quoted 6 lines
tests/qemu-iotests/108 +2
-1@@ -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.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Quoted 24 lines · Eric Blake
Quoted 23 lines · Ilya Leoshkevich
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 directorybecause 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 <[email protected]>--- tests/qemu-iotests/108 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)tests/qemu-iotests/108 +0
-0@@ -53,7 +53,8 @@ _supported_os Linux _unsupported_imgopts 'refcount_bits=\([^1]\|.\([^6]\|$\)\)' data_file
Quoted 9 lines
tests/qemu-iotests/108 _supported_os Linux · line 57
Quoted 4 lines
tests/qemu-iotests/108 +2
-1# 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/loopNvalue 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
Eric Blake
Reviewed-byQuoted 39 lines · Ilya Leoshkevich
Quoted 17 lines · Eric Blake
Quoted 16 lines · Ilya Leoshkevich
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 directorybecause 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 <[email protected]>--- tests/qemu-iotests/108 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)Quoted 15 lines
tests/qemu-iotests/108 _supported_os Linux · line 56
Quoted 10 lines
tests/qemu-iotests/108 +2
-1@@ -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/loopNvalue 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:
Quoted 6 lines
$ 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.
Quoted 8 lines
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
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Am 13.10.2026 um 20:28 hat Ilya Leoshkevich geschrieben:
Quoted 5 lines
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
Quoted 7 lines
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 <[email protected]>
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