vfs_init.c revision 38869
11541Srgrimes/* 21541Srgrimes * Copyright (c) 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * This code is derived from software contributed 61541Srgrimes * to Berkeley by John Heidemann of the UCLA Ficus project. 71541Srgrimes * 81541Srgrimes * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project 91541Srgrimes * 101541Srgrimes * Redistribution and use in source and binary forms, with or without 111541Srgrimes * modification, are permitted provided that the following conditions 121541Srgrimes * are met: 131541Srgrimes * 1. Redistributions of source code must retain the above copyright 141541Srgrimes * notice, this list of conditions and the following disclaimer. 151541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 161541Srgrimes * notice, this list of conditions and the following disclaimer in the 171541Srgrimes * documentation and/or other materials provided with the distribution. 181541Srgrimes * 3. All advertising materials mentioning features or use of this software 191541Srgrimes * must display the following acknowledgement: 201541Srgrimes * This product includes software developed by the University of 211541Srgrimes * California, Berkeley and its contributors. 221541Srgrimes * 4. Neither the name of the University nor the names of its contributors 231541Srgrimes * may be used to endorse or promote products derived from this software 241541Srgrimes * without specific prior written permission. 251541Srgrimes * 261541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 271541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 281541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 291541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 301541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 311541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 321541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 331541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 341541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 351541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 361541Srgrimes * SUCH DAMAGE. 371541Srgrimes * 381541Srgrimes * @(#)vfs_init.c 8.3 (Berkeley) 1/4/94 3938869Sbde * $Id: vfs_init.c,v 1.32 1998/02/09 06:09:33 eivind Exp $ 401541Srgrimes */ 411541Srgrimes 421541Srgrimes 431541Srgrimes#include <sys/param.h> 442112Swollman#include <sys/systm.h> 452946Swollman#include <sys/kernel.h> 461541Srgrimes#include <sys/mount.h> 4738869Sbde#include <sys/sysctl.h> 481541Srgrimes#include <sys/vnode.h> 491541Srgrimes#include <sys/malloc.h> 5029653Sdyson#include <vm/vm_zone.h> 511541Srgrimes 5212913Sphkstatic void vfs_op_init __P((void)); 5312577Sbde 5410653Sdgstatic void vfsinit __P((void *)); 5510358SjulianSYSINIT(vfs, SI_SUB_VFS, SI_ORDER_FIRST, vfsinit, NULL) 5610358Sjulian 5730354SphkMALLOC_DEFINE(M_VNODE, "vnodes", "Dynamically allocated vnodes"); 5830354Sphk 5910358Sjulian/* 601541Srgrimes * Sigh, such primitive tools are these... 611541Srgrimes */ 621541Srgrimes#if 0 631541Srgrimes#define DODEBUG(A) A 641541Srgrimes#else 651541Srgrimes#define DODEBUG(A) 661541Srgrimes#endif 671541Srgrimes 6833181Seivindstatic struct vfsconf void_vfsconf; 692946Swollman 702946Swollmanextern struct linker_set vfs_opv_descs_; 712946Swollman#define vfs_opv_descs ((struct vnodeopv_desc **)vfs_opv_descs_.ls_items) 722946Swollman 732946Swollmanextern struct linker_set vfs_set; 742946Swollman 751541Srgrimesextern struct vnodeop_desc *vfs_op_descs[]; 761541Srgrimes /* and the operations they perform */ 771541Srgrimes 781541Srgrimes/* 7929653Sdyson * Zone for namei 8029653Sdyson */ 8129653Sdysonstruct vm_zone *namei_zone; 8229653Sdyson 8329653Sdyson/* 841541Srgrimes * vfs_init.c 851541Srgrimes * 861541Srgrimes * Allocate and fill in operations vectors. 871541Srgrimes * 881541Srgrimes * An undocumented feature of this approach to defining operations is that 891541Srgrimes * there can be multiple entries in vfs_opv_descs for the same operations 901541Srgrimes * vector. This allows third parties to extend the set of operations 911541Srgrimes * supported by another layer in a binary compatibile way. For example, 921541Srgrimes * assume that NFS needed to be modified to support Ficus. NFS has an entry 931541Srgrimes * (probably nfs_vnopdeop_decls) declaring all the operations NFS supports by 941541Srgrimes * default. Ficus could add another entry (ficus_nfs_vnodeop_decl_entensions) 951541Srgrimes * listing those new operations Ficus adds to NFS, all without modifying the 961541Srgrimes * NFS code. (Of couse, the OTW NFS protocol still needs to be munged, but 971541Srgrimes * that is a(whole)nother story.) This is a feature. 9829290Sphk * 9929290Sphk * Without an explicit reserve area, however, you must replace vnode_if.c 10029290Sphk * and vnode_if.h when you do this, or you will be derefrencing of the 10129290Sphk * end of vfs_op_descs[]. This is a flaw in the use of a structure 10229290Sphk * pointer array rather than an agregate to define vfs_op_descs. So 10329290Sphk * it's not a very dynamic "feature". 1041541Srgrimes */ 1051541Srgrimesvoid 1062946Swollmanvfs_opv_init(struct vnodeopv_desc **them) 1071541Srgrimes{ 1081541Srgrimes int i, j, k; 10912158Sbde vop_t ***opv_desc_vector_p; 11012158Sbde vop_t **opv_desc_vector; 1111541Srgrimes struct vnodeopv_entry_desc *opve_descp; 1121541Srgrimes 1131541Srgrimes /* 1141541Srgrimes * Allocate the dynamic vectors and fill them in. 1151541Srgrimes */ 1162946Swollman for (i=0; them[i]; i++) { 1172946Swollman opv_desc_vector_p = them[i]->opv_desc_vector_p; 1181541Srgrimes /* 1191541Srgrimes * Allocate and init the vector, if it needs it. 1201541Srgrimes * Also handle backwards compatibility. 1211541Srgrimes */ 1221541Srgrimes if (*opv_desc_vector_p == NULL) { 1231541Srgrimes /* XXX - shouldn't be M_VNODE */ 12412158Sbde MALLOC(*opv_desc_vector_p, vop_t **, 12512158Sbde vfs_opv_numops * sizeof(vop_t *), M_VNODE, 12612158Sbde M_WAITOK); 12712158Sbde bzero(*opv_desc_vector_p, 12812158Sbde vfs_opv_numops * sizeof(vop_t *)); 1291541Srgrimes DODEBUG(printf("vector at %x allocated\n", 1301541Srgrimes opv_desc_vector_p)); 1311541Srgrimes } 1321541Srgrimes opv_desc_vector = *opv_desc_vector_p; 1332946Swollman for (j=0; them[i]->opv_desc_ops[j].opve_op; j++) { 1342946Swollman opve_descp = &(them[i]->opv_desc_ops[j]); 1351541Srgrimes 1361541Srgrimes /* 1371541Srgrimes * Sanity check: is this operation listed 1381541Srgrimes * in the list of operations? We check this 1391541Srgrimes * by seeing if its offest is zero. Since 1401541Srgrimes * the default routine should always be listed 1411541Srgrimes * first, it should be the only one with a zero 1421541Srgrimes * offset. Any other operation with a zero 1431541Srgrimes * offset is probably not listed in 1441541Srgrimes * vfs_op_descs, and so is probably an error. 1451541Srgrimes * 1461541Srgrimes * A panic here means the layer programmer 1471541Srgrimes * has committed the all-too common bug 1481541Srgrimes * of adding a new operation to the layer's 1491541Srgrimes * list of vnode operations but 1501541Srgrimes * not adding the operation to the system-wide 1511541Srgrimes * list of supported operations. 1521541Srgrimes */ 1531541Srgrimes if (opve_descp->opve_op->vdesc_offset == 0 && 1541541Srgrimes opve_descp->opve_op->vdesc_offset != 1551541Srgrimes VOFFSET(vop_default)) { 1561541Srgrimes printf("operation %s not listed in %s.\n", 1571541Srgrimes opve_descp->opve_op->vdesc_name, 1581541Srgrimes "vfs_op_descs"); 1591541Srgrimes panic ("vfs_opv_init: bad operation"); 1601541Srgrimes } 1611541Srgrimes /* 1621541Srgrimes * Fill in this entry. 1631541Srgrimes */ 1641541Srgrimes opv_desc_vector[opve_descp->opve_op->vdesc_offset] = 1651541Srgrimes opve_descp->opve_impl; 1661541Srgrimes } 1671541Srgrimes } 1681541Srgrimes /* 1691541Srgrimes * Finally, go back and replace unfilled routines 1701541Srgrimes * with their default. (Sigh, an O(n^3) algorithm. I 1711541Srgrimes * could make it better, but that'd be work, and n is small.) 1721541Srgrimes */ 1732946Swollman for (i = 0; them[i]; i++) { 1742946Swollman opv_desc_vector = *(them[i]->opv_desc_vector_p); 1751541Srgrimes /* 1761541Srgrimes * Force every operations vector to have a default routine. 1771541Srgrimes */ 1781541Srgrimes if (opv_desc_vector[VOFFSET(vop_default)]==NULL) { 1791541Srgrimes panic("vfs_opv_init: operation vector without default routine."); 1801541Srgrimes } 1811541Srgrimes for (k = 0; k<vfs_opv_numops; k++) 1821541Srgrimes if (opv_desc_vector[k] == NULL) 1838876Srgrimes opv_desc_vector[k] = 1841541Srgrimes opv_desc_vector[VOFFSET(vop_default)]; 1851541Srgrimes } 1861541Srgrimes} 1871541Srgrimes 1881541Srgrimes/* 1891541Srgrimes * Initialize known vnode operations vectors. 1901541Srgrimes */ 19112913Sphkstatic void 1921541Srgrimesvfs_op_init() 1931541Srgrimes{ 1941541Srgrimes int i; 1951541Srgrimes 1961541Srgrimes DODEBUG(printf("Vnode_interface_init.\n")); 19729290Sphk DODEBUG(printf ("vfs_opv_numops=%d\n", vfs_opv_numops)); 1981541Srgrimes /* 1991541Srgrimes * Set all vnode vectors to a well known value. 2001541Srgrimes */ 2011541Srgrimes for (i = 0; vfs_opv_descs[i]; i++) 2021541Srgrimes *(vfs_opv_descs[i]->opv_desc_vector_p) = NULL; 2031541Srgrimes /* 20429290Sphk * assign each op to its offset 20529290Sphk * 20629290Sphk * XXX This should not be needed, but is because the per 20729290Sphk * XXX FS ops tables are not sorted according to the 20829290Sphk * XXX vnodeop_desc's offset in vfs_op_descs. This 20929290Sphk * XXX is the same reason we have to take the hit for 21029290Sphk * XXX the static inline function calls instead of using 21129290Sphk * XXX simple macro references. 2121541Srgrimes */ 21329290Sphk for (i = 0; i < vfs_opv_numops; i++) 21429290Sphk vfs_op_descs[i]->vdesc_offset = i; 2151541Srgrimes} 2161541Srgrimes 2171541Srgrimes/* 2181541Srgrimes * Routines having to do with the management of the vnode table. 2191541Srgrimes */ 2201541Srgrimesextern struct vnodeops dead_vnodeops; 2211541Srgrimesextern struct vnodeops spec_vnodeops; 2221541Srgrimesstruct vattr va_null; 2231541Srgrimes 2241541Srgrimes/* 2251541Srgrimes * Initialize the vnode structures and initialize each file system type. 2261541Srgrimes */ 22710358Sjulian/* ARGSUSED*/ 22810358Sjulianstatic void 22912569Sbdevfsinit(dummy) 23012569Sbde void *dummy; 2311541Srgrimes{ 23238869Sbde struct vfsconf **vfc, *vfsp; 23322521Sdyson int maxtypenum; 2341541Srgrimes 23529653Sdyson namei_zone = zinit("NAMEI", MAXPATHLEN, 0, 0, 2); 23629653Sdyson 2371541Srgrimes /* 2381541Srgrimes * Initialize the vnode table 2391541Srgrimes */ 2401541Srgrimes vntblinit(); 2411541Srgrimes /* 2421541Srgrimes * Initialize the vnode name cache 2431541Srgrimes */ 2441541Srgrimes nchinit(); 2451541Srgrimes /* 2461541Srgrimes * Build vnode operation vectors. 2471541Srgrimes */ 2481541Srgrimes vfs_op_init(); 2492946Swollman vfs_opv_init(vfs_opv_descs); /* finish the job */ 2501541Srgrimes /* 2511541Srgrimes * Initialize each file system type. 2521541Srgrimes */ 2531541Srgrimes vattr_null(&va_null); 25422521Sdyson maxtypenum = 0; 25522521Sdyson vfc = (struct vfsconf **)vfs_set.ls_items; 25638869Sbde vfsconf = *vfc; 25738869Sbde for (; *vfc != NULL; maxtypenum++, vfc++) { 25838869Sbde vfsp = *vfc; 25938869Sbde vfsp->vfc_next = *(vfc + 1); 26038869Sbde vfsp->vfc_typenum = maxtypenum; 26138869Sbde if (vfsp->vfc_vfsops->vfs_oid != NULL) { 26238869Sbde vfsp->vfc_vfsops->vfs_oid->oid_number = maxtypenum; 26338869Sbde sysctl_order_all(); 26438869Sbde } 26522521Sdyson (*vfsp->vfc_vfsops->vfs_init)(vfsp); 2661541Srgrimes } 26722521Sdyson /* next vfc_typenum to be used */ 26822521Sdyson maxvfsconf = maxtypenum; 2691541Srgrimes} 2702946Swollman 271