From patchwork Thu Aug 20 11:17:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Layton X-Patchwork-Id: 7043651 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 E1F859F372 for ; Thu, 20 Aug 2015 11:17:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E7767205C2 for ; Thu, 20 Aug 2015 11:17:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E0812205CD for ; Thu, 20 Aug 2015 11:17:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751828AbbHTLRf (ORCPT ); Thu, 20 Aug 2015 07:17:35 -0400 Received: from mail-yk0-f172.google.com ([209.85.160.172]:33384 "EHLO mail-yk0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751761AbbHTLRd (ORCPT ); Thu, 20 Aug 2015 07:17:33 -0400 Received: by ykll84 with SMTP id l84so33731915ykl.0 for ; Thu, 20 Aug 2015 04:17:32 -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=cfzE5Mm1e21IeRjQzmda/7sntff7ylVS1grJ1hjdmlk=; b=cu9FP5rO9PxvB8RroFrFpnTDx6wlkoKtxj/PGkKnzTYcfilRCw0jiJpHF3AhLfbNDm zqJ9a+qW/JyjMA378oNHrizKPpi2tu7CAi5/OFP1ai36VrVB2Q97f5BmS6TjB2SF28hU /lAPRaZPWD1SgpkIFsn8TN00h1Yyl/PqZGXc5ua/tm03+oC5+KPuyqbLjclrfaLEghZj fxM8VSsF4fDOF6+cgnIMmsMT1wXgwPTNKJsHvSYTWcR8SRzYxrAYgGDQzdtrNtes9UHT 8g7JoQXg5vgTvRqi+cdLu9bakKwcL5qIiKFV6c3xjXeRjdyiJg0eAappghb+Pn4wHuKe vcQg== X-Gm-Message-State: ALoCoQmFtRaX/lV/ZgoFpdC++OwlWz8mfphKpYGb9q/eAm0GUNpjsDNvhMh1zt6vuZvBkNQZtOjZ X-Received: by 10.13.193.1 with SMTP id c1mr2501543ywd.172.1440069452732; Thu, 20 Aug 2015 04:17:32 -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 k66sm3637319ywe.0.2015.08.20.04.17.31 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Aug 2015 04:17:32 -0700 (PDT) From: Jeff Layton X-Google-Original-From: Jeff Layton To: bfields@fieldses.org Cc: linux-nfs@vger.kernel.org, hch@lst.de, kinglongmee@gmail.com Subject: [PATCH v3 06/20] locks/nfsd: create a new notifier chain for lease attempts Date: Thu, 20 Aug 2015 07:17:06 -0400 Message-Id: <1440069440-27454-7-git-send-email-jeff.layton@primarydata.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1440069440-27454-1-git-send-email-jeff.layton@primarydata.com> References: <1440069440-27454-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.5 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 With the new file caching infrastructure in nfsd, we can end up holding files open for an indefinite period of time, even when they are still idle. This may prevent the kernel from handing out leases on the file, which we don't really want to block. Fix this by running a blocking notifier call chain whenever on any lease attempt. nfsd can then purge the cache for that inode before returning. Signed-off-by: Jeff Layton --- fs/locks.c | 15 +++++++++++++++ fs/nfsd/filecache.c | 27 +++++++++++++++++++++++++++ include/linux/fs.h | 1 + 3 files changed, 43 insertions(+) diff --git a/fs/locks.c b/fs/locks.c index d3d558ba4da7..c81b96159e5c 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -167,6 +167,13 @@ DEFINE_STATIC_LGLOCK(file_lock_lglock); static DEFINE_PER_CPU(struct hlist_head, file_lock_list); /* + * Some subsystems would like to be notified if someone attempts to set a + * lease on a file. This notifier chain will be called whenever this occurs. + */ +BLOCKING_NOTIFIER_HEAD(lease_notifier_chain); +EXPORT_SYMBOL_GPL(lease_notifier_chain); + +/* * The blocked_hash is used to find POSIX lock loops for deadlock detection. * It is protected by blocked_lock_lock. * @@ -1795,10 +1802,18 @@ EXPORT_SYMBOL(generic_setlease); * * The "priv" pointer is passed directly to the lm_setup function as-is. It * may be NULL if the lm_setup operation doesn't require it. + * + * Kernel subsystems can also register to be notified on any attempt to set + * a new lease with the lease_notifier_chain. This is used by (e.g.) nfsd + * to close files that it may have cached when there is an attempt to set a + * conflicting lease. */ int vfs_setlease(struct file *filp, long arg, struct file_lock **lease, void **priv) { + if (arg != F_UNLCK) + blocking_notifier_call_chain(&lease_notifier_chain, arg, *lease); + if (filp->f_op->setlease) return filp->f_op->setlease(filp, arg, lease, priv); else diff --git a/fs/nfsd/filecache.c b/fs/nfsd/filecache.c index 669e62f6f4f6..77041967d8ff 100644 --- a/fs/nfsd/filecache.c +++ b/fs/nfsd/filecache.c @@ -158,6 +158,22 @@ static struct shrinker nfsd_file_shrinker = { .seeks = 1, }; +static int +nfsd_file_lease_notifier_call(struct notifier_block *nb, unsigned long arg, + void *data) +{ + struct file_lock *fl = data; + + /* Don't close files if we're the one trying to set the lease */ + if (fl->fl_type == FL_LEASE) + nfsd_file_close_inode(file_inode(fl->fl_file)); + return 0; +} + +static struct notifier_block nfsd_file_lease_notifier = { + .notifier_call = nfsd_file_lease_notifier_call, +}; + int nfsd_file_cache_init(void) { @@ -186,12 +202,21 @@ nfsd_file_cache_init(void) goto out_lru; } + ret = blocking_notifier_chain_register(&lease_notifier_chain, + &nfsd_file_lease_notifier); + if (ret) { + pr_err("nfsd: unable to register lease notifier: %d\n", ret); + goto out_shrinker; + } + for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) { INIT_HLIST_HEAD(&nfsd_file_hashtbl[i].nfb_head); spin_lock_init(&nfsd_file_hashtbl[i].nfb_lock); } out: return ret; +out_shrinker: + unregister_shrinker(&nfsd_file_shrinker); out_lru: list_lru_destroy(&nfsd_file_lru); out_err: @@ -207,6 +232,8 @@ nfsd_file_cache_shutdown(void) struct nfsd_file *nf; LIST_HEAD(dispose); + blocking_notifier_chain_unregister(&lease_notifier_chain, + &nfsd_file_lease_notifier); unregister_shrinker(&nfsd_file_shrinker); for (i = 0; i < NFSD_FILE_HASH_SIZE; i++) { spin_lock(&nfsd_file_hashtbl[i].nfb_lock); diff --git a/include/linux/fs.h b/include/linux/fs.h index 9a9d314f7b27..01bb82eae684 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1041,6 +1041,7 @@ extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg); extern int fcntl_getlease(struct file *filp); /* fs/locks.c */ +extern struct blocking_notifier_head lease_notifier_chain; void locks_free_lock_context(struct file_lock_context *ctx); void locks_free_lock(struct file_lock *fl); extern void locks_init_lock(struct file_lock *);