linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH 1/1] fsck.f2fs: allow to fix inconsistency from online resize
@ 2019-07-02  7:42 sunqiuyang
  2019-07-03  6:29 ` Chao Yu
  0 siblings, 1 reply; 3+ messages in thread
From: sunqiuyang @ 2019-07-02  7:42 UTC (permalink / raw)
  To: linux-f2fs-devel, jaegeuk, yuchao0; +Cc: fangwei1, sunqiuyang

From: Qiuyang Sun <sunqiuyang@huawei.com>

During F2FS online resize, if panic or poweroff happens when the new SB
has been committed but not the new CP, the FS may end up with an
inconsistent state, where user_block_count and free_segment_count in CP 
can be larger than allowed by the new SB.

This patch allows fsck.f2fs to fix such inconsistency.

Signed-off-by: Qiuyang Sun <sunqiuyang@huawei.com>
---
 fsck/fsck.c  | 2 ++
 fsck/mount.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/fsck/fsck.c b/fsck/fsck.c
index 6f0f262..66eb53c 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -2083,6 +2083,8 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
 	set_cp(valid_block_count, fsck->chk.valid_blk_cnt);
 	set_cp(valid_node_count, fsck->chk.valid_node_cnt);
 	set_cp(valid_inode_count, fsck->chk.valid_inode_cnt);
+	set_cp(user_block_count, (uint64_t)(get_sb(segment_count_main) -
+			get_cp(overprov_segment_count)) * c.blks_per_seg);
 
 	crc = f2fs_checkpoint_chksum(cp);
 	*((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) =
diff --git a/fsck/mount.c b/fsck/mount.c
index aecd0cd..81ab660 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -953,7 +953,7 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
 	segment_count_main = get_sb(segment_count_main);
 	log_blocks_per_seg = get_sb(log_blocks_per_seg);
 	if (!user_block_count || user_block_count >=
-			segment_count_main << log_blocks_per_seg) {
+			c.total_sectors / c.sectors_per_blk) {
 		MSG(0, "\tWrong user_block_count(%u)\n", user_block_count);
 		return 1;
 	}
-- 
1.8.3.1



_______________________________________________
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] 3+ messages in thread

* Re: [f2fs-dev] [PATCH 1/1] fsck.f2fs: allow to fix inconsistency from online resize
  2019-07-02  7:42 [f2fs-dev] [PATCH 1/1] fsck.f2fs: allow to fix inconsistency from online resize sunqiuyang
@ 2019-07-03  6:29 ` Chao Yu
  2019-07-04  1:23   ` sunqiuyang
  0 siblings, 1 reply; 3+ messages in thread
From: Chao Yu @ 2019-07-03  6:29 UTC (permalink / raw)
  To: sunqiuyang, linux-f2fs-devel, jaegeuk; +Cc: fangwei1

On 2019/7/2 15:42, sunqiuyang wrote:
> From: Qiuyang Sun <sunqiuyang@huawei.com>
> 
> During F2FS online resize, if panic or poweroff happens when the new SB
> has been committed but not the new CP, the FS may end up with an
> inconsistent state, where user_block_count and free_segment_count in CP 
> can be larger than allowed by the new SB.
> 
> This patch allows fsck.f2fs to fix such inconsistency.
> 
> Signed-off-by: Qiuyang Sun <sunqiuyang@huawei.com>
> ---
>  fsck/fsck.c  | 2 ++
>  fsck/mount.c | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/fsck/fsck.c b/fsck/fsck.c
> index 6f0f262..66eb53c 100644
> --- a/fsck/fsck.c
> +++ b/fsck/fsck.c
> @@ -2083,6 +2083,8 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
>  	set_cp(valid_block_count, fsck->chk.valid_blk_cnt);
>  	set_cp(valid_node_count, fsck->chk.valid_node_cnt);
>  	set_cp(valid_inode_count, fsck->chk.valid_inode_cnt);
> +	set_cp(user_block_count, (uint64_t)(get_sb(segment_count_main) -
> +			get_cp(overprov_segment_count)) * c.blks_per_seg);
>  
>  	crc = f2fs_checkpoint_chksum(cp);
>  	*((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) =
> diff --git a/fsck/mount.c b/fsck/mount.c
> index aecd0cd..81ab660 100644
> --- a/fsck/mount.c
> +++ b/fsck/mount.c
> @@ -953,7 +953,7 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
>  	segment_count_main = get_sb(segment_count_main);
>  	log_blocks_per_seg = get_sb(log_blocks_per_seg);
>  	if (!user_block_count || user_block_count >=
> -			segment_count_main << log_blocks_per_seg) {
> +			c.total_sectors / c.sectors_per_blk) {

This breaks the previous consistency check, then cp.user_block_count could still
be corrupted due to we won't call fix_checkpoint later.

Other concern is if user upgrade kernel only, with low version of fsck, user
can't repair image suffering power-cut during online resizing, so I wonder that
is there a way to find such inconsistency and give a hint to user that which
version of fsck can repair such corruption.

Thanks,

>  		MSG(0, "\tWrong user_block_count(%u)\n", user_block_count);
>  		return 1;
>  	}
> 


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

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

* Re: [f2fs-dev] [PATCH 1/1] fsck.f2fs: allow to fix inconsistency from online resize
  2019-07-03  6:29 ` Chao Yu
