From patchwork Fri Apr 5 12:13:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13618989 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 1782ECD11C2 for ; Fri, 5 Apr 2024 12:14:16 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rsiST-0007zU-21; Fri, 05 Apr 2024 12:14:13 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rsiSS-0007zJ-4Z for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:12 +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=erfV+2bquqW2ghUXB/v5Jer+WV2RnO7WW/ShzCsRPLs=; b=ADEBltWVJWllsR7LdhNfqKLX3d vE2CMSFSmznGCwmWsp7jbp//J7adoY7wEB7huY3z9NWC6mcuj7VD+0jQCJ5o/YsaMMOyPUt1kuabQ KKQsxg3oM+8WTbbNTnu9hZpQ2GnggSOQH2Fjd7OekyilCcf8iGzCnvBXUL8pSTx7G+a0=; 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=erfV+2bquqW2ghUXB/v5Jer+WV2RnO7WW/ShzCsRPLs=; b=PTGaQ8uDdQ7+uzc2GzwjFjmokB uhyz8DhdNb2CGznBYxnSr/gOT5VGchvU3yVDJy83qSycOPVWom2iY74wTVftHVU3BWO2EMCOBAC00 dJJeU/1x/W72U0aZk0SaBmwJXzLBhR+3Rk4Wp49YQkJ+uxE3FpzJbZiRVbW+8Xu76KvM=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rsiSO-0004XA-4l for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:12 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712319242; bh=gbN6WCytjAJRP9c+PDqTpJtir5l3AWjdR5F57IOZYi0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qe48yiNoqz4un5MDzVC5HAmynuu5xRSV11zeGUesGXHR39WwGNygJd9kKnl/CIkfs pOSQWomidfJ/haIVfvd6Q3rmv4CycSZDCUpxpJC+Fhe19epQHLE5T6lyR7Kgmbddzc dnE+UvydhezdyhfQAFAebyinuPehuc8FpdS7C9iMllWNeLY/CprKfIUXrlngHYaMob 8VGXTKPOZdYRlZjtM3o4S9XpLxTuy6UBn/LRSXfm7L3fIap33gu6HVg6iZIzkv273O VC5eRQVbjYACFDXstUKiGnab1Kiwu+VVjhDqc9E0J4ieLq1bYJ82cAt3Cm1360tde/ b+N2XHdhuQMGg== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 5121F378212F; Fri, 5 Apr 2024 12:14:01 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Date: Fri, 5 Apr 2024 15:13:24 +0300 Message-Id: <20240405121332.689228-2-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rsiSO-0004XA-4l Subject: [f2fs-dev] [PATCH v16 1/9] ext4: Simplify the handling of cached insensitive names 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: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: krisman@suse.de, brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, ebiggers@kernel.org, viro@zeniv.linux.org.uk, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi Keeping it as qstr avoids the unnecessary conversion in ext4_match Signed-off-by: Gabriel Krisman Bertazi [eugen.hristev@collabora.com: port to 6.8-rc3] Signed-off-by: Eugen Hristev Reviewed-by: Eric Biggers --- fs/ext4/ext4.h | 2 +- fs/ext4/namei.c | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 8d126654019e..d7bc2062cf3f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2508,7 +2508,7 @@ struct ext4_filename { struct fscrypt_str crypto_buf; #endif #if IS_ENABLED(CONFIG_UNICODE) - struct fscrypt_str cf_name; + struct qstr cf_name; #endif }; diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 5e4f65c14dfb..b96983a4c185 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1445,7 +1445,8 @@ static int ext4_ci_compare(const struct inode *parent, const struct qstr *name, int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, struct ext4_filename *name) { - struct fscrypt_str *cf_name = &name->cf_name; + struct qstr *cf_name = &name->cf_name; + unsigned char *buf; struct dx_hash_info *hinfo = &name->hinfo; int len; @@ -1455,18 +1456,18 @@ int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, return 0; } - cf_name->name = kmalloc(EXT4_NAME_LEN, GFP_NOFS); - if (!cf_name->name) + buf = kmalloc(EXT4_NAME_LEN, GFP_NOFS); + if (!buf) return -ENOMEM; - len = utf8_casefold(dir->i_sb->s_encoding, - iname, cf_name->name, - EXT4_NAME_LEN); + len = utf8_casefold(dir->i_sb->s_encoding, iname, buf, EXT4_NAME_LEN); if (len <= 0) { - kfree(cf_name->name); - cf_name->name = NULL; + kfree(buf); + buf = NULL; } + cf_name->name = buf; cf_name->len = (unsigned) len; + if (!IS_ENCRYPTED(dir)) return 0; @@ -1503,8 +1504,6 @@ static bool ext4_match(struct inode *parent, if (IS_CASEFOLDED(parent) && (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { if (fname->cf_name.name) { - struct qstr cf = {.name = fname->cf_name.name, - .len = fname->cf_name.len}; if (IS_ENCRYPTED(parent)) { if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || fname->hinfo.minor_hash != @@ -1513,8 +1512,8 @@ static bool ext4_match(struct inode *parent, return false; } } - return !ext4_ci_compare(parent, &cf, de->name, - de->name_len, true); + return !ext4_ci_compare(parent, &fname->cf_name, + de->name, de->name_len, true); } return !ext4_ci_compare(parent, fname->usr_fname, de->name, de->name_len, false); From patchwork Fri Apr 5 12:13:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13618990 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 872EBCD1297 for ; Fri, 5 Apr 2024 12:14:18 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rsiSX-0005kP-Q0; Fri, 05 Apr 2024 12:14:18 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rsiSV-0005kG-9O for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:15 +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=wWooyawhqTUZk7HmSdAH5/5eWaSQil3bMdJX8giP/0g=; b=c0laeRk3d0prkjhN5fiv6wC1IS knRod8bbIAL2OE6a6JUF74a3KCiQabZNEbu7vpNMD1e0qcHrWbAbFZSyvS+oSrEBZEbwpoW6wDrrh AgHgvdxPCJ6m+vg2rGF/0zz0O9eax6Ay73oIMrYPdE9pfNKhEWeilyqTBCkRiqK2PicM=; 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=wWooyawhqTUZk7HmSdAH5/5eWaSQil3bMdJX8giP/0g=; b=B5nhKRAnWfKKITNkcLJPf/g6Oo Ov9lbMg0o0uioDkK9in0OJwMjzoVNNMfa0S1j/c3wKaWFnMeTmk+Bpw1LEvnwV/c8igNGcyTjrLFz XxToNo58WF2bzu74Ifnle08aAxSUZKx4IWW0vOR3zpklinw+PhOoMqmsLM9r/w3PiAng=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rsiSU-0004XZ-BZ for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712319243; bh=iIf4UZ9JI6uynWIZ1rettGGo6aQjNP/VRVMVUi0YrzY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=koisWkNiM1GbZWp0+UeURFnwnTbomze9gQgUZ+NR8BDRS4Eju6QfhGmwtzDwqgBvb 06kG4xAW0eLcZQAaGYLui809ITYkSnKngQHuTBQpizKDJXC0A0UzX24j0RmHp5tVEG qyhgnRc0Bx5EZz/4jbEIoE8/XJyZrdJwLuJuo0JOPob8hhW7nXQf57oyI/fdn37wLw 35JTpfhCkcZ07hejMSLwtt7LNhwl22cGvU9sMWr9a4oKJMbnotD8MbfSqF1a8THboN 5d4EH3Q/yf/4pVIIgKovNC/U+PAt8aYsZIRSVGxx3EcBemxV6rc7qWijupqfeszJWx 8uKh8VUyKV0mg== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 78CFE3782131; Fri, 5 Apr 2024 12:14:02 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Date: Fri, 5 Apr 2024 15:13:25 +0300 Message-Id: <20240405121332.689228-3-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rsiSU-0004XZ-BZ Subject: [f2fs-dev] [PATCH v16 2/9] f2fs: Simplify the handling of cached insensitive names 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: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: krisman@suse.de, brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, ebiggers@kernel.org, viro@zeniv.linux.org.uk, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi Keeping it as qstr avoids the unnecessary conversion in f2fs_match Signed-off-by: Gabriel Krisman Bertazi [eugen.hristev@collabora.com: port to 6.8-rc3 and minor changes] Signed-off-by: Eugen Hristev Reviewed-by: Eric Biggers --- fs/f2fs/dir.c | 53 ++++++++++++++++++++++++++-------------------- fs/f2fs/f2fs.h | 16 +++++++++++++- fs/f2fs/recovery.c | 9 +------- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index 02c9355176d3..bdf980e25adb 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -42,35 +42,49 @@ static unsigned int bucket_blocks(unsigned int level) return 4; } +#if IS_ENABLED(CONFIG_UNICODE) /* If @dir is casefolded, initialize @fname->cf_name from @fname->usr_fname. */ int f2fs_init_casefolded_name(const struct inode *dir, struct f2fs_filename *fname) { -#if IS_ENABLED(CONFIG_UNICODE) struct super_block *sb = dir->i_sb; + unsigned char *buf; + int len; if (IS_CASEFOLDED(dir) && !is_dot_dotdot(fname->usr_fname->name, fname->usr_fname->len)) { - fname->cf_name.name = f2fs_kmem_cache_alloc(f2fs_cf_name_slab, - GFP_NOFS, false, F2FS_SB(sb)); - if (!fname->cf_name.name) + buf = f2fs_kmem_cache_alloc(f2fs_cf_name_slab, + GFP_NOFS, false, F2FS_SB(sb)); + if (!buf) return -ENOMEM; - fname->cf_name.len = utf8_casefold(sb->s_encoding, - fname->usr_fname, - fname->cf_name.name, - F2FS_NAME_LEN); - if ((int)fname->cf_name.len <= 0) { - kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name); - fname->cf_name.name = NULL; + + len = utf8_casefold(sb->s_encoding, fname->usr_fname, + buf, F2FS_NAME_LEN); + if (len <= 0) { + kmem_cache_free(f2fs_cf_name_slab, buf); if (sb_has_strict_encoding(sb)) return -EINVAL; /* fall back to treating name as opaque byte sequence */ + return 0; } + fname->cf_name.name = buf; + fname->cf_name.len = len; } -#endif + return 0; } +void f2fs_free_casefolded_name(struct f2fs_filename *fname) +{ + unsigned char *buf = (unsigned char *)fname->cf_name.name; + + if (buf) { + kmem_cache_free(f2fs_cf_name_slab, buf); + fname->cf_name.name = NULL; + } +} +#endif /* CONFIG_UNICODE */ + static int __f2fs_setup_filename(const struct inode *dir, const struct fscrypt_name *crypt_name, struct f2fs_filename *fname) @@ -142,12 +156,7 @@ void f2fs_free_filename(struct f2fs_filename *fname) kfree(fname->crypto_buf.name); fname->crypto_buf.name = NULL; #endif -#if IS_ENABLED(CONFIG_UNICODE) - if (fname->cf_name.name) { - kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name); - fname->cf_name.name = NULL; - } -#endif + f2fs_free_casefolded_name(fname); } static unsigned long dir_block_index(unsigned int level, @@ -235,11 +244,9 @@ static inline int f2fs_match_name(const struct inode *dir, struct fscrypt_name f; #if IS_ENABLED(CONFIG_UNICODE) - if (fname->cf_name.name) { - struct qstr cf = FSTR_TO_QSTR(&fname->cf_name); - - return f2fs_match_ci_name(dir, &cf, de_name, de_name_len); - } + if (fname->cf_name.name) + return f2fs_match_ci_name(dir, &fname->cf_name, + de_name, de_name_len); #endif f.usr_fname = fname->usr_fname; f.disk_name = fname->disk_name; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index fced2b7652f4..119769240ffb 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -531,7 +531,7 @@ struct f2fs_filename { * internal operation where usr_fname is also NULL. In all these cases * we fall back to treating the name as an opaque byte sequence. */ - struct fscrypt_str cf_name; + struct qstr cf_name; #endif }; @@ -3533,8 +3533,22 @@ int f2fs_get_tmpfile(struct mnt_idmap *idmap, struct inode *dir, /* * dir.c */ +#if IS_ENABLED(CONFIG_UNICODE) int f2fs_init_casefolded_name(const struct inode *dir, struct f2fs_filename *fname); +void f2fs_free_casefolded_name(struct f2fs_filename *fname); +#else +static inline int f2fs_init_casefolded_name(const struct inode *dir, + struct f2fs_filename *fname) +{ + return 0; +} + +static inline void f2fs_free_casefolded_name(struct f2fs_filename *fname) +{ +} +#endif /* CONFIG_UNICODE */ + int f2fs_setup_filename(struct inode *dir, const struct qstr *iname, int lookup, struct f2fs_filename *fname); int f2fs_prepare_lookup(struct inode *dir, struct dentry *dentry, diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index e7bf15b8240a..00c396973c8a 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -46,10 +46,6 @@ static struct kmem_cache *fsync_entry_slab; -#if IS_ENABLED(CONFIG_UNICODE) -extern struct kmem_cache *f2fs_cf_name_slab; -#endif - bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi) { s64 nalloc = percpu_counter_sum_positive(&sbi->alloc_valid_block_count); @@ -153,11 +149,8 @@ static int init_recovered_filename(const struct inode *dir, if (err) return err; f2fs_hash_filename(dir, fname); -#if IS_ENABLED(CONFIG_UNICODE) /* Case-sensitive match is fine for recovery */ - kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name); - fname->cf_name.name = NULL; -#endif + f2fs_free_casefolded_name(fname); } else { f2fs_hash_filename(dir, fname); } From patchwork Fri Apr 5 12:13:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13618991 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 BF092CD11C2 for ; Fri, 5 Apr 2024 12:14:19 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rsiSY-0005dz-VM; Fri, 05 Apr 2024 12:14:19 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rsiSW-0005dq-GH for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:16 +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=X0Pozop3g4Bc5+gI7l5dBuVa4iK21ypzY/xlD92AcOI=; b=TQow2k7lkc/3J/Fj/R5u+qWhmo sP5e61hNnrQKVi/x7S61C74PFMXrxWO9y5ouNohT/f/cVxXLMZY1RVCiFT+ENMLd9w1kYXB/RiEE5 MT4P0fruqz1TSIMuB41T7kZf9EXHe/kNQL+4Kv97LDNaayeAfIG1/GKEG0ao7WEfRX6M=; 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=X0Pozop3g4Bc5+gI7l5dBuVa4iK21ypzY/xlD92AcOI=; b=C99HYLscWbHHFLHHgokeTYZIpO +ztQHAwvhKaf0NyG6HeEIXcFBH9Mkf0IFhNkF0zCblsoWnp8QFHtaUTl7g5i+ua9cyw9ZCqqftD4d DX1Jn6fOOMAAQvEkRxFNwvA7FgEmt99v7zpzo1Y8FJMug3puU7aXhTn53y36PhxTsYS0=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rsiSV-0004Xd-GV for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712319244; bh=9qh1y4JVe985uO0lqk1EDdTzU0Or+8CTkIgpVaInUzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sDloi5iX1DUGvTXKzsVkv+J+RCTln+x7P0dAgAwiyBeeProuG+ZTeCHkwUO6FAfP4 BqpOucBmT8toIK7qN/4/sIcJOeCOKaCdIcRdLpiceOk1PVCI7SMFFPAnC79jXXplAk JiAyYmbrUYYxJRLO/+GhT92L1TGlsaPY0xQkQ+nqyBskpZa7+2GUsEnrxDx9C1EyKO KIH5n19RP4F65JKc7XciEpZW0gZErBGQZcUrKWvFaWPMU8vOQsFb6VfT+bdiw8nIYi BF2s5xYKCDf6zl1EwHtQBGsBVXl9TsPiPEKhMj54yQs75Jw15Xa4mzh7S0oc/EUz46 5rvTZpoHALzaQ== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id A7F8F3782132; Fri, 5 Apr 2024 12:14:03 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Date: Fri, 5 Apr 2024 15:13:26 +0300 Message-Id: <20240405121332.689228-4-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rsiSV-0004Xd-GV Subject: [f2fs-dev] [PATCH v16 3/9] libfs: Introduce case-insensitive string comparison helper 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: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: krisman@suse.de, brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, ebiggers@kernel.org, viro@zeniv.linux.org.uk, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi generic_ci_match can be used by case-insensitive filesystems to compare strings under lookup with dirents in a case-insensitive way. This function is currently reimplemented by each filesystem supporting casefolding, so this reduces code duplication in filesystem-specific code. Signed-off-by: Gabriel Krisman Bertazi [eugen.hristev@collabora.com: rework to first test the exact match] Signed-off-by: Eugen Hristev --- fs/libfs.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 4 +++ 2 files changed, 77 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 3a6f2cb364f8..88fcd19685a3 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1811,6 +1811,79 @@ static const struct dentry_operations generic_ci_dentry_ops = { .d_revalidate = fscrypt_d_revalidate, #endif }; + +/** + * generic_ci_match() - Match a name (case-insensitively) with a dirent. + * This is a filesystem helper for comparison with directory entries. + * generic_ci_d_compare should be used in VFS' ->d_compare instead. + * + * @parent: Inode of the parent of the dirent under comparison + * @name: name under lookup. + * @folded_name: Optional pre-folded name under lookup + * @de_name: Dirent name. + * @de_name_len: dirent name length. + * + * Test whether a case-insensitive directory entry matches the filename + * being searched. If @folded_name is provided, it is used instead of + * recalculating the casefold of @name. + * + * Return: > 0 if the directory entry matches, 0 if it doesn't match, or + * < 0 on error. + */ +int generic_ci_match(const struct inode *parent, + const struct qstr *name, + const struct qstr *folded_name, + const u8 *de_name, u32 de_name_len) +{ + const struct super_block *sb = parent->i_sb; + const struct unicode_map *um = sb->s_encoding; + struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); + struct qstr dirent = QSTR_INIT(de_name, de_name_len); + int res = 0; + + if (IS_ENCRYPTED(parent)) { + const struct fscrypt_str encrypted_name = + FSTR_INIT((u8 *) de_name, de_name_len); + + if (WARN_ON_ONCE(!fscrypt_has_encryption_key(parent))) + return -EINVAL; + + decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); + if (!decrypted_name.name) + return -ENOMEM; + res = fscrypt_fname_disk_to_usr(parent, 0, 0, &encrypted_name, + &decrypted_name); + if (res < 0) + goto out; + dirent.name = decrypted_name.name; + dirent.len = decrypted_name.len; + } + + /* + * Attempt a case-sensitive match first. It is cheaper and + * should cover most lookups, including all the sane + * applications that expect a case-sensitive filesystem. + */ + if (folded_name->name) { + if (dirent.len == folded_name->len && + !memcmp(folded_name->name, dirent.name, dirent.len)) + goto out; + res = utf8_strncasecmp_folded(um, folded_name, &dirent); + } else { + if (dirent.len == name->len && + !memcmp(name->name, dirent.name, dirent.len) && + (!sb_has_strict_encoding(sb) || !utf8_validate(um, name))) + goto out; + res = utf8_strncasecmp(um, name, &dirent); + } + +out: + kfree(decrypted_name.name); + if (res < 0 && sb_has_strict_encoding(sb)) + return res; + return !res; +} +EXPORT_SYMBOL(generic_ci_match); #endif #ifdef CONFIG_FS_ENCRYPTION diff --git a/include/linux/fs.h b/include/linux/fs.h index 883b72478f61..422488ed24cd 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3346,6 +3346,10 @@ extern int generic_file_fsync(struct file *, loff_t, loff_t, int); extern int generic_check_addressable(unsigned, u64); extern void generic_set_sb_d_ops(struct super_block *sb); +extern int generic_ci_match(const struct inode *parent, + const struct qstr *name, + const struct qstr *folded_name, + const u8 *de_name, u32 de_name_len); static inline bool sb_has_encoding(const struct super_block *sb) { From patchwork Fri Apr 5 12:13:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13618992 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 77186CD1299 for ; Fri, 5 Apr 2024 12:14: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.95) (envelope-from ) id 1rsiSa-0003yU-O0; Fri, 05 Apr 2024 12:14:21 +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.95) (envelope-from ) id 1rsiSX-0003yG-RC for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14: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=Vc7fqOC7SkJfepNzo44OucZ7wbHiHZxidGx82bq3P88=; b=DmLSVjrSXgrq+l0sOEf+oTz5m8 TvkKUeFKIsvMgXEV0C6IOR+rx5u5WIScrdFDipCY+ljEYCP7S98BVzFbwqCiLNGN79glaKB7LQa2S e70X8KHm5bU2nLWERoJVCNn7USXIU3irkosx3gxt4vE5hQ8AhHI2lTgLzD0rxYsnBWzk=; 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=Vc7fqOC7SkJfepNzo44OucZ7wbHiHZxidGx82bq3P88=; b=XDo1aSIcPf4I+1gacAXP02nO/g 3Htxx794Y6hOaU68mSgie7vIe3XfMUDyvA2udJ5edjBhmU5TXNgf9C7ZhJoYjgb0iGQxZq3DMCD62 8HNiS/0F6DutW5yNTBMrJ5mV8F3cXxC76j9np/3u4cgOnt9y0GK4iOkpFzvC9+EP/DJk=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rsiSW-0004Xh-Ji for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712319245; bh=swtZ6BKu+FGmiqRjglGL90hSAB3JlB+upSuAXL/TJpA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LeamS+SotQsJpfKSCnUeuxt8Br9jyLEZm/Oc4Fdf61ABZ3mc4VL304RbXIFEtCkeR JYxBeVgFsCJzLqMa5IqSF2ZK0MzIDm8C729n0aqoLmXu0rbmWIAkpTvoLx1CJBzbfx rda9j9UBrt5qJ+5WB3xuDfM+rTKK+mUxL/3B8JMaobZtTB/967CD9SuuWhzhqRQc/2 19AYHVTMDxFXo36IaWAuVEw4jiZohKW3c6dB/58mcM6ubmX1zy4HYwGefqWHR3ilaI BV0Qq5AyYQl/GsVKY0R5JcCKJCqrztVWK+nV0uYTvuH9WExXQSqoHb9ao14NzWBPDd Gkanvxpl+ny5Q== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id CD38E3782133; Fri, 5 Apr 2024 12:14:04 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Date: Fri, 5 Apr 2024 15:13:27 +0300 Message-Id: <20240405121332.689228-5-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rsiSW-0004Xh-Ji Subject: [f2fs-dev] [PATCH v16 4/9] ext4: Reuse generic_ci_match for ci comparisons 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: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: krisman@suse.de, brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, ebiggers@kernel.org, viro@zeniv.linux.org.uk, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi Instead of reimplementing ext4_match_ci, use the new libfs helper. It also adds a comment explaining why fname->cf_name.name must be checked prior to the encryption hash optimization, because that tripped me before. Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Eugen Hristev Reviewed-by: Eric Biggers --- fs/ext4/namei.c | 91 +++++++++++++++---------------------------------- 1 file changed, 27 insertions(+), 64 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index b96983a4c185..2d0ee232fbe7 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1390,58 +1390,6 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) } #if IS_ENABLED(CONFIG_UNICODE) -/* - * Test whether a case-insensitive directory entry matches the filename - * being searched for. If quick is set, assume the name being looked up - * is already in the casefolded form. - * - * Returns: 0 if the directory entry matches, more than 0 if it - * doesn't match or less than zero on error. - */ -static int ext4_ci_compare(const struct inode *parent, const struct qstr *name, - u8 *de_name, size_t de_name_len, bool quick) -{ - const struct super_block *sb = parent->i_sb; - const struct unicode_map *um = sb->s_encoding; - struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); - struct qstr entry = QSTR_INIT(de_name, de_name_len); - int ret; - - if (IS_ENCRYPTED(parent)) { - const struct fscrypt_str encrypted_name = - FSTR_INIT(de_name, de_name_len); - - decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); - if (!decrypted_name.name) - return -ENOMEM; - ret = fscrypt_fname_disk_to_usr(parent, 0, 0, &encrypted_name, - &decrypted_name); - if (ret < 0) - goto out; - entry.name = decrypted_name.name; - entry.len = decrypted_name.len; - } - - if (quick) - ret = utf8_strncasecmp_folded(um, name, &entry); - else - ret = utf8_strncasecmp(um, name, &entry); - if (ret < 0) { - /* Handle invalid character sequence as either an error - * or as an opaque byte sequence. - */ - if (sb_has_strict_encoding(sb)) - ret = -EINVAL; - else if (name->len != entry.len) - ret = 1; - else - ret = !!memcmp(name->name, entry.name, entry.len); - } -out: - kfree(decrypted_name.name); - return ret; -} - int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname, struct ext4_filename *name) { @@ -1503,20 +1451,35 @@ static bool ext4_match(struct inode *parent, #if IS_ENABLED(CONFIG_UNICODE) if (IS_CASEFOLDED(parent) && (!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) { - if (fname->cf_name.name) { - if (IS_ENCRYPTED(parent)) { - if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || - fname->hinfo.minor_hash != - EXT4_DIRENT_MINOR_HASH(de)) { + int ret; - return false; - } - } - return !ext4_ci_compare(parent, &fname->cf_name, - de->name, de->name_len, true); + /* + * Just checking IS_ENCRYPTED(parent) below is not + * sufficient to decide whether one can use the hash for + * skipping the string comparison, because the key might + * have been added right after + * ext4_fname_setup_ci_filename(). In this case, a hash + * mismatch will be a false negative. Therefore, make + * sure cf_name was properly initialized before + * considering the calculated hash. + */ + if (IS_ENCRYPTED(parent) && fname->cf_name.name && + (fname->hinfo.hash != EXT4_DIRENT_HASH(de) || + fname->hinfo.minor_hash != EXT4_DIRENT_MINOR_HASH(de))) + return false; + + ret = generic_ci_match(parent, fname->usr_fname, + &fname->cf_name, de->name, + de->name_len); + if (ret < 0) { + /* + * Treat comparison errors as not a match. The + * only case where it happens is on a disk + * corruption or ENOMEM. + */ + return false; } - return !ext4_ci_compare(parent, fname->usr_fname, de->name, - de->name_len, false); + return ret; } #endif From patchwork Fri Apr 5 12:13:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13618995 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 95FABCD1297 for ; Fri, 5 Apr 2024 12:14:26 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rsiSf-0005eY-GH; Fri, 05 Apr 2024 12:14:25 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rsiSd-0005eP-LG for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:23 +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=K93gzc0N8n6LEX9UE9DlTpvA2JW97rK3RKSkaKXsbrQ=; b=LkfBvtM9XaDVtNy1cLBOC5rR+v A7lr7EqRwQ6OJj5PH7ZR4RWdeefDnXdtkeETm2LtF159MoQey6H/zn8L1d4KDCtCH0FqPr8FqmtMz Bmfqz4uxn2NwdMnDiJevMLNzHlcjBF3XIsDRu7/P9NWYUQseG05P8S5i/FhlVC0drdw0=; 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=K93gzc0N8n6LEX9UE9DlTpvA2JW97rK3RKSkaKXsbrQ=; b=RoOlwRrhb8YYCiZEwIDNIgWeyA DiJuVcQVqUGCbizRTxptBvlxBWUh4h/6oYq8syKD8mP3zmmJeuY4DlNiuM3tsocKNDj+1yPXWIhmu 0J7SXkYnbcWbDXvPAEIN3/CfLeSuA0fapsIxyY4ziVdZnqJEIaBcirDg8KS/ZMI081Q8=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rsiSc-0004YS-MV for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712319246; bh=7yUG7UGRK7OExSJRvYKpT6PLYdclk+J33hviNbmb5mI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2ySpj2rLA7DYnONIZw4YUlfaBDtZwz0AxOKGhg5GwFbmISCNJ1TzLcGpfhQ+DYg1N L5PocgPil4uWENPLJ2aO/nZPateaq5QGe+/bf2fT3oV4ETthWMpsSyA6NuWSv5Rn/R QRWu9dXPE2/aDOr81v/fVjaot3BUrhG5EIjlP5TLggU6vrabTn55/Va98bBUdMbDmX tBt1V9FCSbEwcge+NPu/5DrlsnMB+h+3CrVFtP5WZLso0yOnYGP300+1Cw4OVtlsLi STgHUHF2MaSI8Asfl4RcJAG58gjFVZC3axxpFTmGgaK25p5bmjnLG4EZw612BFQI8l lRuQwahvB5JaA== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id E91BD3782130; Fri, 5 Apr 2024 12:14:05 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Date: Fri, 5 Apr 2024 15:13:28 +0300 Message-Id: <20240405121332.689228-6-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rsiSc-0004YS-MV Subject: [f2fs-dev] [PATCH v16 5/9] f2fs: Reuse generic_ci_match for ci comparisons 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: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: krisman@suse.de, brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, ebiggers@kernel.org, viro@zeniv.linux.org.uk, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi Now that ci_match is part of libfs, make f2fs reuse it instead of having a different implementation. Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Eugen Hristev Reviewed-by: Eric Biggers --- fs/f2fs/dir.c | 58 ++++----------------------------------------------- 1 file changed, 4 insertions(+), 54 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index bdf980e25adb..cbd7a5e96a37 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -185,58 +185,6 @@ static struct f2fs_dir_entry *find_in_block(struct inode *dir, return f2fs_find_target_dentry(&d, fname, max_slots); } -#if IS_ENABLED(CONFIG_UNICODE) -/* - * Test whether a case-insensitive directory entry matches the filename - * being searched for. - * - * Returns 1 for a match, 0 for no match, and -errno on an error. - */ -static int f2fs_match_ci_name(const struct inode *dir, const struct qstr *name, - const u8 *de_name, u32 de_name_len) -{ - const struct super_block *sb = dir->i_sb; - const struct unicode_map *um = sb->s_encoding; - struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); - struct qstr entry = QSTR_INIT(de_name, de_name_len); - int res; - - if (IS_ENCRYPTED(dir)) { - const struct fscrypt_str encrypted_name = - FSTR_INIT((u8 *)de_name, de_name_len); - - if (WARN_ON_ONCE(!fscrypt_has_encryption_key(dir))) - return -EINVAL; - - decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); - if (!decrypted_name.name) - return -ENOMEM; - res = fscrypt_fname_disk_to_usr(dir, 0, 0, &encrypted_name, - &decrypted_name); - if (res < 0) - goto out; - entry.name = decrypted_name.name; - entry.len = decrypted_name.len; - } - - res = utf8_strncasecmp_folded(um, name, &entry); - /* - * In strict mode, ignore invalid names. In non-strict mode, - * fall back to treating them as opaque byte sequences. - */ - if (res < 0 && !sb_has_strict_encoding(sb)) { - res = name->len == entry.len && - memcmp(name->name, entry.name, name->len) == 0; - } else { - /* utf8_strncasecmp_folded returns 0 on match */ - res = (res == 0); - } -out: - kfree(decrypted_name.name); - return res; -} -#endif /* CONFIG_UNICODE */ - static inline int f2fs_match_name(const struct inode *dir, const struct f2fs_filename *fname, const u8 *de_name, u32 de_name_len) @@ -245,8 +193,10 @@ static inline int f2fs_match_name(const struct inode *dir, #if IS_ENABLED(CONFIG_UNICODE) if (fname->cf_name.name) - return f2fs_match_ci_name(dir, &fname->cf_name, - de_name, de_name_len); + return generic_ci_match(dir, fname->usr_fname, + &fname->cf_name, + de_name, de_name_len); + #endif f.usr_fname = fname->usr_fname; f.disk_name = fname->disk_name; From patchwork Fri Apr 5 12:13:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13618993 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 B07F7C67861 for ; Fri, 5 Apr 2024 12:14:22 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rsiSb-00080i-KI; Fri, 05 Apr 2024 12:14:22 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rsiSX-00080D-Ul for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14: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=ih2S6pyJj+FNOX2FaVqCPxiJGRm/mQyzBzMM/MkTjGU=; b=RaHLEwSL8oBDZyP2q4jlrJgWlP WrzrZI2Yig3zSK24q9fpGIwU2DLT4yoDfeJLOWDWcPPP0q5DkXTeF/6qEJAFNir7tsbmNriW3VkK/ MoYKWqST4YcOmDEmbX8+LcTApegdTtgeGdTS9JtEGNqhraqSFLW/bKt4M34Th/ZfkJeA=; 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=ih2S6pyJj+FNOX2FaVqCPxiJGRm/mQyzBzMM/MkTjGU=; b=PRR8gdse8rsQZ6V3v1bmCMagws PljRvr1rVM1G56ejj1oE9/8vFy7XOooeyQEhOVs5A1lgXkAzXrHczGZixEAEgTeh85zdECMEazxCT kX7UnrwbjYZVutqAkPXGB51cUthuGC44Wu9Z0/RjKqlUHWfhkZ8rsaJ99zrk1cQEUwYY=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rsiSX-0004Xm-LA for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712319248; bh=3qqbmy6OIcOoO07cO28FmCqjE206p+74Pkl9CCe0L8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TKDOJxOER7MirF21hVhlJQygRmK3/cJqX67xIv56OiHAy+8ouFLN8Y6MoZIeZQr5U gKEX2b9K15sZy9+GBZ5VAAd6GKpxvEtgt1iY8IO47IB2Gze+5MDekZvgpveB2GyG6x LNGantlVyvkzvkODN1PXwCuEDdlHax/3eCJLn5OT2wVHpWe16Af4a9/Pjgistv+my2 L99lBBpVAW/4p4xOhSqzNSEuA9P9vS/m2fnRgFtI5a8OBNhBOQPz8DCeITHkwotFTs TUOc9wHNQNQY7H1FvAo3RaxedEuZxNziGZH5t4GHqnaZMGt2KjAK7ynt+aT8NiIv1O 3evyYq2Hw6Q9w== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 289F53782134; Fri, 5 Apr 2024 12:14:07 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Date: Fri, 5 Apr 2024 15:13:29 +0300 Message-Id: <20240405121332.689228-7-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rsiSX-0004Xm-LA Subject: [f2fs-dev] [PATCH v16 6/9] ext4: Log error when lookup of encoded dentry fails 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: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: krisman@suse.de, brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, ebiggers@kernel.org, viro@zeniv.linux.org.uk, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi If the volume is in strict mode, ext4_ci_compare can report a broken encoding name. This will not trigger on a bad lookup, which is caught earlier, only if the actual disk name is bad. Signed-off-by: Gabriel Krisman Bertazi Signed-off-by: Eugen Hristev Reviewed-by: Eric Biggers --- fs/ext4/namei.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 2d0ee232fbe7..3268cf45d9db 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1477,6 +1477,9 @@ static bool ext4_match(struct inode *parent, * only case where it happens is on a disk * corruption or ENOMEM. */ + if (ret == -EINVAL) + EXT4_ERROR_INODE(parent, + "Directory contains filename that is invalid UTF-8"); return false; } return ret; From patchwork Fri Apr 5 12:13:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13618996 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 01DEACD11C2 for ; Fri, 5 Apr 2024 12:14:27 +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.95) (envelope-from ) id 1rsiSh-0003zH-2J; Fri, 05 Apr 2024 12:14:27 +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.95) (envelope-from ) id 1rsiSe-0003yx-IY for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:24 +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=8sbsv28mkc9rYVRw1VmvFfYk6iGtJsLkjAf38gOsMhQ=; b=Mjs6gfQZrX4sGmxkm7tqUMdTCp dSAsmUWz6RT+/ZEdxA6STIItH7XHA1jANAbqySC+HMFIjxZYysyv1D0Ch+V3VTMQ5m8CLjk3wtFCN 2eF7qCHoJOu1EsUSR5pK+39OORDT57eNRXbgcwHrePzSI1VFNDyiNUguTPgfsztAZ+yA=; 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=8sbsv28mkc9rYVRw1VmvFfYk6iGtJsLkjAf38gOsMhQ=; b=DZcAH2c2lrd61KrAPup9vzVzgh uSssS/JcBmLycLC0JbZFqBdP3viV2AT8L3YvUUE4VUiXZDKiw/fxGDVFS3GwfLNzjEo3kkBtP3TkQ kCLXW6hEpyG9M1lrQ4wwmojHqfqMhi9VS/2AzJ5HHaU0f3D+MTbyb9DU2EmDHxRHiBgY=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rsiSd-0004YX-Rw for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712319249; bh=Yqu0eGYoz7+oBoYtg2t/IEEnKe5iA2fOw8gbynJ9Ihs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=df8xZznrABuMa8M76D/XsfV8axeXxvQxOkVf47zrMlcghtQDKi7QspHB/bIuP4gao l/2+hvqJdnjEEoG3F2mILMO2cusG1vFGc4ViArSz/Vf1jtvzB5eVUV9uLymYvLONza eSm6fbscy8EdR9KmWLUqeT76t/WcZ1AiahVLRU81iX5Zll6A5QsAT2QhupFby26xYU 3DgfXtyfCDBNHeA2UArVpEv8OTo5/4/xgpfOoAh13wtwWoR6t6kzF2WJsaPI3DbeQ8 bVtuPaXwjW56g7kS9VRALJkS6F1sCQZQgExEwupzhfU0Wsco8l3/DZlBs2qtNQwLbp k3lrTGi18YKTQ== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 4558B3782135; Fri, 5 Apr 2024 12:14:08 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Date: Fri, 5 Apr 2024 15:13:30 +0300 Message-Id: <20240405121332.689228-8-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rsiSd-0004YX-Rw Subject: [f2fs-dev] [PATCH v16 7/9] f2fs: Log error when lookup of encoded dentry fails 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: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: krisman@suse.de, brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, ebiggers@kernel.org, viro@zeniv.linux.org.uk, kernel@collabora.com Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net If the volume is in strict mode, generi c_ci_compare can report a broken encoding name. This will not trigger on a bad lookup, which is caught earlier, only if the actual disk name is bad. Suggested-by: Gabriel Krisman Bertazi Signed-off-by: Eugen Hristev Reviewed-by: Eric Biggers --- fs/f2fs/dir.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index cbd7a5e96a37..376f705aa3f1 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -192,11 +192,16 @@ static inline int f2fs_match_name(const struct inode *dir, struct fscrypt_name f; #if IS_ENABLED(CONFIG_UNICODE) - if (fname->cf_name.name) - return generic_ci_match(dir, fname->usr_fname, - &fname->cf_name, - de_name, de_name_len); - + if (fname->cf_name.name) { + int ret = generic_ci_match(dir, fname->usr_fname, + &fname->cf_name, + de_name, de_name_len); + if (ret == -EINVAL) + f2fs_warn_ratelimited(F2FS_SB(dir->i_sb), + "Directory contains filename that is invalid UTF-8"); + + return ret; + } #endif f.usr_fname = fname->usr_fname; f.disk_name = fname->disk_name; From patchwork Fri Apr 5 12:13:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13618994 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 4395ACD11C2 for ; Fri, 5 Apr 2024 12:14:24 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rsiSd-0005kp-6Y; Fri, 05 Apr 2024 12:14:23 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rsiSZ-0005kd-Sc for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:20 +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=i6arQXS5D6NAHQy/xmT8CY+Fb6dFd8F7lb/LEAvTkEo=; b=BLuvrpP7Zot6AuXrz2JGvlslmn ukZPN8Q/2qcggRTIl0qUYB5JC27uO6HCRHT0tJYQJk/yP5Q9oTWuNec10f1txZ6wCkp8nXzBIsHgR /Iv1ZgfSySQAI6sYunEqcsYRawgozWP+ofp4ep0oemIPpmGziimsokGVpqVpEovQat7U=; 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=i6arQXS5D6NAHQy/xmT8CY+Fb6dFd8F7lb/LEAvTkEo=; b=gOzIIcGh04iLSu0AlxfKOFNCU8 W13wihH1VotnCDtN0gL+U5ju4GYioVj80RnPU4lPUZnoCr6R0dIkoMfxhfO3AnmyPlyNgvgrHkLIm JJ9LUZCQmeGWzpXw2Vo4vSaMqCo2w+o6ipAKKQQcrOitKUI/ZS1ICHXXHKwTcuMxA1yI=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rsiSY-0004Xu-SJ for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712319250; bh=ccx17Ku0eqXkXpZA5LWBJ39JjJz6lXAlgnt6Amdowfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s6eDFDp13bFYPQfbvk1d5Kd7W7zbAN/TBS9UYG5Tqp/vaJ9faYmpHo3+7jl55xV2U S9MaAMCVYmePQp4T6JlCgkA8i5hR3q034qRkpm0HI5TDumS2VkrlVbhPMuVV+YENN1 sqzhHcJgidhdaXi6CZK4HAb9dhI0+UVoFB+BPfAju7bfcKkRbLCY+a/XL8ktJPbJO3 owqnNQV1Bnjukf91t36jUFR08XwVnhWtHdZHpsSRhbJKi1TV9miduZU5JYpE2J7JIU 2ODvfg5ruD2jjbrAp6R2r1a5QuWXv7v/OdQP15lJ1PKW4uh+R6uvS0fVnXSObw8Jvj /7Lz+5GAnaEMw== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 4C9223782137; Fri, 5 Apr 2024 12:14:09 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Date: Fri, 5 Apr 2024 15:13:31 +0300 Message-Id: <20240405121332.689228-9-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rsiSY-0004Xu-SJ Subject: [f2fs-dev] [PATCH v16 8/9] ext4: Move CONFIG_UNICODE defguards into the code flow 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: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: krisman@suse.de, brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, ebiggers@kernel.org, viro@zeniv.linux.org.uk, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi Instead of a bunch of ifdefs, make the unicode built checks part of the code flow where possible, as requested by Torvalds. Signed-off-by: Gabriel Krisman Bertazi [eugen.hristev@collabora.com: port to 6.8-rc3] Signed-off-by: Eugen Hristev Reviewed-by: Eric Biggers --- fs/ext4/crypto.c | 10 ++-------- fs/ext4/ext4.h | 33 +++++++++++++++++++++------------ fs/ext4/namei.c | 14 +++++--------- fs/ext4/super.c | 4 +--- 4 files changed, 29 insertions(+), 32 deletions(-) diff --git a/fs/ext4/crypto.c b/fs/ext4/crypto.c index 7ae0b61258a7..0a056d97e640 100644 --- a/fs/ext4/crypto.c +++ b/fs/ext4/crypto.c @@ -31,11 +31,10 @@ int ext4_fname_setup_filename(struct inode *dir, const struct qstr *iname, ext4_fname_from_fscrypt_name(fname, &name); -#if IS_ENABLED(CONFIG_UNICODE) err = ext4_fname_setup_ci_filename(dir, iname, fname); if (err) ext4_fname_free_filename(fname); -#endif + return err; } @@ -51,11 +50,9 @@ int ext4_fname_prepare_lookup(struct inode *dir, struct dentry *dentry, ext4_fname_from_fscrypt_name(fname, &name); -#if IS_ENABLED(CONFIG_UNICODE) err = ext4_fname_setup_ci_filename(dir, &dentry->d_name, fname); if (err) ext4_fname_free_filename(fname); -#endif return err; } @@ -70,10 +67,7 @@ void ext4_fname_free_filename(struct ext4_filename *fname) fname->usr_fname = NULL; fname->disk_name.name = NULL; -#if IS_ENABLED(CONFIG_UNICODE) - kfree(fname->cf_name.name); - fname->cf_name.name = NULL; -#endif + ext4_fname_free_ci_filename(fname); } static bool uuid_is_zero(__u8 u[16]) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index d7bc2062cf3f..816fda388d5e 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2742,8 +2742,25 @@ ext4_fsblk_t ext4_inode_to_goal_block(struct inode *); #if IS_ENABLED(CONFIG_UNICODE) extern int ext4_fname_setup_ci_filename(struct inode *dir, - const struct qstr *iname, - struct ext4_filename *fname); + const struct qstr *iname, + struct ext4_filename *fname); + +static inline void ext4_fname_free_ci_filename(struct ext4_filename *fname) +{ + kfree(fname->cf_name.name); + fname->cf_name.name = NULL; +} +#else +static inline int ext4_fname_setup_ci_filename(struct inode *dir, + const struct qstr *iname, + struct ext4_filename *fname) +{ + return 0; +} + +static inline void ext4_fname_free_ci_filename(struct ext4_filename *fname) +{ +} #endif /* ext4 encryption related stuff goes here crypto.c */ @@ -2766,16 +2783,11 @@ static inline int ext4_fname_setup_filename(struct inode *dir, int lookup, struct ext4_filename *fname) { - int err = 0; fname->usr_fname = iname; fname->disk_name.name = (unsigned char *) iname->name; fname->disk_name.len = iname->len; -#if IS_ENABLED(CONFIG_UNICODE) - err = ext4_fname_setup_ci_filename(dir, iname, fname); -#endif - - return err; + return ext4_fname_setup_ci_filename(dir, iname, fname); } static inline int ext4_fname_prepare_lookup(struct inode *dir, @@ -2787,10 +2799,7 @@ static inline int ext4_fname_prepare_lookup(struct inode *dir, static inline void ext4_fname_free_filename(struct ext4_filename *fname) { -#if IS_ENABLED(CONFIG_UNICODE) - kfree(fname->cf_name.name); - fname->cf_name.name = NULL; -#endif + ext4_fname_free_ci_filename(fname); } static inline int ext4_ioctl_get_encryption_pwsalt(struct file *filp, diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 3268cf45d9db..a5d9e5b01015 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1834,8 +1834,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi } } -#if IS_ENABLED(CONFIG_UNICODE) - if (!inode && IS_CASEFOLDED(dir)) { + if (IS_ENABLED(CONFIG_UNICODE) && !inode && IS_CASEFOLDED(dir)) { /* Eventually we want to call d_add_ci(dentry, NULL) * for negative dentries in the encoding case as * well. For now, prevent the negative dentry @@ -1843,7 +1842,7 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, unsi */ return NULL; } -#endif + return d_splice_alias(inode, dentry); } @@ -3173,16 +3172,14 @@ static int ext4_rmdir(struct inode *dir, struct dentry *dentry) ext4_fc_track_unlink(handle, dentry); retval = ext4_mark_inode_dirty(handle, dir); -#if IS_ENABLED(CONFIG_UNICODE) /* VFS negative dentries are incompatible with Encoding and * Case-insensitiveness. Eventually we'll want avoid * invalidating the dentries here, alongside with returning the * negative dentries at ext4_lookup(), when it is better * supported by the VFS for the CI case. */ - if (IS_CASEFOLDED(dir)) + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) d_invalidate(dentry); -#endif end_rmdir: brelse(bh); @@ -3284,16 +3281,15 @@ static int ext4_unlink(struct inode *dir, struct dentry *dentry) goto out_trace; retval = __ext4_unlink(dir, &dentry->d_name, d_inode(dentry), dentry); -#if IS_ENABLED(CONFIG_UNICODE) + /* VFS negative dentries are incompatible with Encoding and * Case-insensitiveness. Eventually we'll want avoid * invalidating the dentries here, alongside with returning the * negative dentries at ext4_lookup(), when it is better * supported by the VFS for the CI case. */ - if (IS_CASEFOLDED(dir)) + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) d_invalidate(dentry); -#endif out_trace: trace_ext4_unlink_exit(dentry, retval); diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 3fce1b80c419..4e212f01b761 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -3604,14 +3604,12 @@ int ext4_feature_set_ok(struct super_block *sb, int readonly) return 0; } -#if !IS_ENABLED(CONFIG_UNICODE) - if (ext4_has_feature_casefold(sb)) { + if (!IS_ENABLED(CONFIG_UNICODE) && ext4_has_feature_casefold(sb)) { ext4_msg(sb, KERN_ERR, "Filesystem with casefold feature cannot be " "mounted without CONFIG_UNICODE"); return 0; } -#endif if (readonly) return 1; From patchwork Fri Apr 5 12:13:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eugen Hristev X-Patchwork-Id: 13618997 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 4DB66CD11C2 for ; Fri, 5 Apr 2024 12:14:31 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1rsiSk-00082V-7V; Fri, 05 Apr 2024 12:14:30 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rsiSh-00081q-4w for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:27 +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=/ezJxfGYemehzFQ474FDiSGDq/uXRTtZO0VJNVCWpxw=; b=lHqFHNbo0aelbxVP8Tw1oL7GvR tkPGTADLXEz3ARtq+CeQTPTB/Qai3DTeCFm4dfCq70Cvpoq2ZzqiKct3/2GDkRteHiDwjFY2QuQOF camh44eXbzvFWKK0Bl+3o0vv3/ahNW9IlI/Z/a9PwcqwurXY7gWZAPADE/l2zPO8JZjY=; 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=/ezJxfGYemehzFQ474FDiSGDq/uXRTtZO0VJNVCWpxw=; b=KBNqgboHPiYexaawOH5/f2Fsse QswJjHlt4iAMrR+OwGwnC7f49TwuvnZVoGGVAVQQzVejazR8K8Dnq0M3PiyvtJXlsyg4XTicfEKFH VI3qkIAqayT6bvPywAawfKPaLlopeYushYgq2PHTco4NnSD+MYyFTtqyayjs/kE7U7vU=; Received: from madrid.collaboradmins.com ([46.235.227.194]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1rsiSg-0004Yr-Mu for linux-f2fs-devel@lists.sourceforge.net; Fri, 05 Apr 2024 12:14:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1712319251; bh=HTiihURQJkrf1R4qMENE36JKmwiQmaMABNkIFCv6n/0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RP8DMOuO94eoZIWw6RKTZw6SpuWp8MEirLCUdsT0mTFbGpDmgn29daN+lX9nf4oot YFDbXUsyXlOo79bYQaMpYCeZrhO03i/NQCXdiDFeKE+LImUgeGfFOdU/9jJ4by2Oe1 umlQ6HOBrveDsnshQGBIbnWZOkIgVemKleji6S6FCulHUOKpc9hVp+CYfIniM6wtr+ k1xcaMCJmreKZBaL3dfGZHjEbR0kdCv31yc0tFDYKupyhAkvdlsKh6QI+a/SjGRSHy qU3MIbfvyJzjkYofy6DuR8WFWp//EktpWO/x3XdB+ytLrk84INDSx2AppZ9wlmojiJ /9kk7zBZEyCOg== Received: from eugen-station.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: ehristev) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 63B8E3782136; Fri, 5 Apr 2024 12:14:10 +0000 (UTC) To: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org Date: Fri, 5 Apr 2024 15:13:32 +0300 Message-Id: <20240405121332.689228-10-eugen.hristev@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240405121332.689228-1-eugen.hristev@collabora.com> References: <20240405121332.689228-1-eugen.hristev@collabora.com> MIME-Version: 1.0 X-Headers-End: 1rsiSg-0004Yr-Mu Subject: [f2fs-dev] [PATCH v16 9/9] f2fs: Move CONFIG_UNICODE defguards into the code flow 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: , X-Patchwork-Original-From: Eugen Hristev via Linux-f2fs-devel From: Eugen Hristev Reply-To: Eugen Hristev Cc: krisman@suse.de, brauner@kernel.org, jack@suse.cz, linux-kernel@vger.kernel.org, eugen.hristev@collabora.com, ebiggers@kernel.org, viro@zeniv.linux.org.uk, kernel@collabora.com, Gabriel Krisman Bertazi Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net From: Gabriel Krisman Bertazi Instead of a bunch of ifdefs, make the unicode built checks part of the code flow where possible, as requested by Torvalds. Signed-off-by: Gabriel Krisman Bertazi [eugen.hristev@collabora.com: port to 6.8-rc3] Signed-off-by: Eugen Hristev Reviewed-by: Eric Biggers --- fs/f2fs/namei.c | 10 ++++------ fs/f2fs/super.c | 8 ++++---- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index e54f8c08bda8..1ecde2b45e99 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -576,8 +576,7 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, goto out_iput; } out_splice: -#if IS_ENABLED(CONFIG_UNICODE) - if (!inode && IS_CASEFOLDED(dir)) { + if (IS_ENABLED(CONFIG_UNICODE) && !inode && IS_CASEFOLDED(dir)) { /* Eventually we want to call d_add_ci(dentry, NULL) * for negative dentries in the encoding case as * well. For now, prevent the negative dentry @@ -586,7 +585,7 @@ static struct dentry *f2fs_lookup(struct inode *dir, struct dentry *dentry, trace_f2fs_lookup_end(dir, dentry, ino, err); return NULL; } -#endif + new = d_splice_alias(inode, dentry); trace_f2fs_lookup_end(dir, !IS_ERR_OR_NULL(new) ? new : dentry, ino, IS_ERR(new) ? PTR_ERR(new) : err); @@ -639,16 +638,15 @@ static int f2fs_unlink(struct inode *dir, struct dentry *dentry) f2fs_delete_entry(de, page, dir, inode); f2fs_unlock_op(sbi); -#if IS_ENABLED(CONFIG_UNICODE) /* VFS negative dentries are incompatible with Encoding and * Case-insensitiveness. Eventually we'll want avoid * invalidating the dentries here, alongside with returning the * negative dentries at f2fs_lookup(), when it is better * supported by the VFS for the CI case. */ - if (IS_CASEFOLDED(dir)) + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) d_invalidate(dentry); -#endif + if (IS_DIRSYNC(dir)) f2fs_sync_fs(sbi->sb, 1); fail: diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index a4bc26dfdb1a..68f3639d9b52 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -311,7 +311,7 @@ struct kmem_cache *f2fs_cf_name_slab; static int __init f2fs_create_casefold_cache(void) { f2fs_cf_name_slab = f2fs_kmem_cache_create("f2fs_casefolded_name", - F2FS_NAME_LEN); + F2FS_NAME_LEN); return f2fs_cf_name_slab ? 0 : -ENOMEM; } @@ -1313,13 +1313,13 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount) return -EINVAL; } #endif -#if !IS_ENABLED(CONFIG_UNICODE) - if (f2fs_sb_has_casefold(sbi)) { + + if (!IS_ENABLED(CONFIG_UNICODE) && f2fs_sb_has_casefold(sbi)) { f2fs_err(sbi, "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); return -EINVAL; } -#endif + /* * The BLKZONED feature indicates that the drive was formatted with * zone alignment optimization. This is optional for host-aware