All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop
@ 2019-08-09 10:52 Chao Yu
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 02/10] f2fs-tools: fix to avoid memory leak of sit_i->sentries Chao Yu
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:52 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

In error path of build_sit_info(), start variable is unsigned int type,
it should never be less than zero, fix it.

build_sit_info()
{
...
	unsigned int start;
...
free_validity_maps:
	for (--start ; start >= 0; --start)
		free(sit_i->sentries[start].cur_valid_map);
...
}

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/mount.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fsck/mount.c b/fsck/mount.c
index fd89b8e..f97c4ea 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1401,7 +1401,8 @@ int build_sit_info(struct f2fs_sb_info *sbi)
 	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
 	struct f2fs_checkpoint *cp = F2FS_CKPT(sbi);
 	struct sit_info *sit_i;
-	unsigned int sit_segs, start;
+	unsigned int sit_segs;
+	int start;
 	char *src_bitmap, *dst_bitmap;
 	unsigned int bitmap_size;
 
-- 
2.18.0.rc1



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

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

* [f2fs-dev] [PATCH 02/10] f2fs-tools: fix to avoid memory leak of sit_i->sentries
  2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
@ 2019-08-09 10:52 ` Chao Yu
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 03/10] f2fs-tools: allocate memory in batch in build_sit_info() Chao Yu
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:52 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

We missed to free sit_i->sentries in f2fs_do_umount(), fix it.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/mount.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/fsck/mount.c b/fsck/mount.c
index f97c4ea..af7149e 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -2917,6 +2917,7 @@ void f2fs_do_umount(struct f2fs_sb_info *sbi)
 		free(sit_i->sentries[i].cur_valid_map);
 
 	free(sit_i->sit_bitmap);
+	free(sit_i->sentries);
 	free(sm_i->sit_info);
 
 	/* free sm_info */
-- 
2.18.0.rc1



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

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

* [f2fs-dev] [PATCH 03/10] f2fs-tools: allocate memory in batch in build_sit_info()
  2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 02/10] f2fs-tools: fix to avoid memory leak of sit_i->sentries Chao Yu
@ 2019-08-09 10:52 ` Chao Yu
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 04/10] fsck.f2fs: introduce current_sit_addr() for cleanup Chao Yu
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:52 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

Like we did in kernel, allocating memory in batch will be more
efficient.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/f2fs.h  |  1 +
 fsck/mount.c | 28 ++++++++++++++++------------
 2 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index a52b5d4..6fc0bf3 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -82,6 +82,7 @@ struct sit_info {
 	block_t sit_base_addr;          /* start block address of SIT area */
 	block_t sit_blocks;             /* # of blocks used by SIT area */
 	block_t written_valid_blocks;   /* # of valid blocks in main area */
+	unsigned char *bitmap;		/* all bitmaps pointer */
 	char *sit_bitmap;               /* SIT bitmap pointer */
 	unsigned int bitmap_size;       /* SIT bitmap size */
 
diff --git a/fsck/mount.c b/fsck/mount.c
index af7149e..bed22d5 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1404,6 +1404,7 @@ int build_sit_info(struct f2fs_sb_info *sbi)
 	unsigned int sit_segs;
 	int start;
 	char *src_bitmap, *dst_bitmap;
+	unsigned char *bitmap;
 	unsigned int bitmap_size;
 
 	sit_i = malloc(sizeof(struct sit_info));
@@ -1420,13 +1421,19 @@ int build_sit_info(struct f2fs_sb_info *sbi)
 		goto free_sit_info;
 	}
 
