Skip to contentSkip to conversation

f2fs-tools: fix the wrong sbi->cur_cp setting

PATCH In review Wang Xiaojun 2 participants 5 messages Oct 25, 2021 – Oct 26, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 f2fs-tools: fix the wrong sbi->cur_cp setting

If sbi->cur_cp is 2 and the duplicate_checkpoint function returns in advance because sbi->cp_backuped is set to true, we cannot set sbi->cur_cp to 1.

---
 fsck/fsck.c  | 3 ---
 fsck/mount.c | 5 ++---
 2 files changed, 2 insertions(+), 6 deletions(-)
fsck/fsck.c +0 -3
index 110c1ec..aa77a34 100644
@@ -2383,9 +2383,6 @@ static void fix_checkpoints(struct f2fs_sb_info *sbi)
 {
 	/* copy valid checkpoint to its mirror position */
 	duplicate_checkpoint(sbi);
-
-	/* repair checkpoint at CP #0 position */
-	sbi->cur_cp = 1;
 	fix_checkpoint(sbi);
 }
 
fsck/mount.c +2 -3
index c928a15..295170e 100644
@@ -2998,6 +2998,8 @@ void duplicate_checkpoint(struct f2fs_sb_info *sbi)
 	ASSERT(ret >= 0);
 
 	sbi->cp_backuped = 1;
+	/* repair checkpoint at CP #0 position */
+	sbi->cur_cp = 1;
 
 	MSG(0, "Info: Duplicate valid checkpoint to mirror position "
 		"%llu -> %llu\n", src, dst);
@@ -3098,9 +3100,6 @@ void write_checkpoints(struct f2fs_sb_info *sbi)
 {
 	/* copy valid checkpoint to its mirror position */
 	duplicate_checkpoint(sbi);
-
-	/* repair checkpoint at CP #0 position */
-	sbi->cur_cp = 1;
 	write_checkpoint(sbi);
 }
 
Signature · 8 lines
2.31.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
#1 lore raw
Quoted 3 lines · Wang Xiaojun

If sbi->cur_cp is 2 and the duplicate_checkpoint function returns in advance because sbi->cp_backuped is set to true, we cannot set sbi->cur_cp to 1.

Hmmm, in previous implementation, what problem we will encounter, and what's the root cause?

Thanks,

Quoted 36 lines
---
  fsck/fsck.c  | 3 ---
  fsck/mount.c | 5 ++---
  2 files changed, 2 insertions(+), 6 deletions(-)
fsck/fsck.c +0 -3
index 110c1ec..aa77a34 100644
@@ -2383,9 +2383,6 @@ static void fix_checkpoints(struct f2fs_sb_info *sbi)
  {
  	/* copy valid checkpoint to its mirror position */
  	duplicate_checkpoint(sbi);
-
-	/* repair checkpoint at CP #0 position */
-	sbi->cur_cp = 1;
  	fix_checkpoint(sbi);
  }
 
fsck/mount.c +2 -0
index c928a15..295170e 100644
@@ -2998,6 +2998,8 @@ void duplicate_checkpoint(struct f2fs_sb_info *sbi)
  	ASSERT(ret >= 0);
 
  	sbi->cp_backuped = 1;
+	/* repair checkpoint at CP #0 position */
+	sbi->cur_cp = 1;
 
  	MSG(0, "Info: Duplicate valid checkpoint to mirror position "
  		"%llu -> %llu\n", src, dst);

fsck/mount.c void write_checkpoints(struct f2fs_sb_info *sbi) · line 3105

Quoted 9 lines
fsck/mount.c +0 -3
@@ -3098,9 +3100,6 @@ void write_checkpoints(struct f2fs_sb_info *sbi)
  {
  	/* copy valid checkpoint to its mirror position */
  	duplicate_checkpoint(sbi);
-
-	/* repair checkpoint at CP #0 position */
-	sbi->cur_cp = 1;
  	write_checkpoint(sbi);
  }
 

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#2 lore raw
Quoted 9 lines · Chao Yu
Quoted 3 lines · Wang Xiaojun

