mkfs.f2fs: support hot file extension

This patch adds new option '-E' to accept user configured hot file
extension, in order to let kernel module handle hot/cold file's datas
separately better.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
This commit is contained in:
Chao Yu 2018-03-01 10:48:47 +08:00 committed by Jaegeuk Kim
parent 4d4a9f2d45
commit 6fdc37ff26
3 changed files with 62 additions and 35 deletions

View File

@ -348,7 +348,7 @@ struct f2fs_configuration {
int32_t dump_fd;
struct device_info devices[MAX_DEVICES];
int ndevs;
char *extension_list;
char *extension_list[2];
const char *rootdev_name;
int dbg_lv;
int show_dentry;
@ -611,7 +611,8 @@ struct f2fs_super_block {
__u8 encrypt_pw_salt[16]; /* Salt used for string2key algorithm */
struct f2fs_device devs[MAX_DEVICES]; /* device list */
__le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */
__u8 reserved[315]; /* valid reserved region */
__u8 hot_ext_count; /* # of hot file extension */
__u8 reserved[314]; /* valid reserved region */
} __attribute__((packed));
/*

View File

@ -68,6 +68,15 @@ const char *media_ext_lists[] = {
NULL
};
const char *hot_ext_lists[] = {
NULL
};
const char **default_ext_list[] = {
media_ext_lists,
hot_ext_lists
};
static bool is_extension_exist(const char *name)
{
int i;
@ -83,44 +92,55 @@ static bool is_extension_exist(const char *name)
static void cure_extension_list(void)
{
const char **extlist = media_ext_lists;
char *ext_str = c.extension_list;
const char **extlist;
char *ext_str;
char *ue;
int name_len;
int i = 0;
int i, pos = 0;
set_sb(extension_count, 0);
memset(sb->extension_list, 0, sizeof(sb->extension_list));
while (*extlist) {
name_len = strlen(*extlist);
memcpy(sb->extension_list[i++], *extlist, name_len);
extlist++;
}
set_sb(extension_count, i);
for (i = 0; i < 2; i++) {
ext_str = c.extension_list[i];
extlist = default_ext_list[i];
if (!ext_str)
return;
/* add user ext list */
ue = strtok(ext_str, ", ");
while (ue != NULL) {
name_len = strlen(ue);
if (name_len >= 8) {
MSG(0, "\tWarn: Extension name (%s) is too long\n", ue);
goto next;
while (*extlist) {
name_len = strlen(*extlist);
memcpy(sb->extension_list[pos++], *extlist, name_len);
extlist++;
}
if (!is_extension_exist(ue))
memcpy(sb->extension_list[i++], ue, name_len);
if (i == 0)
set_sb(extension_count, pos);
else
sb->hot_ext_count = pos - get_sb(extension_count);;
if (!ext_str)
continue;
/* add user ext list */
ue = strtok(ext_str, ", ");
while (ue != NULL) {
name_len = strlen(ue);
if (name_len >= 8) {
MSG(0, "\tWarn: Extension name (%s) is too long\n", ue);
goto next;
}
if (!is_extension_exist(ue))
memcpy(sb->extension_list[pos++], ue, name_len);
next:
ue = strtok(NULL, ", ");
if (i >= F2FS_MAX_EXTENSION)
break;
ue = strtok(NULL, ", ");
if (pos >= F2FS_MAX_EXTENSION)
break;
}
if (i == 0)
set_sb(extension_count, pos);
else
sb->hot_ext_count = pos - get_sb(extension_count);
free(c.extension_list[i]);
}
set_sb(extension_count, i);
free(c.extension_list);
}
static void verify_cur_segs(void)

View File

@ -44,7 +44,8 @@ static void mkfs_usage()
MSG(0, " -a heap-based allocation [default:0]\n");
MSG(0, " -c [device path] up to 7 devices excepts meta device\n");
MSG(0, " -d debug level [default:0]\n");
MSG(0, " -e [extension list] e.g. \"mp3,gif,mov\"\n");
MSG(0, " -e [cold file ext list] e.g. \"mp3,gif,mov\"\n");
MSG(0, " -E [hot file ext list] e.g. \"db\"\n");
MSG(0, " -f force overwrite the exist filesystem\n");
MSG(0, " -i extended node bitmap, node ratio is 20%% by default\n");
MSG(0, " -l label\n");
@ -70,8 +71,10 @@ static void f2fs_show_info()
MSG(0, "Info: Disable heap-based policy\n");
MSG(0, "Info: Debug level = %d\n", c.dbg_lv);
if (c.extension_list)
MSG(0, "Info: Add new extension list\n");
if (c.extension_list[0])
MSG(0, "Info: Add new cold file extension list\n");
if (c.extension_list[1])
MSG(0, "Info: Add new hot file extension list\n");
if (c.vol_label)
MSG(0, "Info: Label = %s\n", c.vol_label);
@ -106,7 +109,7 @@ static void parse_feature(const char *features)
static void f2fs_parse_options(int argc, char *argv[])
{
static const char *option_string = "qa:c:d:e:il:mo:O:s:S:z:t:fw:";
static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:fw:";
int32_t option=0;
while ((option = getopt(argc,argv,option_string)) != EOF) {
@ -134,7 +137,10 @@ static void f2fs_parse_options(int argc, char *argv[])
c.dbg_lv = atoi(optarg);
break;
case 'e':
c.extension_list = strdup(optarg);
c.extension_list[0] = strdup(optarg);
break;
case 'E':
c.extension_list[1] = strdup(optarg);
break;
case 'i':
c.large_nat_bitmap = 1;