diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-10-18 22:34:54 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-10-19 15:38:21 +0200 |
commit | b9a9748abcba4aead6db6600dd27f0feeb758b45 (patch) | |
tree | 390ea5bddcb434861f5594cd52f8be0cd2305785 /src/shared/loop-util.c | |
parent | loop-util: enable LO_FLAGS_DIRECT_IO by default on loopback devices (diff) | |
download | systemd-b9a9748abcba4aead6db6600dd27f0feeb758b45.tar.xz systemd-b9a9748abcba4aead6db6600dd27f0feeb758b45.zip |
loop-util: work around cache invalidation bug in older kernels
Inspired by the discussions in #21003.
Inspired in particular by what Android apexd does:
https://android.googlesource.com/platform/system/apex/+/refs/heads/master/apexd/apexd_loop.cpp
Diffstat (limited to 'src/shared/loop-util.c')
-rw-r--r-- | src/shared/loop-util.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index dbd0266390..072acc8c47 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -326,6 +326,21 @@ static int loop_configure( random_u64_range(UINT64_C(240) * USEC_PER_MSEC * n_attempts/64)); } + /* Work around a kernel bug, where changing offset/size of the loopback device doesn't correctly + * invalidate the buffer cache. For details see: + * + * https://android.googlesource.com/platform/system/apex/+/bef74542fbbb4cd629793f4efee8e0053b360570 + * + * This was fixed in kernel 5.0, see: + * + * https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=5db470e229e22b7eda6e23b5566e532c96fb5bc3 + * + * We'll run the work-around here in the legacy LOOP_SET_STATUS64 codepath. In the LOOP_CONFIGURE + * codepath above it should not be necessary. */ + if (c->info.lo_offset != 0 || c->info.lo_sizelimit != 0) + if (ioctl(fd, BLKFLSBUF, 0) < 0) + log_debug_errno(errno, "Failed to issue BLKFLSBUF ioctl, ignoring: %m"); + /* LO_FLAGS_DIRECT_IO is a flags we need to configure via explicit ioctls. */ if (FLAGS_SET(c->info.lo_flags, LO_FLAGS_DIRECT_IO)) { unsigned long b = 1; |