If sbi->cur_cp is 2 and the duplicate_checkpoint function returns in advance because sbi->cp_backuped is set to true, we cannot set sbi->cur_cp to 1.

Hmmm, in previous implementation, what problem we will encounter, and what's the root cause?

Thanks,

In fact, it's not causing problems at this time.

During the code review, I found that this was not logically reasonable.

This parameter(sbi->cur_cp) can be set to 1 only after successful replication.

Thanks,

Quoted 37 lines
Quoted 37 lines

---
  fsck/fsck.c  | 3 ---
  fsck/mount.c | 5 ++---

  2 files changed, 2 insertions(+), 6 deletions(-)
fsck/fsck.c +0 -3
index 110c1ec..aa77a34 100644
@@ -2383,9 +2383,6 @@ static void fix_checkpoints(struct f2fs_sb_info 
 *sbi)
   {
       /* copy valid checkpoint to its mirror position */
       duplicate_checkpoint(sbi);
-
-    /* repair checkpoint at CP #0 position */
-    sbi->cur_cp = 1;
       fix_checkpoint(sbi);
   }

  diff --git a/fsck/mount.c b/fsck/mount.c
index c928a15..295170e 100644

fsck/mount.c +2 -0
@@ -2998,6 +2998,8 @@ void duplicate_checkpoint(struct f2fs_sb_info 
 *sbi)
       ASSERT(ret >= 0);
         sbi->cp_backuped = 1;
+    /* repair checkpoint at CP #0 position */
+    sbi->cur_cp = 1;

        MSG(0, "Info: Duplicate valid checkpoint to mirror position " "%llu -> %llu\n", src, dst);

fsck/mount.c +0 -0
@@ -3098,9 +3100,6 @@ void write_checkpoints(struct f2fs_sb_info *sbi)
   {
       /* copy valid checkpoint to its mirror position */
Quoted 8 lines

fsck/mount.c void write_checkpoints(struct f2fs_sb_info *sbi) · line 3105

Quoted 7 lines
fsck/mount.c +0 -3
       duplicate_checkpoint(sbi);
-
-    /* repair checkpoint at CP #0 position */
-    sbi->cur_cp = 1;
       write_checkpoint(sbi);
   }
 

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#3 lore raw
Quoted 10 lines · Wang Xiaojun
Quoted 8 lines · Chao Yu
Quoted 3 lines · Wang Xiaojun

If sbi->cur_cp is 2 and the duplicate_checkpoint function returns in advance because sbi->cp_backuped is set to true, we cannot set sbi->cur_cp to 1.

Hmmm, in previous implementation, what problem we will encounter, and what's the root cause?

Quoted 7 lines
Quoted 1 line

Thanks,

In fact, it's not causing problems at this time.

During the code review, I found that this was not logically reasonable.

This parameter(sbi->cur_cp) can be set to 1 only after successful replication.

IIRC, after mirroring checkpoint (cp_backuped == 1), we choose to always update CP #0 area, so once SPO occurs, at least there is one valid checkpoint can be kept in CP #1 area. [1]

[1] 81bad9d11ea5 ("fsck.f2fs: write checkpoint with OPU mode")

Thanks,

Quoted 46 lines

Thanks,

Quoted 43 lines
Quoted 33 lines

---
  fsck/fsck.c  | 3 ---
  fsck/mount.c | 5 ++---

  2 files changed, 2 insertions(+), 6 deletions(-)
fsck/fsck.c +0 -3
index 110c1ec..aa77a34 100644
@@ -2383,9 +2383,6 @@ static void fix_checkpoints(struct f2fs_sb_info *sbi)
   {
       /* copy valid checkpoint to its mirror position */
       duplicate_checkpoint(sbi);
-
-    /* repair checkpoint at CP #0 position */
-    sbi->cur_cp = 1;
       fix_checkpoint(sbi);
   }

  diff --git a/fsck/mount.c b/fsck/mount.c
