]> git.ipfire.org Git - thirdparty/systemd.git/commit
loop-util: reopen device node if we shortcut loop device creation
authorLennart Poettering <lennart@poettering.net>
Thu, 4 Nov 2021 14:01:33 +0000 (15:01 +0100)
committerTopi Miettinen <topimiettinen@users.noreply.github.com>
Fri, 5 Nov 2021 07:08:16 +0000 (07:08 +0000)
commitd7654742eeb808c9a82fcf4ef3591d5cd582190f
treeb85bb0816cc89aa0e7ab421f27edc89c5f35900e
parent7544461cd02d9ddf347e0716ecfc95f86c00c61c
loop-util: reopen device node if we shortcut loop device creation

The LoopDevice object supports a shortcut: if the backing fd we are
supposed to create a loopback device of refers to a
block device alrady then we'll use it as is – if we can – instead of
setting up an unnecessary loopback device that would be pretty much
the same as its backing device.

Previously, when doing this we'd just dup() the original backing fd and
use that. But that's problematic in case O_DIRECT was set on the fd,
since we'll keep that flag set on our copy too, which means we can't do
simple, regular IO on it anymore.

Thus, let's reopen the inode in this case with the exact access flags
we'd apply if we'd actually allocate and open a new loopback device.

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