Re: [PATCH] ext4: Use generic casefolding support

2020-10-29 Thread Theodore Y. Ts'o
On Wed, Oct 28, 2020 at 05:08:20AM +, Daniel Rosenberg wrote:
> This switches ext4 over to the generic support provided in libfs.
> 
> Since casefolded dentries behave the same in ext4 and f2fs, we decrease
> the maintenance burden by unifying them, and any optimizations will
> immediately apply to both.
> 
> Signed-off-by: Daniel Rosenberg 
> Reviewed-by: Eric Biggers 

Applied, thanks.

- Ted


[PATCH] ext4: Use generic casefolding support

2020-10-28 Thread Daniel Rosenberg
This switches ext4 over to the generic support provided in libfs.

Since casefolded dentries behave the same in ext4 and f2fs, we decrease
the maintenance burden by unifying them, and any optimizations will
immediately apply to both.

Signed-off-by: Daniel Rosenberg 
Reviewed-by: Eric Biggers 
---
 fs/ext4/dir.c   | 64 ++---
 fs/ext4/ext4.h  | 12 --
 fs/ext4/hash.c  |  2 +-
 fs/ext4/namei.c | 20 +++-
 fs/ext4/super.c | 12 +-
 5 files changed, 17 insertions(+), 93 deletions(-)

diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index 5b81f3b080ee..ca50c90adc4c 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -669,68 +669,8 @@ const struct file_operations ext4_dir_operations = {
 };
 
 #ifdef CONFIG_UNICODE
-static int ext4_d_compare(const struct dentry *dentry, unsigned int len,
- const char *str, const struct qstr *name)
-{
-   struct qstr qstr = {.name = str, .len = len };
-   const struct dentry *parent = READ_ONCE(dentry->d_parent);
-   const struct inode *inode = d_inode_rcu(parent);
-   char strbuf[DNAME_INLINE_LEN];
-
-   if (!inode || !IS_CASEFOLDED(inode) ||
-   !EXT4_SB(inode->i_sb)->s_encoding) {
-   if (len != name->len)
-   return -1;
-   return memcmp(str, name->name, len);
-   }
-
-   /*
-* If the dentry name is stored in-line, then it may be concurrently
-* modified by a rename.  If this happens, the VFS will eventually retry
-* the lookup, so it doesn't matter what ->d_compare() returns.
-* However, it's unsafe to call utf8_strncasecmp() with an unstable
-* string.  Therefore, we have to copy the name into a temporary buffer.
-*/
-   if (len <= DNAME_INLINE_LEN - 1) {
-   memcpy(strbuf, str, len);
-   strbuf[len] = 0;
-   qstr.name = strbuf;
-   /* prevent compiler from optimizing out the temporary buffer */
-   barrier();
-   }
-
-   return ext4_ci_compare(inode, name, , false);
-}
-
-static int ext4_d_hash(const struct dentry *dentry, struct qstr *str)
-{
-   const struct ext4_sb_info *sbi = EXT4_SB(dentry->d_sb);
-   const struct unicode_map *um = sbi->s_encoding;
-   const struct inode *inode = d_inode_rcu(dentry);
-   unsigned char *norm;
-   int len, ret = 0;
-
-   if (!inode || !IS_CASEFOLDED(inode) || !um)
-   return 0;
-
-   norm = kmalloc(PATH_MAX, GFP_ATOMIC);
-   if (!norm)
-   return -ENOMEM;
-
-   len = utf8_casefold(um, str, norm, PATH_MAX);
-   if (len < 0) {
-   if (ext4_has_strict_mode(sbi))
-   ret = -EINVAL;
-   goto out;
-   }
-   str->hash = full_name_hash(dentry, norm, len);
-out:
-   kfree(norm);
-   return ret;
-}
-
 const struct dentry_operations ext4_dentry_ops = {
-   .d_hash = ext4_d_hash,
-   .d_compare = ext4_d_compare,
+   .d_hash = generic_ci_d_hash,
+   .d_compare = generic_ci_d_compare,
 };
 #endif
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 254d1c26bea8..662d0f40431e 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -1443,14 +1443,6 @@ struct ext4_super_block {
 
 #define EXT4_ENC_UTF8_12_1 1
 
-/*
- * Flags for ext4_sb_info.s_encoding_flags.
- */
-#define EXT4_ENC_STRICT_MODE_FL(1 << 0)
-
-#define ext4_has_strict_mode(sbi) \
-   (sbi->s_encoding_flags & EXT4_ENC_STRICT_MODE_FL)
-
 /*
  * fourth extended-fs super-block data in memory
  */
@@ -1500,10 +1492,6 @@ struct ext4_sb_info {
struct kobject s_kobj;
struct completion s_kobj_unregister;
struct super_block *s_sb;
-#ifdef CONFIG_UNICODE
-   struct unicode_map *s_encoding;
-   __u16 s_encoding_flags;
-#endif
 
/* Journaling */
struct journal_s *s_journal;
diff --git a/fs/ext4/hash.c b/fs/ext4/hash.c
index 2924261226e0..a92eb79de0cc 100644
--- a/fs/ext4/hash.c
+++ b/fs/ext4/hash.c
@@ -275,7 +275,7 @@ int ext4fs_dirhash(const struct inode *dir, const char 
*name, int len,
   struct dx_hash_info *hinfo)
 {
 #ifdef CONFIG_UNICODE
-   const struct unicode_map *um = EXT4_SB(dir->i_sb)->s_encoding;
+   const struct unicode_map *um = dir->i_sb->s_encoding;
int r, dlen;
unsigned char *buff;
struct qstr qstr = {.name = name, .len = len };
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index 5159830dacb8..f458d1d81d96 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -1285,8 +1285,8 @@ static void dx_insert_block(struct dx_frame *frame, u32 
hash, ext4_lblk_t block)
 int ext4_ci_compare(const struct inode *parent, const struct qstr *name,
const struct qstr *entry, bool quick)
 {
-   const struct ext4_sb_info *sbi = EXT4_SB(parent->i_sb);
-   const struct unicode_map *um = sbi->s_encoding;
+   const struct super_block *sb = parent->i_sb;
+