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