linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: Chao Yu <yuchao0@huawei.com>
To: <linux-f2fs-devel@lists.sourceforge.net>
Cc: jaegeuk@kernel.org
Subject: [f2fs-dev] [PATCH] sload.f2fs: fix to set temperature during sload
Date: Wed, 31 Jul 2019 21:00:45 +0800	[thread overview]
Message-ID: <20190731130045.55760-1-yuchao0@huawei.com> (raw)

This patch enable to set file's temperature while loading files
to image.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/dir.c         | 51 ++++++++++++++++++++++++++++++++++++++++++++++
 include/f2fs_fs.h  |  1 +
 mkfs/f2fs_format.c |  2 +-
 3 files changed, 53 insertions(+), 1 deletion(-)

diff --git a/fsck/dir.c b/fsck/dir.c
index b3957d6..92d7e05 100644
--- a/fsck/dir.c
+++ b/fsck/dir.c
@@ -409,6 +409,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)
 {
@@ -467,6 +516,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;
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 9f7717e..2dda901 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -550,6 +550,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
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index c9c4fe5..9402619 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -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;
 			}
-- 
2.18.0.rc1



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

                 reply	other threads:[~2019-07-31 13:01 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190731130045.55760-1-yuchao0@huawei.com \
    --to=yuchao0@huawei.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).