From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E6231990C1; Thu, 10 Oct 2024 19:41:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589270; cv=none; b=obKeoEvydOFxS5QPVJ9SqxXU+U8sf5lc/pn5nMX1Jx5cLKLI3URYS8z5kKmL+bUuA3mKlZ6cKGKEual7AUMBRoKFEBdqwenHI9vWx3COw/mH/jxk/bvLu0XFeJgYVEmCH8YLdfAAMDeIJW0yTtu4bmJWBG3J07EKZ+TYF7LY4KA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589270; c=relaxed/simple; bh=YtR4arEv93bAfUU5w6UvpS+A36oozAQtinGMoam9bT0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ter62YkgH65DeQqKooC9DRDH5mDxDr+aGqwJT7FvShAtCtc/aRtADtXoPkCz/4bUkgXhQME1k70IEnIBpDH8qZ/Jswm38dido8ft2cR+p0XD/haeW3r0ZxxtWST6IMJkMuKoVhhGwVY/S3A/sKoyadgzp3w1t4KIfZulV8BMrAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=X8S1N0Lp; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="X8S1N0Lp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=NLs7GtCp2W3Q9BJj11jchN0o8DALdgxfm9oDq7oy5Jo=; b=X8S1N0LpSdVrFfoMMTr4JRID9A usIaeMrHVxAVjFJBb2AK4GNiyTBV4x5SRhvlw9IFWSL4BXL20ibxP0wBPGsDMx8ZxbzWLLYawSzXl n865ySfXiZWFn5xpx0Ar4u6LKyEPTfxffuXC2tCDBUxJTBbNa9ejWANGB3DcMMT6zZDC1R/V1GkzY Yhf26hMFiDfuFRbx8qwJYVmOne6p7Fv3cf0Xd8m2C2mbdcIG+OUAJzxmupZco1LmN09TUemRbtxA3 s+efEWDmAHQISCeBmfL8AXqAgA6lCU0vtAJNAYwyQaQfyTibZKAXpE2UHnops8Ep0fxDa0w93804g ne7zyLFA==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz1y-007SHz-LR; Thu, 10 Oct 2024 21:41:02 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:36 -0300 Subject: [PATCH v6 01/10] libfs: Create the helper function generic_ci_validate_strict_name() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-1-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Gabriel Krisman Bertazi , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 Create a helper function for filesystems do the checks required for casefold directories and strict encoding. Suggested-by: Gabriel Krisman Bertazi Signed-off-by: Andr=C3=A9 Almeida --- Changes from v4: - Inline this function Changes from v2: - Moved function to libfs and adpated its name - Wrapped at 72 chars column - Decomposed the big if (...) to be more clear --- include/linux/fs.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/linux/fs.h b/include/linux/fs.h index 3559446279c152c70b7f1f3e0154f6e66a5aba33..9b232aee4cd6ad8dce64370db01= 11bd25d3fedfa 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -45,6 +45,7 @@ #include #include #include +#include =20 #include #include @@ -3456,6 +3457,50 @@ extern int generic_ci_match(const struct inode *pare= nt, const struct qstr *folded_name, const u8 *de_name, u32 de_name_len); =20 +#if IS_ENABLED(CONFIG_UNICODE) +/** + * generic_ci_validate_strict_name - Check if a given name is suitable + * for a directory + * + * This functions checks if the proposed filename is valid for the + * parent directory. That means that only valid UTF-8 filenames will be + * accepted for casefold directories from filesystems created with the + * strict encoding flag. That also means that any name will be + * accepted for directories that doesn't have casefold enabled, or + * aren't being strict with the encoding. + * + * @dir: inode of the directory where the new file will be created + * @name: name of the new file + * + * Return: + * * True if the filename is suitable for this directory. It can be + * true if a given name is not suitable for a strict encoding + * directory, but the directory being used isn't strict + * * False if the filename isn't suitable for this directory. This only + * happens when a directory is casefolded and the filesystem is strict + * about its encoding. + */ +static inline bool generic_ci_validate_strict_name(struct inode *dir, stru= ct qstr *name) +{ + if (!IS_CASEFOLDED(dir) || !sb_has_strict_encoding(dir->i_sb)) + return true; + + /* + * A casefold dir must have a encoding set, unless the filesystem + * is corrupted + */ + if (WARN_ON_ONCE(!dir->i_sb->s_encoding)) + return true; + + return utf8_validate(dir->i_sb->s_encoding, name); +} +#else +static inline bool generic_ci_validate_strict_name(struct inode *dir, stru= ct qstr *name) +{ + return true; +} +#endif + static inline bool sb_has_encoding(const struct super_block *sb) { #if IS_ENABLED(CONFIG_UNICODE) --=20 2.47.0 From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C00F1E379F; Thu, 10 Oct 2024 19:41:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589272; cv=none; b=h9DmgyVP1Tt+gG04RaBzhPU588IxZW/QouBcDOOQ9EwxRhY2jaT7VsfaIsnTI50M4PhNRYk7ohLAaI0KhPQg3FC0kGo/EX3aKj9SbLEPsq8c9f4sprVUvg670yjIyIo868vGEe4bVoVBJG+RA11a1hdYaY9U5HB6PehCqWTJgbc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589272; c=relaxed/simple; bh=3NOu1Q+Yns95EfGtXDCM6tiXYbYx0Sjfavo/kztUt8Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KQuXhgilZnAg5OU7QcBAKWcsvGHNptIASKML4cL+lz0QyN6lwwiGa92y+wtEstyPkDORlJ8zFFNIDGkSFth+DRkkOHHTknS1U32M411Dc/wfPXqNC8Mv9S5DbF2Yq4NSwT6aVxkzOwo2hM5v155XLBPM9o1yh0YSOA0grOTl0ug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=DWh5LAbu; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="DWh5LAbu" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=sdXGjKgs/rhRe8l19F01/brI44jeC/ablpb8vlTIOo4=; b=DWh5LAbuzvrFfI8q3pnduTIg0s RXIu8j3fHbDuSLBLGVQsUPFVBhbhX9XL5iBvP0PfwDrJpJFWYfbEJJVexYEcByIq/md6nNcVKO9VX lsEGXuYGUFtfvKdlEHpZGscyOON7IxJcGXhF17P3W5tmsZwb8RUgSusxruV+oi4LkGgHCkmPPbGO8 toQDAbyZixKMWnkXBYJx5F2P/77DtFxkskUlpuuhpUJ6NN3nDwuPfGlPeasXsW1TNA9yWA2wCscvs KypErmDLlSXacL7q+CPiTmQjQ2JHvTXQVrlp872EyvNHKj14nv+tAAmtcgWIgRvQHzjJaNWBDg/ci 07QFXuew==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz23-007SHz-7a; Thu, 10 Oct 2024 21:41:07 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:37 -0300 Subject: [PATCH v6 02/10] ext4: Use generic_ci_validate_strict_name helper Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-2-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, Gabriel Krisman Bertazi , =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 Use the helper function to check the requirements for casefold directories using strict encoding. Suggested-by: Gabriel Krisman Bertazi Signed-off-by: Andr=C3=A9 Almeida Acked-by: Theodore Ts'o Reviewed-by: Gabriel Krisman Bertazi --- Changes from v4: - Now we can drop the if IS_ENABLED() guard --- fs/ext4/namei.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 790db7eac6c2ad5e1790e363e4ac273162e35013..612ccbeb493b8d901c123221ef6= 573457193dd16 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2395,11 +2395,8 @@ static int ext4_add_entry(handle_t *handle, struct d= entry *dentry, if (fscrypt_is_nokey_name(dentry)) return -ENOKEY; =20 -#if IS_ENABLED(CONFIG_UNICODE) - if (sb_has_strict_encoding(sb) && IS_CASEFOLDED(dir) && - utf8_validate(sb->s_encoding, &dentry->d_name)) + if (!generic_ci_validate_strict_name(dir, &dentry->d_name)) return -EINVAL; -#endif =20 retval =3D ext4_fname_setup_filename(dir, &dentry->d_name, 0, &fname); if (retval) --=20 2.47.0 From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E83851E882B; Thu, 10 Oct 2024 19:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589276; cv=none; b=nNdYDBz45W8OKy3NR4u5S7N3LRMzlurhzVaGu8gYwY9LbpwAstJHipSWFWEXWhzVkeeMT1rXc+J0rUmKkMdvV13KSnVQhw8HM5YFTbW97rZdv4Xtkm4RnMP6zFIUhCLXvRl+2i0q/orqeio/pCrY6PE3orBfbYgaCP9kVhjhvf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589276; c=relaxed/simple; bh=D53nHasbAy5mgMYWiQL0gWKqem/rpPA58GRuUy/JWp4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=d8Ox/7yAkW6wbjOAWqXcPx6UiGWAQ/m3em51McZ16qBYd//Z7lfutnydcXP99Agc1LJQ34+ImB9zrq3xlga87kfuvMMnU8xHyKVRm4bDg7WhyZlwIyI6Ncih3yUWXb+rpAZaJs6Ne7pwnlKm1zfGE8ZRxcLBlaC4doJoBFLeB24= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=JscOpjLC; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="JscOpjLC" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=hhDlIiM2rMTHaWInpW6Q+AoMhFTJClxESMUDFdoVjOU=; b=JscOpjLCcDAbWr+y72BNgPbFuT YFffuCfFxjs6RPw7PX+MxgkAyxRSQEaucgc/5WtOLfUHuenuf4pgFNElvM3fOxGP1DFhqC35aoHCx Ov0V/eXe5I0g9YO7VY2It9HBYn85ZVn2LrOzoxgFLj19k5/yFH9Jl41GoX5ZJfrHRqEBtxv4pcMic 67rBjBCnMcnzYBK4rO48DMznqloTqrgwAV9KR1x0daA67b3mZiInkxDgCQ2ByNCNCoG+/J+KYQnpT og0jUep8IQm8/pzZ3bZ5nFan0FK46EBCtJo01dhQUaPwhfWdqEBHXzClxUvjp4yZYMR/dOAp3HLql toZs0oOw==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz27-007SHz-Q3; Thu, 10 Oct 2024 21:41:12 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:38 -0300 Subject: [PATCH v6 03/10] unicode: Export latest available UTF-8 version number Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-3-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Gabriel Krisman Bertazi X-Mailer: b4 0.14.2 Export latest available UTF-8 version number so filesystems can easily load the newest one. Signed-off-by: Andr=C3=A9 Almeida Acked-by: Gabriel Krisman Bertazi --- fs/unicode/utf8-selftest.c | 3 --- include/linux/unicode.h | 2 ++ 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/unicode/utf8-selftest.c b/fs/unicode/utf8-selftest.c index 600e15efe9edfdf6d04cecd162e84f1f5a59c5e1..5ddaf27b21a6543770917d5a837= e86e12eee0b81 100644 --- a/fs/unicode/utf8-selftest.c +++ b/fs/unicode/utf8-selftest.c @@ -17,9 +17,6 @@ static unsigned int failed_tests; static unsigned int total_tests; =20 -/* Tests will be based on this version. */ -#define UTF8_LATEST UNICODE_AGE(12, 1, 0) - #define _test(cond, func, line, fmt, ...) do { \ total_tests++; \ if (!cond) { \ diff --git a/include/linux/unicode.h b/include/linux/unicode.h index 4d39e6e11a950c76f78d775fd6f351296f3d7d53..0c0ab04e84ee80227f9390ad049= 8f21a7ab7d34b 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -16,6 +16,8 @@ struct utf8data_table; ((unsigned int)(MIN) << UNICODE_MIN_SHIFT) | \ ((unsigned int)(REV))) =20 +#define UTF8_LATEST UNICODE_AGE(12, 1, 0) + static inline u8 unicode_major(unsigned int age) { return (age >> UNICODE_MAJ_SHIFT) & 0xff; --=20 2.47.0 From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CC761E906F; Thu, 10 Oct 2024 19:41:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589281; cv=none; b=IODYEGXpOQg9kAE5+paOZX/JLrR6vdA1UnueFVwibFC0Vl431SII339kOtkh333QT6n7NwSce04dGEntE9hDw1TUGyQPjzg38SuPDfXD7sixHG8F7JtQOAxuaCJ1DLdYNjQmOsdM4hjEXaee5fCosQat9uae9SJL0jA78CIZ4TA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589281; c=relaxed/simple; bh=vl3JoB/DwEm8nWzjX2Krc1IOE1I7PuBEAMF2rU+Lsac=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DctDsdl6Ol89XjXpfOa3p6aCHYxA1sJKgvvytaOw9PyRJnQZPmOWZ480llLpDslNOYsRT7genIg5Q2ubBjPKqlwkZOYg6eS9jK7xDAmzgpGlgcNZHXKXNzicXHHrlqo3xaY12TqcpZozRd/qrQrb0JxeyUWgd32fVKWmLQYiDQU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=DAwZ5BTr; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="DAwZ5BTr" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=xvtpXgeaP5+3Qey4SeTiBPWN2JmcKdnKWOsB+lrnGJo=; b=DAwZ5BTrIxiW5InqyottPfBJ6H GOXT5VcX3s+KAchFmfi/4sOsDev0Nd6Wjml60PP2IP+OqHdXhJsk3obIdbu9VBk5Uo0ud+8+MVW4O qQecqteTmktYmhDBsFkHZqESd8rZ3wofZeMJTkXdN4AFjU95K4g3H7rz3YGMqRFj3W8PTPGMtkKHP N3Sr7D900/vDB9fM/xwTYhr32dyJiEBcmxx//4MIPAkAN2Dm5A1sT9lL4o0+NDjmbNT62tfUSJVvq kaj1lZQkAIhaY2L2XYTzy3A4uck3TW56R9Lu1Rpw+bmoUBUTy032CVfBydcIb0tO2eTES/dkAeyf/ VGG7orQQ==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz2C-007SHz-CH; Thu, 10 Oct 2024 21:41:16 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:39 -0300 Subject: [PATCH v6 04/10] unicode: Recreate utf8_parse_version() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-4-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Gabriel Krisman Bertazi X-Mailer: b4 0.14.2 All filesystems that currently support UTF-8 casefold can fetch the UTF-8 version from the filesystem metadata stored on disk. They can get the data stored and directly match it to a integer, so they can skip the string parsing step, which motivated the removal of this function in the first place. However, for tmpfs, the only way to tell the kernel which UTF-8 version we are about to use is via mount options, using a string. Re-introduce utf8_parse_version() to be used by tmpfs. This version differs from the original by skipping the intermediate step of copying the version string to an auxiliary string before calling match_token(). This versions calls match_token() in the argument string. The paramenters are simpler now as well. utf8_parse_version() was created by 9d53690f0d4 ("unicode: implement higher level API for string handling") and later removed by 49bd03cc7e9 ("unicode: pass a UNICODE_AGE() tripple to utf8_load"). Signed-off-by: Andr=C3=A9 Almeida Reviewed-by: Theodore Ts'o Reviewed-by: Gabriel Krisman Bertazi --- Changes from v3: - Return version on the return value, instead of returning version at function args. --- fs/unicode/utf8-core.c | 26 ++++++++++++++++++++++++++ include/linux/unicode.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/fs/unicode/utf8-core.c b/fs/unicode/utf8-core.c index 8395066341a437d0c20d6ab49b0a022eac7eec5c..7f7cb14e01ce8aa87d14dffdd76= 7f63a90cf11f7 100644 --- a/fs/unicode/utf8-core.c +++ b/fs/unicode/utf8-core.c @@ -214,3 +214,29 @@ void utf8_unload(struct unicode_map *um) } EXPORT_SYMBOL(utf8_unload); =20 +/** + * utf8_parse_version - Parse a UTF-8 version number from a string + * + * @version: input string + * + * Returns the parsed version on success, negative code on error + */ +int utf8_parse_version(char *version) +{ + substring_t args[3]; + unsigned int maj, min, rev; + static const struct match_token token[] =3D { + {1, "%d.%d.%d"}, + {0, NULL} + }; + + if (match_token(version, token, args) !=3D 1) + return -EINVAL; + + if (match_int(&args[0], &maj) || match_int(&args[1], &min) || + match_int(&args[2], &rev)) + return -EINVAL; + + return UNICODE_AGE(maj, min, rev); +} +EXPORT_SYMBOL(utf8_parse_version); diff --git a/include/linux/unicode.h b/include/linux/unicode.h index 0c0ab04e84ee80227f9390ad0498f21a7ab7d34b..5e6b212a2aedab7ebf436308333= 9f4c5e9b82f8f 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -78,4 +78,6 @@ int utf8_casefold_hash(const struct unicode_map *um, cons= t void *salt, struct unicode_map *utf8_load(unsigned int version); void utf8_unload(struct unicode_map *um); =20 +int utf8_parse_version(char *version); + #endif /* _LINUX_UNICODE_H */ --=20 2.47.0 From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CAE461EABC4; Thu, 10 Oct 2024 19:41:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589285; cv=none; b=bpO1jtWK5eaQkreJ2I53yTE8SP+Hs8P4LbKg8//D4g4qOrLAT86DpMFw8AxXBWa6IyLPfF/65xm7ROOzQfq3y8A5xZvhm04J9bb8h6RhAC1zvZd5efbNER43retHhtArYYHwj5SKxgS++GUs6YR3Hx2VbIqdRr0771s8VHakWLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589285; c=relaxed/simple; bh=KuSx5QNW+2mvSoBMyvWxQrxOHyeGg6GA3x70AgHni9I=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=oFe7DUdvPQ0pWwmmHHNgY1Pmh4N7QDjUKOVPqu4cmYPAmJwdL8uFSmgW6Wd1gLPnlbcBNRLMLbCNaT3+zct/mhrMMm40nANj/ZnNVpuwINYE3C2Bz/U2Bi6Wxp89QUg5b1hfAfDQ4MYoQbM0PrE+FZ+D2t/iD+KH0m6GQmioNE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=e/wI86TS; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="e/wI86TS" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=Yy1QkMBVz1rUhANkqZgd4aZpMCC+lFeHbVpyTkY8ZcE=; b=e/wI86TS/CqLCywlrfiwkp1WUs HM/n+0gxZKeHi6CUJE4brwibgsgjJv5gT74ZYWGrFkXmIbYetmTe+Pc4o0xdsLaAhndFe+gcNyVKK QiVos7aFwQEM+FSpqTj8Zw/DYljmlNx5FvTjoIHE2/I7FmHETd2nrohp+eDgPu3LlFycnJEd+xb9Y P8MLfHz15A6Enve05fWqu+ysOgEIA7H3fypmIMubJzoyA3rnyc6TVbrx/FT911lZmvvVViVyOW2cY y8+7EkHtdx05Gskguah8myRuScZEEYfuFa5XTIKIrBUZ+wzJvwHLIoV+SDzmC2ia5jTs5Brqcyot+ qlMLVCxw==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz2G-007SHz-Nk; Thu, 10 Oct 2024 21:41:20 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:40 -0300 Subject: [PATCH v6 05/10] libfs: Export generic_ci_ dentry functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-5-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 Export generic_ci_ dentry functions so they can be used by case-insensitive filesystems that need something more custom than the default one set by `struct generic_ci_dentry_ops`. Signed-off-by: Andr=C3=A9 Almeida --- Changes from v4: - Guard func signatures inside IS_ENABLED(CONFIG_UNICODE) Changes from v3: - New patch --- fs/libfs.c | 8 +++++--- include/linux/fs.h | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 46966fd8bcf9f042e85d0b66134e59fbef83abfd..7b290404c5f9901010ada2f921a= 214dbc94eb5fa 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1791,8 +1791,8 @@ bool is_empty_dir_inode(struct inode *inode) * * Return: 0 if names match, 1 if mismatch, or -ERRNO */ -static int generic_ci_d_compare(const struct dentry *dentry, unsigned int = len, - const char *str, const struct qstr *name) +int generic_ci_d_compare(const struct dentry *dentry, unsigned int len, + const char *str, const struct qstr *name) { const struct dentry *parent; const struct inode *dir; @@ -1835,6 +1835,7 @@ static int generic_ci_d_compare(const struct dentry *= dentry, unsigned int len, =20 return utf8_strncasecmp(dentry->d_sb->s_encoding, name, &qstr); } +EXPORT_SYMBOL(generic_ci_d_compare); =20 /** * generic_ci_d_hash - generic d_hash implementation for casefolding files= ystems @@ -1843,7 +1844,7 @@ static int generic_ci_d_compare(const struct dentry *= dentry, unsigned int len, * * Return: 0 if hash was successful or unchanged, and -EINVAL on error */ -static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) +int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str) { const struct inode *dir =3D READ_ONCE(dentry->d_inode); struct super_block *sb =3D dentry->d_sb; @@ -1858,6 +1859,7 @@ static int generic_ci_d_hash(const struct dentry *den= try, struct qstr *str) return -EINVAL; return 0; } +EXPORT_SYMBOL(generic_ci_d_hash); =20 static const struct dentry_operations generic_ci_dentry_ops =3D { .d_hash =3D generic_ci_d_hash, diff --git a/include/linux/fs.h b/include/linux/fs.h index 9b232aee4cd6ad8dce64370db0111bd25d3fedfa..21e183e5041ed029bf47fda018f= 44b20bcdd4389 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3458,6 +3458,10 @@ extern int generic_ci_match(const struct inode *pare= nt, const u8 *de_name, u32 de_name_len); =20 #if IS_ENABLED(CONFIG_UNICODE) +int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str); +int generic_ci_d_compare(const struct dentry *dentry, unsigned int len, + const char *str, const struct qstr *name); + /** * generic_ci_validate_strict_name - Check if a given name is suitable * for a directory --=20 2.47.0 From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B1C21EBA1C; Thu, 10 Oct 2024 19:41:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589289; cv=none; b=Tu3zlwyWYnbq2hrkhHQ4HfTvv6BmN7V3smrHuDhklJYf+dboAGjQ1cLMNLnoJrGyl91mPDsI23naM7AzZLdcatvaz0AJX9hqtCy5TnbnTSpKHoad2RDB3ogvBQECcDzKRLWQ6zRY+mSeITMElUouGxhygebB/+xB6fgkdfgq1c8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589289; c=relaxed/simple; bh=771opDvyFkQ0G0wfNGyjFY0zu6bFKT4oWurlBmF1RZk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=B7IKszNIz6jhibiDwwJDaw1J6203O8ZZ1e6WKFKWonl1UfxFFBfzbFPHszbfxBIPFQDq2MINFFoc7MwD/fCmvwZwQR9QomeMZlfOqiwAORwAkVFpZ7lpiDXiPZgdaPmfUElCmCd9NnE8Xg9sujGviDxW8GwKs+Xxqf+Tk947CSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=gdw40U8C; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="gdw40U8C" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=VzXfvIbzNG0CSJ+bJDRaQbQX3trBLicfbCXoWczurs8=; b=gdw40U8ClqfhBNEr1zvH72DVze ei/o8WrtCUhyyOBxKWaOESNuBIM15Dnar7hBW/4EIqTwb3xfHTvvKWmrM2jcJ07SSqrWCnGhcMuBx OmZnI/kmTHDgMBqxOIfkFRPIzYBe3ay0VysEQqATyKPnMrZZok+8Xz8bZU+BNhlmao9bUfyzRFnLP endEIXVlclO+Q7IRSMHMCELHso5NIZpycJLpRgV5mpZcA+dKJjSR034h4SHkPxDTO2djEpcuoHZ0R 4bktloCNris/aaWJCEljs72STAPAvtsHs8m9TCIEPvUEf2qdj3rvIqXVgF1iELs23iWDjQ14rgrGA sBZ9+Ctw==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz2L-007SHz-30; Thu, 10 Oct 2024 21:41:25 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:41 -0300 Subject: [PATCH v6 06/10] tmpfs: Always set simple_dentry_operations as dentry ops Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-6-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 Set simple_dentry_operations as the superblock dentry ops, so all tmpfs dentries can inherit it. Signed-off-by: Andr=C3=A9 Almeida --- mm/shmem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 4f11b55063631976af81e4221c7366b768db6690..162d68784309bdfb8772aa9ba3c= cc360780395fd 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -4662,6 +4662,8 @@ static int shmem_fill_super(struct super_block *sb, s= truct fs_context *fc) } sb->s_export_op =3D &shmem_export_ops; sb->s_flags |=3D SB_NOSEC | SB_I_VERSION; + + sb->s_d_op =3D &simple_dentry_operations; #else sb->s_flags |=3D SB_NOUSER; #endif --=20 2.47.0 From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A24ED1CFEA1; Thu, 10 Oct 2024 19:41:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589294; cv=none; b=uiHEDkesWdicHuvMbFuBFs7t5/Iui7z80molnRS+ygNDM/8SxzBoAJno/gwdhK2DDTlD0YZzRRoCvrJD15OgQd9FnOJYw7L+V3tM6ex8C6vZg/lEtLfbVFlxnpiqFi32R+T1tWGlNvOaa2b/+I2U4MH9LDKL+AW7qy5D0g2wqCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589294; c=relaxed/simple; bh=7pXL8LHCYcsxCKV3KTzPhhYBPQKOJZ85ua6LTenmvTM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LMSSJHTL3cLSu+u56G+YK0DcdpQgx9kOuKfPsqTYifPLLGZS068ZGQQmNKM+519UBUOa2GZduypyXReOj6w6qvbVJnGLN26jfiOpPpGR0BXtuBShzVZZtfPEUmwP/3PwIf3Ig2Vq39DV63lEb0hTmI60WaiHBfVJy9lvG+paNxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=gE5p1QiS; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="gE5p1QiS" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=XHdi9hQBqFVnhv7IC8o5GpggjJLpirJi3kfx0QcBzok=; b=gE5p1QiSfllJwSdRlI3HsbrVUd dtP0npquWm+YKdZfvs/6gWGWPskTAFQ0ggKlYH/6lq/Wmw/PQFwprLaLQUb9BmkeX2+dlJDVpcQnB wJISy6+Mp6uah+0j5yKvfVDEFFqfW7Kp5af+e7ihAxw7sLH5frwf1pEVByIb3C3jTxeDkYm+6NBPo +UtMCfWckcf+Y9QTYIY/tAFlWTz/34RtQWZGRQfCNzBN8Rj83qbenVje5NjDZo/w327yh+GXUYsLR VFvkutrJUSo6HOh5NfvCXk46jwOVvfH3fOrIWvCzDAmCQ6AW1azHAPTUha3yKGhj0FlA7UlxAg+hP /J3MwBZQ==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz2P-007SHz-ER; Thu, 10 Oct 2024 21:41:29 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:42 -0300 Subject: [PATCH v6 07/10] tmpfs: Add casefold lookup support Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-7-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= X-Mailer: b4 0.14.2 Enable casefold lookup in tmpfs, based on the encoding defined by userspace. That means that instead of comparing byte per byte a file name, it compares to a case-insensitive equivalent of the Unicode string. * Dcache handling There's a special need when dealing with case-insensitive dentries. First of all, we currently invalidated every negative casefold dentries. That happens because currently VFS code has no proper support to deal with that, giving that it could incorrectly reuse a previous filename for a new file that has a casefold match. For instance, this could happen: $ mkdir DIR $ rm -r DIR $ mkdir dir $ ls DIR/ And would be perceived as inconsistency from userspace point of view, because even that we match files in a case-insensitive manner, we still honor whatever is the initial filename. Along with that, tmpfs stores only the first equivalent name dentry used in the dcache, preventing duplications of dentries in the dcache. The d_compare() version for casefold files uses a normalized string, so the filename under lookup will be compared to another normalized string for the existing file, achieving a casefolded lookup. * Enabling casefold via mount options Most filesystems have their data stored in disk, so casefold option need to be enabled when building a filesystem on a device (via mkfs). However, as tmpfs is a RAM backed filesystem, there's no disk information and thus no mkfs to store information about casefold. For tmpfs, create casefold options for mounting. Userspace can then enable casefold support for a mount point using: $ mount -t tmpfs -o casefold=3Dutf8-12.1.0 fs_name mount_dir/ Userspace must set what Unicode standard is aiming to. The available options depends on what the kernel Unicode subsystem supports. And for strict encoding: $ mount -t tmpfs -o casefold=3Dutf8-12.1.0,strict_encoding fs_name mount_di= r/ Strict encoding means that tmpfs will refuse to create invalid UTF-8 sequences. When this option is not enabled, any invalid sequence will be treated as an opaque byte sequence, ignoring the encoding thus not being able to be looked up in a case-insensitive way. * Check for casefold dirs on simple_lookup() On simple_lookup(), do not create dentries for casefold directories. Currently, VFS does not support case-insensitive negative dentries and can create inconsistencies in the filesystem. Prevent such dentries to being created in the first place. Signed-off-by: Andr=C3=A9 Almeida Reviewed-by: Gabriel Krisman Bertazi --- Changes from v4: - Squash commit Check for casefold dirs on simple_lookup() here - Fails to mount if strict_encoding is used without encoding - tmpfs doesn't support fscrypt, so I dropped d_revalidate line Changes from v3: - Simplified shmem_parse_opt_casefold() - sb->s_d_op is set to shmem_ci_dentry_ops during mount time - got rid of shmem_lookup(), modified simple_lookup() Changes from v2: - simple_lookup() now sets d_ops - reworked shmem_parse_opt_casefold() - if `mount -o casefold` has no param, load latest UTF-8 version - using (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir) when possible --- fs/libfs.c | 4 +++ mm/shmem.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +--- 2 files changed, 118 insertions(+), 5 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 7b290404c5f9901010ada2f921a214dbc94eb5fa..a168ece5cc61b74114f537f5b7b= 8a07f2d48b2aa 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -77,6 +77,10 @@ struct dentry *simple_lookup(struct inode *dir, struct d= entry *dentry, unsigned return ERR_PTR(-ENAMETOOLONG); if (!dentry->d_sb->s_d_op) d_set_d_op(dentry, &simple_dentry_operations); + + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + return NULL; + d_add(dentry, NULL); return NULL; } diff --git a/mm/shmem.c b/mm/shmem.c index 162d68784309bdfb8772aa9ba3ccc360780395fd..935e824990799d927098fd88eba= ba384a6284f42 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "swap.h" =20 static struct vfsmount *shm_mnt __ro_after_init; @@ -123,6 +124,8 @@ struct shmem_options { bool noswap; unsigned short quota_types; struct shmem_quota_limits qlimits; + struct unicode_map *encoding; + bool strict_encoding; #define SHMEM_SEEN_BLOCKS 1 #define SHMEM_SEEN_INODES 2 #define SHMEM_SEEN_HUGE 4 @@ -3574,6 +3577,9 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *di= r, if (IS_ERR(inode)) return PTR_ERR(inode); =20 + if (!generic_ci_validate_strict_name(dir, &dentry->d_name)) + return -EINVAL; + error =3D simple_acl_create(dir, inode); if (error) goto out_iput; @@ -3589,7 +3595,12 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *d= ir, dir->i_size +=3D BOGO_DIRENT_SIZE; inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); inode_inc_iversion(dir); - d_instantiate(dentry, inode); + + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + d_add(dentry, inode); + else + d_instantiate(dentry, inode); + dget(dentry); /* Extra count - pin the dentry in core */ return error; =20 @@ -3680,7 +3691,10 @@ static int shmem_link(struct dentry *old_dentry, str= uct inode *dir, inc_nlink(inode); ihold(inode); /* New dentry reference */ dget(dentry); /* Extra pinning count for the created dentry */ - d_instantiate(dentry, inode); + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + d_add(dentry, inode); + else + d_instantiate(dentry, inode); out: return ret; } @@ -3700,6 +3714,14 @@ static int shmem_unlink(struct inode *dir, struct de= ntry *dentry) inode_inc_iversion(dir); drop_nlink(inode); dput(dentry); /* Undo the count from "create" - does all the work */ + + /* + * For now, VFS can't deal with case-insensitive negative dentries, so + * we invalidate them + */ + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + d_invalidate(dentry); + return 0; } =20 @@ -3844,7 +3866,10 @@ static int shmem_symlink(struct mnt_idmap *idmap, st= ruct inode *dir, dir->i_size +=3D BOGO_DIRENT_SIZE; inode_set_mtime_to_ts(dir, inode_set_ctime_current(dir)); inode_inc_iversion(dir); - d_instantiate(dentry, inode); + if (IS_ENABLED(CONFIG_UNICODE) && IS_CASEFOLDED(dir)) + d_add(dentry, inode); + else + d_instantiate(dentry, inode); dget(dentry); return 0; =20 @@ -4197,6 +4222,9 @@ enum shmem_param { Opt_usrquota_inode_hardlimit, Opt_grpquota_block_hardlimit, Opt_grpquota_inode_hardlimit, + Opt_casefold_version, + Opt_casefold, + Opt_strict_encoding, }; =20 static const struct constant_table shmem_param_enums_huge[] =3D { @@ -4228,9 +4256,54 @@ const struct fs_parameter_spec shmem_fs_parameters[]= =3D { fsparam_string("grpquota_block_hardlimit", Opt_grpquota_block_hardlimit), fsparam_string("grpquota_inode_hardlimit", Opt_grpquota_inode_hardlimit), #endif + fsparam_string("casefold", Opt_casefold_version), + fsparam_flag ("casefold", Opt_casefold), + fsparam_flag ("strict_encoding", Opt_strict_encoding), {} }; =20 +#if IS_ENABLED(CONFIG_UNICODE) +static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_param= eter *param, + bool latest_version) +{ + struct shmem_options *ctx =3D fc->fs_private; + unsigned int version =3D UTF8_LATEST; + struct unicode_map *encoding; + char *version_str =3D param->string + 5; + + if (!latest_version) { + if (strncmp(param->string, "utf8-", 5)) + return invalfc(fc, "Only UTF-8 encodings are supported " + "in the format: utf8-"); + + version =3D utf8_parse_version(version_str); + if (version < 0) + return invalfc(fc, "Invalid UTF-8 version: %s", version_str); + } + + encoding =3D utf8_load(version); + + if (IS_ERR(encoding)) { + return invalfc(fc, "Failed loading UTF-8 version: utf8-%u.%u.%u\n", + unicode_major(version), unicode_minor(version), + unicode_rev(version)); + } + + pr_info("tmpfs: Using encoding : utf8-%u.%u.%u\n", + unicode_major(version), unicode_minor(version), unicode_rev(version)); + + ctx->encoding =3D encoding; + + return 0; +} +#else +static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_param= eter *param, + bool latest_version) +{ + return invalfc(fc, "tmpfs: Kernel not built with CONFIG_UNICODE\n"); +} +#endif + static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *par= am) { struct shmem_options *ctx =3D fc->fs_private; @@ -4389,6 +4462,13 @@ static int shmem_parse_one(struct fs_context *fc, st= ruct fs_parameter *param) "Group quota inode hardlimit too large."); ctx->qlimits.grpquota_ihardlimit =3D size; break; + case Opt_casefold_version: + return shmem_parse_opt_casefold(fc, param, false); + case Opt_casefold: + return shmem_parse_opt_casefold(fc, param, true); + case Opt_strict_encoding: + ctx->strict_encoding =3D true; + break; } return 0; =20 @@ -4618,6 +4698,11 @@ static void shmem_put_super(struct super_block *sb) { struct shmem_sb_info *sbinfo =3D SHMEM_SB(sb); =20 +#if IS_ENABLED(CONFIG_UNICODE) + if (sb->s_encoding) + utf8_unload(sb->s_encoding); +#endif + #ifdef CONFIG_TMPFS_QUOTA shmem_disable_quotas(sb); #endif @@ -4628,6 +4713,14 @@ static void shmem_put_super(struct super_block *sb) sb->s_fs_info =3D NULL; } =20 +#if IS_ENABLED(CONFIG_UNICODE) && defined(CONFIG_TMPFS) +static const struct dentry_operations shmem_ci_dentry_ops =3D { + .d_hash =3D generic_ci_d_hash, + .d_compare =3D generic_ci_d_compare, + .d_delete =3D always_delete_dentry, +}; +#endif + static int shmem_fill_super(struct super_block *sb, struct fs_context *fc) { struct shmem_options *ctx =3D fc->fs_private; @@ -4663,10 +4756,24 @@ static int shmem_fill_super(struct super_block *sb,= struct fs_context *fc) sb->s_export_op =3D &shmem_export_ops; sb->s_flags |=3D SB_NOSEC | SB_I_VERSION; =20 - sb->s_d_op =3D &simple_dentry_operations; + if (!ctx->encoding && ctx->strict_encoding) { + pr_err("tmpfs: strict_encoding option without encoding is forbidden\n"); + error =3D -EINVAL; + goto failed; + } + +#if IS_ENABLED(CONFIG_UNICODE) + if (ctx->encoding) { + sb->s_encoding =3D ctx->encoding; + sb->s_d_op =3D &shmem_ci_dentry_ops; + if (ctx->strict_encoding) + sb->s_encoding_flags =3D SB_ENC_STRICT_MODE_FL; + } +#endif + #else sb->s_flags |=3D SB_NOUSER; -#endif +#endif /* CONFIG_TMPFS */ sbinfo->max_blocks =3D ctx->blocks; sbinfo->max_inodes =3D ctx->inodes; sbinfo->free_ispace =3D sbinfo->max_inodes * BOGO_INODE_SIZE; @@ -4940,6 +5047,8 @@ int shmem_init_fs_context(struct fs_context *fc) ctx->uid =3D current_fsuid(); ctx->gid =3D current_fsgid(); =20 + ctx->encoding =3D NULL; + fc->fs_private =3D ctx; fc->ops =3D &shmem_fs_context_ops; return 0; --=20 2.47.0 From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D66251EF949; Thu, 10 Oct 2024 19:41:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589298; cv=none; b=fZipUbqKHeBT4rc07Hb/FHmzy7qEYLnJ4eoF1/jIZgkWKvVRGxKAy6vSPtP1U5BnOj/bPMcdzjOhfPVMnENOce6xRCw7aIeKK5l9r3STxDC7q9ch0RC6SR34hZ9zsadnh1oGDq/N9lH7NowForWBvCeYhqVyFYirpc2tLGjwFX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589298; c=relaxed/simple; bh=9cm/RLr8Rzh1vFGh5pv0TyUOuYayhYnzXjVb8aJOmYM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=D2oldi+B/MD+/wVqvPp70knXchTbvGzXqbsbTIidtC9YBu0bx5gWRm1uwpykE8mI5rr/4aEmZaJEXbo/bjYmPg7AGSS+s6gAZvxthvuTqII8kNQf2Fs3s55MEfFGT2uFzOuAa3D0fK6f7xN72AT1qpOXgEbRZXITlFHzJmiJlV4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=ngCP2OSX; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="ngCP2OSX" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=zoE4RPJrEfLVHReDLgphj31bDW38mEz4OTwqDqkwzOs=; b=ngCP2OSX3FyNez4PeGc6ilBYL2 VlvK0I+D6Vcx+oGjksNEOCAIhEsf2nmAeZ6yfNK0Xu7/OpLkbI9Ac8nl6cNsqLtwmiswOrnpbZ2gx qRLfHMUjuD1+lZ2yw3QPaZihs6cBD8JMFMVYgy6dvePodtMpof9Lx2cUBBFAsDX6KBRfeezxCmL5w S1dqfODKlVQn4QfZu47oIzYvKG0NwX/M1PCPVIyMbt4JPKJFsJcGhP1hNWgnn8Rnl5AfJcl1zk0uP s7whR7pHza136ZA/Y237m8Ul3amIqkqzFuST69DUr1vzeyb1T1+6Guvd38NpahdTd81nZP1a6LLnk Z7xNHMtg==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz2U-007SHz-0k; Thu, 10 Oct 2024 21:41:34 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:43 -0300 Subject: [PATCH v6 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-8-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Gabriel Krisman Bertazi X-Mailer: b4 0.14.2 Enable setting flag FS_CASEFOLD_FL for tmpfs directories, when tmpfs is mounted with casefold support. A special check is need for this flag, since it can't be set for non-empty directories. Signed-off-by: Andr=C3=A9 Almeida Reviewed-by: Gabriel Krisman Bertazi --- Changes from v2: - Fixed bug when adding a non-casefold flag in a non-empty dir --- include/linux/shmem_fs.h | 6 ++--- mm/shmem.c | 70 +++++++++++++++++++++++++++++++++++++++++++-= ---- 2 files changed, 67 insertions(+), 9 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 515a9a6a3c6f82c55952d821887514217a6a00d1..018da28c01e7d71b8fb00bfb23c= 000248c8a83f4 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -42,10 +42,10 @@ struct shmem_inode_info { struct inode vfs_inode; }; =20 -#define SHMEM_FL_USER_VISIBLE FS_FL_USER_VISIBLE +#define SHMEM_FL_USER_VISIBLE (FS_FL_USER_VISIBLE | FS_CASEFOLD_FL) #define SHMEM_FL_USER_MODIFIABLE \ - (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL) -#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL) + (FS_IMMUTABLE_FL | FS_APPEND_FL | FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEF= OLD_FL) +#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL) =20 struct shmem_quota_limits { qsize_t usrquota_bhardlimit; /* Default user quota block hard limit */ diff --git a/mm/shmem.c b/mm/shmem.c index 935e824990799d927098fd88ebaba384a6284f42..1c130a7d58ff3a4f5f920374414= f9e7a29347ed9 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2760,13 +2760,62 @@ static int shmem_file_open(struct inode *inode, str= uct file *file) #ifdef CONFIG_TMPFS_XATTR static int shmem_initxattrs(struct inode *, const struct xattr *, void *); =20 +#if IS_ENABLED(CONFIG_UNICODE) +/* + * shmem_inode_casefold_flags - Deal with casefold file attribute flag + * + * The casefold file attribute needs some special checks. I can just be ad= ded to + * an empty dir, and can't be removed from a non-empty dir. + */ +static int shmem_inode_casefold_flags(struct inode *inode, unsigned int fs= flags, + struct dentry *dentry, unsigned int *i_flags) +{ + unsigned int old =3D inode->i_flags; + struct super_block *sb =3D inode->i_sb; + + if (fsflags & FS_CASEFOLD_FL) { + if (!(old & S_CASEFOLD)) { + if (!sb->s_encoding) + return -EOPNOTSUPP; + + if (!S_ISDIR(inode->i_mode)) + return -ENOTDIR; + + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } + + *i_flags =3D *i_flags | S_CASEFOLD; + } else if (old & S_CASEFOLD) { + if (dentry && !simple_empty(dentry)) + return -ENOTEMPTY; + } + + return 0; +} +#else +static int shmem_inode_casefold_flags(struct inode *inode, unsigned int fs= flags, + struct dentry *dentry, unsigned int *i_flags) +{ + if (fsflags & FS_CASEFOLD_FL) + return -EOPNOTSUPP; + + return 0; +} +#endif + /* * chattr's fsflags are unrelated to extended attributes, * but tmpfs has chosen to enable them under the same config option. */ -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflag= s) +static int shmem_set_inode_flags(struct inode *inode, unsigned int fsflags= , struct dentry *dentry) { unsigned int i_flags =3D 0; + int ret; + + ret =3D shmem_inode_casefold_flags(inode, fsflags, dentry, &i_flags); + if (ret) + return ret; =20 if (fsflags & FS_NOATIME_FL) i_flags |=3D S_NOATIME; @@ -2777,10 +2826,12 @@ static void shmem_set_inode_flags(struct inode *ino= de, unsigned int fsflags) /* * But FS_NODUMP_FL does not require any action in i_flags. */ - inode_set_flags(inode, i_flags, S_NOATIME | S_APPEND | S_IMMUTABLE); + inode_set_flags(inode, i_flags, S_NOATIME | S_APPEND | S_IMMUTABLE | S_CA= SEFOLD); + + return 0; } #else -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflag= s) +static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflag= s, struct dentry *dentry) { } #define shmem_initxattrs NULL @@ -2827,7 +2878,7 @@ static struct inode *__shmem_get_inode(struct mnt_idm= ap *idmap, info->fsflags =3D (dir =3D=3D NULL) ? 0 : SHMEM_I(dir)->fsflags & SHMEM_FL_INHERITED; if (info->fsflags) - shmem_set_inode_flags(inode, info->fsflags); + shmem_set_inode_flags(inode, info->fsflags, NULL); INIT_LIST_HEAD(&info->shrinklist); INIT_LIST_HEAD(&info->swaplist); simple_xattrs_init(&info->xattrs); @@ -3934,16 +3985,23 @@ static int shmem_fileattr_set(struct mnt_idmap *idm= ap, { struct inode *inode =3D d_inode(dentry); struct shmem_inode_info *info =3D SHMEM_I(inode); + int ret, flags; =20 if (fileattr_has_fsx(fa)) return -EOPNOTSUPP; if (fa->flags & ~SHMEM_FL_USER_MODIFIABLE) return -EOPNOTSUPP; =20 - info->fsflags =3D (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | + flags =3D (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) | (fa->flags & SHMEM_FL_USER_MODIFIABLE); =20 - shmem_set_inode_flags(inode, info->fsflags); + ret =3D shmem_set_inode_flags(inode, flags, dentry); + + if (ret) + return ret; + + info->fsflags =3D flags; + inode_set_ctime_current(inode); inode_inc_iversion(inode); return 0; --=20 2.47.0 From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B4611F131C; Thu, 10 Oct 2024 19:41:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589302; cv=none; b=WVY+XV3e+wMN3ITPlpFn8WnQG70ae+Pjo9/uz9aMeKAfPQ/BARZvZgLiEJDr2gI1LQ0+E7hOZMJ3w0CXU1YIZ3ce6q1P6EXMPYBUtumf/Hkv5oW0N27Mtg6c0rPG3zHLr1jbmNgZaviUcALlqW5cE8FDqa080KBfyCfEDeVLiKw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589302; c=relaxed/simple; bh=8sTcVklYZK+ygXjhy+vyLT/3hBZVl45qtQchkQV2cY4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=DGSP+avjYeMmO1fD6DRcjWwxw09J4dMPSBQvzidyRJrVmr95QA12yYhh2pwA0FU7vAVDRXKKBIpUJB9xEVa4fmMiSknHEqgseHdrluCmUrHqQN6JfaiBbAStDS67Kx2Wl0HRza5kcUpvgJkz7AvKhvnTk1up00rOj7zTujxTLK8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=X6en/DE+; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="X6en/DE+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=PVI2yOyAN/UHNCWVPw7UlxKiOm9A/KNT9EdQ/TMvelI=; b=X6en/DE+BvgjfVsX7s/4m3ZAOI 9JKyGbPjruDT4Cgi76g0Ltw6bLkYySyicttEMYiglcq6d+oj8vdyF3avkASdHGZhNHLDWNDeF2eSf s0bVUQP5Wg0LBbAA0Gz4BONeWHHH6AnD1k081SIsMvAqacrP3gG8U+97JuFOZT6jnsqqjPBGyb+9x KeVYaDKvz3pHSxPLuvAKB7Q/Z4/LUERI7Dtqwwzs9SlVH5WNOAZ9hqGgnJONGyWaYWPgg4zJdfLTF qszQ5+E23RkLLoSeoJP/elIl5zM4LB2ObH+RPG3zd8cuVdkn7vuMaROuHB5FCl+Y/hnY9I8gPJnsc m8owllnQ==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz2Y-007SHz-JF; Thu, 10 Oct 2024 21:41:38 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:44 -0300 Subject: [PATCH v6 09/10] tmpfs: Expose filesystem features via sysfs Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-9-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Gabriel Krisman Bertazi X-Mailer: b4 0.14.2 Expose filesystem features through sysfs, so userspace can query if tmpfs support casefold. This follows the same setup as defined by ext4 and f2fs to expose casefold support to userspace. Signed-off-by: Andr=C3=A9 Almeida Reviewed-by: Gabriel Krisman Bertazi --- mm/shmem.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/mm/shmem.c b/mm/shmem.c index 1c130a7d58ff3a4f5f920374414f9e7a29347ed9..eb1ea1f3b37cf7a4a11c3d11ad3= f70ebb0e48d07 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5543,3 +5543,40 @@ struct page *shmem_read_mapping_page_gfp(struct addr= ess_space *mapping, return page; } EXPORT_SYMBOL_GPL(shmem_read_mapping_page_gfp); + +#if defined(CONFIG_SYSFS) && defined(CONFIG_TMPFS) +#if IS_ENABLED(CONFIG_UNICODE) +static DEVICE_STRING_ATTR_RO(casefold, 0444, "supported"); +#endif + +static struct attribute *tmpfs_attributes[] =3D { +#if IS_ENABLED(CONFIG_UNICODE) + &dev_attr_casefold.attr.attr, +#endif + NULL +}; + +static const struct attribute_group tmpfs_attribute_group =3D { + .attrs =3D tmpfs_attributes, + .name =3D "features" +}; + +static struct kobject *tmpfs_kobj; + +static int __init tmpfs_sysfs_init(void) +{ + int ret; + + tmpfs_kobj =3D kobject_create_and_add("tmpfs", fs_kobj); + if (!tmpfs_kobj) + return -ENOMEM; + + ret =3D sysfs_create_group(tmpfs_kobj, &tmpfs_attribute_group); + if (ret) + kobject_put(tmpfs_kobj); + + return ret; +} + +fs_initcall(tmpfs_sysfs_init); +#endif /* CONFIG_SYSFS && CONFIG_TMPFS */ --=20 2.47.0 From nobody Wed Nov 27 08:42:47 2024 Received: from fanzine2.igalia.com (fanzine.igalia.com [178.60.130.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F0B21DFD93; Thu, 10 Oct 2024 19:41:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=178.60.130.6 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589309; cv=none; b=Xd8ggrEW388B8LPhD7KCD3BKFRXdrqnS5SfzRASeI68DX4t0w7QuJbTykhL7Q18mH2PhWzyOBSHlWmw5cF1/mxWhS+LunOuHNYYGSIP/Eq2mk+RG76Nf8y7E874YfUy5L3UBohZE0ZvcTSQu8Df1fGTvLgFlyHE5TgFp6KIS9rc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728589309; c=relaxed/simple; bh=xu7ABk+rICb5+7zadviLGl3zQLm7GHCVyk0SKFszPHk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=iYFbfqbOggUBQ9tPUpnqprD2DF/c2r1JDvEVyDnUKIJLQ52UeNviP86avD6Y+cncP5ttDZwI7AI5gMFH7kG5fznJJz+7AmVHg8EithZive2Dm+142IV/ELjB8qqce/4UfmBG45mjLKHzgQiLkOjjSXc/kAdsSDIi/yvCWnNkxio= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=QviYkYoZ; arc=none smtp.client-ip=178.60.130.6 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="QviYkYoZ" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To: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=MO38/TKDXEZfYM/HH5HvDp3/o+h1cffvB2kBOci8370=; b=QviYkYoZfsrN9cX7rTubnq98UU 7LyTxBOAopZwqqGYcT0V6e+Q7BQ/Dr35uDEh4j7FjWja0wRFY8+dIs2zKg+VX8ftdZIBv19sl3aWT 8uRNDIcbA9EWiIytTjGgBDR4NmXyimdqgJwM6O7/5n3dRZXLZ2ecQ4DxGKmhrS5hSPKT8GpcSZWUj PWia/6xhppkTkKyrUtKdblHmaPN9BviQZ2BvK3zAknjjxgdGDds3/5r+VT79DrY3kwaLu5RDY4n5m l3bGuz6Ulehzjs+fE3jAQVzYLHhOMAP7kNs6J1zEx+xYKeVVUIEoOIAUEZJX2E8iTEuo/jAX0y/L/ o1tSV/3w==; Received: from [187.57.199.212] (helo=[192.168.15.100]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1syz2d-007SHz-5Z; Thu, 10 Oct 2024 21:41:43 +0200 From: =?utf-8?q?Andr=C3=A9_Almeida?= Date: Thu, 10 Oct 2024 16:39:45 -0300 Subject: [PATCH v6 10/10] docs: tmpfs: Add casefold options Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20241010-tonyk-tmpfs-v6-10-79f0ae02e4c8@igalia.com> References: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> In-Reply-To: <20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com> To: Gabriel Krisman Bertazi , Alexander Viro , Christian Brauner , Jan Kara , Theodore Ts'o , Andreas Dilger , Hugh Dickins , Andrew Morton , Jonathan Corbet , smcv@collabora.com Cc: kernel-dev@igalia.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, linux-doc@vger.kernel.org, =?utf-8?q?Andr=C3=A9_Almeida?= , Gabriel Krisman Bertazi X-Mailer: b4 0.14.2 Document mounting options for casefold support in tmpfs. Signed-off-by: Andr=C3=A9 Almeida Reviewed-by: Gabriel Krisman Bertazi --- Changes from v3: - Rewrote note about "this doesn't enable casefold by default" (Krisman) --- Documentation/filesystems/tmpfs.rst | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Documentation/filesystems/tmpfs.rst b/Documentation/filesystem= s/tmpfs.rst index 56a26c843dbe964086503dda9b4e8066a1242d72..0385310f225808f55483413f2c6= 9d3b6dc1b9913 100644 --- a/Documentation/filesystems/tmpfs.rst +++ b/Documentation/filesystems/tmpfs.rst @@ -241,6 +241,28 @@ So 'mount -t tmpfs -o size=3D10G,nr_inodes=3D10k,mode= =3D700 tmpfs /mytmpfs' will give you tmpfs instance on /mytmpfs which can allocate 10GB RAM/SWAP in 10240 inodes and it is only accessible by root. =20 +tmpfs has the following mounting options for case-insensitive lookup suppo= rt: + +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D +casefold Enable casefold support at this mount point using the gi= ven + argument as the encoding standard. Currently only UTF-8 + encodings are supported. If no argument is used, it will= load + the latest UTF-8 encoding available. +strict_encoding Enable strict encoding at this mount point (disabled by + default). In this mode, the filesystem refuses to create= file + and directory with names containing invalid UTF-8 charac= ters. +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D + +This option doesn't render the entire filesystem case-insensitive. One nee= ds to +still set the casefold flag per directory, by flipping +F attribute in an = empty +directory. Nevertheless, new directories will inherit the attribute. The +mountpoint itself cannot be made case-insensitive. + +Example:: + + $ mount -t tmpfs -o casefold=3Dutf8-12.1.0,strict_encoding fs_name /my= tmpfs + $ mount -t tmpfs -o casefold fs_name /mytmpfs + =20 :Author: Christoph Rohland , 1.12.01 @@ -250,3 +272,5 @@ RAM/SWAP in 10240 inodes and it is only accessible by r= oot. KOSAKI Motohiro, 16 Mar 2010 :Updated: Chris Down, 13 July 2020 +:Updated: + Andr=C3=A9 Almeida, 23 Aug 2024 --=20 2.47.0