From patchwork Fri Mar 1 08:25:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiguo Niu X-Patchwork-Id: 208691 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp935712dyb; Fri, 1 Mar 2024 00:28:13 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWlqMgYVkzwnV7ZUx227n/Ae42jvafbemqryR2Tq2I+NWG3bENlL8qyknNGJqXj55Eai7lKy4MvZcNv9uMQQxd9y5tADA== X-Google-Smtp-Source: AGHT+IHY3K7GOduIhFOmUC1vlTVcFyo4VTrlhyBiAnNvy1hs1sgc3Oz0jy3GqTJGS/qgg2ftZxz8 X-Received: by 2002:a05:6a00:1950:b0:6e5:2f97:bf44 with SMTP id s16-20020a056a00195000b006e52f97bf44mr1142377pfk.10.1709281693653; Fri, 01 Mar 2024 00:28:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709281693; cv=pass; d=google.com; s=arc-20160816; b=C90QpEDhWLAfO/sfT5twdBwFyu/w06M8eouuHN3QixsgHwQwyp+3bbeY/lbtW0RjBx d54RUKr2hEpMkwBM+ePtHoMTH0owD77aApG+Q9IjmFFwoltEGLkNFGsOGqNL+5mFi9BP JfXtW8qkYGZAZfqmmcydV2S1b8AexGct37biF/B1AVvQcz8b07vl60usaq1ogdW6Qufi e6mTanQpyWTWM5WcFJDUv5J0dZZKH2QSlFtUKhB9LmY6y4Jg16g7GQgmxdUKZh6S9JHN 23ohr9ckXHPuIMpvXVIEbUrGVEKVR0bzmPOOx4r2SGbMdqgyCACPnb4dJKk3XZwc3HzD BxgA== 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=jU8T3b75g+vGsqrESHmfwveJMe4oiSv4D3tDmEcEXDQ=; fh=r88ULmOhzmh3DE8RgcUXK+PF5Q+3czCYkx5yGhGfkR0=; b=XTYoNZWTIoRzcCsuRvQmRYeSQpviLZrKX32O06gBEXvv7fXnds7chsNvMMviZT73iq pWxYhgc6dHSgrgWzYRuEmh8eJvt3zbM6Y1+230BuB0rzeV8VjFBsVgE/9rHUncScANyR T/QECAyHQuT5Yu9gBRUZwpLzFqTsyPa/DItlhqKPpApYXLk77+1svy2XHJxLAWoUFqPZ DGqOsEbOAOcPtUs+f3VdnNgEWE2XJRfXAfw/8yIHE0C0Ca6FqkMNKPkVZ7oe7NuTuKTO ZUhsC5PurR5sLhFb8xyJYhnM1qyfCN1fNWDfpKxqHJF6PLZ3rESdNST1IZ+z3Gz5Jqkx ExUA==; 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-88075-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88075-ouuuleilei=gmail.com@vger.kernel.org" Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id x27-20020a056a00189b00b006e45d8bc55esi3134174pfh.361.2024.03.01.00.28.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 00:28:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88075-ouuuleilei=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-88075-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88075-ouuuleilei=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 0588628ADA7 for ; Fri, 1 Mar 2024 08:27:13 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 597EF69DF2; Fri, 1 Mar 2024 08:27:01 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [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 5F76569D05 for ; Fri, 1 Mar 2024 08:26:56 +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=1709281619; cv=none; b=SWAahStQJ0GShN/itO4WW2ybl2CbwYCxaeE6ep5WyfqRbngOCNuWoz4cuU8LduW2KKgQAQU6LA7+STclneOXkxsPhy40+JQbctLr1r6GU7UV3jHxCCwHxfH+rICj04DJS48AxK78aW6wQcMwKbY5R/hqSrn0uHs3oRgxsyO+u24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709281619; c=relaxed/simple; bh=9+cMmk/j1E0sLXVifzfj5cm2/RcLIUpa5OLoC8QQBRM=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=TIP7wbEy1J9jucGJGp+zM6+6VUBxbultt39uueKvdvGyi5uQKD1UowX+6DwBoBXPZ+vkTyE/nVGRy7Uco5LH++ngSgXt0jYhP8cY/AwTFk0nm00TVeq7dSSpdqZIyxxQrjwdDgfxxzjpNOY0GWZS6nh7MqdkLzPsuujvHf1e/ys= 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 4218Q82T055542; Fri, 1 Mar 2024 16:26:08 +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 4TmLkN0Dccz2KQsFF; Fri, 1 Mar 2024 16:25:16 +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 16:26:05 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH 1/2] f2fs: fix to check return value __allocate_new_segment Date: Fri, 1 Mar 2024 16:25:54 +0800 Message-ID: <1709281555-11373-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 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 4218Q82T055542 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792311760916438516 X-GMAIL-MSGID: 1792311760916438516 __allocate_new_segment may return error when get_new_segment fails, so its caller should check its return value. Signed-off-by: Zhiguo Niu Reviewed-by: Chao Yu --- fs/f2fs/f2fs.h | 2 +- fs/f2fs/recovery.c | 2 +- fs/f2fs/segment.c | 7 +++++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index db05fd0..4331012 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3705,7 +3705,7 @@ void 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); -void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); +int f2fs_allocate_new_segments(struct f2fs_sb_info *sbi); int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range); bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, struct cp_control *cpc); diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index 3078d56..c381f0a 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -851,7 +851,7 @@ static int recover_data(struct f2fs_sb_info *sbi, struct list_head *inode_list, f2fs_ra_meta_pages_cond(sbi, blkaddr, ra_blocks); } if (!err) - f2fs_allocate_new_segments(sbi); + err = f2fs_allocate_new_segments(sbi); return err; } diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index cdac4cb..72f6ee3 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3163,16 +3163,19 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) return err; } -void f2fs_allocate_new_segments(struct f2fs_sb_info *sbi) +int f2fs_allocate_new_segments(struct f2fs_sb_info *sbi) { int i; + int err = 0; f2fs_down_read(&SM_I(sbi)->curseg_lock); down_write(&SIT_I(sbi)->sentry_lock); for (i = CURSEG_HOT_DATA; i <= CURSEG_COLD_DATA; i++) - __allocate_new_segment(sbi, i, false, false); + err += __allocate_new_segment(sbi, i, false, false); up_write(&SIT_I(sbi)->sentry_lock); f2fs_up_read(&SM_I(sbi)->curseg_lock); + + return err; } bool f2fs_exist_trim_candidates(struct f2fs_sb_info *sbi, From patchwork Fri Mar 1 08:25:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhiguo Niu X-Patchwork-Id: 208690 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp935552dyb; Fri, 1 Mar 2024 00:27:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW5jfB9Dd0Vj5pD5I/DuPsBaBbDSWTNNRENTH1lihita3OOviZEY/TfZJIza2ic7lW8gKh9462uSxX3AniH8TlgoQW5eg== X-Google-Smtp-Source: AGHT+IHKVZDJazqL+f96rfB69ab106t7fY7aCc3Zzg6wsQJlgP0amkHO0CmstI2iJ9pIhNN2s3rl X-Received: by 2002:a05:6402:26c5:b0:566:c156:aab8 with SMTP id x5-20020a05640226c500b00566c156aab8mr947777edd.30.1709281665180; Fri, 01 Mar 2024 00:27:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709281665; cv=pass; d=google.com; s=arc-20160816; b=ylr96SDGJHgkfWWsuEofCG0L8hj8z1z6aNixf+OLBSKBFVG+eP4HxUSgPNjVZ/aam1 NiAImMfTaNVAUsWpvVwFSsjtpH7W87oclnxwqL5hM53GF9wo/MNXNSbu411oNmY5jRFk 7E2kTOidyDJPFeV6pGcL5s86ONcjChVOEB0r61DmkX9ZwTFM/3nLTO8JBSm/V2CAwX2I N2mUoxHUwR2NEhTl4yVKN8OkhR25xdSfRVhN2PIxbYte7MLteq8D0bq0f8N7bGNB3D2l 5AvIe5gIdZ1FvXKBx7G4CAJxAh9PXSMZwISsrsgvPRVJDIV5fmLofGu3axHZeP+pV2Xq aWDw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=N97YKCny0Cs6KHLM8g8hM3GRmmGR/JOopzKxWKTSvjQ=; fh=r88ULmOhzmh3DE8RgcUXK+PF5Q+3czCYkx5yGhGfkR0=; b=xMKlag1LdoOxetNP99oJ+DxxBhUxBZ+m+TQeSYkDDDKuwsX0b/r/sW1RXq/z1bKgpL jrx2E8SEWuF4srKMC91F7vZzszDpBrbyUi5WKJ8JQUAnLfm1y5IT8PYLPU0XtmJ29eca 3dJoNhMD+NO5phjerLYHQItJ3NtwgMiHd9OpsQKVuLAWkjFXzD/Mta0p/qp9A2fHGnp8 tpBMmygQTp2T5ora7kkcKKgifOAxCYip/rJy75oD+xAgDmjqM0/rzOouGy9weOakOUML EcfXH5ONv/jD36eKS86kcwEBelbOyviel2hV3Xkb8nQH4po7CSRviSK4I3Sc32BkBSXm NiKg==; 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-88076-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88076-ouuuleilei=gmail.com@vger.kernel.org" Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w24-20020aa7da58000000b00560c674e301si1298723eds.667.2024.03.01.00.27.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Mar 2024 00:27:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-88076-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-88076-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-88076-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 67BA81F2737B for ; Fri, 1 Mar 2024 08:27:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5E4D569E13; Fri, 1 Mar 2024 08:27:03 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [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 C25A169D14 for ; Fri, 1 Mar 2024 08:26:59 +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=1709281621; cv=none; b=lQzzcGB732AVG986g+lCLZOjPtdFeOuCPT0BiSeIEW3DiBfflBZ73M9eL/jr0hlFlC39JxPMpf3Yob0AOsKgZ8NgK9M5oXeBUl52h4jOX+bkUxtBbX5dnopNMAd1M/JAFCSHoeFYgsV8GWAjSKzDIg3uw6KKdfb+s6SxIwjluf0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709281621; c=relaxed/simple; bh=Qkm28q9qiqVdNpBzw+D1ZzW6MaJgVHb4vj9bN4B0IrM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HSsBt9EgtuUsiO6TSmOr63pqUVdVGdE2NomrnLIzVJk2rmIO2Qwz5zBehPkASWU4KG+imU8b5dKT5Tq6Sg/s8WazmTcxhvHaM9znm7Ec20GKLKBXnzusYgVg7pzIRUV4E3WzOVq+TXcN4EoRNQWgz0o4u7EBoV+xhpAm+ELIIqA= 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 4218QCKa055787; Fri, 1 Mar 2024 16:26:12 +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 4TmLkR6XLSz2KQsFF; Fri, 1 Mar 2024 16:25:19 +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 16:26:09 +0800 From: Zhiguo Niu To: , CC: , , , , , Subject: [PATCH 2/2] f2fs: fix to check return value of f2fs_gc_range Date: Fri, 1 Mar 2024 16:25:55 +0800 Message-ID: <1709281555-11373-2-git-send-email-zhiguo.niu@unisoc.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1709281555-11373-1-git-send-email-zhiguo.niu@unisoc.com> References: <1709281555-11373-1-git-send-email-zhiguo.niu@unisoc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX02.spreadtrum.com (10.0.64.8) X-MAIL: SHSQR01.spreadtrum.com 4218QCKa055787 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792311731325236925 X-GMAIL-MSGID: 1792311731325236925 f2fs_gc_range may return error, so its caller f2fs_allocate_pinning_section should determine whether to do retry based on ist return value. Also just do f2fs_gc_range when f2fs_allocate_new_section return -EAGAIN, and check cp error case in f2fs_gc_range. Signed-off-by: Zhiguo Niu Reviewed-by: Chao Yu --- fs/f2fs/gc.c | 3 +++ fs/f2fs/segment.c | 13 ++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index e435e1f..c60b747 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1986,6 +1986,9 @@ int f2fs_gc_range(struct f2fs_sb_info *sbi, unsigned int segno; unsigned int gc_secs = dry_run_sections; + if (unlikely(f2fs_cp_error(sbi))) + return -EIO; + for (segno = start_seg; segno <= end_seg; segno += SEGS_PER_SEC(sbi)) { struct gc_inode_list gc_list = { .ilist = LIST_HEAD_INIT(gc_list.ilist), diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 72f6ee3..1bb3019 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3109,6 +3109,7 @@ static int __allocate_new_segment(struct f2fs_sb_info *sbi, int type, { struct curseg_info *curseg = CURSEG_I(sbi, type); unsigned int old_segno; + int err = 0; if (type == CURSEG_COLD_DATA_PINNED && !curseg->inited) goto allocate; @@ -3121,8 +3122,9 @@ static int __allocate_new_segment(struct f2fs_sb_info *sbi, int type, allocate: old_segno = curseg->segno; - if (new_curseg(sbi, type, true)) - return -EAGAIN; + err = new_curseg(sbi, type, true); + if (err) + return err; stat_inc_seg_type(sbi, curseg); locate_dirty_segment(sbi, old_segno); return 0; @@ -3151,13 +3153,14 @@ int f2fs_allocate_pinning_section(struct f2fs_sb_info *sbi) err = f2fs_allocate_new_section(sbi, CURSEG_COLD_DATA_PINNED, false); f2fs_unlock_op(sbi); - if (f2fs_sb_has_blkzoned(sbi) && err && gc_required) { + if (f2fs_sb_has_blkzoned(sbi) && err == -EAGAIN && gc_required) { f2fs_down_write(&sbi->gc_lock); - f2fs_gc_range(sbi, 0, GET_SEGNO(sbi, FDEV(0).end_blk), true, 1); + err = f2fs_gc_range(sbi, 0, GET_SEGNO(sbi, FDEV(0).end_blk), true, 1); f2fs_up_write(&sbi->gc_lock); gc_required = false; - goto retry; + if (!err) + goto retry; } return err;