From owner-svn-src-head@FreeBSD.ORG Sun Apr 10 20:43:08 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1DDEF106566B; Sun, 10 Apr 2011 20:43:08 +0000 (UTC) (envelope-from rmacklem@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0DFCD8FC1E; Sun, 10 Apr 2011 20:43:08 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p3AKh7Os059256; Sun, 10 Apr 2011 20:43:07 GMT (envelope-from rmacklem@svn.freebsd.org) Received: (from rmacklem@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p3AKh7W6059252; Sun, 10 Apr 2011 20:43:07 GMT (envelope-from rmacklem@svn.freebsd.org) Message-Id: <201104102043.p3AKh7W6059252@svn.freebsd.org> From: Rick Macklem Date: Sun, 10 Apr 2011 20:43:07 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r220530 - in head/sys/fs: nfs nfsserver X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 10 Apr 2011 20:43:08 -0000 Author: rmacklem Date: Sun Apr 10 20:43:07 2011 New Revision: 220530 URL: http://svn.freebsd.org/changeset/base/220530 Log: Add some cleanup code to the module unload operation for the experimental NFS server, so that it doesn't leak memory when unloaded. However, unloading the NFSv4 server is not recommended, since all NFSv4 state will be lost by the unload and clients will have to recover the state after a server reload/restart as if the server crashed/rebooted. MFC after: 2 weeks Modified: head/sys/fs/nfs/nfs_var.h head/sys/fs/nfsserver/nfs_nfsdport.c head/sys/fs/nfsserver/nfs_nfsdstate.c Modified: head/sys/fs/nfs/nfs_var.h ============================================================================== --- head/sys/fs/nfs/nfs_var.h Sun Apr 10 19:31:00 2011 (r220529) +++ head/sys/fs/nfs/nfs_var.h Sun Apr 10 20:43:07 2011 (r220530) @@ -124,6 +124,7 @@ int nfsrv_checkgetattr(struct nfsrv_desc struct nfsvattr *, nfsattrbit_t *, struct ucred *, NFSPROC_T *); int nfsrv_nfsuserdport(u_short, NFSPROC_T *); void nfsrv_nfsuserddelport(void); +void nfsrv_throwawayallstate(NFSPROC_T *); /* nfs_nfsdserv.c */ int nfsrvd_access(struct nfsrv_descript *, int, Modified: head/sys/fs/nfsserver/nfs_nfsdport.c ============================================================================== --- head/sys/fs/nfsserver/nfs_nfsdport.c Sun Apr 10 19:31:00 2011 (r220529) +++ head/sys/fs/nfsserver/nfs_nfsdport.c Sun Apr 10 20:43:07 2011 (r220530) @@ -54,6 +54,7 @@ extern int newnfs_numnfsd; extern struct mount nfsv4root_mnt; extern struct nfsrv_stablefirst nfsrv_stablefirst; extern void (*nfsd_call_servertimer)(void); +extern SVCPOOL *nfsrvd_pool; struct vfsoptlist nfsv4root_opt, nfsv4root_newopt; NFSDLOCKMUTEX; struct mtx nfs_cache_mutex; @@ -3125,9 +3126,16 @@ nfsd_modevent(module_t mod, int type, vo nfsd_call_servertimer = NULL; nfsd_call_nfsd = NULL; + /* Clean out all NFSv4 state. */ + nfsrv_throwawayallstate(curthread); + /* Clean the NFS server reply cache */ nfsrvd_cleancache(); + /* Free up the krpc server pool. */ + if (nfsrvd_pool != NULL) + svcpool_destroy(nfsrvd_pool); + /* and get rid of the locks */ mtx_destroy(&nfs_cache_mutex); mtx_destroy(&nfs_v4root_mutex); Modified: head/sys/fs/nfsserver/nfs_nfsdstate.c ============================================================================== --- head/sys/fs/nfsserver/nfs_nfsdstate.c Sun Apr 10 19:31:00 2011 (r220529) +++ head/sys/fs/nfsserver/nfs_nfsdstate.c Sun Apr 10 20:43:07 2011 (r220530) @@ -5194,3 +5194,37 @@ nfsrv_unlocklf(struct nfslockfile *lfp) nfsv4_unlock(&lfp->lf_locallock_lck, 0); } +/* + * Clear out all state for the NFSv4 server. + * Must be called by a thread that can sleep when no nfsds are running. + */ +void +nfsrv_throwawayallstate(NFSPROC_T *p) +{ + struct nfsclient *clp, *nclp; + struct nfslockfile *lfp, *nlfp; + int i; + + /* + * For each client, clean out the state and then free the structure. + */ + for (i = 0; i < NFSCLIENTHASHSIZE; i++) { + LIST_FOREACH_SAFE(clp, &nfsclienthash[i], lc_hash, nclp) { + nfsrv_cleanclient(clp, p); + nfsrv_freedeleglist(&clp->lc_deleg); + nfsrv_freedeleglist(&clp->lc_olddeleg); + free(clp, M_NFSDCLIENT); + } + } + + /* + * Also, free up any remaining lock file structures. + */ + for (i = 0; i < NFSLOCKHASHSIZE; i++) { + LIST_FOREACH_SAFE(lfp, &nfslockhash[i], lf_hash, nlfp) { + printf("nfsd unload: fnd a lock file struct\n"); + nfsrv_freenfslockfile(lfp); + } + } +} +