Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1689315iog; Sat, 18 Jun 2022 17:32:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vZ+3g/g0SZ3W1YkTlyqcAincEvF62V4BEeVelxi7qfa2h1v1EMmkg2GDz0ZKsdaYKTBBQC X-Received: by 2002:a17:907:8c1a:b0:715:73d2:df36 with SMTP id ta26-20020a1709078c1a00b0071573d2df36mr15558472ejc.256.1655598748132; Sat, 18 Jun 2022 17:32:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655598748; cv=none; d=google.com; s=arc-20160816; b=i7/nGnX1FAtw0hHR0xEEZGXPGdatW6lpJm9xOoe1yyGUH4ai3c0haj0hATY3se//PW GBQIZDK61WpR9gZpgrDd467R2y/iEFBEWMnKIco8GyDMeNtj9mKoCugLtjpjjtTAAjwR J+Guc/KF0RTDIuKOKpQiL9nPH3ZSmCRb1477WHc6QPemBmCfKHah3bsSHJZ5Wa5KK9Zf Ygzc/bgSuzlStjF93Ow/NBtDoRhKGxokmhIfLbrICKd7XBiX7jjSmXvxzC6lfyALul8R TH0d7AQTE0y783vi7t+TnEWUxjxOle5O3M4tgTAE3ZigBSp/A1NnzVSU6pHqHSMSNx7J YLoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=3RFnMWfU7UvFmdpe1lIg3TslueidBV9FP28xLQ36xbg=; b=m0RtwRVBk4VhnomjqlR8HlDRLm9OafY6OLnqsTWuYBI/5pzsU83kI4CC6vLkPs7xph Wh0caPcIDERfoU2R4633mb8sdNTDeuIOtDnEOw4NW6+oS1KGENyKdKO7kDZFW8SCqoi1 mWflH2iUOfJxsZesYFfzdYGzr7KSfemfX2O3uNC9mPuL+sl2iiqe7GBkUnY7JpoBes0z 3o7WtcgIBklT4zgEDNme7B/4XJsUvql47CpFQ4ERG0u3aSwrzbT3Id5qB8n2MMSRcnwM U04Vexy9uPEu8Ihck+llUkxbN+owc0yJ9h1tEsRsgXeOvxdRWhp8C1ixhCu3f1KkW7a7 yG2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PyhtF9Ww; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n14-20020a05640205ce00b0042e1708c0ebsi7663838edx.579.2022.06.18.17.32.02; Sat, 18 Jun 2022 17:32:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PyhtF9Ww; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231422AbiFSALA (ORCPT + 99 others); Sat, 18 Jun 2022 20:11:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56990 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229446AbiFSAK7 (ORCPT ); Sat, 18 Jun 2022 20:10:59 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEF7EFD26 for ; Sat, 18 Jun 2022 17:10:57 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 309B1B80B43 for ; Sun, 19 Jun 2022 00:10:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA1FAC3411A; Sun, 19 Jun 2022 00:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655597454; bh=pJavzBOpBup2L2XFujyF+W4cOF5r98O8lnH39scpEWM=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=PyhtF9Wwm/fzM9VqL4TSKYSYMr/ZpGzFqS8u1mazEehsHuuuOTISzzWLBeXibwTrd cMv2p9TdV7k5UUOnxyBnhfVzMuX0UuERo/UrTaPJ9mpGd0Er+KDeMeEpdRTzrU7WI1 6X5qFY5P0dULAPEnlBU+kBtsu6DV+Lu0/zYaqN97GiNL5dzaelMLTW0MY8NW8CwWH1 yLrP+R+0sCQAHLAME/C/E1OxBj33bdL5gcNyp5UACwWxoLkqctZ6xozqgO0r1M/7R3 WXdM+Ait16ErrahcTmz3+jrEbrdNeVRTRXtI1FTDItaR3kcx9AxYUfLp2zHJPorAbi DSiStkGAIsYuw== Message-ID: Date: Sun, 19 Jun 2022 08:10:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH 2/2] f2fs-tools: fix to check free space before grow Content-Language: en-US To: qixiaoyu1 , jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, qixiaoyu1 References: <20220614114929.6897-1-qixiaoyu1@xiaomi.com> <20220614114929.6897-2-qixiaoyu1@xiaomi.com> From: Chao Yu In-Reply-To: <20220614114929.6897-2-qixiaoyu1@xiaomi.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/6/14 19:49, qixiaoyu1 wrote: > Otherwise, after grow, kernel may report below error message > when we mount the image if -o parameter is specified during resize: > > F2FS-fs (loop0): invalid crc_offset: 0 > F2FS-fs (loop0): Wrong valid_user_blocks: 16404, user_block_count: 13312 > F2FS-fs (loop0): Failed to get valid F2FS checkpoint > mount(2) system call failed: Structure needs cleaning. > > Signed-off-by: qixiaoyu1 It looks this patch should be merged into previous one, otherwise -o option support is broken for resize.f2fs. Thanks, > --- > fsck/resize.c | 36 ++++++++++++++++++++++++------------ > 1 file changed, 24 insertions(+), 12 deletions(-) > > diff --git a/fsck/resize.c b/fsck/resize.c > index d19c6fa..e135b66 100644 > --- a/fsck/resize.c > +++ b/fsck/resize.c > @@ -599,6 +599,26 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi, > DBG(0, "Info: Done to rebuild checkpoint blocks\n"); > } > > +static int f2fs_resize_check(struct f2fs_sb_info *sbi, struct f2fs_super_block *new_sb) > +{ > + struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); > + block_t user_block_count; > + unsigned int overprov_segment_count; > + > + overprov_segment_count = (get_newsb(segment_count_main) - > + c.new_reserved_segments) * > + c.new_overprovision / 100; > + overprov_segment_count += c.new_reserved_segments; > + > + user_block_count = (get_newsb(segment_count_main) - > + overprov_segment_count) * c.blks_per_seg; > + > + if (get_cp(valid_block_count) > user_block_count) > + return -1; > + > + return 0; > +} > + > static int f2fs_resize_grow(struct f2fs_sb_info *sbi) > { > struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); > @@ -616,6 +636,9 @@ static int f2fs_resize_grow(struct f2fs_sb_info *sbi) > if (get_new_sb(new_sb)) > return -1; > > + if (f2fs_resize_check(sbi, new_sb) < 0) > + return -1; > + > /* check nat availability */ > if (get_sb(segment_count_nat) > get_newsb(segment_count_nat)) { > err = shrink_nats(sbi, new_sb); > @@ -659,11 +682,8 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) > struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); > struct f2fs_super_block new_sb_raw; > struct f2fs_super_block *new_sb = &new_sb_raw; > - struct f2fs_checkpoint *cp = F2FS_CKPT(sbi); > block_t old_end_blkaddr, old_main_blkaddr; > block_t new_end_blkaddr, new_main_blkaddr, tmp_end_blkaddr; > - block_t user_block_count; > - unsigned int overprov_segment_count; > unsigned int offset; > int err = -1; > > @@ -674,15 +694,7 @@ static int f2fs_resize_shrink(struct f2fs_sb_info *sbi) > if (get_new_sb(new_sb)) > return -1; > > - overprov_segment_count = (get_newsb(segment_count_main) - > - c.new_reserved_segments) * > - c.new_overprovision / 100; > - overprov_segment_count += c.new_reserved_segments; > - > - user_block_count = (get_newsb(segment_count_main) - > - overprov_segment_count) * c.blks_per_seg; > - > - if (get_cp(valid_block_count) > user_block_count) > + if (f2fs_resize_check(sbi, new_sb) < 0) > return -1; > > /* check nat availability */