Home | History | Annotate | Line # | Download | only in kern
vfs_hooks.c revision 1.2
      1 /*	$NetBSD: vfs_hooks.c,v 1.2 2005/12/11 12:24:30 christos Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2005 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Julio M. Merino Vidal.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * VFS hooks.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: vfs_hooks.c,v 1.2 2005/12/11 12:24:30 christos Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/mount.h>
     48 
     49 /*
     50  * Static list of file system specific hook sets supported by the kernel.
     51  */
     52 __link_set_decl(vfs_hooks, struct vfs_hooks);
     53 
     54 /*
     55  * Initialize a VFS hook set that does nothing.  This is to ensure that
     56  * we have, at the very least, one item in the link set.  Otherwise,
     57  * ld(1) will complain.
     58  */
     59 static struct vfs_hooks null_hooks = {
     60 	NULL		/* vh_unmount */
     61 };
     62 VFS_HOOKS_ATTACH(null_hooks);
     63 
     64 /*
     65  * Macro to be used in one of the vfs_hooks_* function for hooks that
     66  * return an error code.  Calls will stop as soon as one of the hooks
     67  * fails.
     68  */
     69 #define VFS_HOOKS_W_ERROR(func, args)					\
     70 	int error;							\
     71 	struct vfs_hooks * const *hp;					\
     72  									\
     73 	error = 0;							\
     74  									\
     75 	__link_set_foreach(hp, vfs_hooks) {				\
     76 		if ((*hp)-> func != NULL) {				\
     77 			error = (*hp)-> func args;			\
     78 			if (error != 0)					\
     79 				break;					\
     80 		}							\
     81 	}								\
     82  									\
     83 	return error;
     84 
     85 /*
     86  * Macro to be used in one of the vfs_hooks_* function for hooks that
     87  * do not return any error code.  All hooks will be executed
     88  * unconditionally.
     89  */
     90 #define VFS_HOOKS_WO_ERROR(func, fargs, hook, hargs)			\
     91 void									\
     92 func fargs								\
     93 {									\
     94 	struct vfs_hooks * const *hp;					\
     95  									\
     96 	__link_set_foreach(hp, vfs_hooks) {				\
     97 		if ((*hp)-> hook != NULL)				\
     98 			(*hp)-> hook hargs;				\
     99 	}								\
    100 }
    101 
    102 /*
    103  * Routines to iterate over VFS hooks lists and execute them.
    104  */
    105 
    106 VFS_HOOKS_WO_ERROR(vfs_hooks_unmount, (struct mount *mp), vh_unmount, (mp));
    107 
    108 /*
    109 void
    110 vfs_hooks_unmount(struct mount *mp)
    111 {
    112 
    113 	VFS_HOOKS_WO_ERROR(vh_unmount, (mp));
    114 }
    115 */
    116