1 /* $NetBSD: layer_vfsops.c,v 1.31 2009/03/14 15:36:22 dsl Exp $ */
4 * Copyright (c) 1999 National Aeronautics & Space Administration
7 * This software was written by William Studenmund of the
8 * Numerical Aerospace Simulation Facility, NASA Ames Research Center.
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.
18 * 3. Neither the name of the National Aeronautics & Space Administration
19 * nor the names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior written
23 * THIS SOFTWARE IS PROVIDED BY THE NATIONAL AERONAUTICS & SPACE ADMINISTRATION
24 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ADMINISTRATION OR CONTRIB-
27 * UTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
28 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
36 * Copyright (c) 1992, 1993, 1995
37 * The Regents of the University of California. All rights reserved.
39 * This code is derived from software donated to Berkeley by
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * from: Id: lofs_vfsops.c,v 1.9 1992/05/30 10:26:24 jsp Exp
67 * from: @(#)lofs_vfsops.c 1.2 (Berkeley) 6/18/92
68 * @(#)null_vfsops.c 8.7 (Berkeley) 5/14/95
72 * generic layer vfs ops.
75 #include <sys/cdefs.h>
76 __KERNEL_RCSID(0, "$NetBSD: layer_vfsops.c,v 1.31 2009/03/14 15:36:22 dsl Exp $");
78 #include <sys/param.h>
79 #include <sys/sysctl.h>
80 #include <sys/systm.h>
83 #include <sys/vnode.h>
84 #include <sys/mount.h>
85 #include <sys/namei.h>
86 #include <sys/malloc.h>
87 #include <sys/kauth.h>
88 #include <sys/module.h>
90 #include <miscfs/genfs/layer.h>
91 #include <miscfs/genfs/layer_extern.h>
93 MODULE(MODULE_CLASS_MISC
, layerfs
, NULL
);
96 layerfs_modcmd(modcmd_t cmd
, void *arg
)
100 case MODULE_CMD_INIT
:
102 case MODULE_CMD_FINI
:
112 * VFS start. Nothing needed here - the start routine
113 * on the underlying filesystem will have been called
114 * when that filesystem was mounted.
117 layerfs_start(struct mount
*mp
, int flags
)
121 return VFS_START(MOUNTTOLAYERMOUNT(mp
)->layerm_vfs
, flags
);
128 layerfs_root(struct mount
*mp
, struct vnode
**vpp
)
132 #ifdef LAYERFS_DIAGNOSTIC
134 printf("layerfs_root(mp = %p, vp = %p->%p)\n", mp
,
135 MOUNTTOLAYERMOUNT(mp
)->layerm_rootvp
,
136 LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp
)->layerm_rootvp
));
140 * Return locked reference to root.
142 vp
= MOUNTTOLAYERMOUNT(mp
)->layerm_rootvp
;
148 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
);
154 layerfs_quotactl(struct mount
*mp
, int cmd
, uid_t uid
, void *arg
)
157 return VFS_QUOTACTL(MOUNTTOLAYERMOUNT(mp
)->layerm_vfs
, cmd
, uid
, arg
);
161 layerfs_statvfs(struct mount
*mp
, struct statvfs
*sbp
)
164 struct statvfs
*sbuf
;
166 sbuf
= kmem_alloc(sizeof(*sbuf
), KM_SLEEP
);
170 #ifdef LAYERFS_DIAGNOSTIC
172 printf("layerfs_statvfs(mp = %p, vp = %p->%p)\n", mp
,
173 MOUNTTOLAYERMOUNT(mp
)->layerm_rootvp
,
174 LAYERVPTOLOWERVP(MOUNTTOLAYERMOUNT(mp
)->layerm_rootvp
));
177 (void)memset(sbuf
, 0, sizeof(*sbuf
));
179 error
= VFS_STATVFS(MOUNTTOLAYERMOUNT(mp
)->layerm_vfs
, sbuf
);
183 /* now copy across the "interesting" information and fake the rest */
184 sbp
->f_flag
= sbuf
->f_flag
;
185 sbp
->f_bsize
= sbuf
->f_bsize
;
186 sbp
->f_frsize
= sbuf
->f_frsize
;
187 sbp
->f_iosize
= sbuf
->f_iosize
;
188 sbp
->f_blocks
= sbuf
->f_blocks
;
189 sbp
->f_bfree
= sbuf
->f_bfree
;
190 sbp
->f_bavail
= sbuf
->f_bavail
;
191 sbp
->f_bresvd
= sbuf
->f_bresvd
;
192 sbp
->f_files
= sbuf
->f_files
;
193 sbp
->f_ffree
= sbuf
->f_ffree
;
194 sbp
->f_favail
= sbuf
->f_favail
;
195 sbp
->f_fresvd
= sbuf
->f_fresvd
;
196 sbp
->f_namemax
= sbuf
->f_namemax
;
197 copy_statvfs_info(sbp
, mp
);
199 kmem_free(sbuf
, sizeof(*sbuf
));
204 layerfs_sync(struct mount
*mp
, int waitfor
,
209 * XXX - Assumes no data cached at layer.
215 layerfs_vget(struct mount
*mp
, ino_t ino
, struct vnode
**vpp
)
220 if ((error
= VFS_VGET(MOUNTTOLAYERMOUNT(mp
)->layerm_vfs
,
225 if ((error
= layer_node_create(mp
, vp
, vpp
))) {
235 layerfs_fhtovp(struct mount
*mp
, struct fid
*fidp
, struct vnode
**vpp
)
240 if ((error
= VFS_FHTOVP(MOUNTTOLAYERMOUNT(mp
)->layerm_vfs
,
244 if ((error
= layer_node_create(mp
, vp
, vpp
))) {
254 layerfs_vptofh(struct vnode
*vp
, struct fid
*fhp
, size_t *fh_size
)
257 return (VFS_VPTOFH(LAYERVPTOLOWERVP(vp
), fhp
, fh_size
));
261 * layerfs_snapshot - handle a snapshot through a layered file system
263 * At present, we do NOT support snapshotting through a layered file
264 * system as the ffs implementation changes v_vnlock of the snapshot
265 * vnodes to point to one common lock. As there is no way for us to
266 * absolutely pass this change up the stack, a layered file system
267 * would end up referencing the wrong lock.
269 * This routine serves as a central resource for this behavior; all
270 * layered file systems don't need to worry about the above. Also, if
271 * things get fixed, all layers get the benefit.
274 layerfs_snapshot(struct mount
*mp
, struct vnode
*vp
,
280 SYSCTL_SETUP(sysctl_vfs_layerfs_setup
, "sysctl vfs.layerfs subtree setup")
282 const struct sysctlnode
*layerfs_node
= NULL
;
284 sysctl_createv(clog
, 0, NULL
, NULL
,
286 CTLTYPE_NODE
, "vfs", NULL
,
289 sysctl_createv(clog
, 0, NULL
, &layerfs_node
,
291 CTLTYPE_NODE
, "layerfs",
292 SYSCTL_DESCR("Generic layered file system"),
294 CTL_VFS
, CTL_CREATE
);
296 #ifdef LAYERFS_DIAGNOSTIC
297 sysctl_createv(clog
, 0, &layerfs_node
, NULL
,
298 CTLFLAG_PERMANENT
|CTLFLAG_READWRITE
,
301 SYSCTL_DESCR("Verbose debugging messages"),
302 NULL
, 0, &layerfs_debug
, 0,
303 CTL_CREATE
, CTL_EOL
);
307 * other subtrees should really be aliases to this, but since
308 * they can't tell if layerfs has been instantiated yet, they
309 * can't do that...not easily. not yet. :-)
314 layerfs_renamelock_enter(struct mount
*mp
)
316 return VFS_RENAMELOCK_ENTER(MOUNTTOLAYERMOUNT(mp
)->layerm_vfs
);
320 layerfs_renamelock_exit(struct mount
*mp
)
322 VFS_RENAMELOCK_EXIT(MOUNTTOLAYERMOUNT(mp
)->layerm_vfs
);