From patchwork Thu Feb 22 12:18:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 204736 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp211310dyb; Thu, 22 Feb 2024 04:19:15 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVTb6glIhbQUh82SKUnvv4bZwSYzGEmI9QAf76xpPn7ciHknp7HsauYX0b2vycZ1/q9AoJVnYv4AKucBVCjuXEXJsGJZA== X-Google-Smtp-Source: AGHT+IHbqy/0qF8xB29en6K/zpni1w2KOF89+VxCf004T5mqegM8KE96JWATzjWX2EgY8VOefSgl X-Received: by 2002:aa7:d60f:0:b0:565:4bce:db2 with SMTP id c15-20020aa7d60f000000b005654bce0db2mr383178edr.40.1708604354948; Thu, 22 Feb 2024 04:19:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708604354; cv=pass; d=google.com; s=arc-20160816; b=Ev5UX+pxrCju3FdvYkUQq2EnItrWLJHurWJ2XPAR9kWdYAx/MSflvLiHC77T5QDR+U ZOX63r961ODE43Lx6lb+byr9RvSGoFM0CIQwuP8fGda6e7NPZ6yJuBoCaY3K3weO24us GeKUTUKInxLkCrbU0OpFkoCK/6kNBxMTqlN5qtdL6zKNuHDnKY1Wer6QWefHg3TqYtbD JQnsK4tSiZ7Su4MKMnj/Yow1VaSI2vJTB7QR9Kz5cy2QYU3wzym5Rs5VhmkMiPDJIWQY xRI7rcC62coNtm+CTegGKdxPBJb92XeOhr0825o/q9XKqTH4l0SqPmsIf1s2jWVo7t+t VmHA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=RybAO6UjF9rQEJ8FIGv7KnXw6IFw6ds7eywLmrx2Vw0=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=zwUPcOc2jXXWOu0mp/yPV9KxxoskQC0QjjgAYqgwqzh57WL6RTOMES5VguXfgqgCuA M4Qs+p6iCzs4j3S2xhkc9yoeeNHylpcAxJ6BBbEchpGga918WCPmaBMfm1cntvyPMd0d +toz3rYtVDR3uBewqnczffAPZ+IDN43uQ7bvELKI+cgLUnBtI1PEaYIZgjvCLsW3C4J4 cw0wCQp0nqi4cgA8xa3AuTKZ2Budd8cvre4rFnoTTKOH/fc8KrhiMY17/TsUBkqOGq1k SnL0NNVP01Xj/Jn5HVruAD9i3bErIXzIU5l9OavJGVu8GurKdSiwBbH3rjZJkxEs7lok SfWQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bT18rqCL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76495-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76495-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id x19-20020a05640226d300b0056447ebd7afsi4548713edd.1.2024.02.22.04.19.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 04:19:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76495-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bT18rqCL; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76495-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76495-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 8FCB91F241CE for ; Thu, 22 Feb 2024 12:19:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B338A60DCC; Thu, 22 Feb 2024 12:19:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bT18rqCL" 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 DD6345FBA2 for ; Thu, 22 Feb 2024 12:18:57 +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=1708604338; cv=none; b=CxHBmeRcM4Sf/PkDCtm0w6uTYlsnnrlj0wUdGE40uRxYzZNc6RKInU0k8aufNIL3jdixJtXXfyI2t3Jp5dnbjuF0Dl9SfdmN66SLozg55vUZ/QtJCB/eITGsoTzI6EThlYMAhbHtwjDJ1GtiuhU6AotOVz64D1lp7UHyKRxGN/A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708604338; c=relaxed/simple; bh=hBevzcQ0912uhBWtG4E7Up+PFldcF2IwczOHh20Evtc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=qP/FIZv3VojAM3heMePkaCyWPc6bNFGmQWBVTJFYRH8T+sB7FrVlVsCByynuX65gQOXaARVZcooVSvqyENjugPXdMKvOAtG4Ne6bhMV7hU2FKGYDlk/djjsGaM3g7FOcWXBm3ClByW9F7IdQkXfZI1InCj/HpHpwPgWKCvSH8Ns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bT18rqCL; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FF62C433F1; Thu, 22 Feb 2024 12:18:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708604337; bh=hBevzcQ0912uhBWtG4E7Up+PFldcF2IwczOHh20Evtc=; h=From:To:Cc:Subject:Date:From; b=bT18rqCLQzC7YSmZJAXDveVoZqPTAt+O/d3Ye19a9zklautaxeoKEXQO7eWGIEKVj eN84vFJ8FaO43JUq90P4gF+oabMZlJujN2Q4njfa9qQbqJmalW5EAEjNzIZJOG1RLd u3epzZPURBhSezX3nA2z7UGiaGNmRoS5sLXp8aMzf1JkDJ4RO/ZbYGm0FsZnQddXl6 9/GiVQv1eAgOKAFqfX2nI1s++S8PGQMXSPEPAPbL3l17HnLYU99Lu/ZQYbtV1GrEPJ hgK9pUyPxvZJ8szMAoZPQAa6KdGSWXqOitm7anO/ztW5I9HeLvixbtlxTyJ4nJaU3N FkyaaBqAsMJ0g== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 1/4] f2fs: delete f2fs_get_new_segment() declaration Date: Thu, 22 Feb 2024 20:18:48 +0800 Message-Id: <20240222121851.883141-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791601519883224118 X-GMAIL-MSGID: 1791601519883224118 Commit 093749e296e2 ("f2fs: support age threshold based garbage collection") added this declaration, but w/ definition, delete it. Signed-off-by: Chao Yu --- fs/f2fs/f2fs.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 8a6fd4352a0e..fbbe9a0a4221 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3701,8 +3701,6 @@ bool f2fs_segment_has_free_slot(struct f2fs_sb_info *sbi, int segno); 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_get_new_segment(struct f2fs_sb_info *sbi, - unsigned int *newseg, bool new_sec, int dir); 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); From patchwork Thu Feb 22 12:18:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 204737 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp211410dyb; Thu, 22 Feb 2024 04:19:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXjy6O6GFEm0QOM0HisLnYPtATUv09LZuRUrvf6g+/zVLYGOxCfU30toSWGdgdovhMrJ+kRpejutAqqzRlbEXN+NCYP2w== X-Google-Smtp-Source: AGHT+IEZzVbWHaBvdebgiN+iges2hXpjIpE8UeJ9CIV+oTPwi+scqc63GPNksA83VhLKhOJ9hJsN X-Received: by 2002:a17:90a:5606:b0:299:2924:8bbb with SMTP id r6-20020a17090a560600b0029929248bbbmr16471338pjf.11.1708604365409; Thu, 22 Feb 2024 04:19:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708604365; cv=pass; d=google.com; s=arc-20160816; b=iL5RGCVl0jhi1/mk9xrt9+dfic1+9UkgStf6E1FvKKgWHaaM6Kre7nFt7ezdEzo9y8 wtOOsOaLlbvwC8NK66Gkg3yyhC50wtZAeE900gxFnq1o9X7tFzsIOcWKCMcDqueK78KF sZ/Sizuxeurjax8PeT+6flwNcKJi2/aatFCyyWqk27pqzGfPwKi+hPFy7Sc/M2aFALnS TbDMi3jQETQcvvYPhXYUljNh6NDhlfAPTEhiFqrMWgviZctVe1Jpiv3Zh9i+rteaxidB xseEpCXXNrIj5e9IY3f5ML0XypigSTMWRv7co7+cYB7KNAfWixochYfV9bVYgNnxP6KQ kEbQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=egF2uKlkrZrFqBU0WSciNeTzO1/Wffz3bqGISsIOh4Q=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=BuIMxf8yDQsQXdIt8v7AG1G0IUlqjfZtMxoVoxaH7qatTzk41sroDwWD6I7ni5qoRQ H941FKlmpbAdIJdZTFcaUwq+S3O+FpV7tn12+pxGki4GU4cWM7d3y+tybOGglulA+YVo DYwb4bSIltGpJMZgaojhglReHxElV7QBOVj4Ad3UTn+Dx0FqANSqRmsdFc46HTAKRKnt yQ0Owjo2q7D2jRTNb1vp8jEutMpPviA+mAjfMO03NzCZuGxII0bZdzLaz0fcwhIjs3zY eioRqkjwHdGA4sjTdnQJXpNhtEEIfGItOQQUBNsCTQVXDijdloHpnxqfozPowfvxOTXb S+1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=mDPZhRsl; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76496-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76496-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id x59-20020a17090a6c4100b0029962d0c910si3322848pjj.62.2024.02.22.04.19.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 04:19:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76496-ouuuleilei=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=mDPZhRsl; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76496-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76496-ouuuleilei=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 8C846288A1E for ; Thu, 22 Feb 2024 12:19:24 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EB6F0612D0; Thu, 22 Feb 2024 12:19:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mDPZhRsl" 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 EC21E3D54D for ; Thu, 22 Feb 2024 12:18:59 +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=1708604340; cv=none; b=NQaH3lpqkrfYFjLFxv1H0WeQHJVov5QA/K9ClLBPas2gIvq9tJ6OuJ26gB3oNEGgnQFrQMJuB6FF/g/6as3aujKYpt8mZWKxlLme1rE8uvr4xC8PUTpqPo4AcRdJFIj6Eg3bHveYv5oalHDLFUWDV0rhkvUwy5tJRpdY8qluS6M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708604340; c=relaxed/simple; bh=kfTRBKt4Nbx/JzbJcvx90tf0O1Cn9EETCkS6TLsrw28=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=K3hotsL/J/HVVNSnWEaPlazkTzWDcblBsVD8QLwX2VGxNm1YSW8x/c6nPEZaYjDHObhH2S6QvN9sy/ek1HtB6CuAmQVen/PeGcJWnHLoAyU99sx/QDW0vfeavZjCgrf6Key8UXTjmpC3tbsqVaiyyhKQCW0YgQiVNlQw34NWiiA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mDPZhRsl; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47646C433A6; Thu, 22 Feb 2024 12:18:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708604339; bh=kfTRBKt4Nbx/JzbJcvx90tf0O1Cn9EETCkS6TLsrw28=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mDPZhRslysG7G8AyvkqI8r9ViKpQOP+RQuHHkMeCIcT4GE6xkcFtwtOUwLrA0HTcl e4fhoauXNziXTHN2W1w3JUYD94c04YFog4zl54zZ09EZ6jcyrTi7wexP0TnXtj41nF pZTBiZLeS/XcY5dcSQtyG4jIEVKsl2UBDJqWeNyV9VuhMGrKpv/KdbsVKrGscfycZs QhzasHFMgiDW5BvPoK7K2rKzb71cWIRmOZQwNRDpSSzgNP/yAm26lcgVx8YVM2n2+f DDU+YdTK9Ami/i3bRM0Z+vfc8fG5QArg94/tJ+r/12G9OJ4dloiaGhIVHElja3U7FB kkEf90HRJXeuA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 2/4] f2fs: fix to don't call f2fs_stop_checkpoint in spinlock coverage Date: Thu, 22 Feb 2024 20:18:49 +0800 Message-Id: <20240222121851.883141-2-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240222121851.883141-1-chao@kernel.org> References: <20240222121851.883141-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791601531305147697 X-GMAIL-MSGID: 1791601531305147697 f2fs_stop_checkpoint(, false) is complex and it may sleep, so we should move it outside segmap_lock spinlock coverage in get_new_segment(). Signed-off-by: Chao Yu --- fs/f2fs/segment.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index d0209ea77dd2..8edc42071e6f 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2646,6 +2646,7 @@ static void get_new_segment(struct f2fs_sb_info *sbi, unsigned int old_zoneno = GET_ZONE_FROM_SEG(sbi, *newseg); bool init = true; int i; + int ret = 0; spin_lock(&free_i->segmap_lock); @@ -2671,9 +2672,8 @@ static void get_new_segment(struct f2fs_sb_info *sbi, secno = find_first_zero_bit(free_i->free_secmap, MAIN_SECS(sbi)); if (secno >= MAIN_SECS(sbi)) { - f2fs_stop_checkpoint(sbi, false, - STOP_CP_REASON_NO_SEGMENT); - f2fs_bug_on(sbi, 1); + ret = -ENOSPC; + goto out_unlock; } } segno = GET_SEG_FROM_SEC(sbi, secno); @@ -2704,7 +2704,13 @@ static void get_new_segment(struct f2fs_sb_info *sbi, f2fs_bug_on(sbi, test_bit(segno, free_i->free_segmap)); __set_inuse(sbi, segno); *newseg = segno; +out_unlock: spin_unlock(&free_i->segmap_lock); + + if (ret) { + f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT); + f2fs_bug_on(sbi, 1); + } } static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified) From patchwork Thu Feb 22 12:18:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 204738 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp211512dyb; Thu, 22 Feb 2024 04:19:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXD3I2Yqs2kpmXFh/UjItk8EjZOTw8WaDDFAOerMJYOGHcgBr8lT9vhM/HOJzjU/E90nl8PTc7YU4gFF9QEQpCL+DfXgA== X-Google-Smtp-Source: AGHT+IGkTboMYGM0XsyTcubR+tTrYH4/n+j0yFc3BzlIK1GG52G3Nm9QzDz113/XvHY5mNVFs7RD X-Received: by 2002:a05:620a:1a94:b0:787:9b19:80f3 with SMTP id bl20-20020a05620a1a9400b007879b1980f3mr2277863qkb.24.1708604379005; Thu, 22 Feb 2024 04:19:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708604378; cv=pass; d=google.com; s=arc-20160816; b=TxHyfOcq2x4wSmpx/rGby7EPb1txbefhzn0XHtq1WivMqK71i4HI8yOvG/qNgAUcJv 1G3JgK1AAbD4AHzGcNW5JFdbgXHccRoAE34Qod/loNO09vp9wM1IJlvBkj0nYAiUgMWH X6MUs257doEdMJH+cGW2Sy3MgmHkjEtSdNHcDYYm2qWvtt+OJvmr9qxWZ1vknLbmWdC6 0yILZRtWE+JqLPsHWF7fQnF1XfNw0zwzyTtVEeII20pybLQgEgT2etlvPfidPQq6HACU ImdQH+J5kncnVcIYPskFsholGfmuznUIskFbY1eBldTF0HkQWOl5jh4ccKlcHltveqbZ 9Nsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=5XxDLe1c6Dl0sB8fQLg6jo+WW+90//w1xGF2UrA+ddU=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=If7zdwvMMZd2vp9PRo1/OhBadEX6oKc65Csvon/2D5i3c8CpUkRIOwFjnKdp4Df/nj 5v+QBO+dgU4hiUOMjf2qOGZB2mOFx72dm070VdbDThRIRRd0qs3jj3/opD3WIji3q/fd owi5uxor7WoXhPdmDkAjf6A3vp8fW2nAz1O4AI9n5OmqMNMWl84ROoG+hzLGVnmfSxUl JIoxt0Dl3ff/bDDqZmMV1ZQg29J6/EGmdGvlDLvLvGOhnK3HBi4LkYsm80uIyeGq4wGM GC5pheeMG2v6ed4abmlV0htBJP6Y0OKQsO7z0I/DXGnZgShXin6maGrcsSILhgt7RhIl OTkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=StLUxsYE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76497-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76497-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id m18-20020a05620a24d200b00787354bed11si14207373qkn.413.2024.02.22.04.19.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 04:19:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76497-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=StLUxsYE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76497-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76497-ouuuleilei=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BB3B51C2239E for ; Thu, 22 Feb 2024 12:19:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71AB16166F; Thu, 22 Feb 2024 12:19:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="StLUxsYE" 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 772AD60DDB for ; Thu, 22 Feb 2024 12:19:01 +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=1708604341; cv=none; b=C1/19mRgKZizrtVNEn/W2C5NytIvjD1SwE+d2ZC+NjlWR+aodE4OY7XcNlFwL45ySwTeubp6fiDIR8SYuDlP+nqiD4M1oimFM+tVQAQnC+q1CJxhwOSRP0aaIAeDLfi9BMKZejbeUcgOeIT0bJJKYG15arSxT9kDNPPLHlYNS40= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708604341; c=relaxed/simple; bh=JScqMUmhnumYR16/rHyzcKV1L1sOSHfgCbEcWtK9OnY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gsTVTfu8T6RGJ2Z9vCMs9Vhw/QgrDbXwhkcLVyCYpYy/UMsWZ3s4xXXxZHYN7JwK6T0vuu/hciqQqRJekeBqouTfDn07eOD6JqORa+SMPKPSC//Ao2gkezIvcVPkepSIPHAZSxQYGNO9eTjkVOcmTzMd8v9anJ+MKL0NxPbS9i0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=StLUxsYE; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FF7DC433F1; Thu, 22 Feb 2024 12:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708604341; bh=JScqMUmhnumYR16/rHyzcKV1L1sOSHfgCbEcWtK9OnY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=StLUxsYEGp6qFUHyiSGOtJrfIfpajgNSWYrhEGA2mW/GqMuJq3Mz7Nph1WwW83zgN z2UZeOxs0Q+vEFZ2XsTSVLoTQ82faFpVudcCVVqg9Tc+zRIorhL7WM1ENRpJegUErt Ki/5+wbdTH2iTbfIb+Ro2h49U/pgsmFIvThpZW+1H/3E0gQGiL4W7urwAIPGteNCJt D/FmM+rV1NhQpZat5UT4pZX1c74GW2BpF9m2V8G8u27/jhaWc+/LAZC/iYYpHMTuxh tQ0iERkfaEo6qx5Pji9BYTqKpb7rvoHHknnR4H42xGYOazoO8AMFhB2rMyVOaBnuII ImBjWddAmuITQ== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 3/4] f2fs: fix to handle segment allocation failure correctly Date: Thu, 22 Feb 2024 20:18:50 +0800 Message-Id: <20240222121851.883141-3-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240222121851.883141-1-chao@kernel.org> References: <20240222121851.883141-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791601545083506823 X-GMAIL-MSGID: 1791601545083506823 If CONFIG_F2FS_CHECK_FS is off, and for very rare corner case that we run out of free segment, we should not panic kernel, instead, let's handle such error correctly in its caller. Signed-off-by: Chao Yu Tested-by: Zhiguo Niu --- fs/f2fs/data.c | 7 +++++-- fs/f2fs/f2fs.h | 2 +- fs/f2fs/file.c | 7 ++++++- fs/f2fs/gc.c | 7 ++++++- fs/f2fs/segment.c | 46 +++++++++++++++++++++++++++++++++++++++------- 5 files changed, 57 insertions(+), 12 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 0c9aa3082fcf..c21b92f18463 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1416,8 +1416,11 @@ static int __allocate_data_block(struct dnode_of_data *dn, int seg_type) set_summary(&sum, dn->nid, dn->ofs_in_node, ni.version); old_blkaddr = dn->data_blkaddr; - f2fs_allocate_data_block(sbi, NULL, old_blkaddr, &dn->data_blkaddr, - &sum, seg_type, NULL); + err = f2fs_allocate_data_block(sbi, NULL, old_blkaddr, + &dn->data_blkaddr, &sum, seg_type, NULL); + if (err) + return err; + if (GET_SEGNO(sbi, old_blkaddr) != NULL_SEGNO) f2fs_invalidate_internal_cache(sbi, old_blkaddr); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index fbbe9a0a4221..6390c3d551cb 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -3726,7 +3726,7 @@ void f2fs_replace_block(struct f2fs_sb_info *sbi, struct dnode_of_data *dn, block_t old_addr, block_t new_addr, unsigned char version, bool recover_curseg, bool recover_newaddr); -void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, +int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, block_t old_blkaddr, block_t *new_blkaddr, struct f2fs_summary *sum, int type, struct f2fs_io_info *fio); diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 088d0e79fbbc..d6ec744f1545 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2262,8 +2262,11 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) case F2FS_GOING_DOWN_METASYNC: /* do checkpoint only */ ret = f2fs_sync_fs(sb, 1); - if (ret) + if (ret) { + if (ret == -EIO) + ret = 0; goto out; + } f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_SHUTDOWN); break; case F2FS_GOING_DOWN_NOSYNC: @@ -2279,6 +2282,8 @@ static int f2fs_ioc_shutdown(struct file *filp, unsigned long arg) set_sbi_flag(sbi, SBI_IS_DIRTY); /* do checkpoint only */ ret = f2fs_sync_fs(sb, 1); + if (ret == -EIO) + ret = 0; goto out; default: ret = -EINVAL; diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 6d160d50e14e..42e75e9b8b6b 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1358,8 +1358,13 @@ static int move_data_block(struct inode *inode, block_t bidx, set_summary(&sum, dn.nid, dn.ofs_in_node, ni.version); /* allocate block address */ - f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr, + err = f2fs_allocate_data_block(fio.sbi, NULL, fio.old_blkaddr, &newaddr, &sum, type, NULL); + if (err) { + f2fs_put_page(mpage, 1); + /* filesystem should shutdown, no need to recovery block */ + goto up_out; + } fio.encrypted_page = f2fs_pagecache_get_page(META_MAPPING(fio.sbi), newaddr, FGP_LOCK | FGP_CREAT, GFP_NOFS); diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 8edc42071e6f..71f523431e87 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -400,6 +400,9 @@ int f2fs_commit_atomic_write(struct inode *inode) */ void f2fs_balance_fs(struct f2fs_sb_info *sbi, bool need) { + if (f2fs_cp_error(sbi)) + return; + if (time_to_inject(sbi, FAULT_CHECKPOINT)) f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_FAULT_INJECT); @@ -2636,7 +2639,7 @@ static int is_next_segment_free(struct f2fs_sb_info *sbi, * Find a new segment from the free segments bitmap to right order * This function should be returned with success, otherwise BUG */ -static void get_new_segment(struct f2fs_sb_info *sbi, +static int get_new_segment(struct f2fs_sb_info *sbi, unsigned int *newseg, bool new_sec, bool pinning) { struct free_segmap_info *free_i = FREE_I(sbi); @@ -2711,6 +2714,7 @@ static void get_new_segment(struct f2fs_sb_info *sbi, f2fs_stop_checkpoint(sbi, false, STOP_CP_REASON_NO_SEGMENT); f2fs_bug_on(sbi, 1); } + return ret; } static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified) @@ -2719,6 +2723,10 @@ static void reset_curseg(struct f2fs_sb_info *sbi, int type, int modified) struct summary_footer *sum_footer; unsigned short seg_type = curseg->seg_type; + /* only happen when get_new_segment() fails */ + if (curseg->next_segno == NULL_SEGNO) + return; + curseg->inited = true; curseg->segno = curseg->next_segno; curseg->zone = GET_ZONE_FROM_SEG(sbi, curseg->segno); @@ -2783,7 +2791,10 @@ static int new_curseg(struct f2fs_sb_info *sbi, int type, bool new_sec) write_sum_page(sbi, curseg->sum_blk, GET_SUM_BLOCK(sbi, segno)); segno = __get_next_segno(sbi, type); - get_new_segment(sbi, &segno, new_sec, pinning); + if (get_new_segment(sbi, &segno, new_sec, pinning)) { + curseg->segno = NULL_SEGNO; + return -ENOSPC; + } if (new_sec && pinning && !f2fs_valid_pinned_area(sbi, START_BLOCK(sbi, segno))) { __set_free(sbi, segno); @@ -3425,7 +3436,7 @@ static void f2fs_randomize_chunk(struct f2fs_sb_info *sbi, get_random_u32_inclusive(1, sbi->max_fragment_hole); } -void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, +int f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, block_t old_blkaddr, block_t *new_blkaddr, struct f2fs_summary *sum, int type, struct f2fs_io_info *fio) @@ -3442,6 +3453,9 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, mutex_lock(&curseg->curseg_mutex); down_write(&sit_i->sentry_lock); + if (curseg->segno == NULL_SEGNO) + goto out_err; + if (from_gc) { f2fs_bug_on(sbi, GET_SEGNO(sbi, old_blkaddr) == NULL_SEGNO); se = get_seg_entry(sbi, GET_SEGNO(sbi, old_blkaddr)); @@ -3500,6 +3514,9 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, change_curseg(sbi, type); stat_inc_seg_type(sbi, curseg); } + + if (curseg->segno == NULL_SEGNO) + goto out_err; } skip_new_segment: @@ -3534,8 +3551,15 @@ void f2fs_allocate_data_block(struct f2fs_sb_info *sbi, struct page *page, } mutex_unlock(&curseg->curseg_mutex); - f2fs_up_read(&SM_I(sbi)->curseg_lock); + return 0; +out_err: + *new_blkaddr = NULL_ADDR; + up_write(&sit_i->sentry_lock); + mutex_unlock(&curseg->curseg_mutex); + f2fs_up_read(&SM_I(sbi)->curseg_lock); + return -ENOSPC; + } void f2fs_update_device_state(struct f2fs_sb_info *sbi, nid_t ino, @@ -3573,8 +3597,16 @@ static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio) if (keep_order) f2fs_down_read(&fio->sbi->io_order_lock); - f2fs_allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr, - &fio->new_blkaddr, sum, type, fio); + if (f2fs_allocate_data_block(fio->sbi, fio->page, fio->old_blkaddr, + &fio->new_blkaddr, sum, type, fio)) { + if (fscrypt_inode_uses_fs_layer_crypto(fio->page->mapping->host)) + fscrypt_finalize_bounce_page(&fio->encrypted_page); + if (PageWriteback(fio->page)) + end_page_writeback(fio->page); + if (f2fs_in_warm_node_list(fio->sbi, fio->page)) + f2fs_del_fsync_node_entry(fio->sbi, fio->page); + goto out; + } if (GET_SEGNO(fio->sbi, fio->old_blkaddr) != NULL_SEGNO) f2fs_invalidate_internal_cache(fio->sbi, fio->old_blkaddr); @@ -3582,7 +3614,7 @@ static void do_write_page(struct f2fs_summary *sum, struct f2fs_io_info *fio) f2fs_submit_page_write(fio); f2fs_update_device_state(fio->sbi, fio->ino, fio->new_blkaddr, 1); - +out: if (keep_order) f2fs_up_read(&fio->sbi->io_order_lock); } From patchwork Thu Feb 22 12:18:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chao Yu X-Patchwork-Id: 204739 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp211606dyb; Thu, 22 Feb 2024 04:19:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWtrjIhP6MkXBjnl7OGMNVed5EsVkM0IAa5FvGaq5K3CmtFKD5aszfxlBCaX61lMvoEb0jXDv8OfPuyFZAo/ZM+oKHIsQ== X-Google-Smtp-Source: AGHT+IGeMt4et6HKHgl2rZiWLvD/xZRDWRj3DAqYLSO64L3A3nvv+rV11xxm4ADkwanqbrtWHUbj X-Received: by 2002:aa7:c391:0:b0:565:2468:af2a with SMTP id k17-20020aa7c391000000b005652468af2amr1582425edq.8.1708604385355; Thu, 22 Feb 2024 04:19:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708604385; cv=pass; d=google.com; s=arc-20160816; b=0DLv/xNCne3niQjbKpkl7YhHpAm1jR4RBp7tURFzj5H2ZEtdk+3el+joRAH5whtzfv Nrx1+QzjzVradaynbl6PpZPm5WWtB21IxFUDhk6Mm3mhF42/l237qKTysWvmMabWgdjE Hq3j6G8xe682TTYwStFb03D+JVW96m6+kmvkiwTGgOh0hPHWI5718v+Bnyr0Mx36/gjT cnlSt8ACCPJJHSY3gCa3lHK9KD8OdwFOO2DjPrlk8NvWvQb6QZuccaVWvL60hjsi/SV0 18ZYPgIvZwfFHsa2biu7+hH8i2NgPY1IwvdhYCXxj5jvuHfqOz5hq8kWr2ZIuCym2//5 iEMQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=1+JK4WVLIkawlA+4DRsNdo3qHG1oONosg29W+Nu+dJI=; fh=X1/oBJvTGJUQ0YtRp03u+3tPfRw/dXXALWynfOSlfQQ=; b=xsua+pfwH0bxRDbJdSf4rbpyyg6bdy5m1cG+Wx5mjhzx0vtyGzlpG6Mh82qPg2WbXo MlGzBHt06QC5gOrR2U5I4vstC3cBoE9OniRjndZevuIOTyROm+FQDufWuueWISnazodG kp5G36cVYr1jyUQWGRE8u4l6ZcpcKyEEx0D/OrHJdLMOYFhEDVuEcftDF0HwxfgcfuT2 //1ekhKZ8Xsvm/Uu3BZQe4+eLklPm6bvWEZQQ4ohI/TSnP3iEmpPqGZ1MuJNEsUjtAOS wpKGgUQLba3YI+2E68NxXDMNkCkfJkfaXZMAfhdnAGvoXBjkvgNcqtf3BoJFYuOeDa8d Rv8w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="X20vHx/M"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76498-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76498-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id w16-20020a056402269000b0056450b6424fsi4464225edd.319.2024.02.22.04.19.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 04:19:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76498-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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="X20vHx/M"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-76498-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76498-ouuuleilei=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 am.mirrors.kernel.org (Postfix) with ESMTPS id F37C21F23EB5 for ; Thu, 22 Feb 2024 12:19:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6421461680; Thu, 22 Feb 2024 12:19:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="X20vHx/M" 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 86B54612E1 for ; Thu, 22 Feb 2024 12:19:03 +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=1708604343; cv=none; b=QE+9h+bI8R58VBXw4DZpg7XKOcagxHatJTQ0YiB33aE38gG3ZpjuJVb+RXKyjxvrO2SVE/2sbnRkyEf6tvrBBA7W9myj2c0dnuLYbqv7DCqP+YIhoP1YDs3byr8SXiRNGW7gN/9RrJJ02KhuGDHHFeRyDSna0bMrwU8sHMWmJ7E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708604343; c=relaxed/simple; bh=UBGAWY7QBAf6w4r+D7RUjGAJRqIj79Menb0OJmr4XXg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=DN6zBxqPn9USfwe54MVHpEfNhXYSYyerI6F2SKrKSgSGuE4fnKxf0iSBzbS8OA19s5HCvjQ8Zaq4pvHkNY+SnwUvyR1QoFe7h7yH5RwdoNhlynkaY8tbwsVJZdFTaQRERDg2GX+y5MK7KnA02SS561R9i8pwup4emb+jcDzVLnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X20vHx/M; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC1AEC43390; Thu, 22 Feb 2024 12:19:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708604343; bh=UBGAWY7QBAf6w4r+D7RUjGAJRqIj79Menb0OJmr4XXg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X20vHx/MBMMZ9nbQR/BWo7scTGZoMiocWVi8XVG4+OvGHF7/2fY+wuifhcYWYiVEB ZhuGf9JD6G6eOp1Vn9Eq8eUOW5WYx5c47nQFFqCcID+CZAziyakODU/e5Je+xdtrBb t6gQTyKPqiH/5Tw5ZbfBZzX8qLeNI/eZC7TZ62EeOSCpO4xYY97Ee28kMJEWxnn++w 2TJog2bmir0d4VzHaq2oKeAACSLr09o0krBNqJH+gc0MUPzYu+JdglCZRuACek91hn XeLiUZhX+J6EbunerVYYgqWkdnCpH+uV8IT59d3MOalDNjtcm4DuOcX2y6oI4J3xXa vgMovY33b0kVg== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu Subject: [PATCH 4/4] f2fs: introduce FAULT_NO_SEGMENT Date: Thu, 22 Feb 2024 20:18:51 +0800 Message-Id: <20240222121851.883141-4-chao@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240222121851.883141-1-chao@kernel.org> References: <20240222121851.883141-1-chao@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791601552151368241 X-GMAIL-MSGID: 1791601552151368241 Use it to simulate no free segment case during block allocation. Signed-off-by: Chao Yu --- Documentation/ABI/testing/sysfs-fs-f2fs | 1 + Documentation/filesystems/f2fs.rst | 1 + fs/f2fs/f2fs.h | 1 + fs/f2fs/segment.c | 5 +++++ fs/f2fs/super.c | 1 + 5 files changed, 9 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-fs-f2fs b/Documentation/ABI/testing/sysfs-fs-f2fs index 15044d7d4977..96b54259a02a 100644 --- a/Documentation/ABI/testing/sysfs-fs-f2fs +++ b/Documentation/ABI/testing/sysfs-fs-f2fs @@ -718,6 +718,7 @@ Description: Support configuring fault injection type, should be FAULT_LOCK_OP 0x000020000 FAULT_BLKADDR_VALIDITY 0x000040000 FAULT_BLKADDR_CONSISTENCE 0x000080000 + FAULT_NO_SEGMENT 0x000100000 =========================== =========== What: /sys/fs/f2fs//discard_io_aware_gran diff --git a/Documentation/filesystems/f2fs.rst b/Documentation/filesystems/f2fs.rst index 1b3b73aa3ab9..bc074b8eedbb 100644 --- a/Documentation/filesystems/f2fs.rst +++ b/Documentation/filesystems/f2fs.rst @@ -205,6 +205,7 @@ fault_type=%d Support configuring fault injection type, should be FAULT_LOCK_OP 0x000020000 FAULT_BLKADDR_VALIDITY 0x000040000 FAULT_BLKADDR_CONSISTENCE 0x000080000 + FAULT_NO_SEGMENT 0x000100000 =========================== =========== mode=%s Control block allocation mode which supports "adaptive" and "lfs". In "lfs" mode, there should be no random diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 6390c3d551cb..fdc9a4dc981d 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -62,6 +62,7 @@ enum { FAULT_LOCK_OP, FAULT_BLKADDR_VALIDITY, FAULT_BLKADDR_CONSISTENCE, + FAULT_NO_SEGMENT, FAULT_MAX, }; diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 71f523431e87..8ad88d5d4d1d 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -2653,6 +2653,11 @@ static int get_new_segment(struct f2fs_sb_info *sbi, spin_lock(&free_i->segmap_lock); + if (time_to_inject(sbi, FAULT_NO_SEGMENT)) { + ret = -ENOSPC; + goto out_unlock; + } + if (!new_sec && ((*newseg + 1) % SEGS_PER_SEC(sbi))) { segno = find_next_zero_bit(free_i->free_segmap, GET_SEG_FROM_SEC(sbi, hint + 1), *newseg + 1); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index bb056700b459..dc4fb9a661f2 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -63,6 +63,7 @@ const char *f2fs_fault_name[FAULT_MAX] = { [FAULT_LOCK_OP] = "lock_op", [FAULT_BLKADDR_VALIDITY] = "invalid blkaddr", [FAULT_BLKADDR_CONSISTENCE] = "inconsistent blkaddr", + [FAULT_NO_SEGMENT] = "no free segment", }; void f2fs_build_fault_attr(struct f2fs_sb_info *sbi, unsigned int rate,