Home | History | Annotate | Line # | Download | only in coda
coda_subr.c revision 1.7
      1 /*	$NetBSD: coda_subr.c,v 1.7 1999/10/01 22:25:59 soren Exp $	*/
      2 
      3 /*
      4  *
      5  *             Coda: an Experimental Distributed File System
      6  *                              Release 3.1
      7  *
      8  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9  *                          All Rights Reserved
     10  *
     11  * Permission  to  use, copy, modify and distribute this software and its
     12  * documentation is hereby granted,  provided  that  both  the  copyright
     13  * notice  and  this  permission  notice  appear  in  all  copies  of the
     14  * software, derivative works or  modified  versions,  and  any  portions
     15  * thereof, and that both notices appear in supporting documentation, and
     16  * that credit is given to Carnegie Mellon University  in  all  documents
     17  * and publicity pertaining to direct or indirect use of this code or its
     18  * derivatives.
     19  *
     20  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
     21  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
     22  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
     23  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
     24  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
     25  * ANY DERIVATIVE WORK.
     26  *
     27  * Carnegie  Mellon  encourages  users  of  this  software  to return any
     28  * improvements or extensions that  they  make,  and  to  grant  Carnegie
     29  * Mellon the rights to redistribute these changes without encumbrance.
     30  *
     31  * 	@(#) coda/coda_subr.c,v 1.1.1.1 1998/08/29 21:26:45 rvb Exp $
     32  */
     33 
     34 /*
     35  * Mach Operating System
     36  * Copyright (c) 1989 Carnegie-Mellon University
     37  * All rights reserved.  The CMU software License Agreement specifies
     38  * the terms and conditions for use and redistribution.
     39  */
     40 
     41 /*
     42  * This code was written for the Coda file system at Carnegie Mellon
     43  * University.  Contributers include David Steere, James Kistler, and
     44  * M. Satyanarayanan.  */
     45 
     46 /*
     47  * HISTORY
     48  * $Log: coda_subr.c,v $
     49  * Revision 1.7  1999/10/01 22:25:59  soren
     50  * Account for widened v_usecount in struct vnode.
     51  *
     52  * Revision 1.6  1998/10/28 19:54:50  rvb
     53  * Venus must be passed O_CREAT flag on VOP_OPEN iff this is
     54  * a creat so that we can will allow a mode 444 file to be
     55  * written into.  Sync with the latest coda.h and deal with
     56  * collateral damage.
     57  *
     58  * Revision 1.5  1998/09/25 15:01:13  rvb
     59  * Conditionalize "stray" printouts under DIAGNOSTIC and DEBUG.
     60  * Make files compile if DEBUG is on (from  Alan Barrett).  Finally,
     61  * make coda an lkm.
     62  *
     63  * Revision 1.4  1998/09/15 02:02:59  rvb
     64  * Final piece of rename cfs->coda
     65  *
     66  * Revision 1.3  1998/09/12 15:05:49  rvb
     67  * Change cfs/CFS in symbols, strings and constants to coda/CODA
     68  * to avoid fs conflicts.
     69  *
     70  * Revision 1.2  1998/09/08 17:12:47  rvb
     71  * Pass2 complete
     72  *
     73  * Revision 1.1.1.1  1998/08/29 21:26:45  rvb
     74  * Very Preliminary Coda
     75  *
     76  * Revision 1.11  1998/08/28 18:12:18  rvb
     77  * Now it also works on FreeBSD -current.  This code will be
     78  * committed to the FreeBSD -current and NetBSD -current
     79  * trees.  It will then be tailored to the particular platform
     80  * by flushing conditional code.
     81  *
     82  * Revision 1.10  1998/08/18 17:05:16  rvb
     83  * Don't use __RCSID now
     84  *
     85  * Revision 1.9  1998/08/18 16:31:41  rvb
     86  * Sync the code for NetBSD -current; test on 1.3 later
     87  *
     88  * Revision 1.8  98/01/31  20:53:12  rvb
     89  * First version that works on FreeBSD 2.2.5
     90  *
     91  * Revision 1.7  98/01/23  11:53:42  rvb
     92  * Bring RVB_CODA1_1 to HEAD
     93  *
     94  * Revision 1.6.2.3  98/01/23  11:21:05  rvb
     95  * Sync with 2.2.5
     96  *
     97  * Revision 1.6.2.2  97/12/16  12:40:06  rvb
     98  * Sync with 1.3
     99  *
    100  * Revision 1.6.2.1  97/12/06  17:41:21  rvb
    101  * Sync with peters coda.h
    102  *
    103  * Revision 1.6  97/12/05  10:39:17  rvb
    104  * Read CHANGES
    105  *
    106  * Revision 1.5.4.8  97/11/26  15:28:58  rvb
    107  * Cant make downcall pbuf == union cfs_downcalls yet
    108  *
    109  * Revision 1.5.4.7  97/11/20  11:46:42  rvb
    110  * Capture current cfs_venus
    111  *
    112  * Revision 1.5.4.6  97/11/18  10:27:16  rvb
    113  * cfs_nbsd.c is DEAD!!!; integrated into cfs_vf/vnops.c
    114  * cfs_nb_foo and cfs_foo are joined
    115  *
    116  * Revision 1.5.4.5  97/11/13  22:03:00  rvb
    117  * pass2 cfs_NetBSD.h mt
    118  *
    119  * Revision 1.5.4.4  97/11/12  12:09:39  rvb
    120  * reorg pass1
    121  *
    122  * Revision 1.5.4.3  97/11/06  21:02:38  rvb
    123  * first pass at ^c ^z
    124  *
    125  * Revision 1.5.4.2  97/10/29  16:06:27  rvb
    126  * Kill DYING
    127  *
    128  * Revision 1.5.4.1  97/10/28 23:10:16  rvb
    129  * >64Meg; venus can be killed!
    130  *
    131  * Revision 1.5  97/08/05  11:08:17  lily
    132  * Removed cfsnc_replace, replaced it with a coda_find, unhash, and
    133  * rehash.  This fixes a cnode leak and a bug in which the fid is
    134  * not actually replaced.  (cfs_namecache.c, cfsnc.h, cfs_subr.c)
    135  *
    136  * Revision 1.4  96/12/12  22:10:59  bnoble
    137  * Fixed the "downcall invokes venus operation" deadlock in all known cases.
    138  * There may be more
    139  *
    140  * Revision 1.3  1996/12/05 16:20:15  bnoble
    141  * Minor debugging aids
    142  *
    143  * Revision 1.2  1996/01/02 16:57:01  bnoble
    144  * Added support for Coda MiniCache and raw inode calls (final commit)
    145  *
    146  * Revision 1.1.2.1  1995/12/20 01:57:27  bnoble
    147  * Added CODA-specific files
    148  *
    149  * Revision 3.1.1.1  1995/03/04  19:07:59  bnoble
    150  * Branch for NetBSD port revisions
    151  *
    152  * Revision 3.1  1995/03/04  19:07:58  bnoble
    153  * Bump to major revision 3 to prepare for NetBSD port
    154  *
    155  * Revision 2.8  1995/03/03  17:00:04  dcs
    156  * Fixed kernel bug involving sleep and upcalls. Basically if you killed
    157  * a job waiting on venus, the venus upcall queues got trashed. Depending
    158  * on luck, you could kill the kernel or not.
    159  * (mods to cfs_subr.c and cfs_mach.d)
    160  *
    161  * Revision 2.7  95/03/02  22:45:21  dcs
    162  * Sun4 compatibility
    163  *
    164  * Revision 2.6  95/02/17  16:25:17  dcs
    165  * These versions represent several changes:
    166  * 1. Allow venus to restart even if outstanding references exist.
    167  * 2. Have only one ctlvp per client, as opposed to one per mounted cfs device.d
    168  * 3. Allow ody_expand to return many members, not just one.
    169  *
    170  * Revision 2.5  94/11/09  15:56:26  dcs
    171  * Had the thread sleeping on the wrong thing!
    172  *
    173  * Revision 2.4  94/10/14  09:57:57  dcs
    174  * Made changes 'cause sun4s have braindead compilers
    175  *
    176  * Revision 2.3  94/10/12  16:46:26  dcs
    177  * Cleaned kernel/venus interface by removing XDR junk, plus
    178  * so cleanup to allow this code to be more easily ported.
    179  *
    180  * Revision 1.2  92/10/27  17:58:22  lily
    181  * merge kernel/latest and alpha/src/cfs
    182  *
    183  * Revision 2.4  92/09/30  14:16:26  mja
    184  * 	Incorporated Dave Steere's fix for the GNU-Emacs bug.
    185  * 	Also, included his coda_flush routine in place of the former coda_nc_flush.
    186  * 	[91/02/07            jjk]
    187  *
    188  * 	Added contributors blurb.
    189  * 	[90/12/13            jjk]
    190  *
    191  * 	Hack to allow users to keep coda venus calls uninterruptible. THis
    192  * 	basically prevents the Gnu-emacs bug from appearing, in which a call
    193  * 	was being interrupted, and return EINTR, but gnu didn't check for the
    194  * 	error and figured the file was buggered.
    195  * 	[90/12/09            dcs]
    196  *
    197  * Revision 2.3  90/08/10  10:23:20  mrt
    198  * 	Removed include of vm/vm_page.h as it no longer exists.
    199  * 	[90/08/10            mrt]
    200  *
    201  * Revision 2.2  90/07/05  11:26:35  mrt
    202  * 	Initialize name cache on first call to vcopen.
    203  * 	[90/05/23            dcs]
    204  *
    205  * 	Created for the Coda File System.
    206  * 	[90/05/23            dcs]
    207  *
    208  * Revision 1.5  90/05/31  17:01:35  dcs
    209  * Prepare for merge with facilities kernel.
    210  *
    211  * Revision 1.2  90/03/19  15:56:25  dcs
    212  * Initialize name cache on first call to vcopen.
    213  *
    214  * Revision 1.1  90/03/15  10:43:26  jjk
    215  * Initial revision
    216  *
    217  */
    218 
    219 /* NOTES: rvb
    220  * 1.	Added coda_unmounting to mark all cnodes as being UNMOUNTING.  This has to
    221  *	 be done before dounmount is called.  Because some of the routines that
    222  *	 dounmount calls before coda_unmounted might try to force flushes to venus.
    223  *	 The vnode pager does this.
    224  * 2.	coda_unmounting marks all cnodes scanning coda_cache.
    225  * 3.	cfs_checkunmounting (under DEBUG) checks all cnodes by chasing the vnodes
    226  *	 under the /coda mount point.
    227  * 4.	coda_cacheprint (under DEBUG) prints names with vnode/cnode address
    228  */
    229 
    230 #ifdef	_LKM
    231 #define	NVCODA 4
    232 #else
    233 #include <vcoda.h>
    234 #endif
    235 
    236 #include <sys/param.h>
    237 #include <sys/systm.h>
    238 #include <sys/malloc.h>
    239 #include <sys/proc.h>
    240 #include <sys/select.h>
    241 #include <sys/mount.h>
    242 
    243 #include <coda/coda.h>
    244 #include <coda/cnode.h>
    245 #include <coda/coda_subr.h>
    246 #include <coda/coda_namecache.h>
    247 
    248 int coda_active = 0;
    249 int coda_reuse = 0;
    250 int coda_new = 0;
    251 
    252 struct cnode *coda_freelist = NULL;
    253 struct cnode *coda_cache[CODA_CACHESIZE];
    254 
    255 #define coda_hash(fid) \
    256     (((fid)->Volume + (fid)->Vnode) & (CODA_CACHESIZE-1))
    257 
    258 #define	CNODE_NEXT(cp)	((cp)->c_next)
    259 
    260 #define ODD(vnode)        ((vnode) & 0x1)
    261 
    262 /*
    263  * Allocate a cnode.
    264  */
    265 struct cnode *
    266 coda_alloc(void)
    267 {
    268     struct cnode *cp;
    269 
    270     if (coda_freelist) {
    271 	cp = coda_freelist;
    272 	coda_freelist = CNODE_NEXT(cp);
    273 	coda_reuse++;
    274     }
    275     else {
    276 	CODA_ALLOC(cp, struct cnode *, sizeof(struct cnode));
    277 	/* NetBSD vnodes don't have any Pager info in them ('cause there are
    278 	   no external pagers, duh!) */
    279 #define VNODE_VM_INFO_INIT(vp)         /* MT */
    280 	VNODE_VM_INFO_INIT(CTOV(cp));
    281 	coda_new++;
    282     }
    283     bzero(cp, sizeof (struct cnode));
    284 
    285     return(cp);
    286 }
    287 
    288 /*
    289  * Deallocate a cnode.
    290  */
    291 void
    292 coda_free(cp)
    293      register struct cnode *cp;
    294 {
    295 
    296     CNODE_NEXT(cp) = coda_freelist;
    297     coda_freelist = cp;
    298 }
    299 
    300 /*
    301  * Put a cnode in the hash table
    302  */
    303 void
    304 coda_save(cp)
    305      struct cnode *cp;
    306 {
    307 	CNODE_NEXT(cp) = coda_cache[coda_hash(&cp->c_fid)];
    308 	coda_cache[coda_hash(&cp->c_fid)] = cp;
    309 }
    310 
    311 /*
    312  * Remove a cnode from the hash table
    313  */
    314 void
    315 coda_unsave(cp)
    316      struct cnode *cp;
    317 {
    318     struct cnode *ptr;
    319     struct cnode *ptrprev = NULL;
    320 
    321     ptr = coda_cache[coda_hash(&cp->c_fid)];
    322     while (ptr != NULL) {
    323 	if (ptr == cp) {
    324 	    if (ptrprev == NULL) {
    325 		coda_cache[coda_hash(&cp->c_fid)]
    326 		    = CNODE_NEXT(ptr);
    327 	    } else {
    328 		CNODE_NEXT(ptrprev) = CNODE_NEXT(ptr);
    329 	    }
    330 	    CNODE_NEXT(cp) = (struct cnode *)NULL;
    331 
    332 	    return;
    333 	}
    334 	ptrprev = ptr;
    335 	ptr = CNODE_NEXT(ptr);
    336     }
    337 }
    338 
    339 /*
    340  * Lookup a cnode by fid. If the cnode is dying, it is bogus so skip it.
    341  * NOTE: this allows multiple cnodes with same fid -- dcs 1/25/95
    342  */
    343 struct cnode *
    344 coda_find(fid)
    345      ViceFid *fid;
    346 {
    347     struct cnode *cp;
    348 
    349     cp = coda_cache[coda_hash(fid)];
    350     while (cp) {
    351 	if ((cp->c_fid.Vnode == fid->Vnode) &&
    352 	    (cp->c_fid.Volume == fid->Volume) &&
    353 	    (cp->c_fid.Unique == fid->Unique) &&
    354 	    (!IS_UNMOUNTING(cp)))
    355 	    {
    356 		coda_active++;
    357 		return(cp);
    358 	    }
    359 	cp = CNODE_NEXT(cp);
    360     }
    361     return(NULL);
    362 }
    363 
    364 /*
    365  * coda_kill is called as a side effect to vcopen. To prevent any
    366  * cnodes left around from an earlier run of a venus or warden from
    367  * causing problems with the new instance, mark any outstanding cnodes
    368  * as dying. Future operations on these cnodes should fail (excepting
    369  * coda_inactive of course!). Since multiple venii/wardens can be
    370  * running, only kill the cnodes for a particular entry in the
    371  * coda_mnttbl. -- DCS 12/1/94 */
    372 
    373 int
    374 coda_kill(whoIam, dcstat)
    375 	struct mount *whoIam;
    376 	enum dc_status dcstat;
    377 {
    378 	int hash, count = 0;
    379 	struct cnode *cp;
    380 
    381 	/*
    382 	 * Algorithm is as follows:
    383 	 *     Second, flush whatever vnodes we can from the name cache.
    384 	 *
    385 	 *     Finally, step through whatever is left and mark them dying.
    386 	 *        This prevents any operation at all.
    387 
    388 	 */
    389 
    390 	/* This is slightly overkill, but should work. Eventually it'd be
    391 	 * nice to only flush those entries from the namecache that
    392 	 * reference a vnode in this vfs.  */
    393 	coda_nc_flush(dcstat);
    394 
    395 	for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    396 		for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
    397 			if (CTOV(cp)->v_mount == whoIam) {
    398 #ifdef	DEBUG
    399 				printf("coda_kill: vp %p, cp %p\n", CTOV(cp), cp);
    400 #endif
    401 				count++;
    402 				CODADEBUG(CODA_FLUSH,
    403 					 myprintf(("Live cnode fid %lx.%lx.%lx flags %d count %ld\n",
    404 						   (cp->c_fid).Volume,
    405 						   (cp->c_fid).Vnode,
    406 						   (cp->c_fid).Unique,
    407 						   cp->c_flags,
    408 						   CTOV(cp)->v_usecount)); );
    409 			}
    410 		}
    411 	}
    412 	return count;
    413 }
    414 
    415 /*
    416  * There are two reasons why a cnode may be in use, it may be in the
    417  * name cache or it may be executing.
    418  */
    419 void
    420 coda_flush(dcstat)
    421 	enum dc_status dcstat;
    422 {
    423     int hash;
    424     struct cnode *cp;
    425 
    426     coda_clstat.ncalls++;
    427     coda_clstat.reqs[CODA_FLUSH]++;
    428 
    429     coda_nc_flush(dcstat);	    /* flush files from the name cache */
    430 
    431     for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    432 	for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
    433 	    if (!ODD(cp->c_fid.Vnode)) /* only files can be executed */
    434 		coda_vmflush(cp);
    435 	}
    436     }
    437 }
    438 
    439 /*
    440  * As a debugging measure, print out any cnodes that lived through a
    441  * name cache flush.
    442  */
    443 void
    444 coda_testflush(void)
    445 {
    446     int hash;
    447     struct cnode *cp;
    448 
    449     for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    450 	for (cp = coda_cache[hash];
    451 	     cp != NULL;
    452 	     cp = CNODE_NEXT(cp)) {
    453 	    myprintf(("Live cnode fid %lx.%lx.%lx count %ld\n",
    454 		      (cp->c_fid).Volume,(cp->c_fid).Vnode,
    455 		      (cp->c_fid).Unique, CTOV(cp)->v_usecount));
    456 	}
    457     }
    458 }
    459 
    460 /*
    461  *     First, step through all cnodes and mark them unmounting.
    462  *         NetBSD kernels may try to fsync them now that venus
    463  *         is dead, which would be a bad thing.
    464  *
    465  */
    466 void
    467 coda_unmounting(whoIam)
    468 	struct mount *whoIam;
    469 {
    470 	int hash;
    471 	struct cnode *cp;
    472 
    473 	for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    474 		for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
    475 			if (CTOV(cp)->v_mount == whoIam) {
    476 				if (cp->c_flags & (C_LOCKED|C_WANTED)) {
    477 					printf("coda_unmounting: Unlocking %p\n", cp);
    478 					cp->c_flags &= ~(C_LOCKED|C_WANTED);
    479 					wakeup((caddr_t) cp);
    480 				}
    481 				cp->c_flags |= C_UNMOUNTING;
    482 			}
    483 		}
    484 	}
    485 }
    486 
    487 #ifdef	DEBUG
    488 void
    489 coda_checkunmounting(mp)
    490 	struct mount *mp;
    491 {
    492 	register struct vnode *vp, *nvp;
    493 	struct cnode *cp;
    494 	int count = 0, bad = 0;
    495 loop:
    496 	for (vp = mp->mnt_vnodelist.lh_first; vp; vp = nvp) {
    497 		if (vp->v_mount != mp)
    498 			goto loop;
    499 		nvp = vp->v_mntvnodes.le_next;
    500 		cp = VTOC(vp);
    501 		count++;
    502 		if (!(cp->c_flags & C_UNMOUNTING)) {
    503 			bad++;
    504 			printf("vp %p, cp %p missed\n", vp, cp);
    505 			cp->c_flags |= C_UNMOUNTING;
    506 		}
    507 	}
    508 }
    509 
    510 void
    511 coda_cacheprint(whoIam)
    512 	struct mount *whoIam;
    513 {
    514 	int hash;
    515 	struct cnode *cp;
    516 	int count = 0;
    517 
    518 	printf("coda_cacheprint: coda_ctlvp %p, cp %p", coda_ctlvp, VTOC(coda_ctlvp));
    519 	coda_nc_name(VTOC(coda_ctlvp));
    520 	printf("\n");
    521 
    522 	for (hash = 0; hash < CODA_CACHESIZE; hash++) {
    523 		for (cp = coda_cache[hash]; cp != NULL; cp = CNODE_NEXT(cp)) {
    524 			if (CTOV(cp)->v_mount == whoIam) {
    525 				printf("coda_cacheprint: vp %p, cp %p", CTOV(cp), cp);
    526 				coda_nc_name(cp);
    527 				printf("\n");
    528 				count++;
    529 			}
    530 		}
    531 	}
    532 	printf("coda_cacheprint: count %d\n", count);
    533 }
    534 #endif
    535 
    536 /*
    537  * There are 6 cases where invalidations occur. The semantics of each
    538  * is listed here.
    539  *
    540  * CODA_FLUSH     -- flush all entries from the name cache and the cnode cache.
    541  * CODA_PURGEUSER -- flush all entries from the name cache for a specific user
    542  *                  This call is a result of token expiration.
    543  *
    544  * The next two are the result of callbacks on a file or directory.
    545  * CODA_ZAPDIR    -- flush the attributes for the dir from its cnode.
    546  *                  Zap all children of this directory from the namecache.
    547  * CODA_ZAPFILE   -- flush the attributes for a file.
    548  *
    549  * The fifth is a result of Venus detecting an inconsistent file.
    550  * CODA_PURGEFID  -- flush the attribute for the file
    551  *                  If it is a dir (odd vnode), purge its
    552  *                  children from the namecache
    553  *                  remove the file from the namecache.
    554  *
    555  * The sixth allows Venus to replace local fids with global ones
    556  * during reintegration.
    557  *
    558  * CODA_REPLACE -- replace one ViceFid with another throughout the name cache
    559  */
    560 
    561 int handleDownCall(opcode, out)
    562      int opcode; union outputArgs *out;
    563 {
    564     int error;
    565 
    566     /* Handle invalidate requests. */
    567     switch (opcode) {
    568       case CODA_FLUSH : {
    569 
    570 	  coda_flush(IS_DOWNCALL);
    571 
    572 	  CODADEBUG(CODA_FLUSH,coda_testflush();)    /* print remaining cnodes */
    573 	      return(0);
    574       }
    575 
    576       case CODA_PURGEUSER : {
    577 	  coda_clstat.ncalls++;
    578 	  coda_clstat.reqs[CODA_PURGEUSER]++;
    579 
    580 	  /* XXX - need to prevent fsync's */
    581 	  coda_nc_purge_user(out->coda_purgeuser.cred.cr_uid, IS_DOWNCALL);
    582 	  return(0);
    583       }
    584 
    585       case CODA_ZAPFILE : {
    586 	  struct cnode *cp;
    587 
    588 	  error = 0;
    589 	  coda_clstat.ncalls++;
    590 	  coda_clstat.reqs[CODA_ZAPFILE]++;
    591 
    592 	  cp = coda_find(&out->coda_zapfile.CodaFid);
    593 	  if (cp != NULL) {
    594 	      vref(CTOV(cp));
    595 
    596 	      cp->c_flags &= ~C_VATTR;
    597 	      if (CTOV(cp)->v_flag & VTEXT)
    598 		  error = coda_vmflush(cp);
    599 	      CODADEBUG(CODA_ZAPFILE, myprintf(("zapfile: fid = (%lx.%lx.%lx),
    600                                               refcnt = %ld, error = %d\n",
    601 					      cp->c_fid.Volume,
    602 					      cp->c_fid.Vnode,
    603 					      cp->c_fid.Unique,
    604 					      CTOV(cp)->v_usecount - 1, error)););
    605 	      if (CTOV(cp)->v_usecount == 1) {
    606 		  cp->c_flags |= C_PURGING;
    607 	      }
    608 	      vrele(CTOV(cp));
    609 	  }
    610 
    611 	  return(error);
    612       }
    613 
    614       case CODA_ZAPDIR : {
    615 	  struct cnode *cp;
    616 
    617 	  coda_clstat.ncalls++;
    618 	  coda_clstat.reqs[CODA_ZAPDIR]++;
    619 
    620 	  cp = coda_find(&out->coda_zapdir.CodaFid);
    621 	  if (cp != NULL) {
    622 	      vref(CTOV(cp));
    623 
    624 	      cp->c_flags &= ~C_VATTR;
    625 	      coda_nc_zapParentfid(&out->coda_zapdir.CodaFid, IS_DOWNCALL);
    626 
    627 	      CODADEBUG(CODA_ZAPDIR, myprintf(("zapdir: fid = (%lx.%lx.%lx),
    628                                           refcnt = %ld\n",cp->c_fid.Volume,
    629 					     cp->c_fid.Vnode,
    630 					     cp->c_fid.Unique,
    631 					     CTOV(cp)->v_usecount - 1)););
    632 	      if (CTOV(cp)->v_usecount == 1) {
    633 		  cp->c_flags |= C_PURGING;
    634 	      }
    635 	      vrele(CTOV(cp));
    636 	  }
    637 
    638 	  return(0);
    639       }
    640 
    641       case CODA_PURGEFID : {
    642 	  struct cnode *cp;
    643 
    644 	  error = 0;
    645 	  coda_clstat.ncalls++;
    646 	  coda_clstat.reqs[CODA_PURGEFID]++;
    647 
    648 	  cp = coda_find(&out->coda_purgefid.CodaFid);
    649 	  if (cp != NULL) {
    650 	      vref(CTOV(cp));
    651 	      if (ODD(out->coda_purgefid.CodaFid.Vnode)) { /* Vnode is a directory */
    652 		  coda_nc_zapParentfid(&out->coda_purgefid.CodaFid,
    653 				     IS_DOWNCALL);
    654 	      }
    655 	      cp->c_flags &= ~C_VATTR;
    656 	      coda_nc_zapfid(&out->coda_purgefid.CodaFid, IS_DOWNCALL);
    657 	      if (!(ODD(out->coda_purgefid.CodaFid.Vnode))
    658 		  && (CTOV(cp)->v_flag & VTEXT)) {
    659 
    660 		  error = coda_vmflush(cp);
    661 	      }
    662 	      CODADEBUG(CODA_PURGEFID, myprintf(("purgefid: fid = (%lx.%lx.%lx), refcnt = %ld, error = %d\n",
    663                                             cp->c_fid.Volume, cp->c_fid.Vnode,
    664                                             cp->c_fid.Unique,
    665 					    CTOV(cp)->v_usecount - 1, error)););
    666 	      if (CTOV(cp)->v_usecount == 1) {
    667 		  cp->c_flags |= C_PURGING;
    668 	      }
    669 	      vrele(CTOV(cp));
    670 	  }
    671 	  return(error);
    672       }
    673 
    674       case CODA_REPLACE : {
    675 	  struct cnode *cp = NULL;
    676 
    677 	  coda_clstat.ncalls++;
    678 	  coda_clstat.reqs[CODA_REPLACE]++;
    679 
    680 	  cp = coda_find(&out->coda_replace.OldFid);
    681 	  if (cp != NULL) {
    682 	      /* remove the cnode from the hash table, replace the fid, and reinsert */
    683 	      vref(CTOV(cp));
    684 	      coda_unsave(cp);
    685 	      cp->c_fid = out->coda_replace.NewFid;
    686 	      coda_save(cp);
    687 
    688 	      CODADEBUG(CODA_REPLACE, myprintf(("replace: oldfid = (%lx.%lx.%lx), newfid = (%lx.%lx.%lx), cp = %p\n",
    689 					   out->coda_replace.OldFid.Volume,
    690 					   out->coda_replace.OldFid.Vnode,
    691 					   out->coda_replace.OldFid.Unique,
    692 					   cp->c_fid.Volume, cp->c_fid.Vnode,
    693 					   cp->c_fid.Unique, cp));)
    694 	      vrele(CTOV(cp));
    695 	  }
    696 	  return (0);
    697       }
    698       default:
    699       	myprintf(("handleDownCall: unknown opcode %d\n", opcode));
    700 	return (EINVAL);
    701     }
    702 }
    703 
    704 /* coda_grab_vnode: lives in either cfs_mach.c or cfs_nbsd.c */
    705 
    706 int
    707 coda_vmflush(cp)
    708      struct cnode *cp;
    709 {
    710     return 0;
    711 }
    712 
    713 
    714 /*
    715  * kernel-internal debugging switches
    716  */
    717 
    718 void coda_debugon(void)
    719 {
    720     codadebug = -1;
    721     coda_nc_debug = -1;
    722     coda_vnop_print_entry = 1;
    723     coda_psdev_print_entry = 1;
    724     coda_vfsop_print_entry = 1;
    725 }
    726 
    727 void coda_debugoff(void)
    728 {
    729     codadebug = 0;
    730     coda_nc_debug = 0;
    731     coda_vnop_print_entry = 0;
    732     coda_psdev_print_entry = 0;
    733     coda_vfsop_print_entry = 0;
    734 }
    735 
    736 /*
    737  * Utilities used by both client and server
    738  * Standard levels:
    739  * 0) no debugging
    740  * 1) hard failures
    741  * 2) soft failures
    742  * 3) current test software
    743  * 4) main procedure entry points
    744  * 5) main procedure exit points
    745  * 6) utility procedure entry points
    746  * 7) utility procedure exit points
    747  * 8) obscure procedure entry points
    748  * 9) obscure procedure exit points
    749  * 10) random stuff
    750  * 11) all <= 1
    751  * 12) all <= 2
    752  * 13) all <= 3
    753  * ...
    754  */
    755