]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/shared/loop-util.c
loop-util: if a loopback device we want to use still has partitions, do something...
authorLennart Poettering <lennart@poettering.net>
Fri, 25 Sep 2020 15:12:34 +0000 (17:12 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 22 Oct 2020 12:58:27 +0000 (14:58 +0200)
commit021bf175289537a67345b0ca9d5d6f163a1eaf7c
treee11073fd119ad10179003e550384830991bcd1f5
parent4ba86848c92cf4d2d5466f43b4a42ae4ceddb8b0
loop-util: if a loopback device we want to use still has partitions, do something about it

On current kernels (5.8 for example) under some conditions I don't fully
grok it might happen that a detached loopback block device still has
partition block devices around. Accessing these partition block devices
results in EIO errors (that also fill up dmesg). These devices cannot be
claned up with LOOP_CLR_FD (since the main device already is officially
detached), nor with LOOP_CTL_DELETE (returns EBUSY as long as the
partitions still exist). This is a kernel bug. But it appears to apply
to all recent kernels. I cannot really pin down what triggers this,
suffice to say our heavy-duty test can trigger it.

Either way, let's do something about it: when we notice this state we'll
attach an empty file to it, which is guaranteed to have to part table.
This makes the partitions go away. After closing/reoping the device we
hence are good to go again. ugly workaround, but I think OK enough to
use.

The net result is: with this commit, we'll guarantee that by the time we
attach a file to the loopback device we have zero kernel partitions
associated with it. Thus if we then wait for the kernel partitions we
need to appear we should have entirely reliable behaviour even if
loopback devices by the name are heavily recycled and udev events reach
us very late.

Fixes: #16858
src/shared/loop-util.c