+	bitmap_size = TOTAL_SEGS(sbi) * SIT_VBLOCK_MAP_SIZE;
+
+	sit_i->bitmap = calloc(bitmap_size, 1);
+	if (!sit_i->bitmap) {
+		MSG(1, "\tError: Calloc failed for build_sit_info!!\n");
+		goto free_sentries;
+	}
+
+	bitmap = sit_i->bitmap;
+
 	for (start = 0; start < TOTAL_SEGS(sbi); start++) {
-		sit_i->sentries[start].cur_valid_map
-			= calloc(SIT_VBLOCK_MAP_SIZE, 1);
-		if (!sit_i->sentries[start].cur_valid_map) {
-			MSG(1, "\tError: Calloc failed for build_sit_info!!\n");
-			goto free_validity_maps;
-		}
+		sit_i->sentries[start].cur_valid_map = bitmap;
+		bitmap += SIT_VBLOCK_MAP_SIZE;
 	}
 
 	sit_segs = get_sb(segment_count_sit) >> 1;
@@ -1452,10 +1459,9 @@ int build_sit_info(struct f2fs_sb_info *sbi)
 	return 0;
 
 free_validity_maps:
-	for (--start ; start >= 0; --start)
-		free(sit_i->sentries[start].cur_valid_map);
+	free(sit_i->bitmap);
+free_sentries:
 	free(sit_i->sentries);
-
 free_sit_info:
 	free(sit_i);
 
@@ -2913,9 +2919,7 @@ void f2fs_do_umount(struct f2fs_sb_info *sbi)
 	free(sbi->nm_info);
 
 	/* free sit_info */
-	for (i = 0; i < TOTAL_SEGS(sbi); i++)
-		free(sit_i->sentries[i].cur_valid_map);
-
+	free(sit_i->bitmap);
 	free(sit_i->sit_bitmap);
 	free(sit_i->sentries);
 	free(sm_i->sit_info);
-- 
2.18.0.rc1



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

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

