Skip to contentSkip to conversation

f2fs: update multi-dev metadata in resize_fs

PATCH Superseded sunqiuyang 2 participants 2 messages Sep 18, 2019 – Sep 23, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

sunqiuyang

author
#0 lore raw

PATCH 1/1 f2fs: update multi-dev metadata in resize_fs

From: Qiuyang Sun <[email protected]>

Multi-device metadata should be updated in resize_fs as well.

Also, we check that the new FS size still reaches the last device.

---
 fs/f2fs/gc.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +30 -2
index 5877bd7..a2b8cbe 100644
@@ -1431,26 +1431,46 @@ static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs)
 	int segment_count_main = le32_to_cpu(raw_sb->segment_count_main);
 	long long block_count = le64_to_cpu(raw_sb->block_count);
 	int segs = secs * sbi->segs_per_sec;
+	int ndevs = sbi->s_ndevs;
 
 	raw_sb->section_count = cpu_to_le32(section_count + secs);
 	raw_sb->segment_count = cpu_to_le32(segment_count + segs);
 	raw_sb->segment_count_main = cpu_to_le32(segment_count_main + segs);
 	raw_sb->block_count = cpu_to_le64(block_count +
 					(long long)segs * sbi->blocks_per_seg);
+	if (ndevs > 1) {
+		int dev_segs =
+			le32_to_cpu(raw_sb->devs[ndevs - 1].total_segments);
+
+		raw_sb->devs[ndevs - 1].total_segments =
+						cpu_to_le32(dev_segs + segs);
+	}
 }
 
 static void update_fs_metadata(struct f2fs_sb_info *sbi, int secs)
 {
 	int segs = secs * sbi->segs_per_sec;
+	long long blks = (long long)segs * sbi->blocks_per_seg;
 	long long user_block_count =
 				le64_to_cpu(F2FS_CKPT(sbi)->user_block_count);
+	int ndevs = sbi->s_ndevs;
 
 	SM_I(sbi)->segment_count = (int)SM_I(sbi)->segment_count + segs;
 	MAIN_SEGS(sbi) = (int)MAIN_SEGS(sbi) + segs;
 	FREE_I(sbi)->free_sections = (int)FREE_I(sbi)->free_sections + secs;
 	FREE_I(sbi)->free_segments = (int)FREE_I(sbi)->free_segments + segs;
-	F2FS_CKPT(sbi)->user_block_count = cpu_to_le64(user_block_count +
-					(long long)segs * sbi->blocks_per_seg);
+	F2FS_CKPT(sbi)->user_block_count = cpu_to_le64(user_block_count + blks);
+
+	if (ndevs > 1) {
+		FDEV(ndevs - 1).total_segments =
+				(int)FDEV(ndevs - 1).total_segments + segs;
+		FDEV(ndevs - 1).end_blk =
+				(long long)FDEV(ndevs - 1).end_blk + blks;
+#ifdef CONFIG_BLK_DEV_ZONED
+		FDEV(ndevs - 1).nr_blkz = (int)FDEV(ndevs - 1).nr_blkz +
+					(int)(blks >> sbi->log_blocks_per_blkz);
+#endif
+	}
 }
 
 int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
@@ -1465,6 +1485,14 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
 	if (block_count > old_block_count)
 		return -EINVAL;
 
+	if (sbi->s_ndevs > 1) {
+		__u64 last_segs = FDEV(sbi->s_ndevs - 1).total_segments;
+
+		if (block_count + last_segs * sbi->blocks_per_seg <=
+								old_block_count)
+			return -EINVAL;
+	}
+
 	/* new fs size should align to section size */
 	div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem);
 	if (rem)
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 17 lines · sunqiuyang

From: Qiuyang Sun <[email protected]>

Multi-device metadata should be updated in resize_fs as well.

Also, we check that the new FS size still reaches the last device.

---
 fs/f2fs/gc.c | 32 ++++++++++++++++++++++++++++++--
 1 file changed, 30 insertions(+), 2 deletions(-)
fs/f2fs/gc.c +0 -0
index 5877bd7..a2b8cbe 100644
@@ -1431,26 +1431,46 @@ static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs)
 	int segment_count_main = le32_to_cpu(raw_sb->segment_count_main);

