Home | History | Annotate | Line # | Download | only in coda
coda_subr.c revision 1.27.16.1
      1  1.27.16.1     skrll /*	$NetBSD: coda_subr.c,v 1.27.16.1 2015/04/06 15:18:05 skrll Exp $	*/
      2        1.2       rvb 
      3        1.1       rvb /*
      4       1.17     perry  *
      5        1.2       rvb  *             Coda: an Experimental Distributed File System
      6        1.2       rvb  *                              Release 3.1
      7       1.17     perry  *
      8        1.2       rvb  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9        1.2       rvb  *                          All Rights Reserved
     10       1.17     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.17     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.17     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.17     perry  *
     31       1.17     perry  * 	@(#) coda/coda_subr.c,v 1.1.1.1 1998/08/29 21:26:45 rvb Exp $
     32        1.2       rvb  */
     33        1.1       rvb 
     34       1.17     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.1       rvb  * M. Satyanarayanan.  */
     45        1.1       rvb 
     46        1.1       rvb /* NOTES: rvb
     47        1.3       rvb  * 1.	Added coda_unmounting to mark all cnodes as being UNMOUNTING.  This has to
     48        1.1       rvb  *	 be done before dounmount is called.  Because some of the routines that
     49        1.3       rvb  *	 dounmount calls before coda_unmounted might try to force flushes to venus.
     50        1.1       rvb  *	 The vnode pager does this.
     51        1.3       rvb  * 2.	coda_unmounting marks all cnodes scanning coda_cache.
     52        1.1       rvb  * 3.	cfs_checkunmounting (under DEBUG) checks all cnodes by chasing the vnodes
     53        1.1       rvb  *	 under the /coda mount point.
     54        1.3       rvb  * 4.	coda_cacheprint (under DEBUG) prints names with vnode/cnode address
     55        1.1       rvb  */
     56       1.13     lukem 
     57       1.13     lukem #include <sys/cdefs.h>
     58  1.27.16.1     skrll __KERNEL_RCSID(0, "$NetBSD: coda_subr.c,v 1.27.16.1 2015/04/06 15:18:05 skrll Exp $");
     59        1.1       rvb 
     60        1.1       rvb #include <sys/param.h>
     61        1.1       rvb #include <sys/systm.h>
     62        1.1       rvb #include <sys/malloc.h>
     63        1.1       rvb #include <sys/proc.h>
     64        1.1       rvb #include <sys/select.h>
     65        1.1       rvb #include <sys/mount.h>
     66       1.27  christos #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_subr.h>
     71        1.4       rvb #include <coda/coda_namecache.h>
     72        1.1       rvb 
     73       1.26  christos int codadebug = 0;
     74       1.26  christos int coda_printf_delay = 0;  /* in microseconds */
     75       1.26  christos int coda_vnop_print_entry = 0;
     76       1.26  christos int coda_vfsop_print_entry = 0;
     77        1.1       rvb 
     78       1.15  drochner #ifdef CODA_COMPAT_5
     79        1.3       rvb #define coda_hash(fid) \
     80        1.3       rvb     (((fid)->Volume + (fid)->Vnode) & (CODA_CACHESIZE-1))
     81       1.15  drochner #define IS_DIR(cnode)        (cnode.Vnode & 0x1)
     82       1.15  drochner #else
     83       1.15  drochner #define coda_hash(fid) \
     84       1.15  drochner     (coda_f2i(fid) & (CODA_CACHESIZE-1))
     85       1.15  drochner #define IS_DIR(cnode)        (cnode.opaque[2] & 0x1)
     86       1.15  drochner #endif
     87        1.1       rvb 
     88       1.27  christos struct vnode *coda_ctlvp;
     89       1.27  christos 
     90        1.1       rvb /*
     91  1.27.16.1     skrll  * Lookup a cnode by fid. If the cnode is dying, it is bogus so skip it.
     92  1.27.16.1     skrll  * The cnode is returned locked with the vnode referenced.
     93        1.1       rvb  */
     94        1.1       rvb struct cnode *
     95  1.27.16.1     skrll coda_find(CodaFid *fid)
     96        1.1       rvb {
     97  1.27.16.1     skrll 	int i;
     98  1.27.16.1     skrll 	struct vnode *vp;
     99  1.27.16.1     skrll 	struct cnode *cp;
    100        1.1       rvb 
    101  1.27.16.1     skrll 	for (i = 0; i < NVCODA; i++) {
    102  1.27.16.1     skrll 		if (!coda_mnttbl[i].mi_started)
    103  1.27.16.1     skrll 			continue;
    104  1.27.16.1     skrll 		if (vcache_get(coda_mnttbl[i].mi_vfsp,
    105  1.27.16.1     skrll 		    fid, sizeof(CodaFid), &vp) != 0)
    106  1.27.16.1     skrll 			continue;
    107  1.27.16.1     skrll 		mutex_enter(vp->v_interlock);
    108  1.27.16.1     skrll 		cp = VTOC(vp);
    109  1.27.16.1     skrll 		if (vp->v_type == VNON || cp == NULL || IS_UNMOUNTING(cp)) {
    110  1.27.16.1     skrll 			mutex_exit(vp->v_interlock);
    111  1.27.16.1     skrll 			vrele(vp);
    112  1.27.16.1     skrll 			continue;
    113  1.27.16.1     skrll 		}
    114  1.27.16.1     skrll 		mutex_enter(&cp->c_lock);
    115  1.27.16.1     skrll 		mutex_exit(vp->v_interlock);
    116        1.1       rvb 
    117  1.27.16.1     skrll 		return cp;
    118  1.27.16.1     skrll 	}
    119        1.1       rvb 
    120  1.27.16.1     skrll 	return NULL;
    121        1.1       rvb }
    122        1.1       rvb 
    123        1.1       rvb /*
    124  1.27.16.1     skrll  * Iterate over all nodes attached to coda mounts.
    125        1.1       rvb  */
    126  1.27.16.1     skrll static void
    127  1.27.16.1     skrll coda_iterate(bool (*f)(void *, struct vnode *), void *cl)
    128        1.1       rvb {
    129  1.27.16.1     skrll 	int i;
    130  1.27.16.1     skrll 	struct vnode_iterator *marker;
    131  1.27.16.1     skrll 	struct vnode *vp;
    132       1.17     perry 
    133  1.27.16.1     skrll 	for (i = 0; i < NVCODA; i++) {
    134  1.27.16.1     skrll 		if (coda_mnttbl[i].mi_vfsp == NULL)
    135  1.27.16.1     skrll 			continue;
    136  1.27.16.1     skrll 		vfs_vnode_iterator_init(coda_mnttbl[i].mi_vfsp, &marker);
    137  1.27.16.1     skrll 		while ((vp = vfs_vnode_iterator_next(marker, f, cl)) != NULL)
    138  1.27.16.1     skrll 			vrele(vp);
    139  1.27.16.1     skrll 		vfs_vnode_iterator_destroy(marker);
    140       1.17     perry 	}
    141        1.1       rvb }
    142        1.1       rvb 
    143        1.1       rvb /*
    144        1.3       rvb  * coda_kill is called as a side effect to vcopen. To prevent any
    145        1.1       rvb  * cnodes left around from an earlier run of a venus or warden from
    146        1.1       rvb  * causing problems with the new instance, mark any outstanding cnodes
    147        1.1       rvb  * as dying. Future operations on these cnodes should fail (excepting
    148        1.3       rvb  * coda_inactive of course!). Since multiple venii/wardens can be
    149        1.1       rvb  * running, only kill the cnodes for a particular entry in the
    150        1.3       rvb  * coda_mnttbl. -- DCS 12/1/94 */
    151        1.1       rvb 
    152  1.27.16.1     skrll static bool
    153  1.27.16.1     skrll coda_kill_selector(void *cl, struct vnode *vp)
    154  1.27.16.1     skrll {
    155  1.27.16.1     skrll 	int *count = cl;
    156  1.27.16.1     skrll 
    157  1.27.16.1     skrll 	(*count)++;
    158  1.27.16.1     skrll 
    159  1.27.16.1     skrll 	return false;
    160  1.27.16.1     skrll }
    161  1.27.16.1     skrll 
    162        1.1       rvb int
    163       1.18   xtraeme coda_kill(struct mount *whoIam, enum dc_status dcstat)
    164        1.1       rvb {
    165  1.27.16.1     skrll 	int count = 0;
    166  1.27.16.1     skrll 	struct vnode_iterator *marker;
    167       1.17     perry 
    168       1.17     perry 	/*
    169       1.17     perry 	 * Algorithm is as follows:
    170        1.1       rvb 	 *     Second, flush whatever vnodes we can from the name cache.
    171        1.1       rvb 	 */
    172       1.17     perry 
    173        1.1       rvb 	/* This is slightly overkill, but should work. Eventually it'd be
    174        1.1       rvb 	 * nice to only flush those entries from the namecache that
    175        1.1       rvb 	 * reference a vnode in this vfs.  */
    176        1.3       rvb 	coda_nc_flush(dcstat);
    177       1.17     perry 
    178  1.27.16.1     skrll 
    179  1.27.16.1     skrll 	vfs_vnode_iterator_init(whoIam, &marker);
    180  1.27.16.1     skrll 	vfs_vnode_iterator_next(marker, coda_kill_selector, &count);
    181  1.27.16.1     skrll 	vfs_vnode_iterator_destroy(marker);
    182  1.27.16.1     skrll 
    183        1.1       rvb 	return count;
    184        1.1       rvb }
    185        1.1       rvb 
    186        1.1       rvb /*
    187        1.1       rvb  * There are two reasons why a cnode may be in use, it may be in the
    188       1.17     perry  * name cache or it may be executing.
    189        1.1       rvb  */
    190  1.27.16.1     skrll static bool
    191  1.27.16.1     skrll coda_flush_selector(void *cl, struct vnode *vp)
    192  1.27.16.1     skrll {
    193  1.27.16.1     skrll 	struct cnode *cp = VTOC(vp);
    194  1.27.16.1     skrll 
    195  1.27.16.1     skrll 	if (cp != NULL && !IS_DIR(cp->c_fid)) /* only files can be executed */
    196  1.27.16.1     skrll 		coda_vmflush(cp);
    197  1.27.16.1     skrll 
    198  1.27.16.1     skrll 	return false;
    199  1.27.16.1     skrll }
    200        1.1       rvb void
    201       1.18   xtraeme coda_flush(enum dc_status dcstat)
    202        1.1       rvb {
    203       1.17     perry 
    204        1.3       rvb     coda_clstat.ncalls++;
    205        1.3       rvb     coda_clstat.reqs[CODA_FLUSH]++;
    206       1.17     perry 
    207        1.3       rvb     coda_nc_flush(dcstat);	    /* flush files from the name cache */
    208        1.1       rvb 
    209  1.27.16.1     skrll     coda_iterate(coda_flush_selector, NULL);
    210        1.1       rvb }
    211        1.1       rvb 
    212        1.1       rvb /*
    213        1.1       rvb  * As a debugging measure, print out any cnodes that lived through a
    214       1.17     perry  * name cache flush.
    215        1.1       rvb  */
    216  1.27.16.1     skrll static bool
    217  1.27.16.1     skrll coda_testflush_selector(void *cl, struct vnode *vp)
    218  1.27.16.1     skrll {
    219  1.27.16.1     skrll 	struct cnode *cp = VTOC(vp);
    220  1.27.16.1     skrll 
    221  1.27.16.1     skrll 	if (cp != NULL)
    222  1.27.16.1     skrll 		myprintf(("Live cnode fid %s count %d\n",
    223  1.27.16.1     skrll 		     coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount));
    224  1.27.16.1     skrll 
    225  1.27.16.1     skrll 	return false;
    226  1.27.16.1     skrll }
    227        1.1       rvb void
    228        1.3       rvb coda_testflush(void)
    229        1.1       rvb {
    230       1.17     perry 
    231  1.27.16.1     skrll 	coda_iterate(coda_testflush_selector, NULL);
    232        1.1       rvb }
    233        1.1       rvb 
    234        1.1       rvb /*
    235        1.1       rvb  *     First, step through all cnodes and mark them unmounting.
    236        1.1       rvb  *         NetBSD kernels may try to fsync them now that venus
    237        1.1       rvb  *         is dead, which would be a bad thing.
    238        1.1       rvb  *
    239        1.1       rvb  */
    240  1.27.16.1     skrll static bool
    241  1.27.16.1     skrll coda_unmounting_selector(void *cl, struct vnode *vp)
    242  1.27.16.1     skrll {
    243  1.27.16.1     skrll 	struct cnode *cp = VTOC(vp);
    244  1.27.16.1     skrll 
    245  1.27.16.1     skrll 	if (cp)
    246  1.27.16.1     skrll 		cp->c_flags |= C_UNMOUNTING;
    247  1.27.16.1     skrll 
    248  1.27.16.1     skrll 	return false;
    249  1.27.16.1     skrll }
    250        1.1       rvb void
    251       1.18   xtraeme coda_unmounting(struct mount *whoIam)
    252       1.17     perry {
    253  1.27.16.1     skrll 	struct vnode_iterator *marker;
    254        1.1       rvb 
    255  1.27.16.1     skrll 	vfs_vnode_iterator_init(whoIam, &marker);
    256  1.27.16.1     skrll 	vfs_vnode_iterator_next(marker, coda_unmounting_selector, NULL);
    257  1.27.16.1     skrll 	vfs_vnode_iterator_destroy(marker);
    258        1.1       rvb }
    259        1.1       rvb 
    260        1.1       rvb #ifdef	DEBUG
    261  1.27.16.1     skrll static bool
    262  1.27.16.1     skrll coda_checkunmounting_selector(void *cl, struct vnode *vp)
    263  1.27.16.1     skrll {
    264  1.27.16.1     skrll 	struct cnode *cp = VTOC(vp);
    265  1.27.16.1     skrll 
    266  1.27.16.1     skrll 	if (cp && !(cp->c_flags & C_UNMOUNTING)) {
    267  1.27.16.1     skrll 		printf("vp %p, cp %p missed\n", vp, cp);
    268  1.27.16.1     skrll 		cp->c_flags |= C_UNMOUNTING;
    269  1.27.16.1     skrll 	}
    270  1.27.16.1     skrll 
    271  1.27.16.1     skrll 	return false;
    272  1.27.16.1     skrll }
    273        1.5       rvb void
    274       1.18   xtraeme coda_checkunmounting(struct mount *mp)
    275       1.17     perry {
    276  1.27.16.1     skrll 	struct vnode_iterator *marker;
    277  1.27.16.1     skrll 
    278  1.27.16.1     skrll 	vfs_vnode_iterator_init(mp, &marker);
    279  1.27.16.1     skrll 	vfs_vnode_iterator_next(marker, coda_checkunmounting_selector, NULL);
    280  1.27.16.1     skrll 	vfs_vnode_iterator_destroy(marker);
    281        1.1       rvb }
    282        1.1       rvb 
    283        1.5       rvb void
    284       1.18   xtraeme coda_cacheprint(struct mount *whoIam)
    285       1.17     perry {
    286  1.27.16.1     skrll 	struct vnode *vp;
    287  1.27.16.1     skrll 	struct vnode_iterator *marker;
    288        1.1       rvb 	int count = 0;
    289        1.1       rvb 
    290        1.3       rvb 	printf("coda_cacheprint: coda_ctlvp %p, cp %p", coda_ctlvp, VTOC(coda_ctlvp));
    291        1.5       rvb 	coda_nc_name(VTOC(coda_ctlvp));
    292        1.1       rvb 	printf("\n");
    293        1.1       rvb 
    294  1.27.16.1     skrll 	vfs_vnode_iterator_init(whoIam, &marker);
    295  1.27.16.1     skrll 	while ((vp = vfs_vnode_iterator_next(marker, NULL, NULL)) != NULL) {
    296  1.27.16.1     skrll 		printf("coda_cacheprint: vp %p, cp %p", vp, VTOC(vp));
    297  1.27.16.1     skrll 		coda_nc_name(VTOC(vp));
    298  1.27.16.1     skrll 		printf("\n");
    299  1.27.16.1     skrll 		count++;
    300  1.27.16.1     skrll 		vrele(vp);
    301        1.1       rvb 	}
    302        1.3       rvb 	printf("coda_cacheprint: count %d\n", count);
    303  1.27.16.1     skrll 	vfs_vnode_iterator_destroy(marker);
    304        1.1       rvb }
    305        1.1       rvb #endif
    306        1.1       rvb 
    307        1.1       rvb /*
    308        1.1       rvb  * There are 6 cases where invalidations occur. The semantics of each
    309        1.1       rvb  * is listed here.
    310        1.1       rvb  *
    311        1.3       rvb  * CODA_FLUSH     -- flush all entries from the name cache and the cnode cache.
    312        1.3       rvb  * CODA_PURGEUSER -- flush all entries from the name cache for a specific user
    313        1.1       rvb  *                  This call is a result of token expiration.
    314        1.1       rvb  *
    315        1.1       rvb  * The next two are the result of callbacks on a file or directory.
    316        1.3       rvb  * CODA_ZAPDIR    -- flush the attributes for the dir from its cnode.
    317        1.1       rvb  *                  Zap all children of this directory from the namecache.
    318        1.3       rvb  * CODA_ZAPFILE   -- flush the attributes for a file.
    319        1.1       rvb  *
    320        1.1       rvb  * The fifth is a result of Venus detecting an inconsistent file.
    321        1.3       rvb  * CODA_PURGEFID  -- flush the attribute for the file
    322       1.17     perry  *                  If it is a dir (odd vnode), purge its
    323        1.1       rvb  *                  children from the namecache
    324        1.1       rvb  *                  remove the file from the namecache.
    325        1.1       rvb  *
    326        1.1       rvb  * The sixth allows Venus to replace local fids with global ones
    327        1.1       rvb  * during reintegration.
    328        1.1       rvb  *
    329       1.17     perry  * CODA_REPLACE -- replace one CodaFid with another throughout the name cache
    330        1.1       rvb  */
    331        1.1       rvb 
    332       1.18   xtraeme int handleDownCall(int opcode, union outputArgs *out)
    333        1.1       rvb {
    334        1.1       rvb     int error;
    335        1.1       rvb 
    336        1.1       rvb     /* Handle invalidate requests. */
    337        1.1       rvb     switch (opcode) {
    338        1.3       rvb       case CODA_FLUSH : {
    339        1.1       rvb 
    340        1.3       rvb 	  coda_flush(IS_DOWNCALL);
    341       1.17     perry 
    342        1.3       rvb 	  CODADEBUG(CODA_FLUSH,coda_testflush();)    /* print remaining cnodes */
    343        1.1       rvb 	      return(0);
    344        1.1       rvb       }
    345       1.17     perry 
    346        1.3       rvb       case CODA_PURGEUSER : {
    347        1.3       rvb 	  coda_clstat.ncalls++;
    348        1.3       rvb 	  coda_clstat.reqs[CODA_PURGEUSER]++;
    349       1.17     perry 
    350        1.1       rvb 	  /* XXX - need to prevent fsync's */
    351       1.15  drochner #ifdef CODA_COMPAT_5
    352        1.3       rvb 	  coda_nc_purge_user(out->coda_purgeuser.cred.cr_uid, IS_DOWNCALL);
    353       1.15  drochner #else
    354       1.15  drochner 	  coda_nc_purge_user(out->coda_purgeuser.uid, IS_DOWNCALL);
    355       1.15  drochner #endif
    356        1.1       rvb 	  return(0);
    357        1.1       rvb       }
    358       1.17     perry 
    359        1.3       rvb       case CODA_ZAPFILE : {
    360        1.1       rvb 	  struct cnode *cp;
    361        1.1       rvb 
    362        1.1       rvb 	  error = 0;
    363        1.3       rvb 	  coda_clstat.ncalls++;
    364        1.3       rvb 	  coda_clstat.reqs[CODA_ZAPFILE]++;
    365       1.17     perry 
    366       1.15  drochner 	  cp = coda_find(&out->coda_zapfile.Fid);
    367        1.1       rvb 	  if (cp != NULL) {
    368        1.1       rvb 	      cp->c_flags &= ~C_VATTR;
    369       1.24        ad 	      if (CTOV(cp)->v_iflag & VI_TEXT)
    370        1.3       rvb 		  error = coda_vmflush(cp);
    371       1.11     lukem 	      CODADEBUG(CODA_ZAPFILE, myprintf((
    372       1.15  drochner 		    "zapfile: fid = %s, refcnt = %d, error = %d\n",
    373       1.15  drochner 		    coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1, error)););
    374        1.1       rvb 	      if (CTOV(cp)->v_usecount == 1) {
    375        1.1       rvb 		  cp->c_flags |= C_PURGING;
    376        1.1       rvb 	      }
    377  1.27.16.1     skrll 	      mutex_exit(&cp->c_lock);
    378        1.1       rvb 	      vrele(CTOV(cp));
    379        1.1       rvb 	  }
    380       1.17     perry 
    381        1.1       rvb 	  return(error);
    382        1.1       rvb       }
    383       1.17     perry 
    384        1.3       rvb       case CODA_ZAPDIR : {
    385        1.1       rvb 	  struct cnode *cp;
    386        1.1       rvb 
    387        1.3       rvb 	  coda_clstat.ncalls++;
    388        1.3       rvb 	  coda_clstat.reqs[CODA_ZAPDIR]++;
    389       1.17     perry 
    390       1.15  drochner 	  cp = coda_find(&out->coda_zapdir.Fid);
    391        1.1       rvb 	  if (cp != NULL) {
    392        1.1       rvb 	      cp->c_flags &= ~C_VATTR;
    393       1.17     perry 	      coda_nc_zapParentfid(&out->coda_zapdir.Fid, IS_DOWNCALL);
    394       1.17     perry 
    395       1.11     lukem 	      CODADEBUG(CODA_ZAPDIR, myprintf((
    396       1.15  drochner 		    "zapdir: fid = %s, refcnt = %d\n",
    397       1.15  drochner 		    coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1)););
    398        1.1       rvb 	      if (CTOV(cp)->v_usecount == 1) {
    399        1.1       rvb 		  cp->c_flags |= C_PURGING;
    400        1.1       rvb 	      }
    401  1.27.16.1     skrll 	      mutex_exit(&cp->c_lock);
    402        1.1       rvb 	      vrele(CTOV(cp));
    403        1.1       rvb 	  }
    404       1.17     perry 
    405        1.1       rvb 	  return(0);
    406        1.1       rvb       }
    407       1.17     perry 
    408        1.3       rvb       case CODA_PURGEFID : {
    409        1.1       rvb 	  struct cnode *cp;
    410        1.1       rvb 
    411        1.1       rvb 	  error = 0;
    412        1.3       rvb 	  coda_clstat.ncalls++;
    413        1.3       rvb 	  coda_clstat.reqs[CODA_PURGEFID]++;
    414        1.1       rvb 
    415       1.15  drochner 	  cp = coda_find(&out->coda_purgefid.Fid);
    416        1.1       rvb 	  if (cp != NULL) {
    417       1.15  drochner 	      if (IS_DIR(out->coda_purgefid.Fid)) { /* Vnode is a directory */
    418       1.15  drochner 		  coda_nc_zapParentfid(&out->coda_purgefid.Fid,
    419       1.17     perry 				     IS_DOWNCALL);
    420        1.1       rvb 	      }
    421        1.1       rvb 	      cp->c_flags &= ~C_VATTR;
    422       1.15  drochner 	      coda_nc_zapfid(&out->coda_purgefid.Fid, IS_DOWNCALL);
    423       1.17     perry 	      if (!(IS_DIR(out->coda_purgefid.Fid))
    424       1.24        ad 		  && (CTOV(cp)->v_iflag & VI_TEXT)) {
    425       1.17     perry 
    426        1.3       rvb 		  error = coda_vmflush(cp);
    427        1.1       rvb 	      }
    428       1.15  drochner 	      CODADEBUG(CODA_PURGEFID, myprintf((
    429       1.15  drochner 			 "purgefid: fid = %s, refcnt = %d, error = %d\n",
    430       1.15  drochner 			 coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1, error)););
    431        1.1       rvb 	      if (CTOV(cp)->v_usecount == 1) {
    432        1.1       rvb 		  cp->c_flags |= C_PURGING;
    433        1.1       rvb 	      }
    434  1.27.16.1     skrll 	      mutex_exit(&cp->c_lock);
    435        1.1       rvb 	      vrele(CTOV(cp));
    436        1.1       rvb 	  }
    437        1.1       rvb 	  return(error);
    438        1.1       rvb       }
    439        1.1       rvb 
    440        1.3       rvb       case CODA_REPLACE : {
    441        1.1       rvb 	  struct cnode *cp = NULL;
    442        1.1       rvb 
    443        1.3       rvb 	  coda_clstat.ncalls++;
    444        1.3       rvb 	  coda_clstat.reqs[CODA_REPLACE]++;
    445       1.17     perry 
    446        1.3       rvb 	  cp = coda_find(&out->coda_replace.OldFid);
    447       1.17     perry 	  if (cp != NULL) {
    448  1.27.16.1     skrll 	      error = vcache_rekey_enter(CTOV(cp)->v_mount, CTOV(cp),
    449  1.27.16.1     skrll 		  &out->coda_replace.OldFid, sizeof(CodaFid),
    450  1.27.16.1     skrll 		  &out->coda_replace.NewFid, sizeof(CodaFid));
    451  1.27.16.1     skrll 	      if (error) {
    452  1.27.16.1     skrll 		  mutex_exit(&cp->c_lock);
    453  1.27.16.1     skrll 		  vrele(CTOV(cp));
    454  1.27.16.1     skrll 		  return error;
    455  1.27.16.1     skrll 	      }
    456        1.3       rvb 	      cp->c_fid = out->coda_replace.NewFid;
    457  1.27.16.1     skrll 	      vcache_rekey_exit(CTOV(cp)->v_mount, CTOV(cp),
    458  1.27.16.1     skrll 		  &out->coda_replace.OldFid, sizeof(CodaFid),
    459  1.27.16.1     skrll 		  &cp->c_fid, sizeof(CodaFid));
    460        1.3       rvb 
    461       1.15  drochner 	      CODADEBUG(CODA_REPLACE, myprintf((
    462       1.15  drochner 			"replace: oldfid = %s, newfid = %s, cp = %p\n",
    463       1.15  drochner 			coda_f2s(&out->coda_replace.OldFid),
    464       1.15  drochner 			coda_f2s(&cp->c_fid), cp));)
    465  1.27.16.1     skrll 	      mutex_exit(&cp->c_lock);
    466        1.1       rvb 	      vrele(CTOV(cp));
    467        1.1       rvb 	  }
    468        1.1       rvb 	  return (0);
    469        1.1       rvb       }
    470        1.1       rvb       default:
    471        1.1       rvb       	myprintf(("handleDownCall: unknown opcode %d\n", opcode));
    472        1.1       rvb 	return (EINVAL);
    473        1.1       rvb     }
    474        1.1       rvb }
    475        1.1       rvb 
    476        1.3       rvb /* coda_grab_vnode: lives in either cfs_mach.c or cfs_nbsd.c */
    477        1.1       rvb 
    478        1.1       rvb int
    479       1.22  christos coda_vmflush(struct cnode *cp)
    480        1.1       rvb {
    481        1.1       rvb     return 0;
    482        1.1       rvb }
    483        1.1       rvb 
    484        1.1       rvb 
    485       1.17     perry /*
    486        1.1       rvb  * kernel-internal debugging switches
    487        1.1       rvb  */
    488        1.1       rvb 
    489        1.3       rvb void coda_debugon(void)
    490        1.1       rvb {
    491        1.3       rvb     codadebug = -1;
    492        1.3       rvb     coda_nc_debug = -1;
    493        1.3       rvb     coda_vnop_print_entry = 1;
    494        1.3       rvb     coda_psdev_print_entry = 1;
    495        1.3       rvb     coda_vfsop_print_entry = 1;
    496        1.3       rvb }
    497        1.3       rvb 
    498        1.3       rvb void coda_debugoff(void)
    499        1.3       rvb {
    500        1.3       rvb     codadebug = 0;
    501        1.3       rvb     coda_nc_debug = 0;
    502        1.3       rvb     coda_vnop_print_entry = 0;
    503        1.3       rvb     coda_psdev_print_entry = 0;
    504        1.3       rvb     coda_vfsop_print_entry = 0;
    505        1.1       rvb }
    506        1.1       rvb 
    507       1.27  christos /* How to print a ucred */
    508       1.27  christos void
    509       1.27  christos coda_print_cred(kauth_cred_t cred)
    510       1.27  christos {
    511       1.27  christos 
    512       1.27  christos 	uint16_t ngroups;
    513       1.27  christos 	int i;
    514       1.27  christos 
    515       1.27  christos 	myprintf(("ref %d\tuid %d\n", kauth_cred_getrefcnt(cred),
    516       1.27  christos 		 kauth_cred_geteuid(cred)));
    517       1.27  christos 
    518       1.27  christos 	ngroups = kauth_cred_ngroups(cred);
    519       1.27  christos 	for (i=0; i < ngroups; i++)
    520       1.27  christos 		myprintf(("\tgroup %d: (%d)\n", i, kauth_cred_group(cred, i)));
    521       1.27  christos 	myprintf(("\n"));
    522       1.27  christos 
    523       1.27  christos }
    524       1.27  christos 
    525        1.1       rvb /*
    526        1.1       rvb  * Utilities used by both client and server
    527        1.1       rvb  * Standard levels:
    528        1.1       rvb  * 0) no debugging
    529        1.1       rvb  * 1) hard failures
    530        1.1       rvb  * 2) soft failures
    531        1.1       rvb  * 3) current test software
    532        1.1       rvb  * 4) main procedure entry points
    533        1.1       rvb  * 5) main procedure exit points
    534        1.1       rvb  * 6) utility procedure entry points
    535        1.1       rvb  * 7) utility procedure exit points
    536        1.1       rvb  * 8) obscure procedure entry points
    537        1.1       rvb  * 9) obscure procedure exit points
    538        1.1       rvb  * 10) random stuff
    539        1.1       rvb  * 11) all <= 1
    540        1.1       rvb  * 12) all <= 2
    541        1.1       rvb  * 13) all <= 3
    542        1.1       rvb  * ...
    543        1.1       rvb  */
    544