Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp1604042lqg; Sun, 3 Mar 2024 19:19:46 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW52Nqex/VVx8VrsBfzu+bwc/n6S8+6fHredoaO+yVrGyKntAGvZ1ioO/FwODrVRg/6b/PxFA4qTo9qVkg3PB1dMYd/RV7/6S7Addw3cQ== X-Google-Smtp-Source: AGHT+IFcKiF9TN8OgH/UxyW3o9AJy+OfSTw/7KmRjx6j7uE7daO8v7OAxH0XuTCNVfG8Nbvi3u95 X-Received: by 2002:a17:903:284:b0:1dc:fc5c:9e22 with SMTP id j4-20020a170903028400b001dcfc5c9e22mr4574643plr.33.1709522385878; Sun, 03 Mar 2024 19:19:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709522385; cv=pass; d=google.com; s=arc-20160816; b=mWSKRJyLsjXV68JSLWXypEXG37OrSRh0cvJ74VKwAvgTbDUTnP0jhuH0TZmvSIAhZa mxz3LyJYZyqjpChrOM2Tp1OQiX+f740FuF3dVTLOO0/1QMhluBMcpUy5IfJSIgzTTZuS 8y4rIHzJXDq/zHjvFltHFzEPJPE5kCFsg3MbRIZkEzFwRLSKE2+Tr53uiErQUWj7xgqe XgXqlynqpQ2lRB3WaZjpFGJrIKmaqof2gQtNsOoSW8IdCSJKQ5zE6W/iJnYK3pcTA3hP 3JCaN7yG45lciUrE+ouK1dHgMxXAT7uWNFA1hKC4KXSLovYwBYXPH/+uVEgGVsrqqPj8 01SQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=cyjySM0LxV5dJ8J3vMbN85sd0wjKVGChfzCFke6zVe4=; fh=W6COFBd4BX4Q4YpnsinfP4Lifuq45kIfChsHXFM1YEQ=; b=U/lkuBW5CCk9wPPMTj+swrHOt9xOWhZcggkCQHeo6kfW0IpInuAlunAtW9ZWKkCLWH pRBBOCM7yVUmi70NqUnH+ORk/R3mV/AHfyEnQFvPQhBh3TlkWHXmhdbxhFp+LxZNOM2v pp/0EF0PHbkY4ABKrr3rO7WUzsqj2yU/OXOt6RR0fiFb9l0euSrMv2CVHc9ZPJz8KzOd TL3lhiykUqmgviuDAA19E8XBAjiFVTyPzjF6FKKC+DrGGZoYIy2Gxw4Ir/6MI/eMpjLe hlK3H1qZrnYLWxifJd+pUvEZWoYb98ARrSYCKPeA4mubzcW3zVeyCPcbjm/vXlZk/Okd 04ew==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hEVOR3sc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id k10-20020a170902d58a00b001da240b1596si7550725plh.221.2024.03.03.19.19.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Mar 2024 19:19:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-90005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=hEVOR3sc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-90005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-90005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8FE0A28144A for ; Mon, 4 Mar 2024 03:19:45 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4DB30443D; Mon, 4 Mar 2024 03:19:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hEVOR3sc" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6A1AAA59 for ; Mon, 4 Mar 2024 03:19:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709522379; cv=none; b=jf2jLjT174aAfqjtzwUpFyV6Kd9ddhBqB3OTg6/WdSn31bXBY0u7ik/D6/Hbl4rQ/pVRLASG1wBRwcYGqjA8tOi1OqouAMCPYGQlFGaptcTHY/3XyQG4V4CWQmAHLeMX/3pwT9U4JwZnON9lBNAjjRqJPQkFgKf4Rr1T7yWBZuE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709522379; c=relaxed/simple; bh=V+RFDPpTYUKW1qUvgdx7/B+Sd3EmYDwkX0GvYntj4Ro=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MMalEZc+bxw8b/U8WhPspr7Ms+5vXLGVEHOAGxKQg4aMg7gr8vnrZiQD3XOE2cvJz8hdqL029XFV0NUHKkiuSlX4wVD443/4ERsoa7L+Mzo5ezrzLX3bi+06bdaNEykXLl8W3EicP9XiK2hNcGi4j7KpZbURxM6q2m4GbyCkLys= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hEVOR3sc; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39A04C433C7; Mon, 4 Mar 2024 03:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1709522378; bh=V+RFDPpTYUKW1qUvgdx7/B+Sd3EmYDwkX0GvYntj4Ro=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=hEVOR3scu9UZ5CjncLG9Z95wY0CxECuIZGKuolA5DJt+FI5jqwFdmXFzTqerGuvCv VeUQ5FUAoKvWq7BcZszk/dlUAXYOqyLNbUwgx/7fCtThCGDlavSAgKQ/VCJ/2uEmxh C0OsJmFm9SAAK3l7DbtAZjRRyj+GF5yySbJ9z6tmplQEHW0aoBL5S/XbbWQvdvmPN5 7gS+QsNTrCoBuft9Vp/ULXpzk99WA7RorlDrUxQv3QHCSn+zdWiM8BCmJ5ZJfM9X9E BQFMU6wTIO1R0pzU80veEcMaC/vNYBk4Lh9lNNjDot809r4z2bIMPvJ2je/PkEJubg xkKUWkr7XSH4w== Message-ID: <7dc371ad-2448-4dd4-9551-8caef0a00d48@kernel.org> Date: Mon, 4 Mar 2024 11:19:29 +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 Subject: Re: [PATCH] f2fs: fix to check result of new_curseg in f2fs_allocate_segment_for_resize Content-Language: en-US To: Zhiguo Niu , jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, niuzhiguo84@gmail.com, ke.wang@unisoc.com, hongyu.jin@unisoc.com References: <1709292976-13118-1-git-send-email-zhiguo.niu@unisoc.com> From: Chao Yu In-Reply-To: <1709292976-13118-1-git-send-email-zhiguo.niu@unisoc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 2024/3/1 19:36, Zhiguo Niu wrote: > new_curseg may return error if get_new_segment fail, so its result > should be check in its caller f2fs_allocate_segment_for_resize, > alos pass this results to free_segment_range. Zhiguo, What about handling all error paths of new_curseg() and change_curseg() in one patch? Thanks, > > Signed-off-by: Zhiguo Niu > --- > fs/f2fs/f2fs.h | 2 +- > fs/f2fs/gc.c | 7 +++++-- > fs/f2fs/segment.c | 9 +++++++-- > 3 files changed, 13 insertions(+), 5 deletions(-) > > diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h > index 4331012..39dda7d 100644 > --- a/fs/f2fs/f2fs.h > +++ b/fs/f2fs/f2fs.h > @@ -3701,7 +3701,7 @@ void f2fs_clear_prefree_segments(struct f2fs_sb_info *sbi, > void f2fs_init_inmem_curseg(struct f2fs_sb_info *sbi); > void f2fs_save_inmem_curseg(struct f2fs_sb_info *sbi); > void f2fs_restore_inmem_curseg(struct f2fs_sb_info *sbi); > -void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, > +int f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, > unsigned int start, unsigned int end); > int f2fs_allocate_new_section(struct f2fs_sb_info *sbi, int type, bool force); > int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi); > diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c > index c60b747..7a458fa 100644 > --- a/fs/f2fs/gc.c > +++ b/fs/f2fs/gc.c > @@ -2037,8 +2037,11 @@ static int free_segment_range(struct f2fs_sb_info *sbi, > mutex_unlock(&DIRTY_I(sbi)->seglist_lock); > > /* Move out cursegs from the target range */ > - for (type = CURSEG_HOT_DATA; type < NR_CURSEG_PERSIST_TYPE; type++) > - f2fs_allocate_segment_for_resize(sbi, type, start, end); > + for (type = CURSEG_HOT_DATA; type < NR_CURSEG_PERSIST_TYPE; type++) { > + err = f2fs_allocate_segment_for_resize(sbi, type, start, end); > + if (err) > + goto out; > + } > > /* do GC to move out valid blocks in the range */ > err = f2fs_gc_range(sbi, start, end, dry_run, 0); > diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c > index 1bb3019..2a07b9d 100644 > --- a/fs/f2fs/segment.c > +++ b/fs/f2fs/segment.c > @@ -3071,11 +3071,12 @@ static bool need_new_seg(struct f2fs_sb_info *sbi, int type) > return false; > } > > -void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, > +int f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, > unsigned int start, unsigned int end) > { > struct curseg_info *curseg = CURSEG_I(sbi, type); > unsigned int segno; > + int err = 0; > > f2fs_down_read(&SM_I(sbi)->curseg_lock); > mutex_lock(&curseg->curseg_mutex); > @@ -3089,7 +3090,10 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, > change_curseg(sbi, type); > else > new_curseg(sbi, type, true); > - > + if (curseg->segno == NULL_SEGNO) { > + err = -ENOSPC; > + goto unlock; > + } > stat_inc_seg_type(sbi, curseg); > > locate_dirty_segment(sbi, segno); > @@ -3102,6 +3106,7 @@ void f2fs_allocate_segment_for_resize(struct f2fs_sb_info *sbi, int type, > > mutex_unlock(&curseg->curseg_mutex); > f2fs_up_read(&SM_I(sbi)->curseg_lock); > + return err; > } > > static int __allocate_new_segment(struct f2fs_sb_info *sbi, int type,