@ 2019-07-04  1:23   ` sunqiuyang
  0 siblings, 0 replies; 3+ messages in thread
From: sunqiuyang @ 2019-07-04  1:23 UTC (permalink / raw)
  To: Yuchao (T), linux-f2fs-devel, jaegeuk; +Cc: fangwei (I)

A quick comment: if cp.user_block_count is corrupted due to resize failure, then cp.free_segment_count will also be corrupted. Then in fsck_verify(), we will find the check "free segment_count matched with CP" fails, and still call fix_checkpoint() later.

Thanks,
________________________________________
From: Yuchao (T)
Sent: Wednesday, July 03, 2019 14:29
To: sunqiuyang; linux-f2fs-devel@lists.sourceforge.net; jaegeuk@kernel.org
Cc: fangwei (I)
Subject: Re: [PATCH 1/1] fsck.f2fs: allow to fix inconsistency from online resize

On 2019/7/2 15:42, sunqiuyang wrote:
> From: Qiuyang Sun <sunqiuyang@huawei.com>
>
> During F2FS online resize, if panic or poweroff happens when the new SB
> has been committed but not the new CP, the FS may end up with an
> inconsistent state, where user_block_count and free_segment_count in CP
> can be larger than allowed by the new SB.
>
> This patch allows fsck.f2fs to fix such inconsistency.
>
> Signed-off-by: Qiuyang Sun <sunqiuyang@huawei.com>
> ---
>  fsck/fsck.c  | 2 ++
>  fsck/mount.c | 2 +-
>  2 files changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/fsck/fsck.c b/fsck/fsck.c
> index 6f0f262..66eb53c 100644
> --- a/fsck/fsck.c
> +++ b/fsck/fsck.c
> @@ -2083,6 +2083,8 @@ static void fix_checkpoint(struct f2fs_sb_info *sbi)
>       set_cp(valid_block_count, fsck->chk.valid_blk_cnt);
>       set_cp(valid_node_count, fsck->chk.valid_node_cnt);
>       set_cp(valid_inode_count, fsck->chk.valid_inode_cnt);
> +     set_cp(user_block_count, (uint64_t)(get_sb(segment_count_main) -
> +                     get_cp(overprov_segment_count)) * c.blks_per_seg);
>
>       crc = f2fs_checkpoint_chksum(cp);
>       *((__le32 *)((unsigned char *)cp + get_cp(checksum_offset))) =
> diff --git a/fsck/mount.c b/fsck/mount.c
> index aecd0cd..81ab660 100644
> --- a/fsck/mount.c
> +++ b/fsck/mount.c
> @@ -953,7 +953,7 @@ int sanity_check_ckpt(struct f2fs_sb_info *sbi)
>       segment_count_main = get_sb(segment_count_main);
>       log_blocks_per_seg = get_sb(log_blocks_per_seg);
>       if (!user_block_count || user_block_count >=
> -                     segment_count_main << log_blocks_per_seg) {
> +                     c.total_sectors / c.sectors_per_blk) {

This breaks the previous consistency check, then cp.user_block_count could still
be corrupted due to we won't call fix_checkpoint later.

Other concern is if user upgrade kernel only, with low version of fsck, user
can't repair image suffering power-cut during online resizing, so I wonder that
is there a way to find such inconsistency and give a hint to user that which
version of fsck can repair such corruption.

Thanks,

>               MSG(0, "\tWrong user_block_count(%u)\n", user_block_count);
>               return 1;
>       }
>

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

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

end of thread, other threads:[~2019-07-04  1:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-02  7:42 [f2fs-dev] [PATCH 1/1] fsck.f2fs: allow to fix inconsistency from online resize sunqiuyang
2019-07-03  6:29 ` Chao Yu
2019-07-04  1:23   ` sunqiuyang

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