Skip to content

Commit 632f405

Browse files
krisman-at-collaborabrauner
authored andcommitted
f2fs: Simplify the handling of cached casefolded names
Keeping it as qstr avoids the unnecessary conversion in f2fs_match Signed-off-by: Gabriel Krisman Bertazi <[email protected]> [[email protected]: port to 6.10-rc1 and minor changes] 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]>
1 parent f776f02 commit 632f405

File tree

3 files changed

+46
-32
lines changed

3 files changed

+46
-32
lines changed

fs/f2fs/dir.c

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,35 +42,49 @@ static unsigned int bucket_blocks(unsigned int level)
4242
return 4;
4343
}
4444

45+
#if IS_ENABLED(CONFIG_UNICODE)
4546
/* If @dir is casefolded, initialize @fname->cf_name from @fname->usr_fname. */
4647
int f2fs_init_casefolded_name(const struct inode *dir,
4748
struct f2fs_filename *fname)
4849
{
49-
#if IS_ENABLED(CONFIG_UNICODE)
5050
struct super_block *sb = dir->i_sb;
51+
unsigned char *buf;
52+
int len;
5153

5254
if (IS_CASEFOLDED(dir) &&
5355
!is_dot_dotdot(fname->usr_fname->name, fname->usr_fname->len)) {
54-
fname->cf_name.name = f2fs_kmem_cache_alloc(f2fs_cf_name_slab,
55-
GFP_NOFS, false, F2FS_SB(sb));
56-
if (!fname->cf_name.name)
56+
buf = f2fs_kmem_cache_alloc(f2fs_cf_name_slab,
57+
GFP_NOFS, false, F2FS_SB(sb));
58+
if (!buf)
5759
return -ENOMEM;
58-
fname->cf_name.len = utf8_casefold(sb->s_encoding,
59-
fname->usr_fname,
60-
fname->cf_name.name,
61-
F2FS_NAME_LEN);
62-
if ((int)fname->cf_name.len <= 0) {
63-
kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name);
64-
fname->cf_name.name = NULL;
60+
61+
len = utf8_casefold(sb->s_encoding, fname->usr_fname,
62+
buf, F2FS_NAME_LEN);
63+
if (len <= 0) {
64+
kmem_cache_free(f2fs_cf_name_slab, buf);
6565
if (sb_has_strict_encoding(sb))
6666
return -EINVAL;
6767
/* fall back to treating name as opaque byte sequence */
68+
return 0;
6869
}
70+
fname->cf_name.name = buf;
71+
fname->cf_name.len = len;
6972
}
70-
#endif
73+
7174
return 0;
7275
}
7376

77+
void f2fs_free_casefolded_name(struct f2fs_filename *fname)
78+
{
79+
unsigned char *buf = (unsigned char *)fname->cf_name.name;
80+
81+
if (buf) {
82+
kmem_cache_free(f2fs_cf_name_slab, buf);
83+
fname->cf_name.name = NULL;
84+
}
85+
}
86+
#endif /* CONFIG_UNICODE */
87+
7488
static int __f2fs_setup_filename(const struct inode *dir,
7589
const struct fscrypt_name *crypt_name,
7690
struct f2fs_filename *fname)
@@ -142,12 +156,7 @@ void f2fs_free_filename(struct f2fs_filename *fname)
142156
kfree(fname->crypto_buf.name);
143157
fname->crypto_buf.name = NULL;
144158
#endif
145-
#if IS_ENABLED(CONFIG_UNICODE)
146-
if (fname->cf_name.name) {
147-
kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name);
148-
fname->cf_name.name = NULL;
149-
}
150-
#endif
159+
f2fs_free_casefolded_name(fname);
151160
}
152161

153162
static unsigned long dir_block_index(unsigned int level,
@@ -235,11 +244,9 @@ static inline int f2fs_match_name(const struct inode *dir,
235244
struct fscrypt_name f;
236245

237246
#if IS_ENABLED(CONFIG_UNICODE)
238-
if (fname->cf_name.name) {
239-
struct qstr cf = FSTR_TO_QSTR(&fname->cf_name);
240-
241-
return f2fs_match_ci_name(dir, &cf, de_name, de_name_len);
242-
}
247+
if (fname->cf_name.name)
248+
return f2fs_match_ci_name(dir, &fname->cf_name,
249+
de_name, de_name_len);
243250
#endif
244251
f.usr_fname = fname->usr_fname;
245252
f.disk_name = fname->disk_name;

fs/f2fs/f2fs.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ struct f2fs_filename {
531531
* internal operation where usr_fname is also NULL. In all these cases
532532
* we fall back to treating the name as an opaque byte sequence.
533533
*/
534-
struct fscrypt_str cf_name;
534+
struct qstr cf_name;
535535
#endif
536536
};
537537

@@ -3533,8 +3533,22 @@ int f2fs_get_tmpfile(struct mnt_idmap *idmap, struct inode *dir,
35333533
/*
35343534
* dir.c
35353535
*/
3536+
#if IS_ENABLED(CONFIG_UNICODE)
35363537
int f2fs_init_casefolded_name(const struct inode *dir,
35373538
struct f2fs_filename *fname);
3539+
void f2fs_free_casefolded_name(struct f2fs_filename *fname);
3540+
#else
3541+
static inline int f2fs_init_casefolded_name(const struct inode *dir,
3542+
struct f2fs_filename *fname)
3543+
{
3544+
return 0;
3545+
}
3546+
3547+
static inline void f2fs_free_casefolded_name(struct f2fs_filename *fname)
3548+
{
3549+
}
3550+
#endif /* CONFIG_UNICODE */
3551+
35383552
int f2fs_setup_filename(struct inode *dir, const struct qstr *iname,
35393553
int lookup, struct f2fs_filename *fname);
35403554
int f2fs_prepare_lookup(struct inode *dir, struct dentry *dentry,

fs/f2fs/recovery.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@
4646

4747
static struct kmem_cache *fsync_entry_slab;
4848

49-
#if IS_ENABLED(CONFIG_UNICODE)
50-
extern struct kmem_cache *f2fs_cf_name_slab;
51-
#endif
52-
5349
bool f2fs_space_for_roll_forward(struct f2fs_sb_info *sbi)
5450
{
5551
s64 nalloc = percpu_counter_sum_positive(&sbi->alloc_valid_block_count);
@@ -153,11 +149,8 @@ static int init_recovered_filename(const struct inode *dir,
153149
if (err)
154150
return err;
155151
f2fs_hash_filename(dir, fname);
156-
#if IS_ENABLED(CONFIG_UNICODE)
157152
/* Case-sensitive match is fine for recovery */
158-
kmem_cache_free(f2fs_cf_name_slab, fname->cf_name.name);
159-
fname->cf_name.name = NULL;
160-
#endif
153+
f2fs_free_casefolded_name(fname);
161154
} else {
162155
f2fs_hash_filename(dir, fname);
163156
}

0 commit comments

Comments
 (0)