From owner-svn-src-projects@FreeBSD.ORG Thu Jun 21 10:21:14 2012 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id DF6A4106566B; Thu, 21 Jun 2012 10:21:14 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id CAA658FC08; Thu, 21 Jun 2012 10:21:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q5LALE2d006458; Thu, 21 Jun 2012 10:21:14 GMT (envelope-from glebius@svn.freebsd.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q5LALEnl006456; Thu, 21 Jun 2012 10:21:14 GMT (envelope-from glebius@svn.freebsd.org) Message-Id: <201206211021.q5LALEnl006456@svn.freebsd.org> From: Gleb Smirnoff Date: Thu, 21 Jun 2012 10:21:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r237376 - projects/pf/head/sys/contrib/pf/net X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jun 2012 10:21:15 -0000 Author: glebius Date: Thu Jun 21 10:21:14 2012 New Revision: 237376 URL: http://svn.freebsd.org/changeset/base/237376 Log: - To free all rules when shutting down we need to perform a couple of scans. Do this and provide some comments to explain what is going on here. - We can't call into pf_purge_unlinked_rules() with rules lock held, since it would obtain it exclusively. Modified: projects/pf/head/sys/contrib/pf/net/pf.c Modified: projects/pf/head/sys/contrib/pf/net/pf.c ============================================================================== --- projects/pf/head/sys/contrib/pf/net/pf.c Thu Jun 21 10:06:00 2012 (r237375) +++ projects/pf/head/sys/contrib/pf/net/pf.c Thu Jun 21 10:21:14 2012 (r237376) @@ -1317,19 +1317,45 @@ pf_purge_thread(void *v) CURVNET_SET((struct vnet *)v); - PF_RULES_RLOCK(); for (;;) { + PF_RULES_RLOCK(); rw_sleep(pf_purge_thread, &pf_rules_lock, 0, "pftm", hz / 10); if (V_pf_end_threads) { + /* + * To cleanse up all kifs and rules we need + * two runs: first one clears reference flags, + * then pf_purge_expired_states() doesn't + * raise them, and then second run frees. + */ + PF_RULES_RUNLOCK(); + pf_purge_unlinked_rules(); + pfi_kif_purge(); + + /* + * Now purge everything. + */ pf_purge_expired_states(V_pf_hashmask + 1); pf_purge_expired_fragments(); pf_purge_expired_src_nodes(); + + /* + * Now all kifs & rules should be unreferenced, + * thus should be successfully freed. + */ + pf_purge_unlinked_rules(); + pfi_kif_purge(); + + /* + * Announce success and exit. + */ + PF_RULES_RLOCK(); V_pf_end_threads++; PF_RULES_RUNLOCK(); wakeup(pf_purge_thread); kproc_exit(0); } + PF_RULES_RUNLOCK(); /* Process 1/interval fraction of the state table every run. */ fullrun = pf_purge_expired_states(V_pf_hashmask /