linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
From: sunqiuyang <sunqiuyang@huawei.com>
To: <linux-f2fs-devel@lists.sourceforge.net>, <jaegeuk@kernel.org>,
	<yuchao0@huawei.com>
Cc: fangwei1@huawei.com, sunqiuyang@huawei.com
Subject: [f2fs-dev] [PATCH 1/1] fsck.f2fs: allow to fix inconsistency from online resize
Date: Tue, 2 Jul 2019 15:42:01 +0800	[thread overview]
Message-ID: <20190702074201.34869-1-sunqiuyang@huawei.com> (raw)

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

             reply	other threads:[~2019-07-02  7:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-02  7:42 sunqiuyang [this message]
2019-07-03  6:29 ` [f2fs-dev] [PATCH 1/1] fsck.f2fs: allow to fix inconsistency from online resize Chao Yu
2019-07-04  1:23   ` sunqiuyang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190702074201.34869-1-sunqiuyang@huawei.com \
    --to=sunqiuyang@huawei.com \
    --cc=fangwei1@huawei.com \
    --cc=jaegeuk@kernel.org \
    --cc=linux-f2fs-devel@lists.sourceforge.net \
    --cc=yuchao0@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).