Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp229302lqg; Fri, 1 Mar 2024 03:37:50 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXQ/3NSyrrGiUsGlefr9rIGcNBkUdr7OXl9fRoBXBD/iReoPwwTHJEoNxFDdP1mhRA+jKj+PWJhANW4CsEFuv53Cn6z78UkRyZ8F0s1OA== X-Google-Smtp-Source: AGHT+IGUl9KDh5Zyz4offuUk8d8wkDZMUaepHa+TD7JN66db3VuUp2NY847F9eLwOJSRZcVkZg3n X-Received: by 2002:a17:903:11c7:b0:1db:dd24:9962 with SMTP id q7-20020a17090311c700b001dbdd249962mr7618827plh.21.1709293070339; Fri, 01 Mar 2024 03:37:50 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709293070; cv=pass; d=google.com; s=arc-20160816; b=Kb+RpnXCJXm4aDZF+XjIFJ98FAW1mmT4K1g4I4M5KG3MTFFnbHrJ/Q9o1g4fAMjSTA ZHfaBzbdoNuUyQRXz5tnEywyBs4n8a1RMpav26JSTst229wHaKQd8SyYzuE8ZiqXt7g8 Pjd2/z9Rd6QjGJlM/1h6XinpBASliLklwygtqVRA0xEryuOJKiRG4x/mv6IZ7Hcyf7az QTErYbfnPUw50YNHXM6g3VFWWW9QqFN8NFlv6K6P1bGc3Rp7f3eGylwJyGV2roKZcm79 f5Ak2EP/CIi2c9dowF3DJ6uxkw0HWJCWqKy6Jn6dWsLIhYOFukbIC5JrPjTmjbI5DHFC oKLg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from; bh=DfxOKDksgm9ZQ62GXl9t0jLCRqsGCn25+BykDw29rmc=; fh=r88ULmOhzmh3DE8RgcUXK+PF5Q+3czCYkx5yGhGfkR0=; b=aaP9tRMi1elJexqU1ph7zt47+1naM1ZLFMD1CZnORqVPoDRZWe3QfRZa9qSCiBYFMS uiINnYL68RsY6kVqrdHyWbnmUiD5Ful12vlDx1BvxGAMMSPduQViMGsEwB8DublCDYgg 0fRE5aysGyJQh9j1Oxom3i2/jPjx87svXWl+LbnYrfSzIqoc4Ok3b0KvHoT9nR5oBzFN ccqqERowCGc8qikN099Y7JlvflfzR8GGDqtw+yt9y4UNWNl6bx+/T6ZjtSges3Pit1LC s9Oqyp9il+Euux+A+WGbYASPPEgcWvlvLoI0ELEN0jFtUcn+lVfthH0zDHnMjcMVgJaD vFFg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-88365-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88365-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f9-20020a170902ce8900b001d9d4629bc1si3511287plg.456.2024.03.01.03.37.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 03:37:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88365-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-88365-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88365-linux.lists.archive=gmail.com@vger.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 D1FF528D5E2 for ; Fri, 1 Mar 2024 11:37:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CE1076CDC6; Fri, 1 Mar 2024 11:36:59 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) (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 CF16C6EB51 for ; Fri, 1 Mar 2024 11:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709293019; cv=none; b=djTXL/CBoNDSrtQ2VmGTo2vGRa0ZoX+VMkkkaChUPNFjcZLD5yH7iZHjP0GVKsYTHxBaDFMNnW4peWRO4pwaEW6RPXfLfwDhB8OriQUmuae29yjGz6RSGwE9oej1EpqnOLhnFjDINermPawWVsQX4U8iTfSkd6/uYUGiC/fyRYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709293019; c=relaxed/simple; bh=kTOIpCx85MBExZD7m/gewjcjf04YHT5rYbCmo2npUI4=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=swAeWRZSxMzOt2/+h6twhCqkDA6UMr7OybM8d7ytMjqFVG2HM4POa7ABV+gpHcwpXkJlwu6T8D7QzX/w5EDa/kDw4UttwH5ejs2GZwXdOd1Jh3GOOyURn1TZAp/7edv46vfZJWzQovO9/i6z256oBe4CMPA2cCmCkcLEwJ0uPn0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 421BaPmN084487; Fri, 1 Mar 2024 19:36:25 +0800 (+08) (envelope-from Zhiguo.Niu@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx02.spreadtrum.com [10.0.64.8]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4TmQxw6S0bz2KkZ9v; Fri, 1 Mar 2024 19:35:32 +0800 (CST) Received: from bj08434pcu.spreadtrum.com (10.0.73.87) by BJMBX02.spreadtrum.com (10.0.64.8) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Fri, 1 Mar 2024 19:36:23 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH] f2fs: fix to check result of new_curseg in f2fs_allocate_segment_for_resize Date: Fri, 1 Mar 2024 19:36:16 +0800 Message-ID: <1709292976-13118-1-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL:SHSQR01.spreadtrum.com 421BaPmN084487 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. 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, -- 1.9.1