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