diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-04-07 16:09:45 +0200 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-04-10 15:52:29 +0200 |
commit | 41bc484906e973f6c91f8398a3ba309b7ee16f5a (patch) | |
tree | 57fad1132c0a90f01e527ac948f898ddea9863a4 /src/portable | |
parent | test-loop-block: reenable test on CI (diff) | |
download | systemd-41bc484906e973f6c91f8398a3ba309b7ee16f5a.tar.xz systemd-41bc484906e973f6c91f8398a3ba309b7ee16f5a.zip |
tree-wide: take BSD lock on loopback devices we dissect/mount/operate on
So here's something we should always keep in mind:
systemd-udevd actually does *two* things with BSD file locks on block
devices:
1. While it probes a device it takes a LOCK_SH lock. Thus everyone else
taking a LOCK_EX lock will temporarily block udev from probing
devices, which is good when making changes to it.
2. Whenever a device is closed after write (detected via inotify), udevd
will issue BLKRRPART (requesting the kernel to reread the partition
table). It does this while holding a LOCK_EX lock on the block
device. Thus anyone else taking LOCK_SH or LOCK_EX will temporarily
block udevd from issuing that ioctl. And that's quite relevant, since
the kernel will temporarily flush out all partitions while re-reading
the partition table and then create them anew. Thus it is smart to
take LOCK_SH when dissecting a block device to ensure that no
BLKRRPART is issued in the background, until we mounted the devices.
Diffstat (limited to 'src/portable')
-rw-r--r-- | src/portable/portable.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/portable/portable.c b/src/portable/portable.c index 0c10b161f0..7bba7b47e4 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -359,6 +359,10 @@ static int portable_extract_by_path( /* We now have a loopback block device, let's fork off a child in its own mount namespace, mount it * there, and extract the metadata we need. The metadata is sent from the child back to us. */ + r = loop_device_flock(d, LOCK_SH); + if (r < 0) + return log_debug_errno(r, "Failed to acquire lock on loopback block device: %m"); + BLOCK_SIGNALS(SIGCHLD); r = mkdtemp_malloc("/tmp/inspect-XXXXXX", &tmpdir); |