fs/f2fs/gc.c static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs) · line 1441

Quoted 10 lines
fs/f2fs/gc.c +2 -0
 	long long block_count = le64_to_cpu(raw_sb->block_count);
 	int segs = secs * sbi->segs_per_sec;
+	int ndevs = sbi->s_ndevs;
 
 	raw_sb->section_count = cpu_to_le32(section_count + secs);
 	raw_sb->segment_count = cpu_to_le32(segment_count + segs);
 	raw_sb->segment_count_main = cpu_to_le32(segment_count_main + segs);
 	raw_sb->block_count = cpu_to_le64(block_count +
 					(long long)segs * sbi->blocks_per_seg);
+	if (ndevs > 1) {
if (f2fs_is_multi_device(sbi)) {
	int last_ndev = sbi->s_ndevs - 1;
Quoted 15 lines
fs/f2fs/gc.c +8 -0
+		int dev_segs =
+			le32_to_cpu(raw_sb->devs[ndevs - 1].total_segments);
+
+		raw_sb->devs[ndevs - 1].total_segments =
+						cpu_to_le32(dev_segs + segs);
+	}
 }
 
 static void update_fs_metadata(struct f2fs_sb_info *sbi, int secs)
 {
 	int segs = secs * sbi->segs_per_sec;
+	long long blks = (long long)segs * sbi->blocks_per_seg;
 	long long user_block_count =
 				le64_to_cpu(F2FS_CKPT(sbi)->user_block_count);
+	int ndevs = sbi->s_ndevs;

fs/f2fs/gc.c static void update_sb_metadata(struct f2fs_sb_info *sbi, int secs) · line 1464

Quoted 10 lines
fs/f2fs/gc.c +3 -2
 
 	SM_I(sbi)->segment_count = (int)SM_I(sbi)->segment_count + segs;
 	MAIN_SEGS(sbi) = (int)MAIN_SEGS(sbi) + segs;
 	FREE_I(sbi)->free_sections = (int)FREE_I(sbi)->free_sections + secs;
 	FREE_I(sbi)->free_segments = (int)FREE_I(sbi)->free_segments + segs;
-	F2FS_CKPT(sbi)->user_block_count = cpu_to_le64(user_block_count +
-					(long long)segs * sbi->blocks_per_seg);
+	F2FS_CKPT(sbi)->user_block_count = cpu_to_le64(user_block_count + blks);
+
+	if (ndevs > 1) {
if (f2fs_is_multi_device(sbi)) {
	int last_ndev = sbi->s_ndevs - 1;
Quoted 13 lines
fs/f2fs/gc.c +9 -0
+		FDEV(ndevs - 1).total_segments =
+				(int)FDEV(ndevs - 1).total_segments + segs;
+		FDEV(ndevs - 1).end_blk =
+				(long long)FDEV(ndevs - 1).end_blk + blks;
+#ifdef CONFIG_BLK_DEV_ZONED
+		FDEV(ndevs - 1).nr_blkz = (int)FDEV(ndevs - 1).nr_blkz +
+					(int)(blks >> sbi->log_blocks_per_blkz);
+#endif
+	}
 }
 
 int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)

fs/f2fs/gc.c int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count) · line 1488

Quoted 4 lines
fs/f2fs/gc.c +1 -0
@@ -1465,6 +1485,14 @@ int f2fs_resize_fs(struct f2fs_sb_info *sbi, __u64 block_count)
 	if (block_count > old_block_count)
 		return -EINVAL;
 
+	if (sbi->s_ndevs > 1) {
if (f2fs_is_multi_device(sbi)) {
	int last_ndev = sbi->s_ndevs - 1;

Otherwise it looks good to me.

Thanks,

Quoted 11 lines
fs/f2fs/gc.c +7 -0
+		__u64 last_segs = FDEV(sbi->s_ndevs - 1).total_segments;
+
+		if (block_count + last_segs * sbi->blocks_per_seg <=
+								old_block_count)
+			return -EINVAL;
+	}
+
 	/* new fs size should align to section size */
 	div_u64_rem(block_count, BLKS_PER_SEC(sbi), &rem);
 	if (rem)