* [f2fs-dev] [PATCH 04/10] fsck.f2fs: introduce current_sit_addr() for cleanup
  2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 02/10] f2fs-tools: fix to avoid memory leak of sit_i->sentries Chao Yu
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 03/10] f2fs-tools: allocate memory in batch in build_sit_info() Chao Yu
@ 2019-08-09 10:52 ` Chao Yu
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 05/10] f2fs-tools: introduce f2fs_ra_meta_pages() Chao Yu
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:52 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

Just clean up, no logic change.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/mount.c | 28 +++++++++++++---------------
 1 file changed, 13 insertions(+), 15 deletions(-)

diff --git a/fsck/mount.c b/fsck/mount.c
index bed22d5..eed27bf 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -1700,13 +1700,12 @@ static inline void check_seg_range(struct f2fs_sb_info *sbi, unsigned int segno)
 	ASSERT(segno <= end_segno);
 }
 
-void get_current_sit_page(struct f2fs_sb_info *sbi,
-			unsigned int segno, struct f2fs_sit_block *sit_blk)
+static inline block_t current_sit_addr(struct f2fs_sb_info *sbi,
+						unsigned int segno)
 {
 	struct sit_info *sit_i = SIT_I(sbi);
 	unsigned int offset = SIT_BLOCK_OFFSET(sit_i, segno);
 	block_t blk_addr = sit_i->sit_base_addr + offset;
-	int ret;
 
 	check_seg_range(sbi, segno);
 
@@ -1714,24 +1713,23 @@ void get_current_sit_page(struct f2fs_sb_info *sbi,
 	if (f2fs_test_bit(offset, sit_i->sit_bitmap))
 		blk_addr += sit_i->sit_blocks;
 
-	ret = dev_read_block(sit_blk, blk_addr);
-	ASSERT(ret >= 0);
+	return blk_addr;
 }
 
-void rewrite_current_sit_page(struct f2fs_sb_info *sbi,
+void get_current_sit_page(struct f2fs_sb_info *sbi,
 			unsigned int segno, struct f2fs_sit_block *sit_blk)
 {
-	struct sit_info *sit_i = SIT_I(sbi);
-	unsigned int offset = SIT_BLOCK_OFFSET(sit_i, segno);
-	block_t blk_addr = sit_i->sit_base_addr + offset;
-	int ret;
+	block_t blk_addr = current_sit_addr(sbi, segno);
 
-	/* calculate sit block address */
-	if (f2fs_test_bit(offset, sit_i->sit_bitmap))
-		blk_addr += sit_i->sit_blocks;
+	ASSERT(dev_read_block(sit_blk, blk_addr) >= 0);
+}
 
-	ret = dev_write_block(sit_blk, blk_addr);
-	ASSERT(ret >= 0);
+void rewrite_current_sit_page(struct f2fs_sb_info *sbi,
+			unsigned int segno, struct f2fs_sit_block *sit_blk)
+{
+	block_t blk_addr = current_sit_addr(sbi, segno);
+
+	ASSERT(dev_write_block(sit_blk, blk_addr) >= 0);
 }
 
 void check_block_count(struct f2fs_sb_info *sbi,
-- 
2.18.0.rc1



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

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

* [f2fs-dev] [PATCH 05/10] f2fs-tools: introduce f2fs_ra_meta_pages()
  2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
                   ` (2 preceding siblings ...)
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 04/10] fsck.f2fs: introduce current_sit_addr() for cleanup Chao Yu
@ 2019-08-09 10:52 ` Chao Yu
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 06/10] dump.f2fs: introduce start_bidx_of_node() for cleanup Chao Yu
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:52 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

Introduce f2fs_ra_meta_pages() to readahead meta pages like we did
in kernel.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/f2fs.h       |  28 +++++++++++
 fsck/fsck.c       |   2 +
 fsck/fsck.h       |   1 +
 fsck/mount.c      | 119 ++++++++++++++++++++++++++++++++++++++++++----
 include/f2fs_fs.h |   5 ++
 5 files changed, 147 insertions(+), 8 deletions(-)

diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index 6fc0bf3..52b81ff 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -37,6 +37,20 @@ struct list_head {
 	struct list_head *next, *prev;
 };
 
+/*
+ * indicate meta/data type
+ */
+enum {
+	META_CP,
+	META_NAT,
+	META_SIT,
+	META_SSA,
+	META_MAX,
+	META_POR,
+};
+
+#define MAX_RA_BLOCKS	64
+
 enum {
 	NAT_BITMAP,
 	SIT_BITMAP
@@ -329,6 +343,13 @@ static inline block_t __end_block_addr(struct f2fs_sb_info *sbi)
 	((t == CURSEG_HOT_NODE) || (t == CURSEG_COLD_NODE) ||           \
 	 (t == CURSEG_WARM_NODE))
 
+#define MAIN_BLKADDR(sbi)						\
+	(SM_I(sbi) ? SM_I(sbi)->main_blkaddr :				\
+		le32_to_cpu(F2FS_RAW_SUPER(sbi)->main_blkaddr))
+#define SEG0_BLKADDR(sbi)						\
+	(SM_I(sbi) ? SM_I(sbi)->seg0_blkaddr :				\
+		le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment0_blkaddr))
+
 #define GET_SUM_BLKADDR(sbi, segno)					\
 	((sbi->sm_info->ssa_blkaddr) + segno)
 
@@ -345,9 +366,16 @@ static inline block_t __end_block_addr(struct f2fs_sb_info *sbi)
 	GET_SEGNO_FROM_SEG0(sbi, SM_I(sbi)->main_blkaddr)
 #define GET_R2L_SEGNO(sbi, segno)	(segno + FREE_I_START_SEGNO(sbi))
 
+#define MAIN_SEGS(sbi)	(SM_I(sbi)->main_segments)
+#define TOTAL_BLKS(sbi)	(TOTAL_SEGS(sbi) << (sbi)->log_blocks_per_seg)
+#define MAX_BLKADDR(sbi)	(SEG0_BLKADDR(sbi) + TOTAL_BLKS(sbi))
+
 #define START_BLOCK(sbi, segno)	(SM_I(sbi)->main_blkaddr +		\
 	((segno) << sbi->log_blocks_per_seg))
 
+#define SIT_BLK_CNT(sbi)						\
+	((MAIN_SEGS(sbi) + SIT_ENTRY_PER_BLOCK - 1) / SIT_ENTRY_PER_BLOCK)
+
 static inline struct curseg_info *CURSEG_I(struct f2fs_sb_info *sbi, int type)
 {
 	return (struct curseg_info *)(SM_I(sbi)->curseg_array + type);
diff --git a/fsck/fsck.c b/fsck/fsck.c
index e835a22..d53317c 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -1665,6 +1665,8 @@ int fsck_chk_orphan_node(struct f2fs_sb_info *sbi)
 	start_blk = __start_cp_addr(sbi) + 1 + get_sb(cp_payload);
 	orphan_blkaddr = __start_sum_addr(sbi) - 1 - get_sb(cp_payload);
 
+	f2fs_ra_meta_pages(sbi, start_blk, orphan_blkaddr, META_CP);
+
 	orphan_blk = calloc(BLOCK_SZ, 1);
 	ASSERT(orphan_blk);
 
diff --git a/fsck/fsck.h b/fsck/fsck.h
index aabe4a3..f7ddf50 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -180,6 +180,7 @@ extern int f2fs_set_sit_bitmap(struct f2fs_sb_info *, u32);
 extern void fsck_init(struct f2fs_sb_info *);
 extern int fsck_verify(struct f2fs_sb_info *);
 extern void fsck_free(struct f2fs_sb_info *);
+extern int f2fs_ra_meta_pages(struct f2fs_sb_info *, block_t, int, int);
 extern int f2fs_do_mount(struct f2fs_sb_info *);
 extern void f2fs_do_umount(struct f2fs_sb_info *);
 extern int f2fs_sparse_initialize_meta(struct f2fs_sb_info *);
diff --git a/fsck/mount.c b/fsck/mount.c
index eed27bf..46fe1be 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -473,6 +473,94 @@ void print_sb_state(struct f2fs_super_block *sb)
 	MSG(0, "\n");
 }
 
+bool f2fs_is_valid_blkaddr(struct f2fs_sb_info *sbi,
+					block_t blkaddr, int type)
+{
+	switch (type) {
+	case META_NAT:
+		break;
+	case META_SIT:
+		if (blkaddr >= SIT_BLK_CNT(sbi))
+			return 0;
+		break;
+	case META_SSA:
+		if (blkaddr >= MAIN_BLKADDR(sbi) ||
+			blkaddr < SM_I(sbi)->ssa_blkaddr)
+			return 0;
+		break;
+	case META_CP:
+		if (blkaddr >= SIT_I(sbi)->sit_base_addr ||
+			blkaddr < __start_cp_addr(sbi))
+			return 0;
+		break;
+	case META_POR:
+		if (blkaddr >= MAX_BLKADDR(sbi) ||
+			blkaddr < MAIN_BLKADDR(sbi))
+			return 0;
+		break;
+	default:
+		ASSERT(0);
+	}
+
+	return 1;
+}
+
+static inline block_t current_sit_addr(struct f2fs_sb_info *sbi,
+						unsigned int start);
+
+/*
+ * Readahead CP/NAT/SIT/SSA pages
+ */
+int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages,
+							int type)
+{
+	block_t blkno = start;
+	block_t blkaddr, start_blk = 0, len = 0;
+
+	for (; nrpages-- > 0; blkno++) {
+
+		if (!f2fs_is_valid_blkaddr(sbi, blkno, type))
+			goto out;
+
+		switch (type) {
+		case META_NAT:
+			if (blkno >= NAT_BLOCK_OFFSET(NM_I(sbi)->max_nid))
+				blkno = 0;
+			/* get nat block addr */
+			blkaddr = current_nat_addr(sbi,
+					blkno * NAT_ENTRY_PER_BLOCK, NULL);
+			break;
+		case META_SIT:
+			/* get sit block addr */
+			blkaddr = current_sit_addr(sbi,
+					blkno * SIT_ENTRY_PER_BLOCK);
+			break;
+		case META_SSA:
+		case META_CP:
+		case META_POR:
+			blkaddr = blkno;
+			break;
+		default:
+			ASSERT(0);
+		}
+
+		if (!len) {
+			start_blk = blkaddr;
+			len = 1;
+		} else if (start_blk + len == blkaddr) {
+			len++;
+		} else {
+			dev_readahead(start_blk << F2FS_BLKSIZE_BITS,
+						len << F2FS_BLKSIZE_BITS);
+		}
+	}
+out:
+	if (len)
+		dev_readahead(start_blk << F2FS_BLKSIZE_BITS,
+					len << F2FS_BLKSIZE_BITS);
+	return blkno - start;
+}
+
 void update_superblock(struct f2fs_super_block *sb, int sb_mask)
 {
 	int addr, ret;
@@ -1133,6 +1221,9 @@ static int f2fs_init_nid_bitmap(struct f2fs_sb_info *sbi)
 		return -ENOMEM;
 	}
 
+	f2fs_ra_meta_pages(sbi, 0, NAT_BLOCK_OFFSET(nm_i->max_nid),
+							META_NAT);
+
 	for (nid = 0; nid < nm_i->max_nid; nid++) {
 		if (!(nid % NAT_ENTRY_PER_BLOCK)) {
 			int ret;
@@ -1983,7 +2074,9 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
 	struct f2fs_sit_block *sit_blk;
 	struct seg_entry *se;
 	struct f2fs_sit_entry sit;
-	unsigned int i, segno;
+	int sit_blk_cnt = SIT_BLK_CNT(sbi);
+	unsigned int i, segno, end;
+	unsigned int readed, start_blk = 0;
 
 	sit_blk = calloc(BLOCK_SZ, 1);
 	if (!sit_blk) {
@@ -1991,15 +2084,25 @@ static int build_sit_entries(struct f2fs_sb_info *sbi)
 		return -ENOMEM;
 	}
 
-	for (segno = 0; segno < TOTAL_SEGS(sbi); segno++) {
-		se = &sit_i->sentries[segno];
+	do {
+		readed = f2fs_ra_meta_pages(sbi, start_blk, MAX_RA_BLOCKS,
+								META_SIT);
 
-		get_current_sit_page(sbi, segno, sit_blk);
-		sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
+		segno = start_blk * sit_i->sents_per_block;
+		end = (start_blk + readed) * sit_i->sents_per_block;
+
+		for (; segno < end && segno < TOTAL_SEGS(sbi); segno++) {
+			se = &sit_i->sentries[segno];
+
+			get_current_sit_page(sbi, segno, sit_blk);
+			sit = sit_blk->entries[SIT_ENTRY_OFFSET(sit_i, segno)];
+
+			check_block_count(sbi, segno, &sit);
+			seg_info_from_raw_sit(se, &sit);
+		}
+		start_blk += readed;
+	} while (start_blk < sit_blk_cnt);
 
-		check_block_count(sbi, segno, &sit);
-		seg_info_from_raw_sit(se, &sit);
-	}
 
 	free(sit_blk);
 
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 2dda901..942c8dc 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -1186,6 +1186,11 @@ extern int f2fs_finalize_device(void);
 extern int f2fs_fsync_device(void);
 
 extern int dev_read(void *, __u64, size_t);
+#ifdef POSIX_FADV_WILLNEED
+extern int dev_readahead(__u64, size_t);
+#else
+extern int dev_readahead(__u64, size_t UNUSED(len));
+#endif
 extern int dev_write(void *, __u64, size_t);
 extern int dev_write_block(void *, __u64);
 extern int dev_write_dump(void *, __u64, size_t);
-- 
2.18.0.rc1



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

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

* [f2fs-dev] [PATCH 06/10] dump.f2fs: introduce start_bidx_of_node() for cleanup
  2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
                   ` (3 preceding siblings ...)
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 05/10] f2fs-tools: introduce f2fs_ra_meta_pages() Chao Yu
@ 2019-08-09 10:52 ` Chao Yu
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 07/10] fsck.f2fs: fix to set large section type during allocation Chao Yu
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:52 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

Just cleanup, no logic change, besides, it can be reused by latter
patch.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/dump.c | 39 +++++++++++++++++++++++----------------
 1 file changed, 23 insertions(+), 16 deletions(-)

diff --git a/fsck/dump.c b/fsck/dump.c
index 390361d..a6a1635 100644
--- a/fsck/dump.c
+++ b/fsck/dump.c
@@ -527,11 +527,31 @@ static void dump_node_from_blkaddr(struct f2fs_sb_info *sbi, u32 blk_addr)
 	free(node_blk);
 }
 
+unsigned int start_bidx_of_node(unsigned int node_ofs,
+					struct f2fs_node *node_blk)
+{
+	unsigned int indirect_blks = 2 * NIDS_PER_BLOCK + 4;
+	unsigned int bidx;
+
+	if (node_ofs == 0)
+		return 0;
+
+	if (node_ofs <= 2) {
+		bidx = node_ofs - 1;
+	} else if (node_ofs <= indirect_blks) {
+		int dec = (node_ofs - 4) / (NIDS_PER_BLOCK + 1);
+		bidx = node_ofs - 2 - dec;
+	} else {
+		int dec = (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1);
+		bidx = node_ofs - 5 - dec;
+	}
+	return bidx * ADDRS_PER_BLOCK + ADDRS_PER_INODE(&node_blk->i);
+}
+
 static void dump_data_offset(u32 blk_addr, int ofs_in_node)
 {
 	struct f2fs_node *node_blk;
-	unsigned int indirect_blks = 2 * NIDS_PER_BLOCK + 4;
-	unsigned int bidx = 0;
+	unsigned int bidx;
 	unsigned int node_ofs;
 	int ret;
 
@@ -543,20 +563,7 @@ static void dump_data_offset(u32 blk_addr, int ofs_in_node)
 
 	node_ofs = ofs_of_node(node_blk);
 
-	if (node_ofs == 0)
-		goto got_it;
-
-	if (node_ofs > 0 && node_ofs <= 2) {
-		bidx = node_ofs - 1;
-	} else if (node_ofs <= indirect_blks) {
-		int dec = (node_ofs - 4) / (NIDS_PER_BLOCK + 1);
-		bidx = node_ofs - 2 - dec;
-	} else {
-		int dec = (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1);
-		bidx = node_ofs - 5 - dec;
-	}
-	bidx = bidx * ADDRS_PER_BLOCK + ADDRS_PER_INODE(&node_blk->i);
-got_it:
+	bidx = start_bidx_of_node(node_ofs, node_blk);
 	bidx +=  ofs_in_node;
 
 	setlocale(LC_ALL, "");
-- 
2.18.0.rc1



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

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

* [f2fs-dev] [PATCH 07/10] fsck.f2fs: fix to set large section type during allocation
  2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
                   ` (4 preceding siblings ...)
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 06/10] dump.f2fs: introduce start_bidx_of_node() for cleanup Chao Yu
@ 2019-08-09 10:52 ` Chao Yu
  2019-08-09 10:53 ` [f2fs-dev] [PATCH 08/10] f2fs-tools: advise to mount unclean image to replay journal Chao Yu
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:52 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

