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