Opened 5 years ago
#19413 new defect
Silent fail of inotify_add_watch
| Reported by: | elvanderb | Owned by: | |
|---|---|---|---|
| Component: | USB | Version: | VirtualBox 6.1.4 |
| Keywords: | USB redirection | Cc: | |
| Guest type: | all | Host type: | Linux |
Description
To watch new USB devices, VBoxSVC use inotify_add_watch on /dev/vboxusb. If inotify_add_watch fails, USB redirection will silently fail (no log nor warnings).
inotify_add_watch may fail if the limit of watches is already reached. The limit is quite low on a default stable debian install (8192) and several modern text editors use a lot of watches to... watch directories and subdirectories.
Step to reproduce the problem: 1] make sure that VBoxSVC isn't running 2] check that the limit is not too high cat /proc/sys/fs/inotify/max_user_watches, if it is, just temporarily decrease it: echo 1000 | sudo tee /proc/sys/fs/inotify/max_user_watches 3] drain all the watches (for example by executing inotifywatch -r on a folder with a lot of subfolders. 4] run VBoxSVC, you may strace it to make sure that inotify_add_watch fails 5] run VBoxManage list usbhost 6] observe that inotify_add_watch fails in VBoxSVC and that VBoxManage list usbhost returns nothing. 7] [optionnal] use this script to check who's using all the watches: https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/inotify-consumers
VBoxSVC should return an error that VBoxManage list usbhost and VirtualBox gui client could display to easily diagnose the problem and maybe hint on a solution (kill the process using all the watches or increase the limit).
There may be other use of inotify_add_watch in the VBox codebase and there may be other code path to check (for example, there is also a restriction on the number of inotify instances, cf. /proc/sys/fs/inotify/max_user_instances, that may cause inotify_init to fail).

