vfs_hooks(9) [netbsd man page]
VFS_HOOKS(9) BSD Kernel Developer's Manual VFS_HOOKS(9) NAME
vfs_hooks, vfs_hooks_unmount -- VFS hooks interface SYNOPSIS
#include <sys/param.h> #include <sys/mount.h> void vfs_hooks_unmount(struct mount *mp); DESCRIPTION
The VFS hooks interface provides a way for different kernel subsystems to attach custom functions to specific VFS operations. This enforces code separation by keeping the VFS's core sources uncluttered and makes all subsystem functionality reside in a single place. As an example, this interface is used by the NFS server code to automatically handle the exports list for each mount point. Hooks are described by a struct vfs_hooks object, as seen below: struct vfs_hooks { int (*vh_unmount)(struct mount *); }; For simplicity, each field is named after the VFS operation it refers to. The purpose of each member function, alongside some important notes, is shown below: vh_unmount(mp) This hook is executed during the unmount process of a file system. For more information about the purpose of each operation, see vfsops(9). Note that any of these fields may be a null pointer. After the definition of a struct vfs_hooks object, the kernel has to add it to the vfs_hooks link set using the VFS_HOOKS_ATTACH(struct vfs_hooks *) macro. Please note that this interface is incomplete on purpose to keep it in its smallest possible size (i.e., do not provide a hook that is not used). If you feel the need to hook a routine to a VFS operation that is not yet supported by this interface, just add it to the files described in CODE REFERENCES. FUNCTIONS
The following functions are provided to the VFS code to run the hooked functions: vfs_hooks_unmount(mp) Runs all hooks for the VFS unmount operation. Given that these operations shall not fail, it returns void. CODE REFERENCES
The VFS hooks interface is implemented within the files sys/kern/vfs_hooks.c and sys/sys/mount.h. SEE ALSO
intro(9), vfs(9), vfsops(9) HISTORY
The VFS hooks interface appeared in NetBSD 4.0. BSD
September 23, 2005 BSD
Check Out this Related Man Page
VFSSUBR(9) BSD Kernel Developer's Manual VFSSUBR(9) NAME
vfssubr, vfs_getnewfsid, vfs_getvfs, vfs_export, vfs_showexport, vfs_export_lookup, vfs_setpublicfs, vfs_mountedon, vfs_mountroot, vfs_unmountall, vfs_busy, vfs_unbusy, vfs_mountalloc, vfs_rootmountalloc, vfs_shutdown, vfs_attach, vfs_detach, vfs_reinit, vfs_getopsbyname, vfs_suspend, vfs_resume -- high-level interface to kernel file system interface SYNOPSIS
#include <sys/param.h> #include <sys/mount.h> #include <sys/vnode.h> void vfs_getnewfsid(struct mount *mp); struct mount * vfs_getvfs(fsid_t *fsid); int vfs_export_lookup(struct mount *mp, struct netexport *nep, struct export_args *argp); int vfs_setpublicfs(struct mount *mp, struct netexport *nep, struct export_args *argp); int vfs_mountedon(struct vnode *vp); int vfs_mountroot(void); void vfs_unmountall(struct lwp *l); int vfs_busy(struct mount *mp, int flags, struct simplelock *interlkp); void vfs_unbusy(struct mount *mp); struct mount * vfs_mountalloc(struct vfsops *vfs, struct vnode *vp); int vfs_rootmountalloc(char *fstypename, char *devname, struct mount **mpp); void vfs_shutdown(void); int vfs_attach(struct vfsops *vfs); int vfs_detach(struct vfsops *vfs); void vfs_reinit(void); struct vfsops * vfs_getopsbyname(const char *name); int vfs_suspend(struct mount *mp, int nowait); void vfs_resume(struct mount *mp); DESCRIPTION
The high-level functions described in this page are the interface to the kernel file system interface (VFS). FUNCTIONS
vfs_getnewfsid(mp) Get a new unique file system id type for the file system specified by the mount structure mp. The file system id type is stored in mp->mnt_stat.f_fsidx. vfs_getvfs(fsid) Lookup a mount point with the file system identifier fsid. vfs_export_lookup(mp, nep, argp) Check client permission on the exportable file system specified by the mount structure mp. The argument nam is the address of the networked client. This function is used by file system type specific functions to verify that the client can access the file sys- tem. vfs_setpublicfs(mp, nep, argp) Set the publicly exported file system specified by the mount structure mp. vfs_mountedon(vp) Check to see if a file system is mounted on a block device specified by the vnode vp. vfs_mountroot(void) Mount the root file system. vfs_unmountall(l) Unmount all file systems. vfs_busy(mp, flags, interlkp) Mark the mount point specified by mp as busy. This function is used to synchronize access and to delay unmounting. The interlock specified by argument interlkp is not released on failure. vfs_unbusy(mp) Free the busy file system specified by the mount structure mp. vfs_mountalloc(vfsops, vp) Allocate and initialise a mount structure, setting mnt_vnodecovered to vp and mnt_op to vfsops. On success, mark the mount struc- ture as busy and return its address. Otherwise, return NULL. vfs_rootmountalloc(fstypename, devname, mpp) Lookup a file system type specified by the name fstypename and if found allocate and initialise a mount structure for it. The allo- cated mount structure is returned in the address specified by mpp. The device the root file system was mounted from is specified by the argument devname and is recorded in the new mount structure. vfs_shutdown() Sync and unmount all file systems before shutting down. Invoked by cpu_reboot(9). vfs_attach(vfs) Establish file system vfs and initialise it. vfs_detach(vfs) Remove file system vfs from the kernel. vfs_reinit(void) Reinitialises all file systems within the kernel through file system-specific vfs operation (see vfsops(9)). vfs_getopsbyname(name) Given a file system name specified by name, look up the vfs operations for that file system (see vfsops(9)), or return NULL if file system isn't present in the kernel. vfs_suspend(mp, nowait) Request a mounted file system to suspend all operations. All new operations to the file system are stopped. After all operations in progress have completed, the file system is synced to disk and the function returns. If a file system suspension is currently in progress and nowait is set EWOULDBLOCK is returned. If the operation is successful, zero is returned, otherwise an appropriate error code is returned. vfs_resume(mp) Request a mounted file system to resume operations. CODE REFERENCES
The vfs interface functions are implemented within the files sys/kern/vfs_subr.c and sys/kern/vfs_init.c. SEE ALSO
intro(9), namei(9), vfs(9), vfsops(9), vnode(9), vnodeops(9) BSD
May 9, 2009 BSD