index c928a15..295170e 100644

fsck/mount.c +2 -0
@@ -2998,6 +2998,8 @@ void duplicate_checkpoint(struct f2fs_sb_info *sbi)
       ASSERT(ret >= 0);
         sbi->cp_backuped = 1;
+    /* repair checkpoint at CP #0 position */
+    sbi->cur_cp = 1;

        MSG(0, "Info: Duplicate valid checkpoint to mirror position " "%llu -> %llu\n", src, dst);

fsck/mount.c void write_checkpoints(struct f2fs_sb_info *sbi) · line 3105

Quoted 9 lines
fsck/mount.c +0 -3
@@ -3098,9 +3100,6 @@ void write_checkpoints(struct f2fs_sb_info *sbi)
   {
       /* copy valid checkpoint to its mirror position */
       duplicate_checkpoint(sbi);
-
-    /* repair checkpoint at CP #0 position */
-    sbi->cur_cp = 1;
       write_checkpoint(sbi);
   }
 

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

#4 lore raw
Quoted 19 lines · Chao Yu
Quoted 10 lines · Wang Xiaojun
Quoted 8 lines · Chao Yu
Quoted 3 lines · Wang Xiaojun

If sbi->cur_cp is 2 and the duplicate_checkpoint function returns in advance because sbi->cp_backuped is set to true, we cannot set sbi->cur_cp to 1.

Hmmm, in previous implementation, what problem we will encounter, and what's the root cause?

Quoted 7 lines
Quoted 1 line

Thanks,

In fact, it's not causing problems at this time.

During the code review, I found that this was not logically reasonable.

This parameter(sbi->cur_cp) can be set to 1 only after successful replication.

Quoted 7 lines

IIRC, after mirroring checkpoint (cp_backuped == 1), we choose to always update CP #0 area, so once SPO occurs, at least there is one valid checkpoint can be kept in CP #1 area. [1]

[1] 81bad9d11ea5 ("fsck.f2fs: write checkpoint with OPU mode")

Thanks,

Got it. thanks

Quoted 49 lines
Quoted 49 lines

Thanks,

Quoted 45 lines
Quoted 35 lines

---
  fsck/fsck.c  | 3 ---
  fsck/mount.c | 5 ++---

  2 files changed, 2 insertions(+), 6 deletions(-)
fsck/fsck.c +0 -3
index 110c1ec..aa77a34 100644
@@ -2383,9 +2383,6 @@ static void fix_checkpoints(struct 
 f2fs_sb_info *sbi)
   {
       /* copy valid checkpoint to its mirror position */
       duplicate_checkpoint(sbi);
-
-    /* repair checkpoint at CP #0 position */
-    sbi->cur_cp = 1;
       fix_checkpoint(sbi);
   }

  diff --git a/fsck/mount.c b/fsck/mount.c
index c928a15..295170e 100644

fsck/mount.c +2 -0
@@ -2998,6 +2998,8 @@ void duplicate_checkpoint(struct f2fs_sb_info 
 *sbi)
       ASSERT(ret >= 0);
         sbi->cp_backuped = 1;
+    /* repair checkpoint at CP #0 position */
+    sbi->cur_cp = 1;

        MSG(0, "Info: Duplicate valid checkpoint to mirror position " "%llu -> %llu\n", src, dst);

fsck/mount.c void write_checkpoints(struct f2fs_sb_info *sbi) · line 3105

Quoted 9 lines
fsck/mount.c +0 -3
@@ -3098,9 +3100,6 @@ void write_checkpoints(struct f2fs_sb_info *sbi)
   {
       /* copy valid checkpoint to its mirror position */
       duplicate_checkpoint(sbi);
-
-    /* repair checkpoint at CP #0 position */
-    sbi->cur_cp = 1;
       write_checkpoint(sbi);
   }
 

.

Quoted 1 line

.

_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel