NetBSD/share/man/man9/vfs_hooks.9

112 lines
4.1 KiB
Groff

.\" $NetBSD: vfs_hooks.9,v 1.3 2006/01/16 22:05:21 yamt Exp $
.\"
.\" Copyright (c) 2005 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Julio M. Merino Vidal.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the NetBSD
.\" Foundation, Inc. and its contributors.
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
.\" contributors may be used to endorse or promote products derived
.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd September 23, 2005
.Dt VFS_HOOKS 9
.Os
.Sh NAME
.Nm vfs_hooks ,
.Nm vfs_hooks_unmount
.Nd VFS hooks interface
.Sh SYNOPSIS
.In sys/param.h
.In sys/mount.h
.Ft void
.Fn vfs_hooks_unmount "struct mount *mp"
.Sh 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.
.Pp
Hooks are described by a
.Ft struct vfs_hooks
object, as seen below:
.Bd -literal
struct vfs_hooks {
int (*vh_unmount)(struct mount *);
};
.Ed
.Pp
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:
.Bl -tag -width compat
.It Fn vh_unmount "mp"
This hook is executed during the unmount process of a file system.
.El
.Pp
For more information about the purpose of each operation, see
.Xr vfsops 9 .
Note that any of these fields may be a null pointer.
.Pp
After the definition of a
.Ft struct vfs_hooks
object, the kernel has to add it to the
.Va vfs_hooks
link set using the
.Fn VFS_HOOKS_ATTACH "struct vfs_hooks *"
macro.
.Pp
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
.Sx CODE REFERENCES .
.Sh FUNCTIONS
The following functions are provided to the VFS code to run the hooked
functions:
.Bl -tag -width compact
.It Fn vfs_hooks_unmount "mp"
Runs all hooks for the VFS unmount operation.
Given that these operations shall not fail, it returns
.Ft void .
.El
.Sh CODE REFERENCES
The VFS hooks interface is implemented within the files
.Pa sys/kern/vfs_hooks.c
and
.Pa sys/sys/mount.h .
.Sh SEE ALSO
.Xr intro 9 ,
.Xr vfs 9 ,
.Xr vfsops 9
.Sh HISTORY
The VFS hooks interface appeared in
.Nx 4.0 .