Home | History | Annotate | Line # | Download | only in coda
coda_vfsops.c revision 1.26.2.7
      1  1.26.2.7     skrll /*	$NetBSD: coda_vfsops.c,v 1.26.2.7 2004/10/19 15:56:42 skrll 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.14     lukem 
     47      1.14     lukem #include <sys/cdefs.h>
     48  1.26.2.7     skrll __KERNEL_RCSID(0, "$NetBSD: coda_vfsops.c,v 1.26.2.7 2004/10/19 15:56:42 skrll Exp $");
     49       1.2       rvb 
     50       1.5       rvb #ifdef	_LKM
     51       1.5       rvb #define	NVCODA 4
     52       1.5       rvb #else
     53       1.3       rvb #include <vcoda.h>
     54       1.5       rvb #endif
     55       1.1       rvb 
     56       1.1       rvb #include <sys/param.h>
     57       1.1       rvb #include <sys/systm.h>
     58  1.26.2.3     skrll #include <sys/sysctl.h>
     59       1.1       rvb #include <sys/malloc.h>
     60       1.1       rvb #include <sys/conf.h>
     61       1.1       rvb #include <sys/namei.h>
     62  1.26.2.3     skrll #include <sys/dirent.h>
     63       1.1       rvb #include <sys/mount.h>
     64       1.1       rvb #include <sys/proc.h>
     65       1.1       rvb #include <sys/select.h>
     66       1.1       rvb 
     67       1.4       rvb #include <coda/coda.h>
     68       1.4       rvb #include <coda/cnode.h>
     69       1.4       rvb #include <coda/coda_vfsops.h>
     70       1.4       rvb #include <coda/coda_venus.h>
     71       1.4       rvb #include <coda/coda_subr.h>
     72       1.4       rvb #include <coda/coda_opstats.h>
     73       1.1       rvb /* for VN_RDEV */
     74       1.1       rvb #include <miscfs/specfs/specdev.h>
     75      1.21   thorpej 
     76      1.21   thorpej MALLOC_DEFINE(M_CODA, "coda", "Coda file system structures and tables");
     77       1.1       rvb 
     78       1.3       rvb int codadebug = 0;
     79       1.1       rvb 
     80       1.3       rvb int coda_vfsop_print_entry = 0;
     81      1.15     perry #define ENTRY if(coda_vfsop_print_entry) myprintf(("Entered %s\n",__func__))
     82       1.1       rvb 
     83       1.3       rvb struct vnode *coda_ctlvp;
     84       1.3       rvb struct coda_mntinfo coda_mnttbl[NVCODA]; /* indexed by minor device number */
     85       1.1       rvb 
     86       1.1       rvb /* structure to keep statistics of internally generated/satisfied calls */
     87       1.1       rvb 
     88       1.3       rvb struct coda_op_stats coda_vfsopstats[CODA_VFSOPS_SIZE];
     89       1.1       rvb 
     90       1.3       rvb #define MARK_ENTRY(op) (coda_vfsopstats[op].entries++)
     91       1.3       rvb #define MARK_INT_SAT(op) (coda_vfsopstats[op].sat_intrn++)
     92       1.3       rvb #define MARK_INT_FAIL(op) (coda_vfsopstats[op].unsat_intrn++)
     93       1.3       rvb #define MRAK_INT_GEN(op) (coda_vfsopstats[op].gen_intrn++)
     94       1.1       rvb 
     95      1.18   gehenna extern const struct cdevsw vcoda_cdevsw;
     96      1.11  jdolecek extern const struct vnodeopv_desc coda_vnodeop_opv_desc;
     97       1.1       rvb 
     98      1.11  jdolecek const struct vnodeopv_desc * const coda_vnodeopv_descs[] = {
     99       1.3       rvb 	&coda_vnodeop_opv_desc,
    100       1.1       rvb 	NULL,
    101       1.1       rvb };
    102       1.1       rvb 
    103       1.3       rvb struct vfsops coda_vfsops = {
    104       1.3       rvb     MOUNT_CODA,
    105       1.3       rvb     coda_mount,
    106       1.3       rvb     coda_start,
    107       1.3       rvb     coda_unmount,
    108       1.3       rvb     coda_root,
    109       1.3       rvb     coda_quotactl,
    110  1.26.2.3     skrll     coda_nb_statvfs,
    111       1.3       rvb     coda_sync,
    112       1.3       rvb     coda_vget,
    113  1.26.2.6     skrll     (int (*) (struct mount *, struct fid *, struct vnode **))
    114       1.1       rvb 	eopnotsupp,
    115       1.1       rvb     (int (*) (struct vnode *, struct fid *)) eopnotsupp,
    116       1.3       rvb     coda_init,
    117      1.13       chs     NULL,
    118       1.9  jdolecek     coda_done,
    119  1.26.2.3     skrll     NULL,
    120       1.1       rvb     (int (*)(void)) eopnotsupp,
    121       1.7  wrstuden     (int (*)(struct mount *, struct mbuf *, int *, struct ucred **))
    122       1.7  wrstuden 	eopnotsupp,
    123  1.26.2.3     skrll     (int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
    124       1.3       rvb     coda_vnodeopv_descs,
    125       1.1       rvb     0
    126       1.1       rvb };
    127       1.1       rvb 
    128  1.26.2.3     skrll 
    129       1.1       rvb int
    130       1.3       rvb coda_vfsopstats_init(void)
    131       1.1       rvb {
    132      1.10  augustss 	int i;
    133       1.1       rvb 
    134       1.3       rvb 	for (i=0;i<CODA_VFSOPS_SIZE;i++) {
    135       1.3       rvb 		coda_vfsopstats[i].opcode = i;
    136       1.3       rvb 		coda_vfsopstats[i].entries = 0;
    137       1.3       rvb 		coda_vfsopstats[i].sat_intrn = 0;
    138       1.3       rvb 		coda_vfsopstats[i].unsat_intrn = 0;
    139       1.3       rvb 		coda_vfsopstats[i].gen_intrn = 0;
    140       1.1       rvb 	}
    141       1.1       rvb 
    142       1.1       rvb 	return 0;
    143       1.1       rvb }
    144       1.1       rvb 
    145       1.1       rvb /*
    146       1.1       rvb  * cfs mount vfsop
    147       1.1       rvb  * Set up mount info record and attach it to vfs struct.
    148       1.1       rvb  */
    149       1.1       rvb /*ARGSUSED*/
    150       1.1       rvb int
    151  1.26.2.6     skrll coda_mount(vfsp, path, data, ndp, l)
    152       1.1       rvb     struct mount *vfsp;		/* Allocated and initialized by mount(2) */
    153       1.1       rvb     const char *path;		/* path covered: ignored by the fs-layer */
    154       1.1       rvb     void *data;			/* Need to define a data type for this in netbsd? */
    155       1.1       rvb     struct nameidata *ndp;	/* Clobber this to lookup the device name */
    156  1.26.2.6     skrll     struct lwp *l;		/* The ever-famous lwp pointer */
    157       1.1       rvb {
    158       1.1       rvb     struct vnode *dvp;
    159       1.1       rvb     struct cnode *cp;
    160       1.1       rvb     dev_t dev;
    161       1.3       rvb     struct coda_mntinfo *mi;
    162       1.1       rvb     struct vnode *rootvp;
    163      1.18   gehenna     const struct cdevsw *cdev;
    164  1.26.2.3     skrll     CodaFid rootfid = INVAL_FID;
    165  1.26.2.3     skrll     CodaFid ctlfid = CTL_FID;
    166       1.1       rvb     int error;
    167       1.1       rvb 
    168      1.19  christos     if (vfsp->mnt_flag & MNT_GETARGS)
    169      1.19  christos 	return 0;
    170       1.1       rvb     ENTRY;
    171       1.1       rvb 
    172       1.3       rvb     coda_vfsopstats_init();
    173       1.3       rvb     coda_vnodeopstats_init();
    174       1.1       rvb 
    175       1.3       rvb     MARK_ENTRY(CODA_MOUNT_STATS);
    176       1.3       rvb     if (CODA_MOUNTED(vfsp)) {
    177       1.3       rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    178       1.1       rvb 	return(EBUSY);
    179       1.1       rvb     }
    180       1.1       rvb 
    181       1.1       rvb     /* Validate mount device.  Similar to getmdev(). */
    182       1.1       rvb 
    183  1.26.2.6     skrll     NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, data, l);
    184       1.1       rvb     error = namei(ndp);
    185       1.1       rvb     dvp = ndp->ni_vp;
    186       1.1       rvb 
    187       1.1       rvb     if (error) {
    188       1.3       rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    189       1.1       rvb 	return (error);
    190       1.1       rvb     }
    191       1.1       rvb     if (dvp->v_type != VCHR) {
    192       1.3       rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    193       1.1       rvb 	vrele(dvp);
    194       1.1       rvb 	return(ENXIO);
    195       1.1       rvb     }
    196       1.1       rvb     dev = dvp->v_specinfo->si_rdev;
    197       1.1       rvb     vrele(dvp);
    198      1.18   gehenna     cdev = cdevsw_lookup(dev);
    199      1.18   gehenna     if (cdev == NULL) {
    200       1.3       rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    201       1.1       rvb 	return(ENXIO);
    202       1.1       rvb     }
    203       1.1       rvb 
    204       1.1       rvb     /*
    205       1.1       rvb      * See if the device table matches our expectations.
    206       1.1       rvb      */
    207      1.18   gehenna     if (cdev != &vcoda_cdevsw)
    208       1.1       rvb     {
    209       1.3       rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    210       1.1       rvb 	return(ENXIO);
    211       1.1       rvb     }
    212       1.1       rvb 
    213       1.3       rvb     if (minor(dev) >= NVCODA || minor(dev) < 0) {
    214       1.3       rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    215       1.1       rvb 	return(ENXIO);
    216       1.1       rvb     }
    217       1.1       rvb 
    218       1.1       rvb     /*
    219       1.1       rvb      * Initialize the mount record and link it to the vfs struct
    220       1.1       rvb      */
    221       1.3       rvb     mi = &coda_mnttbl[minor(dev)];
    222       1.1       rvb 
    223       1.1       rvb     if (!VC_OPEN(&mi->mi_vcomm)) {
    224       1.3       rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    225       1.1       rvb 	return(ENODEV);
    226       1.1       rvb     }
    227       1.1       rvb 
    228       1.1       rvb     /* No initialization (here) of mi_vcomm! */
    229      1.17     soren     vfsp->mnt_data = mi;
    230  1.26.2.3     skrll     vfsp->mnt_stat.f_fsidx.__fsid_val[0] = 0;
    231  1.26.2.3     skrll     vfsp->mnt_stat.f_fsidx.__fsid_val[1] = makefstype(MOUNT_CODA);
    232  1.26.2.3     skrll     vfsp->mnt_stat.f_fsid = vfsp->mnt_stat.f_fsidx.__fsid_val[0];
    233  1.26.2.3     skrll     vfsp->mnt_stat.f_namemax = MAXNAMLEN;
    234       1.1       rvb     mi->mi_vfsp = vfsp;
    235       1.1       rvb 
    236       1.1       rvb     /*
    237       1.1       rvb      * Make a root vnode to placate the Vnode interface, but don't
    238       1.3       rvb      * actually make the CODA_ROOT call to venus until the first call
    239       1.3       rvb      * to coda_root in case a server is down while venus is starting.
    240       1.1       rvb      */
    241       1.3       rvb     cp = make_coda_node(&rootfid, vfsp, VDIR);
    242       1.1       rvb     rootvp = CTOV(cp);
    243       1.1       rvb     rootvp->v_flag |= VROOT;
    244       1.1       rvb 
    245       1.3       rvb /*  cp = make_coda_node(&ctlfid, vfsp, VCHR);
    246       1.1       rvb     The above code seems to cause a loop in the cnode links.
    247       1.1       rvb     I don't totally understand when it happens, it is caught
    248       1.1       rvb     when closing down the system.
    249       1.1       rvb  */
    250       1.3       rvb     cp = make_coda_node(&ctlfid, 0, VCHR);
    251       1.1       rvb 
    252       1.3       rvb     coda_ctlvp = CTOV(cp);
    253       1.1       rvb 
    254       1.1       rvb     /* Add vfs and rootvp to chain of vfs hanging off mntinfo */
    255       1.1       rvb     mi->mi_vfsp = vfsp;
    256       1.1       rvb     mi->mi_rootvp = rootvp;
    257       1.1       rvb 
    258       1.1       rvb     /* set filesystem block size */
    259       1.1       rvb     vfsp->mnt_stat.f_bsize = 8192;	    /* XXX -JJK */
    260  1.26.2.3     skrll     vfsp->mnt_stat.f_frsize = 8192;	    /* XXX -JJK */
    261       1.1       rvb 
    262       1.1       rvb     /* error is currently guaranteed to be zero, but in case some
    263       1.1       rvb        code changes... */
    264       1.3       rvb     CODADEBUG(1,
    265       1.3       rvb 	     myprintf(("coda_mount returned %d\n",error)););
    266       1.1       rvb     if (error)
    267       1.3       rvb 	MARK_INT_FAIL(CODA_MOUNT_STATS);
    268       1.1       rvb     else
    269       1.3       rvb 	MARK_INT_SAT(CODA_MOUNT_STATS);
    270      1.22  christos 
    271  1.26.2.3     skrll     return set_statvfs_info("/coda", UIO_SYSSPACE, "CODA", UIO_SYSSPACE, vfsp,
    272  1.26.2.7     skrll 	l);
    273       1.1       rvb }
    274       1.1       rvb 
    275       1.1       rvb int
    276  1.26.2.6     skrll coda_start(vfsp, flags, l)
    277       1.1       rvb     struct mount *vfsp;
    278       1.1       rvb     int flags;
    279  1.26.2.6     skrll     struct lwp *l;
    280       1.1       rvb {
    281       1.1       rvb     ENTRY;
    282  1.26.2.3     skrll     vftomi(vfsp)->mi_started = 1;
    283       1.1       rvb     return (0);
    284       1.1       rvb }
    285       1.1       rvb 
    286       1.1       rvb int
    287  1.26.2.6     skrll coda_unmount(vfsp, mntflags, l)
    288       1.1       rvb     struct mount *vfsp;
    289       1.1       rvb     int mntflags;
    290  1.26.2.6     skrll     struct lwp *l;
    291       1.1       rvb {
    292       1.3       rvb     struct coda_mntinfo *mi = vftomi(vfsp);
    293       1.1       rvb     int active, error = 0;
    294       1.1       rvb 
    295       1.1       rvb     ENTRY;
    296       1.3       rvb     MARK_ENTRY(CODA_UMOUNT_STATS);
    297       1.3       rvb     if (!CODA_MOUNTED(vfsp)) {
    298       1.3       rvb 	MARK_INT_FAIL(CODA_UMOUNT_STATS);
    299       1.1       rvb 	return(EINVAL);
    300       1.1       rvb     }
    301       1.1       rvb 
    302       1.1       rvb     if (mi->mi_vfsp == vfsp) {	/* We found the victim */
    303       1.1       rvb 	if (!IS_UNMOUNTING(VTOC(mi->mi_rootvp)))
    304       1.1       rvb 	    return (EBUSY); 	/* Venus is still running */
    305       1.1       rvb 
    306       1.1       rvb #ifdef	DEBUG
    307       1.3       rvb 	printf("coda_unmount: ROOT: vp %p, cp %p\n", mi->mi_rootvp, VTOC(mi->mi_rootvp));
    308       1.1       rvb #endif
    309  1.26.2.3     skrll 	mi->mi_started = 0;
    310  1.26.2.3     skrll 
    311       1.1       rvb 	vrele(mi->mi_rootvp);
    312       1.1       rvb 
    313       1.3       rvb 	active = coda_kill(vfsp, NOT_DOWNCALL);
    314       1.6       rvb 	mi->mi_rootvp->v_flag &= ~VROOT;
    315       1.1       rvb 	error = vflush(mi->mi_vfsp, NULLVP, FORCECLOSE);
    316       1.3       rvb 	printf("coda_unmount: active = %d, vflush active %d\n", active, error);
    317       1.1       rvb 	error = 0;
    318       1.2       rvb 
    319       1.1       rvb 	/* I'm going to take this out to allow lookups to go through. I'm
    320       1.1       rvb 	 * not sure it's important anyway. -- DCS 2/2/94
    321       1.1       rvb 	 */
    322       1.1       rvb 	/* vfsp->VFS_DATA = NULL; */
    323       1.1       rvb 
    324       1.1       rvb 	/* No more vfsp's to hold onto */
    325       1.1       rvb 	mi->mi_vfsp = NULL;
    326       1.1       rvb 	mi->mi_rootvp = NULL;
    327       1.1       rvb 
    328       1.1       rvb 	if (error)
    329       1.3       rvb 	    MARK_INT_FAIL(CODA_UMOUNT_STATS);
    330       1.1       rvb 	else
    331       1.3       rvb 	    MARK_INT_SAT(CODA_UMOUNT_STATS);
    332       1.1       rvb 
    333       1.1       rvb 	return(error);
    334       1.1       rvb     }
    335       1.1       rvb     return (EINVAL);
    336       1.1       rvb }
    337       1.1       rvb 
    338       1.1       rvb /*
    339       1.1       rvb  * find root of cfs
    340       1.1       rvb  */
    341       1.1       rvb int
    342  1.26.2.4     skrll coda_root(vfsp, vpp)
    343       1.1       rvb 	struct mount *vfsp;
    344       1.1       rvb 	struct vnode **vpp;
    345       1.1       rvb {
    346       1.3       rvb     struct coda_mntinfo *mi = vftomi(vfsp);
    347       1.1       rvb     int error;
    348  1.26.2.4     skrll     struct proc *p = curproc;    /* XXX - bnoble */
    349  1.26.2.3     skrll     CodaFid VFid;
    350  1.26.2.3     skrll     static const CodaFid invalfid = INVAL_FID;
    351       1.1       rvb 
    352       1.1       rvb     ENTRY;
    353       1.3       rvb     MARK_ENTRY(CODA_ROOT_STATS);
    354       1.1       rvb 
    355       1.1       rvb     if (vfsp == mi->mi_vfsp) {
    356  1.26.2.3     skrll     	if (memcmp(&VTOC(mi->mi_rootvp)->c_fid, &invalfid, sizeof(CodaFid)))
    357       1.1       rvb 	    { /* Found valid root. */
    358       1.1       rvb 		*vpp = mi->mi_rootvp;
    359       1.1       rvb 		/* On Mach, this is vref.  On NetBSD, VOP_LOCK */
    360       1.1       rvb 		vref(*vpp);
    361       1.2       rvb 		vn_lock(*vpp, LK_EXCLUSIVE);
    362       1.3       rvb 		MARK_INT_SAT(CODA_ROOT_STATS);
    363       1.1       rvb 		return(0);
    364       1.1       rvb 	    }
    365       1.1       rvb     }
    366       1.1       rvb 
    367  1.26.2.4     skrll     error = venus_root(vftomi(vfsp), p->p_cred->pc_ucred, p, &VFid);
    368       1.1       rvb 
    369       1.1       rvb     if (!error) {
    370       1.1       rvb 	/*
    371       1.1       rvb 	 * Save the new rootfid in the cnode, and rehash the cnode into the
    372       1.1       rvb 	 * cnode hash with the new fid key.
    373       1.1       rvb 	 */
    374       1.3       rvb 	coda_unsave(VTOC(mi->mi_rootvp));
    375       1.1       rvb 	VTOC(mi->mi_rootvp)->c_fid = VFid;
    376       1.3       rvb 	coda_save(VTOC(mi->mi_rootvp));
    377       1.1       rvb 
    378       1.1       rvb 	*vpp = mi->mi_rootvp;
    379       1.1       rvb 	vref(*vpp);
    380       1.2       rvb 	vn_lock(*vpp, LK_EXCLUSIVE);
    381       1.3       rvb 	MARK_INT_SAT(CODA_ROOT_STATS);
    382       1.1       rvb 	goto exit;
    383       1.6       rvb     } else if (error == ENODEV || error == EINTR) {
    384       1.1       rvb 	/* Gross hack here! */
    385       1.1       rvb 	/*
    386       1.3       rvb 	 * If Venus fails to respond to the CODA_ROOT call, coda_call returns
    387       1.1       rvb 	 * ENODEV. Return the uninitialized root vnode to allow vfs
    388       1.1       rvb 	 * operations such as unmount to continue. Without this hack,
    389       1.1       rvb 	 * there is no way to do an unmount if Venus dies before a
    390       1.3       rvb 	 * successful CODA_ROOT call is done. All vnode operations
    391       1.1       rvb 	 * will fail.
    392       1.1       rvb 	 */
    393       1.1       rvb 	*vpp = mi->mi_rootvp;
    394       1.1       rvb 	vref(*vpp);
    395       1.2       rvb 	vn_lock(*vpp, LK_EXCLUSIVE);
    396       1.3       rvb 	MARK_INT_FAIL(CODA_ROOT_STATS);
    397       1.1       rvb 	error = 0;
    398       1.1       rvb 	goto exit;
    399       1.1       rvb     } else {
    400       1.3       rvb 	CODADEBUG( CODA_ROOT, myprintf(("error %d in CODA_ROOT\n", error)); );
    401       1.3       rvb 	MARK_INT_FAIL(CODA_ROOT_STATS);
    402       1.1       rvb 
    403       1.1       rvb 	goto exit;
    404       1.1       rvb     }
    405       1.1       rvb  exit:
    406       1.1       rvb     return(error);
    407       1.1       rvb }
    408       1.1       rvb 
    409       1.1       rvb int
    410  1.26.2.6     skrll coda_quotactl(vfsp, cmd, uid, arg, l)
    411       1.1       rvb     struct mount *vfsp;
    412       1.1       rvb     int cmd;
    413       1.1       rvb     uid_t uid;
    414  1.26.2.3     skrll     void *arg;
    415  1.26.2.6     skrll     struct lwp *l;
    416       1.1       rvb {
    417       1.1       rvb     ENTRY;
    418       1.1       rvb     return (EOPNOTSUPP);
    419       1.1       rvb }
    420       1.1       rvb 
    421       1.1       rvb /*
    422       1.1       rvb  * Get file system statistics.
    423       1.1       rvb  */
    424       1.1       rvb int
    425  1.26.2.6     skrll coda_nb_statvfs(vfsp, sbp, l)
    426      1.10  augustss     struct mount *vfsp;
    427  1.26.2.3     skrll     struct statvfs *sbp;
    428  1.26.2.6     skrll     struct lwp *l;
    429       1.1       rvb {
    430      1.16      phil     struct coda_statfs fsstat;
    431  1.26.2.6     skrll     struct proc *p = l->l_proc;
    432      1.16      phil     int error;
    433      1.16      phil 
    434       1.1       rvb     ENTRY;
    435      1.16      phil     MARK_ENTRY(CODA_STATFS_STATS);
    436       1.3       rvb     if (!CODA_MOUNTED(vfsp)) {
    437      1.16      phil /*	MARK_INT_FAIL(CODA_STATFS_STATS); */
    438       1.1       rvb 	return(EINVAL);
    439       1.1       rvb     }
    440       1.1       rvb 
    441       1.1       rvb     /* XXX - what to do about f_flags, others? --bnoble */
    442       1.1       rvb     /* Below This is what AFS does
    443       1.1       rvb     	#define NB_SFS_SIZ 0x895440
    444       1.1       rvb      */
    445       1.1       rvb     /* Note: Normal fs's have a bsize of 0x400 == 1024 */
    446      1.16      phil 
    447  1.26.2.6     skrll     error = venus_statfs(vftomi(vfsp), p->p_cred->pc_ucred, l, &fsstat);
    448      1.16      phil 
    449      1.16      phil     if (!error) {
    450      1.16      phil 	sbp->f_bsize = 8192; /* XXX */
    451  1.26.2.3     skrll 	sbp->f_frsize = 8192; /* XXX */
    452      1.16      phil 	sbp->f_iosize = 8192; /* XXX */
    453      1.16      phil 	sbp->f_blocks = fsstat.f_blocks;
    454      1.16      phil 	sbp->f_bfree  = fsstat.f_bfree;
    455      1.16      phil 	sbp->f_bavail = fsstat.f_bavail;
    456  1.26.2.3     skrll 	sbp->f_bresvd = 0;
    457      1.16      phil 	sbp->f_files  = fsstat.f_files;
    458      1.16      phil 	sbp->f_ffree  = fsstat.f_ffree;
    459  1.26.2.3     skrll 	sbp->f_favail = fsstat.f_ffree;
    460  1.26.2.3     skrll 	sbp->f_fresvd = 0;
    461  1.26.2.3     skrll 	copy_statvfs_info(sbp, vfsp);
    462      1.16      phil     }
    463      1.16      phil 
    464      1.16      phil     MARK_INT_SAT(CODA_STATFS_STATS);
    465      1.16      phil     return(error);
    466       1.1       rvb }
    467       1.1       rvb 
    468       1.1       rvb /*
    469       1.1       rvb  * Flush any pending I/O.
    470       1.1       rvb  */
    471       1.1       rvb int
    472  1.26.2.6     skrll coda_sync(vfsp, waitfor, cred, l)
    473       1.1       rvb     struct mount *vfsp;
    474       1.1       rvb     int    waitfor;
    475       1.1       rvb     struct ucred *cred;
    476  1.26.2.6     skrll     struct lwp *l;
    477       1.1       rvb {
    478       1.1       rvb     ENTRY;
    479       1.3       rvb     MARK_ENTRY(CODA_SYNC_STATS);
    480       1.3       rvb     MARK_INT_SAT(CODA_SYNC_STATS);
    481       1.1       rvb     return(0);
    482       1.1       rvb }
    483       1.1       rvb 
    484       1.1       rvb int
    485  1.26.2.4     skrll coda_vget(vfsp, ino, vpp)
    486       1.1       rvb     struct mount *vfsp;
    487       1.1       rvb     ino_t ino;
    488       1.1       rvb     struct vnode **vpp;
    489       1.1       rvb {
    490       1.1       rvb     ENTRY;
    491       1.1       rvb     return (EOPNOTSUPP);
    492       1.1       rvb }
    493       1.1       rvb 
    494       1.1       rvb /*
    495       1.1       rvb  * fhtovp is now what vget used to be in 4.3-derived systems.  For
    496       1.1       rvb  * some silly reason, vget is now keyed by a 32 bit ino_t, rather than
    497       1.1       rvb  * a type-specific fid.
    498       1.1       rvb  */
    499       1.1       rvb int
    500  1.26.2.4     skrll coda_fhtovp(vfsp, fhp, nam, vpp, exflagsp, creadanonp)
    501      1.10  augustss     struct mount *vfsp;
    502       1.1       rvb     struct fid *fhp;
    503       1.1       rvb     struct mbuf *nam;
    504       1.1       rvb     struct vnode **vpp;
    505       1.1       rvb     int *exflagsp;
    506       1.1       rvb     struct ucred **creadanonp;
    507       1.1       rvb {
    508       1.1       rvb     struct cfid *cfid = (struct cfid *)fhp;
    509       1.1       rvb     struct cnode *cp = 0;
    510       1.1       rvb     int error;
    511  1.26.2.4     skrll     struct proc *p = curproc; /* XXX -mach */
    512  1.26.2.3     skrll     CodaFid VFid;
    513       1.1       rvb     int vtype;
    514       1.1       rvb 
    515       1.1       rvb     ENTRY;
    516       1.1       rvb 
    517       1.3       rvb     MARK_ENTRY(CODA_VGET_STATS);
    518       1.1       rvb     /* Check for vget of control object. */
    519       1.1       rvb     if (IS_CTL_FID(&cfid->cfid_fid)) {
    520       1.3       rvb 	*vpp = coda_ctlvp;
    521       1.3       rvb 	vref(coda_ctlvp);
    522       1.3       rvb 	MARK_INT_SAT(CODA_VGET_STATS);
    523       1.1       rvb 	return(0);
    524       1.1       rvb     }
    525       1.1       rvb 
    526  1.26.2.4     skrll     error = venus_fhtovp(vftomi(vfsp), &cfid->cfid_fid, p->p_cred->pc_ucred, p, &VFid, &vtype);
    527       1.1       rvb 
    528       1.1       rvb     if (error) {
    529       1.3       rvb 	CODADEBUG(CODA_VGET, myprintf(("vget error %d\n",error));)
    530       1.1       rvb 	    *vpp = (struct vnode *)0;
    531       1.1       rvb     } else {
    532       1.3       rvb 	CODADEBUG(CODA_VGET,
    533  1.26.2.3     skrll 		 myprintf(("vget: %s type %d result %d\n",
    534  1.26.2.3     skrll 			coda_f2s(&VFid), vtype, error)); )
    535       1.1       rvb 
    536       1.3       rvb 	cp = make_coda_node(&VFid, vfsp, vtype);
    537       1.1       rvb 	*vpp = CTOV(cp);
    538       1.1       rvb     }
    539       1.1       rvb     return(error);
    540       1.1       rvb }
    541       1.1       rvb 
    542       1.1       rvb int
    543       1.3       rvb coda_vptofh(vnp, fidp)
    544       1.1       rvb     struct vnode *vnp;
    545       1.1       rvb     struct fid   *fidp;
    546       1.1       rvb {
    547       1.1       rvb     ENTRY;
    548       1.1       rvb     return (EOPNOTSUPP);
    549       1.1       rvb }
    550       1.1       rvb 
    551       1.1       rvb void
    552       1.3       rvb coda_init(void)
    553       1.1       rvb {
    554       1.1       rvb     ENTRY;
    555       1.1       rvb }
    556       1.9  jdolecek 
    557       1.9  jdolecek void
    558       1.9  jdolecek coda_done(void)
    559       1.9  jdolecek {
    560       1.9  jdolecek     ENTRY;
    561       1.9  jdolecek }
    562       1.1       rvb 
    563  1.26.2.3     skrll SYSCTL_SETUP(sysctl_vfs_coda_setup, "sysctl vfs.coda subtree setup")
    564       1.1       rvb {
    565  1.26.2.3     skrll 	sysctl_createv(clog, 0, NULL, NULL,
    566  1.26.2.3     skrll 		       CTLFLAG_PERMANENT,
    567  1.26.2.3     skrll 		       CTLTYPE_NODE, "vfs", NULL,
    568  1.26.2.3     skrll 		       NULL, 0, NULL, 0,
    569  1.26.2.3     skrll 		       CTL_VFS, CTL_EOL);
    570  1.26.2.3     skrll 	sysctl_createv(clog, 0, NULL, NULL,
    571  1.26.2.3     skrll 		       CTLFLAG_PERMANENT,
    572  1.26.2.3     skrll 		       CTLTYPE_NODE, "coda",
    573  1.26.2.3     skrll 		       SYSCTL_DESCR("code vfs options"),
    574  1.26.2.3     skrll 		       NULL, 0, NULL, 0,
    575  1.26.2.3     skrll 		       CTL_VFS, 18, CTL_EOL);
    576  1.26.2.3     skrll 	/*
    577  1.26.2.3     skrll 	 * XXX the "18" above could be dynamic, thereby eliminating
    578  1.26.2.3     skrll 	 * one more instance of the "number to vfs" mapping problem,
    579  1.26.2.3     skrll 	 * but "18" is the order as taken from sys/mount.h
    580  1.26.2.3     skrll 	 */
    581       1.1       rvb 
    582       1.1       rvb /*
    583  1.26.2.3     skrll 	sysctl_createv(clog, 0, NULL, NULL,
    584  1.26.2.3     skrll 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
    585  1.26.2.3     skrll 		       CTLTYPE_INT, "clusterread",
    586  1.26.2.3     skrll 		       SYSCTL_DESCR( anyone? ),
    587  1.26.2.3     skrll 		       NULL, 0, &doclusterread, 0,
    588  1.26.2.3     skrll 		       CTL_VFS, 18, FFS_CLUSTERREAD, CTL_EOL);
    589  1.26.2.3     skrll */
    590       1.1       rvb }
    591       1.1       rvb 
    592       1.1       rvb /*
    593       1.1       rvb  * To allow for greater ease of use, some vnodes may be orphaned when
    594       1.1       rvb  * Venus dies.  Certain operations should still be allowed to go
    595  1.26.2.3     skrll  * through, but without propagating orphan-ness.  So this function will
    596  1.26.2.3     skrll  * get a new vnode for the file from the current run of Venus.
    597  1.26.2.3     skrll  */
    598       1.1       rvb 
    599       1.1       rvb int
    600       1.1       rvb getNewVnode(vpp)
    601       1.1       rvb      struct vnode **vpp;
    602       1.1       rvb {
    603       1.1       rvb     struct cfid cfid;
    604       1.3       rvb     struct coda_mntinfo *mi = vftomi((*vpp)->v_mount);
    605       1.1       rvb 
    606       1.1       rvb     ENTRY;
    607       1.1       rvb 
    608  1.26.2.3     skrll     cfid.cfid_len = (short)sizeof(CodaFid);
    609       1.1       rvb     cfid.cfid_fid = VTOC(*vpp)->c_fid;	/* Structure assignment. */
    610       1.1       rvb     /* XXX ? */
    611       1.1       rvb 
    612       1.1       rvb     /* We're guessing that if set, the 1st element on the list is a
    613       1.1       rvb      * valid vnode to use. If not, return ENODEV as venus is dead.
    614       1.1       rvb      */
    615       1.1       rvb     if (mi->mi_vfsp == NULL)
    616       1.1       rvb 	return ENODEV;
    617       1.1       rvb 
    618       1.3       rvb     return coda_fhtovp(mi->mi_vfsp, (struct fid*)&cfid, NULL, vpp,
    619  1.26.2.4     skrll 		      NULL, NULL);
    620       1.1       rvb }
    621       1.1       rvb 
    622       1.1       rvb #include <ufs/ufs/quota.h>
    623       1.1       rvb #include <ufs/ufs/ufsmount.h>
    624       1.1       rvb /* get the mount structure corresponding to a given device.  Assume
    625       1.1       rvb  * device corresponds to a UFS. Return NULL if no device is found.
    626       1.1       rvb  */
    627       1.1       rvb struct mount *devtomp(dev)
    628       1.1       rvb     dev_t dev;
    629       1.1       rvb {
    630       1.1       rvb     struct mount *mp, *nmp;
    631       1.1       rvb 
    632       1.1       rvb     for (mp = mountlist.cqh_first; mp != (void*)&mountlist; mp = nmp) {
    633       1.1       rvb 	nmp = mp->mnt_list.cqe_next;
    634       1.2       rvb 	if ((!strcmp(mp->mnt_op->vfs_name, MOUNT_UFS)) &&
    635       1.1       rvb 	    ((VFSTOUFS(mp))->um_dev == (dev_t) dev)) {
    636       1.1       rvb 	    /* mount corresponds to UFS and the device matches one we want */
    637       1.1       rvb 	    return(mp);
    638       1.1       rvb 	}
    639       1.1       rvb     }
    640       1.1       rvb     /* mount structure wasn't found */
    641       1.1       rvb     return(NULL);
    642       1.1       rvb }
    643