Home | History | Annotate | Line # | Download | only in nfs
nfs_srvcache.c revision 1.41
      1  1.40      yamt /*	$NetBSD: nfs_srvcache.c,v 1.41 2007/12/04 17:42:31 yamt Exp $	*/
      2   1.8       cgd 
      3   1.1       cgd /*
      4   1.7   mycroft  * Copyright (c) 1989, 1993
      5   1.7   mycroft  *	The Regents of the University of California.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * This code is derived from software contributed to Berkeley by
      8   1.1       cgd  * Rick Macklem at The University of Guelph.
      9   1.1       cgd  *
     10   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11   1.1       cgd  * modification, are permitted provided that the following conditions
     12   1.1       cgd  * are met:
     13   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     15   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     18  1.28       agc  * 3. Neither the name of the University nor the names of its contributors
     19   1.1       cgd  *    may be used to endorse or promote products derived from this software
     20   1.1       cgd  *    without specific prior written permission.
     21   1.1       cgd  *
     22   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.1       cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.1       cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.1       cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.1       cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1       cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.1       cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1       cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1       cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1       cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1       cgd  * SUCH DAMAGE.
     33   1.1       cgd  *
     34  1.12      fvdl  *	@(#)nfs_srvcache.c	8.3 (Berkeley) 3/30/95
     35   1.1       cgd  */
     36   1.1       cgd 
     37   1.1       cgd /*
     38   1.1       cgd  * Reference: Chet Juszczak, "Improving the Performance and Correctness
     39   1.7   mycroft  *		of an NFS Server", in Proc. Winter 1989 USENIX Conference,
     40   1.7   mycroft  *		pages 53-63. San Diego, February 1989.
     41   1.1       cgd  */
     42  1.19     lukem 
     43  1.19     lukem #include <sys/cdefs.h>
     44  1.40      yamt __KERNEL_RCSID(0, "$NetBSD: nfs_srvcache.c,v 1.41 2007/12/04 17:42:31 yamt Exp $");
     45  1.19     lukem 
     46  1.14  jonathan #include "opt_iso.h"
     47  1.14  jonathan 
     48   1.6   mycroft #include <sys/param.h>
     49   1.6   mycroft #include <sys/vnode.h>
     50  1.40      yamt #include <sys/condvar.h>
     51   1.6   mycroft #include <sys/mount.h>
     52   1.6   mycroft #include <sys/kernel.h>
     53   1.6   mycroft #include <sys/systm.h>
     54  1.27      yamt #include <sys/lock.h>
     55   1.7   mycroft #include <sys/proc.h>
     56  1.25      yamt #include <sys/pool.h>
     57   1.6   mycroft #include <sys/mbuf.h>
     58   1.7   mycroft #include <sys/malloc.h>
     59  1.40      yamt #include <sys/mutex.h>
     60   1.6   mycroft #include <sys/socket.h>
     61   1.6   mycroft #include <sys/socketvar.h>
     62   1.1       cgd 
     63   1.6   mycroft #include <netinet/in.h>
     64   1.7   mycroft #ifdef ISO
     65   1.7   mycroft #include <netiso/iso.h>
     66   1.7   mycroft #endif
     67   1.6   mycroft #include <nfs/nfsm_subs.h>
     68   1.7   mycroft #include <nfs/rpcv2.h>
     69  1.12      fvdl #include <nfs/nfsproto.h>
     70   1.7   mycroft #include <nfs/nfs.h>
     71   1.6   mycroft #include <nfs/nfsrvcache.h>
     72  1.11  christos #include <nfs/nfs_var.h>
     73   1.2     glass 
     74  1.12      fvdl extern struct nfsstats nfsstats;
     75  1.20      matt extern const int nfsv2_procid[NFS_NPROCS];
     76   1.7   mycroft long numnfsrvcache, desirednfsrvcache = NFSRVCACHESIZ;
     77  1.25      yamt struct pool nfs_reqcache_pool;
     78   1.1       cgd 
     79   1.9   mycroft #define	NFSRCHASH(xid) \
     80   1.9   mycroft 	(&nfsrvhashtbl[((xid) + ((xid) >> 24)) & nfsrvhash])
     81   1.9   mycroft LIST_HEAD(nfsrvhash, nfsrvcache) *nfsrvhashtbl;
     82   1.9   mycroft TAILQ_HEAD(nfsrvlru, nfsrvcache) nfsrvlruhead;
     83  1.40      yamt kmutex_t nfsrv_reqcache_lock;
     84   1.9   mycroft u_long nfsrvhash;
     85   1.1       cgd 
     86  1.36      yamt #if defined(MBUFTRACE)
     87  1.36      yamt static struct mowner nfsd_cache_mowner = MOWNER_INIT("nfsd", "cache");
     88  1.36      yamt #endif /* defined(MBUFTRACE) */
     89  1.36      yamt 
     90   1.7   mycroft #define	NETFAMILY(rp) \
     91  1.41      yamt 		(((rp)->rc_flags & RC_INETADDR) ? AF_INET : AF_ISO)
     92   1.7   mycroft 
     93  1.27      yamt static struct nfsrvcache *nfsrv_lookupcache(struct nfsrv_descript *nd);
     94  1.27      yamt static void nfsrv_unlockcache(struct nfsrvcache *rp);
     95  1.27      yamt 
     96   1.7   mycroft /*
     97   1.7   mycroft  * Static array that defines which nfs rpc's are nonidempotent
     98   1.7   mycroft  */
     99  1.18  jdolecek const int nonidempotent[NFS_NPROCS] = {
    100  1.37   thorpej 	false,	/* NULL */
    101  1.37   thorpej 	false,	/* GETATTR */
    102  1.37   thorpej 	true,	/* SETATTR */
    103  1.37   thorpej 	false,	/* LOOKUP */
    104  1.37   thorpej 	false,	/* ACCESS */
    105  1.37   thorpej 	false,	/* READLINK */
    106  1.37   thorpej 	false,	/* READ */
    107  1.37   thorpej 	true,	/* WRITE */
    108  1.37   thorpej 	true,	/* CREATE */
    109  1.37   thorpej 	true,	/* MKDIR */
    110  1.37   thorpej 	true,	/* SYMLINK */
    111  1.37   thorpej 	true,	/* MKNOD */
    112  1.37   thorpej 	true,	/* REMOVE */
    113  1.37   thorpej 	true,	/* RMDIR */
    114  1.37   thorpej 	true,	/* RENAME */
    115  1.37   thorpej 	true,	/* LINK */
    116  1.37   thorpej 	false,	/* READDIR */
    117  1.37   thorpej 	false,	/* READDIRPLUS */
    118  1.37   thorpej 	false,	/* FSSTAT */
    119  1.37   thorpej 	false,	/* FSINFO */
    120  1.37   thorpej 	false,	/* PATHCONF */
    121  1.37   thorpej 	false,	/* COMMIT */
    122  1.37   thorpej 	false,	/* NOOP */
    123   1.7   mycroft };
    124   1.1       cgd 
    125   1.1       cgd /* True iff the rpc reply is an nfs status ONLY! */
    126  1.18  jdolecek static const int nfsv2_repstat[NFS_NPROCS] = {
    127  1.37   thorpej 	false,	/* NULL */
    128  1.37   thorpej 	false,	/* GETATTR */
    129  1.37   thorpej 	false,	/* SETATTR */
    130  1.37   thorpej 	false,	/* NOOP */
    131  1.37   thorpej 	false,	/* LOOKUP */
    132  1.37   thorpej 	false,	/* READLINK */
    133  1.37   thorpej 	false,	/* READ */
    134  1.37   thorpej 	false,	/* Obsolete WRITECACHE */
    135  1.37   thorpej 	false,	/* WRITE */
    136  1.37   thorpej 	false,	/* CREATE */
    137  1.37   thorpej 	true,	/* REMOVE */
    138  1.37   thorpej 	true,	/* RENAME */
    139  1.37   thorpej 	true,	/* LINK */
    140  1.37   thorpej 	true,	/* SYMLINK */
    141  1.37   thorpej 	false,	/* MKDIR */
    142  1.37   thorpej 	true,	/* RMDIR */
    143  1.37   thorpej 	false,	/* READDIR */
    144  1.37   thorpej 	false,	/* STATFS */
    145   1.1       cgd };
    146   1.1       cgd 
    147  1.34      yamt static void
    148  1.34      yamt cleanentry(struct nfsrvcache *rp)
    149  1.34      yamt {
    150  1.34      yamt 
    151  1.41      yamt 	if ((rp->rc_flags & RC_REPMBUF) != 0) {
    152  1.34      yamt 		m_freem(rp->rc_reply);
    153  1.34      yamt 	}
    154  1.41      yamt 	if ((rp->rc_flags & RC_NAM) != 0) {
    155  1.34      yamt 		m_free(rp->rc_nam);
    156  1.34      yamt 	}
    157  1.41      yamt 	rp->rc_flags &= ~(RC_REPSTATUS|RC_REPMBUF);
    158  1.34      yamt }
    159  1.34      yamt 
    160   1.1       cgd /*
    161   1.1       cgd  * Initialize the server request cache list
    162   1.1       cgd  */
    163  1.11  christos void
    164   1.1       cgd nfsrv_initcache()
    165   1.1       cgd {
    166   1.7   mycroft 
    167  1.41      yamt 	mutex_init(&nfsrv_reqcache_lock, MUTEX_DEFAULT, IPL_NONE);
    168  1.17        ad 	nfsrvhashtbl = hashinit(desirednfsrvcache, HASH_LIST, M_NFSD,
    169  1.17        ad 	    M_WAITOK, &nfsrvhash);
    170   1.9   mycroft 	TAILQ_INIT(&nfsrvlruhead);
    171  1.25      yamt 	pool_init(&nfs_reqcache_pool, sizeof(struct nfsrvcache), 0, 0, 0,
    172  1.39        ad 	    "nfsreqcachepl", &pool_allocator_nointr, IPL_NONE);
    173  1.36      yamt 	MOWNER_ATTACH(&nfsd_cache_mowner);
    174   1.1       cgd }
    175   1.1       cgd 
    176   1.1       cgd /*
    177  1.27      yamt  * Lookup a cache and lock it
    178  1.27      yamt  */
    179  1.27      yamt static struct nfsrvcache *
    180  1.27      yamt nfsrv_lookupcache(nd)
    181  1.27      yamt 	struct nfsrv_descript *nd;
    182  1.27      yamt {
    183  1.27      yamt 	struct nfsrvcache *rp;
    184  1.27      yamt 
    185  1.40      yamt 	KASSERT(mutex_owned(&nfsrv_reqcache_lock));
    186  1.27      yamt 
    187  1.27      yamt loop:
    188  1.27      yamt 	LIST_FOREACH(rp, NFSRCHASH(nd->nd_retxid), rc_hash) {
    189  1.27      yamt 		if (nd->nd_retxid == rp->rc_xid &&
    190  1.27      yamt 		    nd->nd_procnum == rp->rc_proc &&
    191  1.27      yamt 		    netaddr_match(NETFAMILY(rp), &rp->rc_haddr, nd->nd_nam)) {
    192  1.41      yamt 			if ((rp->rc_gflags & RC_G_LOCKED) != 0) {
    193  1.40      yamt 				cv_wait(&rp->rc_cv, &nfsrv_reqcache_lock);
    194  1.27      yamt 				goto loop;
    195  1.27      yamt 			}
    196  1.41      yamt 			rp->rc_gflags |= RC_G_LOCKED;
    197  1.27      yamt 			break;
    198  1.27      yamt 		}
    199  1.27      yamt 	}
    200  1.27      yamt 
    201  1.27      yamt 	return rp;
    202  1.27      yamt }
    203  1.27      yamt 
    204  1.27      yamt /*
    205  1.27      yamt  * Unlock a cache
    206  1.27      yamt  */
    207  1.27      yamt static void
    208  1.27      yamt nfsrv_unlockcache(rp)
    209  1.27      yamt 	struct nfsrvcache *rp;
    210  1.27      yamt {
    211  1.27      yamt 
    212  1.40      yamt 	KASSERT(mutex_owned(&nfsrv_reqcache_lock));
    213  1.27      yamt 
    214  1.41      yamt 	KASSERT((rp->rc_gflags & RC_G_LOCKED) != 0);
    215  1.41      yamt 	rp->rc_gflags &= ~RC_G_LOCKED;
    216  1.40      yamt 	cv_broadcast(&rp->rc_cv);
    217  1.27      yamt }
    218  1.27      yamt 
    219  1.27      yamt /*
    220   1.1       cgd  * Look for the request in the cache
    221   1.1       cgd  * If found then
    222   1.1       cgd  *    return action and optionally reply
    223   1.1       cgd  * else
    224   1.1       cgd  *    insert it in the cache
    225   1.1       cgd  *
    226   1.1       cgd  * The rules are as follows:
    227   1.1       cgd  * - if in progress, return DROP request
    228   1.1       cgd  * - if completed within DELAY of the current time, return DROP it
    229   1.1       cgd  * - if completed a longer time ago return REPLY if the reply was cached or
    230   1.1       cgd  *   return DOIT
    231   1.1       cgd  * Update/add new request at end of lru list
    232   1.1       cgd  */
    233  1.11  christos int
    234  1.12      fvdl nfsrv_getcache(nd, slp, repp)
    235  1.16  augustss 	struct nfsrv_descript *nd;
    236  1.12      fvdl 	struct nfssvc_sock *slp;
    237   1.1       cgd 	struct mbuf **repp;
    238   1.1       cgd {
    239  1.29      yamt 	struct nfsrvcache *rp, *rpdup;
    240   1.1       cgd 	struct mbuf *mb;
    241   1.7   mycroft 	struct sockaddr_in *saddr;
    242  1.38  christos 	char *bpos;
    243   1.1       cgd 	int ret;
    244   1.1       cgd 
    245  1.40      yamt 	mutex_enter(&nfsrv_reqcache_lock);
    246  1.27      yamt 	rp = nfsrv_lookupcache(nd);
    247  1.27      yamt 	if (rp) {
    248  1.40      yamt 		mutex_exit(&nfsrv_reqcache_lock);
    249  1.27      yamt found:
    250  1.27      yamt 		/* If not at end of LRU chain, move it there */
    251  1.27      yamt 		if (TAILQ_NEXT(rp, rc_lru)) { /* racy but ok */
    252  1.40      yamt 			mutex_enter(&nfsrv_reqcache_lock);
    253  1.27      yamt 			TAILQ_REMOVE(&nfsrvlruhead, rp, rc_lru);
    254  1.27      yamt 			TAILQ_INSERT_TAIL(&nfsrvlruhead, rp, rc_lru);
    255  1.40      yamt 			mutex_exit(&nfsrv_reqcache_lock);
    256  1.27      yamt 		}
    257  1.27      yamt 		if (rp->rc_state == RC_UNUSED)
    258  1.27      yamt 			panic("nfsrv cache");
    259  1.27      yamt 		if (rp->rc_state == RC_INPROG) {
    260  1.27      yamt 			nfsstats.srvcache_inproghits++;
    261  1.27      yamt 			ret = RC_DROPIT;
    262  1.41      yamt 		} else if (rp->rc_flags & RC_REPSTATUS) {
    263  1.27      yamt 			nfsstats.srvcache_nonidemdonehits++;
    264  1.27      yamt 			nfs_rephead(0, nd, slp, rp->rc_status,
    265  1.27      yamt 			   0, (u_quad_t *)0, repp, &mb, &bpos);
    266  1.27      yamt 			ret = RC_REPLY;
    267  1.41      yamt 		} else if (rp->rc_flags & RC_REPMBUF) {
    268  1.27      yamt 			nfsstats.srvcache_nonidemdonehits++;
    269  1.27      yamt 			*repp = m_copym(rp->rc_reply, 0, M_COPYALL,
    270  1.27      yamt 					M_WAIT);
    271  1.27      yamt 			ret = RC_REPLY;
    272  1.27      yamt 		} else {
    273  1.27      yamt 			nfsstats.srvcache_idemdonehits++;
    274  1.27      yamt 			rp->rc_state = RC_INPROG;
    275  1.27      yamt 			ret = RC_DOIT;
    276   1.1       cgd 		}
    277  1.40      yamt 		mutex_enter(&nfsrv_reqcache_lock);
    278  1.27      yamt 		nfsrv_unlockcache(rp);
    279  1.40      yamt 		mutex_exit(&nfsrv_reqcache_lock);
    280  1.27      yamt 		return ret;
    281   1.1       cgd 	}
    282   1.1       cgd 	nfsstats.srvcache_misses++;
    283   1.7   mycroft 	if (numnfsrvcache < desirednfsrvcache) {
    284  1.27      yamt 		numnfsrvcache++;
    285  1.40      yamt 		mutex_exit(&nfsrv_reqcache_lock);
    286  1.25      yamt 		rp = pool_get(&nfs_reqcache_pool, PR_WAITOK);
    287  1.27      yamt 		memset(rp, 0, sizeof *rp);
    288  1.40      yamt 		cv_init(&rp->rc_cv, "nfsdrc");
    289  1.41      yamt 		rp->rc_gflags = RC_G_LOCKED;
    290   1.7   mycroft 	} else {
    291  1.22      yamt 		rp = TAILQ_FIRST(&nfsrvlruhead);
    292  1.41      yamt 		while ((rp->rc_gflags & RC_G_LOCKED) != 0) {
    293  1.40      yamt 			cv_wait(&rp->rc_cv, &nfsrv_reqcache_lock);
    294  1.22      yamt 			rp = TAILQ_FIRST(&nfsrvlruhead);
    295   1.7   mycroft 		}
    296  1.41      yamt 		rp->rc_gflags |= RC_G_LOCKED;
    297   1.9   mycroft 		LIST_REMOVE(rp, rc_hash);
    298   1.9   mycroft 		TAILQ_REMOVE(&nfsrvlruhead, rp, rc_lru);
    299  1.40      yamt 		mutex_exit(&nfsrv_reqcache_lock);
    300  1.34      yamt 		cleanentry(rp);
    301  1.41      yamt 		rp->rc_flags = 0;
    302   1.1       cgd 	}
    303   1.1       cgd 	rp->rc_state = RC_INPROG;
    304   1.7   mycroft 	rp->rc_xid = nd->nd_retxid;
    305  1.12      fvdl 	saddr = mtod(nd->nd_nam, struct sockaddr_in *);
    306   1.7   mycroft 	switch (saddr->sin_family) {
    307   1.7   mycroft 	case AF_INET:
    308  1.41      yamt 		rp->rc_flags |= RC_INETADDR;
    309   1.7   mycroft 		rp->rc_inetaddr = saddr->sin_addr.s_addr;
    310   1.7   mycroft 		break;
    311   1.7   mycroft 	case AF_ISO:
    312   1.7   mycroft 	default:
    313  1.41      yamt 		rp->rc_flags |= RC_NAM;
    314  1.12      fvdl 		rp->rc_nam = m_copym(nd->nd_nam, 0, M_COPYALL, M_WAIT);
    315  1.36      yamt 		m_claimm(rp->rc_nam, &nfsd_cache_mowner);
    316   1.7   mycroft 		break;
    317   1.7   mycroft 	};
    318   1.7   mycroft 	rp->rc_proc = nd->nd_procnum;
    319  1.40      yamt 	mutex_enter(&nfsrv_reqcache_lock);
    320  1.29      yamt 	rpdup = nfsrv_lookupcache(nd);
    321  1.29      yamt 	if (rpdup != NULL) {
    322  1.27      yamt 		/*
    323  1.27      yamt 		 * other thread made duplicate cache entry.
    324  1.27      yamt 		 */
    325  1.41      yamt 		KASSERT(numnfsrvcache > 0);
    326  1.41      yamt 		numnfsrvcache--;
    327  1.40      yamt 		mutex_exit(&nfsrv_reqcache_lock);
    328  1.41      yamt 		cleanentry(rp);
    329  1.40      yamt 		cv_destroy(&rp->rc_cv);
    330  1.27      yamt 		pool_put(&nfs_reqcache_pool, rp);
    331  1.29      yamt 		rp = rpdup;
    332  1.27      yamt 		goto found;
    333  1.27      yamt 	}
    334  1.27      yamt 	TAILQ_INSERT_TAIL(&nfsrvlruhead, rp, rc_lru);
    335   1.9   mycroft 	LIST_INSERT_HEAD(NFSRCHASH(nd->nd_retxid), rp, rc_hash);
    336  1.27      yamt 	nfsrv_unlockcache(rp);
    337  1.40      yamt 	mutex_exit(&nfsrv_reqcache_lock);
    338  1.26      yamt 	return RC_DOIT;
    339   1.1       cgd }
    340   1.1       cgd 
    341   1.1       cgd /*
    342   1.1       cgd  * Update a request cache entry after the rpc has been done
    343   1.1       cgd  */
    344   1.7   mycroft void
    345  1.12      fvdl nfsrv_updatecache(nd, repvalid, repmbuf)
    346  1.16  augustss 	struct nfsrv_descript *nd;
    347   1.1       cgd 	int repvalid;
    348   1.1       cgd 	struct mbuf *repmbuf;
    349   1.1       cgd {
    350  1.16  augustss 	struct nfsrvcache *rp;
    351   1.1       cgd 
    352  1.40      yamt 	mutex_enter(&nfsrv_reqcache_lock);
    353  1.27      yamt 	rp = nfsrv_lookupcache(nd);
    354  1.40      yamt 	mutex_exit(&nfsrv_reqcache_lock);
    355  1.27      yamt 	if (rp) {
    356  1.34      yamt 		cleanentry(rp);
    357  1.27      yamt 		rp->rc_state = RC_DONE;
    358  1.27      yamt 		/*
    359  1.27      yamt 		 * If we have a valid reply update status and save
    360  1.27      yamt 		 * the reply for non-idempotent rpc's.
    361  1.27      yamt 		 */
    362  1.27      yamt 		if (repvalid && nonidempotent[nd->nd_procnum]) {
    363  1.27      yamt 			if ((nd->nd_flag & ND_NFSV3) == 0 &&
    364  1.27      yamt 			  nfsv2_repstat[nfsv2_procid[nd->nd_procnum]]) {
    365  1.27      yamt 				rp->rc_status = nd->nd_repstat;
    366  1.41      yamt 				rp->rc_flags |= RC_REPSTATUS;
    367  1.27      yamt 			} else {
    368  1.27      yamt 				rp->rc_reply = m_copym(repmbuf,
    369  1.27      yamt 					0, M_COPYALL, M_WAIT);
    370  1.36      yamt 				m_claimm(rp->rc_reply, &nfsd_cache_mowner);
    371  1.41      yamt 				rp->rc_flags |= RC_REPMBUF;
    372   1.1       cgd 			}
    373   1.1       cgd 		}
    374  1.40      yamt 		mutex_enter(&nfsrv_reqcache_lock);
    375  1.27      yamt 		nfsrv_unlockcache(rp);
    376  1.40      yamt 		mutex_exit(&nfsrv_reqcache_lock);
    377   1.1       cgd 	}
    378   1.7   mycroft }
    379   1.7   mycroft 
    380   1.7   mycroft /*
    381   1.7   mycroft  * Clean out the cache. Called when the last nfsd terminates.
    382   1.7   mycroft  */
    383   1.7   mycroft void
    384   1.7   mycroft nfsrv_cleancache()
    385   1.7   mycroft {
    386  1.41      yamt 	struct nfsrvcache *rp;
    387   1.7   mycroft 
    388  1.40      yamt 	mutex_enter(&nfsrv_reqcache_lock);
    389  1.41      yamt 	while ((rp = TAILQ_FIRST(&nfsrvlruhead)) != NULL) {
    390  1.41      yamt 		KASSERT((rp->rc_gflags & RC_G_LOCKED) == 0);
    391   1.9   mycroft 		LIST_REMOVE(rp, rc_hash);
    392   1.9   mycroft 		TAILQ_REMOVE(&nfsrvlruhead, rp, rc_lru);
    393  1.41      yamt 		KASSERT(numnfsrvcache > 0);
    394  1.41      yamt 		numnfsrvcache--;
    395  1.41      yamt 		mutex_exit(&nfsrv_reqcache_lock);
    396  1.34      yamt 		cleanentry(rp);
    397  1.40      yamt 		cv_destroy(&rp->rc_cv);
    398  1.25      yamt 		pool_put(&nfs_reqcache_pool, rp);
    399  1.41      yamt 		mutex_enter(&nfsrv_reqcache_lock);
    400   1.7   mycroft 	}
    401  1.41      yamt 	KASSERT(numnfsrvcache == 0);
    402  1.40      yamt 	mutex_exit(&nfsrv_reqcache_lock);
    403   1.1       cgd }
    404