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