Skip to contentSkip to conversation

f2fs-tools: set cold flag for non-dir node

PATCH In review [email protected] 2 participants 4 messages Jun 18, 2020 – Jun 19, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs-tools: set cold flag for non-dir node

From: Wuyun Zhao <[email protected]>

---
 fsck/dir.c  |  1 +
 fsck/node.c |  1 +
 fsck/node.h | 11 +++++++++++
 3 files changed, 13 insertions(+)
fsck/dir.c +1 -0
index 5f4f75e..dc03c98 100644
@@ -522,6 +522,7 @@ static void init_inode_block(struct f2fs_sb_info *sbi,
 	node_blk->footer.nid = cpu_to_le32(de->ino);
 	node_blk->footer.flag = 0;
 	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
+	set_cold_node(node_blk, S_ISDIR(mode));
 
 	if (S_ISDIR(mode)) {
 		make_empty_dir(sbi, node_blk);
fsck/node.c +1 -0
index 229a99c..1d291ca 100644
@@ -79,6 +79,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi,
 	node_blk->footer.ino = f2fs_inode->footer.ino;
 	node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
 	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
+	set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));
 
 	type = CURSEG_COLD_NODE;
 	if (IS_DNODE(node_blk)) {
fsck/node.h +11 -0
index 6bce1fb..99139b1 100644
@@ -161,6 +161,17 @@ static inline int is_node(struct f2fs_node *node_blk, int type)
 	return le32_to_cpu(node_blk->footer.flag) & (1 << type);
 }
 
+static inline void set_cold_node(struct f2fs_node *rn, bool is_dir)
+{
+	unsigned int flag = le32_to_cpu(rn->footer.flag);
+
+	if (is_dir)
+		flag &= ~(0x1 << COLD_BIT_SHIFT);
+	else
+		flag |= (0x1 << COLD_BIT_SHIFT);
+	rn->footer.flag = cpu_to_le32(flag);
+}
+
 #define is_fsync_dnode(node_blk)	is_node(node_blk, FSYNC_BIT_SHIFT)
 #define is_dent_dnode(node_blk)		is_node(node_blk, DENT_BIT_SHIFT)
 
Signature · 1 line
2.7.4
#1 lore raw
Quoted 1 line · On 2020/6/18 20:48, [email protected] wrote:

From: Wuyun Zhao <[email protected]>

Thanks for the patch. :)

Please add commit message here.

Quoted 25 lines
---
 fsck/dir.c  |  1 +
 fsck/node.c |  1 +
 fsck/node.h | 11 +++++++++++
 3 files changed, 13 insertions(+)
fsck/dir.c +1 -0
index 5f4f75e..dc03c98 100644
@@ -522,6 +522,7 @@ static void init_inode_block(struct f2fs_sb_info *sbi,
 	node_blk->footer.nid = cpu_to_le32(de->ino);
 	node_blk->footer.flag = 0;
 	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
+	set_cold_node(node_blk, S_ISDIR(mode));
 
 	if (S_ISDIR(mode)) {
 		make_empty_dir(sbi, node_blk);
fsck/node.c +0 -0
index 229a99c..1d291ca 100644

fsck/node.c block_t new_node_block(struct f2fs_sb_info *sbi, · line 82

Quoted 4 lines
fsck/node.c +1 -0
@@ -79,6 +79,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi,
 	node_blk->footer.ino = f2fs_inode->footer.ino;
 	node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
 	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
+	set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));

How about wrapping these node footer fields assignment into a function? then we can reuse this in other places.

void set_node_footer(nid, ino, ofs, ver, is_dir)

{
	node_blk->footer.nid = cpu_to_le32(nid);
	node_blk->footer.ino = f2fs_inode->footer.ino;
	node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
	set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));
}

fsck/node.h static inline int is_node(struct f2fs_node *node_blk, int type) · line 162

Quoted 10 lines
fsck/node.c +0 -0
 	type = CURSEG_COLD_NODE;
 	if (IS_DNODE(node_blk)) {
fsck/node.h +0 -0
index 6bce1fb..99139b1 100644
@@ -161,6 +161,17 @@ static inline int is_node(struct f2fs_node *node_blk, int type)
 	return le32_to_cpu(node_blk->footer.flag) & (1 << type);
 }

