Skip to content

Commit

Permalink
ext4: Simplify the handling of cached casefolded names
Browse files Browse the repository at this point in the history
Keeping it as qstr avoids the unnecessary conversion in ext4_match

Signed-off-by: Gabriel Krisman Bertazi <[email protected]>
[[email protected]: port to 6.10-rc1]
Signed-off-by: Eugen Hristev <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Eric Biggers <[email protected]>
Reviewed-by: Gabriel Krisman Bertazi <[email protected]>
Signed-off-by: Christian Brauner <[email protected]>
  • Loading branch information
krisman-at-collabora authored and brauner committed Jun 7, 2024
1 parent 1613e60 commit f776f02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion fs/ext4/ext4.h
Original file line number Diff line number Diff line change
Expand Up @@ -2511,7 +2511,7 @@ struct ext4_filename {
struct fscrypt_str crypto_buf;
#endif
#if IS_ENABLED(CONFIG_UNICODE)
struct fscrypt_str cf_name;
struct qstr cf_name;
#endif
};

Expand Down
23 changes: 11 additions & 12 deletions fs/ext4/namei.c
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,8 @@ static int ext4_ci_compare(const struct inode *parent, const struct qstr *name,
int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname,
struct ext4_filename *name)
{
struct fscrypt_str *cf_name = &name->cf_name;
struct qstr *cf_name = &name->cf_name;
unsigned char *buf;
struct dx_hash_info *hinfo = &name->hinfo;
int len;

Expand All @@ -1455,18 +1456,18 @@ int ext4_fname_setup_ci_filename(struct inode *dir, const struct qstr *iname,
return 0;
}

cf_name->name = kmalloc(EXT4_NAME_LEN, GFP_NOFS);
if (!cf_name->name)
buf = kmalloc(EXT4_NAME_LEN, GFP_NOFS);
if (!buf)
return -ENOMEM;

len = utf8_casefold(dir->i_sb->s_encoding,
iname, cf_name->name,
EXT4_NAME_LEN);
len = utf8_casefold(dir->i_sb->s_encoding, iname, buf, EXT4_NAME_LEN);
if (len <= 0) {
kfree(cf_name->name);
cf_name->name = NULL;
kfree(buf);
buf = NULL;
}
cf_name->name = buf;
cf_name->len = (unsigned) len;

if (!IS_ENCRYPTED(dir))
return 0;

Expand Down Expand Up @@ -1503,8 +1504,6 @@ static bool ext4_match(struct inode *parent,
if (IS_CASEFOLDED(parent) &&
(!IS_ENCRYPTED(parent) || fscrypt_has_encryption_key(parent))) {
if (fname->cf_name.name) {
struct qstr cf = {.name = fname->cf_name.name,
.len = fname->cf_name.len};
if (IS_ENCRYPTED(parent)) {
if (fname->hinfo.hash != EXT4_DIRENT_HASH(de) ||
fname->hinfo.minor_hash !=
Expand All @@ -1513,8 +1512,8 @@ static bool ext4_match(struct inode *parent,
return false;
}
}
return !ext4_ci_compare(parent, &cf, de->name,
de->name_len, true);
return !ext4_ci_compare(parent, &fname->cf_name,
de->name, de->name_len, true);
}
return !ext4_ci_compare(parent, fname->usr_fname, de->name,
de->name_len, false);
Expand Down

0 comments on commit f776f02

Please sign in to comment.