Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lxd/fsmonitor/drivers/driver/fsnotify: Switch away from github.com/fs…
…notify/fsnotify package There is an unfortunate behaviour in the fsnotify package in that it watches for all events on a path, and doesn't give the user the option of only watching for specific events. This means that when watching, for example on /dev/net, any writes to /dev/net/tun will cause a WRITE event to be sent to LXD. As you can image, for high traffic interfaces this can cause many events and causes LXD to use a lot of CPU. This is equally the case for other devices that can be written to, such as block devices. The issue is identified in the upstream package (fsnotify/fsnotify#7) but there doesn't seem to be any consensus on how to move forward so the issue has languished. LXD however doesn't need cross-platform support that fsnotify package offers and so can use a lightweight wrapper around the inotify feature (which is what we use with fsnotify anyway). There used to be an inotify wrapper at golang.org/x/exp/inotify which has subsequently moved to gopkg.in/fsnotify.v0. Unfortunately that doesn't support go mod and so isn't usable by LXD. Its also not been updated since 2015. There is however a fork of golang.org/x/exp/inotify at https://github.com/kubernetes/utils/tree/master/inotify which has seen some minor maintenance this year. This package also has go mod support. This commit also makes the following changes: - Avoids the need to make a stat syscall to detect if event is for a directory by using the InIsdir flag in the event Mask. - Avoids calling every registered handler for every new directory and instead performs a path prefix match. - Improves comments and readability. - Cleans the path coming from the event to ensure comparison with registered handlers works. - Reduces repetition in event action logic. Fixes #11151 Signed-off-by: Thomas Parrott <thomas.parrott@canonical.com>
- Loading branch information