From patchwork Tue Jul 3 17:06:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 938830 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=collabora.co.uk Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 41KrDT5FtDz9s1B for ; Wed, 4 Jul 2018 03:08:25 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934309AbeGCRIY (ORCPT ); Tue, 3 Jul 2018 13:08:24 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:33454 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934295AbeGCRIU (ORCPT ); Tue, 3 Jul 2018 13:08:20 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id B6D7A289317 From: Gabriel Krisman Bertazi To: tytso@mit.edu Cc: linux-ext4@vger.kernel.org, darrick.wong@oracle.com, kernel@collabora.com, Gabriel Krisman Bertazi Subject: [PATCH 19/20] vfs: Handle case-exact lookup in d_add_ci Date: Tue, 3 Jul 2018 13:06:59 -0400 Message-Id: <20180703170700.9306-20-krisman@collabora.co.uk> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180703170700.9306-1-krisman@collabora.co.uk> References: <20180703170700.9306-1-krisman@collabora.co.uk> Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This prevents a soft hang if called d_add_ci is called from the FS layer, when doing a CI search but the result dentry is the exact match. Signed-off-by: Gabriel Krisman Bertazi --- fs/dcache.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/fs/dcache.c b/fs/dcache.c index 0e8e5de3c48a..3b55023cca7e 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -2059,6 +2059,20 @@ struct dentry *d_obtain_root(struct inode *inode) } EXPORT_SYMBOL(d_obtain_root); +static inline bool d_same_name(const struct dentry *dentry, + const struct dentry *parent, + const struct qstr *name) +{ + if (likely(!(parent->d_flags & DCACHE_OP_COMPARE))) { + if (dentry->d_name.len != name->len) + return false; + return dentry_cmp(dentry, name->name, name->len) == 0; + } + return parent->d_op->d_compare(dentry, + dentry->d_name.len, dentry->d_name.name, + name) == 0; +} + /** * d_add_ci - lookup or allocate new dentry with case-exact name * @inode: the inode case-insensitive lookup has found @@ -2080,6 +2094,10 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode, { struct dentry *found, *res; + /* Trivial case: CI search is exact match. */ + if (d_same_name(dentry, dentry->d_parent, name)) + return d_splice_alias(inode, dentry); + /* * First check if a dentry matching the name already exists, * if not go ahead and create it now. @@ -2112,21 +2130,6 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode, } EXPORT_SYMBOL(d_add_ci); - -static inline bool d_same_name(const struct dentry *dentry, - const struct dentry *parent, - const struct qstr *name) -{ - if (likely(!(parent->d_flags & DCACHE_OP_COMPARE))) { - if (dentry->d_name.len != name->len) - return false; - return dentry_cmp(dentry, name->name, name->len) == 0; - } - return parent->d_op->d_compare(dentry, - dentry->d_name.len, dentry->d_name.name, - name) == 0; -} - /** * __d_lookup_rcu - search for a dentry (racy, store-free) * @parent: parent dentry