From owner-svn-src-stable@FreeBSD.ORG Sat Mar 27 17:26:31 2010 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9EFB9106566C; Sat, 27 Mar 2010 17:26:31 +0000 (UTC) (envelope-from bz@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 82A588FC1B; Sat, 27 Mar 2010 17:26:31 +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 o2RHQVeW051060; Sat, 27 Mar 2010 17:26:31 GMT (envelope-from bz@svn.freebsd.org) Received: (from bz@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o2RHQVmJ051058; Sat, 27 Mar 2010 17:26:31 GMT (envelope-from bz@svn.freebsd.org) Message-Id: <201003271726.o2RHQVmJ051058@svn.freebsd.org> From: "Bjoern A. Zeeb" Date: Sat, 27 Mar 2010 17:26:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r205750 - stable/8/sys/netinet X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Mar 2010 17:26:31 -0000 Author: bz Date: Sat Mar 27 17:26:31 2010 New Revision: 205750 URL: http://svn.freebsd.org/changeset/base/205750 Log: MFC r203724: Properly free resources when destroying the TCP hostcache while tearing down a network stack (in the VIMAGE jail+vnet case). For that break out the logic from tcp_hc_purge() into an internal function we can call from both, the sysctl handler and the tcp_hc_destroy(). Reviewed by: silby, lstewart Modified: stable/8/sys/netinet/tcp_hostcache.c Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) stable/8/sys/dev/xen/xenpci/ (props changed) Modified: stable/8/sys/netinet/tcp_hostcache.c ============================================================================== --- stable/8/sys/netinet/tcp_hostcache.c Sat Mar 27 17:25:17 2010 (r205749) +++ stable/8/sys/netinet/tcp_hostcache.c Sat Mar 27 17:26:31 2010 (r205750) @@ -115,6 +115,7 @@ static VNET_DEFINE(struct callout, tcp_h static struct hc_metrics *tcp_hc_lookup(struct in_conninfo *); static struct hc_metrics *tcp_hc_insert(struct in_conninfo *); static int sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS); +static void tcp_hc_purge_internal(int); static void tcp_hc_purge(void *); SYSCTL_NODE(_net_inet_tcp, OID_AUTO, hostcache, CTLFLAG_RW, 0, @@ -235,10 +236,19 @@ tcp_hc_init(void) void tcp_hc_destroy(void) { - - /* XXX TODO walk the hashtable and free all entries */ + int i; callout_drain(&V_tcp_hc_callout); + + /* Purge all hc entries. */ + tcp_hc_purge_internal(1); + + /* Free the uma zone and the allocated hash table. */ + uma_zdestroy(V_tcp_hostcache.zone); + + for (i = 0; i < V_tcp_hostcache.hashsize; i++) + mtx_destroy(&V_tcp_hostcache.hashbase[i].hch_mtx); + free(V_tcp_hostcache.hashbase, M_HOSTCACHE); } #endif @@ -633,22 +643,14 @@ sysctl_tcp_hc_list(SYSCTL_HANDLER_ARGS) } /* - * Expire and purge (old|all) entries in the tcp_hostcache. Runs - * periodically from the callout. + * Caller has to make sure the curvnet is set properly. */ static void -tcp_hc_purge(void *arg) +tcp_hc_purge_internal(int all) { - CURVNET_SET((struct vnet *) arg); struct hc_metrics *hc_entry, *hc_next; - int all = 0; int i; - if (V_tcp_hostcache.purgeall) { - all = 1; - V_tcp_hostcache.purgeall = 0; - } - for (i = 0; i < V_tcp_hostcache.hashsize; i++) { THC_LOCK(&V_tcp_hostcache.hashbase[i].hch_mtx); TAILQ_FOREACH_SAFE(hc_entry, @@ -664,6 +666,24 @@ tcp_hc_purge(void *arg) } THC_UNLOCK(&V_tcp_hostcache.hashbase[i].hch_mtx); } +} + +/* + * Expire and purge (old|all) entries in the tcp_hostcache. Runs + * periodically from the callout. + */ +static void +tcp_hc_purge(void *arg) +{ + CURVNET_SET((struct vnet *) arg); + int all = 0; + + if (V_tcp_hostcache.purgeall) { + all = 1; + V_tcp_hostcache.purgeall = 0; + } + + tcp_hc_purge_internal(all); callout_reset(&V_tcp_hc_callout, V_tcp_hostcache.prune * hz, tcp_hc_purge, arg);