]> git.ipfire.org Git - thirdparty/systemd.git/commit
loop-util: rework how we lock loopback block devices
authorLennart Poettering <lennart@poettering.net>
Thu, 1 Sep 2022 13:00:30 +0000 (15:00 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 1 Sep 2022 20:05:32 +0000 (22:05 +0200)
commit7f52206a2bc128f9ae8306db43aa6e2f7d916f82
tree71abcc3bae9c57aa3ceb041e2a3cfea0c193c95b
parent234c2e16e5686d1a49fe84e534d4edb2db8d3719
loop-util: rework how we lock loopback block devices

Let's rework how we lock loopback block devices in two ways:

1. Lock a separate fd, instead of the main block device fd. We already
   did that for our internal locking when allocating loopback block
   devices, but do so for the exposed locking (i.e.
   loop_device_flock()), too, so that the lock is independent of the
   main fd we actually use of IO.

2. Instead of locking the device during allocation of the loopback
   device, then unlocking it (which will make udev run), and then
   re-locking things if we need, let's instead just keep the lock the
   whole time, to make things a bit safer and faster, and not have to
   wait for udev at all. This is done by adding a "lock_op" parameter to
   loop device allocation functions that declares the initial state of
   the lock, and is one of LOCK_UN/LOCK_SH/LOCK_EX. This change also
   shortens a lot of code, since we allocate + immediately lock loopback
   devices pretty much everywhere.
12 files changed:
src/core/namespace.c
src/dissect/dissect.c
src/home/homework-luks.c
src/nspawn/nspawn.c
src/partition/repart.c
src/portable/portable.c
src/shared/discover-image.c
src/shared/dissect-image.c
src/shared/loop-util.c
src/shared/loop-util.h
src/sysext/sysext.c
src/test/test-loop-block.c