1*11a6dbe7Smartin.\" $NetBSD: vfs_hooks.9,v 1.4 2008/04/30 13:10:59 martin Exp $ 22a3e5eebSjmmv.\" 32a3e5eebSjmmv.\" Copyright (c) 2005 The NetBSD Foundation, Inc. 42a3e5eebSjmmv.\" All rights reserved. 52a3e5eebSjmmv.\" 62a3e5eebSjmmv.\" This code is derived from software contributed to The NetBSD Foundation 72a3e5eebSjmmv.\" by Julio M. Merino Vidal. 82a3e5eebSjmmv.\" 92a3e5eebSjmmv.\" Redistribution and use in source and binary forms, with or without 102a3e5eebSjmmv.\" modification, are permitted provided that the following conditions 112a3e5eebSjmmv.\" are met: 122a3e5eebSjmmv.\" 1. Redistributions of source code must retain the above copyright 132a3e5eebSjmmv.\" notice, this list of conditions and the following disclaimer. 142a3e5eebSjmmv.\" 2. Redistributions in binary form must reproduce the above copyright 152a3e5eebSjmmv.\" notice, this list of conditions and the following disclaimer in the 162a3e5eebSjmmv.\" documentation and/or other materials provided with the distribution. 172a3e5eebSjmmv.\" 182a3e5eebSjmmv.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 192a3e5eebSjmmv.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 202a3e5eebSjmmv.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 212a3e5eebSjmmv.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 222a3e5eebSjmmv.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 232a3e5eebSjmmv.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 242a3e5eebSjmmv.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 252a3e5eebSjmmv.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 262a3e5eebSjmmv.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 272a3e5eebSjmmv.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 282a3e5eebSjmmv.\" POSSIBILITY OF SUCH DAMAGE. 292a3e5eebSjmmv.\" 302a3e5eebSjmmv.Dd September 23, 2005 312a3e5eebSjmmv.Dt VFS_HOOKS 9 322a3e5eebSjmmv.Os 332a3e5eebSjmmv.Sh NAME 342a3e5eebSjmmv.Nm vfs_hooks , 352a3e5eebSjmmv.Nm vfs_hooks_unmount 362a3e5eebSjmmv.Nd VFS hooks interface 372a3e5eebSjmmv.Sh SYNOPSIS 382a3e5eebSjmmv.In sys/param.h 392a3e5eebSjmmv.In sys/mount.h 402a3e5eebSjmmv.Ft void 412a3e5eebSjmmv.Fn vfs_hooks_unmount "struct mount *mp" 422a3e5eebSjmmv.Sh DESCRIPTION 432a3e5eebSjmmvThe VFS hooks interface provides a way for different kernel subsystems to 442a3e5eebSjmmvattach custom functions to specific VFS operations. 452a3e5eebSjmmvThis enforces code separation by keeping the VFS's core sources uncluttered 462a3e5eebSjmmvand makes all subsystem functionality reside in a single place. 472a3e5eebSjmmvAs an example, this interface is used by the NFS server code to automatically 482a3e5eebSjmmvhandle the exports list for each mount point. 492a3e5eebSjmmv.Pp 502a3e5eebSjmmvHooks are described by a 512a3e5eebSjmmv.Ft struct vfs_hooks 522a3e5eebSjmmvobject, as seen below: 532a3e5eebSjmmv.Bd -literal 542a3e5eebSjmmvstruct vfs_hooks { 552a3e5eebSjmmv int (*vh_unmount)(struct mount *); 562a3e5eebSjmmv}; 572a3e5eebSjmmv.Ed 582a3e5eebSjmmv.Pp 592a3e5eebSjmmvFor simplicity, each field is named after the VFS operation it refers to. 602a3e5eebSjmmvThe purpose of each member function, alongside some important notes, is 612a3e5eebSjmmvshown below: 622a3e5eebSjmmv.Bl -tag -width compat 632a3e5eebSjmmv.It Fn vh_unmount "mp" 642a3e5eebSjmmvThis hook is executed during the unmount process of a file system. 652a3e5eebSjmmv.El 662a3e5eebSjmmv.Pp 672a3e5eebSjmmvFor more information about the purpose of each operation, see 682a3e5eebSjmmv.Xr vfsops 9 . 692a3e5eebSjmmvNote that any of these fields may be a null pointer. 702a3e5eebSjmmv.Pp 712a3e5eebSjmmvAfter the definition of a 722a3e5eebSjmmv.Ft struct vfs_hooks 732a3e5eebSjmmvobject, the kernel has to add it to the 7450da23b1Swiz.Va vfs_hooks 752a3e5eebSjmmvlink set using the 762a3e5eebSjmmv.Fn VFS_HOOKS_ATTACH "struct vfs_hooks *" 772a3e5eebSjmmvmacro. 782a3e5eebSjmmv.Pp 792a3e5eebSjmmvPlease note that this interface is incomplete on purpose to keep it in its 802a3e5eebSjmmvsmallest possible size (i.e., do not provide a hook that is not used). 812a3e5eebSjmmvIf you feel the need to hook a routine to a VFS operation that is not yet 822a3e5eebSjmmvsupported by this interface, just add it to the files described in 832a3e5eebSjmmv.Sx CODE REFERENCES . 842a3e5eebSjmmv.Sh FUNCTIONS 852a3e5eebSjmmvThe following functions are provided to the VFS code to run the hooked 862a3e5eebSjmmvfunctions: 872a3e5eebSjmmv.Bl -tag -width compact 882a3e5eebSjmmv.It Fn vfs_hooks_unmount "mp" 892a3e5eebSjmmvRuns all hooks for the VFS unmount operation. 902a3e5eebSjmmvGiven that these operations shall not fail, it returns 912a3e5eebSjmmv.Ft void . 92b5550921Syamt.El 932a3e5eebSjmmv.Sh CODE REFERENCES 942a3e5eebSjmmvThe VFS hooks interface is implemented within the files 952a3e5eebSjmmv.Pa sys/kern/vfs_hooks.c 962a3e5eebSjmmvand 972a3e5eebSjmmv.Pa sys/sys/mount.h . 982a3e5eebSjmmv.Sh SEE ALSO 992a3e5eebSjmmv.Xr intro 9 , 1002a3e5eebSjmmv.Xr vfs 9 , 1012a3e5eebSjmmv.Xr vfsops 9 1022a3e5eebSjmmv.Sh HISTORY 1032a3e5eebSjmmvThe VFS hooks interface appeared in 1042a3e5eebSjmmv.Nx 4.0 . 105