Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

losetup --find reports a lost loop device even in a container #2824

Open
mrc0mmand opened this issue Mar 3, 2024 · 3 comments
Open

losetup --find reports a lost loop device even in a container #2824

mrc0mmand opened this issue Mar 3, 2024 · 3 comments
Labels
TODO We going to think about it ;-)

Comments

@mrc0mmand
Copy link
Member

mrc0mmand commented Mar 3, 2024

While trying to upgrade a Fedora Rawhide job in our upstream systemd CI I noticed one strange test fail. This test uses losetup --find to check if loop devices are available (which is admittedly not ideal), and since a6ca045 and 556dac8 this reports a lost loop device even in a container without access to loop devices:

# systemd-nspawn -D / --volatile=yes bash
Spawning container localhost.localdomain on /.
Press Ctrl-] three times within 1s to kill container.
bash-5.2# stat /dev/loop-control
stat: cannot statx '/dev/loop-control': No such file or directory
bash-5.2# losetup --find
/dev/loop0 (lost)
bash-5.2# echo $?
0

Is this expected?

Reproducible with both util-linux-2.40-0.11.rc1.fc41.x86_64 and latest master.

@karelzak
Copy link
Collaborator

karelzak commented Mar 4, 2024

The file /dev/loop-control is optional, and if it's not available, then it scans for /dev/loopN files. It seems that it was able to get /dev/loop0, but later it disappeared, so it's reported as lost.

LOOPDEV_DEBUG=all losetup --find may provide more details.

Not sure why do you see the problem (maybe more tests running in parallel, udevadm settle is good friend).
I'm not able to reproduce it:

# systemd-nspawn -D / --volatile=yes bash
Spawning container vm-10-0-187-68.hosted.upshift.rdu2.redhat.com on /.
Press Ctrl-] three times within 1s to kill container.

bash-5.2#  losetup --find
/dev/loop0
bash-5.2# losetup -V
losetup from util-linux 2.40-rc1

@mrc0mmand
Copy link
Member Author

mrc0mmand commented Mar 4, 2024

Ah, interesting, thank you. I think the reason here why this happens is that I have (or had) /dev/loop0 used on the host machine, so it's then reported as lost in the container, since it's not there (but it's still present in /sys).

[root@localhost ~]# losetup --find
/dev/loop0
[root@localhost ~]# systemd-nspawn -D / --volatile=yes --bind $PWD:/build bash
Spawning container localhost.localdomain on /.
Press Ctrl-] three times within 1s to kill container.
bash-5.2# LOOPDEV_DEBUG=all losetup --find
2: loopdev:      CXT: [0x7ffc49e1e7d0]: initialize context
2: loopdev:      CXT: [0x7ffc49e1e7d0]: init: ignore ioctls
2: loopdev:      CXT: [0x7ffc49e1e7d0]: find_unused requested
2: loopdev:      CXT: [0x7ffc49e1e7d0]: using loop scan
2: loopdev:     ITER: [0x7ffc49e1e9b8]: initialize
2: loopdev:     ITER: [0x7ffc49e1e9b8]: next
2: loopdev:     ITER: [0x7ffc49e1e9b8]: next: default check
2: loopdev:      CXT: [0x7ffc49e1e7d0]: loop0 name assigned
2: loopdev:      CXT: [0x7ffc49e1e7d0]: get_offset [rc=-22]
2: loopdev:     ITER: [0x7ffc49e1e9b8]: de-initialize
2: loopdev:      CXT: [0x7ffc49e1e7d0]: find_unused by scan [rc=0]
/dev/loop0 (lost)
2: loopdev:      CXT: [0x7ffc49e1e7d0]: de-initialize
2: loopdev:     ITER: [0x7ffc49e1e9b8]: de-initialize
# ls /sys/block/
loop0  vda  zram0

So I guess the test needs to be updated on our side, to not use losetup --find to check if loop devices are available.

@karelzak
Copy link
Collaborator

karelzak commented Mar 4, 2024

Maybe losetup should be more competent when testing if the device is used.

Now (in your case) it checks for "offset" (sysfs file loop/offset, the file is missing so it assumes the device is unused). Maybe when it scans for the devices in sysfs it should also check for the device lost and ignore such devices.

@karelzak karelzak added the TODO We going to think about it ;-) label Mar 4, 2024
mrc0mmand added a commit to mrc0mmand/systemd that referenced this issue Mar 27, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824
chunyi-wu pushed a commit to chunyi-wu/systemd that referenced this issue Apr 3, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824
mrc0mmand added a commit to mrc0mmand/systemd-stable that referenced this issue Apr 15, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824

(cherry picked from commit 0348b50)
bluca pushed a commit to systemd/systemd-stable that referenced this issue Apr 15, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824

(cherry picked from commit 0348b50)
bluca pushed a commit to bluca/systemd-stable that referenced this issue Apr 24, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824

(cherry picked from commit 0348b50)
(cherry picked from commit 5ab85d7)
bluca pushed a commit to bluca/systemd-stable that referenced this issue Apr 25, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824

(cherry picked from commit 0348b50)
(cherry picked from commit 5ab85d7)
bluca pushed a commit to systemd/systemd-stable that referenced this issue Apr 25, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824

(cherry picked from commit 0348b50)
(cherry picked from commit 5ab85d7)
bluca pushed a commit to bluca/systemd-stable that referenced this issue Apr 25, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824

(cherry picked from commit 0348b50)
(cherry picked from commit 5ab85d7)
(cherry picked from commit c960f9a)
bluca pushed a commit to systemd/systemd-stable that referenced this issue Apr 25, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824

(cherry picked from commit 0348b50)
(cherry picked from commit 5ab85d7)
(cherry picked from commit c960f9a)
bluca pushed a commit to bluca/systemd-stable that referenced this issue Apr 25, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824

(cherry picked from commit 0348b50)
(cherry picked from commit 5ab85d7)
(cherry picked from commit c960f9a)
(cherry picked from commit 686eb93)
bluca pushed a commit to systemd/systemd-stable that referenced this issue Apr 26, 2024
losetup in util-linux 2.40 started reporting lost loop devices [0] and
it has an unfortunate side-effect where it reports lost devices even in
containers, which then makes the loop device check "falsely" pass [1].

Let's just check for /dev/loop-control explicitly to "work around" this.

[0] util-linux/util-linux@a6ca045
[1] util-linux/util-linux#2824

(cherry picked from commit 0348b50)
(cherry picked from commit 5ab85d7)
(cherry picked from commit c960f9a)
(cherry picked from commit 686eb93)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TODO We going to think about it ;-)
Projects
None yet
Development

No branches or pull requests

2 participants