Skip to content

Commit 9aad901

Browse files
chaseyuJaegeuk Kim
authored andcommitted
mkfs.f2fs: support -C [no]hashonly to control linear lookup fallback
It provides a way to disable linear lookup fallback during mkfs. Behavior summary: Android Distro By default disabled enabled Android case: 1.1) Disable linear lookup: - mkfs.f2fs -f -g android -O casefold -C utf8:hashonly /dev/vdb - dump.f2fs -d3 /dev/vdb |grep s_encoding_flags s_encoding_flags [0x 2 : 2] 1.2) Enable linear lookup: - mkfs.f2fs -f -g android -O casefold -C utf8:nohashonly /dev/vdb - dump.f2fs -d3 /dev/vdb |grep s_encoding_flags s_encoding_flags [0x 0 : 0] 1.3) By default: - mkfs.f2fs -f -g android -O casefold -C utf8 /dev/vdb Info: set default linear_lookup option: disable - dump.f2fs -d3 /dev/vdb |grep s_encoding_flags s_encoding_flags [0x 2 : 2] Distro case: 2.1) Disable linear lookup: - mkfs.f2fs -f -O casefold -C utf8:hashonly /dev/vdb - dump.f2fs -d3 /dev/vdb |grep s_encoding_flags s_encoding_flags [0x 2 : 2] 2.2) Enable linear lookup: - mkfs.f2fs -f -O casefold -C utf8:nohashonly /dev/vdb - dump.f2fs -d3 /dev/vdb |grep s_encoding_flags s_encoding_flags [0x 0 : 0] 2.3) By default: - mkfs.f2fs -f -O casefold -C utf8 /dev/vdb - dump.f2fs -d3 /dev/vdb |grep s_encoding_flags s_encoding_flags [0x 0 : 0] Reviewed-by: Zhiguo Niu <zhiguo.niu@unisoc.com> Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 974ff36 commit 9aad901

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

include/f2fs_fs.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,8 @@ enum {
14781478

14791479
/* feature list in Android */
14801480
enum {
1481-
F2FS_FEATURE_NAT_BITS = 0x0001,
1481+
F2FS_FEATURE_NAT_BITS = 0x0001,
1482+
F2FS_FEATURE_LINEAR_LOOKUP = 0x0002,
14821483
};
14831484

14841485
/* nolinear lookup tune */

lib/libf2fs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,7 @@ static const struct enc_flags {
14241424
char *param;
14251425
} encoding_flags[] = {
14261426
{ F2FS_ENC_STRICT_MODE_FL, "strict" },
1427+
{ F2FS_ENC_NO_COMPAT_FALLBACK_FL, "hashonly"}
14271428
};
14281429

14291430
/* Return a positive number < 0xff indicating the encoding magic number
@@ -1485,6 +1486,11 @@ int f2fs_str2encoding_flags(char **param, __u16 *flags)
14851486
*flags |= fl->flag;
14861487
}
14871488

1489+
if (fl->flag == F2FS_ENC_NO_COMPAT_FALLBACK_FL)
1490+
c.nolinear_lookup = neg ?
1491+
LINEAR_LOOKUP_ENABLE :
1492+
LINEAR_LOOKUP_DISABLE;
1493+
14881494
goto next_flag;
14891495
}
14901496
}

man/mkfs.f2fs.8

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,17 @@ Use UTF-8 for casefolding.
232232
.I flags:
233233
.RS 1.2i
234234
.TP 1.2i
235-
.B strict
235+
.B [no]strict
236236
This flag specifies that invalid strings should be rejected by the filesystem.
237237
Default is disabled.
238238
.RE
239+
.RS 1.2i
240+
.TP 1.2i
241+
.B [no]hashonly
242+
This flag specifies that linear lookup fallback is off during lookup, to turn
243+
on linear lookup fallback, use nohashonly flag.
244+
For android case, it will disable linear lookup by default.
245+
.RE
239246
.RE
240247
.TP
241248
.BI \-q

mkfs/f2fs_format.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,17 @@ static int f2fs_prepare_super_block(void)
687687
memcpy(sb->init_version, c.version, VERSION_LEN);
688688

689689
if (c.feature & F2FS_FEATURE_CASEFOLD) {
690+
/*
691+
* if [no]hashonly option is not assigned, let's disable
692+
* linear lookup fallback by default for Android case.
693+
*/
694+
if ((c.nolinear_lookup == LINEAR_LOOKUP_DEFAULT) &&
695+
(c.disabled_feature & F2FS_FEATURE_LINEAR_LOOKUP)) {
696+
c.s_encoding_flags |= F2FS_ENC_NO_COMPAT_FALLBACK_FL;
697+
MSG(0, "Info: set default linear_lookup option: %s\n",
698+
c.s_encoding_flags & F2FS_ENC_NO_COMPAT_FALLBACK_FL ?
699+
"disable" : "enable");
700+
}
690701
set_sb(s_encoding, c.s_encoding);
691702
set_sb(s_encoding_flags, c.s_encoding_flags);
692703
}

mkfs/f2fs_format_main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ static void add_default_options(void)
143143
force_overwrite = 1;
144144
c.wanted_sector_size = F2FS_BLKSIZE;
145145
c.root_uid = c.root_gid = 0;
146-
c.disabled_feature |= F2FS_FEATURE_NAT_BITS;
146+
c.disabled_feature |= F2FS_FEATURE_NAT_BITS |
147+
F2FS_FEATURE_LINEAR_LOOKUP;
147148

148149
/* RO doesn't need any other features */
149150
if (c.feature & F2FS_FEATURE_RO)

0 commit comments

Comments
 (0)