linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] defrag.f2fs: eliminate unexpected journal entries
@ 2015-12-17 17:23 Jaegeuk Kim
  2015-12-17 17:23 ` [PATCH 2/2] defrag.f2fs: return error if there is no space Jaegeuk Kim
  0 siblings, 1 reply; 2+ messages in thread
From: Jaegeuk Kim @ 2015-12-17 17:23 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: Jaegeuk Kim

When moving data or node blocks, it changes current segment information
dynamtically. Meanwhile, its journal entry space is recovered by old
stale data.
This patch makes sure that its journal space is zeroed out.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fsck/defrag.c | 1 +
 fsck/fsck.h   | 1 +
 fsck/mount.c  | 8 ++++++++
 3 files changed, 10 insertions(+)

diff --git a/fsck/defrag.c b/fsck/defrag.c
index 7ca7260..7abc0bf 100644
--- a/fsck/defrag.c
+++ b/fsck/defrag.c
@@ -90,6 +90,7 @@ int f2fs_defragment(struct f2fs_sb_info *sbi, u64 from, u64 len, u64 to, int lef
 
 	/* update curseg info; can update sit->types */
 	move_curseg_info(sbi, to);
+	zero_journal_entries(sbi);
 	write_curseg_info(sbi);
 
 	/* flush dirty sit entries */
diff --git a/fsck/fsck.h b/fsck/fsck.h
index 1464146..3870948 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -135,6 +135,7 @@ extern int f2fs_do_mount(struct f2fs_sb_info *);
 extern void f2fs_do_umount(struct f2fs_sb_info *);
 
 extern void flush_journal_entries(struct f2fs_sb_info *);
+extern void zero_journal_entries(struct f2fs_sb_info *);
 extern void flush_sit_entries(struct f2fs_sb_info *);
 extern void move_curseg_info(struct f2fs_sb_info *, u64);
 extern void write_curseg_info(struct f2fs_sb_info *);
diff --git a/fsck/mount.c b/fsck/mount.c
index 8418dcc..735ed90 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1446,6 +1446,14 @@ void move_curseg_info(struct f2fs_sb_info *sbi, u64 from)
 	}
 }
 
+void zero_journal_entries(struct f2fs_sb_info *sbi)
+{
+	int i;
+
+	for (i = 0; i < NO_CHECK_TYPE; i++)
+		CURSEG_I(sbi, i)->sum_blk->n_nats = 0;
+}
+
 void write_curseg_info(struct f2fs_sb_info *sbi)
 {
 	struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
-- 
2.5.4 (Apple Git-61)


------------------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH 2/2] defrag.f2fs: return error if there is no space
  2015-12-17 17:23 [PATCH 1/2] defrag.f2fs: eliminate unexpected journal entries Jaegeuk Kim
@ 2015-12-17 17:23 ` Jaegeuk Kim
  0 siblings, 0 replies; 2+ messages in thread
From: Jaegeuk Kim @ 2015-12-17 17:23 UTC (permalink / raw)
  To: linux-f2fs-devel; +Cc: Jaegeuk Kim

This patch checks whether there is a space or not to allocate new blocks.

Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
 fsck/mount.c | 28 ++++++++++++++++++----------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/fsck/mount.c b/fsck/mount.c
index 735ed90..4b38df8 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -11,6 +11,20 @@
 #include "fsck.h"
 #include <locale.h>
 
+static u32 get_free_segments(struct f2fs_sb_info *sbi)
+{
+	u32 i, free_segs = 0;
+
+	for (i = 0; i < TOTAL_SEGS(sbi); i++) {
+		struct seg_entry *se = get_seg_entry(sbi, i);
+
+		if (se->valid_blocks == 0x0 &&
+				!IS_CUR_SEGNO(sbi, i, NO_CHECK_TYPE))
+			free_segs++;
+	}
+	return free_segs;
+}
+
 void print_inode_info(struct f2fs_inode *inode, int name)
 {
 	unsigned int i = 0;
@@ -1376,6 +1390,9 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 	u32 segno;
 	u64 offset;
 
+	if (get_free_segments(sbi) <= SM_I(sbi)->reserved_segments + 1)
+		return -1;
+
 	while (*to >= SM_I(sbi)->main_blkaddr &&
 			*to < F2FS_RAW_SUPER(sbi)->block_count) {
 		segno = GET_SEGNO(sbi, *to);
@@ -1543,10 +1560,8 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
 	struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
 	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
 	block_t orphan_blks = 0;
-	u32 free_segs = 0;
 	unsigned long long cp_blk_no;
 	u32 flags = CP_UMOUNT_FLAG;
-	unsigned int segno;
 	int i, ret;
 	u_int32_t crc = 0;
 
@@ -1557,14 +1572,7 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
 
 	set_cp(ckpt_flags, flags);
 
-	for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) {
-		struct seg_entry *se = get_seg_entry(sbi, segno);
-
-		if (se->valid_blocks == 0x0 &&
-				!IS_CUR_SEGNO(sbi, segno, NO_CHECK_TYPE))
-			free_segs++;
-	}
-	set_cp(free_segment_count, free_segs);
+	set_cp(free_segment_count, get_free_segments(sbi));
 	set_cp(cp_pack_total_block_count, 8 + orphan_blks + get_sb(cp_payload));
 
 	crc = f2fs_cal_crc32(F2FS_SUPER_MAGIC, cp, CHECKSUM_OFFSET);
-- 
2.5.4 (Apple Git-61)


------------------------------------------------------------------------------

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-12-17 17:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-17 17:23 [PATCH 1/2] defrag.f2fs: eliminate unexpected journal entries Jaegeuk Kim
2015-12-17 17:23 ` [PATCH 2/2] defrag.f2fs: return error if there is no space Jaegeuk Kim

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).