From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54B73282F06 for ; Mon, 31 Aug 2026 05:32:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154378; cv=pass; b=KY1kutGUGfFF1rfFQJnNnzWLBCJpMXlvsMGn0EJxfLfujISzGsLUx6Cd6bBST4ASoHur8ZOF+pUO+XN2QeEPb+/GYG0cp/Z2FB4V7R6AUou4d0rb1/EkrY4qyPyFQT+Ivp0Wx/Yz8cIXy9ADZVdFYzv796o2ZtAScg+XmnE8RMQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154378; c=relaxed/simple; bh=MXFqWr7Uky0TUxYJJ7ciGR+LjTO2h6aLcYNxNAXrW0o=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=cbGiAB3V/wTggasbPJhetv9O6+gWNyFjThJnCjQ05q84vyGsgcGWMIFyw8Kvc0EB0SMwikvQDtHZZ6mzhxEFngbNHNY6KkD4ZlcfjsF3nqLY/5ELnTp89uKjRqpN5/SjztFAjvNfyZe+fcn3R+hLnbR1D2UZNPLuTQ/nx2c6v8Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=qzAvsw/7; arc=pass smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qzAvsw/7" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-6a5e971c970so6640814a12.0 for ; Sun, 30 Aug 2026 22:32:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154375; cv=none; d=google.com; s=arc-20260327; b=VJ0t5hk3Hb7j7gAUzV6sZBJiEqkeFYoy+9BPNPYnClAYTGp+w+aCPqVlEAGPHoS2m8 CtYs+gggWT/duCusJGWvfiE/s1dUixRieWtss/l/tdpfzH423YnZCIpMyCKJKlnZdIJP +q36cDZYeQiHGmDOGrAwUSPjsXToQPmFF2jyqqGRyoBUagkVaqYiCdhvoiv/GajoP/bg NwNxqK1oR1U/8spaKLKa5+0S/3VE8/6ApPhAQx88Z2njcwhqCTcUbDUirEDdO2zdXKAr +snjZ61CImtS3LrhV5U4ENSM6Z8lVff8E9m1ukuX3Gcq/pFbNTWjehwhQWFGzuOvFlEW v5cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=C/Ut8igNUUEDDCrdtbCLiaGMVpNyyvqtTQshGja4fhw=; fh=POU6SzYe5CWeIgr8em/2wmPwP8Zmg3EF8OLaDPR1u70=; b=W0x/dr6x23YMkc9ShGKBUrUcI2Svn+UqPvVcZc9RiIq+VcmMc5FCbc4RKZ8nloqOjl xV+jDqiCAhD58cTu+hFp+ZOHtCF1R5OyUYl/obbmhlD3Im62S/noZoOwxRvHiAwQximT ckzSWMCLins1pj+Wu1DgYNaVMit9I/ti2b7TT8pcYSqSaFhYHjIvYOIg8NLZh0xaMXtt MlWNvC6ufA3RG9ovtSvQbpJGuTh+5EaQrTEB3U4OSdklteLwXDDkMrxRaYzO6qVxCdHH OxH6glpNqf4xJFymckjqV5XH/DspuPc3KPfH5xEU9mTy+3iurlpzsWdmlJZS7OoH7A9v AEPQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154375; x=1788759175; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=C/Ut8igNUUEDDCrdtbCLiaGMVpNyyvqtTQshGja4fhw=; b=qzAvsw/7T6rauOmg/zDJBs8WNQpn5vFlV4s+PciRyKYyKuLpja6SvBphhYNt0eOt4O GmR8AmzGkcuaW8ztvMyrt6DXfD+e13PLCrmRVRDaw9iwuAcL5GWQPd+/2fkcmayHWw/u Qa8yftm1mpcuHeBiBNalXDpYOJwYWk+O0JM1uYxvvWIgq1cksraeRcJdWq31qGVljh7d X4Qa+TiVamOO8CYKIgFEuCyqs0Mk+W85WAP612mkKpqRenGXxYvfHgcFQrhZ1FE/7+dp H7ly7yM1lIXzmk0aT7jXcnNZQTcdnsGFSqzSoHKJTikyFl8M/T4TFx9XhIQBGmHLGohN Dnog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154375; x=1788759175; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=C/Ut8igNUUEDDCrdtbCLiaGMVpNyyvqtTQshGja4fhw=; b=PV0zwDQl7EdBPX3xJBf2o0akjJgjvFeuqi6Cq1P2HIxZ2EBFBDBr2uoFsWwPqdt976 Y7grlJLWHAhHN6XgfExOevrVtg0Ax9H2YAnus+z+KxH2R5dbSvMRfAyTMKv/1Ya8tj7W otmWuHJ2YXzyr2T1ecr+310/Kw/UzsCIibEVU5yNFXyxRE8eWfyDFj+99/R+jDG4S9ku ATrwHxTN8ZfLqCsZKAmjFq40BrqnsYdQjEDshRZVIj5eb/EXar0Zy8xV+6/3I4gsYlKA F/q7ZQI7lriPSzK42FV7aB9TTRx9u+L/JMkdfw3RQRf1FpOAOiH3xlcGx+BH6kGwG2di rEzQ== X-Forwarded-Encrypted: i=1; AKwUvBy2E9rFignaVlYna75bsJCXGn8rgmmNR1aHTjhh481sakCcvRkDpTJUGaI0kum7E170zV/WEuqRDtMrCwI=@vger.kernel.org X-Gm-Message-State: AFuF++kUlXSQWjjuMuPPkNP35tRAbSjd7EgZuoAcomLkFRPtHQ9bmdd0 JY7x6+oaUMuBbkqihZLy0a9Av87qC5inGH3rDDRn2tYlCHQU9qbqyj2VY8+/Bn6nl1kMBgy9bZ1 hKYoaWTKryaR2nfDjIVlFLYHk81WK/3A= X-Gm-Gg: AYBFou3cVw16LWFKY55pjJtf8jWMg5bwovds2NT7RkYzbxj3OHuG2mPqqJaVOx5FhiL Lfz6K+RUYhd/qlXuvOd32YXXm4BjuLeNW0K7BaD7wg0jrEH6E9Ch8Dg/VHA+/W817ufbITbToZS p/V8/pyHTMusTXr5ybpj9HeicYnI04g3pldFKks7WjBm0Ye8BWySobj2AvZfh8SouASacIL/fwL cY/fSUQvbC7G2A54zUHpCo8FE4PZpFRy+ih8y0JMPICfw1plbv/BzuCDKDGlBvuw20WoqGGdGvk zOfFyvb4wuynngLL+RqyepMQYQYARnM1bEnSTlthONVXt7WatxCN3KY9BqNCtYQJmsIQHSscGYU llg== X-Received: by 2002:a05:6402:20cd:b0:6a0:a46b:ad3c with SMTP id 4fb4d7f45d1cf-6a647693f75mr3043988a12.1.1788154375170; Sun, 30 Aug 2026 22:32:55 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:32:54 +0200 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:32:54 +0200 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 07:32:54 +0200 X-Gm-Features: AcwNN1W8uweP2JBSMGV-7BI3xN00j4I-usGHDHDv_RvI16_JsR6crt1gVAKyW-I Message-ID: Subject: [PATCH v3 01/11] f2fs: initialize sb_info early in f2fs_fill_super To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Previously, init_sb_info() was invoked late in f2fs_fill_super(), after processing superblock error tracking, mount options, and sb->s_maxbytes. However, read_raw_super_block() reads the superblock folio directly from the block device mapping using folio page offsets. This makes the initial static sb_set_blocksize(sb, F2FS_BLKSIZE) call redundant. Move init_sb_info() to execute immediately after sbi->raw_super is attached, allowing the block device block size to be set dynamically via sb_set_blocksize(sb, sbi->blocksize). This early initialization also prepares for upcoming patches that add dynamically computed filesystem geometry fields, such as sbi->addrs_per_block and sbi->nids_per_block, to init_sb_info(). These fields are required by earlier initialization steps, including mount option consistency checks and sb->s_maxbytes computation. Signed-off-by: Kelvin Zhang --- fs/f2fs/super.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 253a579e9d5b..2d9f5b77f815 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -5125,12 +5125,6 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) } mutex_init(&sbi->flush_lock); - /* set a block size */ - if (unlikely(!sb_set_blocksize(sb, F2FS_BLKSIZE))) { - f2fs_err(sbi, "unable to set blocksize"); - goto free_sbi; - } - err =3D read_raw_super_block(sbi, &raw_super, &valid_super_block, &recovery); if (err) @@ -5138,6 +5132,14 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) sb->s_fs_info =3D sbi; sbi->raw_super =3D raw_super; + init_sb_info(sbi); + + /* set a block size */ + if (!sb_set_blocksize(sb, sbi->blocksize)) { + f2fs_err(sbi, "unable to set blocksize %u", sbi->blocksize); + err =3D -EINVAL; + goto free_sb_buf; + } sbi->max_atc_write_bio_size =3D UINT_MAX; INIT_WORK(&sbi->s_error_work, f2fs_record_error_work); @@ -5217,8 +5219,6 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) if (err) goto free_bio_info; - init_sb_info(sbi); - err =3D f2fs_init_iostat(sbi); if (err) goto free_bio_info; --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0019233F38A for ; Mon, 31 Aug 2026 05:32:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.218.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154380; cv=pass; b=Vy7oQo//G2gTV0zbsTOx9jihlAOFkoy8iTp3jpOgzkR3E/tXTu2+B5sH+M+eXnP/GGctDN8HnSAo7Y8XBDoGrtV53FNZHghhl7wYmNZg9FjmhEXWBhPJe4I30QsnWlSKjg9DECkTa5cD37Qt41ojZc0Tu/RPtnbso19YZ/kd1vQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154380; c=relaxed/simple; bh=pvom9wpZ3/z2OhDUW+XEe4+6ntpBvNublIR31n2nVPI=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=fpD1az5Gbj8uSE/IPkNmSlgpuytOH0lPBXAJKB+/csEh1V/Z0VXsZ8U+ArvmIEOzxC6jqJvhOOOJYVWTZ+y5KuRm5mCrbgjf/NYelI4CNQJQrr7Gm1brzEKvTc/XILe0IVURd2IrsQ0z8zgV2inHLPjiGqVlv5RGZFiHerDhY/Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=sQzCr/pz; arc=pass smtp.client-ip=209.85.218.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sQzCr/pz" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-c25344a8c6cso392910766b.0 for ; Sun, 30 Aug 2026 22:32:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154377; cv=none; d=google.com; s=arc-20260327; b=XE2+XbVFzSYgV25FiUWAHrD6gucm/5i/L1McScIULdpgjf/u4YAbX81r6I5z3bYiT7 p6owCCjmy21oI8MaEqedMLO3tLvBBJ7oQUTAKeYQJ/xiVlUDuAvKrk7WkpzFMJGiukfF z7x2zzHg+cNLlkykmzAtGTr6QwPlXaRAahVnUj21hTbpTbwchVN9wEiz9W0QHgSssJmM iMHoNoYpWhqxG6dGaOlshYPT2C/yPqsMdAn01tox1iy/2aSFTJYaIH4SrAG0nkMdQtaV 6ZnkPAA37JtO8I3dnEhBM0InpWCmytbJOZzNOBl2unFU/h26Zkwb9R/eC4hm1DoBC2Ss b3FQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=J/1FY9WSB5RX6nf65O/jeitFs0+eIMznWlZ+J5l85Tg=; fh=t9wekPEBLx/fMK7p82D5ybLhG8URnuVdk0YdFNY7IYU=; b=lBxQhnVNbrvdf6xZW3a5Bqt35+5RMt98aIthRRuJ5SA/WGJRt3wjZcTafQdCCYwD8q Qg6ZlAPCPI3sbWMydgr2j2flp/GYMzwxancIRaq+3eEqXVjuhx7lC4G+pSgvcK2mQxBr K8qRvqHQf6IHAKvDzuiYO28h0ELflgYCUfdGCxFczk+agMP37mC26apoWG1f6SBFEoNQ KEIOK8Dp0eiVbhlWOATbyMs524lWlW2O9uBHQzvbw3mUvme9IHi8lJSanwELl4olWXYY sLChhHBfpx8hwN31UIsH4BJmyiW1lJ5YSsmcePJXWszPo43WqBGuJB8oUKyRn5JsvDzq 2VzQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154377; x=1788759177; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=J/1FY9WSB5RX6nf65O/jeitFs0+eIMznWlZ+J5l85Tg=; b=sQzCr/pzTMBKXPxYKVOu7VT0TGU6Ob/8M5uZyvUsA7T6c6DCIw/FEq++JWZEnytg9s MyR1wRWkcQ8AmVvJIscuLbuUqoQMeBUJHJ69z1wZKX0URNFtF1O8J2Qx+RZILYv0F72k 2S5VMmtTWM0E4j18aF5f7r+Qf6CVVJujKaUgfObP9ZDIMnO8biwrrPpRd6m8PZ+8ORfE EeCsqJcKmVdnFaP3sMQI0t5ykYRlAW94ugA0H1Wc5WQrQLaeNtYhuUUmCAHhY80eOzyu V4MDmPuoCo2HSwHEfODfvy7Td6AJ3PaAAoIkRa+IwpILQx15/JySeKXHaZeusnjegJdV Un+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154377; x=1788759177; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=J/1FY9WSB5RX6nf65O/jeitFs0+eIMznWlZ+J5l85Tg=; b=ToEyPMVw9ctSVVYndDW9fnAWsXTIcoKftGTh0C1MmsVnvopAjNUOZYlLaEXVMAT1Rm wAEP+shwf4drFjHZ45F2wkpsVrko+uU/t4y4zN+xZS9k9tTqf7f2ytpaRkq7Wlp/j7pS X0BdAZWQQG60U4Jqyjj1n7ZG+e2F21IzmpKA817eBWUvpgGlCJT8wR6fUbYHPg4BCBXB oyMR6uIT/Z3DFGy8f1qDr8rBMaG6F5hUD0bQXxRA1jTberkjsWS6Uz+6kjjrMHURkVo1 gPrJADl2SrWiADW7qPow5KofqtkVRmxfYeS6JXSYnIbaXINgSiJVDY7K8cwxRS3fM43I 8kuw== X-Forwarded-Encrypted: i=1; AHgh+RqOHDPffy6fBqqjGgcvX3JzMZa+lhi1KWeiSl/LUf4sg7Qu3r8ohlBEcsavzsppfUmmdGHerFckZ+HZuVM=@vger.kernel.org X-Gm-Message-State: AFuF++n6Cj/r64d+Em2tT+uaeohUz9QjAhXbKRrVwnu/gtmN2oxGmdzW CKUesjOM+ak9iSrEGph+xu1tH134s2gv6NoZfSVIMZHrCbsZnlu33tns1KA6wWuZl0CeNIXCyQW vTlblYoo0dkj9mefibhBTgEJx5NyAO+c= X-Gm-Gg: AR+sD13FbzgIkXjxjJDY3xSPMwKuTiDHEc31n2XVcbF/hJl7XbZP8zE9KseWPKafrT8 rIr3Hkf3t8oF2Brhxf6OWzlf2hcW1xhuHrffjmJf7MRYLQTcvCtwfioybZyfpjvGHmc58UnRPX+ piQJuP0tHaeSin/bpDTEAR1HqmqyVDc4grXzQrkvI6tc/pAo4Sm72LBf9dHHQNqH+qWWGMxgXUq EprZB7rXNP2La9x1cp69TfPLgHc2O7WGN8zf09QdynWwqyHo59USTeM9EnxHmRcOry2V0+1MKm2 AHZQAxOJVXt3vd76JLeaiVo2ZPRWP0FjaRKbCNLQNeJhA8GzrLaAHafRuIuhD+qcEBJgp/nUxqt ISA== X-Received: by 2002:a17:907:980e:b0:c20:f529:2d6a with SMTP id a640c23a62f3a-c255721317amr1440633166b.22.1788154377113; Sun, 30 Aug 2026 22:32:57 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:32:56 +0200 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:32:56 +0200 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 07:32:56 +0200 X-Gm-Features: AcwNN1WT2cRDtE3ELlGAioJbSUk3Rud_A__S7uC-6BS1Gj3IBh0qn3VPC76keP8 Message-ID: Subject: [PATCH v3 02/11] f2fs: describe SIT block layout dynamically To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" An SIT block consists of an on-disk array of struct f2fs_sit_entry elements whose total capacity depends on the filesystem block size. The existing fixed SIT_ENTRY_PER_BLOCK macro hardcodes a 4KB block size. Convert the entries array in struct f2fs_sit_block into a C flexible array member, and calculate sbi->sit_entries_per_block dynamically in init_sb_info(). Parameterize SIT indexing helpers (SIT_ENTRY_PER_BLOCK, SIT_BLOCK_OFFSET, SIT_BLK_CNT, and f2fs_start_segno) to take struct f2fs_sb_info *sbi, and update all call sites across segment management, checkpointing, and mount. This is a layout-only change; valid 4KB filesystems retain identical runtime geometry and behavior. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/f2fs.h | 3 +++ fs/f2fs/segment.c | 15 ++++++++------- fs/f2fs/segment.h | 22 +++++++++++++--------- fs/f2fs/super.c | 4 +++- include/linux/f2fs_fs.h | 9 ++++++--- 6 files changed, 34 insertions(+), 21 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 4b59f30ef45d..47c4a5c83a70 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -487,7 +487,7 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, goto out; /* get sit block addr */ fio.new_blkaddr =3D current_sit_addr(sbi, - blkno * SIT_ENTRY_PER_BLOCK); + blkno * SIT_ENTRY_PER_BLOCK(sbi)); break; case META_SSA: case META_CP: diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 16720f1f0a9c..035863d513ab 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1863,6 +1863,7 @@ struct f2fs_sb_info { unsigned int log_sectors_per_block; /* log2 sectors per block */ unsigned int log_blocksize; /* log2 block size */ unsigned int blocksize; /* block size */ + unsigned int sit_entries_per_block; /* SIT entries in a block */ unsigned int root_ino_num; /* root inode number*/ unsigned int node_ino_num; /* node inode number*/ unsigned int meta_ino_num; /* meta inode number*/ @@ -2251,6 +2252,8 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio) return F2FS_M_SB(folio->mapping); } +#define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) + static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info = *sbi) { return (struct f2fs_super_block *)(sbi->raw_super); diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 1e7e745be71d..b3bf1b62cdad 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -4708,7 +4708,7 @@ static struct folio *get_next_sit_folio(struct f2fs_sb_info *sbi, seg_info_to_sit_folio(sbi, folio, start); folio_mark_dirty(folio); - set_to_next_sit(sit_i, start); + set_to_next_sit(sbi, sit_i, start); return folio; } @@ -4747,10 +4747,11 @@ static void adjust_sit_entry_set(struct sit_entry_set *ses, list_move_tail(&ses->set_list, head); } -static void add_sit_entry(unsigned int segno, struct list_head *head) +static void add_sit_entry(struct f2fs_sb_info *sbi, unsigned int segno, + struct list_head *head) { struct sit_entry_set *ses; - unsigned int start_segno =3D START_SEGNO(segno); + unsigned int start_segno =3D f2fs_start_segno(sbi, segno); list_for_each_entry(ses, head, set_list) { if (ses->start_segno =3D=3D start_segno) { @@ -4775,7 +4776,7 @@ static void add_sits_in_set(struct f2fs_sb_info *sbi) unsigned int segno; for_each_set_bit(segno, bitmap, MAIN_SEGS(sbi)) - add_sit_entry(segno, set_list); + add_sit_entry(sbi, segno, set_list); } static void remove_sits_in_journal(struct f2fs_sb_info *sbi) @@ -4793,7 +4794,7 @@ static void remove_sits_in_journal(struct f2fs_sb_info *sbi) dirtied =3D __mark_sit_entry_dirty(sbi, segno); if (!dirtied) - add_sit_entry(segno, &SM_I(sbi)->sit_entry_set); + add_sit_entry(sbi, segno, &SM_I(sbi)->sit_entry_set); } update_sits_in_cursum(journal, -i); up_write(&curseg->journal_rwsem); @@ -4843,7 +4844,7 @@ void f2fs_flush_sit_entries(struct f2fs_sb_info *sbi, struct cp_control *cpc) struct folio *folio =3D NULL; struct f2fs_sit_block *raw_sit =3D NULL; unsigned int start_segno =3D ses->start_segno; - unsigned int end =3D min(start_segno + SIT_ENTRY_PER_BLOCK, + unsigned int end =3D min(start_segno + SIT_ENTRY_PER_BLOCK(sbi), (unsigned long)MAIN_SEGS(sbi)); unsigned int segno =3D start_segno; @@ -5008,7 +5009,7 @@ static int build_sit_info(struct f2fs_sb_info *sbi) sit_i->written_valid_blocks =3D 0; sit_i->bitmap_size =3D sit_bitmap_size; sit_i->dirty_sentries =3D 0; - sit_i->sents_per_block =3D SIT_ENTRY_PER_BLOCK; + sit_i->sents_per_block =3D SIT_ENTRY_PER_BLOCK(sbi); sit_i->elapsed_time =3D le64_to_cpu(sbi->ckpt->elapsed_time); sit_i->mounted_time =3D ktime_get_boottime_seconds(); init_rwsem(&sit_i->sentry_lock); diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 5949aa5200ac..534e376cbc92 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -102,12 +102,15 @@ static inline void sanity_check_seg_type(struct f2fs_sb_info *sbi, #define SIT_ENTRY_OFFSET(sit_i, segno) \ ((segno) % (sit_i)->sents_per_block) -#define SIT_BLOCK_OFFSET(segno) \ - ((segno) / SIT_ENTRY_PER_BLOCK) -#define START_SEGNO(segno) \ - (SIT_BLOCK_OFFSET(segno) * SIT_ENTRY_PER_BLOCK) +#define SIT_BLOCK_OFFSET(sbi, segno) \ + ((segno) / SIT_ENTRY_PER_BLOCK(sbi)) +static inline unsigned int +f2fs_start_segno(struct f2fs_sb_info *sbi, unsigned int segno) +{ + return SIT_BLOCK_OFFSET(sbi, segno) * SIT_ENTRY_PER_BLOCK(sbi); +} #define SIT_BLK_CNT(sbi) \ - DIV_ROUND_UP(MAIN_SEGS(sbi), SIT_ENTRY_PER_BLOCK) + DIV_ROUND_UP(MAIN_SEGS(sbi), SIT_ENTRY_PER_BLOCK(sbi)) #define f2fs_bitmap_size(nr) \ (BITS_TO_LONGS(nr) * sizeof(unsigned long)) @@ -424,7 +427,7 @@ static inline void seg_info_to_sit_folio(struct f2fs_sb_info *sbi, struct f2fs_sit_block *raw_sit; struct seg_entry *se; struct f2fs_sit_entry *rs; - unsigned int end =3D min(start + SIT_ENTRY_PER_BLOCK, + unsigned int end =3D min(start + SIT_ENTRY_PER_BLOCK(sbi), (unsigned long)MAIN_SEGS(sbi)); int i; @@ -869,7 +872,7 @@ static inline pgoff_t current_sit_addr(struct f2fs_sb_info *sbi, unsigned int start) { struct sit_info *sit_i =3D SIT_I(sbi); - unsigned int offset =3D SIT_BLOCK_OFFSET(start); + unsigned int offset =3D SIT_BLOCK_OFFSET(sbi, start); block_t blk_addr =3D sit_i->sit_base_addr + offset; f2fs_bug_on(sbi, !valid_main_segno(sbi, start)); @@ -894,9 +897,10 @@ static inline pgoff_t next_sit_addr(struct f2fs_sb_info *sbi, return block_addr + sit_i->sit_base_addr; } -static inline void set_to_next_sit(struct sit_info *sit_i, unsigned int st= art) +static inline void set_to_next_sit(struct f2fs_sb_info *sbi, + struct sit_info *sit_i, unsigned int start) { - unsigned int block_off =3D SIT_BLOCK_OFFSET(start); + unsigned int block_off =3D SIT_BLOCK_OFFSET(sbi, start); f2fs_change_bit(block_off, sit_i->sit_bitmap); } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 2d9f5b77f815..4bd1c9fb1f7f 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4329,7 +4329,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) return 1; } - sit_blk_cnt =3D DIV_ROUND_UP(main_segs, SIT_ENTRY_PER_BLOCK); + sit_blk_cnt =3D DIV_ROUND_UP(main_segs, SIT_ENTRY_PER_BLOCK(sbi)); if (sit_bitmap_size * 8 < sit_blk_cnt) { f2fs_err(sbi, "Wrong bitmap size: sit: %u, sit_blk_cnt:%u", sit_bitmap_size, sit_blk_cnt); @@ -4382,6 +4382,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) le32_to_cpu(raw_super->log_sectors_per_block); sbi->log_blocksize =3D le32_to_cpu(raw_super->log_blocksize); sbi->blocksize =3D BIT(sbi->log_blocksize); + sbi->sit_entries_per_block =3D sbi->blocksize / + sizeof(struct f2fs_sit_entry); sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); sbi->blocks_per_seg =3D BIT(sbi->log_blocks_per_seg); sbi->segs_per_sec =3D le32_to_cpu(raw_super->segs_per_sec); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index bb2b6cd5d507..ecd6694af572 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -396,8 +396,6 @@ struct f2fs_nat_block { * Not allow to change this. */ #define SIT_VBLOCK_MAP_SIZE 64 -#define SIT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_sit_entry)) - /* * F2FS uses 4 bytes to represent block address. As a result, supported si= ze of * disk is 16 TB for a 4K page size and 64 TB for a 16K page size and it e= quals @@ -424,8 +422,13 @@ struct f2fs_sit_entry { __le64 mtime; /* segment age for cleaning */ } __packed; +/* + * The on-disk SIT block is a filesystem-block-sized array of SIT entries. + * Its entry count depends on the filesystem block size, so it must be + * calculated by the caller rather than implied by this C structure. + */ struct f2fs_sit_block { - struct f2fs_sit_entry entries[SIT_ENTRY_PER_BLOCK]; + DECLARE_FLEX_ARRAY(struct f2fs_sit_entry, entries); } __packed; /* --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B96234DCF3 for ; Mon, 31 Aug 2026 05:33:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154384; cv=pass; b=se9Kka/KuGnwRy2h5cXvlkKtl5gL7MluwKaF91e3XowkeLtS9iwkhfbcu8B5gFal4ArFwe2uHyZlX3jFjvp+eHyocpIvW3U9EvPygUAF/xmALAFptUr03DaX/6Mh/SQ00YDtVbpKiT1cHh5Z3hyBrpujJPYFAnFnfsNFLCl2RU0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154384; c=relaxed/simple; bh=51p5F8g9ssw2M3GLd3Yix0LonS3bmkXxUNvHb2SKnpY=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=lWvKaSKwHOzPbm9Y9v49DRxblflE8hWE/VEj5EtJFDRhUuvonYidsIiyy81ry63au8HjTf2XWnCOwCw5wXqxt5J039uoNa5SWZzXEeFlTONmlU3AjfuZwZkbQn3uqS9Uup1+KD6OZGosd5UnGir2lYTM7h83cKtWI5mdohViHtk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Nh0D+7jn; arc=pass smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Nh0D+7jn" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-6a156627e22so7390321a12.1 for ; Sun, 30 Aug 2026 22:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154380; cv=none; d=google.com; s=arc-20260327; b=b/gtWHATaJiyKNHk71pP7Pe4/k4jHUmu9v0w67ivLzwzIpYepq6Te3bqj5pXH38dEQ Cyobf/D9VXkxhcitIB1T5H09hvJABk85+jDl5aTJ+aO0v5eDRQmUX3wsOONlJCQYcrC4 74wP7nKUZuQAdqsxYKaw+ID/R+8sAO8mGZPTLeTRm7x8qOGJQ2rSfmq44oLPik6CcO2v fxsrNY0pGKGaEp5lnVRhKJ9C/DE4ldax1fIcUfwYvTJBn4EDU9Eas23OXafFQIp4QejL vIxxU6kkL9BdrYpFtLYtqQRq3yVPBI+FAS4Th1G7nGLbos611yYnCxbBlLVZu9CDXTDe cxUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=PVwLXjG0EGIG2sCVqV7SElboXN+8PieytR+e7EdMa64=; fh=mlrG0zzVYT3BB5Evr6Funhn+43+MWdscW3vlQtTt3Dw=; b=UU6U3b0fXkkBeOUoIHU5EMRGopN0Ev3TR20H3yrO3oUC4ta5GQmnxCltyWio8B2bTD S20ahy2zBOYVoqRJgQ4VCP2PIKpw4y3DV2IC41emPHVy2lvIprwWx3WN+Nfyw+bSzA+y kdERfMTiT2NqfljjxsHnQgo2N1rBL0A90AGrDjXH2nD4y4XfF4KV1SgLIB8G4NzFdgm8 7c7jXOXZYlridEkMJOd7oz/WegiyUHfo0nPwjuPCrmWN2FBrDy4gbmxRyhhIrpBsyV4C 17+PqB4OwJjG+dIreHuIUGwcxrrxveN8cXkziMjXVpoQMs1DjUqd1KDHvxtbGyyKX3er PiKg==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154380; x=1788759180; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=PVwLXjG0EGIG2sCVqV7SElboXN+8PieytR+e7EdMa64=; b=Nh0D+7jnxhfsE6LAB5eeqI06WtnUA6bId6vfIW16OCIMx9iRmf8AZtyb23KVOx743N FZc2l4vW6L7deC5/wJ6mySZ4c1G8E9TviISp1ypMku9EM0MEgWln6XDuIuPds9dC/Ucs o0zqfYW8Kb26gt+Zwb44SoLH4LHocThYqbdFI+AfcriP/xbqh7qmxeY5vlUgNFUaRb3/ /ieKvb0pA22led9f6yHIdFYYJ/KtfhSaJcwGJ9ZIDybLNmw3KZSGoJVYLO4BOVbOs+7v K3ZABSeQd/bhjf2I3GVPgheluoLVJ1HKZOgLZpe4UiU0/8VrZ3Kf7V3S+tL9ijCSMBKX X4+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154380; x=1788759180; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=PVwLXjG0EGIG2sCVqV7SElboXN+8PieytR+e7EdMa64=; b=iAXlnAw2efoQWQvKNMDMREjG0nGkYEda/GwTlWmMpYOkXyPmm5h4zxAcAg1V6LnVlj CBTsKPStLo2UuwomPM/P1fuq2MNevb7jB6nVbMp/T0CXbvu/eatgk3d5q/Uy/c2XZ9v9 C87jwG1tGHJexWJEGlB/2X5lO6FNBqsHY6qzZAT7pBBMH8/XWFNBwrVdg+962vbTb6U1 0dcbHTXAOmolmr2aLaAAhTng2sHqffcPYkJqoPV+XxjVOrfBDjmyJafets3jQ0dTMGls yFLSaIKpvgvilQdhb5gf6wxEZ1pcUf9B+Czk4D2DYjg9jeBHWpVjKhT3GprczLmPl4kP vRTg== X-Forwarded-Encrypted: i=1; AKwUvBw/cnYF1yI06sRTX1sC+nKGMxnG4++u1k6GJXskLs7CP/XcdKW0wTOxGttmV/7cg3+dXCoF/w86Ey1cN5o=@vger.kernel.org X-Gm-Message-State: AFuF++n3X3DMuqV0Bqx93vVnabXLFZp9h5xhwAwdZbuv0n+gxCzcTGtx x45xwFNz6EwdlgpTYJVP7qf9h6xwY15z4xbn2RcIgiAaeLZVoi7FQvtcqT5QDfQODacJUi18QLq VGw13edlFOHqXb+aBegcS06mj5GGEF1ycxi+cRZM= X-Gm-Gg: AYBFou2UI8rUQUMOzGGsSWKNoHEe6NMDVevqdWFs8LH2IQTDBv9hA4H3JXm2vfBvV/I KFHu6lPsKP2/6UWs2RWqVXt2HrkNrHTiLw0XSzkkQ/E+ZevWpuusymPVPVSUbWHDdwTrYXS/SYi Zy4IAcOpXqJ49wm0fX3lA3NFYISMGhGauFbHlRFS9c289KQ+uaQR3DFbbY7wLzfCSg3psSLG0fP 6QKzyB1mK1qpX7tLem5CE4GhX3Ilsgz5X1B53NnyLnE/uWwryfS+4Syx3buvmghbU5WVFcHNHEX UvMLIMqC8P8VKvOUKuymtrmJljnNYrTf1TRMjAlX1XtRu4tTkD0J8VkO2unklpNTkTzvJC2qMOR u1Q== X-Received: by 2002:a05:6402:20cd:b0:6a0:a46b:ad3c with SMTP id 4fb4d7f45d1cf-6a647693f75mr3044215a12.1.1788154379774; Sun, 30 Aug 2026 22:32:59 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 00:32:59 -0500 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 00:32:59 -0500 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 00:32:59 -0500 X-Gm-Features: AcwNN1XLru7yuw-Kaiuw_V1VetKMTcNoGGhWtQWZD4cTQaO8PEo15iBi_LQhqFs Message-ID: Subject: [PATCH v3 03/11] f2fs: describe NAT block layout dynamically To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A NAT block is a filesystem-block-sized array of struct f2fs_nat_entry elements. The compile-time NAT_ENTRY_PER_BLOCK definition hardcodes the NAT capacity to a 4KB block size. Replace the fixed array in struct f2fs_nat_block with a C flexible array member, and calculate sbi->nat_entries_per_block dynamically in init_sb_info(). Parameterize NAT geometry helpers (NAT_ENTRY_PER_BLOCK, NAT_BLOCK_OFFSET, f2fs_start_nid, NAT_BLK_CNT, and f2fs_nat_bitmap_size) with sbi. Update call sites across node management, checkpointing, GC, and sysfs. This is a layout-only change without behavioral differences for 4KB blocks. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 4 +-- fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 2 ++ fs/f2fs/gc.c | 4 +-- fs/f2fs/node.c | 77 +++++++++++++++++++++-------------------- fs/f2fs/node.h | 22 ++++++++---- fs/f2fs/segment.c | 4 +-- fs/f2fs/shrinker.c | 2 +- fs/f2fs/super.c | 4 ++- include/linux/f2fs_fs.h | 5 ++- 10 files changed, 71 insertions(+), 55 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 47c4a5c83a70..3ecced9b4d57 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -476,11 +476,11 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, switch (type) { case META_NAT: if (unlikely(blkno >=3D - NAT_BLOCK_OFFSET(NM_I(sbi)->max_nid))) + NAT_BLOCK_OFFSET(sbi, NM_I(sbi)->max_nid))) blkno =3D 0; /* get nat block addr */ fio.new_blkaddr =3D current_nat_addr(sbi, - blkno * NAT_ENTRY_PER_BLOCK); + blkno * NAT_ENTRY_PER_BLOCK(sbi)); break; case META_SIT: if (unlikely(blkno >=3D TOTAL_SEGS(sbi))) diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index ff379aff4472..5980b9d79afb 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -345,7 +345,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) si->base_mem +=3D __bitmap_size(sbi, NAT_BITMAP); si->base_mem +=3D F2FS_BLK_TO_BYTES(NM_I(sbi)->nat_bits_blocks); si->base_mem +=3D NM_I(sbi)->nat_blocks * - f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK); + f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK(sbi)); si->base_mem +=3D NM_I(sbi)->nat_blocks / 8; si->base_mem +=3D NM_I(sbi)->nat_blocks * sizeof(unsigned short); diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 035863d513ab..8e6000e7d766 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1863,6 +1863,7 @@ struct f2fs_sb_info { unsigned int log_sectors_per_block; /* log2 sectors per block */ unsigned int log_blocksize; /* log2 block size */ unsigned int blocksize; /* block size */ + unsigned int nat_entries_per_block; /* NAT entries in a block */ unsigned int sit_entries_per_block; /* SIT entries in a block */ unsigned int root_ino_num; /* root inode number*/ unsigned int node_ino_num; /* node inode number*/ @@ -2253,6 +2254,7 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio) } #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) +#define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info = *sbi) { diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 0a00180c21dc..c15c6ba91597 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1066,7 +1066,7 @@ static int gc_node_segment(struct f2fs_sb_info *sbi, continue; if (phase =3D=3D 0) { - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nid), 1, META_NAT, true); continue; } @@ -1614,7 +1614,7 @@ static int gc_data_segment(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, continue; if (phase =3D=3D 0) { - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), 1, + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nid), 1, META_NAT, true); continue; } diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 86c2e67e43b6..960c6657d0d6 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -169,7 +169,7 @@ static struct folio *get_next_nat_folio(struct f2fs_sb_info *sbi, nid_t nid) folio_mark_dirty(dst_folio); f2fs_folio_put(src_folio, true); - set_to_next_nat(nm_i, nid); + set_to_next_nat(sbi, nm_i, nid); return dst_folio; } @@ -254,10 +254,11 @@ static void __del_from_nat_cache(struct f2fs_nm_info *nm_i, struct nat_entry *e) __free_nat_entry(e); } -static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_nm_info *nm_= i, +static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_sb_info *sbi, + struct f2fs_nm_info *nm_i, struct nat_entry *ne) { - nid_t set =3D NAT_BLOCK_OFFSET(ne->ni.nid); + nid_t set =3D NAT_BLOCK_OFFSET(sbi, ne->ni.nid); struct nat_entry_set *head; head =3D radix_tree_lookup(&nm_i->nat_set_root, set); @@ -274,14 +275,15 @@ static struct nat_entry_set *__grab_nat_entry_set(struct f2fs_nm_info *nm_i, return head; } -static void __set_nat_cache_dirty(struct f2fs_nm_info *nm_i, +static void __set_nat_cache_dirty(struct f2fs_sb_info *sbi, + struct f2fs_nm_info *nm_i, struct nat_entry *ne, bool init_dirty) { struct nat_entry_set *head; bool new_ne =3D nat_get_blkaddr(ne) =3D=3D NEW_ADDR; if (!new_ne) - head =3D __grab_nat_entry_set(nm_i, ne); + head =3D __grab_nat_entry_set(sbi, nm_i, ne); /* * update entry_cnt in below condition: @@ -527,7 +529,7 @@ static void set_node_addr(struct f2fs_sb_info *sbi, struct node_info *ni, nat_set_blkaddr(e, new_blkaddr); if (!__is_valid_data_blkaddr(new_blkaddr)) set_nat_flag(e, IS_CHECKPOINTED, false); - __set_nat_cache_dirty(nm_i, e, init_dirty); + __set_nat_cache_dirty(sbi, nm_i, e, init_dirty); /* update fsync_mark if its inode nat entry is still alive */ if (ni->nid !=3D ni->ino) @@ -578,7 +580,7 @@ int f2fs_get_node_info(struct f2fs_sb_info *sbi, nid_t = nid, struct f2fs_nm_info *nm_i =3D NM_I(sbi); struct curseg_info *curseg =3D CURSEG_I(sbi, CURSEG_HOT_DATA); struct f2fs_journal *journal =3D curseg->journal; - nid_t start_nid =3D START_NID(nid); + nid_t start_nid =3D f2fs_start_nid(sbi, nid); struct f2fs_nat_block *nat_blk; struct folio *folio =3D NULL; struct f2fs_nat_entry ne; @@ -2403,8 +2405,8 @@ static void update_free_nid_bitmap(struct f2fs_sb_info *sbi, nid_t nid, bool set, bool build) { struct f2fs_nm_info *nm_i =3D NM_I(sbi); - unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(nid); - unsigned int nid_ofs =3D nid - START_NID(nid); + unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(sbi, nid); + unsigned int nid_ofs =3D nid - f2fs_start_nid(sbi, nid); if (!test_bit_le(nat_ofs, nm_i->nat_block_bitmap)) return; @@ -2524,14 +2526,14 @@ static int scan_nat_page(struct f2fs_sb_info *sbi, { struct f2fs_nm_info *nm_i =3D NM_I(sbi); block_t blk_addr; - unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(start_nid); + unsigned int nat_ofs =3D NAT_BLOCK_OFFSET(sbi, start_nid); int i; __set_bit_le(nat_ofs, nm_i->nat_block_bitmap); - i =3D start_nid % NAT_ENTRY_PER_BLOCK; + i =3D start_nid % NAT_ENTRY_PER_BLOCK(sbi); - for (; i < NAT_ENTRY_PER_BLOCK; i++, start_nid++) { + for (; i < NAT_ENTRY_PER_BLOCK(sbi); i++, start_nid++) { if (unlikely(start_nid >=3D nm_i->max_nid)) break; @@ -2587,16 +2589,16 @@ static void scan_free_nid_bits(struct f2fs_sb_info = *sbi) continue; if (!nm_i->free_nid_count[i]) continue; - for (idx =3D 0; idx < NAT_ENTRY_PER_BLOCK; idx++) { + for (idx =3D 0; idx < NAT_ENTRY_PER_BLOCK(sbi); idx++) { idx =3D find_next_bit_le(nm_i->free_nid_bitmap[i], - NAT_ENTRY_PER_BLOCK, idx); - if (idx >=3D NAT_ENTRY_PER_BLOCK) + NAT_ENTRY_PER_BLOCK(sbi), idx); + if (idx >=3D NAT_ENTRY_PER_BLOCK(sbi)) break; - nid =3D i * NAT_ENTRY_PER_BLOCK + idx; + nid =3D i * NAT_ENTRY_PER_BLOCK(sbi) + idx; add_free_nid(sbi, nid, true, false); - if (nm_i->nid_cnt[FREE_NID] >=3D MAX_FREE_NIDS) + if (nm_i->nid_cnt[FREE_NID] >=3D MAX_FREE_NIDS(sbi)) goto out; } } @@ -2617,11 +2619,11 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi, if (unlikely(nid >=3D nm_i->max_nid)) nid =3D 0; - if (unlikely(nid % NAT_ENTRY_PER_BLOCK)) - nid =3D NAT_BLOCK_OFFSET(nid) * NAT_ENTRY_PER_BLOCK; + if (unlikely(nid % NAT_ENTRY_PER_BLOCK(sbi))) + nid =3D NAT_BLOCK_OFFSET(sbi, nid) * NAT_ENTRY_PER_BLOCK(sbi); /* Enough entries */ - if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK) + if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK(sbi)) return 0; if (!sync && !f2fs_available_free_memory(sbi, FREE_NIDS)) @@ -2631,18 +2633,18 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi, /* try to find free nids in free_nid_bitmap */ scan_free_nid_bits(sbi); - if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK) + if (nm_i->nid_cnt[FREE_NID] >=3D NAT_ENTRY_PER_BLOCK(sbi)) return 0; } /* readahead nat pages to be scanned */ - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nid), FREE_NID_PAGES, + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nid), FREE_NID_PAGES, META_NAT, true); f2fs_down_read_trace(&nm_i->nat_tree_lock, &lc); while (1) { - if (!test_bit_le(NAT_BLOCK_OFFSET(nid), + if (!test_bit_le(NAT_BLOCK_OFFSET(sbi, nid), nm_i->nat_block_bitmap)) { struct folio *folio =3D get_current_nat_folio(sbi, nid); @@ -2668,7 +2670,8 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi, } } - nid +=3D (NAT_ENTRY_PER_BLOCK - (nid % NAT_ENTRY_PER_BLOCK)); + nid +=3D NAT_ENTRY_PER_BLOCK(sbi) - + (nid % NAT_ENTRY_PER_BLOCK(sbi)); if (unlikely(nid >=3D nm_i->max_nid)) nid =3D 0; @@ -2684,7 +2687,7 @@ static int __f2fs_build_free_nids(struct f2fs_sb_info *sbi, f2fs_up_read_trace(&nm_i->nat_tree_lock, &lc); - f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(nm_i->next_scan_nid), + f2fs_ra_meta_pages(sbi, NAT_BLOCK_OFFSET(sbi, nm_i->next_scan_nid), nm_i->ra_nid_pages, META_NAT, false); return 0; @@ -2811,20 +2814,20 @@ int f2fs_try_to_free_nids(struct f2fs_sb_info *sbi, int nr_shrink) struct f2fs_nm_info *nm_i =3D NM_I(sbi); int nr =3D nr_shrink; - if (nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS) + if (nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS(sbi)) return 0; if (!mutex_trylock(&nm_i->build_lock)) return 0; - while (nr_shrink && nm_i->nid_cnt[FREE_NID] > MAX_FREE_NIDS) { + while (nr_shrink && nm_i->nid_cnt[FREE_NID] > MAX_FREE_NIDS(sbi)) { struct free_nid *i, *next; unsigned int batch =3D SHRINK_NID_BATCH_SIZE; spin_lock(&nm_i->nid_list_lock); list_for_each_entry_safe(i, next, &nm_i->free_nid_list, list) { if (!nr_shrink || !batch || - nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS) + nm_i->nid_cnt[FREE_NID] <=3D MAX_FREE_NIDS(sbi)) break; __remove_free_nid(sbi, i, FREE_NID); kmem_cache_free(free_nid_slab, i); @@ -3074,7 +3077,7 @@ static void remove_nats_in_journal(struct f2fs_sb_info *sbi) spin_unlock(&nm_i->nid_list_lock); } - __set_nat_cache_dirty(nm_i, ne, init_dirty); + __set_nat_cache_dirty(sbi, nm_i, ne, init_dirty); } update_nats_in_cursum(journal, -i); up_write(&curseg->journal_rwsem); @@ -3102,7 +3105,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid, const struct f2fs_nat_block *nat_blk) { struct f2fs_nm_info *nm_i =3D NM_I(sbi); - unsigned int nat_index =3D start_nid / NAT_ENTRY_PER_BLOCK; + unsigned int nat_index =3D start_nid / NAT_ENTRY_PER_BLOCK(sbi); int valid =3D 0; int i =3D 0; @@ -3113,7 +3116,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid, valid =3D 1; i =3D 1; } - for (; i < NAT_ENTRY_PER_BLOCK; i++) { + for (; i < NAT_ENTRY_PER_BLOCK(sbi); i++) { if (le32_to_cpu(nat_blk->entries[i].block_addr) !=3D NULL_ADDR) valid++; } @@ -3124,7 +3127,7 @@ static void __update_nat_bits(struct f2fs_sb_info *sbi, nid_t start_nid, } __clear_bit_le(nat_index, nm_i->empty_nat_bits); - if (valid =3D=3D NAT_ENTRY_PER_BLOCK) + if (valid =3D=3D NAT_ENTRY_PER_BLOCK(sbi)) __set_bit_le(nat_index, nm_i->full_nat_bits); else __clear_bit_le(nat_index, nm_i->full_nat_bits); @@ -3135,7 +3138,7 @@ static int __flush_nat_entry_set(struct f2fs_sb_info = *sbi, { struct curseg_info *curseg =3D CURSEG_I(sbi, CURSEG_HOT_DATA); struct f2fs_journal *journal =3D curseg->journal; - nid_t start_nid =3D set->set * NAT_ENTRY_PER_BLOCK; + nid_t start_nid =3D set->set * NAT_ENTRY_PER_BLOCK(sbi); bool to_journal =3D true; struct f2fs_nat_block *nat_blk; struct nat_entry *ne, *cur; @@ -3342,8 +3345,8 @@ static inline void load_free_nid_bitmap(struct f2fs_sb_info *sbi) __set_bit_le(i, nm_i->nat_block_bitmap); - nid =3D i * NAT_ENTRY_PER_BLOCK; - last_nid =3D nid + NAT_ENTRY_PER_BLOCK; + nid =3D i * NAT_ENTRY_PER_BLOCK(sbi); + last_nid =3D nid + NAT_ENTRY_PER_BLOCK(sbi); spin_lock(&NM_I(sbi)->nid_list_lock); for (; nid < last_nid; nid++) @@ -3373,7 +3376,7 @@ static int init_node_manager(struct f2fs_sb_info *sbi) /* segment_count_nat includes pair segment so divide to 2. */ nat_segs =3D le32_to_cpu(sb_raw->segment_count_nat) >> 1; nm_i->nat_blocks =3D nat_segs << le32_to_cpu(sb_raw->log_blocks_per_seg); - nm_i->max_nid =3D NAT_ENTRY_PER_BLOCK * nm_i->nat_blocks; + nm_i->max_nid =3D NAT_ENTRY_PER_BLOCK(sbi) * nm_i->nat_blocks; /* not used nids: 0, node, meta, (and root counted as valid node) */ nm_i->available_nids =3D nm_i->max_nid - sbi->total_valid_node_count - @@ -3436,7 +3439,7 @@ static int init_free_nid_cache(struct f2fs_sb_info *s= bi) for (i =3D 0; i < nm_i->nat_blocks; i++) { nm_i->free_nid_bitmap[i] =3D f2fs_kvzalloc(sbi, - f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK), GFP_KERNEL); + f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK(sbi)), GFP_KERNEL); if (!nm_i->free_nid_bitmap[i]) return -ENOMEM; } diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 5e114f352099..0dce97aac5fc 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -6,14 +6,23 @@ * http://www.samsung.com/ */ /* start node id of a node block dedicated to the given node id */ -#define START_NID(nid) (((nid) / NAT_ENTRY_PER_BLOCK) * NAT_ENTRY_PER_BLOC= K) +static inline nid_t f2fs_start_nid(struct f2fs_sb_info *sbi, nid_t nid) +{ + unsigned int entries =3D NAT_ENTRY_PER_BLOCK(sbi); + + return (nid / entries) * entries; +} + +#define START_NID(sbi, nid) f2fs_start_nid(sbi, nid) /* node block offset on the NAT area dedicated to the given start node id = */ -#define NAT_BLOCK_OFFSET(start_nid) ((start_nid) / NAT_ENTRY_PER_BLOCK) +#define NAT_BLOCK_OFFSET(sbi, start_nid) \ + ((start_nid) / NAT_ENTRY_PER_BLOCK(sbi)) /* # of pages to perform synchronous readahead before building free nids */ #define FREE_NID_PAGES 8 -#define MAX_FREE_NIDS (NAT_ENTRY_PER_BLOCK * FREE_NID_PAGES) +#define MAX_FREE_NIDS(sbi) ((unsigned long)NAT_ENTRY_PER_BLOCK(sbi) * \ + FREE_NID_PAGES) /* size of free nid batch when shrinking */ #define SHRINK_NID_BATCH_SIZE 8 @@ -208,7 +217,7 @@ static inline pgoff_t current_nat_addr(struct f2fs_sb_info *sbi, nid_t start) * OLD =3D (segment_off * 512) * 2 + off_in_segment * NEW =3D 2 * (segment_off * 512 + off_in_segment) - off_in_segment */ - block_off =3D NAT_BLOCK_OFFSET(start); + block_off =3D NAT_BLOCK_OFFSET(sbi, start); block_addr =3D (pgoff_t)(nm_i->nat_blkaddr + (block_off << 1) - @@ -230,9 +239,10 @@ static inline pgoff_t next_nat_addr(struct f2fs_sb_info *sbi, return block_addr + nm_i->nat_blkaddr; } -static inline void set_to_next_nat(struct f2fs_nm_info *nm_i, nid_t start_= nid) +static inline void set_to_next_nat(struct f2fs_sb_info *sbi, + struct f2fs_nm_info *nm_i, nid_t start_nid) { - unsigned int block_off =3D NAT_BLOCK_OFFSET(start_nid); + unsigned int block_off =3D NAT_BLOCK_OFFSET(sbi, start_nid); f2fs_change_bit(block_off, nm_i->nat_bitmap); #ifdef CONFIG_F2FS_CHECK_FS diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index b3bf1b62cdad..b29df65ab5b7 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -512,10 +512,10 @@ void f2fs_balance_fs_bg(struct f2fs_sb_info *sbi, bool from_bg) /* check the # of cached NAT entries */ if (!f2fs_available_free_memory(sbi, NAT_ENTRIES)) - f2fs_try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK); + f2fs_try_to_free_nats(sbi, NAT_ENTRY_PER_BLOCK(sbi)); if (!f2fs_available_free_memory(sbi, FREE_NIDS)) - f2fs_try_to_free_nids(sbi, MAX_FREE_NIDS); + f2fs_try_to_free_nids(sbi, MAX_FREE_NIDS(sbi)); else f2fs_build_free_nids(sbi, false, false); diff --git a/fs/f2fs/shrinker.c b/fs/f2fs/shrinker.c index 4f6bf5926de4..e3e0a7e89406 100644 --- a/fs/f2fs/shrinker.c +++ b/fs/f2fs/shrinker.c @@ -23,7 +23,7 @@ static unsigned long __count_nat_entries(struct f2fs_sb_info *sbi) static unsigned long __count_free_nids(struct f2fs_sb_info *sbi) { - long count =3D NM_I(sbi)->nid_cnt[FREE_NID] - MAX_FREE_NIDS; + long count =3D NM_I(sbi)->nid_cnt[FREE_NID] - MAX_FREE_NIDS(sbi); return count > 0 ? count : 0; } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 4bd1c9fb1f7f..fdc2b0c51c06 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4382,6 +4382,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) le32_to_cpu(raw_super->log_sectors_per_block); sbi->log_blocksize =3D le32_to_cpu(raw_super->log_blocksize); sbi->blocksize =3D BIT(sbi->log_blocksize); + sbi->nat_entries_per_block =3D sbi->blocksize / + sizeof(struct f2fs_nat_entry); sbi->sit_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_sit_entry); sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); @@ -4391,7 +4393,7 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->total_sections =3D le32_to_cpu(raw_super->section_count); sbi->total_node_count =3D SEGS_TO_BLKS(sbi, ((le32_to_cpu(raw_super->segment_count_nat) / 2) * - NAT_ENTRY_PER_BLOCK)); + NAT_ENTRY_PER_BLOCK(sbi))); sbi->allocate_section_hint =3D le32_to_cpu(raw_super->section_count); sbi->allocate_section_policy =3D ALLOCATE_FORWARD_NOHINT; F2FS_ROOT_INO(sbi) =3D le32_to_cpu(raw_super->root_ino); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index ecd6694af572..061f906a7b94 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -375,8 +375,6 @@ struct f2fs_node { /* * For NAT entries */ -#define NAT_ENTRY_PER_BLOCK (F2FS_BLKSIZE / sizeof(struct f2fs_nat_entry)) - struct f2fs_nat_entry { __u8 version; /* latest version of cached nat entry */ __le32 ino; /* inode number */ @@ -384,7 +382,8 @@ struct f2fs_nat_entry { } __packed; struct f2fs_nat_block { - struct f2fs_nat_entry entries[NAT_ENTRY_PER_BLOCK]; + /* The entry count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(struct f2fs_nat_entry, entries); } __packed; /* --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 181543A4F58 for ; Mon, 31 Aug 2026 05:33:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.51 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154386; cv=pass; b=WEXVANNor1JemdTrcyawN1dLRaRzYnhHJWiVFq/9UJnIS6t+l+QLrMAx7HqqtMMllxVSLV069ANWNZ4wM4tg09klSNaQdtJ1pw9h/x2P/1ITyK+kaMnoM43jwMrbvZNbi9oMgnvCCzbmk9HFrf7li0yHNSuWrMbjyytbDg/y7q8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154386; c=relaxed/simple; bh=z+M7LrnY+HVkAAU9PoFTvmt0wxh6P3hPrurjqyUZQiQ=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=jWnUcJOTDBe5MRtN5qwlgUF9wESOHIgRu5fYidaCHnBqp6zp+fV7CskeHsqekw1Jqt3B7nEDkgAbFOMmOqEOPpb9NsXC0u1CTozOsab2bQQT+K0RnXHwIIL1pRW838dy9X0dEjuyjWRa1NpCPVlCAJvybZA7tB8qiBxhH1znS2c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fsVfaiYT; arc=pass smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fsVfaiYT" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-6a38098734bso5070659a12.1 for ; Sun, 30 Aug 2026 22:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154383; cv=none; d=google.com; s=arc-20260327; b=DFRpph06k9Pqu+LCJ60Uw5UwxK+PDtM9KJ7gSG/+/NK2wwZkHBXtDtqGMlurlwMtox ELoKJnimQX49ObXuwzTKlOfoLa7P5fuF1VEjwdnqJ8pP1s0KKf0OZVMODk3EeJ67i4h6 tVpD4IURDNziFc53+Pv9G2Kq9KDiw8BAulyTsYrbD16jZsuPKAt+RrEqr5QumrzgpNOl 5c1P+bRApkrqTITGmYYRNYXGz595ydH7XBYo2S9RHOgW3r8ukB5uf2YbbPMKr5DC07YL Z+9we4Axn6yMvx1EKtMlBF59Nnik1qKsKLFwIAeY6z9228G595q7byuMqK3XVyWHAF5Z LMqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=al32+VJq1jKIId9SnUJ76zOfT5qUXNEzgzuggBSWSDk=; fh=rmHYSks1nOCtp3LWXCQsBO08KCxNS/LRbr6AgdVf5s0=; b=LBlzd5ArfQFG2DsEDCOGd+eMotQRp0z0Bdi+fy5dh6BAiPptKYP8DozcWyksIm87R/ pG5SU1yBv9MmtdMQNIyo0sJY50RzTzAGvrbBYDN9YXOa9wkSmNOeu2FIoibPFKzVjzou aKfnWgyRyes00ijDv7XMcSl39dPUUim9anjpHUBJmQXy/Q8co/Uz+z3wVIUdJLuGa9Yj ubooF6ysDAqC7YX1M3EajiqG8/hB5SuXUTovx5b3WuNI6cWb904Sq41esm9yhH0LmXru eXlKwVF/hpSCnRYpzSQzTJZYQatZDcXrO0DI/F0PNK+0aZ0ZYug4D6K6STn0C2GFcy4d 3CTg==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154383; x=1788759183; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=al32+VJq1jKIId9SnUJ76zOfT5qUXNEzgzuggBSWSDk=; b=fsVfaiYTMirF9KwNKWuuQhoJELrHOd4IzO/bmgHWHYqyPsVBDDzeJGJtBuMYRJ+bxd xJ+EPrEALQWY2NxiNqTVJB3JIymzGJxiS+tq3APxuLc1l2PRk0DBglnvuE5Oa4Wam/3c YiX1WfK4eTeLHo/bDY+WmcUATs++59jhmTaZ67sDZKDLjaQlQSFJ4jRAJAG6HwBxw53t qotUhl6ITMUFTG0a5aZV8+EBJuMnd85ipeCOGII4i5ypq5Ssfe4SHofHOtaTB93GEUKG OltrLHNqzKmZdOhLtkQsXaVnq4VkXF9HRwCaJmBPjpv2v16yHMgqUqGBOUzg7A46ygqu uSRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154383; x=1788759183; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=al32+VJq1jKIId9SnUJ76zOfT5qUXNEzgzuggBSWSDk=; b=oyGpDZ/j9YjbOWO046KExKtpWqn93WDbvxMT22yTsCbvXKkb6hDwQorPt9TFuk/lll s7F9u6f5XoUbUKu9tpxkAEE6ln/NZa5isp49tYE2mnKtS/PpNZkX/kYyvs6H+cnZYPCS g1QmUIr03qSPGkKBUXzWX66WNOK5ZMFrLUPDF8P+FwmH80IWW2kXQVZtTHFDHyDj4eiM O0TRcXT2KSbh0vTfuMKsksTf//XrXW/M8BmoyXGD6y/m4vxw5yAujsiDp757se+qAMG3 3IKLY4rvgPDRATK7QBACOXMXsp+HYZ5FPxUvuG1i0tUADn4PPIQvXrDI8TWEmwJ2KGM1 3LDA== X-Forwarded-Encrypted: i=1; AKwUvByrUci9Ph8er3cmrorYThKOKcXwcoeXKU2E7wAxDL74mI4+WqHLcvzkjmdbRxesgz33YtXKkFPaKYqIC0Q=@vger.kernel.org X-Gm-Message-State: AFuF++nzKgkS434ueG7Oxu2ipAGYPu7puu3FrHrM1B8aOcMgrW4zqhyD /1JqdMdTs502BAX2CHyJeU8WMMg4PYX53fyor1D7KDLbWVahVyksbL7unkqD216XjR0ZJ1jbwUH uWaFgpLG2aS06DY69zkrx67y85T8KxMA= X-Gm-Gg: AYBFou2N6SzG/g4LPZD+SGEy8m7bNiiX1uIya8CX8lykmoS1Xa1WMGczB26v1s+dLwp y0FbGfAFiDrc1WsX7d9eu4foZPMnPvUv+wBDDK2LfVaUslNMZK37kt1ZarE0TSaGp6yZtvjNoK0 ut7078/0ySfqjlDcizZ8KKJrN7ouYi1ZrhWUFAS1E6MbIkbJPdQZ2RLNs7TohzoSPxjTde1ia6v eAA2TACE9/Rgc20C1+wcKRNIatN96umlyorSDHQsKxPAffJFMM6/UoKDe6YGJK15Kgh2ZaGCCc4 OT/dVygUYMIBrPGGGYVpd98GwRym9Y0/LxeWREKQgoCrlGaQUCwzZENgTTMcjNYOIMkTfzZ5p0m 3dg== X-Received: by 2002:a05:6402:2088:b0:6a5:fbc6:cad1 with SMTP id 4fb4d7f45d1cf-6a60d334d1cmr12440801a12.7.1788154383070; Sun, 30 Aug 2026 22:33:03 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 00:33:02 -0500 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 00:33:02 -0500 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 00:33:02 -0500 X-Gm-Features: AcwNN1WXdLhwaTvKo5Ws--zHjKmKCbHB-j7jN9AheKAa8cz7hqKNhAN9Lr7tL8A Message-ID: Subject: [PATCH v3 04/11] f2fs: describe orphan block layout dynamically To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" An on-disk orphan block contains a variable-length array of 32-bit inode numbers followed by a fixed footer at the end of the block. A compile-time whole-block structure cannot represent the footer position when the block size varies at runtime. Remove struct f2fs_orphan_block, introduce struct f2fs_orphan_block_footer, and compute sbi->orphans_per_block dynamically in init_sb_info(). Add helpers to access the inode entry array and footer from a block buffer. Update orphan inode recovery, checkpointing, and mount paths to use the parameterized helpers. This preserves the on-disk format while decoupling orphan handling from compile-time constants. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 44 ++++++++++++++++++++++------------------- fs/f2fs/f2fs.h | 12 +++++++++++ fs/f2fs/super.c | 2 ++ include/linux/f2fs_fs.h | 18 ++++++++++------- 4 files changed, 49 insertions(+), 27 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 3ecced9b4d57..37a72b693545 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1041,7 +1041,8 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) for (i =3D 0; i < orphan_blocks; i++) { struct folio *folio; - struct f2fs_orphan_block *orphan_blk; + __le32 *orphan_inos; + struct f2fs_orphan_footer *footer; unsigned int entry_count; folio =3D f2fs_get_meta_folio(sbi, start_blk + i); @@ -1050,9 +1051,10 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *= sbi) goto out; } - orphan_blk =3D folio_address(folio); - entry_count =3D le32_to_cpu(orphan_blk->entry_count); - if (entry_count > F2FS_ORPHANS_PER_BLOCK) { + orphan_inos =3D folio_address(folio); + footer =3D f2fs_orphan_footer(orphan_inos, sbi); + entry_count =3D le32_to_cpu(footer->entry_count); + if (entry_count > F2FS_ORPHANS_PER_BLOCK(sbi)) { f2fs_err(sbi, "invalid orphan inode entry count %u", entry_count); set_sbi_flag(sbi, SBI_NEED_FSCK); @@ -1063,7 +1065,7 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) } for (j =3D 0; j < entry_count; j++) { - nid_t ino =3D le32_to_cpu(orphan_blk->ino[j]); + nid_t ino =3D le32_to_cpu(orphan_inos[j]); err =3D recover_orphan_inode(sbi, ino); if (err) { @@ -1084,7 +1086,8 @@ int f2fs_recover_orphan_inodes(struct f2fs_sb_info *s= bi) static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_bl= k) { struct list_head *head; - struct f2fs_orphan_block *orphan_blk =3D NULL; + __le32 *orphan_inos =3D NULL; + struct f2fs_orphan_footer *footer =3D NULL; unsigned int nentries =3D 0; unsigned short index =3D 1; unsigned short orphan_blocks; @@ -1092,7 +1095,7 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) struct ino_entry *orphan =3D NULL; struct inode_management *im =3D &sbi->im[ORPHAN_INO]; - orphan_blocks =3D GET_ORPHAN_BLOCKS(im->ino_num); + orphan_blocks =3D GET_ORPHAN_BLOCKS(sbi, im->ino_num); /* * we don't need to do spin_lock(&im->ino_lock) here, since all the @@ -1105,21 +1108,22 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) list_for_each_entry(orphan, head, list) { if (!folio) { folio =3D f2fs_grab_meta_folio(sbi, start_blk++); - orphan_blk =3D folio_address(folio); - memset(orphan_blk, 0, sizeof(*orphan_blk)); + orphan_inos =3D folio_address(folio); + footer =3D f2fs_orphan_footer(orphan_inos, sbi); + memset(orphan_inos, 0, sbi->blocksize); } - orphan_blk->ino[nentries++] =3D cpu_to_le32(orphan->ino); + orphan_inos[nentries++] =3D cpu_to_le32(orphan->ino); - if (nentries =3D=3D F2FS_ORPHANS_PER_BLOCK) { + if (nentries =3D=3D F2FS_ORPHANS_PER_BLOCK(sbi)) { /* - * an orphan block is full of 1020 entries, + * an orphan block is full, * then we need to flush current orphan blocks * and bring another one in memory */ - orphan_blk->blk_addr =3D cpu_to_le16(index); - orphan_blk->blk_count =3D cpu_to_le16(orphan_blocks); - orphan_blk->entry_count =3D cpu_to_le32(nentries); + footer->blk_addr =3D cpu_to_le16(index); + footer->blk_count =3D cpu_to_le16(orphan_blocks); + footer->entry_count =3D cpu_to_le32(nentries); folio_mark_dirty(folio); f2fs_folio_put(folio, true); index++; @@ -1129,9 +1133,9 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) } if (folio) { - orphan_blk->blk_addr =3D cpu_to_le16(index); - orphan_blk->blk_count =3D cpu_to_le16(orphan_blocks); - orphan_blk->entry_count =3D cpu_to_le32(nentries); + footer->blk_addr =3D cpu_to_le16(index); + footer->blk_count =3D cpu_to_le16(orphan_blocks); + footer->entry_count =3D cpu_to_le32(nentries); folio_mark_dirty(folio); f2fs_folio_put(folio, true); } @@ -1824,7 +1828,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) __clear_ckpt_flags(ckpt, CP_COMPACT_SUM_FLAG); spin_unlock_irqrestore(&sbi->cp_lock, flags); - orphan_blocks =3D GET_ORPHAN_BLOCKS(orphan_num); + orphan_blocks =3D GET_ORPHAN_BLOCKS(sbi, orphan_num); ckpt->cp_pack_start_sum =3D cpu_to_le32(1 + cp_payload_blks + orphan_blocks); @@ -2080,7 +2084,7 @@ void f2fs_init_ino_entry_info(struct f2fs_sb_info *sb= i) sbi->max_orphans =3D (BLKS_PER_SEG(sbi) - F2FS_CP_PACKS - NR_CURSEG_PERSIST_TYPE - __cp_payload(sbi)) * - F2FS_ORPHANS_PER_BLOCK; + F2FS_ORPHANS_PER_BLOCK(sbi); } int __init f2fs_create_checkpoint_caches(void) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 8e6000e7d766..2a4ba7d4ec0e 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1865,6 +1865,7 @@ struct f2fs_sb_info { unsigned int blocksize; /* block size */ unsigned int nat_entries_per_block; /* NAT entries in a block */ unsigned int sit_entries_per_block; /* SIT entries in a block */ + unsigned int orphans_per_block; /* orphan inodes in a block */ unsigned int root_ino_num; /* root inode number*/ unsigned int node_ino_num; /* node inode number*/ unsigned int meta_ino_num; /* meta inode number*/ @@ -2255,6 +2256,17 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio) #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) #define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) +#define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) +#define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ + F2FS_ORPHANS_PER_BLOCK(sbi)) + +static inline struct f2fs_orphan_footer * +f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) +{ + return (struct f2fs_orphan_footer *) + ((char *)orphan_block + sbi->blocksize - + sizeof(struct f2fs_orphan_footer)); +} static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info = *sbi) { diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index fdc2b0c51c06..f9811d571ae5 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4386,6 +4386,8 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sizeof(struct f2fs_nat_entry); sbi->sit_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_sit_entry); + sbi->orphans_per_block =3D (sbi->blocksize - + sizeof(struct f2fs_orphan_footer)) / sizeof(__le32); sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); sbi->blocks_per_seg =3D BIT(sbi->log_blocks_per_seg); sbi->segs_per_sec =3D le32_to_cpu(raw_super->segs_per_sec); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 061f906a7b94..7d2cbceb42d5 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -220,14 +220,18 @@ struct f2fs_checkpoint { /* * For orphan inode management + * + * An orphan block has no fixed-size C structure because the number of ino= de + * entries depends on the filesystem block size. Its exact on-disk layout= is: + * + * 0 blocksize - 16 blocksize + * +--------------------------+--------------------------+ + * | ino[0] ... ino[n - 1] | struct f2fs_orphan_footer | + * +--------------------------+--------------------------+ + * + * n =3D (blocksize - sizeof(struct f2fs_orphan_footer)) / sizeof(__le32) */ -#define F2FS_ORPHANS_PER_BLOCK ((F2FS_BLKSIZE - 4 * sizeof(__le32)) / sizeof(__le32)) - -#define GET_ORPHAN_BLOCKS(n) (((n) + F2FS_ORPHANS_PER_BLOCK - 1) / \ - F2FS_ORPHANS_PER_BLOCK) - -struct f2fs_orphan_block { - __le32 ino[F2FS_ORPHANS_PER_BLOCK]; /* inode numbers */ +struct f2fs_orphan_footer { __le32 reserved; /* reserved */ __le16 blk_addr; /* block index in current CP */ __le16 blk_count; /* Number of orphan inode blocks in CP */ --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CD4023A7833 for ; Mon, 31 Aug 2026 05:33:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154389; cv=pass; b=XuYM2z0mhoywefZqU+qDHPUPD20vyIiaN+F9ilDKFF5H7UMlAiddl4xbFe9/cHlU4uaji/XBM2zJShaQDFpFTuomzyl/NWwqRK4fIobh+3+d88h5QIqk5lHIT1oPyVzCWhy/VEmON3/MfR3k46Q28DVvvTzOvq9bkOfJVqhyc7s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154389; c=relaxed/simple; bh=YteMzOk3eRKq81a8FPNyLBsheYGVOnxSAwPicka0cVc=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=C+AjBV1DdjsQ64OHMWLfzaXkMCpnULOfZyuBeYw8NL/UoaMLhF21Qnv64Y6KxZXFXVqUrSKc96ro1gWpBCZI1I9avLPmwqKh1MdNCfRksysR64oZIYY44GZnqihbm4AOD3Py2wHoQZKGSZjKgABgrRDci8xwd4q+fWSqi7N6JuI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lCP8GdvM; arc=pass smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lCP8GdvM" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-6a082b3671fso3571156a12.3 for ; Sun, 30 Aug 2026 22:33:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154386; cv=none; d=google.com; s=arc-20260327; b=aFhe3YfUpimS+AB35lpID6JtQGOuxFp7ivJbp2U3bI/Dtt2+zBy97O0rqcqDCFh9GU 8XkUoTi7Fwakn0T1cI0GwCO6KmuMG4jv7H7VT75T8w6thz+PDbJffI4wuofnCwncnzsK M4RinZDr7jbKRHLv08CCaRXeizvdIDLobukCxVPBv2Pi92i1YdlbkuN0fKvtA++gr1Zo WuIhBFpAxA94CVuLRneugF42HMZL94rsv/YAgM0s6q52jhLHDC8dD+iTdm1sg4Q6+XQ1 UfPD9YdT25MS/zBp9SzuseJPjCpVVub55eJhXfXWtdAF/Q5VbMn64q0mGV9+1X2n0V7Y S8HQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=RqZhl3KyjNT5gAP4GrsiR5RK9iHeIl9R7u9oOVd2Ssc=; fh=fbChR7MKKlc4H579aAY3F2c6J1JeVQqXPNYjXCRNLY4=; b=kZJLwiTTYn7lxjtX8v5BHwgt8vQHK/9Ptnl+wQX1DbzcauUvz3yIsQJjJtXz6Y8YK5 oaUt+d5dmtCikoKEWzV2vUYZB0KNOirJhB90zCnqFSTl3ekK4mCZkAgGur48Oip9mXej mNP8AWgBQpIAwpqFwt//RwyYrEJs1gHs0kx8grSnrew7HP80Gi7OVUeCNwftMEJHpXns Qq7W0ZFJepxyXz7fomn3kKdI3/4LQYTPvEtfkStfVN8XKbrF2s9lqLz5Bbe/ezpl07rf 4g4u2lbDRXzFJuwteUoRA53+WA3vFAk/FmdY7LzcIC+xLbEEGwOPlBIhtxuxuYHpE17+ ptxg==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154386; x=1788759186; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=RqZhl3KyjNT5gAP4GrsiR5RK9iHeIl9R7u9oOVd2Ssc=; b=lCP8GdvMauYy1hgzac8Z0YoK+QtdyMsORtxRxVMZR8AKmqBIluEueb5o4mvmTmQKop //PPuttJUTp+UyhsI73o0vrVhiHAWRBLld4d/r9C5K9xmrczQxLn83bEXDDCt+Vgl03H mSltB0AId5E9A6BaVCQdaJWEWy26nOmq1TYQu+DiW43z35o0fj7uK6gdRYkmx67Yq0DC cMFge4C55wrZn31mZyzw0iLkryIhAYPphkrqFwzNDFQoZkZ++fQW9WpAZyemuDNykc9t VUSc62g28X1mNRLVBEEFkkSBcgknM5qBJ+OoOysYa1vPsGz5Ka2fp4TapEMq/xn8VaSF vpmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154386; x=1788759186; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=RqZhl3KyjNT5gAP4GrsiR5RK9iHeIl9R7u9oOVd2Ssc=; b=Edj97kC5+/UPXmlEcKcjN/6w95V9Tt2LdnZTHOpO+8RYgZAo6c9TX04k9In6ttly4+ Q5x3kbn0N/uFqlTuKFmOLAdGa6Bd+WCeF3UkZVpJREJvnr2aDoZrP3iSzdBLYh2k0mBM wkWKnbDSNIm4QnPf6bh2W9uACnF3kuaToLBMhhMx73DYUjAV7OiGgDd2TcK0fMvhrNpv UGzHnboDPMr0NPOXz0Dfd3L6DW+DnoXW6YQ15DS86huKwu3u6ROYuQbfzJCkIyhU0nng qEWg0fKeE59iZnPhsVBFo/ZorOSRjDL93Y48OI+o/DVl7CfK5U+E7P0nirD6E3tIdCJ0 gLaw== X-Forwarded-Encrypted: i=1; AKwUvBzpqMAPLYuknjj1aK1IQ+rqRVfSeXf8ZETVzT2AoErmnJXLGkY4bJPvWs6LJcrWB8gxVHkcBLUkwnJ7CnM=@vger.kernel.org X-Gm-Message-State: AFuF++kMCmVF7NckknzLQpmQ5QJoUU1qh0wmV3xeHw3Zr8BOWVZ1Rs5s UtA3+ajgr7LPEaQ9x/LExX79HGlLbQn5/sDiArVq80uGsraj09zaNaV4ByLRvpwxOEQUtf94EEV E4wJC79lJCkOh+gbpoI5y3Jsk/8lE5vg= X-Gm-Gg: AYBFou1bkna7lEe1g27IX1U7KK+xclR2fPkIindUyUbgHNuiw4cI0HLGvFjBTal2eGA 35R9sQ/RD2VvzJiHR3r8JbMSPrhazMsvSLUY+zIBkyM3d7/1sOVNG/m2k36aTXCqSkeCrc6FZhm 8zmhj7zJL1CpNfZrF7lPTqUA1qRsKCjHZlkgUO4DWQjL9Op/wTtvpNaQoOkniTlPznG2taWRp3j g4O7aGQ86bIdgIF5w02yLu11CEuE85/5gjeKPmyeTC1ZCO4UHwQ8nzi4vmWEZEIXPjzJ6eA7JXj 8tdERDjxTkybamMjEBIoQhUBc9v5q0nOfRqQvPk4MmXQQFoAcFrxLreIxk4qJJDiqnEiSIBplRY 6hA== X-Received: by 2002:a05:6402:4025:b0:698:be4d:ca2a with SMTP id 4fb4d7f45d1cf-6a65e674f1emr338362a12.15.1788154385801; Sun, 30 Aug 2026 22:33:05 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:04 +0200 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:04 +0200 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 07:33:04 +0200 X-Gm-Features: AcwNN1UP2SdUhylKvGmActR2plqv3gUfsL3Vj15jH4GfWpwuHhfpwqDYVDc4EIM Message-ID: Subject: [PATCH v3 05/11] f2fs: describe dentry block layout dynamically To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" An on-disk directory block contains a bitmap, reserved padding, an array of directory entries (struct f2fs_dir_entry), and matching filename slots. A fixed compile-time structure couples their offsets to 4KB blocks and relies on static reserved-space definitions. Remove struct f2fs_dentry_block and compute region offsets (bitmap bytes, directory-entry count, and filename slots) dynamically from the filesystem block size. Access directory blocks through struct f2fs_dentry_ptr views initialized with the runtime geometry. Update directory operations, inline dentry handling, and recovery paths to use the dynamic block layout. No functional change is introduced for 4KB blocks. Signed-off-by: Kelvin Zhang --- fs/f2fs/dir.c | 51 +++++++++++++++++++++-------------------- fs/f2fs/f2fs.h | 31 ++++++++++++++++--------- fs/f2fs/inline.c | 2 +- fs/f2fs/super.c | 6 +++++ include/linux/f2fs_fs.h | 31 ++++++++++++------------- 5 files changed, 68 insertions(+), 53 deletions(-) diff --git a/fs/f2fs/dir.c b/fs/f2fs/dir.c index fd0e2cd31a81..75ff36a13f60 100644 --- a/fs/f2fs/dir.c +++ b/fs/f2fs/dir.c @@ -195,7 +195,7 @@ static struct f2fs_dir_entry *find_in_block(struct inode *dir, int *max_slots, bool use_hash) { - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; struct f2fs_dentry_ptr d; dentry_blk =3D folio_address(dentry_folio); @@ -518,7 +518,7 @@ static int make_empty_dir(struct inode *inode, struct inode *parent, struct folio *folio) { struct folio *dentry_folio; - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; struct f2fs_dentry_ptr d; if (f2fs_has_inline_dentry(inode)) @@ -530,7 +530,7 @@ static int make_empty_dir(struct inode *inode, dentry_blk =3D folio_address(dentry_folio); - make_dentry_ptr_block(NULL, &d, dentry_blk); + make_dentry_ptr_block(inode, &d, dentry_blk); f2fs_do_make_empty_dir(inode, parent, &d); folio_mark_dirty(dentry_folio); @@ -690,7 +690,7 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname, unsigned long bidx, block; unsigned int nbucket, nblock; struct folio *dentry_folio =3D NULL; - struct f2fs_dentry_block *dentry_blk =3D NULL; + void *dentry_blk =3D NULL; struct f2fs_dentry_ptr d; struct folio *folio =3D NULL; int slots, err =3D 0; @@ -727,9 +727,9 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname, return PTR_ERR(dentry_folio); dentry_blk =3D folio_address(dentry_folio); - bit_pos =3D f2fs_room_for_filename(&dentry_blk->dentry_bitmap, - slots, NR_DENTRY_IN_BLOCK); - if (bit_pos < NR_DENTRY_IN_BLOCK) + make_dentry_ptr_block(dir, &d, dentry_blk); + bit_pos =3D f2fs_room_for_filename(d.bitmap, slots, d.max); + if (bit_pos < d.max) goto add_dentry; f2fs_folio_put(dentry_folio, true); @@ -750,7 +750,6 @@ int f2fs_add_regular_entry(struct inode *dir, const struct f2fs_filename *fname, } } - make_dentry_ptr_block(NULL, &d, dentry_blk); f2fs_update_dentry(ino, mode, &d, &fname->disk_name, fname->hash, bit_pos); @@ -887,7 +886,8 @@ void f2fs_drop_nlink(struct inode *dir, struct inode *i= node) void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio, struct inode *dir, struct inode *inode) { - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; + struct f2fs_dentry_ptr d; unsigned int bit_pos; int slots =3D GET_DENTRY_SLOTS(le16_to_cpu(dentry->name_len)); pgoff_t index =3D folio->index; @@ -905,18 +905,17 @@ void f2fs_delete_entry(struct f2fs_dir_entry *dentry, struct folio *folio, f2fs_folio_wait_writeback(folio, DATA, true, true); dentry_blk =3D folio_address(folio); - bit_pos =3D dentry - dentry_blk->dentry; + make_dentry_ptr_block(dir, &d, dentry_blk); + bit_pos =3D dentry - d.dentry; for (i =3D 0; i < slots; i++) - __clear_bit_le(bit_pos + i, &dentry_blk->dentry_bitmap); + __clear_bit_le(bit_pos + i, d.bitmap); /* Let's check and deallocate this dentry page */ - bit_pos =3D find_next_bit_le(&dentry_blk->dentry_bitmap, - NR_DENTRY_IN_BLOCK, - 0); + bit_pos =3D find_next_bit_le(d.bitmap, d.max, 0); folio_mark_dirty(folio); - if (bit_pos =3D=3D NR_DENTRY_IN_BLOCK && - !f2fs_truncate_hole(dir, index, index + 1)) { + if (bit_pos =3D=3D d.max && + !f2fs_truncate_hole(dir, index, index + 1)) { f2fs_clear_page_cache_dirty_tag(folio); folio_clear_dirty_for_io(folio); folio_clear_uptodate(folio); @@ -938,7 +937,8 @@ bool f2fs_empty_dir(struct inode *dir) { unsigned long bidx =3D 0; unsigned int bit_pos; - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; + struct f2fs_dentry_ptr d; unsigned long nblock =3D dir_blocks(dir); if (f2fs_has_inline_dentry(dir)) @@ -959,17 +959,16 @@ bool f2fs_empty_dir(struct inode *dir) } dentry_blk =3D folio_address(dentry_folio); + make_dentry_ptr_block(dir, &d, dentry_blk); if (bidx =3D=3D 0) bit_pos =3D 2; else bit_pos =3D 0; - bit_pos =3D find_next_bit_le(&dentry_blk->dentry_bitmap, - NR_DENTRY_IN_BLOCK, - bit_pos); + bit_pos =3D find_next_bit_le(d.bitmap, d.max, bit_pos); f2fs_folio_put(dentry_folio, false); - if (bit_pos < NR_DENTRY_IN_BLOCK) + if (bit_pos < d.max) return false; bidx++; @@ -1066,10 +1065,12 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) { struct inode *inode =3D file_inode(file); unsigned long npages =3D dir_blocks(inode); - struct f2fs_dentry_block *dentry_blk =3D NULL; + void *dentry_blk =3D NULL; struct file_ra_state *ra =3D &file->f_ra; loff_t start_pos =3D ctx->pos; - unsigned int n =3D ((unsigned long)ctx->pos / NR_DENTRY_IN_BLOCK); + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + unsigned int entries =3D sbi->dentries_per_block; + unsigned int n =3D (unsigned long)ctx->pos / entries; struct f2fs_dentry_ptr d; struct fscrypt_str fstr =3D FSTR_INIT(NULL, 0); int err =3D 0; @@ -1089,7 +1090,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) goto out_free; } - for (; n < npages; ctx->pos =3D n * NR_DENTRY_IN_BLOCK) { + for (; n < npages; ctx->pos =3D n * entries) { struct folio *dentry_folio; pgoff_t next_pgofs; @@ -1122,7 +1123,7 @@ static int f2fs_readdir(struct file *file, struct dir_context *ctx) make_dentry_ptr_block(inode, &d, dentry_blk); err =3D f2fs_fill_dentries(ctx, &d, - n * NR_DENTRY_IN_BLOCK, &fstr); + n * entries, &fstr); f2fs_folio_put(dentry_folio, false); if (err) break; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 2a4ba7d4ec0e..d2e54573ed34 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -669,17 +669,6 @@ struct f2fs_dentry_ptr { int nr_bitmap; }; -static inline void make_dentry_ptr_block(struct inode *inode, - struct f2fs_dentry_ptr *d, struct f2fs_dentry_block *t) -{ - d->inode =3D inode; - d->max =3D NR_DENTRY_IN_BLOCK; - d->nr_bitmap =3D SIZE_OF_DENTRY_BITMAP; - d->bitmap =3D t->dentry_bitmap; - d->dentry =3D t->dentry; - d->filename =3D t->filename; -} - static inline void make_dentry_ptr_inline(struct inode *inode, struct f2fs_dentry_ptr *d, void *t) { @@ -1866,6 +1855,9 @@ struct f2fs_sb_info { unsigned int nat_entries_per_block; /* NAT entries in a block */ unsigned int sit_entries_per_block; /* SIT entries in a block */ unsigned int orphans_per_block; /* orphan inodes in a block */ + unsigned int dentries_per_block; /* dentries in a block */ + unsigned int dentry_bitmap_size; /* dentry bitmap size in bytes */ + unsigned int dentry_reserved_size; /* dentry reserved bytes */ unsigned int root_ino_num; /* root inode number*/ unsigned int node_ino_num; /* node inode number*/ unsigned int meta_ino_num; /* meta inode number*/ @@ -2268,6 +2260,23 @@ f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) sizeof(struct f2fs_orphan_footer)); } +static inline void make_dentry_ptr_block(struct inode *inode, + struct f2fs_dentry_ptr *d, void *t) +{ + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + unsigned int entries =3D sbi->dentries_per_block; + unsigned int bitmap_size =3D sbi->dentry_bitmap_size; + unsigned int reserved_size =3D sbi->dentry_reserved_size; + + d->inode =3D inode; + d->max =3D entries; + d->nr_bitmap =3D bitmap_size; + d->bitmap =3D t; + d->dentry =3D t + bitmap_size + reserved_size; + d->filename =3D t + bitmap_size + reserved_size + + SIZE_OF_DIR_ENTRY * entries; +} + static inline struct f2fs_super_block *F2FS_RAW_SUPER(struct f2fs_sb_info = *sbi) { return (struct f2fs_super_block *)(sbi->raw_super); diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index aec06fb4fd76..718dd785865a 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -415,7 +415,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio, { struct folio *folio; struct dnode_of_data dn; - struct f2fs_dentry_block *dentry_blk; + void *dentry_blk; struct f2fs_dentry_ptr src, dst; int err; diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index f9811d571ae5..8d2224e585d3 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4388,6 +4388,12 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sizeof(struct f2fs_sit_entry); sbi->orphans_per_block =3D (sbi->blocksize - sizeof(struct f2fs_orphan_footer)) / sizeof(__le32); + sbi->dentries_per_block =3D (BITS_PER_BYTE * sbi->blocksize) / + ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1); + sbi->dentry_bitmap_size =3D DIV_ROUND_UP(sbi->dentries_per_block, + BITS_PER_BYTE); + sbi->dentry_reserved_size =3D sbi->blocksize - sbi->dentry_bitmap_size - + (SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * sbi->dentries_per_block; sbi->log_blocks_per_seg =3D le32_to_cpu(raw_super->log_blocks_per_seg); sbi->blocks_per_seg =3D BIT(sbi->log_blocks_per_seg); sbi->segs_per_sec =3D le32_to_cpu(raw_super->segs_per_sec); diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 7d2cbceb42d5..d1059a27e1b9 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -601,15 +601,7 @@ typedef __le32 f2fs_hash_t; * dentry, when converting inline dentry we should handle this carefully. */ -/* the number of dentry in a block */ -#define NR_DENTRY_IN_BLOCK ((BITS_PER_BYTE * F2FS_BLKSIZE) / \ - ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1)) #define SIZE_OF_DIR_ENTRY 11 /* by byte */ -#define SIZE_OF_DENTRY_BITMAP ((NR_DENTRY_IN_BLOCK + BITS_PER_BYTE - 1) / \ - BITS_PER_BYTE) -#define SIZE_OF_RESERVED (F2FS_BLKSIZE - ((SIZE_OF_DIR_ENTRY + \ - F2FS_SLOT_LEN) * \ - NR_DENTRY_IN_BLOCK + SIZE_OF_DENTRY_BITMAP)) #define MIN_INLINE_DENTRY_SIZE 40 /* just include '.' and '..' entries */ /* One directory entry slot representing F2FS_SLOT_LEN-sized file name */ @@ -620,14 +612,21 @@ struct f2fs_dir_entry { __u8 file_type; /* file type */ } __packed; -/* Block-sized directory entry block */ -struct f2fs_dentry_block { - /* validity bitmap for directory entries in each block */ - __u8 dentry_bitmap[SIZE_OF_DENTRY_BITMAP]; - __u8 reserved[SIZE_OF_RESERVED]; - struct f2fs_dir_entry dentry[NR_DENTRY_IN_BLOCK]; - __u8 filename[NR_DENTRY_IN_BLOCK][F2FS_SLOT_LEN]; -} __packed; +/* + * A dentry block is laid out as follows, where the number of entries and = all + * offsets are determined by the filesystem block size at runtime: + * + * 0 blocksize + * +--------+----------+-------------------+-----------------------+ + * | bitmap | reserved | dir_entry[entries]| filename[entries][8] | + * +--------+----------+-------------------+-----------------------+ + * + * entries =3D (BITS_PER_BYTE * blocksize) / + * ((SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * BITS_PER_BYTE + 1) + * bitmap_size =3D DIV_ROUND_UP(entries, BITS_PER_BYTE) + * reserved_size =3D blocksize - bitmap_size - + * (SIZE_OF_DIR_ENTRY + F2FS_SLOT_LEN) * entries + */ #define F2FS_DEF_PROJID 0 /* default project ID */ --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05E693AB26C for ; Mon, 31 Aug 2026 05:33:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154392; cv=pass; b=AbZ9Q07mWEldrm+bJMnr8nMnaNbwRVYMcSIasUce3+MDockaEJiH8JJL5bmMR4OnITvYl5uMrEZ/lyhsYiIdVsgslpV24ny/g+oePa9AICov0rKU9+SgV4xZy/CdEcgQcFA4vUQ7oU3wrVs1ujSWvGoS60BbuajZYjyESbXbO9Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154392; c=relaxed/simple; bh=04ArNZRCViWRkXgqoE+bp+pqUd9HkZfWSxBQs15Nk7w=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=X2H/QTZCzpll/6MO6XkbyjcZw8PBmXNi5sU2IkoiKYsgNaSersvlMToIeYvQMIFvUJSezGS0d2QZi5oDnYPJ68l+Z7y+6vgb7aXVfYGkJFR4RVI33sbKamvLSUpR1PjW+LjgXblD2oLW+Mep8CdTmgDVIHp5fb41UXUtk8R525o= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=c4GzW75v; arc=pass smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="c4GzW75v" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-6a5e971c970so6640997a12.0 for ; Sun, 30 Aug 2026 22:33:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154388; cv=none; d=google.com; s=arc-20260327; b=OZvGvbGUSmZG2gVwF6pb26IgjObRGmTIrRj+FzAdVjCgufg2v6LrCsBQ+i64sQbNuG I+NfJgLSK1Xz6Sk2Pbwig+KMJP9ne7JS0qaeQvKhJPcDQhTMrDuT6faVjQhUF+SE7bdW NgXsn9bsU75Tam1a2SZdnZNsxYk8aAAaWpH9JZ7ri3wU7h/HIOGE/peWWHrwEv9tsUnh DhY3WxMZi245gAgPaVBndeSrDl1gaCI33806RlP+yAirl+vOs5LsSFlVWHYv6V4UWA4X i5kECIGELwdkf/deQq0w8/BO6woud1D3Cj8ylUPMdvO0VoKY9scAMJYkCqxH9PdN37ZE i9gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=1vBZz0FHk3hbElOsJDIqL5UVlyjBmQ/JI/HbefNK6tE=; fh=/tXc8W3A7z/C/fzrqG6upKP509NfeznGlzZ/eW3zrpc=; b=SK9sEhACg/oIqtfzCqnwhfHtyGUFg8wZJgaivWj6pFUYK/nzMFDF5QJLlsw9/JA4rq te3t7zRscVaei+gPDFFq8eQ/SvRub+VF1eRUG8XkBAu17QbOtDOoog242cc9jGoUOhX6 UW6yxomhEiMrwQEbn7kraDP8DDdiKz7pkiaIopMxJeGFEhwBmz9Pj5owBTMqNTaUlrAD TClld/jTHX3FxnS8DYZTASAlVu7KuazsQZphnzw1pMfhi1RKmygDUuExzGrRFLyK4C10 1rLFXHsdulAZXscpJ4wVB+WxSRAMhtYwMIbLZdgQanOkjIZuKds+g8Ry2gD9TldSdDky plyw==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154388; x=1788759188; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=1vBZz0FHk3hbElOsJDIqL5UVlyjBmQ/JI/HbefNK6tE=; b=c4GzW75vMWnY2uyR+tCcfLmDQjVKUwRzXlTj+GIsMBV3HuwOY46QBhIDDCPpb3hFqf eChTQxFL+dNlVsn18ZbJeIZP993ogCDsJxFDrovYzJ/LZHGNxrrwkvFoi2mnIMeOpvYT vM7GUO7dDdVOttotGHs/Nth3Ne1ch977/oN79Wm832lYwIwdSb/qOJHSi4PUku7vzLMX MYRT3Cn2oWlqikDQOeDRTo4QcLHuSysXx6R9J5BYkZzcINp2X/dn3aJMTWQPfZXrC/r2 f1PKMFzEssjbRAgDGvVBAd+5WeeFx/xNTFucvX3AtBYJaHGYGhuXAE+nQyrsfioooWmn ZBRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154388; x=1788759188; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=1vBZz0FHk3hbElOsJDIqL5UVlyjBmQ/JI/HbefNK6tE=; b=XqNKvFPevrQthQP/iOugSjYZ1zI1UyS0CTINjerLGnPCE/93AX1HOWIZJbuYm/N2qe /s2uk8UWyq/ZpXNSiXEfYqTdinsJhH0MPmCyBra0+2ZDO6WKo+UpgLw4OoU95zenGz1T lvmeUBLKUqyBi9WGq0HHQ7Ti/oJc6LUPjEg8ak92e3v8pJikebi3++ftG7WF6niWfB5/ dpcc//qNkpwO+rObCRibUw0yaWembuDy8WvxKSjXJxQtH6HLsMQvvll/7hKaDS1V3g3/ doTS577gszwk0UoW2n3mErbyJlg4niyAS0O/vcw49hUaG89B41NbEHK0tPps30D9Rv1I fFUQ== X-Forwarded-Encrypted: i=1; AKwUvBw7ssptIu3oyjsN1z6oyN04hoTwufdaB8zRdDJuF1sX5k9Ija6GDQZMKnqZ1tiACXwoIxI0SpWbQQnOpTE=@vger.kernel.org X-Gm-Message-State: AFuF++lknlrDQywVLsn3RGCHEubflnb402WcXNzbd5x53W289Z0bB2+Z DpCr3BA7JHB/qT16YHAlP6gYWpAifCXwkY2cB5Pkwmw55MNsts4w3d+nL+S97w/d8v9eqvIzCal u3aH9Osn/9cf2pvXzzRTNWmKi25jopOo= X-Gm-Gg: AYBFou2leXLHNYAxcu54VYpsBHOeP6dj64pIZFE6r74+h6CBQ8UQZM/gi0tg1ZXITpA KDFEdWrRLc2b/OMf93yvNKOKknXsBx3KAKX3XPiTz8eFltiVDnRDUU3eBi6YqSSsRAgAMqWCikg 5xYmkyzblZWjpCQIOpMjq3nekHCmP7pNIR6cJiR68aOaPLfnEuj3H5nhV94faO3YGMy1rXctfnM 3lonVfcFt9gdo78EXXYudPcS4jtUnmmoq0mCJcyIXB7jdPNRr/TXJv6M+BGgjCLbtHoar19n3Oc eFai2qOSk/wV/GxLDPpz2/fZXqUlv7A03Kk3YkAOka5kfm2tf/OqQn3+NzoHmv492whw7RbkJcO vvA== X-Received: by 2002:a05:6402:5052:b0:697:eb97:a4ed with SMTP id 4fb4d7f45d1cf-6a647759b2amr3213291a12.7.1788154388003; Sun, 30 Aug 2026 22:33:08 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:07 +0200 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:07 +0200 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 07:33:07 +0200 X-Gm-Features: AcwNN1WvreAJnWhyi2veeu8qfPXm9__-weXbPX3FxUPvB9d5Lp7UaIJm264I3jU Message-ID: Subject: [PATCH v3 06/11] f2fs: describe {i,d,id}node block layout dynamically To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" An inode block ends with five i_nid entries followed by a node footer. Data block address pointers (i_addr[]) precede them. Similarly, direct and indirect node blocks contain data addresses or node IDs followed by a node footer at the end of the block. Describe struct f2fs_inode, struct direct_node, and struct indirect_node using flexible array members. Compute the locations of i_nid and node footers dynamically from the filesystem block size. Introduce F2FS_INODE_NIDS() and F2FS_NODE_FOOTER() helpers to access these tail fields. Compute sbi->addrs_per_inode, sbi->addrs_per_block, and sbi->nids_per_block in init_sb_info(), and update node management, file mapping, and recovery paths accordingly. Signed-off-by: Kelvin Zhang --- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 32 ++++++++++++++++++------- fs/f2fs/gc.c | 2 +- fs/f2fs/inline.c | 3 +-- fs/f2fs/inode.c | 5 ++-- fs/f2fs/node.c | 4 +--- fs/f2fs/node.h | 53 +++++++++++++++++++---------------------- fs/f2fs/super.c | 5 ++++ include/linux/f2fs_fs.h | 26 +++++++++++++++----- 9 files changed, 79 insertions(+), 53 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 6ae0eb37d20f..751b7a457d9a 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -2027,7 +2027,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); offset =3D offsetof(struct f2fs_inode, i_addr) + - sizeof(__le32) * (DEF_ADDRS_PER_INODE - + sizeof(__le32) * (DEF_ADDRS_PER_INODE_SBI(sbi) - get_inline_xattr_addrs(inode)); phys +=3D offset; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index d2e54573ed34..247e56522441 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1853,6 +1853,9 @@ struct f2fs_sb_info { unsigned int log_blocksize; /* log2 block size */ unsigned int blocksize; /* block size */ unsigned int nat_entries_per_block; /* NAT entries in a block */ + unsigned int addrs_per_inode; /* addresses in an inode block */ + unsigned int addrs_per_block; /* addresses in a direct node block */ + unsigned int nids_per_block; /* node IDs in an indirect node block */ unsigned int sit_entries_per_block; /* SIT entries in a block */ unsigned int orphans_per_block; /* orphan inodes in a block */ unsigned int dentries_per_block; /* dentries in a block */ @@ -2248,6 +2251,7 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio) #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) #define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) +#define DEF_ADDRS_PER_INODE_SBI(sbi) ((sbi)->addrs_per_inode) #define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) #define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) @@ -2297,6 +2301,12 @@ static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) return (struct f2fs_checkpoint *)(sbi->ckpt); } +static inline struct node_footer *F2FS_NODE_FOOTER(const struct folio *fol= io) +{ + return folio_address(folio) + F2FS_BLKSIZE - + sizeof(struct node_footer); +} + static inline struct f2fs_node *F2FS_NODE(const struct folio *folio) { return (struct f2fs_node *)folio_address(folio); @@ -2307,6 +2317,12 @@ static inline struct f2fs_inode *F2FS_INODE(const struct folio *folio) return &((struct f2fs_node *)folio_address(folio))->i; } +static inline __le32 *F2FS_INODE_NIDS(const struct folio *folio) +{ + return folio_address(folio) + F2FS_BLKSIZE - sizeof(struct node_footer) - + SIZE_OF_I_NID; +} + static inline struct f2fs_nm_info *NM_I(struct f2fs_sb_info *sbi) { return (struct f2fs_nm_info *)(sbi->nm_info); @@ -3277,13 +3293,11 @@ static inline void f2fs_radix_tree_insert(struct radix_tree_root *root, cond_resched(); } -#define RAW_IS_INODE(p) ((p)->footer.nid =3D=3D (p)->footer.ino) - static inline bool IS_INODE(const struct folio *folio) { - struct f2fs_node *p =3D F2FS_NODE(folio); + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); - return RAW_IS_INODE(p); + return footer->nid =3D=3D footer->ino; } static inline int offset_in_addr(struct f2fs_inode *i) @@ -3292,9 +3306,11 @@ static inline int offset_in_addr(struct f2fs_inode *= i) (le16_to_cpu(i->i_extra_isize) / sizeof(__le32)) : 0; } -static inline __le32 *blkaddr_in_node(struct f2fs_node *node) +static inline __le32 *blkaddr_in_node(const struct folio *folio) { - return RAW_IS_INODE(node) ? node->i.i_addr : node->dn.addr; + struct f2fs_node *node =3D F2FS_NODE(folio); + + return IS_INODE(folio) ? node->i.i_addr : node->dn.addr; } static inline int f2fs_has_extra_attr(struct inode *inode); @@ -3311,7 +3327,7 @@ static inline unsigned int get_dnode_base(struct inode *inode, static inline __le32 *get_dnode_addr(struct inode *inode, struct folio *node_folio) { - return blkaddr_in_node(F2FS_NODE(node_folio)) + + return blkaddr_in_node(node_folio) + get_dnode_base(inode, node_folio); } @@ -3639,7 +3655,7 @@ void *inline_xattr_addr(struct inode *inode, const struct folio *folio) { struct f2fs_inode *ri =3D F2FS_INODE(folio); - return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE - + return (void *)&(ri->i_addr[DEF_ADDRS_PER_INODE_SBI(F2FS_I_SB(inode)) - get_inline_xattr_addrs(inode)]); } diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index c15c6ba91597..f15ab07a7347 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1176,7 +1176,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, if (IS_INODE(node_folio)) { base =3D offset_in_addr(F2FS_INODE(node_folio)); - max_addrs =3D DEF_ADDRS_PER_INODE; + max_addrs =3D DEF_ADDRS_PER_INODE_SBI(sbi); } else { base =3D 0; max_addrs =3D DEF_ADDRS_PER_BLOCK; diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 718dd785865a..73cd9b6ddcc5 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -36,14 +36,13 @@ bool f2fs_may_inline_data(struct inode *inode) static bool inode_has_blocks(struct inode *inode, struct folio *ifolio) { - struct f2fs_inode *ri =3D F2FS_INODE(ifolio); int i; if (F2FS_HAS_BLOCKS(inode)) return true; for (i =3D 0; i < DEF_NIDS_PER_INODE; i++) { - if (ri->i_nid[i]) + if (F2FS_INODE_NIDS(ifolio)[i]) return true; } return false; diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 96cc0e777567..fda9ee3bfc61 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -150,9 +150,8 @@ bool f2fs_enable_inode_chksum(struct f2fs_sb_info *sbi, struct folio *folio) static __u32 f2fs_inode_chksum(struct f2fs_sb_info *sbi, struct folio *fol= io) { - struct f2fs_node *node =3D F2FS_NODE(folio); - struct f2fs_inode *ri =3D &node->i; - __le32 ino =3D node->footer.ino; + struct f2fs_inode *ri =3D F2FS_INODE(folio); + __le32 ino =3D F2FS_NODE_FOOTER(folio)->ino; __le32 gen =3D ri->i_generation; __u32 chksum, chksum_seed; __u32 dummy_cs =3D 0; diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 960c6657d0d6..e3f594f7bcce 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -3001,7 +3001,6 @@ int f2fs_recover_inode_page(struct f2fs_sb_info *sbi, struct folio *folio) int f2fs_restore_node_summary(struct f2fs_sb_info *sbi, unsigned int segno, struct f2fs_summary_block *sum) { - struct f2fs_node *rn; struct f2fs_summary *sum_entry; block_t addr; int i, idx, last_offset, nrpages; @@ -3023,8 +3022,7 @@ int f2fs_restore_node_summary(struct f2fs_sb_info *sb= i, if (IS_ERR(folio)) return PTR_ERR(folio); - rn =3D F2FS_NODE(folio); - sum_entry->nid =3D rn->footer.nid; + sum_entry->nid =3D F2FS_NODE_FOOTER(folio)->nid; sum_entry->version =3D 0; sum_entry->ofs_in_node =3D 0; sum_entry++; diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 0dce97aac5fc..6a2b7c63f4a3 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -252,73 +252,68 @@ static inline void set_to_next_nat(struct f2fs_sb_info *sbi, static inline nid_t ino_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le32_to_cpu(rn->footer.ino); + return le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->ino); } static inline nid_t nid_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le32_to_cpu(rn->footer.nid); + return le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->nid); } static inline unsigned int ofs_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - unsigned flag =3D le32_to_cpu(rn->footer.flag); + unsigned int flag =3D le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->flag); return flag >> OFFSET_BIT_SHIFT; } static inline __u64 cpver_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le64_to_cpu(rn->footer.cp_ver); + return le64_to_cpu(F2FS_NODE_FOOTER(node_folio)->cp_ver); } static inline block_t next_blkaddr_of_node(const struct folio *node_folio) { - struct f2fs_node *rn =3D F2FS_NODE(node_folio); - return le32_to_cpu(rn->footer.next_blkaddr); + return le32_to_cpu(F2FS_NODE_FOOTER(node_folio)->next_blkaddr); } static inline void fill_node_footer(const struct folio *folio, nid_t nid, nid_t ino, unsigned int ofs, bool reset) { struct f2fs_node *rn =3D F2FS_NODE(folio); + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); unsigned int old_flag =3D 0; if (reset) - memset(rn, 0, sizeof(*rn)); + memset(rn, 0, F2FS_BLKSIZE); else - old_flag =3D le32_to_cpu(rn->footer.flag); + old_flag =3D le32_to_cpu(footer->flag); - rn->footer.nid =3D cpu_to_le32(nid); - rn->footer.ino =3D cpu_to_le32(ino); + footer->nid =3D cpu_to_le32(nid); + footer->ino =3D cpu_to_le32(ino); /* should remain old flag bits such as COLD_BIT_SHIFT */ - rn->footer.flag =3D cpu_to_le32((ofs << OFFSET_BIT_SHIFT) | + footer->flag =3D cpu_to_le32((ofs << OFFSET_BIT_SHIFT) | (old_flag & OFFSET_BIT_MASK)); } static inline void copy_node_footer(const struct folio *dst, const struct folio *src) { - struct f2fs_node *src_rn =3D F2FS_NODE(src); - struct f2fs_node *dst_rn =3D F2FS_NODE(dst); - memcpy(&dst_rn->footer, &src_rn->footer, sizeof(struct node_footer)); + memcpy(F2FS_NODE_FOOTER(dst), F2FS_NODE_FOOTER(src), + sizeof(struct node_footer)); } static inline void fill_node_footer_blkaddr(struct folio *folio, block_t blkaddr) { struct f2fs_checkpoint *ckpt =3D F2FS_CKPT(F2FS_F_SB(folio)); - struct f2fs_node *rn =3D F2FS_NODE(folio); + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); __u64 cp_ver =3D cur_cp_version(ckpt); if (__is_set_ckpt_flags(ckpt, CP_CRC_RECOVERY_FLAG)) cp_ver |=3D (cur_cp_crc(ckpt) << 32); - rn->footer.cp_ver =3D cpu_to_le64(cp_ver); - rn->footer.next_blkaddr =3D cpu_to_le32(blkaddr); + footer->cp_ver =3D cpu_to_le64(cp_ver); + footer->next_blkaddr =3D cpu_to_le32(blkaddr); } static inline bool is_recoverable_dnode(const struct folio *folio) @@ -378,11 +373,12 @@ static inline bool IS_DNODE(const struct folio *node_folio) static inline int set_nid(struct folio *folio, int off, nid_t nid, bool i) { struct f2fs_node *rn =3D F2FS_NODE(folio); + __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); f2fs_folio_wait_writeback(folio, NODE, true, true); if (i) - rn->i.i_nid[off - NODE_DIR1_BLOCK] =3D cpu_to_le32(nid); + inode_nids[off - NODE_DIR1_BLOCK] =3D cpu_to_le32(nid); else rn->in.nid[off] =3D cpu_to_le32(nid); return folio_mark_dirty(folio); @@ -391,9 +387,10 @@ static inline int set_nid(struct folio *folio, int off, nid_t nid, bool i) static inline nid_t get_nid(const struct folio *folio, int off, bool i) { struct f2fs_node *rn =3D F2FS_NODE(folio); + const __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); if (i) - return le32_to_cpu(rn->i.i_nid[off - NODE_DIR1_BLOCK]); + return le32_to_cpu(inode_nids[off - NODE_DIR1_BLOCK]); return le32_to_cpu(rn->in.nid[off]); } @@ -406,8 +403,7 @@ static inline nid_t get_nid(const struct folio *folio, int off, bool i) static inline int is_node(const struct folio *folio, int type) { - struct f2fs_node *rn =3D F2FS_NODE(folio); - return le32_to_cpu(rn->footer.flag) & BIT(type); + return le32_to_cpu(F2FS_NODE_FOOTER(folio)->flag) & BIT(type); } #define is_cold_node(folio) is_node(folio, COLD_BIT_SHIFT) @@ -416,14 +412,13 @@ static inline int is_node(const struct folio *folio, int type) static inline void __set_mark(const struct folio *folio, bool mark, int ty= pe) { - struct f2fs_node *rn =3D F2FS_NODE(folio); - unsigned int flag =3D le32_to_cpu(rn->footer.flag); - + struct node_footer *footer =3D F2FS_NODE_FOOTER(folio); + unsigned int flag =3D le32_to_cpu(footer->flag); if (mark) flag |=3D BIT(type); else flag &=3D ~BIT(type); - rn->footer.flag =3D cpu_to_le32(flag); + footer->flag =3D cpu_to_le32(flag); } static inline void set_cold_node(const struct folio *folio, bool is_dir) diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 8d2224e585d3..fcaeaacaab33 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -4384,6 +4384,11 @@ static void init_sb_info(struct f2fs_sb_info *sbi) sbi->blocksize =3D BIT(sbi->log_blocksize); sbi->nat_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_nat_entry); + sbi->addrs_per_inode =3D (sbi->blocksize - OFFSET_OF_END_OF_I_EXT - + SIZE_OF_I_NID - sizeof(struct node_footer)) / sizeof(__le32); + sbi->addrs_per_block =3D (sbi->blocksize - + sizeof(struct node_footer)) / sizeof(__le32); + sbi->nids_per_block =3D sbi->addrs_per_block; sbi->sit_entries_per_block =3D sbi->blocksize / sizeof(struct f2fs_sit_entry); sbi->orphans_per_block =3D (sbi->blocksize - diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index d1059a27e1b9..3d0fe2c78e12 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -16,6 +16,7 @@ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ #define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) /* log number for sector/blk */ #define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ +#define F2FS_MAX_BLKSIZE PAGE_SIZE #define F2FS_BLKSIZE_BITS PAGE_SHIFT /* bits for F2FS_BLKSIZE */ #define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_EXTENSION_LEN 8 /* max size of extension */ @@ -343,18 +344,25 @@ struct f2fs_inode { */ __le32 i_extra_end[0]; /* for attribute size calculation */ } __packed; - __le32 i_addr[DEF_ADDRS_PER_INODE]; /* Pointers to data blocks */ + DECLARE_FLEX_ARRAY(__le32, i_addr); /* data block pointers */ }; - __le32 i_nid[DEF_NIDS_PER_INODE]; /* direct(2), indirect(2), - double_indirect(1) node id */ + /* + * __le32 i_nid[DEF_NIDS_PER_INODE]; + * + * It is stored immediately before the node footer at the end of the + * filesystem block. Its offset depends on the filesystem block size, so + * locate it dynamically with F2FS_INODE_NIDS(). + */ } __packed; struct direct_node { - __le32 addr[DEF_ADDRS_PER_BLOCK]; /* array of data block address */ + /* The address count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(__le32, addr); /* array of data block address */ } __packed; struct indirect_node { - __le32 nid[NIDS_PER_BLOCK]; /* array of data block address */ + /* The node ID count depends on the filesystem block size. */ + DECLARE_FLEX_ARRAY(__le32, nid); /* array of data block address */ } __packed; enum { @@ -373,7 +381,13 @@ struct f2fs_node { struct direct_node dn; struct indirect_node in; }; - struct node_footer footer; + /* + * struct node_footer footer; + * + * It is stored at the end of the filesystem block, after the inode or + * direct/indirect node data. Its offset depends on the filesystem block + * size, so locate it dynamically with F2FS_NODE_FOOTER(). + */ } __packed; /* --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13A3C3AC0E6 for ; Mon, 31 Aug 2026 05:33:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154394; cv=pass; b=deoFM/7PSKty9kEKZpbXSRp0elUvVJQ3s1Z2qKXAUcL+6N95qIXyOVNO4Jbl5CBVpPe9jZVbo5hoilTN8hnL8YtuD8be0g6xuwPv1NA6u25+xjiYhGHXSWZWU9lnle9Vl4CYBLNBniCFdib2ptZOuuIgyS5F1xLMbtKfsoeVkCI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154394; c=relaxed/simple; bh=VR5ilbanWF7j2HtEfDuXVi4GqR6LFeBzg+b5xrKjh+c=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=oeqNl0kLXJlPceXxmU+hlTk/OG9vep0NQjDX2bgJ7x6ox6hSJlpjgh9YcYwQUEZHmanisrt64veYuQACgopNEUsuJils7HdYwtWBZHDLmaQ0BlvLC2r8zZQMaV0Kc5GMjZ+QOgrfQsut5JkLH+Pw+gF7Q7b3ZX/otC9Xlh4KGCo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VIH+zKlS; arc=pass smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VIH+zKlS" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-6a63667b78aso2091000a12.3 for ; Sun, 30 Aug 2026 22:33:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154391; cv=none; d=google.com; s=arc-20260327; b=BB1HUgefh7C24ONzetDVCEpNsI376OB/oTaTdmZQQvnMPiMQdk2H31YSxyxT54rC3Y l738e8K6Nm2IpwqIbmV+/uFw0H8CDIqYCqtQq/ffipMJjMNIlYwSiSZYJSnGdyaBTlzI rvXPL6Ni1VguGH0Y71Tob99EYB8ntT+k5LJd3IKewcjZpU5ZbkLJUirBw/z0qcsHTIT9 yg5WG/YX9rc5ix0RlYUgDSCKZdSHAEfhdBPNQUgqhqzWqCGmdEBk6NetzNvv4TMsxh7F RAytMAcleQuTAuGD7UgYA3iPnm/Ob2ujkczOkRulqz9WlDjJv28fEe5+wFh3Lm+Sa9pM dUBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=Jwk6B4YYUYIOqVo5qZvx9IbKKge2giW/CtwxPziGTg4=; fh=+0ykIzFwygZnW9oCWb4p+LZh7InSk70ALvtHH2hVJck=; b=MqQyeFuH0Few+l2xbOkdvGIcPOaStkWf3uVO750zZkh0a6jEd+Lgu9e64f0mLB28c1 Pe0Gm0n2ISQgv41ytJ4Tv720+d/7WLkfdH+3PYi8As/5g4CKH0F2hOX+DSnU2sq4GVUB jQGehA/kgoqc/gYjNw9jepFqjauh5qceEss13GbZ/IGGLrzHuikOYGgw4/GBkLMsaHWH cj/GltvvXEWpTCUbosmd3NlPgvtYgAu8MweIqOm3mBCYmOdmY7PFDVon7Wo+AlL92saX Am8iyFQ0M5GexpKWjUnUGfuuLMPgiHYLQ+EZs5eakwuE7649XRCw5TRJw2Ju64Ct6daq wW2A==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154391; x=1788759191; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Jwk6B4YYUYIOqVo5qZvx9IbKKge2giW/CtwxPziGTg4=; b=VIH+zKlS20fJ/3AD1JCbpdtE1ZqTR9lv56Zl5mjvzsPSAyuIfFkFRBm+BLrLOQZIbW IF1dfWTYBXAFtaoonOORy0ReS3Qb5Fz9O3Hw/gxJscnQHPtnPU+n7m9Wnf4TPSQnI+ol uETIyqM4brcADYJ43n7tlL9cFQWCy9ibHT9Ho6M2XCc4e4GRWsxV9IqqTXs/Pu2Asfdd LIo0oSCLtHPGMS2HmUw7Ooe8GkBgpXjT0Il0GLX/tSzreptV7PdXHndUigMwYAT5tsl8 4sdKEVq6a9zrowHq9iuSMs+hFccAnlyd3ullugYhZWhAh4hJRntD1wseOURouHJ/DteO S9xA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154391; x=1788759191; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=Jwk6B4YYUYIOqVo5qZvx9IbKKge2giW/CtwxPziGTg4=; b=Jy2blkYKW8GtS83FJnrCTZMF/b9MrRx8mM6JsbiGYVlC1Fbi4lBRgwf4UvgiYlQyoW WaEbstR5BZaBGYwwK+n8T4QZ0/ecp4ZMxKhO/A2mLWayKm7rLncoevHmHZ0eCVau+Ixl lOjXKyYMkZQ9uLcmAuTYKJ9qOahNB3VDCd+ojvXxFCRgiy8qTf7Tge2QZuI0VJukrl7E 81+ylQ4kzaZ7JnlAdHY7RBW0zTtHMbtDsE4vzuasBXPAbAWfvW9w/D4fYE6ofmRj5t0z 9b7o/09aGsoTxsN7xq1g/fZ2PLYl3GV0AfSL4nxhpozJVI+GGAck9G3n8E9JrNRtcJlL nmWg== X-Forwarded-Encrypted: i=1; AKwUvByty8Fme5SC+invqgyEmyJGEkBwb02GnLM1YGO7gEQjncT7c8UMYDNrNQ8FfhpN5E4qpGIM6B9vJ/QzGdc=@vger.kernel.org X-Gm-Message-State: AFuF++keWezcHH/mO4hpoQsFlU725OIujG5YJ8GSa+Hf51zXtNy3POif bMuhJSoqmXMGRqOlju91tdgs9Oh7JCRzjRcvjc3JF5esyWbboijWYqTiq3LG3c1zGwfhxqrnd5p 5AtuMQLB6A5GA+O6d6o4/nV6VhOD//GA= X-Gm-Gg: AYBFou2QMTe2w8SfnkdzMj9gPdCu2PM93D4wS1kis3ALfhjelRdhrIDsee2EZ1IPFFk bsWFG/WJyJoSEMnIND0gfkN5ANOfmd+5B+R6/dCDHtIHR3n7zdEV47XkolKiwrDcprlzblb3tZg ApYnKR1SpWnHwvocMcwd0HeVfqJAakfuOWr7v7RjnpIbiGYfLdTgYbb7vPAbVd4ixHK1iTqPoQL sV5c1pjCK1QBqD759y8NtWmTA6NAZHClegsSAjqUlzltiGuKTxcYSyYi7NJYpAzxtbk/7SNs+EL UjxtS/e2s6LdVPHKeCkyEPa5vi8gjRlFb3lYJyWEO5B1WAojI2UscMB9KhDJPPXgfubEExILyT2 2uw== X-Received: by 2002:a05:6402:4516:b0:6a5:f815:b15c with SMTP id 4fb4d7f45d1cf-6a60d35b3a7mr13632777a12.8.1788154390963; Sun, 30 Aug 2026 22:33:10 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:10 +0200 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:10 +0200 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 07:33:10 +0200 X-Gm-Features: AcwNN1Uo2oI1NwLHCU4M6vU3nL9b7_WJhuDJVf5BIQ9FwbURqYY8LcyVVocFuGE Message-ID: Subject: [PATCH v3 07/11] f2fs: describe xattr block layout dynamically To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The usable capacity of dedicated on-disk extended attribute blocks and inline xattr regions scales with the filesystem block size. Parameterize VALID_XATTR_BLOCK_SIZE and MAX_INLINE_XATTR_SIZE to calculate usable xattr limits dynamically from sbi->blocksize rather than hardcoding PAGE_SIZE or DEF_ADDRS_PER_INODE. Update mount option consistency validation for inline_xattr_size to evaluate allowed boundaries dynamically against the runtime block size. Signed-off-by: Kelvin Zhang --- fs/f2fs/inode.c | 4 ++-- fs/f2fs/node.c | 2 +- fs/f2fs/super.c | 17 +++++++++++++++-- fs/f2fs/xattr.c | 8 +++++--- fs/f2fs/xattr.h | 15 ++++++++++----- include/linux/f2fs_fs.h | 2 ++ 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index fda9ee3bfc61..20b0561fe35d 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -337,12 +337,12 @@ static bool sanity_check_inode(struct inode *inode, struct folio *node_folio) } if (f2fs_sb_has_flexible_inline_xattr(sbi) && - (fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE || + (fi->i_inline_xattr_size > MAX_INLINE_XATTR_SIZE(inode) || (f2fs_has_inline_xattr(inode) && fi->i_inline_xattr_size < MIN_INLINE_XATTR_SIZE))) { f2fs_warn(sbi, "%s: inode (ino=3D%llx) has corrupted i_inline_xattr_size: %d, min: %zu, max: %lu", __func__, inode->i_ino, fi->i_inline_xattr_size, - MIN_INLINE_XATTR_SIZE, MAX_INLINE_XATTR_SIZE); + MIN_INLINE_XATTR_SIZE, MAX_INLINE_XATTR_SIZE(inode)); return false; } diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index e3f594f7bcce..7dabfada1b54 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -2919,7 +2919,7 @@ int f2fs_recover_xattr_data(struct inode *inode, struct folio *folio) /* 3: update and set xattr node page dirty */ if (folio) { memcpy(F2FS_NODE(xfolio), F2FS_NODE(folio), - VALID_XATTR_BLOCK_SIZE); + VALID_XATTR_BLOCK_SIZE(inode)); folio_mark_dirty(xfolio); } f2fs_folio_put(xfolio, true); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index fcaeaacaab33..3ba4df757213 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -855,9 +855,11 @@ static int f2fs_parse_param(struct fs_context *fc, struct fs_parameter *param) break; case Opt_inline_xattr_size: if (result.int_32 < MIN_INLINE_XATTR_SIZE || - result.int_32 > MAX_INLINE_XATTR_SIZE) { + result.int_32 > + MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(F2FS_MAX_BLKSIZE)) { f2fs_err(NULL, "inline xattr size is out of range: %u ~ %u", - (u32)MIN_INLINE_XATTR_SIZE, (u32)MAX_INLINE_XATTR_SIZE); + (u32)MIN_INLINE_XATTR_SIZE, + (u32)MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(F2FS_MAX_BLKSIZE)); return -EINVAL; } ctx_set_opt(ctx, F2FS_MOUNT_INLINE_XATTR_SIZE); @@ -1596,6 +1598,8 @@ static int f2fs_check_opt_consistency(struct fs_context *fc, } if (ctx_test_opt(ctx, F2FS_MOUNT_INLINE_XATTR_SIZE)) { + int min_size, max_size; + if (!f2fs_sb_has_extra_attr(sbi) || !f2fs_sb_has_flexible_inline_xattr(sbi)) { f2fs_err(sbi, "extra_attr or flexible_inline_xattr feature is off"); @@ -1605,6 +1609,15 @@ static int f2fs_check_opt_consistency(struct fs_context *fc, f2fs_err(sbi, "inline_xattr_size option should be set with inline_xattr option"); return -EINVAL; } + min_size =3D MIN_INLINE_XATTR_SIZE; + max_size =3D MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(F2FS_BLKSIZE); + + if (F2FS_OPTION(sbi).inline_xattr_size < min_size || + F2FS_OPTION(sbi).inline_xattr_size > max_size) { + f2fs_err(sbi, "inline xattr size is out of range: %d ~ %d", + min_size, max_size); + return -EINVAL; + } } if (ctx_test_opt(ctx, F2FS_MOUNT_ATGC) && diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index 6728d1488cad..99c863513725 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -310,7 +310,8 @@ static int read_xattr_block(struct inode *inode, void *txattr_addr) return PTR_ERR(xfolio); xattr_addr =3D folio_address(xfolio); - memcpy(txattr_addr + inline_size, xattr_addr, VALID_XATTR_BLOCK_SIZE); + memcpy(txattr_addr + inline_size, xattr_addr, + VALID_XATTR_BLOCK_SIZE(inode)); f2fs_folio_put(xfolio, true); return 0; @@ -393,7 +394,7 @@ static int read_all_xattrs(struct inode *inode, struct folio *ifolio, { struct f2fs_xattr_header *header; nid_t xnid =3D F2FS_I(inode)->i_xattr_nid; - unsigned int size =3D VALID_XATTR_BLOCK_SIZE; + unsigned int size =3D VALID_XATTR_BLOCK_SIZE(inode); unsigned int inline_size =3D inline_xattr_size(inode); void *txattr_addr; int err; @@ -502,7 +503,8 @@ static inline int write_all_xattrs(struct inode *inode, __u32 hsize, if (inline_size) memcpy(inline_addr, txattr_addr, inline_size); - memcpy(xattr_addr, txattr_addr + inline_size, VALID_XATTR_BLOCK_SIZE); + memcpy(xattr_addr, txattr_addr + inline_size, + VALID_XATTR_BLOCK_SIZE(inode)); if (inline_size) folio_mark_dirty(ifolio ? ifolio : in_folio); diff --git a/fs/f2fs/xattr.h b/fs/f2fs/xattr.h index bce3d93e4755..d9e2c65a1fc7 100644 --- a/fs/f2fs/xattr.h +++ b/fs/f2fs/xattr.h @@ -71,24 +71,29 @@ struct f2fs_xattr_entry { for (entry =3D XATTR_FIRST_ENTRY(addr);\ !IS_XATTR_LAST_ENTRY(entry);\ entry =3D XATTR_NEXT_ENTRY(entry)) -#define VALID_XATTR_BLOCK_SIZE (PAGE_SIZE - sizeof(struct node_footer)) +#define VALID_XATTR_BLOCK_SIZE(i) (i_blocksize(i) - \ + sizeof(struct node_footer)) #define XATTR_PADDING_SIZE (sizeof(__u32)) #define XATTR_SIZE(i) ((F2FS_I(i)->i_xattr_nid ? \ - VALID_XATTR_BLOCK_SIZE : 0) + \ + VALID_XATTR_BLOCK_SIZE(i) : 0) + \ (inline_xattr_size(i))) #define MIN_OFFSET(i) XATTR_ALIGN(inline_xattr_size(i) + \ - VALID_XATTR_BLOCK_SIZE) + VALID_XATTR_BLOCK_SIZE(i)) #define MAX_VALUE_LEN(i) (MIN_OFFSET(i) - \ sizeof(struct f2fs_xattr_header) - \ sizeof(struct f2fs_xattr_entry)) #define MIN_INLINE_XATTR_SIZE (sizeof(struct f2fs_xattr_header) / sizeof(__le32)) -#define MAX_INLINE_XATTR_SIZE \ - (DEF_ADDRS_PER_INODE - \ +#define MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(blocksize) \ + (((blocksize) - OFFSET_OF_END_OF_I_EXT - \ + SIZE_OF_I_NID - sizeof(struct node_footer)) / \ + sizeof(__le32) - \ F2FS_TOTAL_EXTRA_ATTR_SIZE / sizeof(__le32) - \ DEF_INLINE_RESERVED_SIZE - \ MIN_INLINE_DENTRY_SIZE / sizeof(__le32)) +#define MAX_INLINE_XATTR_SIZE(inode) \ + MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(i_blocksize(inode)) #define DEFAULT_XATTR_SLAB_SIZE (DEFAULT_INLINE_XATTR_ADDRS * \ sizeof(__le32) + XATTR_PADDING_SIZE) diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 3d0fe2c78e12..d4151970ae86 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -15,6 +15,8 @@ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ #define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) /* log number for sector/blk */ +#define F2FS_MIN_LOG_BLOCKSIZE 12 +#define F2FS_MIN_BLKSIZE 4096UL #define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ #define F2FS_MAX_BLKSIZE PAGE_SIZE #define F2FS_BLKSIZE_BITS PAGE_SHIFT /* bits for F2FS_BLKSIZE */ --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CDEA83AE1B9 for ; Mon, 31 Aug 2026 05:33:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.48 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154397; cv=pass; b=OCsUc66b9adVf6D3r6wZerh5UDRmqRKdagKSZJH1yVlW4AyhiE9CRp60GnhMGCnRQckRmnLAA+1p8Z6rlL3bOxsKEu3hOskyIjw+laLHb69S/4jfySozEvYRmXY7Wn6L484R0d0EfZJHwNr/HoCKT2oSjwKN4RyG6t1wxVxk/GQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154397; c=relaxed/simple; bh=LwkNEZNS3n4XrPO4aPp3xwZH1tCkEtoJpNFfuxleVVc=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=AUUqVCciNyPxCeWpX1kmwT6a4tc3ezHxcuKliPGCqgerAiGTU+cd5rw//pXFlCDrnEuXuB+PNz2LD3J226j6Yf/Re3OScotjqDxneREC5ZUs/cEuRg6UZRRDyhttgEPZkR2XNdZoqDmHs17Gpon6ADsNHIoHhDsSqtjkOsQ7wMw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WkLKob15; arc=pass smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WkLKob15" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-6a173ad7cf4so4663658a12.3 for ; Sun, 30 Aug 2026 22:33:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154394; cv=none; d=google.com; s=arc-20260327; b=XuNv2yROFy7QifoNp+khA/cuo0OBFwzfEWAwv5iy+P5sT2D7HF25zWXgl1XCbEDUz7 Drg+vz30nxonqeLmzMx/Bgq714jGjL1qyCT/afBln9NGNQYu75Crws0IID1vicab+qZf AE7OqOpRpLvmTrcIqO/eAtLh+H84jeBfGPAC+3o8RqknavjwQNqfyIgm14yBfY5jQDq1 O0pfEYI9giCOU0lIdgazODg1uLuNy22xHm+gWh5BA223T5T+mwqNKRlfNvZAvj8WUEGq TfNiRDzE7GOIT4z7vMisqbynfgVFVjOl0I+kHyCTgJ+kEk03kSjPUX9YLDsy3Saq4wNq IP1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=teJG0g7hnXcKnDzhThesv9by/6HQHdAle5mTs9kt9nQ=; fh=bMcIl9aGZCteSgBGQSI/fpRzzv+synlXV7lsuL8tV24=; b=Y4hKPsPZi3H8ZDevATVYOtClpWV3ZewrJ6mjoDZJRC0pjrMn/dyNXg9ql3EiSHsyKJ jvMKe8YHUQO5jfE+27u8BxnI0AHHGtetw5ZsGYZ3EUQ8EFcIUtY1a9XiMHPsreZ4Y/na Qsk/+lr7jNfs6d/oYXuRtPrKTjJYo9pyr8c0K4ydO/hiHeDzJjRKtL/hDF4sNjF1rrSQ tGN45t/4Ozh+jamNsT6y0TmexCZoOdJO/rC9z/y+oeqSOJ3eluCA+NK0gEpqvLmJfMqz hHaW7sz1t215b+00au7gJd/PiDavOrLK5QlHqER5R3Qtaq0XITTXf51WEMzkSme7RA+/ krqQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154394; x=1788759194; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=teJG0g7hnXcKnDzhThesv9by/6HQHdAle5mTs9kt9nQ=; b=WkLKob15etMkALCOJ67YUU9SO0CaVVYrqE9KxrOUs6ZK/KAukhonNiT7z/Xj2jhkvk KPjQcA4pXx6Q9Q5DvzSeCJaV4CFFEgGPcz8+77IgdbZ5FzdcnykK9z/5491dZ8pu2a5m zl1e8xgrgciCb3jW9jcWxcFmXklSjQURhGO2q6YQQLszlUtrOAGMwjZduxb+CWjblvGd Hqk//JQZGnH2o8TUtGE4qlvqfRwI5BHxKhP5eFBzFrISJxY/iV5Bl16p85QinVl+jxoM a00yYWui9O3viPSu/XevK5ulVGdao+TJWpOIQ0TozcJE8l61TEtsMumVaYmS1PujGCsc jpng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154394; x=1788759194; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=teJG0g7hnXcKnDzhThesv9by/6HQHdAle5mTs9kt9nQ=; b=rmawvf2Uw2WVXl04/TfCluHdlwsmFm9O06CJOSVpI04P2NM0UPxhWfCk9HWrzC+Dru HUrhr9IRljSmRT5m1MD91PovrhQYPBDuFklTsBJTyJPJcKYXr/ec/4NRNzMCvMYwsuqW 5oFSr3mmFuj6GD02oJ8S6B6zCervCqcrW6GI6hWvb65AIutJVQc5ygvfMmEV5QAnzLVA 9fagGDkv8OL2vSJM6jiEJvjYM4DtWt498TFGlQJyB8zBQZRzKBRdURpb7h95KGk6kL8B UfCunS0POy2oz/O3GuWyL11zJeJVvVfjRxoAJax8FF0w1cdRhZg0cFQcG0Bv3tB+Yw// aC7w== X-Forwarded-Encrypted: i=1; AKwUvBw/RPiIt7obldwLLd3NyfVNHACwce/7EDB8bXNCT2uKHcVy6uyj0t7qnGwlZESUy+/uMf0yzBk5Rje1qrc=@vger.kernel.org X-Gm-Message-State: AFuF++kxSqXafJfa8C+lZl+hUxPfM+a9f//Os0A5Gf7m4vdUmCuLRf3g 3AXQihJbJPCTYfa2DV4aGYZEHa3zp4IDxwJND02WXDDF89GHk4psc1sWv8al+5DH0WyaVa48EHR zcPgXBEeKCPSktgDWs+EMObSt8897SaC0DUbQW1Y= X-Gm-Gg: AYBFou0yB1WRKZkx1rmdjX4Ad8K1barwBSUWYmQO/bLZDbVhPCsjpiYu4iiibKuWYF2 5O2oULJEVD11PU6qaigSBrvO9f5Txk58h20SwLA6vmPUVB9alKFXRrm3D2+RGjYLbOdtM1c81KV Rz0XswuzJ805/o0Ks5HIy31fIJAaVVyKWI6h3yjMhNvWnatxIY2ElUxIqC8yEkoK2V+ZmquGtJ7 +vEdEWUGRG/5YOFxC2rO/cu8Cm1JzrxYK2Cw/B2YyWAA30NQ2MA2ZpO82VES6REnecNDNBycOID gLmCDrrhyiVJ1vQ21IE10iJMS7TzQsjPF+iYU25cfNOWFyyEjIofVr5bjCvh2ZuHdixj15E4Tvx oZg== X-Received: by 2002:a05:6402:5107:b0:6a5:dfb6:3618 with SMTP id 4fb4d7f45d1cf-6a60d318ddamr13168124a12.5.1788154393701; Sun, 30 Aug 2026 22:33:13 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:13 +0200 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:13 +0200 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 07:33:13 +0200 X-Gm-Features: AcwNN1UoJMpz8YqPE1o6OJ4-pQE3eDamohPnpbvZ0InrZnHz_uUCWsqEar_y02E Message-ID: Subject: [PATCH v3 08/11] f2fs: parameterize sector conversion macros To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sector-to-block and block-to-sector conversion helpers previously assumed a fixed sector count per block derived from 4KB pages. Parameterize F2FS_LOG_SECTORS_PER_BLOCK, SECTOR_FROM_BLOCK, and SECTOR_TO_BLOCK with struct f2fs_sb_info *sbi, using sbi->log_sectors_per_block. Update all call sites across metadata I/O, data mapping, discard operations, and zoned block device reporting. Signed-off-by: Kelvin Zhang --- fs/f2fs/data.c | 2 +- fs/f2fs/f2fs.h | 5 +++-- fs/f2fs/file.c | 4 ++-- fs/f2fs/inode.c | 11 +++++++---- fs/f2fs/segment.c | 14 +++++++------- fs/f2fs/segment.h | 8 ++++---- fs/f2fs/super.c | 10 +++++----- include/linux/f2fs_fs.h | 2 +- 8 files changed, 30 insertions(+), 26 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 751b7a457d9a..44e1ae43565e 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -466,7 +466,7 @@ struct block_device *f2fs_target_device(struct f2fs_sb_info *sbi, } if (sector) - *sector =3D SECTOR_FROM_BLOCK(blk_addr); + *sector =3D SECTOR_FROM_BLOCK(sbi, blk_addr); return bdev; } diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 247e56522441..b90c5a42703f 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2609,7 +2609,8 @@ static inline int F2FS_HAS_BLOCKS(struct inode *inode) { block_t xattr_block =3D F2FS_I(inode)->i_xattr_nid ? 1 : 0; - return (inode->i_blocks >> F2FS_LOG_SECTORS_PER_BLOCK) > xattr_block; + return (inode->i_blocks >> + F2FS_LOG_SECTORS_PER_BLOCK(F2FS_I_SB(inode))) > xattr_block; } static inline bool f2fs_has_xattr_block(unsigned int ofs) @@ -2815,7 +2816,7 @@ static inline void dec_valid_block_count(struct f2fs_sb_info *sbi, struct inode *inode, block_t count) { - blkcnt_t sectors =3D count << F2FS_LOG_SECTORS_PER_BLOCK; + blkcnt_t sectors =3D count << F2FS_LOG_SECTORS_PER_BLOCK(sbi); spin_lock(&sbi->stat_lock); if (unlikely(sbi->total_valid_block_count < count)) { diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index d440231b8cb9..2c72e028cec2 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4510,8 +4510,8 @@ static int f2fs_reserve_compress_blocks(struct file *filp, unsigned long arg) static int f2fs_secure_erase(struct block_device *bdev, struct inode *inod= e, pgoff_t off, block_t block, block_t len, u32 flags) { - sector_t sector =3D SECTOR_FROM_BLOCK(block); - sector_t nr_sects =3D SECTOR_FROM_BLOCK(len); + sector_t sector =3D SECTOR_FROM_BLOCK(F2FS_I_SB(inode), block); + sector_t nr_sects =3D SECTOR_FROM_BLOCK(F2FS_I_SB(inode), len); int ret =3D 0; if (flags & F2FS_TRIM_FILE_DISCARD) { diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index 20b0561fe35d..b628fdc4198f 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -221,11 +221,11 @@ static bool sanity_check_compress_inode(struct inode *inode, return false; } if (le64_to_cpu(ri->i_compr_blocks) > - SECTOR_TO_BLOCK(inode->i_blocks)) { + SECTOR_TO_BLOCK(sbi, inode->i_blocks)) { f2fs_warn(sbi, "%s: inode (ino=3D%llx) has inconsistent i_compr_blocks:%llu, i_blocks:%llu, run fsck to fix", __func__, inode->i_ino, le64_to_cpu(ri->i_compr_blocks), - SECTOR_TO_BLOCK(inode->i_blocks)); + SECTOR_TO_BLOCK(sbi, inode->i_blocks)); return false; } if (ri->i_log_cluster_size < MIN_COMPRESS_LOG_SIZE || @@ -446,7 +446,8 @@ static int do_read_inode(struct inode *inode) i_gid_write(inode, le32_to_cpu(ri->i_gid)); set_nlink(inode, le32_to_cpu(ri->i_links)); inode->i_size =3D le64_to_cpu(ri->i_size); - inode->i_blocks =3D SECTOR_FROM_BLOCK(le64_to_cpu(ri->i_blocks) - 1); + inode->i_blocks =3D SECTOR_FROM_BLOCK(sbi, + le64_to_cpu(ri->i_blocks) - 1); inode_set_atime(inode, le64_to_cpu(ri->i_atime), le32_to_cpu(ri->i_atime_nsec)); @@ -695,6 +696,7 @@ struct inode *f2fs_iget_retry(struct super_block *sb, unsigned long ino) void f2fs_update_inode(struct inode *inode, struct folio *node_folio) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct f2fs_inode_info *fi =3D F2FS_I(inode); struct f2fs_inode *ri; struct extent_tree *et =3D fi->extent_tree[EX_READ]; @@ -711,7 +713,8 @@ void f2fs_update_inode(struct inode *inode, struct folio *node_folio) ri->i_uid =3D cpu_to_le32(i_uid_read(inode)); ri->i_gid =3D cpu_to_le32(i_gid_read(inode)); ri->i_links =3D cpu_to_le32(inode->i_nlink); - ri->i_blocks =3D cpu_to_le64(SECTOR_TO_BLOCK(READ_ONCE(inode->i_blocks)) = + 1); + ri->i_blocks =3D cpu_to_le64(SECTOR_TO_BLOCK(sbi, + READ_ONCE(inode->i_blocks)) + 1); if (!f2fs_is_atomic_file(inode) || is_inode_flag_set(inode, FI_ATOMIC_COMMITTED)) diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index b29df65ab5b7..f565b6873832 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1310,7 +1310,7 @@ static void __submit_zone_reset_cmd(struct f2fs_sb_info *sbi, /* sanity check on discard range */ __check_sit_bitmap(sbi, dc->di.lstart, dc->di.lstart + dc->di.len); - bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(dc->di.start); + bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(sbi, dc->di.start); bio->bi_private =3D dc; bio->bi_end_io =3D f2fs_submit_discard_endio; submit_bio(bio); @@ -1327,7 +1327,7 @@ static int __submit_discard_cmd(struct f2fs_sb_info *= sbi, { struct block_device *bdev =3D dc->bdev; unsigned int max_discard_blocks =3D - SECTOR_TO_BLOCK(bdev_max_discard_sectors(bdev)); + SECTOR_TO_BLOCK(sbi, bdev_max_discard_sectors(bdev)); struct discard_cmd_control *dcc =3D SM_I(sbi)->dcc_info; struct list_head *wait_list =3D (dpolicy->type =3D=3D DPOLICY_FSTRIM) ? &(dcc->fstrim_list) : &(dcc->wait_list); @@ -1389,8 +1389,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *= sbi, dc->di.len +=3D len; - __blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(start), - SECTOR_FROM_BLOCK(len), GFP_NOFS, &bio); + __blkdev_issue_discard(bdev, SECTOR_FROM_BLOCK(sbi, start), + SECTOR_FROM_BLOCK(sbi, len), GFP_NOFS, &bio); f2fs_bug_on(sbi, !bio); /* @@ -1518,7 +1518,7 @@ static void __update_discard_tree_range(struct f2fs_sb_info *sbi, struct discard_info di =3D {0}; struct rb_node **insert_p =3D NULL, *insert_parent =3D NULL; unsigned int max_discard_blocks =3D - SECTOR_TO_BLOCK(bdev_max_discard_sectors(bdev)); + SECTOR_TO_BLOCK(sbi, bdev_max_discard_sectors(bdev)); block_t end =3D lstart + len; dc =3D __lookup_discard_cmd_ret(&dcc->root, lstart, @@ -2041,8 +2041,8 @@ static int __f2fs_issue_discard_zone(struct f2fs_sb_info *sbi, /* For sequential zones, reset the zone write pointer */ if (f2fs_blkz_is_seq(sbi, devi, blkstart)) { - sector =3D SECTOR_FROM_BLOCK(blkstart); - nr_sects =3D SECTOR_FROM_BLOCK(blklen); + sector =3D SECTOR_FROM_BLOCK(sbi, blkstart); + nr_sects =3D SECTOR_FROM_BLOCK(sbi, blklen); div64_u64_rem(sector, bdev_zone_sectors(bdev), &remainder); if (remainder || nr_sects !=3D bdev_zone_sectors(bdev)) { diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 534e376cbc92..2275404e769c 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -114,10 +114,10 @@ f2fs_start_segno(struct f2fs_sb_info *sbi, unsigned int segno) #define f2fs_bitmap_size(nr) \ (BITS_TO_LONGS(nr) * sizeof(unsigned long)) -#define SECTOR_FROM_BLOCK(blk_addr) \ - (((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK) -#define SECTOR_TO_BLOCK(sectors) \ - ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK) +#define SECTOR_FROM_BLOCK(sbi, blk_addr) \ + (((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK(sbi)) +#define SECTOR_TO_BLOCK(sbi, sectors) \ + ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK(sbi)) /* * In the victim_sel_policy->alloc_mode, there are three block allocation modes. diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 3ba4df757213..46973207cd7b 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3944,7 +3944,7 @@ static int __f2fs_commit_super(struct f2fs_sb_info *sbi, struct folio *folio, bio =3D bio_alloc(sbi->sb->s_bdev, 1, opf, GFP_NOFS); /* it doesn't need to set crypto context for superblock update */ - bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(folio->index); + bio->bi_iter.bi_sector =3D SECTOR_FROM_BLOCK(sbi, folio->index); if (!bio_add_folio(bio, folio, folio_size(folio), 0)) f2fs_bug_on(sbi, 1); @@ -4520,7 +4520,7 @@ static int f2fs_report_zone_cb(struct blk_zone *zone, unsigned int idx, { struct f2fs_report_zones_args *rz_args =3D data; block_t unusable_blocks =3D (zone->len - zone->capacity) >> - F2FS_LOG_SECTORS_PER_BLOCK; + F2FS_LOG_SECTORS_PER_BLOCK(rz_args->sbi); if (zone->type =3D=3D BLK_ZONE_TYPE_CONVENTIONAL) return 0; @@ -4563,10 +4563,10 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi) zone_sectors =3D bdev_zone_sectors(bdev); if (sbi->blocks_per_blkz && sbi->blocks_per_blkz !=3D - SECTOR_TO_BLOCK(zone_sectors)) + SECTOR_TO_BLOCK(sbi, zone_sectors)) return -EINVAL; - sbi->blocks_per_blkz =3D SECTOR_TO_BLOCK(zone_sectors); - FDEV(devi).nr_blkz =3D div_u64(SECTOR_TO_BLOCK(nr_sectors), + sbi->blocks_per_blkz =3D SECTOR_TO_BLOCK(sbi, zone_sectors); + FDEV(devi).nr_blkz =3D div_u64(SECTOR_TO_BLOCK(sbi, nr_sectors), sbi->blocks_per_blkz); if (nr_sectors & (zone_sectors - 1)) FDEV(devi).nr_blkz++; diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index d4151970ae86..f89609356be8 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -14,7 +14,7 @@ #define F2FS_SUPER_OFFSET 1024 /* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ -#define F2FS_LOG_SECTORS_PER_BLOCK (PAGE_SHIFT - 9) /* log number for sector/blk */ +#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) ((sbi)->log_blocksize - 9) /* log number for sector/blk */ #define F2FS_MIN_LOG_BLOCKSIZE 12 #define F2FS_MIN_BLKSIZE 4096UL #define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 856D83A8743 for ; Mon, 31 Aug 2026 05:33:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.52 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154401; cv=pass; b=M4Pw6dufVMINipFUTqokIAg3KM4yGVoxtmzZ+ZWH9vaZci4c2fKgpIldpet5Gz0tI6vOFVN+yhBr53hfBvxkLYVruB3T6TOFscAwpj+mD6GeRehX54Ndjae1qW/rCqf0TNVE5MMCE5RlfpAdtH6VN0tBoIJj63NtuAOZSDehSFM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154401; c=relaxed/simple; bh=21eauyIJmji6Wn3zcpBU89Zw1E6db127f+7kRGmnaf4=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=aOIbxn0K5azEm/DQy8MTrMTzfstXMZmw7h7PchBESZs8KxCBo0tcX4PwSeTPAP7J0Vz2+gymn+7N3Y6DUT92bKOc8N1i6MDdJ42mGnMvHX3Edhte2oNgcyDgy5UW4SHW6UFncUBs+daa+4Mkj7rSkU9w30mnUeUUNXaoeLXHR4c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UMNKoLnS; arc=pass smtp.client-ip=209.85.208.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UMNKoLnS" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-6a38098734bso5070926a12.1 for ; Sun, 30 Aug 2026 22:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154397; cv=none; d=google.com; s=arc-20260327; b=X8GMcYWvCLU3DvHHQR9J64wYd4J6bwPJhq4j5MFNKTXLuoyGg7yx02UUo/7XxWvksY fpR0Ywvixg4EjFRx7tGinlXOL4qhSDMltb51dGTOKdOAQ5IsMAaPcWW1tfH7iWyRCY5r VI/yakb2pVF4jVP9WgD/h7JD0+PnOOHNhbjniJoCuc4AoNyN2aOz+cm8wLcGqdtHWmXh 9Jc9xlgB+pN+/yCDuwwWr0QuD2DbZlaCaelOkRIHtmhgzv5uS+hONWa6lEwkl4yL0myR SWFlbFFkJQ/vSnQ6ybPltmfUZpT/wWowpTqrApz8n5rWLjuG3LSR0O9r98OhRkbcpiHe y6Nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=+xPiXuwsOTRL3JNx7wAokgncqkI7ZPy08oFiV3kG4YI=; fh=5eCFbxnIYRzNy8MS8u6fJCRJOKTSyYZa72vr1uldRTk=; b=MCEgwi3GnsXQpbZqVmytP6SnFXX7Qzhntnqs4kYGzXjnXkNGyEauh9ZO+8N2gDk7L6 S9zKS9yuny6GX2nZO5YRhvlUUV4ImxO20caLbjQ3SSFtA7jLLO14/9srF96FAhcsoXGT ml7xsCzxL5Vfts9583ELEBK+2i21y0amu0XPY71OONx4RPgOunIG2EoOU/Zm98OFgmQ6 FkdcMF9eWHtPj6l0Zz8A2xDrPdwxjHY7bp8N+S0I0Fzx/750+TCX6jCYMPpZMj1O1CQr WGPknU7SUVDjdRidCxdq2aSA6KUD25gfRBI1FH2cHsBVUzBOQBSef+7z6XsaMFTdXBVx +owQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154397; x=1788759197; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=+xPiXuwsOTRL3JNx7wAokgncqkI7ZPy08oFiV3kG4YI=; b=UMNKoLnS/+C4TthKsGC3GGSVdorGNInpMlb/QzVAUVm5GHUKTeJ5JSGBuhGRenmMIe Sg3ahi987bzsAUzAXWZXrB/1nI0/l+MDwxkIwfAAAmjHyEVvCH/4OvVAvHgWORaSRf5K t7T35CxjvnSBmRoarNlHxKP8oJ9bzanzV6LH9bFUGIKO8HlyiYS0f+Zfz7rZLay4wgFH Q8r0W6g3gMRjjnKPTHRWb1Jr7UWi2aVrBD0g01y6F7szA9asBH3N1FLcnGUOYT6zKiqR uXGexcOlLuF8W2BhUUhSZJzr5by9UBUa3/xLdePjkiTwSP0JpMWeoQXHql6Xxxb/1wYD sbMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154397; x=1788759197; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=+xPiXuwsOTRL3JNx7wAokgncqkI7ZPy08oFiV3kG4YI=; b=flDZch1wY4I1BoFXSBax7TGYlg/8lFO3s82NPp/DI6aiArc34TsRa3aL1e+L/9U75l SNLD6eIFDAYowFdDLFW3H81mgCyufU2YrjWFBMPFHXYfd/PHsIOdjq35Z70YN1pNGMJw ewCwuUVkbIYhc0gN2vI32r5MQztHthoTzRrA1NIY2/pTpFbPKaz43DEwFCUsPN9nLOlJ Cyv4QhKYomfFu+H1SxMQuQMsHztJsxKj2V4SMvM+9gt6CJnii3ZoFeBELL4kuBnR+fcj W9pwXlG4LrAhaoIunVFMU699D/8Pru73U9Uwiclqdimf8VEuupZKGNNRO3PNEFCdfW1w +dLQ== X-Forwarded-Encrypted: i=1; AKwUvByGUpjeqchgmDgx1RADgliMK8sahieoQxWEQrmwwb6wqTM+MzNvX/8X946ZlgOBnmUGQRc0raz4eAUwJfU=@vger.kernel.org X-Gm-Message-State: AFuF++k5Z9KpPhFQEvjNQrDseV1OQsxQFkq4Ucs59ie3CmcBxL7V3RYR V+I2RQY0XQo8/NF7TsDPLL2cjmaF0D1nPQr5DvdR4R4vYPHFqcehjoJpTpEC+scTDE1pMpztxOJ fAtSa0UGUmFRje/TzTSgWBsQbYTThIiE= X-Gm-Gg: AYBFou0iCdevFKITl117fop/4ndfAz7GBnsVIfySL0EVzdqfWb0H8wq24mz6hk+6OKn 3UmLRwYxQonCVMAb2PNlz4tyMF67ugtxmq+eAdi4chRoWiguEnShUD6DqCl3UPF0Ljgz/85zuxn 2y+jNF/66F636VEuhJlRFd/RvN3czRmx7qc8hixsSyrA7KBrkX6MxHwHfDctFj4MYaw1dln4jci MUICuRJBmZ8yHpMokh/ak/a6nv+aE9bfOmC/+/E2B005RCQAAKx5P4H7KNi/PIu0hXCy9XQegSr J5+yR/OR45FdgsPT/eMh2FGESX5iyy3D1f9TFLflda14PgnQrQgoJabRB1I0FQA3xibAAoq7p8G dmw== X-Received: by 2002:a05:6402:4014:b0:6a0:a4f5:f4eb with SMTP id 4fb4d7f45d1cf-6a60d30c331mr15872158a12.4.1788154396469; Sun, 30 Aug 2026 22:33:16 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:15 +0200 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:15 +0200 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 07:33:15 +0200 X-Gm-Features: AcwNN1Xi69TmvUKHw4RqclQkOgl3ljPrxWH_zJOy2uEx04fHBpPpttoQwpAYPKo Message-ID: Subject: [PATCH v3 09/11] f2fs: parameterize byte and block conversion macros To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Byte-to-block and block-to-byte conversion helpers previously relied on global PAGE_SIZE, PAGE_SHIFT, or F2FS_BLKSIZE_BITS. Parameterize F2FS_BYTES_TO_BLK, F2FS_BLK_TO_BYTES, F2FS_BLK_END_BYTES, F2FS_BLK_ALIGN, and max_file_blocks with struct f2fs_sb_info *sbi using sbi->log_blocksize. Update all call sites across data mapping, file operations, fiemap queries, fsverity checks, NAT bitmap allocations, and truncate paths. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 2 +- fs/f2fs/data.c | 58 +++++++++++++++++++++++------------------ fs/f2fs/debug.c | 2 +- fs/f2fs/f2fs.h | 7 ++--- fs/f2fs/file.c | 54 +++++++++++++++++++++----------------- fs/f2fs/node.c | 7 ++--- fs/f2fs/recovery.c | 4 +-- fs/f2fs/segment.c | 9 ++++--- fs/f2fs/super.c | 9 ++++--- fs/f2fs/verity.c | 6 +++-- include/linux/f2fs_fs.h | 12 ++++++--- 11 files changed, 96 insertions(+), 74 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index 37a72b693545..d0dcc918422e 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -1866,7 +1866,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) blk =3D start_blk + BLKS_PER_SEG(sbi) - nm_i->nat_bits_blocks; for (i =3D 0; i < nm_i->nat_bits_blocks; i++) f2fs_update_meta_page(sbi, nm_i->nat_bits + - F2FS_BLK_TO_BYTES(i), blk + i); + F2FS_BLK_TO_BYTES(sbi, i), blk + i); } /* write out checkpoint buffer at block 0 */ diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 44e1ae43565e..6ee4440c17dd 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1977,12 +1977,12 @@ static bool __f2fs_overwrite_io(struct inode *inode, loff_t pos, size_t len, if (pos + len > i_size_read(inode)) return false; - map.m_lblk =3D F2FS_BYTES_TO_BLK(pos); + map.m_lblk =3D F2FS_BYTES_TO_BLK(F2FS_I_SB(inode), pos); map.m_next_pgofs =3D NULL; map.m_next_extent =3D NULL; map.m_seg_type =3D NO_CHECK_TYPE; map.m_may_create =3D false; - last_lblk =3D F2FS_BLK_ALIGN(pos + len); + last_lblk =3D F2FS_BLK_ALIGN(F2FS_I_SB(inode), pos + len); while (map.m_lblk < last_lblk) { map.m_len =3D last_lblk - map.m_lblk; @@ -2025,7 +2025,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, return err; } - phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); + phys =3D F2FS_BLK_TO_BYTES(sbi, ni.blk_addr); offset =3D offsetof(struct f2fs_inode, i_addr) + sizeof(__le32) * (DEF_ADDRS_PER_INODE_SBI(sbi) - get_inline_xattr_addrs(inode)); @@ -2059,7 +2059,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, return err; } - phys =3D F2FS_BLK_TO_BYTES(ni.blk_addr); + phys =3D F2FS_BLK_TO_BYTES(sbi, ni.blk_addr); len =3D inode->i_sb->s_blocksize; f2fs_folio_put(folio, true); @@ -2078,6 +2078,7 @@ static int f2fs_xattr_fiemap(struct inode *inode, int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, u64 start, u64 len) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct f2fs_map_blocks map; sector_t start_blk, last_blk, blk_len, max_len; pgoff_t next_pgofs; @@ -2101,7 +2102,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, inode_lock_shared(inode); - maxbytes =3D F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + maxbytes =3D F2FS_BLK_TO_BYTES(sbi, max_file_blocks(sbi, inode)); if (start > maxbytes) { ret =3D -EFBIG; goto out; @@ -2121,10 +2122,10 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, goto out; } - start_blk =3D F2FS_BYTES_TO_BLK(start); - last_blk =3D F2FS_BYTES_TO_BLK(start + len - 1); + start_blk =3D F2FS_BYTES_TO_BLK(sbi, start); + last_blk =3D F2FS_BYTES_TO_BLK(sbi, start + len - 1); blk_len =3D last_blk - start_blk + 1; - max_len =3D F2FS_BYTES_TO_BLK(maxbytes) - start_blk; + max_len =3D F2FS_BYTES_TO_BLK(sbi, maxbytes) - start_blk; next: memset(&map, 0, sizeof(map)); @@ -2146,7 +2147,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, if (!compr_cluster && !(map.m_flags & F2FS_MAP_FLAGS)) { start_blk =3D next_pgofs; - if (F2FS_BLK_TO_BYTES(start_blk) < maxbytes) + if (F2FS_BLK_TO_BYTES(sbi, start_blk) < maxbytes) goto prep_next; flags |=3D FIEMAP_EXTENT_LAST; @@ -2194,14 +2195,14 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, } else if (compr_appended) { unsigned int appended_blks =3D cluster_size - count_in_cluster + 1; - size +=3D F2FS_BLK_TO_BYTES(appended_blks); + size +=3D F2FS_BLK_TO_BYTES(sbi, appended_blks); start_blk +=3D appended_blks; compr_cluster =3D false; } else { - logical =3D F2FS_BLK_TO_BYTES(start_blk); + logical =3D F2FS_BLK_TO_BYTES(sbi, start_blk); phys =3D __is_valid_data_blkaddr(map.m_pblk) ? - F2FS_BLK_TO_BYTES(map.m_pblk) : 0; - size =3D F2FS_BLK_TO_BYTES(map.m_len); + F2FS_BLK_TO_BYTES(sbi, map.m_pblk) : 0; + size =3D F2FS_BLK_TO_BYTES(sbi, map.m_len); flags =3D 0; if (compr_cluster) { @@ -2215,7 +2216,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, flags =3D FIEMAP_EXTENT_UNWRITTEN; } - start_blk +=3D F2FS_BYTES_TO_BLK(size); + start_blk +=3D F2FS_BYTES_TO_BLK(sbi, size); } prep_next: @@ -2235,7 +2236,8 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, static inline loff_t f2fs_readpage_limit(struct inode *inode) { if (IS_ENABLED(CONFIG_FS_VERITY) && IS_VERITY(inode)) - return F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + return F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode)); return i_size_read(inode); } @@ -2263,7 +2265,8 @@ static int f2fs_read_single_page(struct inode *inode, struct fsverity_info *vi, block_in_file =3D (sector_t)index; last_block =3D block_in_file + nr_pages; - last_block_in_file =3D F2FS_BYTES_TO_BLK(f2fs_readpage_limit(inode) + + last_block_in_file =3D F2FS_BYTES_TO_BLK(F2FS_I_SB(inode), + f2fs_readpage_limit(inode) + blocksize - 1); if (last_block > last_block_in_file) last_block =3D last_block_in_file; @@ -2374,7 +2377,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, f2fs_bug_on(sbi, f2fs_cluster_is_empty(cc)); - last_block_in_file =3D F2FS_BYTES_TO_BLK(f2fs_readpage_limit(inode) + + last_block_in_file =3D F2FS_BYTES_TO_BLK(sbi, + f2fs_readpage_limit(inode) + blocksize - 1); /* get rid of pages beyond EOF */ @@ -4236,7 +4240,7 @@ static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) filemap_write_and_wait(mapping); /* Block number less than F2FS MAX BLOCKS */ - if (unlikely(block >=3D max_file_blocks(inode))) + if (unlikely(block >=3D max_file_blocks(F2FS_I_SB(inode), inode))) goto out; if (f2fs_compressed_file(inode)) { @@ -4352,7 +4356,7 @@ static int check_swap_activate(struct swap_info_struct *sis, * to be very smart. */ cur_lblock =3D 0; - last_lblock =3D F2FS_BYTES_TO_BLK(i_size_read(inode)); + last_lblock =3D F2FS_BYTES_TO_BLK(sbi, i_size_read(inode)); while (cur_lblock < last_lblock && cur_lblock < sis->max) { struct f2fs_map_blocks map; @@ -4607,12 +4611,14 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, unsigned int flags, struct iomap *iomap, struct iomap *srcmap) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); struct f2fs_map_blocks map =3D { NULL, }; pgoff_t next_pgofs =3D 0; int err; - map.m_lblk =3D F2FS_BYTES_TO_BLK(offset); - map.m_len =3D F2FS_BYTES_TO_BLK(offset + length - 1) - map.m_lblk + 1; + map.m_lblk =3D F2FS_BYTES_TO_BLK(sbi, offset); + map.m_len =3D F2FS_BYTES_TO_BLK(sbi, offset + length - 1) - + map.m_lblk + 1; map.m_next_pgofs =3D &next_pgofs; map.m_seg_type =3D f2fs_rw_hint_to_seg_type(F2FS_I_SB(inode), inode->i_write_hint); @@ -4633,7 +4639,7 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, if (err) return err; - iomap->offset =3D F2FS_BLK_TO_BYTES(map.m_lblk); + iomap->offset =3D F2FS_BLK_TO_BYTES(sbi, map.m_lblk); /* * When inline encryption is enabled, sometimes I/O to an encrypted file @@ -4653,11 +4659,11 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, if (WARN_ON_ONCE(map.m_pblk =3D=3D NEW_ADDR)) return -EINVAL; - iomap->length =3D F2FS_BLK_TO_BYTES(map.m_len); + iomap->length =3D F2FS_BLK_TO_BYTES(sbi, map.m_len); iomap->type =3D IOMAP_MAPPED; iomap->flags |=3D IOMAP_F_MERGED; iomap->bdev =3D map.m_bdev; - iomap->addr =3D F2FS_BLK_TO_BYTES(map.m_pblk); + iomap->addr =3D F2FS_BLK_TO_BYTES(sbi, map.m_pblk); if (flags & IOMAP_WRITE && map.m_last_pblk) iomap->private =3D (void *)map.m_last_pblk; @@ -4666,11 +4672,11 @@ static int f2fs_iomap_begin(struct inode *inode, loff_t offset, loff_t length, return -ENOTBLK; if (map.m_pblk =3D=3D NULL_ADDR) { - iomap->length =3D F2FS_BLK_TO_BYTES(next_pgofs) - + iomap->length =3D F2FS_BLK_TO_BYTES(sbi, next_pgofs) - iomap->offset; iomap->type =3D IOMAP_HOLE; } else if (map.m_pblk =3D=3D NEW_ADDR) { - iomap->length =3D F2FS_BLK_TO_BYTES(map.m_len); + iomap->length =3D F2FS_BLK_TO_BYTES(sbi, map.m_len); iomap->type =3D IOMAP_UNWRITTEN; } else { f2fs_bug_on(F2FS_I_SB(inode), 1); diff --git a/fs/f2fs/debug.c b/fs/f2fs/debug.c index 5980b9d79afb..a6cfceafe2fe 100644 --- a/fs/f2fs/debug.c +++ b/fs/f2fs/debug.c @@ -343,7 +343,7 @@ static void update_mem_info(struct f2fs_sb_info *sbi) /* build nm */ si->base_mem +=3D sizeof(struct f2fs_nm_info); si->base_mem +=3D __bitmap_size(sbi, NAT_BITMAP); - si->base_mem +=3D F2FS_BLK_TO_BYTES(NM_I(sbi)->nat_bits_blocks); + si->base_mem +=3D F2FS_BLK_TO_BYTES(sbi, NM_I(sbi)->nat_bits_blocks); si->base_mem +=3D NM_I(sbi)->nat_blocks * f2fs_bitmap_size(NAT_ENTRY_PER_BLOCK(sbi)); si->base_mem +=3D NM_I(sbi)->nat_blocks / 8; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index b90c5a42703f..c625a2572841 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -4016,7 +4016,7 @@ void f2fs_inode_synced(struct inode *inode); int f2fs_dquot_initialize(struct inode *inode); int f2fs_enable_quota_files(struct f2fs_sb_info *sbi, bool rdonly); int f2fs_do_quota_sync(struct super_block *sb, int type); -loff_t max_file_blocks(struct inode *inode); +loff_t max_file_blocks(struct f2fs_sb_info *sbi, struct inode *inode); void f2fs_quota_off_umount(struct super_block *sb); void f2fs_save_errors(struct f2fs_sb_info *sbi, unsigned char flag); void f2fs_handle_error(struct f2fs_sb_info *sbi, unsigned char error); @@ -5263,8 +5263,9 @@ static inline void f2fs_truncate_meta_inode_pages(struct f2fs_sb_info *sbi, NULL, 0, DATA); truncate_inode_pages_range(META_MAPPING(sbi), - F2FS_BLK_TO_BYTES((loff_t)blkaddr), - F2FS_BLK_END_BYTES((loff_t)(blkaddr + cnt - 1))); + F2FS_BLK_TO_BYTES(sbi, (loff_t)blkaddr), + F2FS_BLK_END_BYTES(sbi, + (loff_t)(blkaddr + cnt - 1))); } static inline void f2fs_invalidate_internal_cache(struct f2fs_sb_info *sbi, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 2c72e028cec2..6fafb32bc5f2 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -513,7 +513,8 @@ static bool __found_offset(struct address_space *mappin= g, static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) { struct inode *inode =3D file->f_mapping->host; - loff_t maxbytes =3D F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + loff_t maxbytes =3D F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode)); struct dnode_of_data dn; pgoff_t pgofs, end_offset; loff_t data_ofs =3D offset; @@ -537,9 +538,10 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) } } - pgofs =3D (pgoff_t)(offset >> PAGE_SHIFT); + pgofs =3D F2FS_BYTES_TO_BLK(F2FS_I_SB(inode), offset); - for (; data_ofs < isize; data_ofs =3D (loff_t)pgofs << PAGE_SHIFT) { + for (; data_ofs < isize; + data_ofs =3D F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), pgofs)) { set_new_dnode(&dn, inode, NULL, NULL, 0); err =3D f2fs_get_dnode_of_data(&dn, pgofs, LOOKUP_NODE); if (err && err !=3D -ENOENT) { @@ -559,7 +561,7 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) /* find data/hole in dnode block */ for (; dn.ofs_in_node < end_offset; dn.ofs_in_node++, pgofs++, - data_ofs =3D (loff_t)pgofs << PAGE_SHIFT) { + data_ofs =3D F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), pgofs)) { block_t blkaddr; blkaddr =3D f2fs_data_blkaddr(&dn); @@ -595,7 +597,8 @@ static loff_t f2fs_seek_block(struct file *file, loff_t offset, int whence) static loff_t f2fs_llseek(struct file *file, loff_t offset, int whence) { struct inode *inode =3D file->f_mapping->host; - loff_t maxbytes =3D F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + loff_t maxbytes =3D F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode)); switch (whence) { case SEEK_SET: @@ -846,9 +849,9 @@ int f2fs_do_truncate_blocks(struct inode *inode, u64 from, bool lock) goto out_err; } - free_from =3D (pgoff_t)F2FS_BLK_ALIGN(from); + free_from =3D (pgoff_t)F2FS_BLK_ALIGN(sbi, from); - if (free_from >=3D max_file_blocks(inode)) + if (free_from >=3D max_file_blocks(sbi, inode)) goto free_partial; if (lock) @@ -959,9 +962,10 @@ int f2fs_truncate_blocks(struct inode *inode, u64 from, bool lock) int f2fs_truncate(struct inode *inode) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); int err; - if (unlikely(f2fs_cp_error(F2FS_I_SB(inode)))) + if (unlikely(f2fs_cp_error(sbi))) return -EIO; if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || @@ -970,7 +974,7 @@ int f2fs_truncate(struct inode *inode) trace_f2fs_truncate(inode); - if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE)) + if (time_to_inject(sbi, FAULT_TRUNCATE)) return -EIO; err =3D f2fs_dquot_initialize(inode); @@ -986,8 +990,8 @@ int f2fs_truncate(struct inode *inode) * leak in evict() path. */ truncate_inode_pages_range(inode->i_mapping, - F2FS_BLK_TO_BYTES(0), - F2FS_BLK_END_BYTES(0)); + F2FS_BLK_TO_BYTES(sbi, 0), + F2FS_BLK_END_BYTES(sbi, 0)); return err; } } @@ -1161,7 +1165,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, return -EOPNOTSUPP; if (is_inode_flag_set(inode, FI_COMPRESS_RELEASED) && !IS_ALIGNED(attr->ia_size, - F2FS_BLK_TO_BYTES(fi->i_cluster_size))) + F2FS_BLK_TO_BYTES(sbi, fi->i_cluster_size))) return -EINVAL; if (f2fs_is_pinned_file(inode)) { @@ -1177,7 +1181,7 @@ int f2fs_setattr(struct mnt_idmap *idmap, struct dentry *dentry, * pinned file. */ else if (!IS_ALIGNED(attr->ia_size, - F2FS_BLK_TO_BYTES(CAP_BLKS_PER_SEC(sbi)))) + F2FS_BLK_TO_BYTES(sbi, CAP_BLKS_PER_SEC(sbi)))) return -EINVAL; } } @@ -2648,7 +2652,8 @@ static int f2fs_keep_noreuse_range(struct inode *inod= e, loff_t offset, loff_t len) { struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); - u64 max_bytes =3D F2FS_BLK_TO_BYTES(max_file_blocks(inode)); + u64 max_bytes =3D F2FS_BLK_TO_BYTES(sbi, + max_file_blocks(sbi, inode)); u64 start, end; int ret =3D 0; @@ -3191,8 +3196,8 @@ static int f2fs_ioc_defragment(struct file *filp, unsigned long arg) if (range.start & (F2FS_BLKSIZE - 1) || range.len & (F2FS_BLKSIZE - 1)) return -EINVAL; - if (unlikely((range.start + range.len) >> PAGE_SHIFT > - max_file_blocks(inode))) + if (unlikely(F2FS_BYTES_TO_BLK(sbi, range.start + range.len) > + max_file_blocks(sbi, inode))) return -EINVAL; err =3D mnt_want_write_file(filp); @@ -3326,9 +3331,9 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, } f2fs_lock_op(sbi, &lc); - ret =3D __exchange_data_block(src, dst, F2FS_BYTES_TO_BLK(pos_in), - F2FS_BYTES_TO_BLK(pos_out), - F2FS_BYTES_TO_BLK(len), false); + ret =3D __exchange_data_block(src, dst, F2FS_BYTES_TO_BLK(sbi, pos_in), + F2FS_BYTES_TO_BLK(sbi, pos_out), + F2FS_BYTES_TO_BLK(sbi, len), false); if (!ret) { if (dst_max_i_size) @@ -3994,7 +3999,7 @@ int f2fs_precache_extents(struct inode *inode) map.m_next_extent =3D &m_next_extent; map.m_seg_type =3D NO_CHECK_TYPE; map.m_may_create =3D false; - end =3D F2FS_BLK_ALIGN(i_size_read(inode)); + end =3D F2FS_BLK_ALIGN(F2FS_I_SB(inode), i_size_read(inode)); while (map.m_lblk < end) { map.m_len =3D end - map.m_lblk; @@ -4594,7 +4599,7 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) goto err; } - index =3D F2FS_BYTES_TO_BLK(range.start); + index =3D F2FS_BYTES_TO_BLK(sbi, range.start); pg_end =3D DIV_ROUND_UP(end_addr, F2FS_BLKSIZE); ret =3D f2fs_convert_inline_inode(inode); @@ -5385,7 +5390,8 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter, * buffered IO, if DIO meets any holes. */ if (dio && i_size_read(inode) && - (F2FS_BYTES_TO_BLK(pos) < F2FS_BLK_ALIGN(i_size_read(inode)))) + (F2FS_BYTES_TO_BLK(sbi, pos) < + F2FS_BLK_ALIGN(sbi, i_size_read(inode)))) return 0; /* No-wait I/O can't allocate blocks. */ @@ -5406,8 +5412,8 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *iter, } /* Do not preallocate blocks that will be written partially in 4KB. */ - map.m_lblk =3D F2FS_BLK_ALIGN(pos); - map.m_len =3D F2FS_BYTES_TO_BLK(pos + count); + map.m_lblk =3D F2FS_BLK_ALIGN(sbi, pos); + map.m_len =3D F2FS_BYTES_TO_BLK(sbi, pos + count); if (map.m_len > map.m_lblk) map.m_len -=3D map.m_lblk; else diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 7dabfada1b54..e7aa3b790214 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -3294,9 +3294,10 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sb= i) if (!enabled_nat_bits(sbi, NULL)) return 0; - nm_i->nat_bits_blocks =3D F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8); + nm_i->nat_bits_blocks =3D F2FS_BLK_ALIGN(sbi, + (nat_bits_bytes << 1) + 8); nm_i->nat_bits =3D f2fs_kvzalloc(sbi, - F2FS_BLK_TO_BYTES(nm_i->nat_bits_blocks), GFP_KERNEL); + F2FS_BLK_TO_BYTES(sbi, nm_i->nat_bits_blocks), GFP_KERNEL); if (!nm_i->nat_bits) return -ENOMEM; @@ -3309,7 +3310,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) if (IS_ERR(folio)) return PTR_ERR(folio); - memcpy(nm_i->nat_bits + F2FS_BLK_TO_BYTES(i), + memcpy(nm_i->nat_bits + F2FS_BLK_TO_BYTES(sbi, i), folio_address(folio), F2FS_BLKSIZE); f2fs_folio_put(folio, true); } diff --git a/fs/f2fs/recovery.c b/fs/f2fs/recovery.c index aaa5227739c8..b52718741ddc 100644 --- a/fs/f2fs/recovery.c +++ b/fs/f2fs/recovery.c @@ -734,9 +734,9 @@ static int do_recover_data(struct f2fs_sb_info *sbi, struct inode *inode, } if (!file_keep_isize(inode) && - (i_size_read(inode) <=3D ((loff_t)index << PAGE_SHIFT))) + (i_size_read(inode) <=3D F2FS_BLK_TO_BYTES(sbi, index))) f2fs_i_size_write(inode, - (loff_t)(index + 1) << PAGE_SHIFT); + F2FS_BLK_TO_BYTES(sbi, index + 1)); /* * dest is reserved block, invalidate src block diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index f565b6873832..f58b26c84b3a 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -3592,8 +3592,8 @@ static unsigned int __issue_discard_cmd_range(struct f2fs_sb_info *sbi, int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) { - __u64 start =3D F2FS_BYTES_TO_BLK(range->start); - __u64 end =3D start + F2FS_BYTES_TO_BLK(range->len) - 1; + __u64 start =3D F2FS_BYTES_TO_BLK(sbi, range->start); + __u64 end =3D start + F2FS_BYTES_TO_BLK(sbi, range->len) - 1; unsigned int start_segno, end_segno; block_t start_block, end_block; struct cp_control cpc; @@ -3624,7 +3624,8 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) } cpc.reason =3D CP_DISCARD; - cpc.trim_minlen =3D max_t(__u64, 1, F2FS_BYTES_TO_BLK(range->minlen)); + cpc.trim_minlen =3D max_t(__u64, 1, + F2FS_BYTES_TO_BLK(sbi, range->minlen)); cpc.trim_start =3D start_segno; cpc.trim_end =3D end_segno; @@ -3658,7 +3659,7 @@ int f2fs_trim_fs(struct f2fs_sb_info *sbi, struct fstrim_range *range) start_block, end_block); out: if (!err) - range->len =3D F2FS_BLK_TO_BYTES(trimmed); + range->len =3D F2FS_BLK_TO_BYTES(sbi, trimmed); return err; } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 46973207cd7b..b962c14cbcc1 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3884,7 +3884,7 @@ static const struct export_operations f2fs_export_ops= =3D { .get_parent =3D f2fs_get_parent, }; -loff_t max_file_blocks(struct inode *inode) +loff_t max_file_blocks(struct f2fs_sb_info *sbi, struct inode *inode) { loff_t result =3D 0; loff_t leaf_count; @@ -3918,7 +3918,8 @@ loff_t max_file_blocks(struct inode *inode) * fit within U32_MAX + 1 data units. */ - result =3D umin(result, F2FS_BYTES_TO_BLK(((loff_t)U32_MAX + 1) * 4096)); + result =3D umin(result, F2FS_BYTES_TO_BLK(sbi, + ((loff_t)U32_MAX + 1) * 4096)); return result; } @@ -4370,7 +4371,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi) nat_blocks =3D nat_segs << log_blocks_per_seg; nat_bits_bytes =3D nat_blocks / BITS_PER_BYTE; - nat_bits_blocks =3D F2FS_BLK_ALIGN((nat_bits_bytes << 1) + 8); + nat_bits_blocks =3D F2FS_BLK_ALIGN(sbi, (nat_bits_bytes << 1) + 8); if (__is_set_ckpt_flags(ckpt, CP_NAT_BITS_FLAG) && (cp_payload + F2FS_CP_PACKS + NR_CURSEG_PERSIST_TYPE + nat_bits_blocks >=3D blocks_per_seg)) { @@ -5193,7 +5194,7 @@ static int f2fs_fill_super(struct super_block *sb, struct fs_context *fc) if (err) goto free_options; - sb->s_maxbytes =3D max_file_blocks(NULL) << + sb->s_maxbytes =3D max_file_blocks(sbi, NULL) << le32_to_cpu(raw_super->log_blocksize); sb->s_max_links =3D F2FS_LINK_MAX; diff --git a/fs/f2fs/verity.c b/fs/f2fs/verity.c index 39f482515445..ee838f880c4a 100644 --- a/fs/f2fs/verity.c +++ b/fs/f2fs/verity.c @@ -75,7 +75,8 @@ static int pagecache_write(struct inode *inode, const void *buf, size_t count, struct address_space *mapping =3D inode->i_mapping; const struct address_space_operations *aops =3D mapping->a_ops; - if (pos + count > F2FS_BLK_TO_BYTES(max_file_blocks(inode))) + if (pos + count > F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode))) return -EFBIG; while (count) { @@ -239,7 +240,8 @@ static int f2fs_get_verity_descriptor(struct inode *inode, void *buf, /* Get the descriptor */ if (pos + size < pos || - pos + size > F2FS_BLK_TO_BYTES(max_file_blocks(inode)) || + pos + size > F2FS_BLK_TO_BYTES(F2FS_I_SB(inode), + max_file_blocks(F2FS_I_SB(inode), inode)) || pos < f2fs_verity_metadata_pos(inode) || size > INT_MAX) { f2fs_warn(F2FS_I_SB(inode), "invalid verity xattr"); f2fs_handle_error(F2FS_I_SB(inode), diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index f89609356be8..f622d26f37a7 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -28,10 +28,14 @@ #define COMPRESS_ADDR ((block_t)-2) /* used as compressed data flag */ #define F2FS_BLKSIZE_MASK (F2FS_BLKSIZE - 1) -#define F2FS_BYTES_TO_BLK(bytes) ((unsigned long long)(bytes) >> F2FS_BLKSIZE_BITS) -#define F2FS_BLK_TO_BYTES(blk) ((unsigned long long)(blk) << F2FS_BLKSIZE_BITS) -#define F2FS_BLK_END_BYTES(blk) (F2FS_BLK_TO_BYTES(blk + 1) - 1) -#define F2FS_BLK_ALIGN(x) (F2FS_BYTES_TO_BLK((x) + F2FS_BLKSIZE - 1)) +#define F2FS_BYTES_TO_BLK(sbi, bytes) \ + ((unsigned long long)(bytes) >> (sbi)->log_blocksize) +#define F2FS_BLK_TO_BYTES(sbi, blk) \ + ((unsigned long long)(blk) << (sbi)->log_blocksize) +#define F2FS_BLK_END_BYTES(sbi, blk) \ + (F2FS_BLK_TO_BYTES(sbi, (blk) + 1) - 1) +#define F2FS_BLK_ALIGN(sbi, x) \ + DIV_ROUND_UP_ULL((x), (sbi)->blocksize) /* 0, 1(node nid), 2(meta nid) are reserved node id */ #define F2FS_RESERVED_NODE_NUM 3 --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CCA1A3AFAFF for ; Mon, 31 Aug 2026 05:33:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.49 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154404; cv=pass; b=YQaD4X20LAPFDlTNiyh1RPGW00o+TscJGRZSQx+b5zcNEcQpdC+3M4aNARBPNGhqXrsWAehjK+CHs4jbiA9ykGRLa1tkRWKzin66gg4pv3PQw8aMUdmbXAbML4gi3VKXNrA25hypFh7x7tH5GBCKF+dAVHfCaslDBP4yAqFpyHQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154404; c=relaxed/simple; bh=oWDDGVo9/ixUJbCUqClZMUKQtzlC1BY4zNmUi/W6+v8=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=dEth0djKI0WpPYujvy9iMYujCTOYBO+1BEuC3ENXuD/9NQPyjJ/z/+nsqW9sHsJfNPJp9vWvT5099yogpdpFHDBQEUfHiY+LxqK8Lw7moDP4XSKgZtIDNjnufylTt9xlVOZCKzMkCtzGVawcYZiSM4gJZdVFieqILoxc3S9Ptjo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d0txFg3B; arc=pass smtp.client-ip=209.85.208.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d0txFg3B" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-6a38098734bso5070993a12.1 for ; Sun, 30 Aug 2026 22:33:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154400; cv=none; d=google.com; s=arc-20260327; b=fhDHWwEGiLp5lATxJ2fKIjEgBzGLS2AW5hDQKK18sG/YaP99hyvy3djPuTaOBs2Htg nVoMn+MWe3z266ImLsxPPiUN2OIoII9yqj/Nuj+vRuLlZ6pd/94wh+vWzhu+aSqs+JNt QdCiWJbp7J8oO/SND8zGOXJX8nc+rYZf5GuBOWQugU9fdjstPAu2bYHng4z9vb+6NLCN +z5L3GBsFt/EGFOkbv8mQruNBV3xX5G7jEvARpjTXDc4qRrF2b+ReKig3fDZj07mkMNU 5Atcuxol+w3JX+jcyj0chxT7QVcES7gbi0lhQmpRxGk/BL4/VOjy/gDURu7TBgyn7D/s euvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=sShZ/p9JhAyJtYlCQ6JBaxq71U2kKKsBw7SA3hikdnY=; fh=g+I9Hw+GbcGGbrCaj2ejaOrG/t/gS8AOk0Ok7dcxM+U=; b=Zh2EWVBli1xplCPIcnilfpPU88/SzdNO/UsE4zsFHoRIOFXVUkYyJ45uDlK2uybIDG z0QqHiar8UN2HSpw4cK2X821DKy1BFIIuQ3hoDmCq2F7ExMwtd1/4QsPyj0jk/j/Ytct oO9Pksi7HK91jR1LyvYG6wDe6rXCGgUvYRceYU9SF/z13OSiHVBnuWtZ8A90B2Vm75oQ NOMlNUhmrkpLrA6EGGvtXUhgAYPzwyZYJMvwjH/fo9eYusb+Ia9DL12ilxLTzYQsoA3E e8+KWv8WB/ngsO7b8n8CVMYaSwbeBzpIlI21bRvRdtDuLBfPwrcWvAh0r35SEhCWKpbv q4IA==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154400; x=1788759200; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=sShZ/p9JhAyJtYlCQ6JBaxq71U2kKKsBw7SA3hikdnY=; b=d0txFg3BbMh4PrYtzM79pb6/MoZ0T6VAkxKFAbdwAVVawDIg7FBqxCxFHMARxsZwg2 3JA9tChnfSt3B1TuWJRvkXTYlGDG2gMLRKA5QjaIl+ol54TleANbqDae38O6UIv4GzcI M4BuVy7pty8VrdZKzt8kWtGRQdZ1XA0DUBSsCiKn9gkZ2tb3LwB5KYQ18k6eUPdAkqOJ w00PNsgyZiNDol1rC6WZ2iX0PlAzomEZT+kSWbHz3a9fS+Gnu4rzy/MNxhD9Sywm0NGy seQb1wzoDPXjdSYNJZ4vrwf7J9jFbORLxh62p6jeuKzS6A/eAqAR2pPh719oa8I7oWgU 6dKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154400; x=1788759200; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=sShZ/p9JhAyJtYlCQ6JBaxq71U2kKKsBw7SA3hikdnY=; b=jS2W/Ui2hmUdWRikszhyd5/l45qW/n0JrgkwJhxYKj+/D5OVWYsscD2bPbvjEe9Cbn W7/ECi9T1stfXu4LO36QSu8Ej+iByf1LbRylcHCmBRQ/UF0bCfu2L4MpFcpf0n5hdUch v5q0Fzo7RcDleklDBJ3O4E6EESsK9BenFhjsi9dhBp81pWRb0c96ErnmLqzWy7ki//+8 P1XEVn5xm5JtuCRkRzBV4Ccxxd2zJh+Y6GYZQud2Np5RgseqCHrHw2y3s4kVGJJFXTeg Rso2vflB6TpjZJnAjI0rwNcUCaHQZb01h4nOjq5ACWedSqBpiSAuEy7EBtbEiesjs85s qKIw== X-Forwarded-Encrypted: i=1; AKwUvBzLQpXbBPKLku6FtooYe4YlRHQ89ku4lbe7kPVjAGxadKQHIhJrS3ygOP+nFQrm9ZTDsHVL7ZVNwJqwVFM=@vger.kernel.org X-Gm-Message-State: AFuF++l8xSiDtiNr35uYhssekVZ/JVXGZeVc6MUZeNET5j7CBp9KVhWd gNOGyP2MAj5a5Cna13qYPRd0X3z6ZTIF1K6dwWReDJPVeadwXBdxLNeRgRYKrbzy9G9tUexS6Qg ijVYt0hd5mSRF8aSuHMdG3B+PiNghWIvo0RxTY1I= X-Gm-Gg: AYBFou0dHDKJC4Rwid1xo+dZX5Ht85ewxwv2mexYbWe3xdvZuiXktJ3GGF4KrcD3+OU sgiTMELk/uSGbLT2k7NkrH0ISTtVq5d40LPW1XY6Eu4dyP1poKJ+Vuj6F2llOqUfnvOlJlUVkey 9JapYsO8Y8qPIKdFV9n1kJOC5n9fxWOd3Ou4pBW1GB+JJYUGI27u6MNAzrQQEPtS1brCySdY6di ueiqpah8NfQ3S+x0FXLqbVoDYwRCyqNVB6+c8Rj+j7OdXiifxQoX4ymmuMY4SpyiNXlUXn+fxC1 OqZmk6f/LQMMWMmFpC0k6nmsHWj8xG6Fg+qUMBAgnBEBUhe/IOR7syq1JjeVnZCwKDyz5x6E1aH /Rw== X-Received: by 2002:a05:6402:510c:b0:69c:811f:8f5 with SMTP id 4fb4d7f45d1cf-6a60d32f3ecmr12406765a12.6.1788154399807; Sun, 30 Aug 2026 22:33:19 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:18 +0200 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:18 +0200 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 07:33:18 +0200 X-Gm-Features: AcwNN1UuNdyjNqRYwsvLtaXsLpDOIKAL_ipaefzEhYQCTMkQRaXo2k1fckqS2s0 Message-ID: Subject: [PATCH v3 10/11] f2fs: parameterize block size and mask macros To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Block size constants, shift counts, masks, and page-to-block ratios were globally defined assuming a fixed 4KB block size. Parameterize F2FS_BLKSIZE, F2FS_BLKSIZE_BITS, F2FS_BLKSIZE_MASK, F2FS_BLKS_PER_PAGE, and CP_CHKSUM_OFFSET with struct f2fs_sb_info *sbi to reference sbi->blocksize, sbi->log_blocksize, and runtime masks. Update call sites across metadata operations, data I/O, file operations, garbage collection, inline data, and sysfs information. Signed-off-by: Kelvin Zhang --- fs/f2fs/checkpoint.c | 23 ++++++++++++----------- fs/f2fs/data.c | 25 ++++++++++++++----------- fs/f2fs/extent_cache.c | 6 ++++-- fs/f2fs/f2fs.h | 15 +++++++++++---- fs/f2fs/file.c | 30 +++++++++++++++++------------- fs/f2fs/gc.c | 11 ++++++----- fs/f2fs/inline.c | 6 +++--- fs/f2fs/inode.c | 4 ++-- fs/f2fs/node.c | 7 ++++--- fs/f2fs/node.h | 2 +- fs/f2fs/segment.c | 18 +++++++++++------- fs/f2fs/segment.h | 4 ++-- fs/f2fs/super.c | 6 +++--- fs/f2fs/sysfs.c | 10 +++++----- fs/f2fs/xattr.c | 2 +- include/linux/f2fs_fs.h | 22 +++++++++++----------- 16 files changed, 107 insertions(+), 84 deletions(-) diff --git a/fs/f2fs/checkpoint.c b/fs/f2fs/checkpoint.c index d0dcc918422e..015c7449e45a 100644 --- a/fs/f2fs/checkpoint.c +++ b/fs/f2fs/checkpoint.c @@ -288,7 +288,7 @@ static struct folio *__get_meta_folio(struct f2fs_sb_info *sbi, pgoff_t index, return ERR_PTR(err); } - f2fs_update_iostat(sbi, NULL, FS_META_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, FS_META_READ_IO, F2FS_BLKSIZE(sbi)); folio_lock(folio); if (unlikely(!is_meta_folio(folio))) { @@ -513,7 +513,7 @@ int f2fs_ra_meta_pages(struct f2fs_sb_info *sbi, block_t start, int nrpages, if (!err) f2fs_update_iostat(sbi, NULL, FS_META_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(sbi)); } out: blk_finish_plug(&plug); @@ -1141,16 +1141,17 @@ static void write_orphan_inodes(struct f2fs_sb_info *sbi, block_t start_blk) } } -static __u32 f2fs_checkpoint_chksum(struct f2fs_checkpoint *ckpt) +static __u32 f2fs_checkpoint_chksum(struct f2fs_sb_info *sbi, + struct f2fs_checkpoint *ckpt) { unsigned int chksum_ofs =3D le32_to_cpu(ckpt->checksum_offset); __u32 chksum; chksum =3D f2fs_crc32(ckpt, chksum_ofs); - if (chksum_ofs < CP_CHKSUM_OFFSET) { + if (chksum_ofs < CP_CHKSUM_OFFSET(sbi)) { chksum_ofs +=3D sizeof(chksum); chksum =3D f2fs_chksum(chksum, (__u8 *)ckpt + chksum_ofs, - F2FS_BLKSIZE - chksum_ofs); + F2FS_BLKSIZE(sbi) - chksum_ofs); } return chksum; } @@ -1170,13 +1171,13 @@ static int get_checkpoint_version(struct f2fs_sb_info *sbi, block_t cp_addr, crc_offset =3D le32_to_cpu((*cp_block)->checksum_offset); if (crc_offset < CP_MIN_CHKSUM_OFFSET || - crc_offset > CP_CHKSUM_OFFSET) { + crc_offset > CP_CHKSUM_OFFSET(sbi)) { f2fs_folio_put(*cp_folio, true); f2fs_warn(sbi, "invalid crc_offset: %zu", crc_offset); return -EINVAL; } - crc =3D f2fs_checkpoint_chksum(*cp_block); + crc =3D f2fs_checkpoint_chksum(sbi, *cp_block); if (crc !=3D cur_cp_crc(*cp_block)) { f2fs_folio_put(*cp_folio, true); f2fs_warn(sbi, "invalid crc value"); @@ -1713,7 +1714,7 @@ static void commit_checkpoint(struct f2fs_sb_info *sb= i, */ struct folio *folio =3D f2fs_grab_meta_folio(sbi, blk_addr); - memcpy(folio_address(folio), src, PAGE_SIZE); + memcpy(folio_address(folio), src, F2FS_BLKSIZE(sbi)); folio_mark_dirty(folio); if (unlikely(!folio_clear_dirty_for_io(folio))) @@ -1848,7 +1849,7 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) get_sit_bitmap(sbi, __bitmap_ptr(sbi, SIT_BITMAP)); get_nat_bitmap(sbi, __bitmap_ptr(sbi, NAT_BITMAP)); - crc32 =3D f2fs_checkpoint_chksum(ckpt); + crc32 =3D f2fs_checkpoint_chksum(sbi, ckpt); *((__le32 *)((unsigned char *)ckpt + le32_to_cpu(ckpt->checksum_offset))) =3D cpu_to_le32(crc32); @@ -1873,8 +1874,8 @@ static int do_checkpoint(struct f2fs_sb_info *sbi, struct cp_control *cpc) f2fs_update_meta_page(sbi, ckpt, start_blk++); for (i =3D 1; i < 1 + cp_payload_blks; i++) - f2fs_update_meta_page(sbi, (char *)ckpt + i * F2FS_BLKSIZE, - start_blk++); + f2fs_update_meta_page(sbi, (char *)ckpt + + i * F2FS_BLKSIZE(sbi), start_blk++); if (orphan_num) { write_orphan_inodes(sbi, start_blk); diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 6ee4440c17dd..d7b22eaa746e 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1227,7 +1227,7 @@ static void f2fs_submit_page_read(struct inode *inode, struct fsverity_info *vi, f2fs_bug_on(sbi, 1); inc_page_count(sbi, F2FS_RD_DATA); - f2fs_update_iostat(sbi, NULL, FS_DATA_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, FS_DATA_READ_IO, F2FS_BLKSIZE(sbi)); f2fs_submit_read_bio(sbi, bio, DATA); } @@ -2210,7 +2210,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, count_in_cluster +=3D map.m_len; if (count_in_cluster =3D=3D cluster_size) { compr_cluster =3D false; - size +=3D F2FS_BLKSIZE; + size +=3D F2FS_BLKSIZE(sbi); } } else if (map.m_flags & F2FS_MAP_DELALLOC) { flags =3D FIEMAP_EXTENT_UNWRITTEN; @@ -2255,7 +2255,7 @@ static int f2fs_read_single_page(struct inode *inode, struct fsverity_info *vi, struct readahead_control *rac) { struct bio *bio =3D *bio_ret; - const unsigned int blocksize =3D F2FS_BLKSIZE; + const unsigned int blocksize =3D F2FS_BLKSIZE(F2FS_I_SB(inode)); sector_t block_in_file; sector_t last_block; sector_t last_block_in_file; @@ -2344,7 +2344,7 @@ static int f2fs_read_single_page(struct inode *inode, struct fsverity_info *vi, inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA); f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(F2FS_I_SB(inode))); *last_block_in_bio =3D block_nr; out: *bio_ret =3D bio; @@ -2362,7 +2362,7 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, struct bio *bio =3D *bio_ret; unsigned int start_idx =3D cc->cluster_idx << cc->log_cluster_size; sector_t last_block_in_file; - const unsigned int blocksize =3D F2FS_BLKSIZE; + const unsigned int blocksize =3D F2FS_BLKSIZE(sbi); struct decompress_io_ctx *dic =3D NULL; struct extent_info ei =3D {}; bool from_dnode =3D true; @@ -2495,7 +2495,8 @@ int f2fs_read_multi_pages(struct compress_ctx *cc, struct bio **bio_ret, refcount_inc(&dic->refcnt); inc_page_count(sbi, F2FS_RD_DATA); - f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, + F2FS_BLKSIZE(sbi)); *last_block_in_bio =3D blkaddr; } @@ -2669,14 +2670,14 @@ static int f2fs_read_data_large_folio(struct inode *inode, */ f2fs_wait_on_block_writeback(inode, block_nr); - if (!bio_add_folio(bio, folio, F2FS_BLKSIZE, - offset << PAGE_SHIFT)) + if (!bio_add_folio(bio, folio, F2FS_BLKSIZE(F2FS_I_SB(inode)), + offset << PAGE_SHIFT)) goto submit_and_realloc; folio_in_bio =3D true; inc_page_count(F2FS_I_SB(inode), F2FS_RD_DATA); f2fs_update_iostat(F2FS_I_SB(inode), NULL, FS_DATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(F2FS_I_SB(inode))); last_block_in_bio =3D block_nr; } trace_f2fs_read_folio(folio, DATA); @@ -4230,6 +4231,7 @@ static sector_t f2fs_bmap_compress(struct inode *inode, sector_t block) static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) { struct inode *inode =3D mapping->host; + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); sector_t blknr =3D 0; if (f2fs_has_inline_data(inode)) @@ -4240,7 +4242,7 @@ static sector_t f2fs_bmap(struct address_space *mapping, sector_t block) filemap_write_and_wait(mapping); /* Block number less than F2FS MAX BLOCKS */ - if (unlikely(block >=3D max_file_blocks(F2FS_I_SB(inode), inode))) + if (unlikely(block >=3D max_file_blocks(sbi, inode))) goto out; if (f2fs_compressed_file(inode)) { @@ -4442,7 +4444,8 @@ static int check_swap_activate(struct swap_info_struct *sis, out: if (not_aligned) f2fs_warn(sbi, "Swapfile (%u) is not align to section: 1) creat(), 2) ioctl(F2FS_IOC_SET_PIN_FILE), 3) fallocate(%lu * N)", - not_aligned, blks_per_sec * F2FS_BLKSIZE); + not_aligned, + (unsigned long)blks_per_sec * F2FS_BLKSIZE(sbi)); return ret; } diff --git a/fs/f2fs/extent_cache.c b/fs/f2fs/extent_cache.c index 37cf9fa8d537..2d3fdd82b13d 100644 --- a/fs/f2fs/extent_cache.c +++ b/fs/f2fs/extent_cache.c @@ -904,11 +904,13 @@ static int __get_new_block_age(struct inode *inode, struct extent_info *ei, struct extent_info tei =3D *ei; /* only fofs and len are valid */ /* - * When I/O is not aligned to a PAGE_SIZE, update will happen to the last + * When I/O is not aligned to the filesystem block size, update will + * happen to the last * file block even in seq write. So don't record age for newly last file * block here. */ - if ((f_size >> PAGE_SHIFT) =3D=3D ei->fofs && f_size & (PAGE_SIZE - 1) && + if ((f_size >> sbi->log_blocksize) =3D=3D ei->fofs && + f_size & F2FS_BLKSIZE_MASK(sbi) && blkaddr =3D=3D NEW_ADDR) return -EINVAL; diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index c625a2572841..f83cdab66f54 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -2234,7 +2234,7 @@ static inline struct f2fs_sb_info *F2FS_SB(struct super_block *sb) return sb->s_fs_info; } -static inline struct f2fs_sb_info *F2FS_I_SB(struct inode *inode) +static inline struct f2fs_sb_info *F2FS_I_SB(const struct inode *inode) { return F2FS_SB(inode->i_sb); } @@ -2249,12 +2249,18 @@ static inline struct f2fs_sb_info *F2FS_F_SB(const struct folio *folio) return F2FS_M_SB(folio->mapping); } +static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) +{ + return F2FS_F_SB(page_folio(page)); +} + #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) #define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) #define DEF_ADDRS_PER_INODE_SBI(sbi) ((sbi)->addrs_per_inode) #define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) #define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) +#define CP_CHKSUM_OFFSET(sbi) (F2FS_BLKSIZE(sbi) - sizeof(__le32)) static inline struct f2fs_orphan_footer * f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) @@ -2303,7 +2309,7 @@ static inline struct f2fs_checkpoint *F2FS_CKPT(struct f2fs_sb_info *sbi) static inline struct node_footer *F2FS_NODE_FOOTER(const struct folio *fol= io) { - return folio_address(folio) + F2FS_BLKSIZE - + return folio_address(folio) + F2FS_BLKSIZE(F2FS_F_SB(folio)) - sizeof(struct node_footer); } @@ -2319,7 +2325,8 @@ static inline struct f2fs_inode *F2FS_INODE(const struct folio *folio) static inline __le32 *F2FS_INODE_NIDS(const struct folio *folio) { - return folio_address(folio) + F2FS_BLKSIZE - sizeof(struct node_footer) - + return folio_address(folio) + F2FS_BLKSIZE(F2FS_F_SB(folio)) - + sizeof(struct node_footer) - SIZE_OF_I_NID; } @@ -2968,7 +2975,7 @@ static inline void *__bitmap_ptr(struct f2fs_sb_info *sbi, int flag) if (flag =3D=3D NAT_BITMAP) return tmp_ptr; else - return (unsigned char *)ckpt + F2FS_BLKSIZE; + return (unsigned char *)ckpt + F2FS_BLKSIZE(sbi); } else { offset =3D (flag =3D=3D NAT_BITMAP) ? le32_to_cpu(ckpt->sit_ver_bitmap_bytesize) : 0; diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 6fafb32bc5f2..7001c18da506 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -110,7 +110,8 @@ static vm_fault_t f2fs_filemap_fault(struct vm_fault *v= mf) ret =3D filemap_fault(vmf); if (ret & VM_FAULT_LOCKED) f2fs_update_iostat(F2FS_I_SB(inode), inode, - APP_MAPPED_READ_IO, F2FS_BLKSIZE); + APP_MAPPED_READ_IO, + F2FS_BLKSIZE(F2FS_I_SB(inode))); trace_f2fs_filemap_fault(inode, vmf->pgoff, flags, ret); @@ -233,7 +234,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault = *vmf) } folio_mark_dirty(folio); - f2fs_update_iostat(sbi, inode, APP_MAPPED_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, inode, APP_MAPPED_IO, F2FS_BLKSIZE(sbi)); f2fs_update_time(sbi, REQ_TIME); out_sem: @@ -974,7 +975,7 @@ int f2fs_truncate(struct inode *inode) trace_f2fs_truncate(inode); - if (time_to_inject(sbi, FAULT_TRUNCATE)) + if (time_to_inject(F2FS_I_SB(inode), FAULT_TRUNCATE)) return -EIO; err =3D f2fs_dquot_initialize(inode); @@ -1675,7 +1676,8 @@ static int f2fs_collapse_range(struct inode *inode, loff_t offset, loff_t len) return -EINVAL; /* collapse range should be aligned to block size of f2fs. */ - if (offset & (F2FS_BLKSIZE - 1) || len & (F2FS_BLKSIZE - 1)) + if (offset & F2FS_BLKSIZE_MASK(F2FS_I_SB(inode)) || + len & F2FS_BLKSIZE_MASK(F2FS_I_SB(inode))) return -EINVAL; ret =3D f2fs_convert_inline_inode(inode); @@ -1890,7 +1892,8 @@ static int f2fs_insert_range(struct inode *inode, loff_t offset, loff_t len) return -EINVAL; /* insert range should be aligned to block size of f2fs. */ - if (offset & (F2FS_BLKSIZE - 1) || len & (F2FS_BLKSIZE - 1)) + if (offset & F2FS_BLKSIZE_MASK(F2FS_I_SB(inode)) || + len & F2FS_BLKSIZE_MASK(F2FS_I_SB(inode))) return -EINVAL; ret =3D f2fs_convert_inline_inode(inode); @@ -3193,7 +3196,8 @@ static int f2fs_ioc_defragment(struct file *filp, unsigned long arg) return -EFAULT; /* verify alignment of offset & size */ - if (range.start & (F2FS_BLKSIZE - 1) || range.len & (F2FS_BLKSIZE - 1)) + if (range.start & F2FS_BLKSIZE_MASK(sbi) || + range.len & F2FS_BLKSIZE_MASK(sbi)) return -EINVAL; if (unlikely(F2FS_BYTES_TO_BLK(sbi, range.start + range.len) > @@ -3279,7 +3283,7 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, if (src =3D=3D dst && pos_out > pos_in && pos_out < pos_in + len) goto out_unlock; if (pos_in + len =3D=3D src->i_size) - len =3D ALIGN(src->i_size, F2FS_BLKSIZE) - pos_in; + len =3D ALIGN(src->i_size, F2FS_BLKSIZE(sbi)) - pos_in; if (len =3D=3D 0) { ret =3D 0; goto out_unlock; @@ -3297,9 +3301,9 @@ static int f2fs_move_file_range(struct file *file_in, loff_t pos_in, } /* verify the end result is block aligned */ - if (!IS_ALIGNED(pos_in, F2FS_BLKSIZE) || - !IS_ALIGNED(pos_in + len, F2FS_BLKSIZE) || - !IS_ALIGNED(pos_out, F2FS_BLKSIZE)) + if (!IS_ALIGNED(pos_in, F2FS_BLKSIZE(sbi)) || + !IS_ALIGNED(pos_in + len, F2FS_BLKSIZE(sbi)) || + !IS_ALIGNED(pos_out, F2FS_BLKSIZE(sbi))) goto out_unlock; ret =3D f2fs_convert_inline_inode(src); @@ -4593,14 +4597,14 @@ static int f2fs_sec_trim_file(struct file *filp, unsigned long arg) to_end =3D true; } - if (!IS_ALIGNED(range.start, F2FS_BLKSIZE) || - (!to_end && !IS_ALIGNED(end_addr, F2FS_BLKSIZE))) { + if (!IS_ALIGNED(range.start, F2FS_BLKSIZE(sbi)) || + (!to_end && !IS_ALIGNED(end_addr, F2FS_BLKSIZE(sbi)))) { ret =3D -EINVAL; goto err; } index =3D F2FS_BYTES_TO_BLK(sbi, range.start); - pg_end =3D DIV_ROUND_UP(end_addr, F2FS_BLKSIZE); + pg_end =3D F2FS_BLK_ALIGN(sbi, end_addr); ret =3D f2fs_convert_inline_inode(inode); if (ret) diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index f15ab07a7347..299d5310e597 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1303,8 +1303,8 @@ static int ra_data_block(struct inode *inode, pgoff_t index) f2fs_put_page(fio.encrypted_page, false); f2fs_folio_put(folio, true); - f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE); - f2fs_update_iostat(sbi, NULL, FS_GDATA_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, inode, FS_DATA_READ_IO, F2FS_BLKSIZE(sbi)); + f2fs_update_iostat(sbi, NULL, FS_GDATA_READ_IO, F2FS_BLKSIZE(sbi)); if (atomic_inode) iput(atomic_inode); @@ -1424,9 +1424,9 @@ static int move_data_block(struct inode *inode, block_t bidx, } f2fs_update_iostat(fio.sbi, inode, FS_DATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(fio.sbi)); f2fs_update_iostat(fio.sbi, NULL, FS_GDATA_READ_IO, - F2FS_BLKSIZE); + F2FS_BLKSIZE(fio.sbi)); folio_lock(mfolio); if (unlikely(!is_meta_folio(mfolio) || @@ -1477,7 +1477,8 @@ static int move_data_block(struct inode *inode, block_t bidx, fio.new_blkaddr =3D newaddr; f2fs_submit_page_write(&fio); - f2fs_update_iostat(fio.sbi, NULL, FS_GC_DATA_IO, F2FS_BLKSIZE); + f2fs_update_iostat(fio.sbi, NULL, FS_GC_DATA_IO, + F2FS_BLKSIZE(fio.sbi)); f2fs_update_data_blkaddr(&dn, newaddr); set_inode_flag(inode, FI_APPEND_WRITE); diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 73cd9b6ddcc5..3e0b9449ffba 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -448,7 +448,7 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio, * Start by zeroing the full block, to ensure that all unused space is * zeroed and no uninitialized memory is leaked to disk. */ - memset(dentry_blk, 0, F2FS_BLKSIZE); + memset(dentry_blk, 0, F2FS_BLKSIZE(F2FS_I_SB(dir))); make_dentry_ptr_inline(dir, &src, inline_dentry); make_dentry_ptr_block(dir, &dst, dentry_blk); @@ -477,8 +477,8 @@ static int f2fs_move_inline_dirents(struct inode *dir, struct folio *ifolio, F2FS_I(dir)->i_inline_xattr_size =3D 0; f2fs_i_depth_write(dir, 1); - if (i_size_read(dir) < PAGE_SIZE) - f2fs_i_size_write(dir, PAGE_SIZE); + if (i_size_read(dir) < F2FS_BLKSIZE(F2FS_I_SB(dir))) + f2fs_i_size_write(dir, F2FS_BLKSIZE(F2FS_I_SB(dir))); out: f2fs_folio_put(folio, true); return err; diff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c index b628fdc4198f..b947b724b3bc 100644 --- a/fs/f2fs/inode.c +++ b/fs/f2fs/inode.c @@ -165,7 +165,7 @@ static __u32 f2fs_inode_chksum(struct f2fs_sb_info *sbi, struct folio *folio) chksum =3D f2fs_chksum(chksum, (__u8 *)&dummy_cs, cs_size); offset +=3D cs_size; chksum =3D f2fs_chksum(chksum, (__u8 *)ri + offset, - F2FS_BLKSIZE - offset); + F2FS_BLKSIZE(sbi) - offset); return chksum; } @@ -447,7 +447,7 @@ static int do_read_inode(struct inode *inode) set_nlink(inode, le32_to_cpu(ri->i_links)); inode->i_size =3D le64_to_cpu(ri->i_size); inode->i_blocks =3D SECTOR_FROM_BLOCK(sbi, - le64_to_cpu(ri->i_blocks) - 1); + le64_to_cpu(ri->i_blocks) - 1); inode_set_atime(inode, le64_to_cpu(ri->i_atime), le32_to_cpu(ri->i_atime_nsec)); diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index e7aa3b790214..8d16715a3aae 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -165,7 +165,7 @@ static struct folio *get_next_nat_folio(struct f2fs_sb_info *sbi, nid_t nid) src_addr =3D folio_address(src_folio); dst_addr =3D folio_address(dst_folio); - memcpy(dst_addr, src_addr, PAGE_SIZE); + memcpy(dst_addr, src_addr, F2FS_BLKSIZE(sbi)); folio_mark_dirty(dst_folio); f2fs_folio_put(src_folio, true); @@ -1498,7 +1498,8 @@ static int read_node_folio(struct folio *folio, blk_opf_t op_flags) err =3D f2fs_submit_page_bio(&fio); if (!err) - f2fs_update_iostat(sbi, NULL, FS_NODE_READ_IO, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, FS_NODE_READ_IO, + F2FS_BLKSIZE(sbi)); return err; } @@ -3311,7 +3312,7 @@ static int __get_nat_bitmaps(struct f2fs_sb_info *sbi) return PTR_ERR(folio); memcpy(nm_i->nat_bits + F2FS_BLK_TO_BYTES(sbi, i), - folio_address(folio), F2FS_BLKSIZE); + folio_address(folio), F2FS_BLKSIZE(sbi)); f2fs_folio_put(folio, true); } diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 6a2b7c63f4a3..32125f8fc753 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -284,7 +284,7 @@ static inline void fill_node_footer(const struct folio *folio, nid_t nid, unsigned int old_flag =3D 0; if (reset) - memset(rn, 0, F2FS_BLKSIZE); + memset(rn, 0, F2FS_BLKSIZE(F2FS_F_SB(folio))); else old_flag =3D le32_to_cpu(footer->flag); diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index f58b26c84b3a..f2641a6080ae 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -1316,7 +1316,8 @@ static void __submit_zone_reset_cmd(struct f2fs_sb_info *sbi, submit_bio(bio); atomic_inc(&dcc->issued_discard); - f2fs_update_iostat(sbi, NULL, FS_ZONE_RESET_IO, dc->di.len * F2FS_BLKSIZE= ); + f2fs_update_iostat(sbi, NULL, FS_ZONE_RESET_IO, + dc->di.len * F2FS_BLKSIZE(sbi)); } #endif @@ -1419,7 +1420,8 @@ static int __submit_discard_cmd(struct f2fs_sb_info *= sbi, atomic_inc(&dcc->issued_discard); - f2fs_update_iostat(sbi, NULL, FS_DISCARD_IO, len * F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, FS_DISCARD_IO, + len * F2FS_BLKSIZE(sbi)); lstart +=3D len; start +=3D len; @@ -2797,7 +2799,7 @@ void f2fs_update_meta_page(struct f2fs_sb_info *sbi, if (IS_ERR(folio)) return; - memcpy(folio_address(folio), src, PAGE_SIZE); + memcpy(folio_address(folio), src, F2FS_BLKSIZE(sbi)); folio_mark_dirty(folio); f2fs_folio_put(folio, true); } @@ -4152,7 +4154,7 @@ void f2fs_do_write_meta_page(struct f2fs_sb_info *sbi, struct folio *folio, f2fs_submit_page_write(&fio); stat_inc_meta_count(sbi, folio->index); - f2fs_update_iostat(sbi, NULL, io_type, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, NULL, io_type, F2FS_BLKSIZE(sbi)); } void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio) @@ -4162,7 +4164,8 @@ void f2fs_do_write_node_page(unsigned int nid, struct f2fs_io_info *fio) set_summary(&sum, nid, 0, 0); do_write_page(&sum, fio); - f2fs_update_iostat(fio->sbi, NULL, fio->io_type, F2FS_BLKSIZE); + f2fs_update_iostat(fio->sbi, NULL, fio->io_type, + F2FS_BLKSIZE(fio->sbi)); } void f2fs_outplace_write_data(struct dnode_of_data *dn, @@ -4178,7 +4181,8 @@ void f2fs_outplace_write_data(struct dnode_of_data *d= n, do_write_page(&sum, fio); f2fs_update_data_blkaddr(dn, fio->new_blkaddr); - f2fs_update_iostat(sbi, dn->inode, fio->io_type, F2FS_BLKSIZE); + f2fs_update_iostat(sbi, dn->inode, fio->io_type, + F2FS_BLKSIZE(sbi)); } int f2fs_inplace_write_data(struct f2fs_io_info *fio) @@ -4220,7 +4224,7 @@ int f2fs_inplace_write_data(struct f2fs_io_info *fio) f2fs_update_device_state(fio->sbi, fio->ino, fio->new_blkaddr, 1); f2fs_update_iostat(fio->sbi, fio_inode(fio), - fio->io_type, F2FS_BLKSIZE); + fio->io_type, F2FS_BLKSIZE(fio->sbi)); } return err; diff --git a/fs/f2fs/segment.h b/fs/f2fs/segment.h index 2275404e769c..2c85c085961b 100644 --- a/fs/f2fs/segment.h +++ b/fs/f2fs/segment.h @@ -116,7 +116,7 @@ f2fs_start_segno(struct f2fs_sb_info *sbi, unsigned int segno) #define SECTOR_FROM_BLOCK(sbi, blk_addr) \ (((sector_t)blk_addr) << F2FS_LOG_SECTORS_PER_BLOCK(sbi)) -#define SECTOR_TO_BLOCK(sbi, sectors) \ +#define SECTOR_TO_BLOCK(sbi, sectors) \ ((sectors) >> F2FS_LOG_SECTORS_PER_BLOCK(sbi)) /* @@ -432,7 +432,7 @@ static inline void seg_info_to_sit_folio(struct f2fs_sb_info *sbi, int i; raw_sit =3D folio_address(folio); - memset(raw_sit, 0, PAGE_SIZE); + memset(raw_sit, 0, F2FS_BLKSIZE(sbi)); for (i =3D 0; i < end - start; i++) { rs =3D &raw_sit->entries[i]; se =3D get_seg_entry(sbi, start + i); diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index b962c14cbcc1..ca6403a0ed88 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -1610,7 +1610,7 @@ static int f2fs_check_opt_consistency(struct fs_context *fc, return -EINVAL; } min_size =3D MIN_INLINE_XATTR_SIZE; - max_size =3D MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(F2FS_BLKSIZE); + max_size =3D MAX_INLINE_XATTR_SIZE_FOR_BLOCKSIZE(F2FS_BLKSIZE(sbi)); if (F2FS_OPTION(sbi).inline_xattr_size < min_size || F2FS_OPTION(sbi).inline_xattr_size > max_size) { @@ -4079,10 +4079,10 @@ static int sanity_check_raw_super(struct f2fs_sb_info *sbi, } /* only support block_size equals to PAGE_SIZE */ - if (le32_to_cpu(raw_super->log_blocksize) !=3D F2FS_BLKSIZE_BITS) { + if (le32_to_cpu(raw_super->log_blocksize) !=3D PAGE_SHIFT) { f2fs_info(sbi, "Invalid log_blocksize (%u), supports only %u", le32_to_cpu(raw_super->log_blocksize), - F2FS_BLKSIZE_BITS); + PAGE_SHIFT); return -EFSCORRUPTED; } diff --git a/fs/f2fs/sysfs.c b/fs/f2fs/sysfs.c index 811e350a1430..aaca9ed9b169 100644 --- a/fs/f2fs/sysfs.c +++ b/fs/f2fs/sysfs.c @@ -1871,8 +1871,8 @@ static int __maybe_unused disk_map_seq_show(struct seq_file *seq, struct f2fs_sb_info *sbi =3D F2FS_SB(sb); int i; - seq_printf(seq, "Address Layout : %5luB Block address (# of Segments)\n= ", - F2FS_BLKSIZE); + seq_printf(seq, "Address Layout : %5uB Block address (# of Segments)\n", + F2FS_BLKSIZE(sbi)); seq_printf(seq, " SB : %12s\n", "0/1024B"); seq_printf(seq, " seg0_blkaddr : 0x%010x\n", SEG0_BLKADDR(sbi)); seq_printf(seq, " Checkpoint : 0x%010x (%10d)\n", @@ -1889,13 +1889,13 @@ static int __maybe_unused disk_map_seq_show(struct seq_file *seq, seq_printf(seq, " Main : 0x%010x (%10d)\n", SM_I(sbi)->main_blkaddr, le32_to_cpu(F2FS_RAW_SUPER(sbi)->segment_count_main)); - seq_printf(seq, " Block size : %12lu KB\n", F2FS_BLKSIZE >> 10); + seq_printf(seq, " Block size : %12u KB\n", F2FS_BLKSIZE(sbi) >> 10); seq_printf(seq, " Segment size : %12d MB\n", - (BLKS_PER_SEG(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); + (BLKS_PER_SEG(sbi) << (F2FS_BLKSIZE_BITS(sbi) - 10)) >> 10); seq_printf(seq, " Segs/Sections : %12d\n", SEGS_PER_SEC(sbi)); seq_printf(seq, " Section size : %12d MB\n", - (BLKS_PER_SEC(sbi) << (F2FS_BLKSIZE_BITS - 10)) >> 10); + (BLKS_PER_SEC(sbi) << (F2FS_BLKSIZE_BITS(sbi) - 10)) >> 10); seq_printf(seq, " # of Sections : %12d\n", le32_to_cpu(F2FS_RAW_SUPER(sbi)->section_count)); diff --git a/fs/f2fs/xattr.c b/fs/f2fs/xattr.c index 99c863513725..98059e583b09 100644 --- a/fs/f2fs/xattr.c +++ b/fs/f2fs/xattr.c @@ -850,4 +850,4 @@ int __init f2fs_init_xattr_cache(void) void f2fs_destroy_xattr_cache(void) { kmem_cache_destroy(inline_xattr_slab); -} \ No newline at end of file +} diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index f622d26f37a7..957bb713ff24 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -14,12 +14,9 @@ #define F2FS_SUPER_OFFSET 1024 /* byte-size offset */ #define F2FS_MIN_LOG_SECTOR_SIZE 9 /* 9 bits for 512 bytes */ #define F2FS_MAX_LOG_SECTOR_SIZE PAGE_SHIFT /* Max is Block Size */ -#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) ((sbi)->log_blocksize - 9) /* log number for sector/blk */ #define F2FS_MIN_LOG_BLOCKSIZE 12 #define F2FS_MIN_BLKSIZE 4096UL -#define F2FS_BLKSIZE PAGE_SIZE /* support only block =3D=3D page */ #define F2FS_MAX_BLKSIZE PAGE_SIZE -#define F2FS_BLKSIZE_BITS PAGE_SHIFT /* bits for F2FS_BLKSIZE */ #define F2FS_MAX_EXTENSION 64 /* # of extension entries */ #define F2FS_EXTENSION_LEN 8 /* max size of extension */ @@ -27,15 +24,19 @@ #define NEW_ADDR ((block_t)-1) /* used as block_t addresses */ #define COMPRESS_ADDR ((block_t)-2) /* used as compressed data flag */ -#define F2FS_BLKSIZE_MASK (F2FS_BLKSIZE - 1) +#define F2FS_BLKSIZE(sbi) ((sbi)->blocksize) +#define F2FS_BLKSIZE_BITS(sbi) ((sbi)->log_blocksize) +#define F2FS_BLKSIZE_MASK(sbi) (F2FS_BLKSIZE(sbi) - 1) +#define F2FS_LOG_SECTORS_PER_BLOCK(sbi) (F2FS_BLKSIZE_BITS(sbi) - 9) +#define F2FS_BLKS_PER_PAGE(sbi) (PAGE_SIZE / F2FS_BLKSIZE(sbi)) #define F2FS_BYTES_TO_BLK(sbi, bytes) \ - ((unsigned long long)(bytes) >> (sbi)->log_blocksize) + ((unsigned long long)(bytes) >> F2FS_BLKSIZE_BITS(sbi)) #define F2FS_BLK_TO_BYTES(sbi, blk) \ - ((unsigned long long)(blk) << (sbi)->log_blocksize) + ((unsigned long long)(blk) << F2FS_BLKSIZE_BITS(sbi)) #define F2FS_BLK_END_BYTES(sbi, blk) \ (F2FS_BLK_TO_BYTES(sbi, (blk) + 1) - 1) #define F2FS_BLK_ALIGN(sbi, x) \ - DIV_ROUND_UP_ULL((x), (sbi)->blocksize) + DIV_ROUND_UP_ULL((x), F2FS_BLKSIZE(sbi)) /* 0, 1(node nid), 2(meta nid) are reserved node id */ #define F2FS_RESERVED_NODE_NUM 3 @@ -221,7 +222,6 @@ struct f2fs_checkpoint { unsigned char sit_nat_version_bitmap[]; } __packed; -#define CP_CHKSUM_OFFSET (F2FS_BLKSIZE - sizeof(__le32)) /* default chksum offset in checkpoint */ #define CP_MIN_CHKSUM_OFFSET \ (offsetof(struct f2fs_checkpoint, sit_nat_version_bitmap)) @@ -271,7 +271,7 @@ struct node_footer { } __packed; /* Address Pointers in an Inode */ -#define DEF_ADDRS_PER_INODE ((F2FS_BLKSIZE - OFFSET_OF_END_OF_I_EXT \ +#define DEF_ADDRS_PER_INODE ((PAGE_SIZE - OFFSET_OF_END_OF_I_EXT \ - SIZE_OF_I_NID \ - sizeof(struct node_footer)) / sizeof(__le32)) #define CUR_ADDRS_PER_INODE(inode) (DEF_ADDRS_PER_INODE - \ @@ -279,10 +279,10 @@ struct node_footer { #define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */ #define ADDRS_PER_INODE(inode) addrs_per_page(inode, true) /* Address Pointers in a Direct Block */ -#define DEF_ADDRS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32)) +#define DEF_ADDRS_PER_BLOCK ((PAGE_SIZE - sizeof(struct node_footer)) / sizeof(__le32)) #define ADDRS_PER_BLOCK(inode) addrs_per_page(inode, false) /* Node IDs in an Indirect Block */ -#define NIDS_PER_BLOCK ((F2FS_BLKSIZE - sizeof(struct node_footer)) / sizeof(__le32)) +#define NIDS_PER_BLOCK ((PAGE_SIZE - sizeof(struct node_footer)) / sizeof(__le32)) #define ADDRS_PER_PAGE(folio, inode) (addrs_per_page(inode, IS_INODE(folio= ))) --=20 2.53.0 From nobody Sat Sep 26 20:31:42 2026 Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D47C13AD501 for ; Mon, 31 Aug 2026 05:33:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.47 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154406; cv=pass; b=k1n4pF2F2tcYE/eJD9eqpSGD7oXo35DsTyKm9WWJAJwlSuO2D6Z9nOJ0AHUbv7J1ajnfyRtB7WSaBWUofZlUVlq239cmAq9jIU1UVg2UDBmACLe4Soa5IUashKuSqhznSvqOW4foT5gkLoc/4iPikRPO5xKv1w+cyrtol8wJaqE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788154406; c=relaxed/simple; bh=rHXDhFy9Y/hBFBdEADRVzFYPyfTQ2b97M/3SEfCiUxg=; h=From:MIME-Version:In-Reply-To:References:Date:Message-ID:Subject: To:Cc:Content-Type; b=cesNx4aWRYVDw6hXHXi/pa8ipDicIW2FYbLuOShFYwTgbgGs2WJdRw0/6OostGe5k/+NJRjQhItSQOjSOLnxvzL1VO/f6jJvpa7OwXK/chZy1Dk+5OFP5SqSxvbqLl45lFRXdab/XxZDwRjt9VtpZ2InILRQ1/fskCNTBAGALIg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=i037nQjj; arc=pass smtp.client-ip=209.85.208.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i037nQjj" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-6a6108734d5so4361904a12.3 for ; Sun, 30 Aug 2026 22:33:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1788154402; cv=none; d=google.com; s=arc-20260327; b=f3VtLgFsBXsDOhQcOk4D3oNuFLMgiRbxjgdoT/0eqef4kRpR3/NxDEHqMnmoInY/fQ ks+J3G9CcRhUeaT2Jmh4Lej3YGzN8DL2QJnbw+6e4p3akL2gkIJsGpvIglR9AkMJNK49 Dm8jKbpkD6AFOxTTPas9ZcDvNwU6dzCoKsCWnGCjPcgD6EWqlamtuamg2I00NMHlssWL K4XOLHZEhX1DeZ3Gj5v8sVVyrzd6QE02aDZHg+2v84i8/58bTtmfWwAAAgx3CipzoF0q TEUzbWhqGj0LcU1Afl8kJYkvaSjNM/Y0zZBvaIFUa0tfe9aOLKaix4slUPMQv+A8SYn5 OA+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:references:in-reply-to:mime-version :from:dkim-signature; bh=WvhIM3bw4Fo4g8EM6EjhZk/faYLf6d+8ugMbi89OSKo=; fh=r2XYMjOv/K2T7dM7A7Dv7xhMjYXo8Dlz8w+YgT5I81U=; b=BXCYtPJ5FQy1DEBU+T33nYQgFUAfJAZCidTq/HmFjiMTOLVqNfp+5eh8WnjLdavjB/ YUe9mnQO2sp7OyhIb+sbQkpbJG1eCFnLZ19znq7KPRn3wIutwurDMaeZmSUTdeokrj39 y8jrUp4sd9pAp6+pgF0DohUeKs3nY7io3yI/MDgGe/nIXigrGejQPXZ98CaFtcWSMJON eDV3JkTKfaZXwhDO1hF1ZHc5PxT7qtah4OecGCJqJy4VvuyVl8hka7bbzhdeotipSkRX uHUKhkWJ1x1Ddkus+J/NsVcWNwLfYir1eK5ZD9h46eQ8TKA9bn45sh8QSUlbyRm/KvPk yz+g==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788154402; x=1788759202; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=WvhIM3bw4Fo4g8EM6EjhZk/faYLf6d+8ugMbi89OSKo=; b=i037nQjjGoXx3Z6FZFXCJe2Bw5NuSgr8M44vbzWVym4RV8DbMEtl64o1SlUzmDWW4U CVf2tR3OICXwmnlxphmCt4MhfJbr/YP3knV5KrK9K12bn+2UP//zIPjiy/RcXpkSxAwc OC3pIdxBBSRI+PVW+W4Y3/ElX7whcJlNyLsp23Ax0MMzAOwvrrsipd7SwhIHyqzEG0wF u5B0RrAdiac96EZeh6QCwdw8xx7KOC1RTz58HOTjcIbF+4UPOoEOlVWZkBu8YgKs3Zr6 Vxa00/2Eq76Tf4u+Xt2drG3kebCEEW1aoJNfBCpBsYNdAj8BVwXbeCvW1yaZLddz8Y3k J+ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788154402; x=1788759202; h=content-type:cc:to:subject:message-id:date:references:in-reply-to :mime-version:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=WvhIM3bw4Fo4g8EM6EjhZk/faYLf6d+8ugMbi89OSKo=; b=RYs1xQVrWTn2Eu/bUW3wxH9IxJStoMLsJ2tJZRWgsz+92WWDgZL26ZWeV1r8q1C1Ks nMQcB+mfYY2l+C0Jd2jLouPLZGyEFFEB0EfF7O8IOCRqQPlBWjl5HPPLHMH5Fl12m+Hv AQWkVpofzZk/vExQ3UjYPpe/lgP150JaZn3MnC/SBgPoBlj0DLFBH5euYvuXH5jeq9ay +oKdS5bj1dIGKoW3vxU7YphN47PL7iwn0DsfT35CbgPrVjKBk+sscw1EqvYvdVbrp+M0 YlJ0RHyUI6scA1h078UZCaJJaWh5wD9lNv68I2tcaPjunw9f9Hi8qlApGMQ3p7ArlQ2O uIKg== X-Forwarded-Encrypted: i=1; AKwUvByH+ejhheOAv67XJ9tGTpL6UnzS3fwRXG58SIQRgcUxnPH7LtKk8vjDqloFxGUQNeiz+E2llyKaMSQuskM=@vger.kernel.org X-Gm-Message-State: AFuF++m1o8+tJaSlxQAycroiJbpx9lsGcfaJD7F9N7BkRV0m8xa7nyCX b8ztQUHo0VBZ/mU0ej5fZIv7dcgildR8IAM8IMg9NaikJxMIj0wsaVpCCTBO/JSrP1zJPG/dPYW ZBO4j2PmJk4CdkRXWdVOftwm+rSqDfgk= X-Gm-Gg: AYBFou0vuc7iFskm4VrIsbP/BiGEDWWLFP7PL30TbLC3LOdnavuPFdCuWVz/zSlVS3k WG2hLyCmNUUy9BjTR4OzD+6kZ8V1gy+CwfTrbjCjC1hu0n2i5TipmWdVgAgnPvwGP6OsFBE0D1P WOTyG0U0HCR7ySvuYs/8TbMnV2P3iWDR2GaETjj8jgafw/sUklRaWBhDPGbn+PQXjJC4azRRdNF 1EFtlhNqGJj6YcNGiVF5dzxdEtPW8zsTiDDIneA8T07UY8unjFE14q8fBHIYubMY+EPxGIRKqJU UmaB3QunA7MG4v92CsV9gEjijZWg2yDgt9Ryrw+1Z/kJBRP8FEC8uZ33lIbvrHC/bMWfBHRrBlz Mucnkev5WHE3h X-Received: by 2002:a05:6402:530b:b0:6a1:f7f4:200b with SMTP id 4fb4d7f45d1cf-6a65e6832cbmr352353a12.12.1788154401808; Sun, 30 Aug 2026 22:33:21 -0700 (PDT) Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:21 +0200 Received: from 637551599889 named unknown by gmailapi.google.com with HTTPREST; Mon, 31 Aug 2026 07:33:21 +0200 From: Xinping Zhang Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 In-Reply-To: References: Date: Mon, 31 Aug 2026 07:33:21 +0200 X-Gm-Features: AcwNN1UycFypQqmzcGQjc6wvqbCkuJCVTCW7q4zqXZ7mSMvcNwAlb50DBoQeaHA Message-ID: Subject: [PATCH v3 11/11] f2fs: describe node tree geometry dynamically To: linux-f2fs-devel@lists.sourceforge.net Cc: jaegeuk@kernel.org, chao@kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The file indexing tree boundaries separating direct, indirect, and double-indirect node blocks depend on the number of data block addresses and node IDs contained in each node block. Parameterize index boundary macros (NODE_DIR1_BLOCK, NODE_DIR2_BLOCK, NODE_IND1_BLOCK, NODE_IND2_BLOCK, and NODE_DIND_BLOCK) and address capacity helpers (DEF_ADDRS_PER_BLOCK, NIDS_PER_BLOCK, cur_addrs_per_inode, addrs_per_page, and addrs_per_folio) with struct f2fs_sb_info *sbi. Update file mapping, block allocation, truncate, garbage collection, and recovery paths to compute indexing tree offsets from the runtime geometry. Signed-off-by: Kelvin Zhang --- fs/f2fs/f2fs.h | 19 +++++++++-- fs/f2fs/gc.c | 10 +++--- fs/f2fs/node.c | 74 +++++++++++++++++++++-------------------- fs/f2fs/node.h | 18 ++++++---- fs/f2fs/super.c | 6 ++-- include/linux/f2fs_fs.h | 18 ++-------- 6 files changed, 77 insertions(+), 68 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f83cdab66f54..e1f33ac24c6e 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -602,8 +602,12 @@ static inline int update_sits_in_cursum(struct f2fs_journal *journal, int i) #define DEF_INLINE_RESERVED_SIZE 1 static inline int get_extra_isize(struct inode *inode); static inline int get_inline_xattr_addrs(struct inode *inode); +static inline unsigned int cur_addrs_per_inode(struct inode *inode) +{ + return DEF_ADDRS_PER_INODE(inode) - get_extra_isize(inode); +} #define MAX_INLINE_DATA(inode) (sizeof(__le32) * \ - (CUR_ADDRS_PER_INODE(inode) - \ + (cur_addrs_per_inode(inode) - \ get_inline_xattr_addrs(inode) - \ DEF_INLINE_RESERVED_SIZE)) @@ -2257,11 +2261,19 @@ static inline struct f2fs_sb_info *F2FS_P_SB(struct page *page) #define SIT_ENTRY_PER_BLOCK(sbi) ((sbi)->sit_entries_per_block) #define NAT_ENTRY_PER_BLOCK(sbi) ((sbi)->nat_entries_per_block) #define DEF_ADDRS_PER_INODE_SBI(sbi) ((sbi)->addrs_per_inode) +#define DEF_ADDRS_PER_BLOCK(sbi) ((sbi)->addrs_per_block) +#define NIDS_PER_BLOCK(sbi) ((sbi)->nids_per_block) #define F2FS_ORPHANS_PER_BLOCK(sbi) ((sbi)->orphans_per_block) #define GET_ORPHAN_BLOCKS(sbi, n) DIV_ROUND_UP((n), \ F2FS_ORPHANS_PER_BLOCK(sbi)) #define CP_CHKSUM_OFFSET(sbi) (F2FS_BLKSIZE(sbi) - sizeof(__le32)) +#define NODE_DIR1_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 1) +#define NODE_DIR2_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 2) +#define NODE_IND1_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 3) +#define NODE_IND2_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 4) +#define NODE_DIND_BLOCK(sbi) (DEF_ADDRS_PER_INODE_SBI(sbi) + 5) + static inline struct f2fs_orphan_footer * f2fs_orphan_footer(void *orphan_block, struct f2fs_sb_info *sbi) { @@ -3650,8 +3662,9 @@ static inline bool f2fs_need_compress_data(struct inode *inode) static inline unsigned int addrs_per_page(struct inode *inode, bool is_inode) { - unsigned int addrs =3D is_inode ? (CUR_ADDRS_PER_INODE(inode) - - get_inline_xattr_addrs(inode)) : DEF_ADDRS_PER_BLOCK; + unsigned int addrs =3D is_inode ? (cur_addrs_per_inode(inode) - + get_inline_xattr_addrs(inode)) : + DEF_ADDRS_PER_BLOCK(F2FS_I_SB(inode)); if (f2fs_compressed_file(inode)) return ALIGN_DOWN(addrs, F2FS_I(inode)->i_cluster_size); diff --git a/fs/f2fs/gc.c b/fs/f2fs/gc.c index 299d5310e597..b17e7ce58f2c 100644 --- a/fs/f2fs/gc.c +++ b/fs/f2fs/gc.c @@ -1123,7 +1123,8 @@ static int gc_node_segment(struct f2fs_sb_info *sbi, */ block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode) { - unsigned int indirect_blks =3D 2 * NIDS_PER_BLOCK + 4; + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); + unsigned int indirect_blks =3D 2 * NIDS_PER_BLOCK(sbi) + 4; unsigned int bidx; if (node_ofs =3D=3D 0) @@ -1132,11 +1133,12 @@ block_t f2fs_start_bidx_of_node(unsigned int node_ofs, struct inode *inode) if (node_ofs <=3D 2) { bidx =3D node_ofs - 1; } else if (node_ofs <=3D indirect_blks) { - int dec =3D (node_ofs - 4) / (NIDS_PER_BLOCK + 1); + int dec =3D (node_ofs - 4) / (NIDS_PER_BLOCK(sbi) + 1); bidx =3D node_ofs - 2 - dec; } else { - int dec =3D (node_ofs - indirect_blks - 3) / (NIDS_PER_BLOCK + 1); + int dec =3D (node_ofs - indirect_blks - 3) / + (NIDS_PER_BLOCK(sbi) + 1); bidx =3D node_ofs - 5 - dec; } @@ -1179,7 +1181,7 @@ static bool is_alive(struct f2fs_sb_info *sbi, struct f2fs_summary *sum, max_addrs =3D DEF_ADDRS_PER_INODE_SBI(sbi); } else { base =3D 0; - max_addrs =3D DEF_ADDRS_PER_BLOCK; + max_addrs =3D DEF_ADDRS_PER_BLOCK(sbi); } if (base + ofs_in_node >=3D max_addrs) { diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 8d16715a3aae..68a95d703c4a 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -691,7 +691,7 @@ static void f2fs_ra_node_pages(struct folio *parent, int start, int n) /* Then, try readahead for siblings of the desired node */ end =3D start + n; - end =3D min(end, (int)NIDS_PER_BLOCK); + end =3D min_t(int, end, NIDS_PER_BLOCK(sbi)); for (i =3D start; i < end; i++) { nid =3D get_nid(parent, i, false); f2fs_ra_node_page(sbi, nid); @@ -702,9 +702,11 @@ static void f2fs_ra_node_pages(struct folio *parent, int start, int n) pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(dn->inode); const long direct_index =3D ADDRS_PER_INODE(dn->inode); const long direct_blks =3D ADDRS_PER_BLOCK(dn->inode); - const long indirect_blks =3D ADDRS_PER_BLOCK(dn->inode) * NIDS_PER_BLOCK; + const long indirect_blks =3D ADDRS_PER_BLOCK(dn->inode) * + NIDS_PER_BLOCK(sbi); unsigned int skipped_unit =3D ADDRS_PER_BLOCK(dn->inode); int cur_level =3D dn->cur_level; int max_level =3D dn->max_level; @@ -714,7 +716,7 @@ pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs) return pgofs + 1; while (max_level-- > cur_level) - skipped_unit *=3D NIDS_PER_BLOCK; + skipped_unit *=3D NIDS_PER_BLOCK(sbi); switch (dn->max_level) { case 3: @@ -740,11 +742,13 @@ pgoff_t f2fs_get_next_page_offset(struct dnode_of_data *dn, pgoff_t pgofs) static int get_node_path(struct inode *inode, long block, int offset[4], unsigned int noffset[4]) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(inode); const long direct_index =3D ADDRS_PER_INODE(inode); const long direct_blks =3D ADDRS_PER_BLOCK(inode); - const long dptrs_per_blk =3D NIDS_PER_BLOCK; - const long indirect_blks =3D ADDRS_PER_BLOCK(inode) * NIDS_PER_BLOCK; - const long dindirect_blks =3D indirect_blks * NIDS_PER_BLOCK; + const long dptrs_per_blk =3D NIDS_PER_BLOCK(sbi); + const long indirect_blks =3D ADDRS_PER_BLOCK(inode) * + NIDS_PER_BLOCK(sbi); + const long dindirect_blks =3D indirect_blks * NIDS_PER_BLOCK(sbi); int n =3D 0; int level =3D 0; @@ -756,7 +760,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D direct_index; if (block < direct_blks) { - offset[n++] =3D NODE_DIR1_BLOCK; + offset[n++] =3D NODE_DIR1_BLOCK(sbi); noffset[n] =3D 1; offset[n] =3D block; level =3D 1; @@ -764,7 +768,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D direct_blks; if (block < direct_blks) { - offset[n++] =3D NODE_DIR2_BLOCK; + offset[n++] =3D NODE_DIR2_BLOCK(sbi); noffset[n] =3D 2; offset[n] =3D block; level =3D 1; @@ -772,7 +776,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D direct_blks; if (block < indirect_blks) { - offset[n++] =3D NODE_IND1_BLOCK; + offset[n++] =3D NODE_IND1_BLOCK(sbi); noffset[n] =3D 3; offset[n++] =3D block / direct_blks; noffset[n] =3D 4 + offset[n - 1]; @@ -782,7 +786,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D indirect_blks; if (block < indirect_blks) { - offset[n++] =3D NODE_IND2_BLOCK; + offset[n++] =3D NODE_IND2_BLOCK(sbi); noffset[n] =3D 4 + dptrs_per_blk; offset[n++] =3D block / direct_blks; noffset[n] =3D 5 + dptrs_per_blk + offset[n - 1]; @@ -792,7 +796,7 @@ static int get_node_path(struct inode *inode, long bloc= k, } block -=3D indirect_blks; if (block < dindirect_blks) { - offset[n++] =3D NODE_DIND_BLOCK; + offset[n++] =3D NODE_DIND_BLOCK(sbi); noffset[n] =3D 5 + (dptrs_per_blk * 2); offset[n++] =3D block / indirect_blks; noffset[n] =3D 6 + (dptrs_per_blk * 2) + @@ -1054,6 +1058,7 @@ static int truncate_dnode(struct dnode_of_data *dn) static int truncate_nodes(struct dnode_of_data *dn, unsigned int nofs, int ofs, int depth) { + struct f2fs_sb_info *sbi =3D F2FS_I_SB(dn->inode); struct dnode_of_data rdn =3D *dn; struct folio *folio; struct f2fs_node *rn; @@ -1063,7 +1068,7 @@ static int truncate_nodes(struct dnode_of_data *dn, unsigned int nofs, int i, ret; if (dn->nid =3D=3D 0) - return NIDS_PER_BLOCK + 1; + return NIDS_PER_BLOCK(sbi) + 1; trace_f2fs_truncate_nodes_enter(dn->inode, dn->nid, dn->data_blkaddr); @@ -1074,11 +1079,11 @@ static int truncate_nodes(struct dnode_of_data *dn, unsigned int nofs, return PTR_ERR(folio); } - f2fs_ra_node_pages(folio, ofs, NIDS_PER_BLOCK); + f2fs_ra_node_pages(folio, ofs, NIDS_PER_BLOCK(sbi)); rn =3D F2FS_NODE(folio); if (depth < 3) { - for (i =3D ofs; i < NIDS_PER_BLOCK; i++, freed++) { + for (i =3D ofs; i < NIDS_PER_BLOCK(sbi); i++, freed++) { child_nid =3D le32_to_cpu(rn->in.nid[i]); if (child_nid =3D=3D 0) continue; @@ -1090,16 +1095,16 @@ static int truncate_nodes(struct dnode_of_data *dn, unsigned int nofs, dn->node_changed =3D true; } } else { - child_nofs =3D nofs + ofs * (NIDS_PER_BLOCK + 1) + 1; - for (i =3D ofs; i < NIDS_PER_BLOCK; i++) { + child_nofs =3D nofs + ofs * (NIDS_PER_BLOCK(sbi) + 1) + 1; + for (i =3D ofs; i < NIDS_PER_BLOCK(sbi); i++) { child_nid =3D le32_to_cpu(rn->in.nid[i]); if (child_nid =3D=3D 0) { - child_nofs +=3D NIDS_PER_BLOCK + 1; + child_nofs +=3D NIDS_PER_BLOCK(sbi) + 1; continue; } rdn.nid =3D child_nid; ret =3D truncate_nodes(&rdn, child_nofs, 0, depth - 1); - if (ret =3D=3D (NIDS_PER_BLOCK + 1)) { + if (ret =3D=3D (NIDS_PER_BLOCK(sbi) + 1)) { if (set_nid(folio, i, 0, false)) dn->node_changed =3D true; child_nofs +=3D ret; @@ -1156,10 +1161,12 @@ static int truncate_partial_nodes(struct dnode_of_data *dn, nid[i + 1] =3D get_nid(folios[i], offset[i + 1], false); } - f2fs_ra_node_pages(folios[idx], offset[idx + 1], NIDS_PER_BLOCK); + f2fs_ra_node_pages(folios[idx], offset[idx + 1], + NIDS_PER_BLOCK(F2FS_I_SB(dn->inode))); /* free direct nodes linked to a partial indirect node */ - for (i =3D offset[idx + 1]; i < NIDS_PER_BLOCK; i++) { + for (i =3D offset[idx + 1]; + i < NIDS_PER_BLOCK(F2FS_I_SB(dn->inode)); i++) { child_nid =3D get_nid(folios[idx], i, false); if (!child_nid) continue; @@ -1193,7 +1200,9 @@ static int truncate_partial_nodes(struct dnode_of_data *dn, } /* - * All the block addresses of data and nodes should be nullified. + * All the node blocks actually belong to the inode will be released. + * If the level is 0, we will simply truncate the dnode, + * or else we should do dynamic truncate for the node pointers with the de= pth. */ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from) { @@ -1240,10 +1249,10 @@ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from) err =3D truncate_partial_nodes(&dn, offset, level); if (err < 0 && err !=3D -ENOENT) goto fail; - nofs +=3D 1 + NIDS_PER_BLOCK; + nofs +=3D 1 + NIDS_PER_BLOCK(sbi); break; case 3: - nofs =3D 5 + 2 * NIDS_PER_BLOCK; + nofs =3D 5 + 2 * NIDS_PER_BLOCK(sbi); if (!offset[level - 1]) goto skip_partial; err =3D truncate_partial_nodes(&dn, offset, level); @@ -1257,23 +1266,16 @@ int f2fs_truncate_inode_blocks(struct inode *inode, pgoff_t from) skip_partial: while (cont) { dn.nid =3D get_nid(folio, offset[0], true); - switch (offset[0]) { - case NODE_DIR1_BLOCK: - case NODE_DIR2_BLOCK: + if (offset[0] =3D=3D NODE_DIR1_BLOCK(sbi) || + offset[0] =3D=3D NODE_DIR2_BLOCK(sbi)) { err =3D truncate_dnode(&dn); - break; - - case NODE_IND1_BLOCK: - case NODE_IND2_BLOCK: + } else if (offset[0] =3D=3D NODE_IND1_BLOCK(sbi) || + offset[0] =3D=3D NODE_IND2_BLOCK(sbi)) { err =3D truncate_nodes(&dn, nofs, offset[1], 2); - break; - - case NODE_DIND_BLOCK: + } else if (offset[0] =3D=3D NODE_DIND_BLOCK(sbi)) { err =3D truncate_nodes(&dn, nofs, offset[1], 3); cont =3D 0; - break; - - default: + } else { BUG(); } if (err =3D=3D -ENOENT) { diff --git a/fs/f2fs/node.h b/fs/f2fs/node.h index 32125f8fc753..66898288b961 100644 --- a/fs/f2fs/node.h +++ b/fs/f2fs/node.h @@ -354,17 +354,18 @@ static inline bool is_recoverable_dnode(const struct folio *folio) */ static inline bool IS_DNODE(const struct folio *node_folio) { + struct f2fs_sb_info *sbi =3D F2FS_F_SB(node_folio); unsigned int ofs =3D ofs_of_node(node_folio); if (f2fs_has_xattr_block(ofs)) return true; - if (ofs =3D=3D 3 || ofs =3D=3D 4 + NIDS_PER_BLOCK || - ofs =3D=3D 5 + 2 * NIDS_PER_BLOCK) + if (ofs =3D=3D 3 || ofs =3D=3D 4 + NIDS_PER_BLOCK(sbi) || + ofs =3D=3D 5 + 2 * NIDS_PER_BLOCK(sbi)) return false; - if (ofs >=3D 6 + 2 * NIDS_PER_BLOCK) { - ofs -=3D 6 + 2 * NIDS_PER_BLOCK; - if (!((long int)ofs % (NIDS_PER_BLOCK + 1))) + if (ofs >=3D 6 + 2 * NIDS_PER_BLOCK(sbi)) { + ofs -=3D 6 + 2 * NIDS_PER_BLOCK(sbi); + if (!((long)ofs % (NIDS_PER_BLOCK(sbi) + 1))) return false; } return true; @@ -372,13 +373,15 @@ static inline bool IS_DNODE(const struct folio *node_folio) static inline int set_nid(struct folio *folio, int off, nid_t nid, bool i) { + struct f2fs_sb_info *sbi =3D F2FS_F_SB(folio); struct f2fs_node *rn =3D F2FS_NODE(folio); __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); f2fs_folio_wait_writeback(folio, NODE, true, true); if (i) - inode_nids[off - NODE_DIR1_BLOCK] =3D cpu_to_le32(nid); + inode_nids[off - NODE_DIR1_BLOCK(sbi)] =3D + cpu_to_le32(nid); else rn->in.nid[off] =3D cpu_to_le32(nid); return folio_mark_dirty(folio); @@ -388,9 +391,10 @@ static inline nid_t get_nid(const struct folio *folio, int off, bool i) { struct f2fs_node *rn =3D F2FS_NODE(folio); const __le32 *inode_nids =3D F2FS_INODE_NIDS(folio); + int nid_index =3D off - NODE_DIR1_BLOCK(F2FS_F_SB(folio)); if (i) - return le32_to_cpu(inode_nids[off - NODE_DIR1_BLOCK]); + return le32_to_cpu(inode_nids[nid_index]); return le32_to_cpu(rn->in.nid[off]); } diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index ca6403a0ed88..f6c492f76f0c 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -3899,17 +3899,17 @@ loff_t max_file_blocks(struct f2fs_sb_info *sbi, struct inode *inode) if (inode && f2fs_compressed_file(inode)) leaf_count =3D ADDRS_PER_BLOCK(inode); else - leaf_count =3D DEF_ADDRS_PER_BLOCK; + leaf_count =3D DEF_ADDRS_PER_BLOCK(sbi); /* two direct node blocks */ result +=3D (leaf_count * 2); /* two indirect node blocks */ - leaf_count *=3D NIDS_PER_BLOCK; + leaf_count *=3D NIDS_PER_BLOCK(sbi); result +=3D (leaf_count * 2); /* one double indirect node block */ - leaf_count *=3D NIDS_PER_BLOCK; + leaf_count *=3D NIDS_PER_BLOCK(sbi); result +=3D leaf_count; /* diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 957bb713ff24..e43ac6509550 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -271,27 +271,15 @@ struct node_footer { } __packed; /* Address Pointers in an Inode */ -#define DEF_ADDRS_PER_INODE ((PAGE_SIZE - OFFSET_OF_END_OF_I_EXT \ - - SIZE_OF_I_NID \ - - sizeof(struct node_footer)) / sizeof(__le32)) -#define CUR_ADDRS_PER_INODE(inode) (DEF_ADDRS_PER_INODE - \ - get_extra_isize(inode)) +#define DEF_ADDRS_PER_INODE(inode) \ + ((i_blocksize(inode) - OFFSET_OF_END_OF_I_EXT - SIZE_OF_I_NID - \ + sizeof(struct node_footer)) / sizeof(__le32)) #define DEF_NIDS_PER_INODE 5 /* Node IDs in an Inode */ #define ADDRS_PER_INODE(inode) addrs_per_page(inode, true) /* Address Pointers in a Direct Block */ -#define DEF_ADDRS_PER_BLOCK ((PAGE_SIZE - sizeof(struct node_footer)) / sizeof(__le32)) #define ADDRS_PER_BLOCK(inode) addrs_per_page(inode, false) -/* Node IDs in an Indirect Block */ -#define NIDS_PER_BLOCK ((PAGE_SIZE - sizeof(struct node_footer)) / sizeof(__le32)) - #define ADDRS_PER_PAGE(folio, inode) (addrs_per_page(inode, IS_INODE(folio= ))) -#define NODE_DIR1_BLOCK (DEF_ADDRS_PER_INODE + 1) -#define NODE_DIR2_BLOCK (DEF_ADDRS_PER_INODE + 2) -#define NODE_IND1_BLOCK (DEF_ADDRS_PER_INODE + 3) -#define NODE_IND2_BLOCK (DEF_ADDRS_PER_INODE + 4) -#define NODE_DIND_BLOCK (DEF_ADDRS_PER_INODE + 5) - #define F2FS_INLINE_XATTR 0x01 /* file inline xattr flag */ #define F2FS_INLINE_DATA 0x02 /* file inline data flag */ #define F2FS_INLINE_DENTRY 0x04 /* file inline dentry flag */ --=20 2.53.0