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