io/ioutil is deprecated since Go 1.16. Besides, we now have a nice
t.TempDir() function which simplifies things a lot.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1. Background.
Since the dawn of times mount-utils package tries to work around the bug
in the Linux kernel, which results in occasional incomplete read of
mountinfo entries (from either /proc/mounts or /proc/PID/mountinfo).
The workaround used is to read the whole file twice and compare the two
blobs. If they differ, try again.
The kernel bug is manifesting when mountinfo read is performed
concurrently with an unmount, and can easily be reproduced by running
lots of mounts and unmounts in parallel with the code reading mountinfo.
For one such reproducer, see https://github.com/kolyshkin/procfs-test.
On a Kubernetes node with lots of short-lived containers, mounts and
unmounts are quite frequent. This leads to the occasional bug, and
surely results in much more re-reads of mountinfo, because the
workaround assumes its content is more-or-less static.
The good news is, this bug was finally fixed by kernel commit
9f6c61f96f2d97, which made its way into Linux 5.8.
2. The issue.
The code still read every file at least twice, and up to 10 times. The
chance of re-reading is higher if there is a mount or unmount going on
at the same time. The result is higher system and kernel load, and
degraded performance.
3. The fix.
As the re-reading is not necessary for newer kernels, let's check the
kernel version and skip the workaround if running Linux >= 5.8.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Here's before/after comparison.
[kir@kir-rhat mount-utils]$ benchstat before after
name old time/op new time/op delta
IsMountPointMatch-4 707ns ± 1% 40ns ± 1% -94.39% (p=0.008 n=5+5)
name old alloc/op new alloc/op delta
IsMountPointMatch-4 264B ± 0% 0B -100.00% (p=0.008 n=5+5)
name old allocs/op new allocs/op delta
IsMountPointMatch-4 11.0 ± 0% 0.0 -100.00% (p=0.008 n=5+5)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Commit 44bea35804 added a code to return unwrapped fs.ErrNotExist
error in case filepath.EvalSymlinks failed a wrapped one.
This never worked because of a copy/paste bug.
Fix this.
Fixes: 44bea35804
Cc: Manu Gupta <manugupt1@gmail.com>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
gofumpt is a superset of go fmt, enabling some more strict formatting
rules, mostly to improve code readability.
No functional or code change, just formatting.
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
When running kubeadm / installing k8s early during boot,
the CA certificate can be generated before time is synchronised
and time is jumped backward.
Make notBefore 1 hour in the past to accept small clock jump.
Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
When running iscsi test, use dbus socket from the host. targetcli uses the
socket for synchronization.
Recent Fedoras can run dbus only via systemd, which is cumbersome here.
Once DeferCleanup for the worker goroutine is invoked, there's no need to
continue doing anything anymore in that goroutine and it can return
immediately, without reporting the "context canceled" error because there is no
other reason for that.