Skip to contentSkip to conversation

mkfs.f2fs: make sure clean all reset dnodes

PATCH In review Jaegeuk Kim 2 participants 5 messages Feb 14, 2017 – Feb 23, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 mkfs.f2fs: make sure clean all reset dnodes

From: Kinglong Mee <[email protected]>

memset(raw_node, 0, F2FS_BLKSIZE) sets the next_blkaddr to zero, so that, only one reset dnode is cleaned always.

Fixes ad042d9194f5 "mkfs.f2fs: reset dnode with zeros",
---
 mkfs/f2fs_format.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
mkfs/f2fs_format.c +4 -1
index 2e0a4e5..e61adaa 100644
@@ -775,6 +775,8 @@ static int f2fs_write_super_block(void)
 #ifndef WITH_ANDROID
 static int discard_obsolete_dnode(struct f2fs_node *raw_node, u_int64_t offset)
 {
+	u_int64_t next_blkaddr = 0;
+
 	if (c.zoned_mode)
 		return 0;
 	do {
@@ -787,6 +789,7 @@ static int discard_obsolete_dnode(struct f2fs_node *raw_node, u_int64_t offset)
 			return -1;
 		}
 
+		next_blkaddr = le32_to_cpu(raw_node->footer.next_blkaddr);
 		memset(raw_node, 0, F2FS_BLKSIZE);
 
 		DBG(1, "\tDiscard dnode, at offset 0x%08"PRIx64"\n", offset);
@@ -794,7 +797,7 @@ static int discard_obsolete_dnode(struct f2fs_node *raw_node, u_int64_t offset)
 			MSG(1, "\tError: While discarding direct node!!!\n");
 			return -1;
 		}
-		offset = le32_to_cpu(raw_node->footer.next_blkaddr);
+		offset = next_blkaddr;
 	} while (1);
 
 	return 0;
Signature · 6 lines
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
#1 lore raw

PATCH 2/4 f2fs-tools: catch up up-to-date checkpoint flag

It needs to use up-to-date ckpt flag.

---
 include/f2fs_fs.h | 1 +
 1 file changed, 1 insertion(+)
include/f2fs_fs.h +1 -0
index 97ee297..44c5d61 100644
@@ -514,6 +514,7 @@ struct f2fs_super_block {
 /*
  * For checkpoint
  */
+#define CP_CRC_RECOVERY_FLAG	0x00000040
 #define CP_FASTBOOT_FLAG	0x00000020
 #define CP_FSCK_FLAG		0x00000010
 #define CP_ERROR_FLAG		0x00000008
Signature · 6 lines
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
#2 lore raw

PATCH 3/4 fsck.f2fs: fix wrong usage out

In reply to Jaegeuk Kim

This fixes wrong messages for error out.

---
 fsck/main.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)
fsck/main.c +10 -8
index 6c94a70..8bf5cd9 100644
@@ -88,18 +88,20 @@ static int is_digits(char *optarg)
 	return i == strlen(optarg);
 }
 
-static void error_out(void)
+static void error_out(char *prog)
 {
-	if (c.func == FSCK)
+	if (!strcmp("fsck.f2fs", prog))
 		fsck_usage();
-	else if (c.func == DUMP)
+	else if (!strcmp("dump.f2fs", prog))
 		dump_usage();
-	else if (c.func == DEFRAG)
+	else if (!strcmp("defrag.f2fs", prog))
 		defrag_usage();
-	else if (c.func == RESIZE)
+	else if (!strcmp("resize.f2fs", prog))
 		resize_usage();
-	else if (c.func == SLOAD)
+	else if (!strcmp("sload.f2fs", prog))
 		sload_usage();
+	else
+		MSG(0, "\nWrong progam.\n");
 }
 
 void f2fs_parse_options(int argc, char *argv[])
@@ -110,7 +112,7 @@ void f2fs_parse_options(int argc, char *argv[])
 
 	if (argc < 2) {
 		MSG(0, "\tError: Device not specified\n");
-		error_out();
+		error_out(prog);
 	}
 	c.devices[0].path = strdup(argv[argc - 1]);
 	argv[argc-- - 1] = 0;
@@ -392,7 +394,7 @@ void f2fs_parse_options(int argc, char *argv[])
 		MSG(0, "\tError: Unknown argument %s\n", argv[optind]);
 		break;
 	}
-	error_out();
+	error_out(prog);
 }
 
 static void do_fsck(struct f2fs_sb_info *sbi)
Signature · 6 lines
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
#3 lore raw

PATCH 4/4 mkfs.f2fs: support nat_bits feature

In reply to Jaegeuk Kim

This patch adds nat_bits in the last one ore two 4KB-sized blocks of first checkpoint segment. So, now a set of checkpoint *segment* consists of:

< checkpoint segment >
----------------------
| cp page #1 | 4KB
----------------------
| compacted data sum | 4KB
----------------------
| node sum #1 | 4KB
----------------------
| node sum #2 | 4KB
----------------------
| node sum #3 | 4KB
----------------------
| cp page #2 | 4KB
----------------------
...
----------------------
| crc|cpver | 8 bytes
----------------------
| full NAT bits | # of NAT segments / 2 * 512 / 8 bytes
----------------------
| empty NAT bits | # of NAT segments / 2 * 512 / 8 bytes
----------------------

---
 fsck/fsck.c        |   8 +++-
 fsck/fsck.h        |   5 +++
 fsck/mount.c       | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++--
 fsck/resize.c      |  12 ++++-
 include/f2fs_fs.h  |  12 +++++
 mkfs/f2fs_format.c |  48 ++++++++++++++++++--
 6 files changed, 203 insertions(+), 9 deletions(-)
