From patchwork Wed Aug 5 21:13:26 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 6953111 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6798E9F39D for ; Wed, 5 Aug 2015 21:13:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 64BAD2052C for ; Wed, 5 Aug 2015 21:13:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6372B204AB for ; Wed, 5 Aug 2015 21:13:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752728AbbHEVNx (ORCPT ); Wed, 5 Aug 2015 17:13:53 -0400 Received: from mail-yk0-f177.google.com ([209.85.160.177]:33880 "EHLO mail-yk0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752471AbbHEVNt (ORCPT ); Wed, 5 Aug 2015 17:13:49 -0400 Received: by ykax123 with SMTP id x123so46811560yka.1 for ; Wed, 05 Aug 2015 14:13:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HC+ZeZakbuQiD6z+ZJjH/slwAJ9HUIUb+JYt5IComCk=; b=YKp0hGRvHA6Yjg7d76Iw3168gbXnjAXvW6y1R1dUYp6EXyJByaN4K7XJGMzPlPbYbq oGurrC/wAV7ht4MX8b92UkncwTRQayij4H6JOKIKKjAxBXTcm5YqYk1oOHhShWvTZpTo Gu3icHpATNZ/po0yuT58b0fRgLOP13O5iSh/16KdDhnt87ubCHi8hJITK3Zo1+9vfElU S/TkClxrLjSwxLiaRM7VqabdIsBoE5PGqgGDsEsEDJfuJHBskNQt4cnfYCT9wLq2XQVb Zy5x701gOWWcTVEKVsUHgBeTVxTcTFcej4UanLeOOHEcizG5HzJruWIBiVK2DXG9sHas 3VdQ== X-Gm-Message-State: ALoCoQks0gXq3lqVjjZMkLFhHcFxHnXD9XLpWpng3cCe2fcFWcjurdKrMO8HWLM1eVAxj9foRtQx X-Received: by 10.13.237.1 with SMTP id w1mr11584720ywe.132.1438809229094; Wed, 05 Aug 2015 14:13:49 -0700 (PDT) Received: from tlielax.poochiereds.net (cpe-45-37-211-243.nc.res.rr.com. [45.37.211.243]) by smtp.googlemail.com with ESMTPSA id p81sm3975306ywe.19.2015.08.05.14.13.48 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 05 Aug 2015 14:13:48 -0700 (PDT) From: Jeff Layton X-Google-Original-From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org Subject: [PATCH v2 08/18] nfsd: add a ->flush routine to svc_export_cache Date: Wed, 5 Aug 2015 17:13:26 -0400 Message-Id: <1438809216-4846-9-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1438809216-4846-1-git-send-email-jeff.layton@primarydata.com> References: <1438264341-18048-1-git-send-email-jeff.layton@primarydata.com> <1438809216-4846-1-git-send-email-jeff.layton@primarydata.com> Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP ...to purge the nfsd_file table. This should help ensure that filesystems are unmountable very soon after unexporting them. Note that we take the nfsd_mutex in this code to ensure that we can't race with a concurrent shutdown of nfsd that might destroy the cache. Signed-off-by: Jeff Layton --- fs/nfsd/export.c | 14 ++++++++++++++ fs/nfsd/filecache.c | 39 +++++++++++++++++++++++++-------------- fs/nfsd/filecache.h | 1 + 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c index f79521a59747..be80ff370072 100644 --- a/fs/nfsd/export.c +++ b/fs/nfsd/export.c @@ -21,6 +21,7 @@ #include "nfsfh.h" #include "netns.h" #include "pnfs.h" +#include "filecache.h" #define NFSDDBG_FACILITY NFSDDBG_EXPORT @@ -231,6 +232,18 @@ static struct cache_head *expkey_alloc(void) return NULL; } +static void +expkey_flush(void) +{ + /* + * Take the nfsd_mutex here to ensure that the file cache is not + * destroyed while we're in the middle of flushing. + */ + mutex_lock(&nfsd_mutex); + nfsd_file_cache_purge(); + mutex_unlock(&nfsd_mutex); +} + static struct cache_detail svc_expkey_cache_template = { .owner = THIS_MODULE, .hash_size = EXPKEY_HASHMAX, @@ -243,6 +256,7 @@ static struct cache_detail svc_expkey_cache_template = { .init = expkey_init, .update = expkey_update, .alloc = expkey_alloc, + .flush = expkey_flush, }; static int diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 5278b8d9e79a..a3782cf7b352 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -124,6 +124,30 @@ nfsd_file_dispose_list(struct list_head *dispose) } } +void +nfsd_file_cache_purge(void) +{ + unsigned int i; + struct nfsd_file *nf; + LIST_HEAD(dispose); + + if (!atomic_read(&nfsd_file_count)) + return; + + for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) { + spin_lock(&nfsd_file_hashtbl[i].nfb_lock); + while(!hlist_empty(&nfsd_file_hashtbl[i].nfb_head)) { + nf = hlist_entry(nfsd_file_hashtbl[i].nfb_head.first, + struct nfsd_file, nf_node); + nfsd_file_unhash(nf); + /* put the hash reference */ + nfsd_file_put_locked(nf, &dispose); + } + spin_unlock(&nfsd_file_hashtbl[i].nfb_lock); + nfsd_file_dispose_list(&dispose); + } +} + static void nfsd_file_cache_prune(void) { @@ -200,23 +224,10 @@ out_nomem: void nfsd_file_cache_shutdown(void) { - unsigned int i; - struct nfsd_file *nf; LIST_HEAD(dispose); cancel_delayed_work_sync(&nfsd_file_cache_clean_work); - for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) { - spin_lock(&nfsd_file_hashtbl[i].nfb_lock); - while(!hlist_empty(&nfsd_file_hashtbl[i].nfb_head)) { - nf = hlist_entry(nfsd_file_hashtbl[i].nfb_head.first, - struct nfsd_file, nf_node); - nfsd_file_unhash(nf); - /* put the hash reference */ - nfsd_file_put_locked(nf, &dispose); - } - spin_unlock(&nfsd_file_hashtbl[i].nfb_lock); - nfsd_file_dispose_list(&dispose); - } + nfsd_file_cache_purge(); kfree(nfsd_file_hashtbl); nfsd_file_hashtbl = NULL; } diff --git a/fs/nfsd/filecache.h b/fs/nfsd/filecache.h index adf7e78b8e43..98976f71caa8 100644 --- a/fs/nfsd/filecache.h +++ b/fs/nfsd/filecache.h @@ -39,6 +39,7 @@ struct nfsd_file { }; int nfsd_file_cache_init(void); +void nfsd_file_cache_purge(void); void nfsd_file_cache_shutdown(void); void nfsd_file_put(struct nfsd_file *nf); __be32 nfsd_file_acquire(struct svc_rqst *rqstp, struct svc_fh *fhp,