sload.f2fs: fix to set temperature during sload
authorChao Yu <yuchao0@huawei.com>
Wed, 31 Jul 2019 13:00:45 +0000 (21:00 +0800)
committerJaegeuk Kim <jaegeuk@kernel.org>
Tue, 20 Aug 2019 18:23:58 +0000 (11:23 -0700)
This patch enable to set file's temperature while loading files
to image.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
fsck/dir.c
include/f2fs_fs.h
mkfs/f2fs_format.c

index 1e21294..d0c9019 100644 (file)
@@ -406,6 +406,55 @@ static void page_symlink(struct f2fs_sb_info *sbi, struct f2fs_node *inode,
        free(data_blk);
 }
 
+static inline int is_extension_exist(const char *s,
+                                       const char *sub)
+{
+       unsigned int slen = strlen(s);
+       unsigned int  sublen = strlen(sub);
+       int i;
+
+       /*
+        * filename format of multimedia file should be defined as:
+        * "filename + '.' + extension + (optional: '.' + temp extension)".
+        */
+       if (slen < sublen + 2)
+               return 0;
+
+       for (i = 1; i < slen - sublen; i++) {
+               if (s[i] != '.')
+                       continue;
+               if (!strncasecmp(s + i + 1, sub, sublen))
+                       return 1;
+       }
+
+       return 0;
+}
+
+static void set_file_temperature(struct f2fs_sb_info *sbi,
+                               struct f2fs_node *node_blk,
+                               const unsigned char *name)
+{
+       __u8 (*extlist)[F2FS_EXTENSION_LEN] = sbi->raw_super->extension_list;
+       int i, cold_count, hot_count;
+
+       cold_count = le32_to_cpu(sbi->raw_super->extension_count);
+       hot_count = sbi->raw_super->hot_ext_count;
+
+       for (i = 0; i < cold_count + hot_count; i++) {
+               if (is_extension_exist((const char *)name,
+                                       (const char *)extlist[i]))
+                       break;
+       }
+
+       if (i == cold_count + hot_count)
+               return;
+
+       if (i < cold_count)
+               node_blk->i.i_advise |= FADVISE_COLD_BIT;
+       else
+               node_blk->i.i_advise |= FADVISE_HOT_BIT;
+}
+
 static void init_inode_block(struct f2fs_sb_info *sbi,
                struct f2fs_node *node_blk, struct dentry *de)
 {
@@ -464,6 +513,8 @@ static void init_inode_block(struct f2fs_sb_info *sbi,
                node_blk->i.i_extra_isize = cpu_to_le16(calc_extra_isize());
        }
 
+       set_file_temperature(sbi, node_blk, de->name);
+
        node_blk->footer.ino = cpu_to_le32(de->ino);
        node_blk->footer.nid = cpu_to_le32(de->ino);
        node_blk->footer.flag = 0;
index 0d9a036..edc08ec 100644 (file)
@@ -548,6 +548,7 @@ enum {
 #define F2FS_MAX_LOG_SECTOR_SIZE       12      /* 12 bits for 4096 bytes */
 #define F2FS_BLKSIZE                   4096    /* support only 4KB block */
 #define F2FS_MAX_EXTENSION             64      /* # of extension entries */
+#define F2FS_EXTENSION_LEN             8       /* max size of extension */
 #define F2FS_BLK_ALIGN(x)      (((x) + F2FS_BLKSIZE - 1) / F2FS_BLKSIZE)
 
 #define NULL_ADDR              0x0U
index 8f41052..15be7bb 100644 (file)
@@ -146,7 +146,7 @@ static void cure_extension_list(void)
                ue = strtok(ext_str, ", ");
                while (ue != NULL) {
                        name_len = strlen(ue);
-                       if (name_len >= 8) {
+                       if (name_len >= F2FS_EXTENSION_LEN) {
                                MSG(0, "\tWarn: Extension name (%s) is too long\n", ue);
                                goto next;
                        }