From 4039c53163a3a9456e0c64468e5c9e0e6221286d Mon Sep 17 00:00:00 2001 From: Bryan Drewery Date: Mon, 7 Mar 2016 21:39:29 +0000 Subject: [PATCH] Require kldunload -f to unload. Code may still be executing from the wrappers at unload time and thus is not generally safe to unload. Converting the wrappers to use EVENTHANDLER(9) will allow this to safely drain on active threads in hooks. More work on EVENTHANDLER(9) is needed first. MFC after: 1 week Sponsored by: EMC / Isilon Storage Division --- share/man/man4/filemon.4 | 3 +++ sys/dev/filemon/filemon.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/share/man/man4/filemon.4 b/share/man/man4/filemon.4 index c0b4a51c5b4a..a006fd2d573d 100644 --- a/share/man/man4/filemon.4 +++ b/share/man/man4/filemon.4 @@ -194,3 +194,6 @@ Only children of the set process are logged. Processes can escape being traced by double forking. This is not seen as a problem as the intended use is build monitoring, which does not make sense to have daemons for. +.Pp +Unloading the module may panic the system, thus requires using +.Ic kldunload -f . diff --git a/sys/dev/filemon/filemon.c b/sys/dev/filemon/filemon.c index ed0ead535f93..78bfbb3dc7eb 100644 --- a/sys/dev/filemon/filemon.c +++ b/sys/dev/filemon/filemon.c @@ -68,8 +68,6 @@ extern struct sysentvec elf64_freebsd_sysvec; static d_close_t filemon_close; static d_ioctl_t filemon_ioctl; static d_open_t filemon_open; -static int filemon_unload(void); -static void filemon_load(void *); static struct cdevsw filemon_cdevsw = { .d_version = D_VERSION, @@ -301,6 +299,13 @@ filemon_modevent(module_t mod __unused, int type, void *data) error = filemon_unload(); break; + case MOD_QUIESCE: + /* + * The wrapper implementation is unsafe for reliable unload. + * Require forcing an unload. + */ + error = EBUSY; + case MOD_SHUTDOWN: break;