fsck/fsck.c +7 -1
index b625153..116eae5 100644
@@ -1779,9 +1779,11 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
 		flags |= CP_ORPHAN_PRESENT_FLAG;
 	}
 
-	set_cp(ckpt_flags, flags);
 	set_cp(cp_pack_total_block_count, 8 + orphan_blks + get_sb(cp_payload));
 
+	flags = update_nat_bits_flags(sb, cp, flags);
+	set_cp(ckpt_flags, flags);
+
 	set_cp(free_segment_count, get_free_segments(sbi));
 	set_cp(valid_block_count, fsck->chk.valid_blk_cnt);
 	set_cp(valid_node_count, fsck->chk.valid_node_cnt);
@@ -1814,6 +1816,10 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
 
 	ret = dev_write_block(cp, cp_blk_no++);
 	ASSERT(ret >= 0);
+
+	/* Write nat bits */
+	if (flags & CP_NAT_BITS_FLAG)
+		write_nat_bits(sbi, sb, cp, sbi->cur_cp);
 }
 
 int check_curseg_offset(struct f2fs_sb_info *sbi)
fsck/fsck.h +5 -0
index 5a6f018..b6c9cbd 100644
@@ -178,6 +178,11 @@ extern struct f2fs_sit_block *get_current_sit_page(struct f2fs_sb_info *,
 extern void rewrite_current_sit_page(struct f2fs_sb_info *, unsigned int,
 			struct f2fs_sit_block *);
 
+extern u32 update_nat_bits_flags(struct f2fs_super_block *,
+				struct f2fs_checkpoint *, u32);
+extern void write_nat_bits(struct f2fs_sb_info *, struct f2fs_super_block *,
+			struct f2fs_checkpoint *, int);
+
 /* dump.c */
 struct dump_option {
 	nid_t nid;
fsck/mount.c +123 -4

177 lines not on this page · raw message

fsck/resize.c +11 -1
index 4791f74..4584d6f 100644
@@ -423,6 +423,7 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
 	block_t orphan_blks = 0;
 	block_t new_cp_blk_no, old_cp_blk_no;
 	u_int32_t crc = 0;
+	u32 flags;
 	void *buf;
 	int i, ret;
 
@@ -475,12 +476,17 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
 			((get_newsb(segment_count_nat) / 2) <<
 			get_newsb(log_blocks_per_seg)) / 8);
 
+	/* update nat_bits flag */
+	flags = update_nat_bits_flags(new_sb, cp, get_cp(ckpt_flags));
+	set_cp(ckpt_flags, flags);
+
 	memcpy(new_cp, cp, (unsigned char *)cp->sit_nat_version_bitmap -
 						(unsigned char *)cp);
 	new_cp->checkpoint_ver = cpu_to_le64(cp_ver + 1);
 
 	crc = f2fs_cal_crc32(F2FS_SUPER_MAGIC, new_cp, CHECKSUM_OFFSET);
-	*((__le32 *)((unsigned char *)new_cp + CHECKSUM_OFFSET)) = cpu_to_le32(crc);
+	*((__le32 *)((unsigned char *)new_cp + CHECKSUM_OFFSET)) =
+							cpu_to_le32(crc);
 
 	/* Write a new checkpoint in the other set */
 	new_cp_blk_no = old_cp_blk_no = get_sb(cp_blkaddr);
@@ -521,6 +527,10 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
 	ret = dev_write_block(new_cp, new_cp_blk_no++);
 	ASSERT(ret >= 0);
 
+	/* Write nat bits */
+	if (flags & CP_NAT_BITS_FLAG)
+		write_nat_bits(sbi, new_sb, new_cp, sbi->cur_cp == 1 ? 2 : 1);
+
 	/* disable old checkpoint */
 	memset(buf, 0, BLOCK_SZ);
 	ret = dev_write_block(buf, old_cp_blk_no);
include/f2fs_fs.h +12 -0
index 44c5d61..057adf3 100644
@@ -514,6 +514,7 @@ struct f2fs_super_block {
 /*
  * For checkpoint
  */
+#define CP_NAT_BITS_FLAG	0x00000080
 #define CP_CRC_RECOVERY_FLAG	0x00000040
 #define CP_FASTBOOT_FLAG	0x00000020
 #define CP_FSCK_FLAG		0x00000010
@@ -1084,4 +1085,15 @@ static inline double get_best_overprovision(struct f2fs_super_block *sb)
 	return max_ovp;
 }
 
+static inline __le64 get_cp_crc(struct f2fs_checkpoint *cp)
+{
+	u_int64_t cp_ver = get_cp(checkpoint_ver);
+	size_t crc_offset = get_cp(checksum_offset);
+	u_int32_t crc = le32_to_cpu(*(__le32 *)((unsigned char *)cp +
+							crc_offset));
+
+	cp_ver |= ((u_int64_t)crc << 32);
+	return cpu_to_le64(cp_ver);
+}
+
 #endif	/*__F2FS_FS_H */
mkfs/f2fs_format.c +45 -3

82 lines not on this page · raw message

Signature · 6 lines
2.11.0


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Reviewed-by on v1 1/4
#4 lore raw
In reply to Jaegeuk Kim
Quoted 8 lines · Jaegeuk Kim

From: Kinglong Mee <[email protected]>

memset(raw_node, 0, F2FS_BLKSIZE) sets the next_blkaddr to zero, so that, only one reset dnode is cleaned always.

Fixes ad042d9194f5 "mkfs.f2fs: reset dnode with zeros",

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, SlashDot.org! http://sdm.link/slashdot