Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1672994ybf; Sun, 1 Mar 2020 15:26:33 -0800 (PST) X-Google-Smtp-Source: APXvYqzSOrnGqankCRcT29gUVZjBj1qLfO/46I+PQ++r+fT+8lgElYoHXvykwPkp8GpT76/RQtwa X-Received: by 2002:a05:6830:168b:: with SMTP id k11mr7402854otr.156.1583105193175; Sun, 01 Mar 2020 15:26:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583105193; cv=none; d=google.com; s=arc-20160816; b=Y2SQ3lw/zWPT6l9cLBUC2sUPUH/jTRA6WBXtbXZp9UezocAto+GtK5U1UIgS+CDGlq tc1hdIVpOhB6Bokjqng9x/lo7Ho1FPuy0qhtOd3sXkAFDHATQl44wl17/Jn1hf5aU6or OLAcXahUdfWBUKo5gG3bL1sVdc+Q2AB++UrpsH12dwAmh5+z/ljlhEngrFTb+m6iWFq+ W0oOyxLuKjQODIjDYEa7UNPY4SqiscYdcZlkvHcsZEBRrlIQ5xuRuBwx7x3RmaAb5q+v 5YIX1VyqUq4bI4UaIIXlhyDnoHnFUY10C2IOt55rBoJ8sLzXLj76g1VGnjwMlYvr7Xzg XYug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MWEyLw6EQcAivJXsLlZHcdf1lKHYi989/KDUlTy90nY=; b=K37StvtkitYe7qff8ZzkvaGcQBJ1Qeu9kElGjHYcUWSd10dXydKOuWlY6A6TxnbsCD KCZ6rglJSHQKa5EBRvPBFkVHLF4DL8J4KNzvYJNZ6WUC09/7+AdiK6I0pbnAjq9JulBT vptEnUKCB6/T1y+TDmZgu/xR1FHls6kuVQeCTDm+y+ObAb3PnKvJc3TXNzCF6JQpv5ov /xJPMyNN80Ox158ZJl5nZA3+L9+N1bLPG+nTzKEiljYkOMzecNH8n1lApICUNYNw9unD EvnwGaQ8EH5C0kUZ7gZ8+CGNsnOI963Ow3T1XXcZyh+kqHFquJx1C7cnkJVSgYS/k/Ji JhYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vZfAfthe; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d22si5846929oti.316.2020.03.01.15.26.22; Sun, 01 Mar 2020 15:26:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=vZfAfthe; spf=pass (google.com: best guess record for domain of linux-nfs-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726627AbgCAXZW (ORCPT + 99 others); Sun, 1 Mar 2020 18:25:22 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:38997 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726673AbgCAXZW (ORCPT ); Sun, 1 Mar 2020 18:25:22 -0500 Received: by mail-yw1-f68.google.com with SMTP id x184so9482034ywd.6 for ; Sun, 01 Mar 2020 15:25:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MWEyLw6EQcAivJXsLlZHcdf1lKHYi989/KDUlTy90nY=; b=vZfAftheEIXvNSdnKIAErv4k0Yl+Wx0I72g/Oknhfk1AUHGxdLY1D65sIdyly40zYC qDo+oFwkKgqpmgmST1Q6wBkqMd15JBKOEbFBCXaBGoyNtnBExl0YizpXrvIMod+YCWhA O6N/eVUhT/pYcZ+GLgOyFTEvZJXfVVn9Fe9a1eoKFY+81IkhY0MsGQoeFeA7a2QOXY8F ab5Fu2faFQx6xAEf5kLtWt/LmQDNAlns/DGQXEWzwyh1HFYVva+yD3/ASMIXVZ550hKl daAC3ghJi3jYEdTLORXeiuBwn9n4+GVDeUU+PesmysAoHQNqLkswGwP93fN6RrKpfZRT xSuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=MWEyLw6EQcAivJXsLlZHcdf1lKHYi989/KDUlTy90nY=; b=Y01GMO3ElMZa3WuQ0cP7FmnsjkFtEa0xXsdCnoh6kvv6WUJa6LAvGbZXrwRdpdWIsV ZR1lBjsBNSaBMawofP/SLaAq95cWzAnuVfNv1Dwf2FU0IX7Xvsdqz139vBeAXU9q1Bmq nKCkctHTnSOnvlLql01qg1SmNFw5QO2PPveBnLFljR+PwhnoGS1Tu6b0t7rib8B9F0yl 6mQc/7s2QMTAMK7egl93cOpn04GCcryqozb2YWYND3/dTR20f7sxrwZ+yJ0KqxJWZYIr I7fpTLbVDdwiNgGNXfxkBHbITpOerq+04inqgsjqNNOHy12slL3kF1VQmS5VK/dZnPqU Fbww== X-Gm-Message-State: ANhLgQ26KiH4Oto8+w8iH75aznoQZ87UkzaVB/Im0oupg7prqt0seIZU C6w+1JSERbvpeWsjdBNavkrJRcdPvw== X-Received: by 2002:a05:6902:693:: with SMTP id i19mr389340ybt.297.1583105119633; Sun, 01 Mar 2020 15:25:19 -0800 (PST) Received: from localhost.localdomain (c-68-40-189-247.hsd1.mi.comcast.net. [68.40.189.247]) by smtp.gmail.com with ESMTPSA id u4sm7167301ywu.26.2020.03.01.15.25.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Mar 2020 15:25:19 -0800 (PST) From: Trond Myklebust X-Google-Original-From: Trond Myklebust To: "J. Bruce Fields" Cc: linux-nfs@vger.kernel.org Subject: [PATCH 6/8] SUNRPC/cache: Allow garbage collection of invalid cache entries Date: Sun, 1 Mar 2020 18:21:43 -0500 Message-Id: <20200301232145.1465430-7-trond.myklebust@hammerspace.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200301232145.1465430-6-trond.myklebust@hammerspace.com> References: <20200301232145.1465430-1-trond.myklebust@hammerspace.com> <20200301232145.1465430-2-trond.myklebust@hammerspace.com> <20200301232145.1465430-3-trond.myklebust@hammerspace.com> <20200301232145.1465430-4-trond.myklebust@hammerspace.com> <20200301232145.1465430-5-trond.myklebust@hammerspace.com> <20200301232145.1465430-6-trond.myklebust@hammerspace.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org If the cache entry never gets initialised, we want the garbage collector to be able to evict it. Otherwise if the upcall daemon fails to initialise the entry, we end up never expiring it. Signed-off-by: Trond Myklebust --- include/linux/sunrpc/cache.h | 3 --- net/sunrpc/cache.c | 36 +++++++++++++++++++----------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h index 656882a50991..532cdbda43da 100644 --- a/include/linux/sunrpc/cache.h +++ b/include/linux/sunrpc/cache.h @@ -209,9 +209,6 @@ static inline void cache_put(struct cache_head *h, struct cache_detail *cd) static inline bool cache_is_expired(struct cache_detail *detail, struct cache_head *h) { - if (!test_bit(CACHE_VALID, &h->flags)) - return false; - return (h->expiry_time < seconds_since_boot()) || (detail->flush_time >= h->last_refresh); } diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c index 5e14513603cb..b7ddb2affb7e 100644 --- a/net/sunrpc/cache.c +++ b/net/sunrpc/cache.c @@ -64,13 +64,14 @@ static struct cache_head *sunrpc_cache_find_rcu(struct cache_detail *detail, rcu_read_lock(); hlist_for_each_entry_rcu(tmp, head, cache_list) { - if (detail->match(tmp, key)) { - if (cache_is_expired(detail, tmp)) - continue; - tmp = cache_get_rcu(tmp); - rcu_read_unlock(); - return tmp; - } + if (!detail->match(tmp, key)) + continue; + if (test_bit(CACHE_VALID, &tmp->flags) && + cache_is_expired(detail, tmp)) + continue; + tmp = cache_get_rcu(tmp); + rcu_read_unlock(); + return tmp; } rcu_read_unlock(); return NULL; @@ -113,17 +114,18 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail, /* check if entry appeared while we slept */ hlist_for_each_entry_rcu(tmp, head, cache_list) { - if (detail->match(tmp, key)) { - if (cache_is_expired(detail, tmp)) { - sunrpc_begin_cache_remove_entry(tmp, detail); - freeme = tmp; - break; - } - cache_get(tmp); - spin_unlock(&detail->hash_lock); - cache_put(new, detail); - return tmp; + if (!detail->match(tmp, key)) + continue; + if (test_bit(CACHE_VALID, &tmp->flags) && + cache_is_expired(detail, tmp)) { + sunrpc_begin_cache_remove_entry(tmp, detail); + freeme = tmp; + break; } + cache_get(tmp); + spin_unlock(&detail->hash_lock); + cache_put(new, detail); + return tmp; } hlist_add_head_rcu(&new->cache_list, head); -- 2.24.1