Skip to content

Commit eca4873

Browse files
drosen-googleJaegeuk Kim
authored andcommitted
f2fs: Use generic casefolding support
This switches f2fs over to the generic support provided in the previous patch. 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 <drosen@google.com> Reviewed-by: Eric Biggers <ebiggers@google.com> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent c843843 commit eca4873

File tree

5 files changed

+20
-91
lines changed

5 files changed

+20
-91
lines changed

fs/f2fs/dir.c

Lines changed: 9 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -75,21 +75,22 @@ int f2fs_init_casefolded_name(const struct inode *dir,
7575
struct f2fs_filename *fname)
7676
{
7777
#ifdef CONFIG_UNICODE
78-
struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
78+
struct super_block *sb = dir->i_sb;
79+
struct f2fs_sb_info *sbi = F2FS_SB(sb);
7980

8081
if (IS_CASEFOLDED(dir)) {
8182
fname->cf_name.name = f2fs_kmalloc(sbi, F2FS_NAME_LEN,
8283
GFP_NOFS);
8384
if (!fname->cf_name.name)
8485
return -ENOMEM;
85-
fname->cf_name.len = utf8_casefold(sbi->s_encoding,
86+
fname->cf_name.len = utf8_casefold(sb->s_encoding,
8687
fname->usr_fname,
8788
fname->cf_name.name,
8889
F2FS_NAME_LEN);
8990
if ((int)fname->cf_name.len <= 0) {
9091
kfree(fname->cf_name.name);
9192
fname->cf_name.name = NULL;
92-
if (f2fs_has_strict_mode(sbi))
93+
if (sb_has_strict_encoding(sb))
9394
return -EINVAL;
9495
/* fall back to treating name as opaque byte sequence */
9596
}
@@ -215,8 +216,8 @@ static struct f2fs_dir_entry *find_in_block(struct inode *dir,
215216
static bool f2fs_match_ci_name(const struct inode *dir, const struct qstr *name,
216217
const u8 *de_name, u32 de_name_len)
217218
{
218-
const struct f2fs_sb_info *sbi = F2FS_SB(dir->i_sb);
219-
const struct unicode_map *um = sbi->s_encoding;
219+
const struct super_block *sb = dir->i_sb;
220+
const struct unicode_map *um = sb->s_encoding;
220221
struct qstr entry = QSTR_INIT(de_name, de_name_len);
221222
int res;
222223

@@ -226,7 +227,7 @@ static bool f2fs_match_ci_name(const struct inode *dir, const struct qstr *name,
226227
* In strict mode, ignore invalid names. In non-strict mode,
227228
* fall back to treating them as opaque byte sequences.
228229
*/
229-
if (f2fs_has_strict_mode(sbi) || name->len != entry.len)
230+
if (sb_has_strict_encoding(sb) || name->len != entry.len)
230231
return false;
231232
return !memcmp(name->name, entry.name, name->len);
232233
}
@@ -1107,75 +1108,8 @@ const struct file_operations f2fs_dir_operations = {
11071108
};
11081109

11091110
#ifdef CONFIG_UNICODE
1110-
static int f2fs_d_compare(const struct dentry *dentry, unsigned int len,
1111-
const char *str, const struct qstr *name)
1112-
{
1113-
const struct dentry *parent = READ_ONCE(dentry->d_parent);
1114-
const struct inode *dir = READ_ONCE(parent->d_inode);
1115-
const struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
1116-
struct qstr entry = QSTR_INIT(str, len);
1117-
char strbuf[DNAME_INLINE_LEN];
1118-
int res;
1119-
1120-
if (!dir || !IS_CASEFOLDED(dir))
1121-
goto fallback;
1122-
1123-
/*
1124-
* If the dentry name is stored in-line, then it may be concurrently
1125-
* modified by a rename. If this happens, the VFS will eventually retry
1126-
* the lookup, so it doesn't matter what ->d_compare() returns.
1127-
* However, it's unsafe to call utf8_strncasecmp() with an unstable
1128-
* string. Therefore, we have to copy the name into a temporary buffer.
1129-
*/
1130-
if (len <= DNAME_INLINE_LEN - 1) {
1131-
memcpy(strbuf, str, len);
1132-
strbuf[len] = 0;
1133-
entry.name = strbuf;
1134-
/* prevent compiler from optimizing out the temporary buffer */
1135-
barrier();
1136-
}
1137-
1138-
res = utf8_strncasecmp(sbi->s_encoding, name, &entry);
1139-
if (res >= 0)
1140-
return res;
1141-
1142-
if (f2fs_has_strict_mode(sbi))
1143-
return -EINVAL;
1144-
fallback:
1145-
if (len != name->len)
1146-
return 1;
1147-
return !!memcmp(str, name->name, len);
1148-
}
1149-
1150-
static int f2fs_d_hash(const struct dentry *dentry, struct qstr *str)
1151-
{
1152-
struct f2fs_sb_info *sbi = F2FS_SB(dentry->d_sb);
1153-
const struct unicode_map *um = sbi->s_encoding;
1154-
const struct inode *inode = READ_ONCE(dentry->d_inode);
1155-
unsigned char *norm;
1156-
int len, ret = 0;
1157-
1158-
if (!inode || !IS_CASEFOLDED(inode))
1159-
return 0;
1160-
1161-
norm = f2fs_kmalloc(sbi, PATH_MAX, GFP_ATOMIC);
1162-
if (!norm)
1163-
return -ENOMEM;
1164-
1165-
len = utf8_casefold(um, str, norm, PATH_MAX);
1166-
if (len < 0) {
1167-
if (f2fs_has_strict_mode(sbi))
1168-
ret = -EINVAL;
1169-
goto out;
1170-
}
1171-
str->hash = full_name_hash(dentry, norm, len);
1172-
out:
1173-
kvfree(norm);
1174-
return ret;
1175-
}
1176-
11771111
const struct dentry_operations f2fs_dentry_ops = {
1178-
.d_hash = f2fs_d_hash,
1179-
.d_compare = f2fs_d_compare,
1112+
.d_hash = generic_ci_d_hash,
1113+
.d_compare = generic_ci_d_compare,
11801114
};
11811115
#endif

fs/f2fs/f2fs.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,10 +1414,6 @@ struct f2fs_sb_info {
14141414
int valid_super_block; /* valid super block no */
14151415
unsigned long s_flag; /* flags for sbi */
14161416
struct mutex writepages; /* mutex for writepages() */
1417-
#ifdef CONFIG_UNICODE
1418-
struct unicode_map *s_encoding;
1419-
__u16 s_encoding_flags;
1420-
#endif
14211417

14221418
#ifdef CONFIG_BLK_DEV_ZONED
14231419
unsigned int blocks_per_blkz; /* F2FS blocks per zone */

fs/f2fs/super.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ static void f2fs_put_super(struct super_block *sb)
12821282
for (i = 0; i < NR_PAGE_TYPE; i++)
12831283
kvfree(sbi->write_io[i]);
12841284
#ifdef CONFIG_UNICODE
1285-
utf8_unload(sbi->s_encoding);
1285+
utf8_unload(sb->s_encoding);
12861286
#endif
12871287
kfree(sbi);
12881288
}
@@ -3359,7 +3359,7 @@ static int f2fs_scan_devices(struct f2fs_sb_info *sbi)
33593359
static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
33603360
{
33613361
#ifdef CONFIG_UNICODE
3362-
if (f2fs_sb_has_casefold(sbi) && !sbi->s_encoding) {
3362+
if (f2fs_sb_has_casefold(sbi) && !sbi->sb->s_encoding) {
33633363
const struct f2fs_sb_encodings *encoding_info;
33643364
struct unicode_map *encoding;
33653365
__u16 encoding_flags;
@@ -3390,8 +3390,8 @@ static int f2fs_setup_casefold(struct f2fs_sb_info *sbi)
33903390
"%s-%s with flags 0x%hx", encoding_info->name,
33913391
encoding_info->version?:"\b", encoding_flags);
33923392

3393-
sbi->s_encoding = encoding;
3394-
sbi->s_encoding_flags = encoding_flags;
3393+
sbi->sb->s_encoding = encoding;
3394+
sbi->sb->s_encoding_flags = encoding_flags;
33953395
sbi->sb->s_d_op = &f2fs_dentry_ops;
33963396
}
33973397
#else
@@ -3887,7 +3887,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
38873887
kvfree(sbi->write_io[i]);
38883888

38893889
#ifdef CONFIG_UNICODE
3890-
utf8_unload(sbi->s_encoding);
3890+
utf8_unload(sb->s_encoding);
38913891
#endif
38923892
free_options:
38933893
#ifdef CONFIG_QUOTA

fs/f2fs/sysfs.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,14 @@ static ssize_t encoding_show(struct f2fs_attr *a,
176176
struct f2fs_sb_info *sbi, char *buf)
177177
{
178178
#ifdef CONFIG_UNICODE
179+
struct super_block *sb = sbi->sb;
180+
179181
if (f2fs_sb_has_casefold(sbi))
180182
return snprintf(buf, PAGE_SIZE, "%s (%d.%d.%d)\n",
181-
sbi->s_encoding->charset,
182-
(sbi->s_encoding->version >> 16) & 0xff,
183-
(sbi->s_encoding->version >> 8) & 0xff,
184-
sbi->s_encoding->version & 0xff);
183+
sb->s_encoding->charset,
184+
(sb->s_encoding->version >> 16) & 0xff,
185+
(sb->s_encoding->version >> 8) & 0xff,
186+
sb->s_encoding->version & 0xff);
185187
#endif
186188
return sprintf(buf, "(none)");
187189
}

include/linux/f2fs_fs.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@
3838
#define F2FS_MAX_QUOTAS 3
3939

4040
#define F2FS_ENC_UTF8_12_1 1
41-
#define F2FS_ENC_STRICT_MODE_FL (1 << 0)
42-
#define f2fs_has_strict_mode(sbi) \
43-
(sbi->s_encoding_flags & F2FS_ENC_STRICT_MODE_FL)
4441

4542
#define F2FS_IO_SIZE(sbi) (1 << F2FS_OPTION(sbi).write_io_size_bits) /* Blocks */
4643
#define F2FS_IO_SIZE_KB(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2)) /* KB */

0 commit comments

Comments
 (0)