1 /* 2 * Copyright (c) 1989, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed 6 * to Berkeley by John Heidemann of the UCLA Ficus project. 7 * 8 * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project 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 University of 21 * California, Berkeley and its contributors. 22 * 4. Neither the name of the University nor the names of its contributors 23 * may be used to endorse or promote products derived from this software 24 * without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * SUCH DAMAGE. 37 * 38 * @(#)vfs_init.c 8.3 (Berkeley) 1/4/94 39 * $Id: vfs_init.c,v 1.27 1997/09/10 20:11:01 phk Exp $ 40 */ 41 42 43 #include <sys/param.h> 44 #include <sys/systm.h> 45 #include <sys/kernel.h> 46 #include <sys/mount.h> 47 #include <sys/vnode.h> 48 #include <sys/malloc.h> 49 #include <vm/vm_zone.h> 50 51 static void vfs_op_init __P((void)); 52 53 static void vfsinit __P((void *)); 54 SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_FIRST, vfsinit, NULL) 55 56 /* 57 * Sigh, such primitive tools are these... 58 */ 59 #if 0 60 #define DODEBUG(A) A 61 #else 62 #define DODEBUG(A) 63 #endif 64 65 struct vfsconf void_vfsconf; 66 67 extern struct linker_set vfs_opv_descs_; 68 #define vfs_opv_descs ((struct vnodeopv_desc **)vfs_opv_descs_.ls_items) 69 70 extern struct linker_set vfs_set; 71 72 extern struct vnodeop_desc *vfs_op_descs[]; 73 /* and the operations they perform */ 74 75 /* 76 * Zone for namei 77 */ 78 struct vm_zone *namei_zone; 79 80 /* 81 * A miscellaneous routine. 82 * A generic "default" routine that just returns an error. 83 */ 84 int 85 vn_default_error() 86 { 87 88 return (EOPNOTSUPP); 89 } 90 91 /* 92 * vfs_init.c 93 * 94 * Allocate and fill in operations vectors. 95 * 96 * An undocumented feature of this approach to defining operations is that 97 * there can be multiple entries in vfs_opv_descs for the same operations 98 * vector. This allows third parties to extend the set of operations 99 * supported by another layer in a binary compatibile way. For example, 100 * assume that NFS needed to be modified to support Ficus. NFS has an entry 101 * (probably nfs_vnopdeop_decls) declaring all the operations NFS supports by 102 * default. Ficus could add another entry (ficus_nfs_vnodeop_decl_entensions) 103 * listing those new operations Ficus adds to NFS, all without modifying the 104 * NFS code. (Of couse, the OTW NFS protocol still needs to be munged, but 105 * that is a(whole)nother story.) This is a feature. 106 * 107 * Without an explicit reserve area, however, you must replace vnode_if.c 108 * and vnode_if.h when you do this, or you will be derefrencing of the 109 * end of vfs_op_descs[]. This is a flaw in the use of a structure 110 * pointer array rather than an agregate to define vfs_op_descs. So 111 * it's not a very dynamic "feature". 112 */ 113 void 114 vfs_opv_init(struct vnodeopv_desc **them) 115 { 116 int i, j, k; 117 vop_t ***opv_desc_vector_p; 118 vop_t **opv_desc_vector; 119 struct vnodeopv_entry_desc *opve_descp; 120 121 /* 122 * Allocate the dynamic vectors and fill them in. 123 */ 124 for (i=0; them[i]; i++) { 125 opv_desc_vector_p = them[i]->opv_desc_vector_p; 126 /* 127 * Allocate and init the vector, if it needs it. 128 * Also handle backwards compatibility. 129 */ 130 if (*opv_desc_vector_p == NULL) { 131 /* XXX - shouldn't be M_VNODE */ 132 MALLOC(*opv_desc_vector_p, vop_t **, 133 vfs_opv_numops * sizeof(vop_t *), M_VNODE, 134 M_WAITOK); 135 bzero(*opv_desc_vector_p, 136 vfs_opv_numops * sizeof(vop_t *)); 137 DODEBUG(printf("vector at %x allocated\n", 138 opv_desc_vector_p)); 139 } 140 opv_desc_vector = *opv_desc_vector_p; 141 for (j=0; them[i]->opv_desc_ops[j].opve_op; j++) { 142 opve_descp = &(them[i]->opv_desc_ops[j]); 143 144 /* 145 * Sanity check: is this operation listed 146 * in the list of operations? We check this 147 * by seeing if its offest is zero. Since 148 * the default routine should always be listed 149 * first, it should be the only one with a zero 150 * offset. Any other operation with a zero 151 * offset is probably not listed in 152 * vfs_op_descs, and so is probably an error. 153 * 154 * A panic here means the layer programmer 155 * has committed the all-too common bug 156 * of adding a new operation to the layer's 157 * list of vnode operations but 158 * not adding the operation to the system-wide 159 * list of supported operations. 160 */ 161 if (opve_descp->opve_op->vdesc_offset == 0 && 162 opve_descp->opve_op->vdesc_offset != 163 VOFFSET(vop_default)) { 164 printf("operation %s not listed in %s.\n", 165 opve_descp->opve_op->vdesc_name, 166 "vfs_op_descs"); 167 panic ("vfs_opv_init: bad operation"); 168 } 169 /* 170 * Fill in this entry. 171 */ 172 opv_desc_vector[opve_descp->opve_op->vdesc_offset] = 173 opve_descp->opve_impl; 174 } 175 } 176 /* 177 * Finally, go back and replace unfilled routines 178 * with their default. (Sigh, an O(n^3) algorithm. I 179 * could make it better, but that'd be work, and n is small.) 180 */ 181 for (i = 0; them[i]; i++) { 182 opv_desc_vector = *(them[i]->opv_desc_vector_p); 183 /* 184 * Force every operations vector to have a default routine. 185 */ 186 if (opv_desc_vector[VOFFSET(vop_default)]==NULL) { 187 panic("vfs_opv_init: operation vector without default routine."); 188 } 189 for (k = 0; k<vfs_opv_numops; k++) 190 if (opv_desc_vector[k] == NULL) 191 opv_desc_vector[k] = 192 opv_desc_vector[VOFFSET(vop_default)]; 193 } 194 } 195 196 /* 197 * Initialize known vnode operations vectors. 198 */ 199 static void 200 vfs_op_init() 201 { 202 int i; 203 204 DODEBUG(printf("Vnode_interface_init.\n")); 205 DODEBUG(printf ("vfs_opv_numops=%d\n", vfs_opv_numops)); 206 /* 207 * Set all vnode vectors to a well known value. 208 */ 209 for (i = 0; vfs_opv_descs[i]; i++) 210 *(vfs_opv_descs[i]->opv_desc_vector_p) = NULL; 211 /* 212 * assign each op to its offset 213 * 214 * XXX This should not be needed, but is because the per 215 * XXX FS ops tables are not sorted according to the 216 * XXX vnodeop_desc's offset in vfs_op_descs. This 217 * XXX is the same reason we have to take the hit for 218 * XXX the static inline function calls instead of using 219 * XXX simple macro references. 220 */ 221 for (i = 0; i < vfs_opv_numops; i++) 222 vfs_op_descs[i]->vdesc_offset = i; 223 } 224 225 /* 226 * Routines having to do with the management of the vnode table. 227 */ 228 extern struct vnodeops dead_vnodeops; 229 extern struct vnodeops spec_vnodeops; 230 struct vattr va_null; 231 232 /* 233 * Initialize the vnode structures and initialize each file system type. 234 */ 235 /* ARGSUSED*/ 236 static void 237 vfsinit(dummy) 238 void *dummy; 239 { 240 struct vfsconf **vfc; 241 int maxtypenum; 242 243 namei_zone = zinit("NAMEI", MAXPATHLEN, 0, 0, 2); 244 245 /* 246 * Initialize the vnode table 247 */ 248 vntblinit(); 249 /* 250 * Initialize the vnode name cache 251 */ 252 nchinit(); 253 /* 254 * Build vnode operation vectors. 255 */ 256 vfs_op_init(); 257 vfs_opv_init(vfs_opv_descs); /* finish the job */ 258 /* 259 * Initialize each file system type. 260 */ 261 vattr_null(&va_null); 262 maxtypenum = 0; 263 vfc = (struct vfsconf **)vfs_set.ls_items; 264 vfsconf = *vfc; /* simulate Lite2 vfsconf array */ 265 while (*vfc) { 266 struct vfsconf *vfsp = *vfc; 267 268 vfc++; 269 vfsp->vfc_next = *vfc; 270 if (maxtypenum <= vfsp->vfc_typenum) 271 maxtypenum = vfsp->vfc_typenum + 1; 272 (*vfsp->vfc_vfsops->vfs_init)(vfsp); 273 } 274 /* next vfc_typenum to be used */ 275 maxvfsconf = maxtypenum; 276 } 277 278 /* 279 * kernel related system variables. 280 */ 281 282 /* 283 * This goop is here to support a loadable NFS module... grumble... 284 */ 285 int (*lease_check_hook) __P((struct vop_lease_args *)) 286 = 0; 287 void (*lease_updatetime) __P((int)) 288 = 0; 289 290 int 291 lease_check(ap) 292 struct vop_lease_args /* { 293 struct vnode *a_vp; 294 struct proc *a_p; 295 struct ucred *a_cred; 296 int a_flag; 297 } */ *ap; 298 { 299 if (lease_check_hook) 300 return (*lease_check_hook)(ap); 301 else 302 return 0; 303 } 304