Skip to contentSkip to conversation

f2fs-tools: fix blocks allocation direction inside segment

RFC PATCH In review Junling Zheng 3 participants 3 messages May 8, 2018 – May 18, 2018

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 f2fs-tools: fix blocks allocation direction inside segment

This fixes the block allocation direction from left to right inside one segment despite of the direction of segment allocation.

---
 fsck/mount.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fsck/mount.c +6 -3
index 1396a2e..38d2aa2 100644
@@ -1921,13 +1921,13 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 
 		if (se->valid_blocks == sbi->blocks_per_seg ||
 				IS_CUR_SEGNO(sbi, segno, type)) {
-			*to = left ? START_BLOCK(sbi, segno) - 1:
+			*to = left ? START_BLOCK(sbi, segno - 1) :
 						START_BLOCK(sbi, segno + 1);
 			continue;
 		}
 
 		if (se->valid_blocks == 0 && not_enough) {
-			*to = left ? START_BLOCK(sbi, segno) - 1:
+			*to = left ? START_BLOCK(sbi, segno - 1) :
 						START_BLOCK(sbi, segno + 1);
 			continue;
 		}
@@ -1949,7 +1949,10 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 			!f2fs_test_bit(offset, (const char *)se->cur_valid_map))
 			return 0;
 
-		*to = left ? *to - 1: *to + 1;
+		if (!(OFFSET_IN_SEG(sbi, *to + 1)) && left)
+			*to = START_BLOCK(sbi, segno - 1);
+		else
+			*to = *to + 1;
 	}
 	return -1;
 }
Signature · 6 lines
2.16.2


------------------------------------------------------------------------------
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
Quoted 2 lines · Junling Zheng

This fixes the block allocation direction from left to right inside one segment despite of the direction of segment allocation.

Hmm.. there is no such restriction that we have to keep misc tools' allocation algorithm line with kernel one, so I suggest that let's just keep original codes. Jaegeuk, what's your opinion?

Thanks,

Quoted 29 lines
---
 fsck/mount.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fsck/mount.c +2 -2
index 1396a2e..38d2aa2 100644
@@ -1921,13 +1921,13 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 
 		if (se->valid_blocks == sbi->blocks_per_seg ||
 				IS_CUR_SEGNO(sbi, segno, type)) {
-			*to = left ? START_BLOCK(sbi, segno) - 1:
+			*to = left ? START_BLOCK(sbi, segno - 1) :
 						START_BLOCK(sbi, segno + 1);
 			continue;
 		}
 
 		if (se->valid_blocks == 0 && not_enough) {
-			*to = left ? START_BLOCK(sbi, segno) - 1:
+			*to = left ? START_BLOCK(sbi, segno - 1) :
 						START_BLOCK(sbi, segno + 1);
 			continue;
 		}
@@ -1949,7 +1949,10 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 			!f2fs_test_bit(offset, (const char *)se->cur_valid_map))

fsck/mount.c int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type) · line 1958

Quoted 10 lines
fsck/mount.c +4 -1
 			return 0;
 
-		*to = left ? *to - 1: *to + 1;
+		if (!(OFFSET_IN_SEG(sbi, *to + 1)) && left)
+			*to = START_BLOCK(sbi, segno - 1);
+		else
+			*to = *to + 1;
 	}
 	return -1;
 }

------------------------------------------------------------------------------
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
Quoted 7 lines · Chao Yu
Quoted 2 lines · Junling Zheng

This fixes the block allocation direction from left to right inside one segment despite of the direction of segment allocation.

Hmm.. there is no such restriction that we have to keep misc tools' allocation algorithm line with kernel one, so I suggest that let's just keep original codes. Jaegeuk, what's your opinion?

Yeah, let's keep it as is.

Quoted 33 lines

Thanks,

Quoted 30 lines
---
 fsck/mount.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
fsck/mount.c +2 -2
index 1396a2e..38d2aa2 100644
@@ -1921,13 +1921,13 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 
 		if (se->valid_blocks == sbi->blocks_per_seg ||
 				IS_CUR_SEGNO(sbi, segno, type)) {
-			*to = left ? START_BLOCK(sbi, segno) - 1:
+			*to = left ? START_BLOCK(sbi, segno - 1) :
 						START_BLOCK(sbi, segno + 1);
 			continue;
 		}
 
 		if (se->valid_blocks == 0 && not_enough) {
-			*to = left ? START_BLOCK(sbi, segno) - 1:
+			*to = left ? START_BLOCK(sbi, segno - 1) :
 						START_BLOCK(sbi, segno + 1);
 			continue;
 		}
@@ -1949,7 +1949,10 @@ int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type)
 			!f2fs_test_bit(offset, (const char *)se->cur_valid_map))
 			return 0;
 
Quoted 9 lines

fsck/mount.c int find_next_free_block(struct f2fs_sb_info *sbi, u64 *to, int left, int type) · line 1958

Quoted 9 lines
fsck/mount.c +4 -1
-		*to = left ? *to - 1: *to + 1;
+		if (!(OFFSET_IN_SEG(sbi, *to + 1)) && left)
+			*to = START_BLOCK(sbi, segno - 1);
+		else
+			*to = *to + 1;
 	}
 	return -1;
 }

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