From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D4A2AC433F5 for ; Wed, 11 May 2022 19:32:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346903AbiEKTcR (ORCPT ); Wed, 11 May 2022 15:32:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346901AbiEKTcL (ORCPT ); Wed, 11 May 2022 15:32:11 -0400 Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2A7756FB3 for ; Wed, 11 May 2022 12:32:09 -0700 (PDT) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 8B01A1F42944 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1652297528; bh=jXSApmwKt9A12GLlMcHNXsKbIVOb7Ib9KkOyAmhLVhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P7I6UaRP59k2wRohMrSXqi4JaBIa0iRvfjVriIPJp2D/ZcHhH/QSMWUq+y0Nt6DeO bUNsV9WEzz6jhmdOI7oLJvCENJ2nsQm07OWcmI7yPHjbnNb7dlxdFRSpCZd05MHXYh IPCoWL4qqTVTJCnfAeLk/bGFxK0NM70s6tTNDMEZLtI34TCgCCLlWAythJTBFURLTb qHZLcQrshDWB7Euau/PVh1sGI/73EKokHwaMB9mcqPsXst1vlLVQqMFAByccKiYWjn VPy56mPHpA9RlOhDu8ga6Q9dmqI+AIOJEkn881JDF+tyj5KUWukkSaXrjdyskqFQEi 3WRogz1GCCktg== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org Cc: linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, ebiggers@kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com Subject: [PATCH v4 04/10] ext4: Implement ci comparison using unicode_name Date: Wed, 11 May 2022 15:31:40 -0400 Message-Id: <20220511193146.27526-5-krisman@collabora.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220511193146.27526-1-krisman@collabora.com> References: <20220511193146.27526-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org By using a new type here, we can hide most of the caching casefold logic from ext4. The condition in ext4_match is now quite redundant, but this is addressed in the next patch. This doesn't use ext4_filename to keep it generic, since the function will be moved to libfs to be shared with f2fs. Signed-off-by: Gabriel Krisman Bertazi -- Changes since v1: - Instead of (ab)using fscrypt_name, create a new type (ebiggers). --- fs/ext4/namei.c | 32 +++++++++++++++----------------- include/linux/fs.h | 5 +++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 84fdb23f09b8..5296ced2e43e 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1321,20 +1321,19 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) /** * ext4_match_ci() - Match (case-insensitive) a name with a dirent. * @parent: Inode of the parent of the dentry. - * @name: name under lookup. + * @uname: name under lookup. * @de_name: Dirent name. * @de_name_len: dirent name length. - * @quick: whether @name is already casefolded. * * Test whether a case-insensitive directory entry matches the filename - * being searched. If quick is set, the @name being looked up is - * already in the casefolded form. + * being searched. * * Return: > 0 if the directory entry matches, 0 if it doesn't match, or * < 0 on error. */ -static int ext4_match_ci(const struct inode *parent, const struct qstr *name, - u8 *de_name, size_t de_name_len, bool quick) +static int ext4_match_ci(const struct inode *parent, + const struct unicode_name *uname, + u8 *de_name, size_t de_name_len) { const struct super_block *sb = parent->i_sb; const struct unicode_map *um = sb->s_encoding; @@ -1357,10 +1356,10 @@ static int ext4_match_ci(const struct inode *parent, const struct qstr *name, entry.len = decrypted_name.len; } - if (quick) - ret = utf8_strncasecmp_folded(um, name, &entry); + if (uname->folded_name->name) + ret = utf8_strncasecmp_folded(um, uname->folded_name, &entry); else - ret = utf8_strncasecmp(um, name, &entry); + ret = utf8_strncasecmp(um, uname->usr_name, &entry); if (!ret) match = true; @@ -1370,8 +1369,8 @@ static int ext4_match_ci(const struct inode *parent, const struct qstr *name, * the names have invalid characters. */ ret = 0; - match = ((name->len == entry.len) && - !memcmp(name->name, entry.name, entry.len)); + match = ((uname->usr_name->len == entry.len) && + !memcmp(uname->usr_name->name, entry.name, entry.len)); } out: @@ -1441,6 +1440,10 @@ static bool ext4_match(struct inode *parent, #if IS_ENABLED(CONFIG_UNICODE) if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent) && (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { + struct unicode_name u = { + .folded_name = &fname->cf_name, + .usr_name = fname->usr_fname + }; int ret; if (fname->cf_name.name) { @@ -1452,14 +1455,9 @@ static bool ext4_match(struct inode *parent, return false; } } - - ret = ext4_match_ci(parent, &fname->cf_name, de->name, - de->name_len, true); - } else { - ret = ext4_match_ci(parent, fname->usr_fname, - de->name, de->name_len, false); } + ret = ext4_match_ci(parent, &u, de->name, de->name_len); if (ret < 0) { /* * Treat comparison errors as not a match. The diff --git a/include/linux/fs.h b/include/linux/fs.h index e2d892b201b0..3f76a18a5f40 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3358,6 +3358,11 @@ extern int generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_check_addressable(unsigned, u64); +struct unicode_name { + const struct qstr *folded_name; + const struct qstr *usr_name; +}; + extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); #ifdef CONFIG_MIGRATION -- 2.36.1 From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 855C6C43217 for ; Wed, 11 May 2022 19:32:21 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.94.2) (envelope-from ) id 1nos4J-0006ky-IE; Wed, 11 May 2022 19:32:20 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1nos4I-0006kp-3N for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 May 2022 19:32:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=LacDOvoeoXRfvDUEYmfFK0qYCLlxL0thUwTKrKQrqhw=; b=QKmpi3xGOxdZfzi2IsF9G1JuIf w3D4khAv22WKVic9Q3Z49WQYUCLaPVu4BJClN2Emjdr+xPcJCwFu4eE3dps/JpT825EVm4hbzo9kG 7a5V1x771XBlf+Cwu1cAgptx9qo06c6fmZBZsDS0otYVmNNTRtQ9dCt9jWSjfhOpPz3s=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=LacDOvoeoXRfvDUEYmfFK0qYCLlxL0thUwTKrKQrqhw=; b=P9g7E3HiZDVaQr8hqiikvPJQGg rNYa30Bq0OJg4sTkRzgyW1Bsi/huUoUo5+Bg7eyJmqllEf+ug3o0ZLkE/gzCoQKd5cQK7AsaPNj0J wXFMePHoZZk0sBuciNqgXH/Y9tp/YIrsI+TGCRMrljkbagVyKgtNZkn99FUvUe0wq8EU=; Received: from bhuna.collabora.co.uk ([46.235.227.227]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.94.2) id 1nos4H-0007Iz-Ka for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 May 2022 19:32:18 +0000 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 8B01A1F42944 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1652297528; bh=jXSApmwKt9A12GLlMcHNXsKbIVOb7Ib9KkOyAmhLVhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P7I6UaRP59k2wRohMrSXqi4JaBIa0iRvfjVriIPJp2D/ZcHhH/QSMWUq+y0Nt6DeO bUNsV9WEzz6jhmdOI7oLJvCENJ2nsQm07OWcmI7yPHjbnNb7dlxdFRSpCZd05MHXYh IPCoWL4qqTVTJCnfAeLk/bGFxK0NM70s6tTNDMEZLtI34TCgCCLlWAythJTBFURLTb qHZLcQrshDWB7Euau/PVh1sGI/73EKokHwaMB9mcqPsXst1vlLVQqMFAByccKiYWjn VPy56mPHpA9RlOhDu8ga6Q9dmqI+AIOJEkn881JDF+tyj5KUWukkSaXrjdyskqFQEi 3WRogz1GCCktg== From: Gabriel Krisman Bertazi To: tytso@mit.edu, adilger.kernel@dilger.ca, jaegeuk@kernel.org Date: Wed, 11 May 2022 15:31:40 -0400 Message-Id: <20220511193146.27526-5-krisman@collabora.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220511193146.27526-1-krisman@collabora.com> References: <20220511193146.27526-1-krisman@collabora.com> MIME-Version: 1.0 X-Headers-End: 1nos4H-0007Iz-Ka Subject: [f2fs-dev] [PATCH v4 04/10] ext4: Implement ci comparison using unicode_name X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ebiggers@kernel.org, linux-ext4@vger.kernel.org, Gabriel Krisman Bertazi , kernel@collabora.com, linux-f2fs-devel@lists.sourceforge.net Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net By using a new type here, we can hide most of the caching casefold logic from ext4. The condition in ext4_match is now quite redundant, but this is addressed in the next patch. This doesn't use ext4_filename to keep it generic, since the function will be moved to libfs to be shared with f2fs. Signed-off-by: Gabriel Krisman Bertazi -- Changes since v1: - Instead of (ab)using fscrypt_name, create a new type (ebiggers). --- fs/ext4/namei.c | 32 +++++++++++++++----------------- include/linux/fs.h | 5 +++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 84fdb23f09b8..5296ced2e43e 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1321,20 +1321,19 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) /** * ext4_match_ci() - Match (case-insensitive) a name with a dirent. * @parent: Inode of the parent of the dentry. - * @name: name under lookup. + * @uname: name under lookup. * @de_name: Dirent name. * @de_name_len: dirent name length. - * @quick: whether @name is already casefolded. * * Test whether a case-insensitive directory entry matches the filename - * being searched. If quick is set, the @name being looked up is - * already in the casefolded form. + * being searched. * * Return: > 0 if the directory entry matches, 0 if it doesn't match, or * < 0 on error. */ -static int ext4_match_ci(const struct inode *parent, const struct qstr *name, - u8 *de_name, size_t de_name_len, bool quick) +static int ext4_match_ci(const struct inode *parent, + const struct unicode_name *uname, + u8 *de_name, size_t de_name_len) { const struct super_block *sb = parent->i_sb; const struct unicode_map *um = sb->s_encoding; @@ -1357,10 +1356,10 @@ static int ext4_match_ci(const struct inode *parent, const struct qstr *name, entry.len = decrypted_name.len; } - if (quick) - ret = utf8_strncasecmp_folded(um, name, &entry); + if (uname->folded_name->name) + ret = utf8_strncasecmp_folded(um, uname->folded_name, &entry); else - ret = utf8_strncasecmp(um, name, &entry); + ret = utf8_strncasecmp(um, uname->usr_name, &entry); if (!ret) match = true; @@ -1370,8 +1369,8 @@ static int ext4_match_ci(const struct inode *parent, const struct qstr *name, * the names have invalid characters. */ ret = 0; - match = ((name->len == entry.len) && - !memcmp(name->name, entry.name, entry.len)); + match = ((uname->usr_name->len == entry.len) && + !memcmp(uname->usr_name->name, entry.name, entry.len)); } out: @@ -1441,6 +1440,10 @@ static bool ext4_match(struct inode *parent, #if IS_ENABLED(CONFIG_UNICODE) if (parent->i_sb->s_encoding && IS_CASEFOLDED(parent) && (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { + struct unicode_name u = { + .folded_name = &fname->cf_name, + .usr_name = fname->usr_fname + }; int ret; if (fname->cf_name.name) { @@ -1452,14 +1455,9 @@ static bool ext4_match(struct inode *parent, return false; } } - - ret = ext4_match_ci(parent, &fname->cf_name, de->name, - de->name_len, true); - } else { - ret = ext4_match_ci(parent, fname->usr_fname, - de->name, de->name_len, false); } + ret = ext4_match_ci(parent, &u, de->name, de->name_len); if (ret < 0) { /* * Treat comparison errors as not a match. The diff --git a/include/linux/fs.h b/include/linux/fs.h index e2d892b201b0..3f76a18a5f40 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3358,6 +3358,11 @@ extern int generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_check_addressable(unsigned, u64); +struct unicode_name { + const struct qstr *folded_name; + const struct qstr *usr_name; +}; + extern void generic_set_encrypted_ci_d_ops(struct dentry *dentry); #ifdef CONFIG_MIGRATION -- 2.36.1 _______________________________________________ Linux-f2fs-devel mailing list Linux-f2fs-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel