Home | History | Annotate | Line # | Download | only in coda
coda_subr.c revision 1.28
      1  1.28   hannken /*	$NetBSD: coda_subr.c,v 1.28 2014/12/13 15:57:46 hannken 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.28   hannken __KERNEL_RCSID(0, "$NetBSD: coda_subr.c,v 1.28 2014/12/13 15:57:46 hannken 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.16       mrg #ifdef _KERNEL_OPT
     74  1.15  drochner #include "opt_coda_compat.h"
     75  1.16       mrg #endif
     76  1.15  drochner 
     77   1.3       rvb int coda_active = 0;
     78   1.3       rvb int coda_reuse = 0;
     79   1.3       rvb int coda_new = 0;
     80   1.1       rvb 
     81   1.3       rvb struct cnode *coda_freelist = NULL;
     82   1.3       rvb struct cnode *coda_cache[CODA_CACHESIZE];
     83  1.26  christos MALLOC_DEFINE(M_CODA, "coda", "Coda file system structures and tables");
     84  1.26  christos 
     85  1.26  christos int codadebug = 0;
     86  1.26  christos int coda_printf_delay = 0;  /* in microseconds */
     87  1.26  christos int coda_vnop_print_entry = 0;
     88  1.26  christos int coda_vfsop_print_entry = 0;
     89   1.1       rvb 
     90  1.15  drochner #define	CNODE_NEXT(cp)	((cp)->c_next)
     91  1.15  drochner 
     92  1.15  drochner #ifdef CODA_COMPAT_5
     93   1.3       rvb #define coda_hash(fid) \
     94   1.3       rvb     (((fid)->Volume + (fid)->Vnode) & (CODA_CACHESIZE-1))
     95  1.15  drochner #define IS_DIR(cnode)        (cnode.Vnode & 0x1)
     96  1.15  drochner #else
     97  1.15  drochner #define coda_hash(fid) \
     98  1.15  drochner     (coda_f2i(fid) & (CODA_CACHESIZE-1))
     99  1.15  drochner #define IS_DIR(cnode)        (cnode.opaque[2] & 0x1)
    100  1.15  drochner #endif
    101   1.1       rvb 
    102  1.27  christos struct vnode *coda_ctlvp;
    103  1.27  christos 
    104   1.1       rvb /*
    105   1.1       rvb  * Allocate a cnode.
    106   1.1       rvb  */
    107   1.1       rvb struct cnode *
    108   1.3       rvb coda_alloc(void)
    109   1.1       rvb {
    110   1.1       rvb     struct cnode *cp;
    111   1.1       rvb 
    112   1.3       rvb     if (coda_freelist) {
    113   1.3       rvb 	cp = coda_freelist;
    114   1.3       rvb 	coda_freelist = CNODE_NEXT(cp);
    115   1.3       rvb 	coda_reuse++;
    116   1.1       rvb     }
    117   1.1       rvb     else {
    118   1.3       rvb 	CODA_ALLOC(cp, struct cnode *, sizeof(struct cnode));
    119   1.1       rvb 	/* NetBSD vnodes don't have any Pager info in them ('cause there are
    120   1.1       rvb 	   no external pagers, duh!) */
    121   1.1       rvb #define VNODE_VM_INFO_INIT(vp)         /* MT */
    122   1.1       rvb 	VNODE_VM_INFO_INIT(CTOV(cp));
    123   1.3       rvb 	coda_new++;
    124   1.1       rvb     }
    125  1.12   thorpej     memset(cp, 0, sizeof (struct cnode));
    126   1.1       rvb 
    127   1.1       rvb     return(cp);
    128   1.1       rvb }
    129   1.1       rvb 
    130   1.1       rvb /*
    131   1.1       rvb  * Deallocate a cnode.
    132   1.1       rvb  */
    133   1.1       rvb void
    134  1.18   xtraeme coda_free(struct cnode *cp)
    135   1.1       rvb {
    136   1.1       rvb 
    137   1.3       rvb     CNODE_NEXT(cp) = coda_freelist;
    138   1.3       rvb     coda_freelist = cp;
    139   1.1       rvb }
    140   1.1       rvb 
    141   1.1       rvb /*
    142   1.1       rvb  * Put a cnode in the hash table
    143   1.1       rvb  */
    144   1.1       rvb void
    145  1.18   xtraeme coda_save(struct cnode *cp)
    146   1.1       rvb {
    147   1.3       rvb 	CNODE_NEXT(cp) = coda_cache[coda_hash(&cp->c_fid)];
    148   1.3       rvb 	coda_cache[coda_hash(&cp->c_fid)] = cp;
    149   1.1       rvb }
    150   1.1       rvb 
    151   1.1       rvb /*
    152   1.1       rvb  * Remove a cnode from the hash table
    153   1.1       rvb  */
    154   1.1       rvb void
    155  1.18   xtraeme coda_unsave(struct cnode *cp)
    156   1.1       rvb {
    157   1.1       rvb     struct cnode *ptr;
    158   1.1       rvb     struct cnode *ptrprev = NULL;
    159  1.17     perry 
    160  1.17     perry     ptr = coda_cache[coda_hash(&cp->c_fid)];
    161  1.17     perry     while (ptr != NULL) {
    162  1.17     perry 	if (ptr == cp) {
    163   1.1       rvb 	    if (ptrprev == NULL) {
    164  1.17     perry 		coda_cache[coda_hash(&cp->c_fid)]
    165   1.1       rvb 		    = CNODE_NEXT(ptr);
    166   1.1       rvb 	    } else {
    167   1.1       rvb 		CNODE_NEXT(ptrprev) = CNODE_NEXT(ptr);
    168   1.1       rvb 	    }
    169  1.25    plunky 	    CNODE_NEXT(cp) = NULL;
    170  1.17     perry 
    171  1.17     perry 	    return;
    172  1.17     perry 	}
    173   1.1       rvb 	ptrprev = ptr;
    174   1.1       rvb 	ptr = CNODE_NEXT(ptr);
    175  1.17     perry     }
    176   1.1       rvb }
    177   1.1       rvb 
    178   1.1       rvb /*
    179   1.1       rvb  * Lookup a cnode by fid. If the cnode is dying, it is bogus so skip it.
    180   1.1       rvb  * NOTE: this allows multiple cnodes with same fid -- dcs 1/25/95
    181   1.1       rvb  */
    182   1.1       rvb struct cnode *
    183  1.18   xtraeme coda_find(CodaFid *fid)
    184   1.1       rvb {
    185   1.1       rvb     struct cnode *cp;
    186   1.1       rvb 
    187   1.3       rvb     cp = coda_cache[coda_hash(fid)];
    188   1.1       rvb     while (cp) {
    189  1.15  drochner     	if (coda_fid_eq(&(cp->c_fid), fid) &&
    190   1.1       rvb 	    (!IS_UNMOUNTING(cp)))
    191   1.1       rvb 	    {
    192   1.3       rvb 		coda_active++;
    193  1.17     perry 		return(cp);
    194  1.17     perry 	    }
    195   1.1       rvb 	cp = CNODE_NEXT(cp);
    196   1.1       rvb     }
    197   1.1       rvb     return(NULL);
    198   1.1       rvb }
    199   1.1       rvb 
    200   1.1       rvb /*
    201   1.3       rvb  * coda_kill is called as a side effect to vcopen. To prevent any
    202   1.1       rvb  * cnodes left around from an earlier run of a venus or warden from
    203   1.1       rvb  * causing problems with the new instance, mark any outstanding cnodes
    204   1.1       rvb  * as dying. Future operations on these cnodes should fail (excepting
    205   1.3       rvb  * coda_inactive of course!). Since multiple venii/wardens can be
    206   1.1       rvb  * running, only kill the cnodes for a particular entry in the
    207   1.3       rvb  * coda_mnttbl. -- DCS 12/1/94 */
    208   1.1       rvb 
    209   1.1       rvb int
    210  1.18   xtraeme coda_kill(struct mount *whoIam, enum dc_status dcstat)
    211   1.1       rvb {
    212   1.1       rvb 	int hash, count = 0;
    213   1.1       rvb 	struct cnode *cp;
    214  1.17     perry 
    215  1.17     perry 	/*
    216  1.17     perry 	 * Algorithm is as follows:
    217   1.1       rvb 	 *     Second, flush whatever vnodes we can from the name cache.
    218  1.17     perry 	 *
    219   1.1       rvb 	 *     Finally, step through whatever is left and mark them dying.
    220   1.1       rvb 	 *        This prevents any operation at all.
    221   1.2       rvb 
    222   1.1       rvb 	 */
    223  1.17     perry 
    224   1.1       rvb 	/* This is slightly overkill, but should work. Eventually it'd be
    225   1.1       rvb 	 * nice to only flush those entries from the namecache that
    226   1.1       rvb 	 * reference a vnode in this vfs.  */
    227   1.3       rvb 	coda_nc_flush(dcstat);
    228  1.17     perry 
    229   1.3       rvb 	for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    230   1.3       rvb 		for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
    231  1.28   hannken 			if (IS_CTL_VP(CTOV(cp)))
    232  1.28   hannken 				continue;
    233   1.1       rvb 			if (CTOV(cp)->v_mount == whoIam) {
    234   1.1       rvb #ifdef	DEBUG
    235   1.3       rvb 				printf("coda_kill: vp %p, cp %p\n", CTOV(cp), cp);
    236   1.1       rvb #endif
    237   1.1       rvb 				count++;
    238  1.17     perry 				CODADEBUG(CODA_FLUSH,
    239  1.15  drochner 					 myprintf(("Live cnode fid %s flags %d count %d\n",
    240  1.15  drochner 						   coda_f2s(&cp->c_fid),
    241   1.1       rvb 						   cp->c_flags,
    242   1.1       rvb 						   CTOV(cp)->v_usecount)); );
    243   1.1       rvb 			}
    244   1.1       rvb 		}
    245   1.1       rvb 	}
    246   1.1       rvb 	return count;
    247   1.1       rvb }
    248   1.1       rvb 
    249   1.1       rvb /*
    250   1.1       rvb  * There are two reasons why a cnode may be in use, it may be in the
    251  1.17     perry  * name cache or it may be executing.
    252   1.1       rvb  */
    253   1.1       rvb void
    254  1.18   xtraeme coda_flush(enum dc_status dcstat)
    255   1.1       rvb {
    256   1.1       rvb     int hash;
    257   1.1       rvb     struct cnode *cp;
    258  1.17     perry 
    259   1.3       rvb     coda_clstat.ncalls++;
    260   1.3       rvb     coda_clstat.reqs[CODA_FLUSH]++;
    261  1.17     perry 
    262   1.3       rvb     coda_nc_flush(dcstat);	    /* flush files from the name cache */
    263   1.1       rvb 
    264   1.3       rvb     for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    265  1.17     perry 	for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
    266  1.15  drochner 	    if (!IS_DIR(cp->c_fid)) /* only files can be executed */
    267   1.3       rvb 		coda_vmflush(cp);
    268   1.1       rvb 	}
    269   1.1       rvb     }
    270   1.1       rvb }
    271   1.1       rvb 
    272   1.1       rvb /*
    273   1.1       rvb  * As a debugging measure, print out any cnodes that lived through a
    274  1.17     perry  * name cache flush.
    275   1.1       rvb  */
    276   1.1       rvb void
    277   1.3       rvb coda_testflush(void)
    278   1.1       rvb {
    279   1.1       rvb     int hash;
    280   1.1       rvb     struct cnode *cp;
    281  1.17     perry 
    282   1.3       rvb     for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    283   1.3       rvb 	for (cp = coda_cache[hash];
    284   1.1       rvb 	     cp != NULL;
    285  1.17     perry 	     cp = CNODE_NEXT(cp)) {
    286  1.15  drochner 	    myprintf(("Live cnode fid %s count %d\n",
    287  1.15  drochner 		      coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount));
    288   1.1       rvb 	}
    289   1.1       rvb     }
    290   1.1       rvb }
    291   1.1       rvb 
    292   1.1       rvb /*
    293   1.1       rvb  *     First, step through all cnodes and mark them unmounting.
    294   1.1       rvb  *         NetBSD kernels may try to fsync them now that venus
    295   1.1       rvb  *         is dead, which would be a bad thing.
    296   1.1       rvb  *
    297   1.1       rvb  */
    298   1.1       rvb void
    299  1.18   xtraeme coda_unmounting(struct mount *whoIam)
    300  1.17     perry {
    301   1.1       rvb 	int hash;
    302   1.1       rvb 	struct cnode *cp;
    303   1.1       rvb 
    304   1.3       rvb 	for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    305   1.3       rvb 		for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
    306   1.1       rvb 			if (CTOV(cp)->v_mount == whoIam) {
    307   1.1       rvb 				cp->c_flags |= C_UNMOUNTING;
    308   1.1       rvb 			}
    309   1.1       rvb 		}
    310   1.1       rvb 	}
    311   1.1       rvb }
    312   1.1       rvb 
    313   1.1       rvb #ifdef	DEBUG
    314   1.5       rvb void
    315  1.18   xtraeme coda_checkunmounting(struct mount *mp)
    316  1.17     perry {
    317  1.21   reinoud 	struct vnode *vp;
    318   1.1       rvb 	struct cnode *cp;
    319   1.1       rvb 	int count = 0, bad = 0;
    320   1.1       rvb loop:
    321  1.21   reinoud 	TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
    322   1.1       rvb 		if (vp->v_mount != mp)
    323   1.1       rvb 			goto loop;
    324   1.1       rvb 		cp = VTOC(vp);
    325   1.1       rvb 		count++;
    326   1.1       rvb 		if (!(cp->c_flags & C_UNMOUNTING)) {
    327   1.1       rvb 			bad++;
    328   1.1       rvb 			printf("vp %p, cp %p missed\n", vp, cp);
    329   1.1       rvb 			cp->c_flags |= C_UNMOUNTING;
    330   1.1       rvb 		}
    331   1.1       rvb 	}
    332   1.1       rvb }
    333   1.1       rvb 
    334   1.5       rvb void
    335  1.18   xtraeme coda_cacheprint(struct mount *whoIam)
    336  1.17     perry {
    337   1.1       rvb 	int hash;
    338   1.1       rvb 	struct cnode *cp;
    339   1.1       rvb 	int count = 0;
    340   1.1       rvb 
    341   1.3       rvb 	printf("coda_cacheprint: coda_ctlvp %p, cp %p", coda_ctlvp, VTOC(coda_ctlvp));
    342   1.5       rvb 	coda_nc_name(VTOC(coda_ctlvp));
    343   1.1       rvb 	printf("\n");
    344   1.1       rvb 
    345   1.3       rvb 	for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    346   1.3       rvb 		for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
    347   1.1       rvb 			if (CTOV(cp)->v_mount == whoIam) {
    348   1.3       rvb 				printf("coda_cacheprint: vp %p, cp %p", CTOV(cp), cp);
    349   1.3       rvb 				coda_nc_name(cp);
    350   1.1       rvb 				printf("\n");
    351   1.1       rvb 				count++;
    352   1.1       rvb 			}
    353   1.1       rvb 		}
    354   1.1       rvb 	}
    355   1.3       rvb 	printf("coda_cacheprint: count %d\n", count);
    356   1.1       rvb }
    357   1.1       rvb #endif
    358   1.1       rvb 
    359   1.1       rvb /*
    360   1.1       rvb  * There are 6 cases where invalidations occur. The semantics of each
    361   1.1       rvb  * is listed here.
    362   1.1       rvb  *
    363   1.3       rvb  * CODA_FLUSH     -- flush all entries from the name cache and the cnode cache.
    364   1.3       rvb  * CODA_PURGEUSER -- flush all entries from the name cache for a specific user
    365   1.1       rvb  *                  This call is a result of token expiration.
    366   1.1       rvb  *
    367   1.1       rvb  * The next two are the result of callbacks on a file or directory.
    368   1.3       rvb  * CODA_ZAPDIR    -- flush the attributes for the dir from its cnode.
    369   1.1       rvb  *                  Zap all children of this directory from the namecache.
    370   1.3       rvb  * CODA_ZAPFILE   -- flush the attributes for a file.
    371   1.1       rvb  *
    372   1.1       rvb  * The fifth is a result of Venus detecting an inconsistent file.
    373   1.3       rvb  * CODA_PURGEFID  -- flush the attribute for the file
    374  1.17     perry  *                  If it is a dir (odd vnode), purge its
    375   1.1       rvb  *                  children from the namecache
    376   1.1       rvb  *                  remove the file from the namecache.
    377   1.1       rvb  *
    378   1.1       rvb  * The sixth allows Venus to replace local fids with global ones
    379   1.1       rvb  * during reintegration.
    380   1.1       rvb  *
    381  1.17     perry  * CODA_REPLACE -- replace one CodaFid with another throughout the name cache
    382   1.1       rvb  */
    383   1.1       rvb 
    384  1.18   xtraeme int handleDownCall(int opcode, union outputArgs *out)
    385   1.1       rvb {
    386   1.1       rvb     int error;
    387   1.1       rvb 
    388   1.1       rvb     /* Handle invalidate requests. */
    389   1.1       rvb     switch (opcode) {
    390   1.3       rvb       case CODA_FLUSH : {
    391   1.1       rvb 
    392   1.3       rvb 	  coda_flush(IS_DOWNCALL);
    393  1.17     perry 
    394   1.3       rvb 	  CODADEBUG(CODA_FLUSH,coda_testflush();)    /* print remaining cnodes */
    395   1.1       rvb 	      return(0);
    396   1.1       rvb       }
    397  1.17     perry 
    398   1.3       rvb       case CODA_PURGEUSER : {
    399   1.3       rvb 	  coda_clstat.ncalls++;
    400   1.3       rvb 	  coda_clstat.reqs[CODA_PURGEUSER]++;
    401  1.17     perry 
    402   1.1       rvb 	  /* XXX - need to prevent fsync's */
    403  1.15  drochner #ifdef CODA_COMPAT_5
    404   1.3       rvb 	  coda_nc_purge_user(out->coda_purgeuser.cred.cr_uid, IS_DOWNCALL);
    405  1.15  drochner #else
    406  1.15  drochner 	  coda_nc_purge_user(out->coda_purgeuser.uid, IS_DOWNCALL);
    407  1.15  drochner #endif
    408   1.1       rvb 	  return(0);
    409   1.1       rvb       }
    410  1.17     perry 
    411   1.3       rvb       case CODA_ZAPFILE : {
    412   1.1       rvb 	  struct cnode *cp;
    413   1.1       rvb 
    414   1.1       rvb 	  error = 0;
    415   1.3       rvb 	  coda_clstat.ncalls++;
    416   1.3       rvb 	  coda_clstat.reqs[CODA_ZAPFILE]++;
    417  1.17     perry 
    418  1.15  drochner 	  cp = coda_find(&out->coda_zapfile.Fid);
    419   1.1       rvb 	  if (cp != NULL) {
    420   1.1       rvb 	      vref(CTOV(cp));
    421  1.17     perry 
    422   1.1       rvb 	      cp->c_flags &= ~C_VATTR;
    423  1.24        ad 	      if (CTOV(cp)->v_iflag & VI_TEXT)
    424   1.3       rvb 		  error = coda_vmflush(cp);
    425  1.11     lukem 	      CODADEBUG(CODA_ZAPFILE, myprintf((
    426  1.15  drochner 		    "zapfile: fid = %s, refcnt = %d, error = %d\n",
    427  1.15  drochner 		    coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1, error)););
    428   1.1       rvb 	      if (CTOV(cp)->v_usecount == 1) {
    429   1.1       rvb 		  cp->c_flags |= C_PURGING;
    430   1.1       rvb 	      }
    431   1.1       rvb 	      vrele(CTOV(cp));
    432   1.1       rvb 	  }
    433  1.17     perry 
    434   1.1       rvb 	  return(error);
    435   1.1       rvb       }
    436  1.17     perry 
    437   1.3       rvb       case CODA_ZAPDIR : {
    438   1.1       rvb 	  struct cnode *cp;
    439   1.1       rvb 
    440   1.3       rvb 	  coda_clstat.ncalls++;
    441   1.3       rvb 	  coda_clstat.reqs[CODA_ZAPDIR]++;
    442  1.17     perry 
    443  1.15  drochner 	  cp = coda_find(&out->coda_zapdir.Fid);
    444   1.1       rvb 	  if (cp != NULL) {
    445   1.1       rvb 	      vref(CTOV(cp));
    446  1.17     perry 
    447   1.1       rvb 	      cp->c_flags &= ~C_VATTR;
    448  1.17     perry 	      coda_nc_zapParentfid(&out->coda_zapdir.Fid, IS_DOWNCALL);
    449  1.17     perry 
    450  1.11     lukem 	      CODADEBUG(CODA_ZAPDIR, myprintf((
    451  1.15  drochner 		    "zapdir: fid = %s, refcnt = %d\n",
    452  1.15  drochner 		    coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1)););
    453   1.1       rvb 	      if (CTOV(cp)->v_usecount == 1) {
    454   1.1       rvb 		  cp->c_flags |= C_PURGING;
    455   1.1       rvb 	      }
    456   1.1       rvb 	      vrele(CTOV(cp));
    457   1.1       rvb 	  }
    458  1.17     perry 
    459   1.1       rvb 	  return(0);
    460   1.1       rvb       }
    461  1.17     perry 
    462   1.3       rvb       case CODA_PURGEFID : {
    463   1.1       rvb 	  struct cnode *cp;
    464   1.1       rvb 
    465   1.1       rvb 	  error = 0;
    466   1.3       rvb 	  coda_clstat.ncalls++;
    467   1.3       rvb 	  coda_clstat.reqs[CODA_PURGEFID]++;
    468   1.1       rvb 
    469  1.15  drochner 	  cp = coda_find(&out->coda_purgefid.Fid);
    470   1.1       rvb 	  if (cp != NULL) {
    471   1.1       rvb 	      vref(CTOV(cp));
    472  1.15  drochner 	      if (IS_DIR(out->coda_purgefid.Fid)) { /* Vnode is a directory */
    473  1.15  drochner 		  coda_nc_zapParentfid(&out->coda_purgefid.Fid,
    474  1.17     perry 				     IS_DOWNCALL);
    475   1.1       rvb 	      }
    476   1.1       rvb 	      cp->c_flags &= ~C_VATTR;
    477  1.15  drochner 	      coda_nc_zapfid(&out->coda_purgefid.Fid, IS_DOWNCALL);
    478  1.17     perry 	      if (!(IS_DIR(out->coda_purgefid.Fid))
    479  1.24        ad 		  && (CTOV(cp)->v_iflag & VI_TEXT)) {
    480  1.17     perry 
    481   1.3       rvb 		  error = coda_vmflush(cp);
    482   1.1       rvb 	      }
    483  1.15  drochner 	      CODADEBUG(CODA_PURGEFID, myprintf((
    484  1.15  drochner 			 "purgefid: fid = %s, refcnt = %d, error = %d\n",
    485  1.15  drochner 			 coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1, error)););
    486   1.1       rvb 	      if (CTOV(cp)->v_usecount == 1) {
    487   1.1       rvb 		  cp->c_flags |= C_PURGING;
    488   1.1       rvb 	      }
    489   1.1       rvb 	      vrele(CTOV(cp));
    490   1.1       rvb 	  }
    491   1.1       rvb 	  return(error);
    492   1.1       rvb       }
    493   1.1       rvb 
    494   1.3       rvb       case CODA_REPLACE : {
    495   1.1       rvb 	  struct cnode *cp = NULL;
    496   1.1       rvb 
    497   1.3       rvb 	  coda_clstat.ncalls++;
    498   1.3       rvb 	  coda_clstat.reqs[CODA_REPLACE]++;
    499  1.17     perry 
    500   1.3       rvb 	  cp = coda_find(&out->coda_replace.OldFid);
    501  1.17     perry 	  if (cp != NULL) {
    502   1.1       rvb 	      /* remove the cnode from the hash table, replace the fid, and reinsert */
    503   1.1       rvb 	      vref(CTOV(cp));
    504   1.3       rvb 	      coda_unsave(cp);
    505   1.3       rvb 	      cp->c_fid = out->coda_replace.NewFid;
    506   1.3       rvb 	      coda_save(cp);
    507   1.3       rvb 
    508  1.15  drochner 	      CODADEBUG(CODA_REPLACE, myprintf((
    509  1.15  drochner 			"replace: oldfid = %s, newfid = %s, cp = %p\n",
    510  1.15  drochner 			coda_f2s(&out->coda_replace.OldFid),
    511  1.15  drochner 			coda_f2s(&cp->c_fid), cp));)
    512   1.1       rvb 	      vrele(CTOV(cp));
    513   1.1       rvb 	  }
    514   1.1       rvb 	  return (0);
    515   1.1       rvb       }
    516   1.1       rvb       default:
    517   1.1       rvb       	myprintf(("handleDownCall: unknown opcode %d\n", opcode));
    518   1.1       rvb 	return (EINVAL);
    519   1.1       rvb     }
    520   1.1       rvb }
    521   1.1       rvb 
    522   1.3       rvb /* coda_grab_vnode: lives in either cfs_mach.c or cfs_nbsd.c */
    523   1.1       rvb 
    524   1.1       rvb int
    525  1.22  christos coda_vmflush(struct cnode *cp)
    526   1.1       rvb {
    527   1.1       rvb     return 0;
    528   1.1       rvb }
    529   1.1       rvb 
    530   1.1       rvb 
    531  1.17     perry /*
    532   1.1       rvb  * kernel-internal debugging switches
    533   1.1       rvb  */
    534   1.1       rvb 
    535   1.3       rvb void coda_debugon(void)
    536   1.1       rvb {
    537   1.3       rvb     codadebug = -1;
    538   1.3       rvb     coda_nc_debug = -1;
    539   1.3       rvb     coda_vnop_print_entry = 1;
    540   1.3       rvb     coda_psdev_print_entry = 1;
    541   1.3       rvb     coda_vfsop_print_entry = 1;
    542   1.3       rvb }
    543   1.3       rvb 
    544   1.3       rvb void coda_debugoff(void)
    545   1.3       rvb {
    546   1.3       rvb     codadebug = 0;
    547   1.3       rvb     coda_nc_debug = 0;
    548   1.3       rvb     coda_vnop_print_entry = 0;
    549   1.3       rvb     coda_psdev_print_entry = 0;
    550   1.3       rvb     coda_vfsop_print_entry = 0;
    551   1.1       rvb }
    552   1.1       rvb 
    553  1.27  christos /* How to print a ucred */
    554  1.27  christos void
    555  1.27  christos coda_print_cred(kauth_cred_t cred)
    556  1.27  christos {
    557  1.27  christos 
    558  1.27  christos 	uint16_t ngroups;
    559  1.27  christos 	int i;
    560  1.27  christos 
    561  1.27  christos 	myprintf(("ref %d\tuid %d\n", kauth_cred_getrefcnt(cred),
    562  1.27  christos 		 kauth_cred_geteuid(cred)));
    563  1.27  christos 
    564  1.27  christos 	ngroups = kauth_cred_ngroups(cred);
    565  1.27  christos 	for (i=0; i < ngroups; i++)
    566  1.27  christos 		myprintf(("\tgroup %d: (%d)\n", i, kauth_cred_group(cred, i)));
    567  1.27  christos 	myprintf(("\n"));
    568  1.27  christos 
    569  1.27  christos }
    570  1.27  christos 
    571   1.1       rvb /*
    572   1.1       rvb  * Utilities used by both client and server
    573   1.1       rvb  * Standard levels:
    574   1.1       rvb  * 0) no debugging
    575   1.1       rvb  * 1) hard failures
    576   1.1       rvb  * 2) soft failures
    577   1.1       rvb  * 3) current test software
    578   1.1       rvb  * 4) main procedure entry points
    579   1.1       rvb  * 5) main procedure exit points
    580   1.1       rvb  * 6) utility procedure entry points
    581   1.1       rvb  * 7) utility procedure exit points
    582   1.1       rvb  * 8) obscure procedure entry points
    583   1.1       rvb  * 9) obscure procedure exit points
    584   1.1       rvb  * 10) random stuff
    585   1.1       rvb  * 11) all <= 1
    586   1.1       rvb  * 12) all <= 2
    587   1.1       rvb  * 13) all <= 3
    588   1.1       rvb  * ...
    589   1.1       rvb  */
    590