kernel_optimize_test/fs/ext4
Gabriel Krisman Bertazi b886ee3e77 ext4: Support case-insensitive file name lookups
This patch implements the actual support for case-insensitive file name
lookups in ext4, based on the feature bit and the encoding stored in the
superblock.

A filesystem that has the casefold feature set is able to configure
directories with the +F (EXT4_CASEFOLD_FL) attribute, enabling lookups
to succeed in that directory in a case-insensitive fashion, i.e: match
a directory entry even if the name used by userspace is not a byte per
byte match with the disk name, but is an equivalent case-insensitive
version of the Unicode string.  This operation is called a
case-insensitive file name lookup.

The feature is configured as an inode attribute applied to directories
and inherited by its children.  This attribute can only be enabled on
empty directories for filesystems that support the encoding feature,
thus preventing collision of file names that only differ by case.

* dcache handling:

For a +F directory, Ext4 only stores the first equivalent name dentry
used in the dcache. This is done to prevent unintentional duplication of
dentries in the dcache, while also allowing the VFS code to quickly find
the right entry in the cache despite which equivalent string was used in
a previous lookup, without having to resort to ->lookup().

d_hash() of casefolded directories is implemented as the hash of the
casefolded string, such that we always have a well-known bucket for all
the equivalencies of the same string. d_compare() uses the
utf8_strncasecmp() infrastructure, which handles the comparison of
equivalent, same case, names as well.

For now, negative lookups are not inserted in the dcache, since they
would need to be invalidated anyway, because we can't trust missing file
dentries.  This is bad for performance but requires some leveraging of
the vfs layer to fix.  We can live without that for now, and so does
everyone else.

* on-disk data:

Despite using a specific version of the name as the internal
representation within the dcache, the name stored and fetched from the
disk is a byte-per-byte match with what the user requested, making this
implementation 'name-preserving'. i.e. no actual information is lost
when writing to storage.

DX is supported by modifying the hashes used in +F directories to make
them case/encoding-aware.  The new disk hashes are calculated as the
hash of the full casefolded string, instead of the string directly.
This allows us to efficiently search for file names in the htree without
requiring the user to provide an exact name.

* Dealing with invalid sequences:

By default, when a invalid UTF-8 sequence is identified, ext4 will treat
it as an opaque byte sequence, ignoring the encoding and reverting to
the old behavior for that unique file.  This means that case-insensitive
file name lookup will not work only for that file.  An optional bit can
be set in the superblock telling the filesystem code and userspace tools
to enforce the encoding.  When that optional bit is set, any attempt to
create a file name using an invalid UTF-8 sequence will fail and return
an error to userspace.

* Normalization algorithm:

The UTF-8 algorithms used to compare strings in ext4 is implemented
lives in fs/unicode, and is based on a previous version developed by
SGI.  It implements the Canonical decomposition (NFD) algorithm
described by the Unicode specification 12.1, or higher, combined with
the elimination of ignorable code points (NFDi) and full
case-folding (CF) as documented in fs/unicode/utf8_norm.c.

NFD seems to be the best normalization method for EXT4 because:

  - It has a lower cost than NFC/NFKC (which requires
    decomposing to NFD as an intermediary step)
  - It doesn't eliminate important semantic meaning like
    compatibility decompositions.

Although:

  - This implementation is not completely linguistic accurate, because
  different languages have conflicting rules, which would require the
  specialization of the filesystem to a given locale, which brings all
  sorts of problems for removable media and for users who use more than
  one language.

Signed-off-by: Gabriel Krisman Bertazi <krisman@collabora.co.uk>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2019-04-25 14:12:08 -04:00
..
acl.c ext4: compare old and new mode before setting update_mode flag 2018-12-10 00:22:38 -05:00
acl.h
balloc.c
bitmap.c
block_validity.c ext4: cond_resched in work-heavy group loops 2019-04-25 12:58:01 -04:00
dir.c ext4: Support case-insensitive file name lookups 2019-04-25 14:12:08 -04:00
ext4_extents.h
ext4_jbd2.c
ext4_jbd2.h Miscellaneous ext4 bug fixes for 5.1. 2019-03-24 13:41:37 -07:00
ext4.h ext4: Support case-insensitive file name lookups 2019-04-25 14:12:08 -04:00
extents_status.c ext4: use BUG() instead of BUG_ON(1) 2019-04-07 12:24:43 -04:00
extents_status.h
extents.c A large number of bug fixes and cleanups. One new feature to allow 2019-03-12 15:03:21 -07:00
file.c ext4: fix data corruption caused by unaligned direct AIO 2019-03-14 23:20:25 -04:00
fsmap.c
fsmap.h
fsync.c Revert "ext4: use ext4_write_inode() when fsyncing w/o a journal" 2019-01-31 23:41:11 -05:00
hash.c ext4: Support case-insensitive file name lookups 2019-04-25 14:12:08 -04:00
ialloc.c ext4: Support case-insensitive file name lookups 2019-04-25 14:12:08 -04:00
indirect.c ext4: cleanup bh release code in ext4_ind_remove_space() 2019-03-23 11:56:01 -04:00
inline.c ext4: Support case-insensitive file name lookups 2019-04-25 14:12:08 -04:00
inode.c ext4: Support case-insensitive file name lookups 2019-04-25 14:12:08 -04:00
ioctl.c ext4: Support case-insensitive file name lookups 2019-04-25 14:12:08 -04:00
Kconfig A large number of bug fixes and cleanups. One new feature to allow 2019-03-12 15:03:21 -07:00
Makefile
mballoc.c ext4: cond_resched in work-heavy group loops 2019-04-25 12:58:01 -04:00
mballoc.h
migrate.c ext4: clean up indentation issues, remove extraneous tabs 2018-12-04 00:16:44 -05:00
mmp.c
move_extent.c ext4: use IS_ENCRYPTED() to check encryption status 2019-01-23 23:56:43 -05:00
namei.c ext4: Support case-insensitive file name lookups 2019-04-25 14:12:08 -04:00
page-io.c A large number of bug fixes and cleanups. One new feature to allow 2019-03-12 15:03:21 -07:00
readpage.c ext4: fix prefetchw of NULL page 2019-04-07 11:54:27 -04:00
resize.c ext4: avoid drop reference to iloc.bh twice 2019-04-25 11:44:15 -04:00
super.c ext4: Support case-insensitive file name lookups 2019-04-25 14:12:08 -04:00
symlink.c
sysfs.c A large number of bug fixes and cleanups. One new feature to allow 2019-03-12 15:03:21 -07:00
truncate.h
xattr_security.c
xattr_trusted.c
xattr_user.c
xattr.c ext4: ignore e_value_offs for xattrs with value-in-ea-inode 2019-04-10 00:37:36 -04:00
xattr.h