From 77d3deeab50a2fe368c1f94cdedebc867e65f157 Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Sun, 14 Aug 2022 17:49:59 +0000 Subject: [PATCH 3/7] vfs: switch vfs_mounted and vfs_unmounted to the new API Reviewed by: Differential Revision: --- sys/kern/vfs_mount.c | 15 ++++++++---- sys/security/mac_veriexec/mac_veriexec.c | 30 +++++++++++++++++------- sys/sys/eventhandler.h | 11 --------- sys/sys/mount.h | 15 ++++++++++++ 4 files changed, 48 insertions(+), 23 deletions(-) diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c index 7d74ec8b0a9e..9a20d3c4d7a7 100644 --- a/sys/kern/vfs_mount.c +++ b/sys/kern/vfs_mount.c @@ -122,8 +122,8 @@ struct mntlist mountlist = TAILQ_HEAD_INITIALIZER(mountlist); /* For any iteration/modification of mountlist */ struct mtx_padalign __exclusive_cache_line mountlist_mtx; -EVENTHANDLER_LIST_DEFINE(vfs_mounted); -EVENTHANDLER_LIST_DEFINE(vfs_unmounted); +EVENTHANDLER_SLEEPABLE_DEFINE(vfs_mounted); +EVENTHANDLER_SLEEPABLE_DEFINE(vfs_unmounted); static void vfs_deferred_unmount(void *arg, int pending); static struct timeout_task deferred_unmount_task; @@ -1076,6 +1076,7 @@ vfs_domount_first( ) { struct vattr va; + struct vfs_mounted_arg vma; struct mount *mp; struct vnode *newdp, *rootvp; int error, error1; @@ -1224,7 +1225,10 @@ vfs_domount_first( mtx_unlock(&mountlist_mtx); vfs_event_signal(NULL, VQ_MOUNT, 0); VOP_UNLOCK(vp); - EVENTHANDLER_DIRECT_INVOKE(vfs_mounted, mp, newdp, td); + vma.mp = mp; + vma.newdp = newdp; + vma.td = td; + EVENTHANDLER_SLEEPABLE_INVOKE(vfs_mounted, &vma); VOP_UNLOCK(newdp); mount_devctl_event("MOUNT", mp, false); mountcheckdirs(vp, newdp); @@ -1993,6 +1997,7 @@ vfs_deferred_unmount(void *argi __unused, int pending __unused) int dounmount(struct mount *mp, uint64_t flags, struct thread *td) { + struct vfs_unmounted_arg vua; struct mount_upper_node *upper; struct vnode *coveredvp, *rootvp; int error; @@ -2239,7 +2244,9 @@ dounmount(struct mount *mp, uint64_t flags, struct thread *td) mtx_lock(&mountlist_mtx); TAILQ_REMOVE(&mountlist, mp, mnt_list); mtx_unlock(&mountlist_mtx); - EVENTHANDLER_DIRECT_INVOKE(vfs_unmounted, mp, td); + vua.mp = mp; + vua.td = td; + EVENTHANDLER_SLEEPABLE_INVOKE(vfs_unmounted, &vua); if (coveredvp != NULL) { VI_LOCK(coveredvp); vn_irflag_unset_locked(coveredvp, VIRF_MOUNTPOINT); diff --git a/sys/security/mac_veriexec/mac_veriexec.c b/sys/security/mac_veriexec/mac_veriexec.c index 99a76abd4afb..f0c395003a17 100644 --- a/sys/security/mac_veriexec/mac_veriexec.c +++ b/sys/security/mac_veriexec/mac_veriexec.c @@ -183,12 +183,21 @@ sysctl_mac_veriexec_state(SYSCTL_HANDLER_ARGS) * @param td calling thread */ static void -mac_veriexec_vfs_mounted(void *arg __unused, struct mount *mp, - struct vnode *fsrootvp, struct thread *td) +mac_veriexec_vfs_mounted(void *arg) { + struct vfs_mounted_arg vma; + struct mount *mp; + struct vnode *fsrootvp; + struct thread *td; + struct vattr va; int error; + vma = arg; + mp = vma->mp; + fsrootvp = vma->newdp; + td = vma->td; + error = VOP_GETATTR(fsrootvp, &va, td->td_ucred); if (error) return; @@ -212,11 +221,18 @@ mac_veriexec_vfs_mounted(void *arg __unused, struct mount *mp, * @param td calling thread */ static void -mac_veriexec_vfs_unmounted(void *arg __unused, struct mount *mp, - struct thread *td) +mac_veriexec_vfs_unmounted(void *arg) { + struct vfs_unmounted_arg vua; + struct mount *mp; + struct thread *td; + dev_t fsid; + vua = arg; + mp = vua->mp; + td = vua->td; + fsid = SLOT(mp->mnt_label); if (fsid) { MAC_VERIEXEC_DBG(3, "fsid %ju, cleaning up mount", @@ -622,10 +638,8 @@ mac_veriexec_init(struct mac_policy_conf *mpc __unused) mac_veriexec_fingerprint_init(); /* Register event handlers */ - EVENTHANDLER_REGISTER(vfs_mounted, mac_veriexec_vfs_mounted, NULL, - EVENTHANDLER_PRI_FIRST); - EVENTHANDLER_REGISTER(vfs_unmounted, mac_veriexec_vfs_unmounted, NULL, - EVENTHANDLER_PRI_LAST); + EVENTHANDLER_SLEEPABLE_REGISTER(vfs_mounted, mac_veriexec_vfs_mounted, FIRST); + EVENTHANDLER_REGISTER(vfs_unmounted, mac_veriexec_vfs_unmounted, LAST); } /** diff --git a/sys/sys/eventhandler.h b/sys/sys/eventhandler.h index 634f8c526396..f08ffaa76251 100644 --- a/sys/sys/eventhandler.h +++ b/sys/sys/eventhandler.h @@ -219,17 +219,6 @@ EVENTHANDLER_DECLARE(mbuf_lowmem, vm_lowmem_handler_t); typedef void (*mountroot_handler_t)(void *); EVENTHANDLER_DECLARE(mountroot, mountroot_handler_t); -/* File system mount events */ -struct mount; -struct vnode; -struct thread; -typedef void (*vfs_mounted_notify_fn)(void *, struct mount *, struct vnode *, - struct thread *); -typedef void (*vfs_unmounted_notify_fn)(void *, struct mount *, - struct thread *); -EVENTHANDLER_DECLARE(vfs_mounted, vfs_mounted_notify_fn); -EVENTHANDLER_DECLARE(vfs_unmounted, vfs_unmounted_notify_fn); - /* * application dump event */ diff --git a/sys/sys/mount.h b/sys/sys/mount.h index ffb2676258f3..fa9449bc70b2 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -44,6 +44,7 @@ #include #include #include +#include #endif /* @@ -1167,6 +1168,20 @@ void resume_all_fs(void); _mpcpu->mntp_##count -= val; \ } while (0) +struct vfs_mounted_arg { + struct mount *mp; + struct vnode *newdp; + struct thread *td; +}; + +struct vfs_unmounted_arg { + struct mount *mp; + struct thread *td; +}; + +EVENTHANDLER_SLEEPABLE_DECLARE(vfs_mounted); +EVENTHANDLER_SLEEPABLE_DECLARE(vfs_unmounted); + #else /* !_KERNEL */ #include -- 2.34.1