1 /* $NetBSD: vfs_hooks.c,v 1.5 2008/11/19 18:36:07 ad Exp $ */
4 * Copyright (c) 2005 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Julio M. Merino Vidal.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: vfs_hooks.c,v 1.5 2008/11/19 18:36:07 ad Exp $");
39 #include <sys/param.h>
40 #include <sys/queue.h>
41 #include <sys/mount.h>
42 #include <sys/mutex.h>
44 LIST_HEAD(vfs_hooks_head
, vfs_hooks
) vfs_hooks_head
=
45 LIST_HEAD_INITIALIZER(vfs_hooks_head
);
47 kmutex_t vfs_hooks_lock
;
53 mutex_init(&vfs_hooks_lock
, MUTEX_DEFAULT
, IPL_NONE
);
57 vfs_hooks_attach(struct vfs_hooks
*vfs_hooks
)
60 mutex_enter(&vfs_hooks_lock
);
61 LIST_INSERT_HEAD(&vfs_hooks_head
, vfs_hooks
, vfs_hooks_list
);
62 mutex_exit(&vfs_hooks_lock
);
68 vfs_hooks_detach(struct vfs_hooks
*vfs_hooks
)
73 mutex_enter(&vfs_hooks_lock
);
74 LIST_FOREACH(hp
, &vfs_hooks_head
, vfs_hooks_list
) {
75 if (hp
== vfs_hooks
) {
76 LIST_REMOVE(hp
, vfs_hooks_list
);
82 mutex_exit(&vfs_hooks_lock
);
88 * Macro to be used in one of the vfs_hooks_* function for hooks that
89 * return an error code. Calls will stop as soon as one of the hooks
92 #define VFS_HOOKS_W_ERROR(func, fargs, hook, hargs) \
97 struct vfs_hooks *hp; \
99 error = EJUSTRETURN; \
101 mutex_enter(&vfs_hooks_lock); \
102 LIST_FOREACH(hp, &vfs_hooks_head, vfs_hooks_list) { \
103 if (hp-> hook != NULL) { \
104 error = hp-> hook hargs; \
109 mutex_exit(&vfs_hooks_lock); \
115 * Macro to be used in one of the vfs_hooks_* function for hooks that
116 * do not return any error code. All hooks will be executed
119 #define VFS_HOOKS_WO_ERROR(func, fargs, hook, hargs) \
123 struct vfs_hooks *hp; \
125 mutex_enter(&vfs_hooks_lock); \
126 LIST_FOREACH(hp, &vfs_hooks_head, vfs_hooks_list) { \
127 if (hp-> hook != NULL) \
130 mutex_exit(&vfs_hooks_lock); \
134 * Routines to iterate over VFS hooks lists and execute them.
137 VFS_HOOKS_WO_ERROR(vfs_hooks_unmount
, (struct mount
*mp
), vh_unmount
, (mp
));
138 VFS_HOOKS_W_ERROR(vfs_hooks_reexport
, (struct mount
*mp
, const char *path
, void *data
), vh_reexport
, (mp
, path
, data
));