From nobody Sat Nov 30 03:46:46 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 6EBBA1AAE3E; Wed, 11 Sep 2024 14: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=1726065939; cv=none; b=Qda27tGyVcmmAr1t1boCm9VHRd7v6r9r8/3inItXvs8DfgxM/KbWR8Nhthq036+6ExqH2okjHyGFM3oZ7iVkdlw9b5iC6hEVJITBc+u1I3xhpne3T/jjS+js6cLrQo5zOEvM1WrQa/UKIf9u4F0sdATQ+MPqlKovKIhrx6Vwzho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065939; c=relaxed/simple; bh=JDDkfI5C/SzSPFtrnIr+Hv41Z4nJqWVVuGXk4VwNw9s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JLqJdU0Ojv0ecLHwd232s7xvoCwjwrT8bpHLQ9lf4779OJGFtfNkXobHZ2xpzn9vro1FlGCllOJzqc+LBJfU+GA/0pPEvi72tUyoZHvC6T6UrqeRuoG4E4mY4o6JLmb9UEKAOBt14yZ022RkzBV56m+oRXLmbo1cGTWNKmER+MQ= 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=TvzCw0sR; 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="TvzCw0sR" 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=h3G2XLqID4r09rjc35sdSginc1+HQQOMXWwkAOpIqMQ=; b=TvzCw0sR6HZM4aA4GH3FuRWYVI Px1BmzDY56FJAszk+GMHqk6MfhKr9AEhgBV6FEg9nSClLKdbWiQL8W1gw2pGA0XM0I2cafcQTMa2a mQImN7F+fHAec/ZSZtxFLaf8Wwxk6UxtKbGW1nWSQb59kGyGHtUL0cDVy7ISICVNfg63Ul2RkokT/ N4wTFu2Cw67udkHhRhTtzMmsu0D1cV7XEPHq9WhsvDx+fQ9Rk6CGeWlPhh17D7Ca9aXtNgQQZRDn7 Di0uygBcmjjmwtUXmwrtrGH9LguZ1wuQ6mutHL0QktiGfRSTDSL/LddnC/W4PrlubNkwUJWZ3hW2V j8C6emTg==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soOap-00CTwi-PH; Wed, 11 Sep 2024 16: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 v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name() Date: Wed, 11 Sep 2024 11:44:53 -0300 Message-ID: <20240911144502.115260-2-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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 v2: - Moved function to libfs and adpated its name - Wrapped at 72 chars column - Decomposed the big if (...) to be more clear --- fs/libfs.c | 38 ++++++++++++++++++++++++++++++++++++++ include/linux/fs.h | 1 + 2 files changed, 39 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 8aa34870449f..99fb36b48708 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1928,6 +1928,44 @@ int generic_ci_match(const struct inode *parent, return !res; } EXPORT_SYMBOL(generic_ci_match); + +/** + * 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. + */ +bool generic_ci_validate_strict_name(struct inode *dir, struct 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); +} +EXPORT_SYMBOL(generic_ci_validate_strict_name); #endif =20 #ifdef CONFIG_FS_ENCRYPTION diff --git a/include/linux/fs.h b/include/linux/fs.h index fd34b5755c0b..937142950dfe 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3385,6 +3385,7 @@ extern int generic_ci_match(const struct inode *paren= t, const struct qstr *name, const struct qstr *folded_name, const u8 *de_name, u32 de_name_len); +bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name); =20 static inline bool sb_has_encoding(const struct super_block *sb) { --=20 2.46.0 From nobody Sat Nov 30 03:46:46 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 5E05B1AAE37; Wed, 11 Sep 2024 14:45:37 +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=1726065939; cv=none; b=TAcO6qNGnnC35GieJU653YTTeym+25x85Ckk0bNYbpYdaAsw3skTG6t8GcD0kckhWbQs0oLpG8TjZ86N+nZsJyN9+dn9CARX7nw5f3yk5x8HfY92CZiI/yXfRqrGKM/CfYQPiutksXNRuCcGgI6dMsFBa/+dAp4ED25k84Jljyk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065939; c=relaxed/simple; bh=0taofh0Xk8e/xFeBuR+ZJrAFWG6Ywq1ifG5UXMsoJA8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OzRCrh0ULld5iN9Gb+q0w0/lzwZmnoyukSR21THdhyJov3dmEXgbW4K7se8Lb9ENbRqmOemqA7/2LoJslX3nHP7WO35p8LwmNZUwE/EoSf6ptvay2Qrl/7m1todJYW/DQtY0Stt7jogiAW+dfWby7MQ0qHn3vLy2CkoGpgvmpzk= 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=d3GntHFk; 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="d3GntHFk" 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=kxZabVtRIbsH5N40Gr/wp92cNKF1pfI7iuz0Er/EL18=; b=d3GntHFkdbbMSCXQUNBp91ixBf 9OIUngs6Lz8HspCHitoMhM+6/l/YsLELRFGnW2P9DblIt558GwmqgnJGce4qp6WHDmuG86C5POYVV Bl5v5DEh2FEO70Vymnl9a/tI3/1xWfCgIybnnSHuPd74+4vWpGjFuxoo6gvobs+wc0hgznp0Jc9DS 2lTOaJ5cRQQwanvW74I+p5hOUYaoDu7HS0Jwx0055qobygH786E/npE4xaeuZNpnXhtAwPpGRMsog Ok13crqzkBfgGFCSmzuMbx4DjIQAQTYQZpXBatIclfY56U2TN45aNkHqbXaOi7dD4qTiHYo3mkWE8 wI1XTxgg==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soOau-00CTwi-4M; Wed, 11 Sep 2024 16: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?= , Gabriel Krisman Bertazi Subject: [PATCH v4 02/10] ext4: Use generic_ci_validate_strict_name helper Date: Wed, 11 Sep 2024 11:44:54 -0300 Message-ID: <20240911144502.115260-3-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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 --- fs/ext4/namei.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 6a95713f9193..beca80e70b0c 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2394,8 +2394,7 @@ static int ext4_add_entry(handle_t *handle, struct de= ntry *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 --=20 2.46.0 From nobody Sat Nov 30 03:46:46 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 291791AB536; Wed, 11 Sep 2024 14:45:39 +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=1726065942; cv=none; b=gxRhGu2NpWkRIOmo7sBi/uKRw1kYCcsNuCzDnqGRs9hUL3WbFPVl+76rQF5gAf51iMFGQ3DvsSp2vG1lxzWwtkbuHYmNBgBwqEfXmaTZodYJc8jtrYPG1JuWM4KjjWd9WqGQ8FL4GRY7OEFTvl8cOmKuQ5JJE6OxsGeY5PNh4Ss= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065942; c=relaxed/simple; bh=xj4gbEvuGuSc9wGpnsVfvK1OkBraHXynbeiYyQAAspI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EgdT0Y2D7IiE2z7HKY/hhowp7eJF07mJrJ0InfWBg2k7Vkld3RrWj6oWE1l0EXRKvd+AD8wtazQPR5TqjUO2V4WAs0I9F3iYFvMZvCWBUcav63ZCxueaiTJ9oar1FZDoS+W6w0IGWOr/VGqXKEhgN1FG26QxIQcTTWRhTIu3XyY= 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=mL80uITq; 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="mL80uITq" 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=WN3J9Ey5243Buto3KVkQAnNnAuXnNzeuNPoBKu1Uxzk=; b=mL80uITqrstdF/YOk+k9aSonku pXo5DDt06puEPHzWWm9fxQlUUhbeyg1ua0cn56u0HI5O0R2+eVN3TMcCfmpONscPwSMntpWPX+52K jT+CxL9RyLFn4NI0o3CNt/2y9revtz7hXPKfb7sD54PF/d2PJOcjE/oUxmbFbuirS1uxn5vrHN8gU tLXxQ8L/rc57Kf+IpTunNBFBtWr3rp88g10exMPPRHM0bYkPLh3DhC6NgDEeefO3LdsDZT7uw1tbp 31DW/eEiPk1KLMosg20VA+XJpE3X598rr/3orHXs0/woYyja/KIVxOQ3dPtyVOlXtTh185I5y92tx f2LiS5cA==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soOay-00CTwi-8f; Wed, 11 Sep 2024 16:45:24 +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 v4 03/10] unicode: Recreate utf8_parse_version() Date: Wed, 11 Sep 2024 11:44:55 -0300 Message-ID: <20240911144502.115260-4-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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 4d39e6e11a95..12face04c763 100644 --- a/include/linux/unicode.h +++ b/include/linux/unicode.h @@ -76,4 +76,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 Sat Nov 30 03:46:46 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 291F71AB537; Wed, 11 Sep 2024 14:45:39 +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=1726065941; cv=none; b=Jclc7nx0LxAYJgDzpsk7dKOxTJWRrsLxm45a7nwZVzvdebCJm8KEWbQuePWHzC7VRZS9m0BTseIgTItL7+RB3VnFbXWlsb85jx9kG35r6ENt850Jc1CwVSQ1wcmFvO+r6M0LYdrz8M9iowwXeYt9+BhIMYFjfy5/MttSTV7kUKc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065941; c=relaxed/simple; bh=TNZ/1JgO74m1hYqUho91tGqfE80KNCqAjRAv1/zC2VY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=tNT2oECHHn6hw4El4U2fidzBh43f3bCwyKct0kZn3gfNwWg2ezjhk1FydusXPC6PJTHsuuoun4xhmlebXqeX4Hfci3WrvFBDpc0QbCcEGhF4L/rwzdoY1MjWFaAmDVfR5QlC43TgoWBQm0C81xBPODz0WU4+fGaDMMYWoJKzBQ8= 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=RNPzzW+J; 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="RNPzzW+J" 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=Q0CxLvnub6YNgaQNFMUQs5iJpolg9jiEm0ayfVoTv18=; b=RNPzzW+J6Gy+V7B4nSX+XG52Pv mrTDmizb56Ty4IzYaIyjxAFQgOgdRKJYM34xOv64sr9PVV8kbabW76/oWNPdm+0Utqhh8sC/OQg0W 3lpoSGCXhe49JKsQv9lsQ2jUmNmuNjG69npKt6k5TV3g8MgJRHJQ4/JypQs9EOwcifkjLK0WGwQD7 unLC+UxtoDo0VewnbYj9oeiZuVk0XYwqxOpBp/PAcGGjmWRLy4kv0p7EwJztZazVs8KS10o7mNeoY TvngTO0It3S6tzFVn0hNSiHadP8T0DQxncgAiTK4LF8Qf7QA1rBFVhbKsOh25JVczfyokdbHftNMA Xp8oLGxQ==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soOb2-00CTwi-L9; Wed, 11 Sep 2024 16: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?= , Gabriel Krisman Bertazi Subject: [PATCH v4 04/10] unicode: Export latest available UTF-8 version number Date: Wed, 11 Sep 2024 11:44:56 -0300 Message-ID: <20240911144502.115260-5-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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 12face04c763..5e6b212a2aed 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 Sat Nov 30 03:46:46 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 D05961AC436; Wed, 11 Sep 2024 14:45: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=1726065944; cv=none; b=n4OthD2s/GdQMpBlowG0tePaHMFMy8l38wjnG4+Eq8qFAvJd7HiFOclq0Yw4FJYXidz6NdTyIz2Jocj1rLBw1j3NyvIWfdXwW4VyWZ9LHwcgp9i3kfxNWKzfuK1AupS9FQKWHDHDjn5PvMmqYjGoE1U/jxU3/gvWJtNZITj4DFk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065944; c=relaxed/simple; bh=W9Wi8Y+3FyQ4n9+LPtbm+LEcdkX09Opva/ZdK2u5bRU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OzPffUFool6qK/juZG02/8nv5JvDqsNF0Aj5HNf6dzd7am2xcWakeN3n6b3l1hhDndUeKqL8wdflXpaHOneW1LLIPzcOBBwLJDaXrJyGBDZQA339EuRVaExWPu9kN8Gmw9zMkN4wzBIPaJR07lMpcep8aLhkln1b83zYQXhvvVk= 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=JM3ErL2m; 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="JM3ErL2m" 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=3FFQIAuGvH/0A1mPCgj4xlU1M+Y3nXSW60dESGxKvsQ=; b=JM3ErL2mdbpqkr+KcUJ1aszMzB jLUIm09KwRkExt16iFaCVWUoYp+LQYa1M8VbtDybGticsjAqAlWcY2NjwguRMr8P3SiiqOT+fbESB 3KQTsCcWkDhdfP0wvYJ9Vge/dkxu7H24NfFYEYPIZmMHqhv7hW80CTFZQ94DizqdnAvx9ruoU02MG tAc2qt6fQ24oNqy7UUU6FxcXymXkkPUVxqlCjU9lrA6CjR+R7J546lGLArpOb7MISi5m+tQyBPemd +KDsSJsXEv+xrk2OD2lZ2WZpAziErf0cxqXrKqtZLXWYgrIq8V+vCRArNAZnX0WkvFBZKEqQJk5Ih m6IL6OTw==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soOb6-00CTwi-Pc; Wed, 11 Sep 2024 16: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?= Subject: [PATCH v4 05/10] libfs: Check for casefold dirs on simple_lookup() Date: Wed, 11 Sep 2024 11:44:57 -0300 Message-ID: <20240911144502.115260-6-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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 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 --- fs/libfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/libfs.c b/fs/libfs.c index 99fb36b48708..838524314b1b 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; } --=20 2.46.0 From nobody Sat Nov 30 03:46:46 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 7B2491AD9FD; Wed, 11 Sep 2024 14:45:45 +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=1726065947; cv=none; b=b8tUu+1NUw9LOy2tWXthBd8U8JkQwH6DIwWLu9ZbfnN14o+GJguHpq7Ha7oCZ9lyRV7JDcXeIW3cy4u41+u7bCSoCoHq9fsdjBTerHAVay5+kK+pXH5jNRiaRYhEplVeAN3Mw0pM+pMsbrNAX/W/cJ792WYKk/4omGpNlrE3DcU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065947; c=relaxed/simple; bh=ZTyJ3+L6ldDa1N/KAPphItaNAKDuyEQ7XO8b1Li5eHk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QXXj8S//w+q6gofAttNoiPTYSMJBvEcC/QP0/auoBvb3ZhM3oFjCPWQTyWcbT+KvpIxngzipQnEWBT9B75MNjyAUE5cAwDOmkmpA9zScjZaU9//eq3C5fkBAz4nugT0aHiqFKwSR+Rbt7PUXj9PQWagXcppesdVzcuijf9GDDXg= 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=hxJKefRG; 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="hxJKefRG" 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=B86Pw1ckCkywr9gzf5gk+joWfc2NDawEVXulB0pNBG0=; b=hxJKefRG1tjyLL745br9iC9O4A jcfqv+LNEBW2FgL9bLdQh841tBi7M1XJNljoL/h+w6JBZ4Qt7AHX2JQ3fILqb1kKkXydBhzZ0f/Zf 5lQTd/bh6iYANTNNqdkhLdBaM1zx9cBpMHpmQyGAudyPYwWKf8+nLNLqCBhQrnDelY7LcUOoRIzx6 3CVm4GH7tvWsHOn94OzODUu0C3KhOEYk153KyDh4Nh/wRDk6L28h0fmMeYJaL4Fbpp3iM0xX4PfBy gNWVKo1x38q654U/6UwewxkbF/8tDNc93lckRXHV2U0om76pxlBisCcYgv+MdbVwlRUe67gK3SZVA HSnuoh7Q==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soObA-00CTwi-UH; Wed, 11 Sep 2024 16:45:37 +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 v4 06/10] libfs: Export generic_ci_ dentry functions Date: Wed, 11 Sep 2024 11:44:58 -0300 Message-ID: <20240911144502.115260-7-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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 v3: - New patch --- fs/libfs.c | 8 +++++--- include/linux/fs.h | 3 +++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/libfs.c b/fs/libfs.c index 838524314b1b..c09254ecdcdd 100644 --- a/fs/libfs.c +++ b/fs/libfs.c @@ -1783,8 +1783,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; @@ -1827,6 +1827,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 @@ -1835,7 +1836,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; @@ -1850,6 +1851,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 937142950dfe..4cd86d36c03d 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3386,6 +3386,9 @@ extern int generic_ci_match(const struct inode *paren= t, const struct qstr *folded_name, const u8 *de_name, u32 de_name_len); bool generic_ci_validate_strict_name(struct inode *dir, struct qstr *name); +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); =20 static inline bool sb_has_encoding(const struct super_block *sb) { --=20 2.46.0 From nobody Sat Nov 30 03:46:46 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 2EECE1AD9FD; Wed, 11 Sep 2024 14:45:50 +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=1726065952; cv=none; b=BDb7SlBG4QD6jLArC/ORyJnxKFquSzNACScn/zmcDOzRXKvlwbSd893TaUFecvWSICQq3H6MCC7gpxcQts7m0DqMqFdTVm1vHqK5Gh5mtmBsvKmUVSZH7w7d28gTIpkY+GzHsWHSckOmj1FfRmeN8fmmYoFDCnu5jW2eIHgyy28= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065952; c=relaxed/simple; bh=+4df8y2p/MI9R+0ry8uI0ow98RTEWRxW2HDqEQ0Sz54=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=EIXT5ejuJ/aYGfzWZIvIWd1u/LV+YQm8rkdEAHSxS2HqwjGRynjZutbTUraKIgVc23Amh7VNEvdgDiH0IW1sg+YVicnMeP8jOu44zQf3zWodoWpQSIXz10eDIq0LJzt4YKAA+llwwTL14ZxftlP3BR+4Yc/oPaCEAP/+jxcQSSQ= 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=FmEHDMG7; 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="FmEHDMG7" 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=kMwi9DgjI7/4v55ZzZscrcyDvk5lH8JPPPnq5o6cGm4=; b=FmEHDMG7eXG0TEGGUg8tka63zK RnKBDbAXjJqpfqHBUAcPugh2cNDiWQ0po9F4c3IwIaT0Jc7gVNacP6mCQMf0yPKzqfOQfZs8IwGmv 5iKwUQQ775VWfdLlDKuT6Z/eLOdkST79naFS28AUdk0lxUjvDxginAYs5OSVEdu59EGsUO3p1PGc4 va4ORflAzosENoLy71Jw4KuKkR3poXZC93u7SrvFwMV4keO9skIW6nHStCFY8bzfBXa9kgw2HAH9g zHoxIJKJhA+iQm3bu4SUKXKDLIeymG7T13PVtH9ZYRNy2ITJsW3PtqXN/cYB6B1jGyyovMLfOo4dV uj/VJYow==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soObF-00CTwi-2s; Wed, 11 Sep 2024 16:45:41 +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 v4 07/10] tmpfs: Add casefold lookup support Date: Wed, 11 Sep 2024 11:44:59 -0300 Message-ID: <20240911144502.115260-8-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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. Signed-off-by: Andr=C3=A9 Almeida --- 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 --- mm/shmem.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 115 insertions(+), 4 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 5a77acf6ac6a..4fde63596ab3 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include "swap.h" =20 static struct vfsmount *shm_mnt __ro_after_init; @@ -123,6 +125,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 @@ -3427,6 +3431,10 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *d= ir, if (IS_ERR(inode)) return PTR_ERR(inode); =20 + if (IS_ENABLED(CONFIG_UNICODE) && + !generic_ci_validate_strict_name(dir, &dentry->d_name)) + return -EINVAL; + error =3D simple_acl_create(dir, inode); if (error) goto out_iput; @@ -3442,7 +3450,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 @@ -3533,7 +3546,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; } @@ -3553,6 +3569,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 @@ -3697,7 +3721,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 @@ -4050,6 +4077,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 { @@ -4081,9 +4111,53 @@ 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; @@ -4242,6 +4316,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 @@ -4471,6 +4552,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 @@ -4481,6 +4567,17 @@ 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, +#ifdef CONFIG_FS_ENCRYPTION + .d_revalidate =3D fscrypt_d_revalidate, +#endif + .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; @@ -4515,9 +4612,21 @@ 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; + +#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; + } #else - sb->s_flags |=3D SB_NOUSER; + sb->s_d_op =3D &simple_dentry_operations; #endif + +#else + sb->s_flags |=3D SB_NOUSER; +#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; @@ -4791,6 +4900,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 Sat Nov 30 03:46:46 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 D2F6E1AAE08; Wed, 11 Sep 2024 14:45:53 +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=1726065955; cv=none; b=tr5qHKka7biWOd6oN20HIPHF4IA2SJARyxX8Okvc57GrnGyWPN3fvi8yschUtPbMnLeWMR2bQZrKTWNLCyE6arEaHxz9JHsP1JeTzOSZ5evVYmczb5jHyy+BSzyc67lFK6VfxFeK+rxM0EmngxDvxqeWeuFT2QWsgU/o+KXLAVg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065955; c=relaxed/simple; bh=bdlgvEgcilJq6nkpwK/PfnN3kvplmyyOlL4uBaGZBY8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Xv0g7clS4CdxSAt6qHP5O2yNZVk3tdshZ3orsXsxgW2Mz3zl+vNXz+oBkbNxFPEtLNj3xNs3rxFBLSXFXPKsc78Iy2fRlvhG6N+4TZTJITpAsyY1breI4lO1HsGEqk0jurdQSu9UIYFA3zzSoP6mZG5cHBEat8Yb2OdjW3yYJwE= 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=A7Dg7fX5; 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="A7Dg7fX5" 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=pWMEhCsmENMz2YxsCsMAnt8xrE5QYXGLyTRuCLCRswY=; b=A7Dg7fX5KbF29tj/ZUs7s1d8xF LoxB0wt7OWD8cD2bQkKQ6V+iZ+jAqU19nbtnKGvoTUunl0XyHT1UeJyM4KPnPIYCzQ0CkkuBtYJXa dALijuXnTc9DQl9TmwyAdwExS8sEjAKLN4mHvjmVHpEKJ2FkIjycdHCqWCHMqGIKL4d6zdbvpyPDF 2uepRXkz3ah0siPKv5m14Ad3246xMxJCIU5UlL3zZrLFbHgFXz+brqy3forjWy47mLkofoc3P+gN2 vG0fJs7j4lty9DDtMyOeYrXfG3j0RqJ7miKvVKihcaDQwaXfFPIwVdLEKJvrJYs2hDM6s2li2bFv0 cVRIaV0A==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soObJ-00CTwi-FK; Wed, 11 Sep 2024 16:45:45 +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 v4 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs Date: Wed, 11 Sep 2024 11:45:00 -0300 Message-ID: <20240911144502.115260-9-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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 1d06b1e5408a..8367ca2b99d9 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 4fde63596ab3..fc0e0cd46146 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -2613,13 +2613,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; @@ -2630,10 +2679,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 @@ -2680,7 +2731,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); @@ -3789,16 +3840,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 Sat Nov 30 03:46:46 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 AA4FD1B150C; Wed, 11 Sep 2024 14:45:57 +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=1726065959; cv=none; b=eO1iJaBGN5qXjmFeb/UPlTz7D7Aax1tIsZph5Hq+HDjYjwiXWsKRC/8w0s15aw99uhTFImX/HxwcvvdWCB5xWuoI2mSBjRmTnUC3bHp76dL34DFehvOKU5zgU5q5wtz5a98zt1xwzlDsNilU8YcTXUIV2gdyYLajepAQKdjMaG8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065959; c=relaxed/simple; bh=bT2/q19cnNS7Q7W80DiDSRZZ6L7hZi9AEaHQUixUSXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=N+6roLYGhb625BqoZJW0VQ6GQDeem4lvZ6ltTwz7+kL9XTaQCj9kpFqC5FZYe7z5eq7E2bojSbqiaRXGLICUgUZPlgNZeCwusJrfRaXQ1cN351IjzOjQZNm4q+eT0KU+UfhwDpXrzzUqkftijvI40UXrf/GqUEDOZbqBEPnH8pA= 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=ViLjtovm; 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="ViLjtovm" 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=pK8srYuw9wrv3ZwJYkO0PSANkqjQtOsAR4zsFhEgnYA=; b=ViLjtovm9+jx46z9NAxTCgvkry 83+J+2uzaaR+6xtpgGNpGwxlNqYrbscclmySVeWUNc4M5x0NRA9qyA3DeINjEBW6m0KO3tqeFh1i9 WVU+dRvo8ovMdPLU+s07ZLsiMEvkNgpR2DVKPAwbjco4llsIwnDSbT+IAW7LNf7sn/JRDex/60WoS t9QbIB8RcRheSXc21NUKmn5X2NUGj2746kiav+LMMSeb5OWIpr5kXyTG9rnVDMOTMC9VnwYgdExG+ GNBUguE2FMSA4DwzRxkh0QSnSeH36bJdhW6Y0TkedAwpFRhEQymVXoLOoRVglEoMMJnJjyC4EeR8n NBePUPYA==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soObN-00CTwi-Jj; Wed, 11 Sep 2024 16:45:50 +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 v4 09/10] tmpfs: Expose filesystem features via sysfs Date: Wed, 11 Sep 2024 11:45:01 -0300 Message-ID: <20240911144502.115260-10-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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 fc0e0cd46146..7e7e2461a314 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -5401,3 +5401,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 Sat Nov 30 03:46:46 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 7542F1B2EC2; Wed, 11 Sep 2024 14:46:02 +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=1726065963; cv=none; b=kB82uJMQvqRGBxHDQWU4iBWZhpo4JwTSHWd/XJLxVp10161InYojdtaIRXWvlZz/e5GUfcmIY5E5vprJJwr6YdU2Y9baAFCPVQsBHnpHcwgu1xNLelbkv3Iy0KaYizUg7pJTtNEMlApSUGBdzTQ+ARS2fYp5n9vvz6oGQQ3hWEw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726065963; c=relaxed/simple; bh=tAhx4WtHwtNNtqBtA6C9IS/6URDL5GzuezIWXIWXOJ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JV+8xFYUahd7V3MjwoypKLclEzeoBTM0857ei/D49A5It1w5Ek4rojiaX3ZGmb4hVKIYCo51wfuxIAUl9fZVCbQVwatHPcuTGBf27iDKorKxX4l+xGbkwOCNCN2jYuCfog4ypEX1x44EaHCThptTgOGqCo49P+Bm163Jk/in5qQ= 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=f8TRd/op; 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="f8TRd/op" 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=ZrWTg49UzMkjH8qd8vKX5SzyF13hb+rnSQKtHmhmDkI=; b=f8TRd/opCrY9v2ZjWMMp83cRTL K8o057bdo7X+rtob6NwPA+uNCqwDbmAUYFeIZd6ShwqIRTBRRgq/TkNEG8FpwNDUl61n13XXNjRfo L/wvYEiBYcPJ275FTVs6AoJ1R55b4O7yXher5u36fgakVeVl/A7tEmS9ahsG3H6xcgbgthySTSrHD ba2x2Az6gGYRk9WHA/sB3qy5rbduq6QgwF4cZ8zD/lxKMxVreJwGZlG/NwU11Rd1vUKu3jJBjYuXr ChfM17dfstrvbewzcKEifKQ2ILLXzPsc4Hz+qOEnh6qBLVhaLiAi76y5NeURt73wDP7P0pLjMh4ZC apRs/NMA==; Received: from [177.172.122.98] (helo=localhost.localdomain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1soObR-00CTwi-OM; Wed, 11 Sep 2024 16:45:54 +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 v4 10/10] docs: tmpfs: Add casefold options Date: Wed, 11 Sep 2024 11:45:02 -0300 Message-ID: <20240911144502.115260-11-andrealmeid@igalia.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240911144502.115260-1-andrealmeid@igalia.com> References: <20240911144502.115260-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..f72fcc0baef3 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 will 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