From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F11EE3859CE for ; Mon, 3 Aug 2026 07:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785742750; cv=none; b=TjJy4uEfg2zbwfjaK+D8fZTj+yLLwykIM5JzdT72JWgzjK3ew7QMEr66far991GKHwflCUeac2EDmpJyjXKjdyeR/4m6zx9fs2ZW+JgLhNOWnUKmxSQVWsdolRcxkRqpRLLb5gsMDauVXi76m76z7hmaURo4SbrebNrLdwWMbwg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785742750; c=relaxed/simple; bh=LLItmxU5LjcE6eMg1cXoKjueh1zuJLp30EKi/qFoqLE=; h=Message-ID:Date:MIME-Version:Cc:Subject:To:References:From: In-Reply-To:Content-Type; b=j/aMWmrheMkliLFaqsXffCng19r48cuZsmwlrbr/KY9hWXYX0TmdBPftmTw4xOjNJMPh8O8aob8zqg/vn46OcSmVGOdFx1peRqod5BNNN7FMkQVREVnoUbus65NRSjr8+bAj2GJ0iRm2qM9Hii3DmQDozD1b3yfbKePl6ZEyrGQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LMRdESgw; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="LMRdESgw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 60D311F00A3A; Mon, 3 Aug 2026 07:39:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785742748; bh=fejKHcPM2ITUhqGAzQ+zd1iL7MlkWRA5eMaBt7uQOrY=; h=Date:Cc:Subject:To:References:From:In-Reply-To; b=LMRdESgwY+8jtpGWjXA5C7Lr5qXvWRppNMiOfBW1WqJZ6O9fXkK87G3WylRNejc/W VdMB2BxMXCYaWSZKIQE7ok3vMnArpzK23t5UeoaNSqaaY5TEKA4Y1sGzh2kt/IFnuk g4Y0M8luZHxmpwc3UepuNmsru1a66s8GxPEEx9fD52CHPxqr1T8J8R401AzF23vcxK 7CmY4atNTOFUMJkSpqCoUX8Wy69nUUrlsPxAQA07HZwwSWzRLwIBrq75Hg+YNnJLWz ks+6aw4mA6ZfJs6HvOzJPhBz1klRP9eZtlVaO9UZ0+BBtPAi151eDRttP15r1rvLMJ Wk5/lC+GEvvHw== Message-ID: Date: Mon, 3 Aug 2026 15:39:05 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Cc: chao@kernel.org, Daeho Jeong Subject: Re: [f2fs-dev] [PATCH] fsck.f2fs: handle find_next_free_block failure gracefully To: Daeho Jeong , linux-kernel@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, kernel-team@android.com References: <20260723193544.2462174-1-daeho43@gmail.com> Content-Language: en-US From: Chao Yu In-Reply-To: <20260723193544.2462174-1-daeho43@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 7/24/26 03:35, Daeho Jeong wrote: > From: Daeho Jeong > > When find_next_free_block() fails to allocate a free block, callers like > move_one_curseg_info(), reserve_new_block(), and update_block() previously > crashed via ASSERT(). Seems there are a lot of ASSERT() in path of above functions? e.g. f2fs_create /* write child */ set_summary(&sum, de->ino, 0, ni.version); ret = reserve_new_block(sbi, &blkaddr, &sum, CURSEG_HOT_NODE, 1); nodeblk_alloced = true; ASSERT(!ret); convert_inline_dentry ret = update_block(sbi, node, p_blkaddr, NULL); ASSERT(ret >= 0); Can you please take a look? > > Replace these ASSERT() calls with proper error propagation to gracefully > abort FSCK execution instead of crashing. > > Signed-off-by: Daeho Jeong > --- > fsck/fsck.c | 22 +++++++++++++++------- > fsck/fsck.h | 8 ++++---- > fsck/main.c | 4 +++- > fsck/mount.c | 28 ++++++++++++++++++---------- > fsck/segment.c | 8 ++++---- > 5 files changed, 44 insertions(+), 26 deletions(-) > > diff --git a/fsck/fsck.c b/fsck/fsck.c > index db44f9d..b128617 100644 > --- a/fsck/fsck.c > +++ b/fsck/fsck.c > @@ -2972,13 +2972,15 @@ int check_curseg_offsets(struct f2fs_sb_info *sbi, bool check_wp) > return 0; > } > > -static void fix_curseg_info(struct f2fs_sb_info *sbi, bool check_wp) > +static int fix_curseg_info(struct f2fs_sb_info *sbi, bool check_wp) > { > - int i, need_update = 0; > + int i, need_update = 0, ret; > > for (i = 0; i < NO_CHECK_TYPE; i++) { > if (check_curseg_offset(sbi, i, check_wp)) { > - update_curseg_info(sbi, i); > + ret = update_curseg_info(sbi, i); Another caller of fix_curseg_info(), fsck_verify() will accept the failure silently, I think it needs to propagate the error to do_fsck(). Thanks, > + if (ret) > + return ret; > need_update = 1; > } > } > @@ -2987,6 +2989,7 @@ static void fix_curseg_info(struct f2fs_sb_info *sbi, bool check_wp) > write_curseg_info(sbi); > flush_curseg_sit_entries(sbi); > } > + return 0; > } > > int check_sit_types(struct f2fs_sb_info *sbi) > @@ -3595,23 +3598,28 @@ static void fix_wp_sit_alignment(struct f2fs_sb_info *UNUSED(sbi)) > * Check and fix consistency with write pointers at the beginning of > * fsck so that following writes by fsck do not fail. > */ > -void fsck_chk_and_fix_write_pointers(struct f2fs_sb_info *sbi) > +int fsck_chk_and_fix_write_pointers(struct f2fs_sb_info *sbi) > { > struct f2fs_fsck *fsck = F2FS_FSCK(sbi); > + int ret = 0; > > if (c.zoned_model != F2FS_ZONED_HM) > - return; > + return 0; > > if (c.fix_on) { > flush_nat_journal_entries(sbi); > flush_sit_journal_entries(sbi); > > - if (check_curseg_offsets(sbi, true)) > - fix_curseg_info(sbi, true); > + if (check_curseg_offsets(sbi, true)) { > + ret = fix_curseg_info(sbi, true); > + if (ret) > + return ret; > + } > > fix_wp_sit_alignment(sbi); > fsck->chk.wp_fixed = 1; > } > + return 0; > } > > int fsck_chk_curseg_info(struct f2fs_sb_info *sbi) > diff --git a/fsck/fsck.h b/fsck/fsck.h > index 05daa2d..ec37e08 100644 > --- a/fsck/fsck.h > +++ b/fsck/fsck.h > @@ -190,7 +190,7 @@ int fsck_chk_inline_dentries(struct f2fs_sb_info *, struct f2fs_node *, > void fsck_chk_checkpoint(struct f2fs_sb_info *sbi); > void fsck_update_sb_flags(struct f2fs_sb_info *sbi); > int fsck_chk_meta(struct f2fs_sb_info *sbi); > -void fsck_chk_and_fix_write_pointers(struct f2fs_sb_info *); > +int fsck_chk_and_fix_write_pointers(struct f2fs_sb_info *sbi); > int fsck_chk_curseg_info(struct f2fs_sb_info *); > void pretty_print_filename(const u8 *raw_name, u32 len, > char out[F2FS_PRINT_NAMELEN], int enc_name); > @@ -227,11 +227,11 @@ extern int f2fs_find_fsync_inode(struct f2fs_sb_info *, struct list_head *); > extern void f2fs_destroy_fsync_dnodes(struct list_head *); > > extern void flush_journal_entries(struct f2fs_sb_info *); > -extern void update_curseg_info(struct f2fs_sb_info *, int); > +extern int update_curseg_info(struct f2fs_sb_info *sbi, int type); > extern void zero_journal_entries(struct f2fs_sb_info *); > extern void flush_sit_entries(struct f2fs_sb_info *); > -extern void move_curseg_info(struct f2fs_sb_info *, u64, int); > -extern void move_one_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left, > +extern int move_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left); > +extern int move_one_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left, > int i); > extern void write_curseg_info(struct f2fs_sb_info *); > extern void save_curseg_warm_node_info(struct f2fs_sb_info *); > diff --git a/fsck/main.c b/fsck/main.c > index 08d38d8..460e4db 100644 > --- a/fsck/main.c > +++ b/fsck/main.c > @@ -985,7 +985,9 @@ static int do_fsck(struct f2fs_sb_info *sbi) > if (c.roll_forward && c.zoned_model == F2FS_ZONED_HM) > save_curseg_warm_node_info(sbi); > > - fsck_chk_and_fix_write_pointers(sbi); > + ret = fsck_chk_and_fix_write_pointers(sbi); > + if (ret) > + return FSCK_OPERATIONAL_ERROR; > > fsck_chk_curseg_info(sbi); > > diff --git a/fsck/mount.c b/fsck/mount.c > index 6f640a0..85ed404 100644 > --- a/fsck/mount.c > +++ b/fsck/mount.c > @@ -3159,7 +3159,7 @@ next_segment: > return -1; > } > > -void move_one_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left, > +int move_one_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left, > int i) > { > struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi); > @@ -3171,7 +3171,7 @@ void move_one_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left, > > if ((get_sb(feature) & F2FS_FEATURE_RO)) { > if (i != CURSEG_HOT_DATA && i != CURSEG_HOT_NODE) > - return; > + return 0; > > if (i == CURSEG_HOT_DATA) { > left = 0; > @@ -3191,7 +3191,10 @@ bypass_ssa: > to = from; > ret = find_next_free_block(sbi, &to, left, i, > c.zoned_model == F2FS_ZONED_HM); > - ASSERT(ret == 0); > + if (ret) { > + ERR_MSG("Failed to find next free block for curseg[%d]\n", i); > + return ret; > + } > > old_segno = curseg->segno; > curseg->segno = GET_SEGNO(sbi, to); > @@ -3211,22 +3214,27 @@ bypass_ssa: > > FIX_MSG("Move curseg[%d] %x -> %x after %"PRIx64"\n", > i, old_segno, curseg->segno, from); > + return 0; > } > > -void move_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left) > +int move_curseg_info(struct f2fs_sb_info *sbi, u64 from, int left) > { > - int i; > + int i, ret; > > /* update summary blocks having nullified journal entries */ > - for (i = 0; i < NO_CHECK_TYPE; i++) > - move_one_curseg_info(sbi, from, left, i); > + for (i = 0; i < NO_CHECK_TYPE; i++) { > + ret = move_one_curseg_info(sbi, from, left, i); > + if (ret) > + return ret; > + } > + return 0; > } > > -void update_curseg_info(struct f2fs_sb_info *sbi, int type) > +int update_curseg_info(struct f2fs_sb_info *sbi, int type) > { > if (!relocate_curseg_offset(sbi, type)) > - return; > - move_one_curseg_info(sbi, SM_I(sbi)->main_blkaddr, 0, type); > + return 0; > + return move_one_curseg_info(sbi, SM_I(sbi)->main_blkaddr, 0, type); > } > > void zero_journal_entries(struct f2fs_sb_info *sbi) > diff --git a/fsck/segment.c b/fsck/segment.c > index 96de22a..46dc747 100644 > --- a/fsck/segment.c > +++ b/fsck/segment.c > @@ -70,8 +70,8 @@ int reserve_new_block(struct f2fs_sb_info *sbi, block_t *to, > } > > if (find_next_free_block(sbi, &blkaddr, left, type, false)) { > - ERR_MSG("Can't find free block"); > - ASSERT(0); > + ERR_MSG("Can't find free block\n"); > + return -ENOSPC; > } > > se = get_seg_entry(sbi, GET_SEGNO(sbi, blkaddr)); > @@ -789,8 +789,8 @@ int update_block(struct f2fs_sb_info *sbi, void *buf, u32 *blkaddr, > > new_blkaddr = SM_I(sbi)->main_blkaddr; > if (find_next_free_block(sbi, &new_blkaddr, 0, type, false)) { > - ERR_MSG("Can't find free block for the update"); > - ASSERT(0); > + ERR_MSG("Can't find free block for the update\n"); > + return -ENOSPC; > } > > ret = dev_write_block(buf, new_blkaddr, f2fs_io_type_to_rw_hint(type));