Home | History | Annotate | Line # | Download | only in coda
coda_vfsops.c revision 1.6
      1  1.6  rvb /*	$NetBSD: coda_vfsops.c,v 1.6 1998/12/10 02:22:52 rvb Exp $	*/
      2  1.2  rvb 
      3  1.1  rvb /*
      4  1.2  rvb  *
      5  1.2  rvb  *             Coda: an Experimental Distributed File System
      6  1.2  rvb  *                              Release 3.1
      7  1.2  rvb  *
      8  1.2  rvb  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9  1.2  rvb  *                          All Rights Reserved
     10  1.2  rvb  *
     11  1.2  rvb  * Permission  to  use, copy, modify and distribute this software and its
     12  1.2  rvb  * documentation is hereby granted,  provided  that  both  the  copyright
     13  1.2  rvb  * notice  and  this  permission  notice  appear  in  all  copies  of the
     14  1.2  rvb  * software, derivative works or  modified  versions,  and  any  portions
     15  1.2  rvb  * thereof, and that both notices appear in supporting documentation, and
     16  1.2  rvb  * that credit is given to Carnegie Mellon University  in  all  documents
     17  1.2  rvb  * and publicity pertaining to direct or indirect use of this code or its
     18  1.2  rvb  * derivatives.
     19  1.2  rvb  *
     20  1.2  rvb  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
     21  1.2  rvb  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
     22  1.2  rvb  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
     23  1.2  rvb  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
     24  1.2  rvb  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
     25  1.2  rvb  * ANY DERIVATIVE WORK.
     26  1.2  rvb  *
     27  1.2  rvb  * Carnegie  Mellon  encourages  users  of  this  software  to return any
     28  1.2  rvb  * improvements or extensions that  they  make,  and  to  grant  Carnegie
     29  1.2  rvb  * Mellon the rights to redistribute these changes without encumbrance.
     30  1.2  rvb  *
     31  1.3  rvb  * 	@(#) cfs/coda_vfsops.c,v 1.1.1.1 1998/08/29 21:26:45 rvb Exp $
     32  1.2  rvb  */
     33  1.1  rvb 
     34  1.1  rvb /*
     35  1.1  rvb  * Mach Operating System
     36  1.1  rvb  * Copyright (c) 1989 Carnegie-Mellon University
     37  1.1  rvb  * All rights reserved.  The CMU software License Agreement specifies
     38  1.1  rvb  * the terms and conditions for use and redistribution.
     39  1.1  rvb  */
     40  1.1  rvb 
     41  1.1  rvb /*
     42  1.1  rvb  * This code was written for the Coda file system at Carnegie Mellon
     43  1.1  rvb  * University.  Contributers include David Steere, James Kistler, and
     44  1.1  rvb  * M. Satyanarayanan.
     45  1.1  rvb  */
     46  1.1  rvb 
     47  1.1  rvb /*
     48  1.1  rvb  * HISTORY
     49  1.3  rvb  * $Log: coda_vfsops.c,v $
     50  1.6  rvb  * Revision 1.6  1998/12/10 02:22:52  rvb
     51  1.6  rvb  * Commit a couple of old fixes
     52  1.6  rvb  *
     53  1.6  rvb  * Revision 1.5  1998/09/25 15:01:13  rvb
     54  1.6  rvb  * Conditionalize "stray" printouts under DIAGNOSTIC and DEBUG.
     55  1.5  rvb  * Make files compile if DEBUG is on (from  Alan Barrett).  Finally,
     56  1.5  rvb  * make coda an lkm.
     57  1.5  rvb  *
     58  1.4  rvb  * Revision 1.4  1998/09/15 02:03:00  rvb
     59  1.4  rvb  * Final piece of rename cfs->coda
     60  1.4  rvb  *
     61  1.4  rvb  * Revision 1.3  1998/09/12 15:05:49  rvb
     62  1.3  rvb  * Change cfs/CFS in symbols, strings and constants to coda/CODA
     63  1.3  rvb  * to avoid fs conflicts.
     64  1.3  rvb  *
     65  1.2  rvb  * Revision 1.2  1998/09/08 17:12:47  rvb
     66  1.2  rvb  * Pass2 complete
     67  1.2  rvb  *
     68  1.1  rvb  * Revision 1.1.1.1  1998/08/29 21:26:45  rvb
     69  1.1  rvb  * Very Preliminary Coda
     70  1.1  rvb  *
     71  1.1  rvb  * Revision 1.11  1998/08/28 18:12:22  rvb
     72  1.1  rvb  * Now it also works on FreeBSD -current.  This code will be
     73  1.1  rvb  * committed to the FreeBSD -current and NetBSD -current
     74  1.1  rvb  * trees.  It will then be tailored to the particular platform
     75  1.1  rvb  * by flushing conditional code.
     76  1.1  rvb  *
     77  1.1  rvb  * Revision 1.10  1998/08/18 17:05:19  rvb
     78  1.1  rvb  * Don't use __RCSID now
     79  1.1  rvb  *
     80  1.1  rvb  * Revision 1.9  1998/08/18 16:31:44  rvb
     81  1.1  rvb  * Sync the code for NetBSD -current; test on 1.3 later
     82  1.1  rvb  *
     83  1.1  rvb  * Revision 1.8  98/02/24  22:22:48  rvb
     84  1.3  rvb  * Fixes up mainly to flush iopen and friends
     85  1.1  rvb  *
     86  1.1  rvb  * Revision 1.7  98/01/23  11:53:45  rvb
     87  1.1  rvb  * Bring RVB_CODA1_1 to HEAD
     88  1.1  rvb  *
     89  1.1  rvb  * Revision 1.6.2.6  98/01/23  11:21:07  rvb
     90  1.3  rvb  * Sync with 2.2.5
     91  1.1  rvb  *
     92  1.1  rvb  * Revision 1.6.2.5  98/01/22  13:05:33  rvb
     93  1.1  rvb  * Move make_coda_node ctlfid later so vfsp is known
     94  1.1  rvb  *
     95  1.1  rvb  * Revision 1.6.2.4  97/12/19  14:26:05  rvb
     96  1.1  rvb  * session id
     97  1.1  rvb  *
     98  1.1  rvb  * Revision 1.6.2.3  97/12/16  12:40:11  rvb
     99  1.1  rvb  * Sync with 1.3
    100  1.1  rvb  *
    101  1.1  rvb  * Revision 1.6.2.2  97/12/10  11:40:25  rvb
    102  1.1  rvb  * No more ody
    103  1.1  rvb  *
    104  1.1  rvb  * Revision 1.6.2.1  97/12/06  17:41:24  rvb
    105  1.1  rvb  * Sync with peters coda.h
    106  1.1  rvb  *
    107  1.1  rvb  * Revision 1.6  97/12/05  10:39:21  rvb
    108  1.1  rvb  * Read CHANGES
    109  1.1  rvb  *
    110  1.1  rvb  * Revision 1.5.14.8  97/11/24  15:44:46  rvb
    111  1.3  rvb  * Final cfs_venus.c w/o macros, but one locking bug
    112  1.1  rvb  *
    113  1.1  rvb  * Revision 1.5.14.7  97/11/21  13:22:03  rvb
    114  1.1  rvb  * Catch a few coda_calls in coda_vfsops.c
    115  1.1  rvb  *
    116  1.1  rvb  * Revision 1.5.14.6  97/11/20  11:46:48  rvb
    117  1.1  rvb  * Capture current cfs_venus
    118  1.1  rvb  *
    119  1.1  rvb  * Revision 1.5.14.5  97/11/18  10:27:17  rvb
    120  1.1  rvb  * cfs_nbsd.c is DEAD!!!; integrated into cfs_vf/vnops.c
    121  1.1  rvb  * cfs_nb_foo and cfs_foo are joined
    122  1.1  rvb  *
    123  1.1  rvb  * Revision 1.5.14.4  97/11/13  22:03:01  rvb
    124  1.1  rvb  * pass2 cfs_NetBSD.h mt
    125  1.1  rvb  *
    126  1.1  rvb  * Revision 1.5.14.3  97/11/12  12:09:40  rvb
    127  1.1  rvb  * reorg pass1
    128  1.1  rvb  *
    129  1.1  rvb  * Revision 1.5.14.2  97/10/29  16:06:28  rvb
    130  1.1  rvb  * Kill DYING
    131  1.1  rvb  *
    132  1.1  rvb  * Revision 1.5.14.1  1997/10/28 23:10:17  rvb
    133  1.1  rvb  * >64Meg; venus can be killed!
    134  1.1  rvb  *
    135  1.1  rvb  * Revision 1.5  1997/01/13 17:11:07  bnoble
    136  1.1  rvb  * Coda statfs needs to return something other than -1 for blocks avail. and
    137  1.1  rvb  * files available for wabi (and other windowsish) programs to install
    138  1.1  rvb  * there correctly.
    139  1.1  rvb  *
    140  1.1  rvb  * Revision 1.4  1996/12/12 22:11:00  bnoble
    141  1.1  rvb  * Fixed the "downcall invokes venus operation" deadlock in all known cases.
    142  1.1  rvb  * There may be more
    143  1.1  rvb  *
    144  1.1  rvb  * Revision 1.3  1996/11/08 18:06:12  bnoble
    145  1.1  rvb  * Minor changes in vnode operation signature, VOP_UPDATE signature, and
    146  1.1  rvb  * some newly defined bits in the include files.
    147  1.1  rvb  *
    148  1.1  rvb  * Revision 1.2  1996/01/02 16:57:04  bnoble
    149  1.3  rvb  * Added support for Coda MiniCache and raw inode calls (final commit)
    150  1.1  rvb  *
    151  1.1  rvb  * Revision 1.1.2.1  1995/12/20 01:57:32  bnoble
    152  1.1  rvb  * Added CODA-specific files
    153  1.1  rvb  *
    154  1.1  rvb  * Revision 3.1.1.1  1995/03/04  19:08:02  bnoble
    155  1.1  rvb  * Branch for NetBSD port revisions
    156  1.1  rvb  *
    157  1.1  rvb  * Revision 3.1  1995/03/04  19:08:01  bnoble
    158  1.1  rvb  * Bump to major revision 3 to prepare for NetBSD port
    159  1.1  rvb  *
    160  1.1  rvb  * Revision 2.4  1995/02/17  16:25:22  dcs
    161  1.1  rvb  * These versions represent several changes:
    162  1.1  rvb  * 1. Allow venus to restart even if outstanding references exist.
    163  1.1  rvb  * 2. Have only one ctlvp per client, as opposed to one per mounted cfs device.d
    164  1.1  rvb  * 3. Allow ody_expand to return many members, not just one.
    165  1.1  rvb  *
    166  1.1  rvb  * Revision 2.3  94/10/14  09:58:21  dcs
    167  1.1  rvb  * Made changes 'cause sun4s have braindead compilers
    168  1.1  rvb  *
    169  1.1  rvb  * Revision 2.2  94/10/12  16:46:33  dcs
    170  1.1  rvb  * Cleaned kernel/venus interface by removing XDR junk, plus
    171  1.1  rvb  * so cleanup to allow this code to be more easily ported.
    172  1.1  rvb  *
    173  1.1  rvb  * Revision 1.3  93/05/28  16:24:29  bnoble
    174  1.1  rvb  * *** empty log message ***
    175  1.1  rvb  *
    176  1.1  rvb  * Revision 1.2  92/10/27  17:58:24  lily
    177  1.3  rvb  * merge kernel/latest and alpha/src/cfs
    178  1.1  rvb  *
    179  1.1  rvb  * Revision 2.3  92/09/30  14:16:32  mja
    180  1.1  rvb  * 	Added call to coda_flush to coda_unmount.
    181  1.1  rvb  * 	[90/12/15            dcs]
    182  1.1  rvb  *
    183  1.1  rvb  * 	Added contributors blurb.
    184  1.1  rvb  * 	[90/12/13            jjk]
    185  1.1  rvb  *
    186  1.1  rvb  * Revision 2.2  90/07/05  11:26:40  mrt
    187  1.1  rvb  * 	Created for the Coda File System.
    188  1.1  rvb  * 	[90/05/23            dcs]
    189  1.1  rvb  *
    190  1.1  rvb  * Revision 1.3  90/05/31  17:01:42  dcs
    191  1.1  rvb  * Prepare for merge with facilities kernel.
    192  1.2  rvb  *
    193  1.5  rvb  *
    194  1.5  rvb  */
    195  1.5  rvb 
    196  1.3  rvb #ifdef	_LKM
    197  1.5  rvb #define	NVCODA 4
    198  1.1  rvb #else
    199  1.1  rvb #include <vcoda.h>
    200  1.1  rvb #endif
    201  1.1  rvb 
    202  1.1  rvb #include <sys/param.h>
    203  1.1  rvb #include <sys/systm.h>
    204  1.1  rvb #include <sys/malloc.h>
    205  1.1  rvb #include <sys/conf.h>
    206  1.1  rvb #include <sys/namei.h>
    207  1.1  rvb #include <sys/mount.h>
    208  1.4  rvb #include <sys/proc.h>
    209  1.4  rvb #include <sys/select.h>
    210  1.4  rvb 
    211  1.4  rvb #include <coda/coda.h>
    212  1.4  rvb #include <coda/cnode.h>
    213  1.4  rvb #include <coda/coda_vfsops.h>
    214  1.1  rvb #include <coda/coda_venus.h>
    215  1.1  rvb #include <coda/coda_subr.h>
    216  1.1  rvb #include <coda/coda_opstats.h>
    217  1.3  rvb /* for VN_RDEV */
    218  1.1  rvb #include <miscfs/specfs/specdev.h>
    219  1.3  rvb 
    220  1.3  rvb int codadebug = 0;
    221  1.1  rvb 
    222  1.3  rvb int coda_vfsop_print_entry = 0;
    223  1.3  rvb #define ENTRY if(coda_vfsop_print_entry) myprintf(("Entered %s\n",__FUNCTION__))
    224  1.1  rvb 
    225  1.1  rvb struct vnode *coda_ctlvp;
    226  1.1  rvb struct coda_mntinfo coda_mnttbl[NVCODA]; /* indexed by minor device number */
    227  1.3  rvb 
    228  1.1  rvb /* structure to keep statistics of internally generated/satisfied calls */
    229  1.3  rvb 
    230  1.3  rvb struct coda_op_stats coda_vfsopstats[CODA_VFSOPS_SIZE];
    231  1.3  rvb 
    232  1.3  rvb #define MARK_ENTRY(op) (coda_vfsopstats[op].entries++)
    233  1.1  rvb #define MARK_INT_SAT(op) (coda_vfsopstats[op].sat_intrn++)
    234  1.3  rvb #define MARK_INT_FAIL(op) (coda_vfsopstats[op].unsat_intrn++)
    235  1.1  rvb #define MRAK_INT_GEN(op) (coda_vfsopstats[op].gen_intrn++)
    236  1.3  rvb 
    237  1.3  rvb extern int coda_nc_initialized;     /* Set if cache has been initialized */
    238  1.1  rvb extern int vc_nb_open __P((dev_t, int, int, struct proc *));
    239  1.3  rvb extern struct cdevsw cdevsw[];    /* For sanity check in coda_mount */
    240  1.3  rvb extern struct vnodeopv_desc coda_vnodeop_opv_desc;
    241  1.1  rvb 
    242  1.1  rvb struct vnodeopv_desc *coda_vnodeopv_descs[] = {
    243  1.1  rvb 	&coda_vnodeop_opv_desc,
    244  1.3  rvb 	NULL,
    245  1.3  rvb };
    246  1.3  rvb 
    247  1.3  rvb struct vfsops coda_vfsops = {
    248  1.3  rvb     MOUNT_CODA,
    249  1.3  rvb     coda_mount,
    250  1.3  rvb     coda_start,
    251  1.3  rvb     coda_unmount,
    252  1.3  rvb     coda_root,
    253  1.3  rvb     coda_quotactl,
    254  1.1  rvb     coda_nb_statfs,
    255  1.1  rvb     coda_sync,
    256  1.1  rvb     coda_vget,
    257  1.1  rvb     (int (*) (struct mount *, struct fid *, struct mbuf *, struct vnode **,
    258  1.3  rvb 	      int *, struct ucred **))
    259  1.3  rvb 	eopnotsupp,
    260  1.1  rvb     (int (*) (struct vnode *, struct fid *)) eopnotsupp,
    261  1.3  rvb     coda_init,
    262  1.1  rvb     coda_sysctl,
    263  1.1  rvb     (int (*)(void)) eopnotsupp,
    264  1.1  rvb     coda_vnodeopv_descs,
    265  1.1  rvb     0
    266  1.3  rvb };
    267  1.1  rvb 
    268  1.1  rvb int
    269  1.1  rvb coda_vfsopstats_init(void)
    270  1.3  rvb {
    271  1.3  rvb 	register int i;
    272  1.3  rvb 
    273  1.3  rvb 	for (i=0;i<CODA_VFSOPS_SIZE;i++) {
    274  1.3  rvb 		coda_vfsopstats[i].opcode = i;
    275  1.3  rvb 		coda_vfsopstats[i].entries = 0;
    276  1.1  rvb 		coda_vfsopstats[i].sat_intrn = 0;
    277  1.1  rvb 		coda_vfsopstats[i].unsat_intrn = 0;
    278  1.1  rvb 		coda_vfsopstats[i].gen_intrn = 0;
    279  1.1  rvb 	}
    280  1.1  rvb 
    281  1.1  rvb 	return 0;
    282  1.1  rvb }
    283  1.1  rvb 
    284  1.1  rvb /*
    285  1.1  rvb  * cfs mount vfsop
    286  1.1  rvb  * Set up mount info record and attach it to vfs struct.
    287  1.3  rvb  */
    288  1.1  rvb /*ARGSUSED*/
    289  1.1  rvb int
    290  1.1  rvb coda_mount(vfsp, path, data, ndp, p)
    291  1.1  rvb     struct mount *vfsp;		/* Allocated and initialized by mount(2) */
    292  1.1  rvb     const char *path;		/* path covered: ignored by the fs-layer */
    293  1.1  rvb     void *data;			/* Need to define a data type for this in netbsd? */
    294  1.1  rvb     struct nameidata *ndp;	/* Clobber this to lookup the device name */
    295  1.1  rvb     struct proc *p;		/* The ever-famous proc pointer */
    296  1.1  rvb {
    297  1.3  rvb     struct vnode *dvp;
    298  1.1  rvb     struct cnode *cp;
    299  1.1  rvb     dev_t dev;
    300  1.1  rvb     struct coda_mntinfo *mi;
    301  1.1  rvb     struct vnode *rootvp;
    302  1.1  rvb     ViceFid rootfid;
    303  1.1  rvb     ViceFid ctlfid;
    304  1.1  rvb     int error;
    305  1.3  rvb 
    306  1.3  rvb     ENTRY;
    307  1.1  rvb 
    308  1.3  rvb     coda_vfsopstats_init();
    309  1.3  rvb     coda_vnodeopstats_init();
    310  1.3  rvb 
    311  1.1  rvb     MARK_ENTRY(CODA_MOUNT_STATS);
    312  1.1  rvb     if (CODA_MOUNTED(vfsp)) {
    313  1.1  rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    314  1.1  rvb 	return(EBUSY);
    315  1.1  rvb     }
    316  1.1  rvb 
    317  1.1  rvb     /* Validate mount device.  Similar to getmdev(). */
    318  1.1  rvb 
    319  1.1  rvb     NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, data, p);
    320  1.1  rvb     error = namei(ndp);
    321  1.3  rvb     dvp = ndp->ni_vp;
    322  1.1  rvb 
    323  1.1  rvb     if (error) {
    324  1.1  rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    325  1.3  rvb 	return (error);
    326  1.1  rvb     }
    327  1.1  rvb     if (dvp->v_type != VCHR) {
    328  1.1  rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    329  1.1  rvb 	vrele(dvp);
    330  1.1  rvb 	return(ENXIO);
    331  1.1  rvb     }
    332  1.3  rvb     dev = dvp->v_specinfo->si_rdev;
    333  1.1  rvb     vrele(dvp);
    334  1.1  rvb     if (major(dev) >= nchrdev || major(dev) < 0) {
    335  1.1  rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    336  1.1  rvb 	return(ENXIO);
    337  1.1  rvb     }
    338  1.1  rvb 
    339  1.1  rvb     /*
    340  1.1  rvb      * See if the device table matches our expectations.
    341  1.3  rvb      */
    342  1.1  rvb     if (cdevsw[major(dev)].d_open != vc_nb_open)
    343  1.1  rvb     {
    344  1.1  rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    345  1.3  rvb 	return(ENXIO);
    346  1.3  rvb     }
    347  1.1  rvb 
    348  1.1  rvb     if (minor(dev) >= NVCODA || minor(dev) < 0) {
    349  1.1  rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    350  1.1  rvb 	return(ENXIO);
    351  1.1  rvb     }
    352  1.1  rvb 
    353  1.3  rvb     /*
    354  1.1  rvb      * Initialize the mount record and link it to the vfs struct
    355  1.1  rvb      */
    356  1.3  rvb     mi = &coda_mnttbl[minor(dev)];
    357  1.1  rvb 
    358  1.1  rvb     if (!VC_OPEN(&mi->mi_vcomm)) {
    359  1.1  rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    360  1.1  rvb 	return(ENODEV);
    361  1.1  rvb     }
    362  1.1  rvb 
    363  1.3  rvb     /* No initialization (here) of mi_vcomm! */
    364  1.1  rvb     vfsp->mnt_data = (qaddr_t)mi;
    365  1.1  rvb     vfsp->mnt_stat.f_fsid.val[0] = 0;
    366  1.1  rvb     vfsp->mnt_stat.f_fsid.val[1] = makefstype(MOUNT_CODA);
    367  1.1  rvb     mi->mi_vfsp = vfsp;
    368  1.3  rvb 
    369  1.3  rvb     /*
    370  1.1  rvb      * Make a root vnode to placate the Vnode interface, but don't
    371  1.1  rvb      * actually make the CODA_ROOT call to venus until the first call
    372  1.1  rvb      * to coda_root in case a server is down while venus is starting.
    373  1.1  rvb      */
    374  1.3  rvb     rootfid.Volume = 0;
    375  1.1  rvb     rootfid.Vnode = 0;
    376  1.1  rvb     rootfid.Unique = 0;
    377  1.1  rvb     cp = make_coda_node(&rootfid, vfsp, VDIR);
    378  1.1  rvb     rootvp = CTOV(cp);
    379  1.1  rvb     rootvp->v_flag |= VROOT;
    380  1.1  rvb 
    381  1.3  rvb     ctlfid.Volume = CTL_VOL;
    382  1.1  rvb     ctlfid.Vnode = CTL_VNO;
    383  1.1  rvb     ctlfid.Unique = CTL_UNI;
    384  1.1  rvb /*  cp = make_coda_node(&ctlfid, vfsp, VCHR);
    385  1.1  rvb     The above code seems to cause a loop in the cnode links.
    386  1.3  rvb     I don't totally understand when it happens, it is caught
    387  1.1  rvb     when closing down the system.
    388  1.3  rvb  */
    389  1.1  rvb     cp = make_coda_node(&ctlfid, 0, VCHR);
    390  1.1  rvb 
    391  1.1  rvb     coda_ctlvp = CTOV(cp);
    392  1.1  rvb 
    393  1.1  rvb     /* Add vfs and rootvp to chain of vfs hanging off mntinfo */
    394  1.1  rvb     mi->mi_vfsp = vfsp;
    395  1.1  rvb     mi->mi_rootvp = rootvp;
    396  1.1  rvb 
    397  1.1  rvb     /* set filesystem block size */
    398  1.1  rvb     vfsp->mnt_stat.f_bsize = 8192;	    /* XXX -JJK */
    399  1.3  rvb 
    400  1.3  rvb     /* error is currently guaranteed to be zero, but in case some
    401  1.1  rvb        code changes... */
    402  1.3  rvb     CODADEBUG(1,
    403  1.1  rvb 	     myprintf(("coda_mount returned %d\n",error)););
    404  1.3  rvb     if (error)
    405  1.1  rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    406  1.1  rvb     else
    407  1.1  rvb 	MARK_INT_SAT(CODA_MOUNT_STATS);
    408  1.1  rvb 
    409  1.1  rvb     return(error);
    410  1.3  rvb }
    411  1.1  rvb 
    412  1.1  rvb int
    413  1.1  rvb coda_start(vfsp, flags, p)
    414  1.1  rvb     struct mount *vfsp;
    415  1.1  rvb     int flags;
    416  1.1  rvb     struct proc *p;
    417  1.1  rvb {
    418  1.1  rvb     ENTRY;
    419  1.1  rvb     return (0);
    420  1.3  rvb }
    421  1.1  rvb 
    422  1.1  rvb int
    423  1.1  rvb coda_unmount(vfsp, mntflags, p)
    424  1.1  rvb     struct mount *vfsp;
    425  1.3  rvb     int mntflags;
    426  1.1  rvb     struct proc *p;
    427  1.1  rvb {
    428  1.1  rvb     struct coda_mntinfo *mi = vftomi(vfsp);
    429  1.3  rvb     int active, error = 0;
    430  1.3  rvb 
    431  1.3  rvb     ENTRY;
    432  1.1  rvb     MARK_ENTRY(CODA_UMOUNT_STATS);
    433  1.1  rvb     if (!CODA_MOUNTED(vfsp)) {
    434  1.1  rvb 	MARK_INT_FAIL(CODA_UMOUNT_STATS);
    435  1.1  rvb 	return(EINVAL);
    436  1.1  rvb     }
    437  1.1  rvb 
    438  1.1  rvb     if (mi->mi_vfsp == vfsp) {	/* We found the victim */
    439  1.1  rvb 	if (!IS_UNMOUNTING(VTOC(mi->mi_rootvp)))
    440  1.3  rvb 	    return (EBUSY); 	/* Venus is still running */
    441  1.1  rvb 
    442  1.1  rvb #ifdef	DEBUG
    443  1.1  rvb 	printf("coda_unmount: ROOT: vp %p, cp %p\n", mi->mi_rootvp, VTOC(mi->mi_rootvp));
    444  1.3  rvb #endif
    445  1.6  rvb 	vrele(mi->mi_rootvp);
    446  1.1  rvb 
    447  1.3  rvb 	active = coda_kill(vfsp, NOT_DOWNCALL);
    448  1.1  rvb 	mi->mi_rootvp->v_flag &= ~VROOT;
    449  1.2  rvb 	error = vflush(mi->mi_vfsp, NULLVP, FORCECLOSE);
    450  1.1  rvb 	printf("coda_unmount: active = %d, vflush active %d\n", active, error);
    451  1.1  rvb 	error = 0;
    452  1.1  rvb 
    453  1.1  rvb 	/* I'm going to take this out to allow lookups to go through. I'm
    454  1.1  rvb 	 * not sure it's important anyway. -- DCS 2/2/94
    455  1.1  rvb 	 */
    456  1.1  rvb 	/* vfsp->VFS_DATA = NULL; */
    457  1.1  rvb 
    458  1.1  rvb 	/* No more vfsp's to hold onto */
    459  1.1  rvb 	mi->mi_vfsp = NULL;
    460  1.3  rvb 	mi->mi_rootvp = NULL;
    461  1.1  rvb 
    462  1.3  rvb 	if (error)
    463  1.1  rvb 	    MARK_INT_FAIL(CODA_UMOUNT_STATS);
    464  1.1  rvb 	else
    465  1.1  rvb 	    MARK_INT_SAT(CODA_UMOUNT_STATS);
    466  1.1  rvb 
    467  1.1  rvb 	return(error);
    468  1.1  rvb     }
    469  1.1  rvb     return (EINVAL);
    470  1.1  rvb }
    471  1.1  rvb 
    472  1.1  rvb /*
    473  1.3  rvb  * find root of cfs
    474  1.1  rvb  */
    475  1.1  rvb int
    476  1.1  rvb coda_root(vfsp, vpp)
    477  1.3  rvb 	struct mount *vfsp;
    478  1.1  rvb 	struct vnode **vpp;
    479  1.1  rvb {
    480  1.1  rvb     struct coda_mntinfo *mi = vftomi(vfsp);
    481  1.1  rvb     struct vnode **result;
    482  1.1  rvb     int error;
    483  1.1  rvb     struct proc *p = curproc;    /* XXX - bnoble */
    484  1.3  rvb     ViceFid VFid;
    485  1.1  rvb 
    486  1.1  rvb     ENTRY;
    487  1.1  rvb     MARK_ENTRY(CODA_ROOT_STATS);
    488  1.1  rvb     result = NULL;
    489  1.1  rvb 
    490  1.1  rvb     if (vfsp == mi->mi_vfsp) {
    491  1.1  rvb 	if ((VTOC(mi->mi_rootvp)->c_fid.Volume != 0) ||
    492  1.1  rvb 	    (VTOC(mi->mi_rootvp)->c_fid.Vnode != 0) ||
    493  1.1  rvb 	    (VTOC(mi->mi_rootvp)->c_fid.Unique != 0))
    494  1.1  rvb 	    { /* Found valid root. */
    495  1.2  rvb 		*vpp = mi->mi_rootvp;
    496  1.3  rvb 		/* On Mach, this is vref.  On NetBSD, VOP_LOCK */
    497  1.1  rvb 		vref(*vpp);
    498  1.1  rvb 		vn_lock(*vpp, LK_EXCLUSIVE);
    499  1.1  rvb 		MARK_INT_SAT(CODA_ROOT_STATS);
    500  1.1  rvb 		return(0);
    501  1.1  rvb 	    }
    502  1.1  rvb     }
    503  1.1  rvb 
    504  1.1  rvb     error = venus_root(vftomi(vfsp), p->p_cred->pc_ucred, p, &VFid);
    505  1.1  rvb 
    506  1.1  rvb     if (!error) {
    507  1.1  rvb 	/*
    508  1.3  rvb 	 * Save the new rootfid in the cnode, and rehash the cnode into the
    509  1.1  rvb 	 * cnode hash with the new fid key.
    510  1.3  rvb 	 */
    511  1.1  rvb 	coda_unsave(VTOC(mi->mi_rootvp));
    512  1.1  rvb 	VTOC(mi->mi_rootvp)->c_fid = VFid;
    513  1.1  rvb 	coda_save(VTOC(mi->mi_rootvp));
    514  1.2  rvb 
    515  1.3  rvb 	*vpp = mi->mi_rootvp;
    516  1.1  rvb 	vref(*vpp);
    517  1.6  rvb 	vn_lock(*vpp, LK_EXCLUSIVE);
    518  1.1  rvb 	MARK_INT_SAT(CODA_ROOT_STATS);
    519  1.1  rvb 	goto exit;
    520  1.3  rvb     } else if (error == ENODEV || error == EINTR) {
    521  1.1  rvb 	/* Gross hack here! */
    522  1.1  rvb 	/*
    523  1.1  rvb 	 * If Venus fails to respond to the CODA_ROOT call, coda_call returns
    524  1.3  rvb 	 * ENODEV. Return the uninitialized root vnode to allow vfs
    525  1.1  rvb 	 * operations such as unmount to continue. Without this hack,
    526  1.1  rvb 	 * there is no way to do an unmount if Venus dies before a
    527  1.1  rvb 	 * successful CODA_ROOT call is done. All vnode operations
    528  1.1  rvb 	 * will fail.
    529  1.2  rvb 	 */
    530  1.3  rvb 	*vpp = mi->mi_rootvp;
    531  1.1  rvb 	vref(*vpp);
    532  1.1  rvb 	vn_lock(*vpp, LK_EXCLUSIVE);
    533  1.1  rvb 	MARK_INT_FAIL(CODA_ROOT_STATS);
    534  1.3  rvb 	error = 0;
    535  1.3  rvb 	goto exit;
    536  1.1  rvb     } else {
    537  1.1  rvb 	CODADEBUG( CODA_ROOT, myprintf(("error %d in CODA_ROOT\n", error)); );
    538  1.1  rvb 	MARK_INT_FAIL(CODA_ROOT_STATS);
    539  1.1  rvb 
    540  1.1  rvb 	goto exit;
    541  1.1  rvb     }
    542  1.1  rvb  exit:
    543  1.1  rvb     return(error);
    544  1.3  rvb }
    545  1.1  rvb 
    546  1.1  rvb int
    547  1.1  rvb coda_quotactl(vfsp, cmd, uid, arg, p)
    548  1.1  rvb     struct mount *vfsp;
    549  1.1  rvb     int cmd;
    550  1.1  rvb     uid_t uid;
    551  1.1  rvb     caddr_t arg;
    552  1.1  rvb     struct proc *p;
    553  1.1  rvb {
    554  1.1  rvb     ENTRY;
    555  1.1  rvb     return (EOPNOTSUPP);
    556  1.1  rvb }
    557  1.1  rvb 
    558  1.1  rvb /*
    559  1.3  rvb  * Get file system statistics.
    560  1.1  rvb  */
    561  1.1  rvb int
    562  1.1  rvb coda_nb_statfs(vfsp, sbp, p)
    563  1.1  rvb     register struct mount *vfsp;
    564  1.1  rvb     struct statfs *sbp;
    565  1.3  rvb     struct proc *p;
    566  1.3  rvb {
    567  1.3  rvb     ENTRY;
    568  1.1  rvb /*  MARK_ENTRY(CODA_STATFS_STATS); */
    569  1.1  rvb     if (!CODA_MOUNTED(vfsp)) {
    570  1.1  rvb /*	MARK_INT_FAIL(CODA_STATFS_STATS);*/
    571  1.1  rvb 	return(EINVAL);
    572  1.1  rvb     }
    573  1.1  rvb 
    574  1.1  rvb     bzero(sbp, sizeof(struct statfs));
    575  1.1  rvb     /* XXX - what to do about f_flags, others? --bnoble */
    576  1.1  rvb     /* Below This is what AFS does
    577  1.1  rvb     	#define NB_SFS_SIZ 0x895440
    578  1.1  rvb      */
    579  1.1  rvb     /* Note: Normal fs's have a bsize of 0x400 == 1024 */
    580  1.1  rvb     sbp->f_type = 0;
    581  1.1  rvb     sbp->f_bsize = 8192; /* XXX */
    582  1.1  rvb     sbp->f_iosize = 8192; /* XXX */
    583  1.1  rvb #define NB_SFS_SIZ 0x8AB75D
    584  1.1  rvb     sbp->f_blocks = NB_SFS_SIZ;
    585  1.1  rvb     sbp->f_bfree = NB_SFS_SIZ;
    586  1.1  rvb     sbp->f_bavail = NB_SFS_SIZ;
    587  1.3  rvb     sbp->f_files = NB_SFS_SIZ;
    588  1.1  rvb     sbp->f_ffree = NB_SFS_SIZ;
    589  1.3  rvb     bcopy((caddr_t)&(vfsp->mnt_stat.f_fsid), (caddr_t)&(sbp->f_fsid), sizeof (fsid_t));
    590  1.3  rvb     strncpy(sbp->f_fstypename, MOUNT_CODA, MFSNAMELEN-1);
    591  1.1  rvb     strcpy(sbp->f_mntonname, "/coda");
    592  1.1  rvb     strcpy(sbp->f_mntfromname, "CODA");
    593  1.1  rvb /*  MARK_INT_SAT(CODA_STATFS_STATS); */
    594  1.1  rvb     return(0);
    595  1.1  rvb }
    596  1.1  rvb 
    597  1.1  rvb /*
    598  1.3  rvb  * Flush any pending I/O.
    599  1.1  rvb  */
    600  1.1  rvb int
    601  1.1  rvb coda_sync(vfsp, waitfor, cred, p)
    602  1.1  rvb     struct mount *vfsp;
    603  1.1  rvb     int    waitfor;
    604  1.1  rvb     struct ucred *cred;
    605  1.3  rvb     struct proc *p;
    606  1.3  rvb {
    607  1.1  rvb     ENTRY;
    608  1.1  rvb     MARK_ENTRY(CODA_SYNC_STATS);
    609  1.1  rvb     MARK_INT_SAT(CODA_SYNC_STATS);
    610  1.1  rvb     return(0);
    611  1.3  rvb }
    612  1.1  rvb 
    613  1.1  rvb int
    614  1.1  rvb coda_vget(vfsp, ino, vpp)
    615  1.1  rvb     struct mount *vfsp;
    616  1.1  rvb     ino_t ino;
    617  1.1  rvb     struct vnode **vpp;
    618  1.1  rvb {
    619  1.1  rvb     ENTRY;
    620  1.1  rvb     return (EOPNOTSUPP);
    621  1.1  rvb }
    622  1.1  rvb 
    623  1.1  rvb /*
    624  1.1  rvb  * fhtovp is now what vget used to be in 4.3-derived systems.  For
    625  1.1  rvb  * some silly reason, vget is now keyed by a 32 bit ino_t, rather than
    626  1.3  rvb  * a type-specific fid.
    627  1.1  rvb  */
    628  1.1  rvb int
    629  1.1  rvb coda_fhtovp(vfsp, fhp, nam, vpp, exflagsp, creadanonp)
    630  1.1  rvb     register struct mount *vfsp;
    631  1.1  rvb     struct fid *fhp;
    632  1.1  rvb     struct mbuf *nam;
    633  1.1  rvb     struct vnode **vpp;
    634  1.1  rvb     int *exflagsp;
    635  1.1  rvb     struct ucred **creadanonp;
    636  1.1  rvb {
    637  1.1  rvb     struct cfid *cfid = (struct cfid *)fhp;
    638  1.1  rvb     struct cnode *cp = 0;
    639  1.1  rvb     int error;
    640  1.1  rvb     struct proc *p = curproc; /* XXX -mach */
    641  1.1  rvb     ViceFid VFid;
    642  1.1  rvb     int vtype;
    643  1.3  rvb 
    644  1.1  rvb     ENTRY;
    645  1.1  rvb 
    646  1.3  rvb     MARK_ENTRY(CODA_VGET_STATS);
    647  1.3  rvb     /* Check for vget of control object. */
    648  1.3  rvb     if (IS_CTL_FID(&cfid->cfid_fid)) {
    649  1.1  rvb 	*vpp = coda_ctlvp;
    650  1.1  rvb 	vref(coda_ctlvp);
    651  1.1  rvb 	MARK_INT_SAT(CODA_VGET_STATS);
    652  1.1  rvb 	return(0);
    653  1.1  rvb     }
    654  1.1  rvb 
    655  1.3  rvb     error = venus_fhtovp(vftomi(vfsp), &cfid->cfid_fid, p->p_cred->pc_ucred, p, &VFid, &vtype);
    656  1.1  rvb 
    657  1.1  rvb     if (error) {
    658  1.3  rvb 	CODADEBUG(CODA_VGET, myprintf(("vget error %d\n",error));)
    659  1.1  rvb 	    *vpp = (struct vnode *)0;
    660  1.1  rvb     } else {
    661  1.1  rvb 	CODADEBUG(CODA_VGET,
    662  1.3  rvb 		 myprintf(("vget: vol %lx vno %lx uni %lx type %d result %d\n",
    663  1.1  rvb 			VFid.Volume, VFid.Vnode, VFid.Unique, vtype, error)); )
    664  1.1  rvb 
    665  1.1  rvb 	cp = make_coda_node(&VFid, vfsp, vtype);
    666  1.1  rvb 	*vpp = CTOV(cp);
    667  1.1  rvb     }
    668  1.1  rvb     return(error);
    669  1.3  rvb }
    670  1.1  rvb 
    671  1.1  rvb int
    672  1.1  rvb coda_vptofh(vnp, fidp)
    673  1.1  rvb     struct vnode *vnp;
    674  1.1  rvb     struct fid   *fidp;
    675  1.1  rvb {
    676  1.1  rvb     ENTRY;
    677  1.1  rvb     return (EOPNOTSUPP);
    678  1.3  rvb }
    679  1.1  rvb 
    680  1.1  rvb void
    681  1.1  rvb coda_init(void)
    682  1.1  rvb {
    683  1.1  rvb     ENTRY;
    684  1.3  rvb }
    685  1.1  rvb 
    686  1.1  rvb int
    687  1.1  rvb coda_sysctl(name, namelen, oldp, oldlp, newp, newl, p)
    688  1.1  rvb 	int *name;
    689  1.1  rvb 	u_int namelen;
    690  1.1  rvb 	void *oldp;
    691  1.1  rvb 	size_t *oldlp;
    692  1.1  rvb 	void *newp;
    693  1.1  rvb 	size_t newl;
    694  1.1  rvb 	struct proc *p;
    695  1.1  rvb {
    696  1.1  rvb 
    697  1.1  rvb 	/* all sysctl names at this level are terminal */
    698  1.1  rvb 	if (namelen != 1)
    699  1.1  rvb 		return (ENOTDIR);		/* overloaded */
    700  1.1  rvb 
    701  1.1  rvb 	switch (name[0]) {
    702  1.1  rvb /*
    703  1.1  rvb 	case FFS_CLUSTERREAD:
    704  1.1  rvb 		return (sysctl_int(oldp, oldlp, newp, newl, &doclusterread));
    705  1.1  rvb  */
    706  1.1  rvb 	default:
    707  1.1  rvb 		return (EOPNOTSUPP);
    708  1.1  rvb 	}
    709  1.1  rvb 	/* NOTREACHED */
    710  1.1  rvb }
    711  1.1  rvb 
    712  1.1  rvb /*
    713  1.1  rvb  * To allow for greater ease of use, some vnodes may be orphaned when
    714  1.1  rvb  * Venus dies.  Certain operations should still be allowed to go
    715  1.1  rvb  * through, but without propagating ophan-ness.  So this function will
    716  1.1  rvb  * get a new vnode for the file from the current run of Venus.  */
    717  1.1  rvb 
    718  1.1  rvb int
    719  1.1  rvb getNewVnode(vpp)
    720  1.3  rvb      struct vnode **vpp;
    721  1.1  rvb {
    722  1.1  rvb     struct cfid cfid;
    723  1.1  rvb     struct coda_mntinfo *mi = vftomi((*vpp)->v_mount);
    724  1.1  rvb 
    725  1.1  rvb     ENTRY;
    726  1.1  rvb 
    727  1.1  rvb     cfid.cfid_len = (short)sizeof(ViceFid);
    728  1.1  rvb     cfid.cfid_fid = VTOC(*vpp)->c_fid;	/* Structure assignment. */
    729  1.1  rvb     /* XXX ? */
    730  1.1  rvb 
    731  1.1  rvb     /* We're guessing that if set, the 1st element on the list is a
    732  1.1  rvb      * valid vnode to use. If not, return ENODEV as venus is dead.
    733  1.1  rvb      */
    734  1.3  rvb     if (mi->mi_vfsp == NULL)
    735  1.1  rvb 	return ENODEV;
    736  1.1  rvb 
    737  1.1  rvb     return coda_fhtovp(mi->mi_vfsp, (struct fid*)&cfid, NULL, vpp,
    738  1.1  rvb 		      NULL, NULL);
    739  1.1  rvb }
    740  1.1  rvb 
    741  1.1  rvb #include <ufs/ufs/quota.h>
    742  1.1  rvb #include <ufs/ufs/ufsmount.h>
    743  1.1  rvb /* get the mount structure corresponding to a given device.  Assume
    744  1.1  rvb  * device corresponds to a UFS. Return NULL if no device is found.
    745  1.1  rvb  */
    746  1.1  rvb struct mount *devtomp(dev)
    747  1.1  rvb     dev_t dev;
    748  1.1  rvb {
    749  1.1  rvb     struct mount *mp, *nmp;
    750  1.2  rvb 
    751  1.1  rvb     for (mp = mountlist.cqh_first; mp != (void*)&mountlist; mp = nmp) {
    752  1.1  rvb 	nmp = mp->mnt_list.cqe_next;
    753  1.1  rvb 	if ((!strcmp(mp->mnt_op->vfs_name, MOUNT_UFS)) &&
    754  1.1  rvb 	    ((VFSTOUFS(mp))->um_dev == (dev_t) dev)) {
    755  1.1  rvb 	    /* mount corresponds to UFS and the device matches one we want */
    756  1.1  rvb 	    return(mp);
    757  1.1  rvb 	}
    758  1.1  rvb     }
    759               /* mount structure wasn't found */
    760               return(NULL);
    761           }
    762