From patchwork Mon Feb 11 17:27:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10806527 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7B6C17FB for ; Mon, 11 Feb 2019 17:30:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B238F2AFFA for ; Mon, 11 Feb 2019 17:30:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A65842B000; Mon, 11 Feb 2019 17:30:34 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable 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 53F752AFFA for ; Mon, 11 Feb 2019 17:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731312AbfBKRaV (ORCPT ); Mon, 11 Feb 2019 12:30:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:46570 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730338AbfBKR3n (ORCPT ); Mon, 11 Feb 2019 12:29:43 -0500 Received: from sol.localdomain (c-107-3-167-184.hsd1.ca.comcast.net [107.3.167.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1A352222A9; Mon, 11 Feb 2019 17:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1549906181; bh=LHU0VKAUPXgaadVEq89d1supnSav2nCovQtUB0yGf0M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HHC+TaMMTJM3NpzleY+Gsh4zsYqdjXl27kj8EKGOxvdOQMUV76TXes1bBxZgZVLUc btxFfSTT/164wINdM4xan+haMIICRG1pQZ0tdBp1uEF5+go7g4s7oWC4rG4zRwFgEA kMuj9c9HL7pLK4CsqZRWGYgB90wmkpsHcUOPIcA4= From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org, linux-crypto@vger.kernel.org, linux-api@vger.kernel.org, keyrings@vger.kernel.org, Satya Tangirala , Paul Crowley Subject: [RFC PATCH v2 10/20] fs/dcache.c: add shrink_dcache_inode() Date: Mon, 11 Feb 2019 09:27:28 -0800 Message-Id: <20190211172738.4633-11-ebiggers@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190211172738.4633-1-ebiggers@kernel.org> References: <20190211172738.4633-1-ebiggers@kernel.org> MIME-Version: 1.0 Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers When a filesystem encryption key is removed, we need all files which had been "unlocked" (had ->i_crypt_info set up) with it to appear "locked" again. This is most easily done by evicting the inodes. This can currently be done using 'echo 2 > /proc/sys/vm/drop_caches'; however, that is overkill and not usable by non-root users. To evict just the needed inodes we also need the ability to evict those inodes' dentries, since an inode is pinned by its dentries. Therefore, add a function shrink_dcache_inode() which iterates through an inode's dentries and evicts any unused ones as well as any unused descendants (since there may be negative dentries pinning the inode's dentries). Signed-off-by: Eric Biggers --- fs/dcache.c | 32 ++++++++++++++++++++++++++++++++ include/linux/dcache.h | 1 + 2 files changed, 33 insertions(+) diff --git a/fs/dcache.c b/fs/dcache.c index 2593153471cf..6a7db8797b2d 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -1484,6 +1484,38 @@ void shrink_dcache_parent(struct dentry *parent) } EXPORT_SYMBOL(shrink_dcache_parent); +/** + * shrink_dcache_inode - prune dcache for inode + * @inode: inode to prune + * + * Evict all unused aliases of the specified inode from the dcache. This is + * intended to be used when trying to evict a specific inode, since inodes are + * pinned by their dentries. We also have to descend to ->d_subdirs for each + * alias, since aliases may be pinned by negative child dentries. + */ +void shrink_dcache_inode(struct inode *inode) +{ + for (;;) { + struct select_data data; + struct dentry *dentry; + + INIT_LIST_HEAD(&data.dispose); + data.start = NULL; + data.found = 0; + + spin_lock(&inode->i_lock); + hlist_for_each_entry(dentry, &inode->i_dentry, d_u.d_alias) + d_walk(dentry, &data, select_collect); + spin_unlock(&inode->i_lock); + + if (!data.found) + break; + + shrink_dentry_list(&data.dispose); + cond_resched(); + } +} + static enum d_walk_ret umount_check(void *_data, struct dentry *dentry) { /* it has busy descendents; complain about those instead */ diff --git a/include/linux/dcache.h b/include/linux/dcache.h index ef4b70f64f33..c02dab98bc97 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -245,6 +245,7 @@ extern struct dentry * d_obtain_alias(struct inode *); extern struct dentry * d_obtain_root(struct inode *); extern void shrink_dcache_sb(struct super_block *); extern void shrink_dcache_parent(struct dentry *); +extern void shrink_dcache_inode(struct inode *); extern void shrink_dcache_for_umount(struct super_block *); extern void d_invalidate(struct dentry *);