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