From patchwork Tue Jul 3 17:07:00 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: 938831 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 41KrDY1tdxz9s1B for ; Wed, 4 Jul 2018 03:08:29 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934311AbeGCRI1 (ORCPT ); Tue, 3 Jul 2018 13:08:27 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:33464 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934303AbeGCRIX (ORCPT ); Tue, 3 Jul 2018 13:08:23 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id A4345289318 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 20/20] ext4: Implement encoding-aware dcache hooks Date: Tue, 3 Jul 2018 13:07:00 -0400 Message-Id: <20180703170700.9306-21-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 d_revalidate to reject negative dentries is not needed, because we avoided adding those in the first place during lookup, similar to what xfs does. Signed-off-by: Gabriel Krisman Bertazi --- fs/ext4/dir.c | 30 ++++++++++++++++++++++++++++++ fs/ext4/ext4.h | 1 + fs/ext4/super.c | 4 ++++ 3 files changed, 35 insertions(+) diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c index e2902d394f1b..c520b9e94778 100644 --- a/fs/ext4/dir.c +++ b/fs/ext4/dir.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "ext4.h" #include "xattr.h" @@ -664,3 +665,32 @@ const struct file_operations ext4_dir_operations = { .open = ext4_dir_open, .release = ext4_release_dir, }; + +static int ext4_d_compare(const struct dentry *dentry, unsigned int len, + const char *str, const struct qstr *name) +{ + struct nls_table *charset = EXT4_SB(dentry->d_sb)->encoding; + size_t nlen = strlen(name->name); + + return nls_strncmp(charset, str, len, name->name, nlen); +} + +static int ext4_d_hash(const struct dentry *dentry, struct qstr *q) +{ + const struct nls_table *charset = EXT4_SB(dentry->d_sb)->encoding; + unsigned char norm[PATH_MAX]; + int len; + + len = nls_normalize(charset, q->name, q->len, norm, PATH_MAX); + if (len < 0) + return -EINVAL; + + q->hash = full_name_hash(dentry, norm, len); + + return 0; +} + +const struct dentry_operations ext4_dentry_ops = { + .d_hash = ext4_d_hash, + .d_compare = ext4_d_compare, +}; diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index fb0b70d6eb68..2a5c7712967f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2953,6 +2953,7 @@ static inline void ext4_unlock_group(struct super_block *sb, /* dir.c */ extern const struct file_operations ext4_dir_operations; +extern const struct dentry_operations ext4_dentry_ops; /* file.c */ extern const struct inode_operations ext4_file_inode_operations; diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 53db9b6c7e33..f292cc5bacda 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -4358,6 +4358,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) iput(root); goto failed_mount4; } + + if (sbi->encoding) + sb->s_d_op = &ext4_dentry_ops; + sb->s_root = d_make_root(root); if (!sb->s_root) { ext4_msg(sb, KERN_ERR, "get root dentry failed");