From patchwork Mon Feb 6 04:01:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinglong Mee X-Patchwork-Id: 9557077 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2DBE8602B1 for ; Mon, 6 Feb 2017 04:02:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D898269E2 for ; Mon, 6 Feb 2017 04:02:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F71826E82; Mon, 6 Feb 2017 04:02:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E357269E2 for ; Mon, 6 Feb 2017 04:02:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753446AbdBFECB (ORCPT ); Sun, 5 Feb 2017 23:02:01 -0500 Received: from mail-io0-f196.google.com ([209.85.223.196]:34398 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751968AbdBFECA (ORCPT ); Sun, 5 Feb 2017 23:02:00 -0500 Received: by mail-io0-f196.google.com with SMTP id c80so8105954iod.1 for ; Sun, 05 Feb 2017 20:02:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=XYDbOENdbZ2v5U+ycjUBvdBgTpfx82igKJtbUxe+SwI=; b=bNnLJsSE2D8VkcfTzzfCxVuTePP3ArEO39jK/JrVXutbgbx4B1uFAvlfBBIAvq2tLP 9K7rMgHNs93rmaEujvzsbXa6zSDADbTXs28Sfue2O7bHs1nbpyA1/mq6uw6Hit6DnIaC WqEisnWncErMW+mIiyOL8LEPck++AuFbKVRZ8tgaIC2pH6CxFC4plPOTB5z+XRntnxee GAttRHr/aXQ3jqWJpLQ2seBymOgasU1migKa1EzWLYAoFAaID4WwXJqeDDo/EQIjLfGD nZh5l2+3AOLwsZxz3R532LJ5HSaeVc4HmWKLwWsMKtfgJ2Kmb99lASl3wOa1dCt1sroT 2cxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=XYDbOENdbZ2v5U+ycjUBvdBgTpfx82igKJtbUxe+SwI=; b=ACllHEE37K+rVSe5K614K5MmcXZCvQcgQbjJOb9YwrOTg59xA+gcmemhPz+b4oVpXd FuGwh1XQvNksZWAmcIBptSAiEaRC5PiVGtqwGJeZD5sy3Ntsyo07D8zy/Jyju0OyjEsj T5NS+C2K1gKoGICxPM8/7gVY943Q9IZVTostQWyqVBzJDfwGlDba3AzoNyIlixZPxOCP gGh98GGKieMi3oubf7tt6kJSytJMOiTvefeq91Cq5CFJD2iy3HGD57KFCp2BY0o5EGTJ hj6h115VytchVDhu0n0KR2qvpA+aUir97l2STf7NRa02F/8rvAMYPgTFrS8scO3mLs2n e2oQ== X-Gm-Message-State: AMke39m+PocC4hR9FGMlf2ooZvGA0Uq3E0bFOUEkRfrfOQBrjssJ2mMywJ7xChZt3BClOg== X-Received: by 10.107.137.224 with SMTP id t93mr5533980ioi.60.1486353719726; Sun, 05 Feb 2017 20:01:59 -0800 (PST) Received: from [192.168.0.107] ([182.139.117.200]) by smtp.gmail.com with ESMTPSA id x100sm3628195ita.12.2017.02.05.20.01.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Feb 2017 20:01:59 -0800 (PST) To: "J. Bruce Fields" , linux-nfs@vger.kernel.org Cc: NeilBrown , Trond Myklebust , Kinglong Mee From: Kinglong Mee Subject: [PATCH 2/2] SUNRPC: Drop all entries from cache_detail when cache_purge() Message-ID: <400d714e-3e4c-74b0-6734-96dbf491b9d9@gmail.com> Date: Mon, 6 Feb 2017 12:01:52 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.7.0 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP User always free the cache_detail after sunrpc_destroy_cache_detail(), so, it must cleanup up entries that left in the cache_detail, otherwise, NULL reference may be caused when using the left entries. Also, NeriBrown suggests "write a stand-alone cache_purge()." v2, a stand-alone cache_purge(), not only for sunrpc_destroy_cache_detail Signed-off-by: Kinglong Mee --- net/sunrpc/cache.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 8147e8d..bd6ee79 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -362,11 +362,6 @@ void sunrpc_destroy_cache_detail(struct cache_detail *cd) cache_purge(cd); spin_lock(&cache_list_lock); write_lock(&cd->hash_lock); - if (cd->entries) { - write_unlock(&cd->hash_lock); - spin_unlock(&cache_list_lock); - goto out; - } if (current_detail == cd) current_detail = NULL; list_del_init(&cd->others); @@ -376,9 +371,6 @@ void sunrpc_destroy_cache_detail(struct cache_detail *cd) /* module must be being unloaded so its safe to kill the worker */ cancel_delayed_work_sync(&cache_cleaner); } - return; -out: - printk(KERN_ERR "RPC: failed to unregister %s cache\n", cd->name); } EXPORT_SYMBOL_GPL(sunrpc_destroy_cache_detail); @@ -497,13 +489,30 @@ EXPORT_SYMBOL_GPL(cache_flush); void cache_purge(struct cache_detail *detail) { - time_t now = seconds_since_boot(); - if (detail->flush_time >= now) - now = detail->flush_time + 1; - /* 'now' is the maximum value any 'last_refresh' can have */ - detail->flush_time = now; - detail->nextcheck = seconds_since_boot(); - cache_flush(); + struct cache_head *ch = NULL; + struct hlist_head *head = NULL; + struct hlist_node *tmp = NULL; + int i = 0; + + write_lock(&detail->hash_lock); + if (!detail->entries) { + write_unlock(&detail->hash_lock); + return; + } + + dprintk("RPC: %d entries in %s cache\n", detail->entries, detail->name); + for (i = 0; i < detail->hash_size; i++) { + head = &detail->hash_table[i]; + hlist_for_each_entry_safe(ch, tmp, head, cache_list) { + hlist_del_init(&ch->cache_list); + detail->entries--; + + set_bit(CACHE_CLEANED, &ch->flags); + cache_fresh_unlocked(ch, detail); + cache_put(ch, detail); + } + } + write_unlock(&detail->hash_lock); } EXPORT_SYMBOL_GPL(cache_purge);