From nobody Thu Nov 28 06:32:09 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 AF4AF199249; Wed, 2 Oct 2024 23:45: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=1727912717; cv=none; b=rxfcnqu594pAPwkm+kwwgH+5MktbQg4+ZozZaOdZBkcI/j679j2RGqJJzkSMl/CgmNIYDXWwelxqAql7HI2bmpfHs+W4cl1aVrFdb3cMD3riFuBe1XMJE5F0HmEgbi507FSTobA0rQqgvbN89rTEA8395rj2ildn+Vv6bm0nLrg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912717; c=relaxed/simple; bh=XD0655LMXQQE3H7/vJ0Cph68fsRLWyVLDTRgK0rdatk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YL1uNFwPo6E39Zsny2GJrEynbuSgSffZdwdl9eruKMlaECdOLPZLl4eVAVt2WWZTly2hN6AfhZym5NvkwLAOGUN9Rk7bUVbvSGRvEtAZ/slZVqKekkJdRg+ohnu0kAbeY2wK7cIeaoUwQj+EOkW6tsEgESYHtXmi4YVP5gpavcs= 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=aFc7Mb1H; 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="aFc7Mb1H" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=Y8QDzI/AINMwYgFuy4R/IREoIrpywxbZXblB5AdDFcw=; b=aFc7Mb1HSQlbH0FXXlc1YsbKdF OZD65SM+Mo9xLxyEBrZUjzuHCCkRsZcBFJYLdQlKwdRX6nWq0w6esff57g7fqherOH8YuTk/Ost1I MI5DF3mAGvO4fodymwddk7xTPROZmALyoPPx4GX8GMtxBfNe6NQnqxLTUICHA3fuLjd14/LosDiAH an2uWrZtQFDjpoR+7iy4UR4FQ+0BmINEzIOpELXgGGsF8Pb1kAG/2mPbfUeYlwphCN9FwOpNZp2SY g8rT81v0k5CwfMJtLdPaFf6qxEgZIn5jEowDq9ZdmiMlRlCg4j+hhgQHvYsQ/JS8K174GH9+q36lD n7m+wA/w==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw91j-0045tc-71; Thu, 03 Oct 2024 01:45:03 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v5 01/10] libfs: Create the helper function generic_ci_validate_strict_name() Date: Wed, 2 Oct 2024 20:44:35 -0300 Message-ID: <20241002234444.398367-2-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 e3c603d01337..9a5d38fc3b67 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -45,6 +45,7 @@ #include #include #include +#include =20 #include #include @@ -3451,6 +3452,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.46.0 From nobody Thu Nov 28 06:32:09 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 4563D1A00CB; Wed, 2 Oct 2024 23:45:16 +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=1727912718; cv=none; b=PXO6x1NJ4l+DDA+7ihzazpHdL7STgVNEDjigorLHeMhS2tKXDAJrJF54C8vhuzba3NZR3BsHcQtpOYnp9NmYhs2R5p3QTjPPBs72fUvyI7nIGOsv72iqVmoy1kH70dCAnlNBxjGGM5a7Ch7q9XK0gbIp8vLbzTiVizp7QVPhW0s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912718; c=relaxed/simple; bh=oIHm5vuPIZznXvIblbYar2SLDHn+DYeKHsv+ZEkNTRI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hNCEEm+c4FXbzP3UBxTqIBKHT4hU26/PwgkxLFcUJEOylC5eoD2RPt0NAHCBvkml7QSozD26+EqXLKoXf6KsGGbL3GfoIOiAaunSmqZNbD7Bu8n87lGuN5deGyidNuHybgEHPavY0ZPD/NyLt/2njgruPM9W+qxIhbuil+tdIrE= 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=R/1/uZzI; 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="R/1/uZzI" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=KXLeYwW1OCCqt0oK34O4XtdDejRlj8zSL51Jo9mqNzY=; b=R/1/uZzI/kIq1MfL9Fyep64GAN DThJRyI7liLrxMsvDeAcg6HQv1z1Ydktk7c41UBYpBb6SSjONTsurzcfgayHZg7l7w6+BjRbv/xAB DP9pG7AKa2oReMvwGx3Ae/uX5AKWeV05+AoQUggMbeWFPoDkmlcVfWpYsFaMa3OwMQjNTvfCwzdOE 6tsFAE3ox7EsCugi/yvjLSJJ61mXHnko8SZzbTqWkIZ0CedMr0cb++XzjBjmNJpsZKc+zHVEKrJwr qyPVsw23JHhXUalI88GbHqQ7nkbaKLJMo8FDotp3h3zqxex+/7qTO7s0gmVWqRuJUFpMaIuwnKqgj G864n8bA==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw91n-0045tc-JV; Thu, 03 Oct 2024 01:45:08 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v5 02/10] ext4: Use generic_ci_validate_strict_name helper Date: Wed, 2 Oct 2024 20:44:36 -0300 Message-ID: <20241002234444.398367-3-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 790db7eac6c2..612ccbeb493b 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.46.0 From nobody Thu Nov 28 06:32:09 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 D36FC1A4F1C; Wed, 2 Oct 2024 23:45:20 +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=1727912723; cv=none; b=YyQcCbfxvxTfLlvqk+9gxYd4EqcRwKvyMcEFh76vGsauVFJCAn4cd+fsVJLTaeArzdR5JCyGY+PDwyMTXNdPCFVQjok3GZ7m0MKTTnGdpTSvcOwEp3HtkbpgcSeXeUTks2wjpNJRH/P+hSvpkQDYDnUBQvLlN1X40vHoWBY4l28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912723; c=relaxed/simple; bh=D3t0v1iUUZS5Dn6r8EulUfg/PAjBiyFz29UUoFs9DQ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oyPkYDGaOZ9T4PakFLxGnGID0I80XR2bcR7gWo/8vbSMK5NQhTl4fN0nw2abkiUAEQ2XmtkxtAl0PPaSdo0H6bT1CMQUJ1hYUKbuOksf/6HWk/Roo5pvx4iD+rB2kOIe3ea+A6/EDy/OAlS2qgvUkygWiwRw4YH6s3/DgRZ+6jA= 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=UgzBQREk; 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="UgzBQREk" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=DalQc9ZFDkAEv3Wa+zRkk2ZJ5+lE2Yk2pdRycpfio0A=; b=UgzBQREksyY9Nb2Y5xXzTaqlbk yogZnCArPZAn08oPQZEdWPUNmG8pl5ZtM0j4iy5+XcdiKQeVPztN7tOaXFDXSHiDH1W3nSydxyKD9 TxqluSZz/becVnaml0eECIvj0UHDLW9LB78cePc0ddHXzgGqjJyxW6mVViMMfYDoR9qTF67iOKwqU nk+aRiWIdAQx++IsD/G9JXyzVFa+wE1aoGe2qG3FklV22U9GHo/U2OPbM8crVUe/wE8jYMtPWJqXO td8xWsu3H/xoWO1GM3zXOqrsz3hzBXpQMiDgDQK9PH9um02ltAp2yQt8JlswIlCaloNLF+5eIyei4 +YJl6+kg==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw91r-0045tc-Vt; Thu, 03 Oct 2024 01:45:12 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v5 03/10] unicode: Export latest available UTF-8 version number Date: Wed, 2 Oct 2024 20:44:37 -0300 Message-ID: <20241002234444.398367-4-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 600e15efe9ed..5ddaf27b21a6 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 4d39e6e11a95..0c0ab04e84ee 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.46.0 From nobody Thu Nov 28 06:32:09 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 614FA1A4F1C; Wed, 2 Oct 2024 23:45:25 +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=1727912727; cv=none; b=rG9Z339uIt5WRayvv7ZOLUJCdrxDevgz3njp5xprdQ7DU8KxnGTbrRa+MKeCZjb8IFQEJLkeclETuYGfMU5km1GZEmX+aC/oNv1mUixwqB6d3l7KPAOSB8DPDLIv1NRhgwp8y68rGVXep0BS7Eax0vJQwcAursCGu21aA8NCkjs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912727; c=relaxed/simple; bh=+kkwFwJnq0dJkV7YDtzBnVifdVhZtRPynXmCviDLHIY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bsNpg+O8J+Ep1qmQW87rHEzkZ6/posq0lcJmPqCKpykcrwglletrZXjOo2Ghx7xP+FK5YX3uUw+sEvVyg1sn9sBNJEL4G4+Dr1Ef2ALNU+Zgzkqc5sb1e1NNvgmG3cw2ru2IIN0K8cc5BbI5Oj/AZbtXMZCBTRxloZXdVY/GZUU= 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=rEN9q944; 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="rEN9q944" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=HCbVqueHUmSSCcT+A2gsLYEdLj0anlbi7vfWbqjQz7g=; b=rEN9q9445fHCa6+Cu5k/ZNfA6l rUVf5HN05YiPW6LBeSVDHVW4yadCX1//v6PcFQTA/Mu90qZhR7Kx2QsPMNbrNzyHSUt4N8NcoKeY7 WDaRV9YyJxmiKIQKzgH4Tqf6xY2PfLxyrL1xu+3E+lHnOktCjoFwrwW0u+T+Dm6IIp3tyD2xekUbA ppP90YeCpxXhbXEgPg7bO0JT0sxAzzCV9SfZH9N9JKBfMt7feJ+oUh9ehxpd5ETYEhNy9ULePV+4s oCrLHrmwF0ZREkJLY1US/OZkYXFek93sSO42K+dxBJIzW+OHd0L33CVG8dyiqCs0qBtz3j5HTqmPQ O0FJJMEQ==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw91w-0045tc-Bz; Thu, 03 Oct 2024 01:45:16 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v5 04/10] unicode: Recreate utf8_parse_version() Date: Wed, 2 Oct 2024 20:44:38 -0300 Message-ID: <20241002234444.398367-5-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 0400824ef493..6fc9ab8667e6 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 0c0ab04e84ee..5e6b212a2aed 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.46.0 From nobody Thu Nov 28 06:32:09 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 DC8921C0DCB; Wed, 2 Oct 2024 23:45:28 +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=1727912730; cv=none; b=U+yJZOk/L9a+PgdjkcLaQPPujqaLmtRheFVzqzxFsRSQqKszQZvITDoz7vkG4tGiURtNPsXtv9ldAEzdVULiKYN9oXMsFi2truEVXEhou+PiHtspCnWQZ5Sf/GxM7o/wWLL4Or/IBPRt4gNYdXRrA+n3O8VuTVi3JOK7ClIxPTE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912730; c=relaxed/simple; bh=YxdydQxEeqgWOKZDzzhLVNxkB+ZO7uV8OQ8R50Iwbbk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WYD5Vx3uj1DXcEOF1xXREXd3Yc5uOLtHOzToyTR/Or/4d+S4L4LLciygPDOQDnaZpBo+6RBUkBT9UIw0XOiQD1AtA1x/9kDx2dijVTIfSx1s9NiRu4afH+W/XKNV7bZ7I1uunee3tdOued7PXWRZzsD/JuzSKTc3o4MTfyxGPvY= 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=GRS0ZU4D; 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="GRS0ZU4D" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=AQXk6ztfHTUQteq8elPhWhUuCISghcvWoGYTPvw/Cw8=; b=GRS0ZU4D/LbdgGtJz8RqDet2I/ kBSmua98CNEkx9YC1kQqu5FoWtonv8v6mjKUDDc+4jt2vUVc3H6KfulRVGlmnmc77P+HgeXkffCxc ylDiVRu9Ko+fcofddOY/MotK4SzHmfX/qso/QhYfbjx+NngmuqyXbkJsJKWcizQVxvqWLiSXbitLm 7N5QOFhclCGI2g2TRhiPKOVDDFSHwO19js7JLFOv+9TrSrB6I5oA81S9Gzs6k2x9duS/K3VXWggQY rjF7yM0fWEyE+RAq7rdWWkODzySa7GRoaOxdV0lHMyk6n0mrrCOHOXnjiIU+96+GbfoKG8yqtGoj/ 1ycf+wPA==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw920-0045tc-HW; Thu, 03 Oct 2024 01:45:20 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v5 05/10] libfs: Export generic_ci_ dentry functions Date: Wed, 2 Oct 2024 20:44:39 -0300 Message-ID: <20241002234444.398367-6-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 46966fd8bcf9..7b290404c5f9 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 9a5d38fc3b67..400d070d9a9b 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3453,6 +3453,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.46.0 From nobody Thu Nov 28 06:32:09 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 9DAD31C2DBE; Wed, 2 Oct 2024 23:45:33 +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=1727912735; cv=none; b=mKkOrocDSv2BC2DJcYF5JtridPG68+3OeNKFuzwf/yU2UP/Zq+rVw5GtmKEnMkbsAszFyDV3/AP4CiuM6Lv2VgAGndineiZ04RGB9Az8IA53eoxuh6oZIDqXZ/CRbygArudSLbXeOzNXnqaZggCartpNnDe628Pw131D/fxgob4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912735; c=relaxed/simple; bh=baYyqH1zkRLR2JTEM1uWa5kkwLV6py0GhE+cOwhsPGk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=WSKxPymW42Kf89pWr5uC1isnmDWEL9Lp9jalM3cboJWZR241XVXGOijDST6wlxmHqQJSNrceh0DZ8GabMb07kTJFZsbxMY8n2uWojSrOe2LKxHbOGhe0RUSKdV+RNLvjtP1FTVUfPWCSbK21wcPRjhncsY2NYTcrsK0mK958AR0= 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=bka5vrt0; 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="bka5vrt0" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=Quu0dtbQ9E+zFuEMK6MzcOIEYam2pR7bqkVHBNP4Z1M=; b=bka5vrt0u16euP1xIhWZ/Kg1wh ar8IE3EbJsB3viwk03hqbcr4jQJ2jK9Xd6LueY/9eMGT++ho5OGh5/nR0NfR5aDwNNIoORZs/tzPz xFCknGIhr9MWfGMTi7ksYaVVUUNTC7KXm0a4Ifde3cNKpmNSRYxCGMWk/4ECZlxRe2NbGewsG7ttU t9jE5ElARxyxdq15MgdjrRrqqiW5cAx8boixraK6bpaUw1r/5E6uO6yzCTq45C4dbRy9hfU7qwsMV CmUkUxxnREwLcSVoSqLD/1vhksx9xUx1OfIaSteNU0kxODerKgSU6VvcJH3wt1Syiovvb9s8Zj6NQ rIR49aAA==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw924-0045tc-N1; Thu, 03 Oct 2024 01:45:25 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v5 06/10] tmpfs: Always set simple_dentry_operations as dentry ops Date: Wed, 2 Oct 2024 20:44:40 -0300 Message-ID: <20241002234444.398367-7-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 4f11b5506363..162d68784309 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.46.0 From nobody Thu Nov 28 06:32:09 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 10F0E1C7B7F; Wed, 2 Oct 2024 23:45:38 +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=1727912740; cv=none; b=K0JuO8CZF5qB5U3NEf5nvb1fTiUqNHpkX/BT+QixITF983nBSu/ASae3FQn2Y9TVn9BzZnpCG5Co81gaYRjF3fWAIXYJXmvG9gwQmcW6lUtOoGMLY/VcfoOTOEK2DL3BbKz9XYnlWcO0cZsjb8V/w6LJKYRMl7B69dV+F4iCeyo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912740; c=relaxed/simple; bh=Sa+//KaquEMlmqekUsr7aQ/KhcNfYjdlVFv0NcFuJyM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=uq1/H54tsDQcdKSwB7JHxAZhg3eEX+hy+uMocMLZU+BosxyPd2EiwaG4ADBpgdxWR6I4qau0HJBXaSi0yPVxFir1hsX4UhGhKyaHfP2nBs7LYY5fdLsRniZr41RRlFHXhtaJUfqosBdC3VKEGrU/my6jODPNFbZiZNjE95Hv5gc= 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=WQXH2dH+; 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="WQXH2dH+" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=a44X2hLHZHM6OEDMyxUHO1xVlMNMtLmqduY2AzXe0HA=; b=WQXH2dH+S1J9YIo6G0O001t96K J5FiSqTRu2ts8uBrtgp7+vm3sVcL9rJDY2x0K3cGx0tLF2Ft8sN50OJWFJcCUMEIb4ihwv8K83qM8 j0xJsAd3Soy2U8p9+uTvqu3je5yS0dTvCMbNI+a0qCv2RdNc5vMRf6HUKVi7/9AFPRAH6VhN0jVsU 06lFGMoUusQhHd11deSJT7hrzmEnZL0BuygM2JU6jq00BJlXr+cHiH/H0A6DWH+/ytKWn8tcGTkLp oibfaKgYymHDk8q/Q2s0PJDOYvePUNM2Xc0QJkgrTVO4pWIvjc/5WtudxD3RCYRa9sS5UDJwtuCdV YOAVB09g==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw928-0045tc-SR; Thu, 03 Oct 2024 01:45:29 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= Subject: [PATCH v5 07/10] tmpfs: Add casefold lookup support Date: Wed, 2 Oct 2024 20:44:41 -0300 Message-ID: <20241002234444.398367-8-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 --- 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 7b290404c5f9..a168ece5cc61 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 162d68784309..3c8c7b34632a 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) +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.46.0 From nobody Thu Nov 28 06:32:09 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 1682E1C9DC2; Wed, 2 Oct 2024 23:45:42 +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=1727912743; cv=none; b=uuyu1cy4qxHFvuIwCpVhwrYJqVmdJ5hllQkrsLu8aOHc4JnADnE/Vev5FZ8uJoHlDsfAb+5qobDeubrlQHxweiGVj201UpgITLdnayi+XAgeyD09TK9koxaLcqwUjzQSKr5Gk4ytcTjek5HSKkxo3ZliKl3S7yIP7dtxBJPQyNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912743; c=relaxed/simple; bh=qKBxsVp/91eSCWgq+8I6tAO54YPVMjb1pJ/8/vbu/9g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GQFpsGTmzV6mpMa9PjHi31XCYAH/WV3kTsf3IHkxvAa2lNdrLPHpgdtHniVVDImTC2DC8CPPovolka/755HAlCyyFUraZANVVYp1oh5moJK6E5M9sMxTudicddc6C2n/HPIXBROEE/zsJ0szmJ9+rnStpk7F3IYKcttG5Ma/Jv0= 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=S3porjiK; 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="S3porjiK" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=QytpkEJz2P1dJL+CmfxoJi8346LIRFv339Bsa+p1XKQ=; b=S3porjiKB8j1yc1P13gIqYyX/u 7PmSf6enyYqUSXaev5M2yurMA9//3IHYmZFL5hQ8Tl+aU1b5nDWsh6QW0POaCoR4JQTLD+jPpIE5I VfJYHblM+8f7loAVsR0hBj6degYp9N+sBHcRgqVXTChMkEOYB8stu7o5x0uZwfti8kRtYo8P5hOgM eLQrWem3+Rh9e+YodNjfn+z7wVKQc7DDFggSevcgRQ1moW8XNTc/dhyCYkyGFlOyZLiHSKJR15j6v 0xMZOcXyrKWkkB6VaAFCxvLVOS0ug0/gRrBnlnlOz9XlKAt/lIpekWGhqHK0geEG5g80+EXaDABwB wEyThyVQ==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw92D-0045tc-FT; Thu, 03 Oct 2024 01:45:33 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v5 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Date: Wed, 2 Oct 2024 20:44:42 -0300 Message-ID: <20241002234444.398367-9-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 515a9a6a3c6f..018da28c01e7 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 3c8c7b34632a..f07b446b3c98 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.46.0 From nobody Thu Nov 28 06:32:09 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 58AFD1CC14C; Wed, 2 Oct 2024 23:45: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=1727912747; cv=none; b=VRZ1otsMZnyTYllkCuyccUYP1VqD7vDvMOCUM3t0GPIgR4sxHIljPGqYVBu/Fz+JaD9l6PM7/g9uD6pKrDJbmkjh3Tti6md3krhGGM3jzydoW3RdsAeULT9Qb/nQFp/NS6gw9jYBntTAtkDjJx4/OgNuOBoUVkaiVaQDoCssX0g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912747; c=relaxed/simple; bh=Q5OxMdiU6Bu3fjUb9MsjJWYA7YZ1HuV4bsGRFebf78M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=c0rwWX6z4JYNBlGul3MBwQdnzSnt7/v/S+Wo8d0IG/NGSuEc/mSv9a8VHMgKSneYcO4JMG+LnmzJ4gz/fM6EwR2wvcVYgMMJO/JXf21ZZ3sPglJEPzm81M22OQJCs/svDDrmmazvlNJEISqlqqpIDn56u2yorYFTETLONvA4lqM= 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=YUXfIqOm; 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="YUXfIqOm" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=IRPMd0h51YpQUBbAAX/wcuH0ZmexRZTVdCGmfxXJDJ4=; b=YUXfIqOmAm+ugm/XutADfo8KPq 852FMkqLH0SDzwTuLviY9XWwuciBiWB4uZfTdN24lUwGI3iZLz9ztLI4yr4ZiyMOkqajRybBp4+6Y ZVNOj6EVyZdjf3mfra9zlRHjbxVuwh3/Z7v79gNubJXqRoQVGVoJi+XcDsmWWGpHG+/pqElH1cuGD jlrxW7RXb3rlOqzNOGq7INMOtQuN2U3xQ1Qpt7V/+XV7ntd24CXQJgXdwHF2fo2xTS1t0RNn6ugun BmWFAlzoQECJH/X4J4E+FfadeI5VAdDMnKrk+E24N09A1HfCdwjjM2faNC5hDeOKzLCKd6vGLTVVO pnqUI3LQ==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw92H-0045tc-Rv; Thu, 03 Oct 2024 01:45:38 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v5 09/10] tmpfs: Expose filesystem features via sysfs Date: Wed, 2 Oct 2024 20:44:43 -0300 Message-ID: <20241002234444.398367-10-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 f07b446b3c98..007123019d1c 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.46.0 From nobody Thu Nov 28 06:32:09 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 221F81A0AE9; Wed, 2 Oct 2024 23:45:51 +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=1727912752; cv=none; b=Ue2mT8Ehffzfac5ZMW1ptXtEhr31FS4VAa5nd4ecb39063caSv4J53+jdFprWYDN8OmZnK1XgJLQkoh/eHAQ7uwCRVcnxd9/IDxW0kMJ0SvaSlr+jkaHtz+LcRHcf5M7e3ZRpX+x7bGJdosmPC4LOXcpH0NcmPs9zka8jpwmF3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727912752; c=relaxed/simple; bh=g6SodgXuhFSjZPqpwigjcfcJJcRz7X6EEVS62TB2WS8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k6K1i4I1M+HS3Xju26VTQpDXDiwKz7aJtOU+k+NdnRgKED+njx/30XOugg1hdVVbe6u/fmROr5VYkgLH2sLCFS1QtzP5eWQaHZo263KKHM/7dl2Th4Wx/1X0got9ABN237t+rcgsE1flqUOOw0yAiVZviCbSHblpgOnRu0hQrRE= 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=JUOKNPWp; 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="JUOKNPWp" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:Cc:To: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=bm71yghG5LmMPzMX6MAemKlkSPoby82wgR5jHJ9lUOc=; b=JUOKNPWprVahbSaKyzgJmNEx3M oddv6lJOok+SD7V/VPr5KC+WOTyqzaNMHoygRYybFzuPmkQvSGabEroPITqAbrEqUoJLlbjmakWUX hoScsaL4uMDdYEijrIvsiQxlnzqY7xACli8TttrH8Yy/LF94oWJWS2PtftPR4qaWqGqRuvnnoWKy3 CntcYbyf3l+Z1irHv4S9UUt56wM37QvLpNIzei5pCPOpcDRWjuKox8OWO+LkUUs5Jp6TfYQ/A9P8G lGJTtTypJdsTL+JjpHdQkscGbV7p2UgehaMyGB0lGLtg9M8SyPMKkkCBd3EK5zQbwnJ3SKKQIc/Yi eB2wDhuQ==; Received: from [187.57.199.212] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1sw92M-0045tc-81; Thu, 03 Oct 2024 01:45:42 +0200 From: =?UTF-8?q?Andr=C3=A9=20Almeida?= To: Hugh Dickins , Andrew Morton , Alexander Viro , Christian Brauner , Jan Kara , krisman@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-dev@igalia.com, Daniel Rosenberg , smcv@collabora.com, Christoph Hellwig , Theodore Ts'o , =?UTF-8?q?Andr=C3=A9=20Almeida?= , Gabriel Krisman Bertazi Subject: [PATCH v5 10/10] docs: tmpfs: Add casefold options Date: Wed, 2 Oct 2024 20:44:44 -0300 Message-ID: <20241002234444.398367-11-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241002234444.398367-1-andrealmeid@igalia.com> References: <20241002234444.398367-1-andrealmeid@igalia.com> 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 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 56a26c843dbe..0385310f2258 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.46.0