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