Beside this, I think we need to use set_node_footer() in:
- f2fs_write_root_inode
- f2fs_write_qf_inode
- f2fs_write_lpf_inode

as well to fix mkfs bugs.

Thanks,

Quoted 16 lines
fsck/node.h +11 -0
+static inline void set_cold_node(struct f2fs_node *rn, bool is_dir)
+{
+	unsigned int flag = le32_to_cpu(rn->footer.flag);
+
+	if (is_dir)
+		flag &= ~(0x1 << COLD_BIT_SHIFT);
+	else
+		flag |= (0x1 << COLD_BIT_SHIFT);
+	rn->footer.flag = cpu_to_le32(flag);
+}
+
 #define is_fsync_dnode(node_blk)	is_node(node_blk, FSYNC_BIT_SHIFT)
 #define is_dent_dnode(node_blk)		is_node(node_blk, DENT_BIT_SHIFT)
 
 
author
#2 lore raw
Quoted 6 lines · On 2020/6/18 20:48, [email protected] wrote:
Quoted 1 line

From: Wuyun Zhao <[email protected]>

Thanks for the patch. :)

Please add commit message here.

OK

Quoted 35 lines

fsck/dir.c static void init_inode_block(struct f2fs_sb_info

Quoted 13 lines
---
 fsck/dir.c  |  1 +
 fsck/node.c |  1 +
 fsck/node.h | 11 +++++++++++
 3 files changed, 13 insertions(+)
fsck/dir.c +0 -0
index 5f4f75e..dc03c98 100644
@@ -522,6 +522,7 @@ static void init_inode_block(struct f2fs_sb_info

*sbi,

Quoted 12 lines
fsck/dir.c +1 -0
 	node_blk->footer.nid = cpu_to_le32(de->ino);
 	node_blk->footer.flag = 0;
 	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
+	set_cold_node(node_blk, S_ISDIR(mode));
 
 	if (S_ISDIR(mode)) {
 		make_empty_dir(sbi, node_blk);
fsck/node.c +0 -0
index 229a99c..1d291ca 100644

fsck/node.c block_t new_node_block(struct f2fs_sb_info *sbi, · line 82

Quoted 4 lines
fsck/node.c +1 -0
@@ -79,6 +79,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi,
 	node_blk->footer.ino = f2fs_inode->footer.ino;
 	node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
 	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
+	set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));

How about wrapping these node footer fields assignment into a function? then
we can reuse this in other places.

Quoted 8 lines

void set_node_footer(nid, ino, ofs, ver, is_dir)

{
	node_blk->footer.nid = cpu_to_le32(nid);
	node_blk->footer.ino = f2fs_inode->footer.ino;
	node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
	set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));
}

Ok, That's good.

Quoted 12 lines

fsck/node.h static inline int is_node(struct f2fs_node

Quoted 8 lines
fsck/node.c +0 -0
 	type = CURSEG_COLD_NODE;
 	if (IS_DNODE(node_blk)) {
fsck/node.h +0 -0
index 6bce1fb..99139b1 100644
@@ -161,6 +161,17 @@ static inline int is_node(struct f2fs_node

*node_blk, int type)

fsck/node.h static inline int is_node(struct f2fs_node *node_blk, int type) · line 162

Quoted 2 lines
fsck/node.h +0 -0
 	return le32_to_cpu(node_blk->footer.flag) & (1 << type);
 }
Quoted 6 lines

Beside this, I think we need to use set_node_footer() in:
- f2fs_write_root_inode
- f2fs_write_qf_inode
- f2fs_write_lpf_inode

as well to fix mkfs bugs.

the root inode and the lpf inode is dir, need to set cold flag?

Quoted 19 lines

Thanks,

Quoted 4 lines
fsck/node.h +3 -0
+static inline void set_cold_node(struct f2fs_node *rn, bool is_dir)
+{
+	unsigned int flag = le32_to_cpu(rn->footer.flag);

fsck/node.h static inline int is_node(struct f2fs_node *node_blk, int type)

Quoted 10 lines
fsck/node.h +8 -0
+
+	if (is_dir)
+		flag &= ~(0x1 << COLD_BIT_SHIFT);
+	else
+		flag |= (0x1 << COLD_BIT_SHIFT);
+	rn->footer.flag = cpu_to_le32(flag);
+}
+
 #define is_fsync_dnode(node_blk)	is_node(node_blk, FSYNC_BIT_SHIFT)
 #define is_dent_dnode(node_blk)		is_node(node_blk,

DENT_BIT_SHIFT)