During block allocation in large free section, we need to change
all sub segments' type in it, otherwise, we will fail to allocate
block in non-first segment due to mismatch seg-type.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/mount.c | 19 ++++++++++++++++++-
 1 file changed, 18 insertions(+), 1 deletion(-)

diff --git a/fsck/mount.c b/fsck/mount.c
index 46fe1be..ad20d19 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -2393,6 +2393,20 @@ int relocate_curseg_offset(struct f2fs_sb_info *sbi, int type)
 	return 0;
 }
 
+void set_section_type(struct f2fs_sb_info *sbi, unsigned int segno, int type)
+{
+	struct seg_entry *se;
+	unsigned int i;
+
+	if (sbi->segs_per_sec == 1)
+		return;
+
+	for (i = 0; i < sbi->segs_per_sec; i++) {
+		se = get_seg_entry(sbi, segno + i);
+		se->type = type;
+	}
+}
+
 int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 {
 	struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
@@ -2436,8 +2450,11 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 				if (se2->valid_blocks)
 					break;
 			}
-			if (i == sbi->segs_per_sec)
+
+			if (i == sbi->segs_per_sec) {
+				set_section_type(sbi, segno, type);
 				return 0;
+			}
 		}
 
 		if (se->type == type &&
-- 
2.18.0.rc1



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

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

* [f2fs-dev] [PATCH 08/10] f2fs-tools: advise to mount unclean image to replay journal
  2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
                   ` (5 preceding siblings ...)
  2019-08-09 10:52 ` [f2fs-dev] [PATCH 07/10] fsck.f2fs: fix to set large section type during allocation Chao Yu
@ 2019-08-09 10:53 ` Chao Yu
  2019-08-09 10:53 ` [f2fs-dev] [PATCH 09/10] fsck.f2fs: fix to propagate error of write_dquots() Chao Yu
  2019-08-09 10:53 ` [f2fs-dev] [PATCH 10/10] f2fs-tools: add missing newline symbol in log Chao Yu
  8 siblings, 0 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:53 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

For defrag, resize, sload tools, let's advise to mount unclean
image to replay journal first in order to not lose any fsynced
data.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/mount.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/fsck/mount.c b/fsck/mount.c
index ad20d19..6e950bd 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -2969,6 +2969,12 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
 	}
 	cp = F2FS_CKPT(sbi);
 
+	if (c.func != FSCK && c.func != DUMP &&
+		!is_set_ckpt_flags(F2FS_CKPT(sbi), CP_UMOUNT_FLAG)) {
+		ERR_MSG("Mount unclean image to replay log first\n");
+		return -1;
+	}
+
 	print_ckpt_info(sbi);
 
 	if (c.quota_fix) {
-- 
2.18.0.rc1



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

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

* [f2fs-dev] [PATCH 09/10] fsck.f2fs: fix to propagate error of write_dquots()
  2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
                   ` (6 preceding siblings ...)
  2019-08-09 10:53 ` [f2fs-dev] [PATCH 08/10] f2fs-tools: advise to mount unclean image to replay journal Chao Yu
@ 2019-08-09 10:53 ` Chao Yu
  2019-08-09 10:53 ` [f2fs-dev] [PATCH 10/10] f2fs-tools: add missing newline symbol in log Chao Yu
  8 siblings, 0 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:53 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

Propagate correct error number from write_dquots() to
quota_write_inode().

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/mkquota.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fsck/mkquota.c b/fsck/mkquota.c
index c1abbc4..84f9d3d 100644
--- a/fsck/mkquota.c
+++ b/fsck/mkquota.c
@@ -42,10 +42,11 @@ static void print_dquot(const char *desc, struct dquot *dq)
 #define print_dquot(...)
 #endif
 
-static void write_dquots(dict_t *dict, struct quota_handle *qh)
+static int write_dquots(dict_t *dict, struct quota_handle *qh)
 {
 	dnode_t		*n;
 	struct dquot	*dq;
+	int retval = 0;
 
 	for (n = dict_first(dict); n; n = dict_next(dict, n)) {
 		dq = dnode_get(n);
@@ -53,10 +54,13 @@ static void write_dquots(dict_t *dict, struct quota_handle *qh)
 			print_dquot("write", dq);
 			dq->dq_h = qh;
 			update_grace_times(dq);
-			if (qh->qh_ops->commit_dquot(dq))
+			if (qh->qh_ops->commit_dquot(dq)) {
+				retval = -1;
 				break;
+			}
 		}
 	}
+	return retval;
 }
 
 errcode_t quota_write_inode(struct f2fs_sb_info *sbi, enum quota_type qtype)
@@ -83,7 +87,7 @@ errcode_t quota_write_inode(struct f2fs_sb_info *sbi, enum quota_type qtype)
 		if (retval) {
 			log_debug("Cannot initialize io on quotafile");
 		} else {
-			write_dquots(dict, h);
+			retval = write_dquots(dict, h);
 			quota_file_close(sbi, h, 1);
 		}
 	}
-- 
2.18.0.rc1



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

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

* [f2fs-dev] [PATCH 10/10] f2fs-tools: add missing newline symbol in log
  2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
                   ` (7 preceding siblings ...)
  2019-08-09 10:53 ` [f2fs-dev] [PATCH 09/10] fsck.f2fs: fix to propagate error of write_dquots() Chao Yu
@ 2019-08-09 10:53 ` Chao Yu
  8 siblings, 0 replies; 10+ messages in thread
From: Chao Yu @ 2019-08-09 10:53 UTC (permalink / raw)
  To: jaegeuk; +Cc: linux-f2fs-devel

to show pretty log format.

Signed-off-by: Chao Yu <yuchao0@huawei.com>
---
 fsck/segment.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/fsck/segment.c b/fsck/segment.c
index 2d18358..b0c6889 100644
--- a/fsck/segment.c
+++ b/fsck/segment.c
@@ -28,23 +28,23 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to,
 	if (old_blkaddr == NULL_ADDR) {
 		if (c.func == FSCK) {
 			if (fsck->chk.valid_blk_cnt >= sbi->user_block_count) {
-				ERR_MSG("Not enough space");
+				ERR_MSG("Not enough space\n");
 				return -ENOSPC;
 			}
 			if (is_node && fsck->chk.valid_node_cnt >=
 					sbi->total_valid_node_count) {
-				ERR_MSG("Not enough space for node block");
+				ERR_MSG("Not enough space for node block\n");
 				return -ENOSPC;
 			}
 		} else {
 			if (sbi->total_valid_block_count >=
 						sbi->user_block_count) {
-				ERR_MSG("Not enough space");
+				ERR_MSG("Not enough space\n");
 				return -ENOSPC;
 			}
 			if (is_node && sbi->total_valid_node_count >=
 						sbi->total_node_count) {
-				ERR_MSG("Not enough space for node block");
+				ERR_MSG("Not enough space for node block\n");
 				return -ENOSPC;
 			}
 		}
-- 
2.18.0.rc1



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

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

end of thread, other threads:[~2019-08-09 10:53 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-09 10:52 [f2fs-dev] [PATCH 01/10] f2fs-tools: fix potential deadloop Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 02/10] f2fs-tools: fix to avoid memory leak of sit_i->sentries Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 03/10] f2fs-tools: allocate memory in batch in build_sit_info() Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 04/10] fsck.f2fs: introduce current_sit_addr() for cleanup Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 05/10] f2fs-tools: introduce f2fs_ra_meta_pages() Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 06/10] dump.f2fs: introduce start_bidx_of_node() for cleanup Chao Yu
2019-08-09 10:52 ` [f2fs-dev] [PATCH 07/10] fsck.f2fs: fix to set large section type during allocation Chao Yu
2019-08-09 10:53 ` [f2fs-dev] [PATCH 08/10] f2fs-tools: advise to mount unclean image to replay journal Chao Yu
2019-08-09 10:53 ` [f2fs-dev] [PATCH 09/10] fsck.f2fs: fix to propagate error of write_dquots() Chao Yu
2019-08-09 10:53 ` [f2fs-dev] [PATCH 10/10] f2fs-tools: add missing newline symbol in log Chao Yu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.