[PATCH v8 0/9] tmpfs: Add case-insensitive support for tmpfs

André Almeida posted 9 patches 1 month ago
Documentation/filesystems/tmpfs.rst |  24 ++++
fs/ext4/namei.c                     |   5 +-
fs/libfs.c                          |  12 +-
fs/unicode/utf8-core.c              |  26 ++++
fs/unicode/utf8-selftest.c          |   3 -
include/linux/fs.h                  |  49 ++++++++
include/linux/shmem_fs.h            |   6 +-
include/linux/unicode.h             |   4 +
mm/shmem.c                          | 234 ++++++++++++++++++++++++++++++++++--
9 files changed, 340 insertions(+), 23 deletions(-)
[PATCH v8 0/9] tmpfs: Add case-insensitive support for tmpfs
Posted by André Almeida 1 month ago
Hi,

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

[1] https://lore.kernel.org/fstests/20240823173008.280917-1-andrealmeid@igalia.com/

Changes in v8:
 - Fix docs typo (Randy)
 - Consistently guard `encoding` and `strict_encoding` fields from struct
   shmem_options, so those fields only exists with CONFIG_UNICODE (Brauner)
 v7: https://lore.kernel.org/r/20241017-tonyk-tmpfs-v7-0-a9c056f8391f@igalia.com

Changes in v7:
 - Fixed generic_ci_validate_strict_name()
 - Dropped patch "tmpfs: Always set simple_dentry_operations as dentry ops"
 - Re-place generic_ci_validate_strict_name() before inode creation
 v6: https://lore.kernel.org/r/20241010-tonyk-tmpfs-v6-0-79f0ae02e4c8@igalia.com

Changes in v6:
 - Fixed kernel bot warning 'shmem_ci_dentry_ops' defined but not used
 v5: https://lore.kernel.org/lkml/20241002234444.398367-1-andrealmeid@igalia.com/

Changes in v5:
 - New patch "Always set simple_dentry_operations as dentry ops"
 - "Squashed libfs: Check for casefold dirs on simple_lookup()" into "tmpfs: Add
    casefold lookup support"
 - Fail to mount if strict_encoding is used without encoding
 - Inlined generic_ci_validate_strict_name()
 - Added IS_ENABLED(UNICODE) guards to public generic_ci_ funcs
 - Dropped .d_revalidate = fscrypt_d_revalidate, tmpfs doesn't support it
 v4: https://lore.kernel.org/lkml/20240911144502.115260-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 (9):
      libfs: Create the helper function generic_ci_validate_strict_name()
      ext4: Use generic_ci_validate_strict_name helper
      unicode: Export latest available UTF-8 version number
      unicode: Recreate utf8_parse_version()
      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                     |   5 +-
 fs/libfs.c                          |  12 +-
 fs/unicode/utf8-core.c              |  26 ++++
 fs/unicode/utf8-selftest.c          |   3 -
 include/linux/fs.h                  |  49 ++++++++
 include/linux/shmem_fs.h            |   6 +-
 include/linux/unicode.h             |   4 +
 mm/shmem.c                          | 234 ++++++++++++++++++++++++++++++++++--
 9 files changed, 340 insertions(+), 23 deletions(-)
---
base-commit: 42f7652d3eb527d03665b09edac47f85fb600924
change-id: 20241010-tonyk-tmpfs-fd4e181913d2

Best regards,
-- 
André Almeida <andrealmeid@igalia.com>

Re: [PATCH v8 0/9] tmpfs: Add case-insensitive support for tmpfs
Posted by Christian Brauner 4 weeks ago
On Mon, 21 Oct 2024 13:37:16 -0300, André Almeida wrote:
> 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.
> 
> [...]

Applied to the vfs.tmpfs branch of the vfs/vfs.git tree.
Patches in the vfs.tmpfs branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.tmpfs

[1/9] libfs: Create the helper function generic_ci_validate_strict_name()
      https://git.kernel.org/vfs/vfs/c/0e152beb5aa1
[2/9] ext4: Use generic_ci_validate_strict_name helper
      https://git.kernel.org/vfs/vfs/c/3f5ad0d21db8
[3/9] unicode: Export latest available UTF-8 version number
      https://git.kernel.org/vfs/vfs/c/04dad6c6d37d
[4/9] unicode: Recreate utf8_parse_version()
      https://git.kernel.org/vfs/vfs/c/142fa60f61f9
[5/9] libfs: Export generic_ci_ dentry functions
      https://git.kernel.org/vfs/vfs/c/458532c8dfeb
[6/9] tmpfs: Add casefold lookup support
      https://git.kernel.org/vfs/vfs/c/58e55efd6c72
[7/9] tmpfs: Add flag FS_CASEFOLD_FL support for tmpfs dirs
      https://git.kernel.org/vfs/vfs/c/5cd9aecbc72c
[8/9] tmpfs: Expose filesystem features via sysfs
      https://git.kernel.org/vfs/vfs/c/5132f08bd332
[9/9] docs: tmpfs: Add casefold options
      https://git.kernel.org/vfs/vfs/c/a713f830c903
Re: [PATCH v8 0/9] tmpfs: Add case-insensitive support for tmpfs
Posted by André Almeida 4 weeks ago
Em 28/10/2024 09:37, Christian Brauner escreveu:
> On Mon, 21 Oct 2024 13:37:16 -0300, André Almeida wrote:
>> 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.
>>
>> [...]
> 
> Applied to the vfs.tmpfs branch of the vfs/vfs.git tree.
> Patches in the vfs.tmpfs branch should appear in linux-next soon.
> 

Thanks!