Fix an endless recursion and double fault which could occur when accessing
[dragonfly.git] / sys / vfs / nullfs / null_vnops.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1992, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * John Heidemann of the UCLA Ficus project.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * @(#)null_vnops.c 8.6 (Berkeley) 5/27/95
37 *
38 * Ancestors:
39 * @(#)lofs_vnops.c 1.2 (Berkeley) 6/18/92
40 * $FreeBSD: src/sys/miscfs/nullfs/null_vnops.c,v 1.38.2.6 2002/07/31 00:32:28 semenu Exp $
3ea4f8fe 41 * $DragonFly: src/sys/vfs/nullfs/null_vnops.c,v 1.29 2008/09/05 23:27:12 dillon Exp $
984263bc
MD
42 * ...and...
43 * @(#)null_vnodeops.c 1.20 92/07/07 UCLA Ficus project
44 *
45 * $FreeBSD: src/sys/miscfs/nullfs/null_vnops.c,v 1.38.2.6 2002/07/31 00:32:28 semenu Exp $
46 */
47
48/*
49 * Null Layer
50 *
51 * (See mount_null(8) for more information.)
52 *
53 * The null layer duplicates a portion of the file system
54 * name space under a new name. In this respect, it is
55 * similar to the loopback file system. It differs from
56 * the loopback fs in two respects: it is implemented using
57 * a stackable layers techniques, and its "null-node"s stack above
58 * all lower-layer vnodes, not just over directory vnodes.
59 *
60 * The null layer has two purposes. First, it serves as a demonstration
61 * of layering by proving a layer which does nothing. (It actually
62 * does everything the loopback file system does, which is slightly
63 * more than nothing.) Second, the null layer can serve as a prototype
64 * layer. Since it provides all necessary layer framework,
65 * new file system layers can be created very easily be starting
66 * with a null layer.
67 *
68 * The remainder of this man page examines the null layer as a basis
69 * for constructing new layers.
70 *
71 *
72 * INSTANTIATING NEW NULL LAYERS
73 *
74 * New null layers are created with mount_null(8).
75 * Mount_null(8) takes two arguments, the pathname
76 * of the lower vfs (target-pn) and the pathname where the null
77 * layer will appear in the namespace (alias-pn). After
78 * the null layer is put into place, the contents
79 * of target-pn subtree will be aliased under alias-pn.
80 *
81 *
82 * OPERATION OF A NULL LAYER
83 *
84 * The null layer is the minimum file system layer,
85 * simply bypassing all possible operations to the lower layer
8cb8b61a
MD
86 * for processing there. The majority of its activity used to center
87 * on a so-called bypass routine, through which nullfs vnodes
88 * passed on operation to their underlying peer.
89 *
90 * However, with the current implementation nullfs doesn't have any private
3ea4f8fe 91 * vnodes, rather it relies on DragonFly's namecache API. That gives a much
8cb8b61a
MD
92 * more lightweight null layer, as namecache structures are pure data, with
93 * no private operations, so there is no need of subtle dispatching routines.
94 *
95 * Unlike the old code, this implementation is not a general skeleton overlay
ccb16a17
SW
96 * filesystem: to get more comprehensive overlaying, we will need vnode
97 * operation dispatch. Other overlay filesystems, like unionfs might be
98 * able to get on with a hybrid solution: overlay some vnodes, and rely
8cb8b61a
MD
99 * on namecache API for the rest.
100 */
101
984263bc
MD
102#include <sys/param.h>
103#include <sys/systm.h>
104#include <sys/kernel.h>
105#include <sys/sysctl.h>
106#include <sys/vnode.h>
107#include <sys/mount.h>
dadab5e9 108#include <sys/proc.h>
984263bc
MD
109#include <sys/namei.h>
110#include <sys/malloc.h>
111#include <sys/buf.h>
1f2de5d4 112#include "null.h"
984263bc 113
fad57d0e
MD
114static int null_nresolve(struct vop_nresolve_args *ap);
115static int null_ncreate(struct vop_ncreate_args *ap);
116static int null_nmkdir(struct vop_nmkdir_args *ap);
8cb8b61a
MD
117static int null_nmknod(struct vop_nmknod_args *ap);
118static int null_nlink(struct vop_nlink_args *ap);
119static int null_nsymlink(struct vop_nsymlink_args *ap);
120static int null_nwhiteout(struct vop_nwhiteout_args *ap);
fad57d0e
MD
121static int null_nremove(struct vop_nremove_args *ap);
122static int null_nrmdir(struct vop_nrmdir_args *ap);
123static int null_nrename(struct vop_nrename_args *ap);
124
417215fe 125static int
fad57d0e 126null_nresolve(struct vop_nresolve_args *ap)
417215fe 127{
28623bf9 128 ap->a_head.a_ops = MOUNTTONULLMOUNT(ap->a_nch->mount)->nullm_vfs->mnt_vn_norm_ops;
5fd012e0 129
8cb8b61a 130 return vop_nresolve_ap(ap);
5fd012e0
MD
131}
132
984263bc 133static int
8cb8b61a 134null_ncreate(struct vop_ncreate_args *ap)
984263bc 135{
28623bf9 136 ap->a_head.a_ops = MOUNTTONULLMOUNT(ap->a_nch->mount)->nullm_vfs->mnt_vn_norm_ops;
984263bc 137
8cb8b61a 138 return vop_ncreate_ap(ap);
984263bc
MD
139}
140
984263bc 141static int
8cb8b61a 142null_nmkdir(struct vop_nmkdir_args *ap)
984263bc 143{
28623bf9 144 ap->a_head.a_ops = MOUNTTONULLMOUNT(ap->a_nch->mount)->nullm_vfs->mnt_vn_norm_ops;
984263bc 145
8cb8b61a 146 return vop_nmkdir_ap(ap);
984263bc
MD
147}
148
984263bc 149static int
8cb8b61a 150null_nmknod(struct vop_nmknod_args *ap)
984263bc 151{
28623bf9 152 ap->a_head.a_ops = MOUNTTONULLMOUNT(ap->a_nch->mount)->nullm_vfs->mnt_vn_norm_ops;
3446c007 153
8cb8b61a 154 return vop_nmknod_ap(ap);
984263bc
MD
155}
156
157static int
8cb8b61a 158null_nlink(struct vop_nlink_args *ap)
984263bc 159{
28623bf9 160 ap->a_head.a_ops = MOUNTTONULLMOUNT(ap->a_nch->mount)->nullm_vfs->mnt_vn_norm_ops;
984263bc 161
8cb8b61a 162 return vop_nlink_ap(ap);
984263bc
MD
163}
164
984263bc 165static int
8cb8b61a 166null_nsymlink(struct vop_nsymlink_args *ap)
984263bc 167{
28623bf9 168 ap->a_head.a_ops = MOUNTTONULLMOUNT(ap->a_nch->mount)->nullm_vfs->mnt_vn_norm_ops;
984263bc 169
8cb8b61a 170 return vop_nsymlink_ap(ap);
984263bc
MD
171}
172
984263bc 173static int
8cb8b61a 174null_nwhiteout(struct vop_nwhiteout_args *ap)
984263bc 175{
28623bf9 176 ap->a_head.a_ops = MOUNTTONULLMOUNT(ap->a_nch->mount)->nullm_vfs->mnt_vn_norm_ops;
984263bc 177
8cb8b61a 178 return vop_nwhiteout_ap(ap);
984263bc
MD
179}
180
181static int
8cb8b61a 182null_nremove(struct vop_nremove_args *ap)
984263bc 183{
28623bf9 184 ap->a_head.a_ops = MOUNTTONULLMOUNT(ap->a_nch->mount)->nullm_vfs->mnt_vn_norm_ops;
984263bc 185
8cb8b61a 186 return vop_nremove_ap(ap);
984263bc
MD
187}
188
984263bc 189static int
8cb8b61a 190null_nrmdir(struct vop_nrmdir_args *ap)
984263bc 191{
28623bf9 192 ap->a_head.a_ops = MOUNTTONULLMOUNT(ap->a_nch->mount)->nullm_vfs->mnt_vn_norm_ops;
984263bc 193
8cb8b61a 194 return vop_nrmdir_ap(ap);
984263bc
MD
195}
196
984263bc 197static int
8cb8b61a 198null_nrename(struct vop_nrename_args *ap)
984263bc 199{
8cb8b61a 200 struct mount *lmp;
984263bc 201
28623bf9
MD
202 lmp = MOUNTTONULLMOUNT(ap->a_fnch->mount)->nullm_vfs;
203 if (lmp != MOUNTTONULLMOUNT(ap->a_tnch->mount)->nullm_vfs)
8cb8b61a 204 return (EINVAL);
71ed54ce 205
8cb8b61a 206 ap->a_head.a_ops = lmp->mnt_vn_norm_ops;
984263bc 207
8cb8b61a 208 return vop_nrename_ap(ap);
984263bc
MD
209}
210
211/*
212 * Global vfs data structures
213 */
66a1ddf5
MD
214struct vop_ops null_vnode_vops = {
215 .vop_nresolve = null_nresolve,
216 .vop_ncreate = null_ncreate,
217 .vop_nmkdir = null_nmkdir,
218 .vop_nmknod = null_nmknod,
219 .vop_nlink = null_nlink,
220 .vop_nsymlink = null_nsymlink,
221 .vop_nwhiteout = null_nwhiteout,
222 .vop_nremove = null_nremove,
223 .vop_nrmdir = null_nrmdir,
224 .vop_nrename = null_nrename
984263bc 225};
984263bc 226