Quoted 2 lines
#3 lore raw
Quoted 67 lines · Zac
Quoted 6 lines · On 2020/6/18 20:48, [email protected] wrote:
Quoted 1 line

From: Wuyun Zhao <[email protected]>

Thanks for the patch. :)

Please add commit message here.

OK

Quoted 35 lines

fsck/dir.c static void init_inode_block(struct f2fs_sb_info

Quoted 13 lines
---
 fsck/dir.c  |  1 +
 fsck/node.c |  1 +
 fsck/node.h | 11 +++++++++++
 3 files changed, 13 insertions(+)
fsck/dir.c +0 -0
index 5f4f75e..dc03c98 100644
@@ -522,6 +522,7 @@ static void init_inode_block(struct f2fs_sb_info

*sbi,

Quoted 12 lines
fsck/dir.c +1 -0
 	node_blk->footer.nid = cpu_to_le32(de->ino);
 	node_blk->footer.flag = 0;
 	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
+	set_cold_node(node_blk, S_ISDIR(mode));
 
 	if (S_ISDIR(mode)) {
 		make_empty_dir(sbi, node_blk);
fsck/node.c +0 -0
index 229a99c..1d291ca 100644

fsck/node.c block_t new_node_block(struct f2fs_sb_info *sbi, · line 82

Quoted 4 lines
fsck/node.c +1 -0
@@ -79,6 +79,7 @@ block_t new_node_block(struct f2fs_sb_info *sbi,
 	node_blk->footer.ino = f2fs_inode->footer.ino;
 	node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
 	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
+	set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));

How about wrapping these node footer fields assignment into a function? then
we can reuse this in other places.

Quoted 8 lines

void set_node_footer(nid, ino, ofs, ver, is_dir)

{
	node_blk->footer.nid = cpu_to_le32(nid);
	node_blk->footer.ino = f2fs_inode->footer.ino;
	node_blk->footer.flag = cpu_to_le32(ofs << OFFSET_BIT_SHIFT);
	node_blk->footer.cp_ver = ckpt->checkpoint_ver;
	set_cold_node(node_blk, S_ISDIR(le16_to_cpu(f2fs_inode->i.i_mode)));
}

Ok, That's good.

Quoted 12 lines

fsck/node.h static inline int is_node(struct f2fs_node

Quoted 8 lines
fsck/node.c +0 -0
 	type = CURSEG_COLD_NODE;
 	if (IS_DNODE(node_blk)) {
fsck/node.h +0 -0
index 6bce1fb..99139b1 100644
@@ -161,6 +161,17 @@ static inline int is_node(struct f2fs_node

*node_blk, int type)

Quoted 2 lines
fsck/node.h +0 -0
 	return le32_to_cpu(node_blk->footer.flag) & (1 << type);
 }
Quoted 8 lines
Quoted 6 lines

Beside this, I think we need to use set_node_footer() in:
- f2fs_write_root_inode
- f2fs_write_qf_inode
- f2fs_write_lpf_inode

as well to fix mkfs bugs.

the root inode and the lpf inode is dir, need to set cold flag?

No, but it is worth to use set_node_footer(..., is_dir:true) for cleanup.

Thanks,

Quoted 23 lines
Quoted 4 lines

Thanks,

Quoted 1 line
Quoted 16 lines

fsck/node.h static inline int is_node(struct f2fs_node *node_blk, int type)

Quoted 13 lines
fsck/node.h +11 -0
+static inline void set_cold_node(struct f2fs_node *rn, bool is_dir)
+{
+	unsigned int flag = le32_to_cpu(rn->footer.flag);
+
+	if (is_dir)
+		flag &= ~(0x1 << COLD_BIT_SHIFT);
+	else
+		flag |= (0x1 << COLD_BIT_SHIFT);
+	rn->footer.flag = cpu_to_le32(flag);
+}
+
 #define is_fsync_dnode(node_blk)	is_node(node_blk, FSYNC_BIT_SHIFT)
 #define is_dent_dnode(node_blk)		is_node(node_blk,

DENT_BIT_SHIFT)

Quoted 2 lines

.