* [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs
@ 2024-09-11 14:44 André Almeida
2024-09-11 14:44 ` [PATCH v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name() André Almeida
` (9 more replies)
0 siblings, 10 replies; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:44 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida
Hi,
This series is based on [0].
This patchset adds support for case-insensitive file names lookups in
tmpfs. The main difference from other casefold filesystems is that tmpfs
has no information on disk, just on RAM, so we can't use mkfs to create a
case-insensitive tmpfs. For this implementation, I opted to have a mount
option for casefolding. The rest of the patchset follows a similar approach
as ext4 and f2fs.
* Use case (from the original cover letter)
The use case for this feature is similar to the use case for ext4, to
better support compatibility layers (like Wine), particularly in
combination with sandboxing/container tools (like Flatpak). Those
containerization tools can share a subset of the host filesystem with an
application. In the container, the root directory and any parent
directories required for a shared directory are on tmpfs, with the
shared directories bind-mounted into the container's view of the
filesystem.
If the host filesystem is using case-insensitive directories, then the
application can do lookups inside those directories in a
case-insensitive way, without this needing to be implemented in
user-space. However, if the host is only sharing a subset of a
case-insensitive directory with the application, then the parent
directories of the mount point will be part of the container's root
tmpfs. When the application tries to do case-insensitive lookups of
those parent directories on a case-sensitive tmpfs, the lookup will
fail.
For example, if /srv/games is a case-insensitive directory on the host,
then applications will expect /srv/games/Steam/Half-Life and
/srv/games/steam/half-life to be interchangeable; but if the
container framework is only sharing /srv/games/Steam/Half-Life and
/srv/games/Steam/Portal (and not the rest of /srv/games) with the
container, with /srv, /srv/games and /srv/games/Steam as part of the
container's tmpfs root, then making /srv/games a case-insensitive
directory inside the container would be necessary to meet that
expectation.
* Testing
I send a patch for xfstests to enable the casefold test (generic/556) for
tmpfs.[1] The test succeed.
You can test this patchset using:
sudo mount -t tmpfs -o casefold tmpfs mnt/
And making a dir case-insensitive:
mkdir mnt/dir
chattr +F mnt/dir
[0] https://lore.kernel.org/linux-fsdevel/20210323195941.69720-1-andrealmeid@collabora.com/
[1] https://lore.kernel.org/fstests/20240823173008.280917-1-andrealmeid@igalia.com/
Changes in v4:
- Got rid of shmem_lookup() and changed simple_lookup() to cover casefold use
case
- Simplified shmem_parse_opt_casefold() and how it handle the lastest_version
option
- Simplified utf8_parse_version() to return the version in one variable instead
of three
- Rewrote part of the documentation patch
- Make sure that d_sb->s_d_op is set during mount time
- Moved `generic_ci_always_del_dentry_ops` to mm/shmem.c as `shmem_ci_dentry_ops`
v3: https://lore.kernel.org/lkml/20240905190252.461639-1-andrealmeid@igalia.com/
Changes in v3:
- Renamed utf8_check_strict_name() to generic_ci_validate_strict_name(), and
reworked the big if(...) to be more clear
- Expose the latest UTF-8 version in include/linux/unicode.h
- shmem_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
- Fixed bug when adding a non-casefold flag in a non-empty dir
v2: https://lore.kernel.org/lkml/20240902225511.757831-1-andrealmeid@igalia.com/
Changes in v2:
- Found and fixed a bug in utf8_load()
- Created a helper for checking strict file names (Krisman)
- Merged patch 1/ and 3/ together (Krisman)
- Reworded the explanation about d_compare (Krisman)
- Removed bool casefold from shmem_sb_info (Krisman)
- Reworked d_add(dentry, NULL) to be called as d_add(dentry, inode) (Krisman)
- Moved utf8_parse_version to common unicode code
- Fixed some smatch/sparse warnings (kernel test bot/Dan Carpenter)
v1: https://lore.kernel.org/linux-fsdevel/20240823173332.281211-1-andrealmeid@igalia.com/
André Almeida (10):
libfs: Create the helper function generic_ci_validate_strict_name()
ext4: Use generic_ci_validate_strict_name helper
unicode: Recreate utf8_parse_version()
unicode: Export latest available UTF-8 version number
libfs: Check for casefold dirs on simple_lookup()
libfs: Export generic_ci_ dentry functions
tmpfs: Add casefold lookup support
tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs
tmpfs: Expose filesystem features via sysfs
docs: tmpfs: Add casefold options
Documentation/filesystems/tmpfs.rst | 24 +++
fs/ext4/namei.c | 3 +-
fs/libfs.c | 50 +++++-
fs/unicode/utf8-core.c | 26 ++++
fs/unicode/utf8-selftest.c | 3 -
include/linux/fs.h | 4 +
include/linux/shmem_fs.h | 6 +-
include/linux/unicode.h | 4 +
mm/shmem.c | 226 ++++++++++++++++++++++++++--
9 files changed, 325 insertions(+), 21 deletions(-)
--
2.46.0
^ permalink raw reply [flat|nested] 23+ messages in thread
* [PATCH v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name()
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
@ 2024-09-11 14:44 ` André Almeida
2024-09-12 19:16 ` Gabriel Krisman Bertazi
2024-09-11 14:44 ` [PATCH v4 02/10] ext4: Use generic_ci_validate_strict_name helper André Almeida
` (8 subsequent siblings)
9 siblings, 1 reply; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:44 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida, Gabriel Krisman Bertazi
Create a helper function for filesystems do the checks required for
casefold directories and strict encoding.
Suggested-by: Gabriel Krisman Bertazi <gabriel@krisman.be>
Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
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
#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 *parent,
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);
static inline bool sb_has_encoding(const struct super_block *sb)
{
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 02/10] ext4: Use generic_ci_validate_strict_name helper
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
2024-09-11 14:44 ` [PATCH v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name() André Almeida
@ 2024-09-11 14:44 ` André Almeida
2024-09-12 19:14 ` Gabriel Krisman Bertazi
2024-09-11 14:44 ` [PATCH v4 03/10] unicode: Recreate utf8_parse_version() André Almeida
` (7 subsequent siblings)
9 siblings, 1 reply; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:44 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida, Gabriel Krisman Bertazi
Use the helper function to check the requirements for casefold
directories using strict encoding.
Suggested-by: Gabriel Krisman Bertazi <gabriel@krisman.be>
Signed-off-by: André Almeida <andrealmeid@igalia.com>
Acked-by: Theodore Ts'o <tytso@mit.edu>
---
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 dentry *dentry,
return -ENOKEY;
#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
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 03/10] unicode: Recreate utf8_parse_version()
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
2024-09-11 14:44 ` [PATCH v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name() André Almeida
2024-09-11 14:44 ` [PATCH v4 02/10] ext4: Use generic_ci_validate_strict_name helper André Almeida
@ 2024-09-11 14:44 ` André Almeida
2024-09-12 19:14 ` Gabriel Krisman Bertazi
2024-09-11 14:44 ` [PATCH v4 04/10] unicode: Export latest available UTF-8 version number André Almeida
` (6 subsequent siblings)
9 siblings, 1 reply; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:44 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida
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é Almeida <andrealmeid@igalia.com>
Reviewed-by: Theodore Ts'o <tytso@mit.edu>
---
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);
+/**
+ * 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[] = {
+ {1, "%d.%d.%d"},
+ {0, NULL}
+ };
+
+ if (match_token(version, token, args) != 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, const void *salt,
struct unicode_map *utf8_load(unsigned int version);
void utf8_unload(struct unicode_map *um);
+int utf8_parse_version(char *version);
+
#endif /* _LINUX_UNICODE_H */
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 04/10] unicode: Export latest available UTF-8 version number
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
` (2 preceding siblings ...)
2024-09-11 14:44 ` [PATCH v4 03/10] unicode: Recreate utf8_parse_version() André Almeida
@ 2024-09-11 14:44 ` André Almeida
2024-09-11 14:44 ` [PATCH v4 05/10] libfs: Check for casefold dirs on simple_lookup() André Almeida
` (5 subsequent siblings)
9 siblings, 0 replies; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:44 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida, Gabriel Krisman Bertazi
Export latest available UTF-8 version number so filesystems can easily
load the newest one.
Signed-off-by: André Almeida <andrealmeid@igalia.com>
Acked-by: Gabriel Krisman Bertazi <krisman@suse.de>
---
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;
-/* 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)))
+#define UTF8_LATEST UNICODE_AGE(12, 1, 0)
+
static inline u8 unicode_major(unsigned int age)
{
return (age >> UNICODE_MAJ_SHIFT) & 0xff;
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 05/10] libfs: Check for casefold dirs on simple_lookup()
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
` (3 preceding siblings ...)
2024-09-11 14:44 ` [PATCH v4 04/10] unicode: Export latest available UTF-8 version number André Almeida
@ 2024-09-11 14:44 ` André Almeida
2024-09-11 14:44 ` [PATCH v4 06/10] libfs: Export generic_ci_ dentry functions André Almeida
` (4 subsequent siblings)
9 siblings, 0 replies; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:44 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida
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é Almeida <andrealmeid@igalia.com>
---
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 dentry *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;
}
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 06/10] libfs: Export generic_ci_ dentry functions
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
` (4 preceding siblings ...)
2024-09-11 14:44 ` [PATCH v4 05/10] libfs: Check for casefold dirs on simple_lookup() André Almeida
@ 2024-09-11 14:44 ` André Almeida
2024-09-12 19:13 ` Gabriel Krisman Bertazi
2024-09-11 14:44 ` [PATCH v4 07/10] tmpfs: Add casefold lookup support André Almeida
` (3 subsequent siblings)
9 siblings, 1 reply; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:44 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida
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é Almeida <andrealmeid@igalia.com>
---
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,
return utf8_strncasecmp(dentry->d_sb->s_encoding, name, &qstr);
}
+EXPORT_SYMBOL(generic_ci_d_compare);
/**
* generic_ci_d_hash - generic d_hash implementation for casefolding filesystems
@@ -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 = READ_ONCE(dentry->d_inode);
struct super_block *sb = dentry->d_sb;
@@ -1850,6 +1851,7 @@ static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str)
return -EINVAL;
return 0;
}
+EXPORT_SYMBOL(generic_ci_d_hash);
static const struct dentry_operations generic_ci_dentry_ops = {
.d_hash = 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 *parent,
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);
static inline bool sb_has_encoding(const struct super_block *sb)
{
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 07/10] tmpfs: Add casefold lookup support
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
` (5 preceding siblings ...)
2024-09-11 14:44 ` [PATCH v4 06/10] libfs: Export generic_ci_ dentry functions André Almeida
@ 2024-09-11 14:44 ` André Almeida
2024-09-12 19:04 ` Gabriel Krisman Bertazi
` (2 more replies)
2024-09-11 14:45 ` [PATCH v4 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs André Almeida
` (2 subsequent siblings)
9 siblings, 3 replies; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:44 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida
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=utf8-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=utf8-12.1.0,strict_encoding fs_name mount_dir/
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é Almeida <andrealmeid@igalia.com>
---
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 <linux/fs_parser.h>
#include <linux/swapfile.h>
#include <linux/iversion.h>
+#include <linux/unicode.h>
+#include <linux/parser.h>
#include "swap.h"
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 *dir,
if (IS_ERR(inode))
return PTR_ERR(inode);
+ if (IS_ENABLED(CONFIG_UNICODE) &&
+ !generic_ci_validate_strict_name(dir, &dentry->d_name))
+ return -EINVAL;
+
error = simple_acl_create(dir, inode);
if (error)
goto out_iput;
@@ -3442,7 +3450,12 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir,
dir->i_size += 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;
@@ -3533,7 +3546,10 @@ static int shmem_link(struct dentry *old_dentry, struct 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 dentry *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;
}
@@ -3697,7 +3721,10 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
dir->i_size += 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;
@@ -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,
};
static const struct constant_table shmem_param_enums_huge[] = {
@@ -4081,9 +4111,53 @@ const struct fs_parameter_spec shmem_fs_parameters[] = {
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),
{}
};
+#if IS_ENABLED(CONFIG_UNICODE)
+static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_parameter *param,
+ bool latest_version)
+{
+ struct shmem_options *ctx = fc->fs_private;
+ unsigned int version = UTF8_LATEST;
+ struct unicode_map *encoding;
+ char *version_str = 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 number>");
+
+ version = utf8_parse_version(version_str);
+ if (version < 0)
+ return invalfc(fc, "Invalid UTF-8 version: %s", version_str);
+ }
+
+ encoding = 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 = encoding;
+
+ return 0;
+}
+#else
+static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_parameter *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 *param)
{
struct shmem_options *ctx = fc->fs_private;
@@ -4242,6 +4316,13 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
"Group quota inode hardlimit too large.");
ctx->qlimits.grpquota_ihardlimit = 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 = true;
+ break;
}
return 0;
@@ -4471,6 +4552,11 @@ static void shmem_put_super(struct super_block *sb)
{
struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
+#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 = NULL;
}
+#if IS_ENABLED(CONFIG_UNICODE)
+static const struct dentry_operations shmem_ci_dentry_ops = {
+ .d_hash = generic_ci_d_hash,
+ .d_compare = generic_ci_d_compare,
+#ifdef CONFIG_FS_ENCRYPTION
+ .d_revalidate = fscrypt_d_revalidate,
+#endif
+ .d_delete = always_delete_dentry,
+};
+#endif
+
static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
{
struct shmem_options *ctx = fc->fs_private;
@@ -4515,9 +4612,21 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
}
sb->s_export_op = &shmem_export_ops;
sb->s_flags |= SB_NOSEC | SB_I_VERSION;
+
+#if IS_ENABLED(CONFIG_UNICODE)
+ if (ctx->encoding) {
+ sb->s_encoding = ctx->encoding;
+ sb->s_d_op = &shmem_ci_dentry_ops;
+ if (ctx->strict_encoding)
+ sb->s_encoding_flags = SB_ENC_STRICT_MODE_FL;
+ }
#else
- sb->s_flags |= SB_NOUSER;
+ sb->s_d_op = &simple_dentry_operations;
#endif
+
+#else
+ sb->s_flags |= SB_NOUSER;
+#endif /* CONFIG_TMPFS */
sbinfo->max_blocks = ctx->blocks;
sbinfo->max_inodes = ctx->inodes;
sbinfo->free_ispace = sbinfo->max_inodes * BOGO_INODE_SIZE;
@@ -4791,6 +4900,8 @@ int shmem_init_fs_context(struct fs_context *fc)
ctx->uid = current_fsuid();
ctx->gid = current_fsgid();
+ ctx->encoding = NULL;
+
fc->fs_private = ctx;
fc->ops = &shmem_fs_context_ops;
return 0;
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
` (6 preceding siblings ...)
2024-09-11 14:44 ` [PATCH v4 07/10] tmpfs: Add casefold lookup support André Almeida
@ 2024-09-11 14:45 ` André Almeida
2024-09-12 19:10 ` Gabriel Krisman Bertazi
2024-09-11 14:45 ` [PATCH v4 09/10] tmpfs: Expose filesystem features via sysfs André Almeida
2024-09-11 14:45 ` [PATCH v4 10/10] docs: tmpfs: Add casefold options André Almeida
9 siblings, 1 reply; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:45 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida
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é Almeida <andrealmeid@igalia.com>
---
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;
};
-#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_CASEFOLD_FL)
+#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL)
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, struct file *file)
#ifdef CONFIG_TMPFS_XATTR
static int shmem_initxattrs(struct inode *, const struct xattr *, void *);
+#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 added 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 fsflags,
+ struct dentry *dentry, unsigned int *i_flags)
+{
+ unsigned int old = inode->i_flags;
+ struct super_block *sb = 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 = *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 fsflags,
+ 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 fsflags)
+static int shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry)
{
unsigned int i_flags = 0;
+ int ret;
+
+ ret = shmem_inode_casefold_flags(inode, fsflags, dentry, &i_flags);
+ if (ret)
+ return ret;
if (fsflags & FS_NOATIME_FL)
i_flags |= S_NOATIME;
@@ -2630,10 +2679,12 @@ static void shmem_set_inode_flags(struct inode *inode, 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_CASEFOLD);
+
+ return 0;
}
#else
-static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags)
+static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry)
{
}
#define shmem_initxattrs NULL
@@ -2680,7 +2731,7 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap,
info->fsflags = (dir == 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 *idmap,
{
struct inode *inode = d_inode(dentry);
struct shmem_inode_info *info = SHMEM_I(inode);
+ int ret, flags;
if (fileattr_has_fsx(fa))
return -EOPNOTSUPP;
if (fa->flags & ~SHMEM_FL_USER_MODIFIABLE)
return -EOPNOTSUPP;
- info->fsflags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) |
+ flags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) |
(fa->flags & SHMEM_FL_USER_MODIFIABLE);
- shmem_set_inode_flags(inode, info->fsflags);
+ ret = shmem_set_inode_flags(inode, flags, dentry);
+
+ if (ret)
+ return ret;
+
+ info->fsflags = flags;
+
inode_set_ctime_current(inode);
inode_inc_iversion(inode);
return 0;
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 09/10] tmpfs: Expose filesystem features via sysfs
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
` (7 preceding siblings ...)
2024-09-11 14:45 ` [PATCH v4 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs André Almeida
@ 2024-09-11 14:45 ` André Almeida
2024-09-12 19:07 ` Gabriel Krisman Bertazi
2024-09-11 14:45 ` [PATCH v4 10/10] docs: tmpfs: Add casefold options André Almeida
9 siblings, 1 reply; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:45 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida
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é Almeida <andrealmeid@igalia.com>
---
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 address_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[] = {
+#if IS_ENABLED(CONFIG_UNICODE)
+ &dev_attr_casefold.attr.attr,
+#endif
+ NULL
+};
+
+static const struct attribute_group tmpfs_attribute_group = {
+ .attrs = tmpfs_attributes,
+ .name = "features"
+};
+
+static struct kobject *tmpfs_kobj;
+
+static int __init tmpfs_sysfs_init(void)
+{
+ int ret;
+
+ tmpfs_kobj = kobject_create_and_add("tmpfs", fs_kobj);
+ if (!tmpfs_kobj)
+ return -ENOMEM;
+
+ ret = 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 */
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* [PATCH v4 10/10] docs: tmpfs: Add casefold options
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
` (8 preceding siblings ...)
2024-09-11 14:45 ` [PATCH v4 09/10] tmpfs: Expose filesystem features via sysfs André Almeida
@ 2024-09-11 14:45 ` André Almeida
2024-09-12 19:07 ` Gabriel Krisman Bertazi
9 siblings, 1 reply; 23+ messages in thread
From: André Almeida @ 2024-09-11 14:45 UTC (permalink / raw)
To: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, krisman
Cc: linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o,
André Almeida
Document mounting options for casefold support in tmpfs.
Signed-off-by: André Almeida <andrealmeid@igalia.com>
---
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/filesystems/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=10G,nr_inodes=10k,mode=700 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.
+tmpfs has the following mounting options for case-insensitive lookup support:
+
+================= ==============================================================
+casefold Enable casefold support at this mount point using the given
+ 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 characters.
+================= ==============================================================
+
+This option doesn't render the entire filesystem case-insensitive. One needs 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=utf8-12.1.0,strict_encoding fs_name /mytmpfs
+ $ mount -t tmpfs -o casefold fs_name /mytmpfs
+
:Author:
Christoph Rohland <cr@sap.com>, 1.12.01
@@ -250,3 +272,5 @@ RAM/SWAP in 10240 inodes and it is only accessible by root.
KOSAKI Motohiro, 16 Mar 2010
:Updated:
Chris Down, 13 July 2020
+:Updated:
+ André Almeida, 23 Aug 2024
--
2.46.0
^ permalink raw reply related [flat|nested] 23+ messages in thread
* Re: [PATCH v4 07/10] tmpfs: Add casefold lookup support
2024-09-11 14:44 ` [PATCH v4 07/10] tmpfs: Add casefold lookup support André Almeida
@ 2024-09-12 19:04 ` Gabriel Krisman Bertazi
2024-10-02 1:40 ` André Almeida
2024-09-13 16:28 ` kernel test robot
2024-09-13 18:25 ` kernel test robot
2 siblings, 1 reply; 23+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-09-12 19:04 UTC (permalink / raw)
To: André Almeida
Cc: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o
André Almeida <andrealmeid@igalia.com> writes:
> 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.
I think this looks much better.
A few things left. First, I'd suggest you merge patch 5 and this
one. There is not much sense in keeping them separate; patch 5 is a
dependency that won't crash the build, but might cause runtime errors if anyone
cherry-picks the feature but forgets to pull it.
> 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 <linux/fs_parser.h>
> #include <linux/swapfile.h>
> #include <linux/iversion.h>
> +#include <linux/unicode.h>
> +#include <linux/parser.h>
I think you don't need this header anymore
> #include "swap.h"
>
> 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 *dir,
> if (IS_ERR(inode))
> return PTR_ERR(inode);
>
> + if (IS_ENABLED(CONFIG_UNICODE) &&
> + !generic_ci_validate_strict_name(dir, &dentry->d_name))
> + return -EINVAL;
> +
Commenting here, but this is about generic_ci_validate_strict_name. Can
you make it an inline function in the header file instead? This way you
can fold the IS_ENABLED into it and also avoid the function call.
> error = simple_acl_create(dir, inode);
> if (error)
> goto out_iput;
> @@ -3442,7 +3450,12 @@ shmem_mknod(struct mnt_idmap *idmap, struct inode *dir,
> dir->i_size += 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;
>
> @@ -3533,7 +3546,10 @@ static int shmem_link(struct dentry *old_dentry, struct 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 dentry *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;
> }
>
> @@ -3697,7 +3721,10 @@ static int shmem_symlink(struct mnt_idmap *idmap, struct inode *dir,
> dir->i_size += 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;
>
> @@ -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,
> };
>
> static const struct constant_table shmem_param_enums_huge[] = {
> @@ -4081,9 +4111,53 @@ const struct fs_parameter_spec shmem_fs_parameters[] = {
> 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),
> {}
> };
>
> +#if IS_ENABLED(CONFIG_UNICODE)
> +static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_parameter *param,
> + bool latest_version)
> +{
> + struct shmem_options *ctx = fc->fs_private;
> + unsigned int version = UTF8_LATEST;
> + struct unicode_map *encoding;
> + char *version_str = 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 number>");
> +
> + version = utf8_parse_version(version_str);
> + if (version < 0)
> + return invalfc(fc, "Invalid UTF-8 version: %s", version_str);
> + }
> +
> + encoding = 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));
bad indentation?
> + }
> +
> + pr_info("tmpfs: Using encoding : utf8-%u.%u.%u\n",
> + unicode_major(version), unicode_minor(version), unicode_rev(version));
> +
> + ctx->encoding = encoding;
> +
> + return 0;
> +}
> +#else
> +static int shmem_parse_opt_casefold(struct fs_context *fc, struct fs_parameter *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 *param)
> {
> struct shmem_options *ctx = fc->fs_private;
> @@ -4242,6 +4316,13 @@ static int shmem_parse_one(struct fs_context *fc, struct fs_parameter *param)
> "Group quota inode hardlimit too large.");
> ctx->qlimits.grpquota_ihardlimit = 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 = true;
Using strict_encoding without encoding should be explicitly forbidden.
> + break;
> }
> return 0;
>
> @@ -4471,6 +4552,11 @@ static void shmem_put_super(struct super_block *sb)
> {
> struct shmem_sb_info *sbinfo = SHMEM_SB(sb);
>
> +#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 = NULL;
> }
>
> +#if IS_ENABLED(CONFIG_UNICODE)
> +static const struct dentry_operations shmem_ci_dentry_ops = {
> + .d_hash = generic_ci_d_hash,
> + .d_compare = generic_ci_d_compare,
> +#ifdef CONFIG_FS_ENCRYPTION
> + .d_revalidate = fscrypt_d_revalidate,
> +#endif
> + .d_delete = always_delete_dentry,
> +};
> +#endif
> +
> static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
> {
> struct shmem_options *ctx = fc->fs_private;
> @@ -4515,9 +4612,21 @@ static int shmem_fill_super(struct super_block *sb, struct fs_context *fc)
> }
> sb->s_export_op = &shmem_export_ops;
> sb->s_flags |= SB_NOSEC | SB_I_VERSION;
> +
> +#if IS_ENABLED(CONFIG_UNICODE)
> + if (ctx->encoding) {
> + sb->s_encoding = ctx->encoding;
> + sb->s_d_op = &shmem_ci_dentry_ops;
> + if (ctx->strict_encoding)
> + sb->s_encoding_flags = SB_ENC_STRICT_MODE_FL;
> + }
> #else
> - sb->s_flags |= SB_NOUSER;
> + sb->s_d_op = &simple_dentry_operations;
Moving simple_dentry_operations to be set at s_d_op should be a separate
patch.
It is a change that has non-obvious side effects (i.e. the way we
treat the root dentry) so it needs proper review by itself. It is
also not related to the rest of the case-insensitive patch.
Also, why is it done only for CONFIG_UNICODE=n?
> #endif
> +
> +#else
> + sb->s_flags |= SB_NOUSER;
> +#endif /* CONFIG_TMPFS */
> sbinfo->max_blocks = ctx->blocks;
> sbinfo->max_inodes = ctx->inodes;
> sbinfo->free_ispace = sbinfo->max_inodes * BOGO_INODE_SIZE;
> @@ -4791,6 +4900,8 @@ int shmem_init_fs_context(struct fs_context *fc)
> ctx->uid = current_fsuid();
> ctx->gid = current_fsgid();
>
> + ctx->encoding = NULL;
> +
> fc->fs_private = ctx;
> fc->ops = &shmem_fs_context_ops;
> return 0;
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 10/10] docs: tmpfs: Add casefold options
2024-09-11 14:45 ` [PATCH v4 10/10] docs: tmpfs: Add casefold options André Almeida
@ 2024-09-12 19:07 ` Gabriel Krisman Bertazi
0 siblings, 0 replies; 23+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-09-12 19:07 UTC (permalink / raw)
To: André Almeida
Cc: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o
André Almeida <andrealmeid@igalia.com> writes:
> Document mounting options for casefold support in tmpfs.
>
> Signed-off-by: André Almeida <andrealmeid@igalia.com>
> ---
> 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/filesystems/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=10G,nr_inodes=10k,mode=700 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.
>
> +tmpfs has the following mounting options for case-insensitive lookup support:
> +
> +================= ==============================================================
> +casefold Enable casefold support at this mount point using the given
> + 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 characters.
> +================= ==============================================================
> +
> +This option doesn't render the entire filesystem case-insensitive. One needs 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.
s/will//
Other than that:
Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
> +
> +Example::
> +
> + $ mount -t tmpfs -o casefold=utf8-12.1.0,strict_encoding fs_name /mytmpfs
> + $ mount -t tmpfs -o casefold fs_name /mytmpfs
> +
>
> :Author:
> Christoph Rohland <cr@sap.com>, 1.12.01
> @@ -250,3 +272,5 @@ RAM/SWAP in 10240 inodes and it is only accessible by root.
> KOSAKI Motohiro, 16 Mar 2010
> :Updated:
> Chris Down, 13 July 2020
> +:Updated:
> + André Almeida, 23 Aug 2024
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 09/10] tmpfs: Expose filesystem features via sysfs
2024-09-11 14:45 ` [PATCH v4 09/10] tmpfs: Expose filesystem features via sysfs André Almeida
@ 2024-09-12 19:07 ` Gabriel Krisman Bertazi
0 siblings, 0 replies; 23+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-09-12 19:07 UTC (permalink / raw)
To: André Almeida
Cc: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o
André Almeida <andrealmeid@igalia.com> writes:
> 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.
Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs
2024-09-11 14:45 ` [PATCH v4 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs André Almeida
@ 2024-09-12 19:10 ` Gabriel Krisman Bertazi
0 siblings, 0 replies; 23+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-09-12 19:10 UTC (permalink / raw)
To: André Almeida
Cc: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o
André Almeida <andrealmeid@igalia.com> writes:
> 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.
Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
>
> Signed-off-by: André Almeida <andrealmeid@igalia.com>
> ---
> 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;
> };
>
> -#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_CASEFOLD_FL)
> +#define SHMEM_FL_INHERITED (FS_NODUMP_FL | FS_NOATIME_FL | FS_CASEFOLD_FL)
>
> 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, struct file *file)
> #ifdef CONFIG_TMPFS_XATTR
> static int shmem_initxattrs(struct inode *, const struct xattr *, void *);
>
> +#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 added 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 fsflags,
> + struct dentry *dentry, unsigned int *i_flags)
> +{
> + unsigned int old = inode->i_flags;
> + struct super_block *sb = 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 = *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 fsflags,
> + 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 fsflags)
> +static int shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry)
> {
> unsigned int i_flags = 0;
> + int ret;
> +
> + ret = shmem_inode_casefold_flags(inode, fsflags, dentry, &i_flags);
> + if (ret)
> + return ret;
>
> if (fsflags & FS_NOATIME_FL)
> i_flags |= S_NOATIME;
> @@ -2630,10 +2679,12 @@ static void shmem_set_inode_flags(struct inode *inode, 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_CASEFOLD);
> +
> + return 0;
> }
> #else
> -static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags)
> +static void shmem_set_inode_flags(struct inode *inode, unsigned int fsflags, struct dentry *dentry)
> {
> }
> #define shmem_initxattrs NULL
> @@ -2680,7 +2731,7 @@ static struct inode *__shmem_get_inode(struct mnt_idmap *idmap,
> info->fsflags = (dir == 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 *idmap,
> {
> struct inode *inode = d_inode(dentry);
> struct shmem_inode_info *info = SHMEM_I(inode);
> + int ret, flags;
>
> if (fileattr_has_fsx(fa))
> return -EOPNOTSUPP;
> if (fa->flags & ~SHMEM_FL_USER_MODIFIABLE)
> return -EOPNOTSUPP;
>
> - info->fsflags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) |
> + flags = (info->fsflags & ~SHMEM_FL_USER_MODIFIABLE) |
> (fa->flags & SHMEM_FL_USER_MODIFIABLE);
>
> - shmem_set_inode_flags(inode, info->fsflags);
> + ret = shmem_set_inode_flags(inode, flags, dentry);
> +
> + if (ret)
> + return ret;
> +
> + info->fsflags = flags;
> +
> inode_set_ctime_current(inode);
> inode_inc_iversion(inode);
> return 0;
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 06/10] libfs: Export generic_ci_ dentry functions
2024-09-11 14:44 ` [PATCH v4 06/10] libfs: Export generic_ci_ dentry functions André Almeida
@ 2024-09-12 19:13 ` Gabriel Krisman Bertazi
0 siblings, 0 replies; 23+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-09-12 19:13 UTC (permalink / raw)
To: André Almeida
Cc: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o
André Almeida <andrealmeid@igalia.com> writes:
> 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é Almeida <andrealmeid@igalia.com>
> ---
> 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,
>
> return utf8_strncasecmp(dentry->d_sb->s_encoding, name, &qstr);
> }
> +EXPORT_SYMBOL(generic_ci_d_compare);
>
> /**
> * generic_ci_d_hash - generic d_hash implementation for casefolding filesystems
> @@ -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 = READ_ONCE(dentry->d_inode);
> struct super_block *sb = dentry->d_sb;
> @@ -1850,6 +1851,7 @@ static int generic_ci_d_hash(const struct dentry *dentry, struct qstr *str)
> return -EINVAL;
> return 0;
> }
> +EXPORT_SYMBOL(generic_ci_d_hash);
>
> static const struct dentry_operations generic_ci_dentry_ops = {
> .d_hash = 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 *parent,
> 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);
guard these with:
#if IS_ENABLED(CONFIG_UNICODE)
#endif
>
> static inline bool sb_has_encoding(const struct super_block *sb)
> {
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 03/10] unicode: Recreate utf8_parse_version()
2024-09-11 14:44 ` [PATCH v4 03/10] unicode: Recreate utf8_parse_version() André Almeida
@ 2024-09-12 19:14 ` Gabriel Krisman Bertazi
0 siblings, 0 replies; 23+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-09-12 19:14 UTC (permalink / raw)
To: André Almeida
Cc: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o
André Almeida <andrealmeid@igalia.com> writes:
> 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.
Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 02/10] ext4: Use generic_ci_validate_strict_name helper
2024-09-11 14:44 ` [PATCH v4 02/10] ext4: Use generic_ci_validate_strict_name helper André Almeida
@ 2024-09-12 19:14 ` Gabriel Krisman Bertazi
0 siblings, 0 replies; 23+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-09-12 19:14 UTC (permalink / raw)
To: André Almeida
Cc: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o
André Almeida <andrealmeid@igalia.com> writes:
> Use the helper function to check the requirements for casefold
> directories using strict encoding.
Reviewed-by: Gabriel Krisman Bertazi <krisman@suse.de>
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name()
2024-09-11 14:44 ` [PATCH v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name() André Almeida
@ 2024-09-12 19:16 ` Gabriel Krisman Bertazi
0 siblings, 0 replies; 23+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-09-12 19:16 UTC (permalink / raw)
To: André Almeida
Cc: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o
André Almeida <andrealmeid@igalia.com> writes:
> Create a helper function for filesystems do the checks required for
> casefold directories and strict encoding.
>
> Suggested-by: Gabriel Krisman Bertazi <gabriel@krisman.be>
> Signed-off-by: André Almeida <andrealmeid@igalia.com>
> ---
> 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
>
> #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 *parent,
> 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);
As mentioned in the other patch, please make this an inline helper. But
also, the declaration needs to be guarded by CONFIG_UNICODE.
>
> static inline bool sb_has_encoding(const struct super_block *sb)
> {
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 07/10] tmpfs: Add casefold lookup support
2024-09-11 14:44 ` [PATCH v4 07/10] tmpfs: Add casefold lookup support André Almeida
2024-09-12 19:04 ` Gabriel Krisman Bertazi
@ 2024-09-13 16:28 ` kernel test robot
2024-09-13 18:25 ` kernel test robot
2 siblings, 0 replies; 23+ messages in thread
From: kernel test robot @ 2024-09-13 16:28 UTC (permalink / raw)
To: André Almeida, Hugh Dickins, Andrew Morton, Alexander Viro,
Christian Brauner, Jan Kara, krisman
Cc: llvm, oe-kbuild-all, Linux Memory Management List, linux-kernel,
linux-fsdevel, kernel-dev, Daniel Rosenberg, smcv,
Christoph Hellwig, Theodore Ts'o, André Almeida
Hi André,
kernel test robot noticed the following build errors:
[auto build test ERROR on akpm-mm/mm-everything]
[also build test ERROR on tytso-ext4/dev brauner-vfs/vfs.all linus/master v6.11-rc7 next-20240913]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andr-Almeida/libfs-Create-the-helper-function-generic_ci_validate_strict_name/20240911-224740
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20240911144502.115260-8-andrealmeid%40igalia.com
patch subject: [PATCH v4 07/10] tmpfs: Add casefold lookup support
config: i386-buildonly-randconfig-005-20240913 (https://download.01.org/0day-ci/archive/20240914/202409140037.lwGxfq6h-lkp@intel.com/config)
compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240914/202409140037.lwGxfq6h-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409140037.lwGxfq6h-lkp@intel.com/
All errors (new ones prefixed by >>):
>> mm/shmem.c:4723:18: error: use of undeclared identifier 'fscrypt_d_revalidate'
4723 | .d_revalidate = fscrypt_d_revalidate,
| ^
1 error generated.
vim +/fscrypt_d_revalidate +4723 mm/shmem.c
4717
4718 #if IS_ENABLED(CONFIG_UNICODE)
4719 static const struct dentry_operations shmem_ci_dentry_ops = {
4720 .d_hash = generic_ci_d_hash,
4721 .d_compare = generic_ci_d_compare,
4722 #ifdef CONFIG_FS_ENCRYPTION
> 4723 .d_revalidate = fscrypt_d_revalidate,
4724 #endif
4725 .d_delete = always_delete_dentry,
4726 };
4727 #endif
4728
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 07/10] tmpfs: Add casefold lookup support
2024-09-11 14:44 ` [PATCH v4 07/10] tmpfs: Add casefold lookup support André Almeida
2024-09-12 19:04 ` Gabriel Krisman Bertazi
2024-09-13 16:28 ` kernel test robot
@ 2024-09-13 18:25 ` kernel test robot
2 siblings, 0 replies; 23+ messages in thread
From: kernel test robot @ 2024-09-13 18:25 UTC (permalink / raw)
To: André Almeida, Hugh Dickins, Andrew Morton, Alexander Viro,
Christian Brauner, Jan Kara, krisman
Cc: oe-kbuild-all, Linux Memory Management List, linux-kernel,
linux-fsdevel, kernel-dev, Daniel Rosenberg, smcv,
Christoph Hellwig, Theodore Ts'o, André Almeida
Hi André,
kernel test robot noticed the following build warnings:
[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on tytso-ext4/dev brauner-vfs/vfs.all linus/master v6.11-rc7 next-20240913]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andr-Almeida/libfs-Create-the-helper-function-generic_ci_validate_strict_name/20240911-224740
base: https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/r/20240911144502.115260-8-andrealmeid%40igalia.com
patch subject: [PATCH v4 07/10] tmpfs: Add casefold lookup support
config: csky-randconfig-002-20240913 (https://download.01.org/0day-ci/archive/20240914/202409140236.RR9Gbvqh-lkp@intel.com/config)
compiler: csky-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240914/202409140236.RR9Gbvqh-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202409140236.RR9Gbvqh-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> mm/shmem.c:4719:39: warning: 'shmem_ci_dentry_ops' defined but not used [-Wunused-const-variable=]
4719 | static const struct dentry_operations shmem_ci_dentry_ops = {
| ^~~~~~~~~~~~~~~~~~~
vim +/shmem_ci_dentry_ops +4719 mm/shmem.c
4717
4718 #if IS_ENABLED(CONFIG_UNICODE)
> 4719 static const struct dentry_operations shmem_ci_dentry_ops = {
4720 .d_hash = generic_ci_d_hash,
4721 .d_compare = generic_ci_d_compare,
4722 #ifdef CONFIG_FS_ENCRYPTION
4723 .d_revalidate = fscrypt_d_revalidate,
4724 #endif
4725 .d_delete = always_delete_dentry,
4726 };
4727 #endif
4728
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 07/10] tmpfs: Add casefold lookup support
2024-09-12 19:04 ` Gabriel Krisman Bertazi
@ 2024-10-02 1:40 ` André Almeida
2024-10-02 21:29 ` Gabriel Krisman Bertazi
0 siblings, 1 reply; 23+ messages in thread
From: André Almeida @ 2024-10-02 1:40 UTC (permalink / raw)
To: Gabriel Krisman Bertazi
Cc: Hugh Dickins, Andrew Morton, Alexander Viro, Christian Brauner,
Jan Kara, linux-mm, linux-kernel, linux-fsdevel, kernel-dev,
Daniel Rosenberg, smcv, Christoph Hellwig, Theodore Ts'o
Hey Krisman,
Em 12/09/2024 16:04, Gabriel Krisman Bertazi escreveu:
> André Almeida <andrealmeid@igalia.com> writes:
>
[...]
>> +#if IS_ENABLED(CONFIG_UNICODE)
>> + if (ctx->encoding) {
>> + sb->s_encoding = ctx->encoding;
>> + sb->s_d_op = &shmem_ci_dentry_ops;
>> + if (ctx->strict_encoding)
>> + sb->s_encoding_flags = SB_ENC_STRICT_MODE_FL;
>> + }
>> #else
>> - sb->s_flags |= SB_NOUSER;
>> + sb->s_d_op = &simple_dentry_operations;
>
> Moving simple_dentry_operations to be set at s_d_op should be a separate
> patch.
>
> It is a change that has non-obvious side effects (i.e. the way we
> treat the root dentry) so it needs proper review by itself. It is
> also not related to the rest of the case-insensitive patch.
>
The idea of setting simple_dentry_operations come from my previous
approach of having our own shmem_lookup(), replacing simple_lookup().
Now that we are settled to keep with simple_lookup() anyway (that
already sets simple_dentry_operations), I think we don't need this
change anymore, right?
This will be set for every dentry that doesn't have a
dentry->d_sb->s_d_op. Case-insensitive mount points will have this set,
so we don't risk overwriting it.
^ permalink raw reply [flat|nested] 23+ messages in thread
* Re: [PATCH v4 07/10] tmpfs: Add casefold lookup support
2024-10-02 1:40 ` André Almeida
@ 2024-10-02 21:29 ` Gabriel Krisman Bertazi
0 siblings, 0 replies; 23+ messages in thread
From: Gabriel Krisman Bertazi @ 2024-10-02 21:29 UTC (permalink / raw)
To: André Almeida
Cc: Gabriel Krisman Bertazi, Hugh Dickins, Andrew Morton,
Alexander Viro, Christian Brauner, Jan Kara, linux-mm,
linux-kernel, linux-fsdevel, kernel-dev, Daniel Rosenberg, smcv,
Christoph Hellwig, Theodore Ts'o
André Almeida <andrealmeid@igalia.com> writes:
> Hey Krisman,
>
> Em 12/09/2024 16:04, Gabriel Krisman Bertazi escreveu:
>> André Almeida <andrealmeid@igalia.com> writes:
>>
>
> [...]
>
>>> +#if IS_ENABLED(CONFIG_UNICODE)
>>> + if (ctx->encoding) {
>>> + sb->s_encoding = ctx->encoding;
>>> + sb->s_d_op = &shmem_ci_dentry_ops;
>>> + if (ctx->strict_encoding)
>>> + sb->s_encoding_flags = SB_ENC_STRICT_MODE_FL;
>>> + }
>>> #else
>>> - sb->s_flags |= SB_NOUSER;
>>> + sb->s_d_op = &simple_dentry_operations;
>> Moving simple_dentry_operations to be set at s_d_op should be a
>> separate
>> patch.
>> It is a change that has non-obvious side effects (i.e. the way we
>> treat the root dentry) so it needs proper review by itself. It is
>> also not related to the rest of the case-insensitive patch.
>>
>
> The idea of setting simple_dentry_operations come from my previous
> approach of having our own shmem_lookup(), replacing
> simple_lookup(). Now that we are settled to keep with simple_lookup()
> anyway (that already sets simple_dentry_operations), I think we don't
> need this change anymore, right?
Up to you, really. If you don't need it to support casefold lookup in
tmpfs, it doesn't need to be part of the same patchset.
> This will be set for every dentry that doesn't have a
> dentry->d_sb->s_d_op. Case-insensitive mount points will have this set,
> so we don't risk overwriting it.
I encourage you to send a new version with this. makes sense to me.
--
Gabriel Krisman Bertazi
^ permalink raw reply [flat|nested] 23+ messages in thread
end of thread, other threads:[~2024-10-02 21:29 UTC | newest]
Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-11 14:44 [PATCH v4 00/10] tmpfs: Add case-insensitive support for tmpfs André Almeida
2024-09-11 14:44 ` [PATCH v4 01/10] libfs: Create the helper function generic_ci_validate_strict_name() André Almeida
2024-09-12 19:16 ` Gabriel Krisman Bertazi
2024-09-11 14:44 ` [PATCH v4 02/10] ext4: Use generic_ci_validate_strict_name helper André Almeida
2024-09-12 19:14 ` Gabriel Krisman Bertazi
2024-09-11 14:44 ` [PATCH v4 03/10] unicode: Recreate utf8_parse_version() André Almeida
2024-09-12 19:14 ` Gabriel Krisman Bertazi
2024-09-11 14:44 ` [PATCH v4 04/10] unicode: Export latest available UTF-8 version number André Almeida
2024-09-11 14:44 ` [PATCH v4 05/10] libfs: Check for casefold dirs on simple_lookup() André Almeida
2024-09-11 14:44 ` [PATCH v4 06/10] libfs: Export generic_ci_ dentry functions André Almeida
2024-09-12 19:13 ` Gabriel Krisman Bertazi
2024-09-11 14:44 ` [PATCH v4 07/10] tmpfs: Add casefold lookup support André Almeida
2024-09-12 19:04 ` Gabriel Krisman Bertazi
2024-10-02 1:40 ` André Almeida
2024-10-02 21:29 ` Gabriel Krisman Bertazi
2024-09-13 16:28 ` kernel test robot
2024-09-13 18:25 ` kernel test robot
2024-09-11 14:45 ` [PATCH v4 08/10] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs André Almeida
2024-09-12 19:10 ` Gabriel Krisman Bertazi
2024-09-11 14:45 ` [PATCH v4 09/10] tmpfs: Expose filesystem features via sysfs André Almeida
2024-09-12 19:07 ` Gabriel Krisman Bertazi
2024-09-11 14:45 ` [PATCH v4 10/10] docs: tmpfs: Add casefold options André Almeida
2024-09-12 19:07 ` Gabriel Krisman Bertazi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).