From nobody Sat Nov 30 07:36:20 2024 Received: from APC01-PSA-obe.outbound.protection.outlook.com (mail-psaapc01on2086.outbound.protection.outlook.com [40.107.255.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF2F17DA81 for ; Wed, 11 Sep 2024 03:43:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.255.86 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726026233; cv=fail; b=Zu5ZJ0Q/j6LlhuytisY+TywVqLOYp9p5esMDIruP5EEheFft1wh/cJUzzZPoblIhKruWvB1Yx6Ha0y2pjnroAnX3ivzlyFICu0SDXcdXtUi7VfCf0zOjDQvz88JJJbeuFZf6+Zj3TVwR39Xn/qSO8qEtpCurH4UMuPaF53EZTzY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726026233; c=relaxed/simple; bh=edtOBKHzBOSiRCBdIrz/ZrKbk3tC1xZL7TmtJVUVnCo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=pDLsQbtuRmzkaiWb4aXZSeSx0gKX8E8aVYGOhbQC2PoZRwoRN9Owv/f32dH9XQFLwlIGKtMWr82zKHdm9Va+ZZM3/WTlXXHn+ZGDEo7z81AfEV7J+RhaDZEyEFBI1K57JK0NNmZTsbZfsw6vhN5838Eizg/qE+N1K8rZq1xQE/0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com; spf=pass smtp.mailfrom=vivo.com; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b=Ry8/SoGb; arc=fail smtp.client-ip=40.107.255.86 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=vivo.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=vivo.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=vivo.com header.i=@vivo.com header.b="Ry8/SoGb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=a2cgjNKJ1x+MOyywpPy9gJUh3zdWxe3hxkiCW+VrSv4Q8t/k0FpGnFwQSa+v2rtAf8G+9Cm3HFH82xx5JGQhYsVC7D7a6o4a/9kr0otn7dm3NmTGco3nYUpngOl2kmjb8hvNf97gtG48KzInoX/6Rm/+Wgyc9nQf1UJOBkq1TTQR3eGGgnz1VSfYyiLU5zWYTLapVmhJ1BmrHWfP5HStTIfoaKhsew32pZoacq+AHWL8f7UtwR4n/50k33xbL/17yQb0P7xQnag3uLD8L9wYPAVZM4Ydh7dtJgkC/0adkrYyvlTG5SEVTzsYq5KS0Lmgv4mVuL6Gj5DQFnuflRsHww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NMu3pawJjX7tZUFb0bQVd90/AKHOuyxS8U1KgIgm3H0=; b=rGi2rHuDW3oFdTkdxY0gnvqENpHvg49/Lqn5ie39/S895SFVzWy2d5Ym8+jjgldQN5JLU6EICygxz0FxBz5zbgl47e2wuvpk1VYRomDLz+9zk3MptAKnIXlTs1hwreX3kyYhwfzYQUcS8NZm4d4Mpk5RxjgYuo5uolLtgQzCqdddfMxeP6xaUtKtxvcMu5/vK7PFnlMePio1SlOn4clHih9KF5Hp07mQuzNXnpcrWftPLg4Wg5APZbfNiqxbAaP0ESb+TpyObvWG6DiSbXLuORvac9gwMjPlckor/VbTYyeevf5HZowAbC29sdJx3aLzoZ8rVhkZp/U3EveAtBzwZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vivo.com; dmarc=pass action=none header.from=vivo.com; dkim=pass header.d=vivo.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivo.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NMu3pawJjX7tZUFb0bQVd90/AKHOuyxS8U1KgIgm3H0=; b=Ry8/SoGbXR2EQXNXGV2xNxXCePE9XSMg0oekEZPu+xiZmu2qq+4hh9IfBBz2u/cmkDhjbDyO7QnQL47/SUVTkYc/J0E5usyvSf2PkZRxwUfJe7voz00YmS+R1BDK9DYEYemFpoZlNOW3Ue81OfutVwmzURYdfa9SigqcVydyfOxH4dcduvR9ydI0hh/qwp7jpuVHvp0Ww4gdwhIttmG6wbKzjgFv7lQXH4CmttWed1T791uwM0pyqENomQ51T+jGJZOv3G5E3bJptE/swM5ZtfdXgnW8qwyEPh9ziHFqQcqB5IIr3EWHuw/h3Wh4VTYwQ7kuZK50/uppkH1mQJ0AJQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=vivo.com; Received: from PSAPR06MB4486.apcprd06.prod.outlook.com (2603:1096:301:89::11) by JH0PR06MB6917.apcprd06.prod.outlook.com (2603:1096:990:67::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7939.24; Wed, 11 Sep 2024 03:43:43 +0000 Received: from PSAPR06MB4486.apcprd06.prod.outlook.com ([fe80::43cb:1332:afef:81e5]) by PSAPR06MB4486.apcprd06.prod.outlook.com ([fe80::43cb:1332:afef:81e5%4]) with mapi id 15.20.7962.016; Wed, 11 Sep 2024 03:43:42 +0000 From: Wu Bo To: linux-kernel@vger.kernel.org Cc: Jaegeuk Kim , Chao Yu , linux-f2fs-devel@lists.sourceforge.net, Wu Bo , Wu Bo Subject: [PATCH v2 09/13] f2fs: fix data loss during inline tail writing Date: Tue, 10 Sep 2024 21:57:22 -0600 Message-Id: <067f905e4f3b71727cfada291b090896463ef796.1726024117.git.bo.wu@vivo.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SI2PR02CA0049.apcprd02.prod.outlook.com (2603:1096:4:196::7) To PSAPR06MB4486.apcprd06.prod.outlook.com (2603:1096:301:89::11) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PSAPR06MB4486:EE_|JH0PR06MB6917:EE_ X-MS-Office365-Filtering-Correlation-Id: cdff4dde-1059-498a-b65f-08dcd213ee84 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|366016|52116014|376014|38350700014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?Ss9DWppozGV6sIjKkUxjmPSUUa8Qhyx2qQMslagm5T5+g0uvjh2B1ZCLu2ZI?= =?us-ascii?Q?bsIf6f6hYidIn/Qeaq73JztgoZZ4R5ToPUZqkQgGxRRbqM4lO0QRGi2jerxh?= =?us-ascii?Q?e+cg4tGY0mVsRycuqPYj4ymXFcEluaT5vryO+qU3377d48jpoo3Yl4WXxNZw?= =?us-ascii?Q?bFnHcOoLdDEi/I+9+WWLZCPA1W69anAvcxuLDmAxS0Z0EopUi2yTuITGLPKE?= =?us-ascii?Q?Nl6jEtqfol/GN1j3x1QMp7f1IzJKSViTF/VZ44fK85v/YfvfwmITvix48u2Q?= =?us-ascii?Q?+L2y+l13reixdAYgB6Y6dXQ5kLrjwk2Y6U8e+rNEHXge+hnfAxTrYiqi1u12?= =?us-ascii?Q?qgeqqUtHx/uD3ALyrB0a064iueh53puw7nKmtam3tQbukVpCwmZHALdobfS4?= =?us-ascii?Q?iKTwFz8Byv61enx0aC91dBnmtP50PmvU+oXhd/aY+AeS0Vd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bmIHtF2wUmq8nemL6622xkfmBxz1tNrENneD+UXv?= =?us-ascii?Q?TY4/TAQ2j065vyi2L1bZUrCM+YcLNA96HSJfmPujaBzMYc+DrA=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PSAPR06MB4486.apcprd06.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(366016)(52116014)(376014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?CX2/ugSHKNEahTe3/R7kYmfjW5vF3F3S187WNL4nwLXJRPGhZnqgZhRIZK9s?= =?us-ascii?Q?g2F+gRkrGd9okNwTpfYhMn5X1bRKcXPMAaUZclh7cPUHj0CkmbT68Rxk0LQ1?= =?us-ascii?Q?Aea2KFBFVW50YyANq21y+1SKfHPXRmR2zJ0L5ph1GrPnJK3rB+x12Axi3x1b?= =?us-ascii?Q?A9bUT+GLujOOnQRZbtXOw9z+9Wn48VGJRfD08J/gV0Ygd6EsiD2ZKPnOwfFp?= =?us-ascii?Q?FbBTy2R/5Wx+Lmw5PUIBcTT90ABvRDfkhl2LlJiAkJNCjKKXTTvHNDGsjoEf?= =?us-ascii?Q?zUSLrdf1Izxbabt8UTX4Bl9l2p/cZu1QyAaKmDbdBHWisdD2NJz3sz/bXWE8?= =?us-ascii?Q?eiUSgNrlWDJo8Af27kD/hxbyjpgGCV6BJ9iqNJm7CY4/Q3gbM9QQDKWSlIb6?= =?us-ascii?Q?n43JxekM9F5ByQUPeRDL0VK00TM9mG9Eb602lHzSE7W1Zpw7PWmZ3/d1b8n1?= =?us-ascii?Q?uWr7Lb+/NcxrheucwJcsaYz+ihdsQTwlUitzLo60jnJBmqw9+KC+Jlrv/Mja?= =?us-ascii?Q?YCMRWjBBtWwG1vHIXy8TmEbrLJ6IYnGFALk+TREDUPCqcGjE3n1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Zs8izG1k0+RFe2ovH7UqfumOTjP0AzMZk?= =?us-ascii?Q?DKofOA34jn2ys9L39VDGL7222AbYWcpXwqT3BVFXMdViLoXb1BBkQpjjneSl?= =?us-ascii?Q?6d0R+YouigcB5yht7VRO8ypMzM0SDeaP4uEJrcR9?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: cdff4dde-1059-498a-b65f-08dcd213ee84 X-MS-Exchange-CrossTenant-AuthSource: PSAPR06MB4486.apcprd06.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Sep 2024 03:43:42.9244 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 923e42dc-48d5-4cbe-b582-1a797a6412ed X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: tkZLaHWG9XqFNpWDDyJg7zzkocszHKug5nnqmLyN6igtnqlD88jZzyBbhh7F1rBtmbCV8/vVWTWftlIOkCGH5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB6917 Content-Type: text/plain; charset="utf-8" This is detected by xfstest generic/114. The inline data needs to be read out before writing to avoid losing the already inline data. Signed-off-by: Wu Bo --- fs/f2fs/data.c | 3 ++- fs/f2fs/file.c | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 476325a26d4e..275c5739993e 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3477,7 +3477,8 @@ static int prepare_write_begin(struct f2fs_sb_info *s= bi, if (inode->i_nlink) set_page_private_inline(ipage); goto out; - } + } else if (f2fs_exist_data(inode)) + f2fs_do_read_inline_data(page_folio(page), ipage); } =20 if (!f2fs_lookup_read_extent_cache_block(inode, index, diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 2551403a5b83..64ea0bfc2e1e 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -4729,7 +4729,7 @@ static int f2fs_preallocate_blocks(struct kiocb *iocb= , struct iov_iter *iter, =20 if (f2fs_has_inline_tail(inode) && (pos + count > MAX_INLINE_TAIL(inode))) { - ret =3D f2fs_clear_inline_tail(inode, true); + ret =3D f2fs_convert_inline_tail(inode); if (ret) return ret; } @@ -4842,6 +4842,7 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *iocb= , struct iov_iter *from, if (iocb->ki_flags & IOCB_NOWAIT) { /* f2fs_convert_inline_inode() and block allocation can block */ if (f2fs_has_inline_data(inode) || + f2fs_has_inline_tail(inode) || !f2fs_overwrite_io(inode, pos, count)) { ret =3D -EAGAIN; goto out; @@ -4861,6 +4862,10 @@ static ssize_t f2fs_dio_write_iter(struct kiocb *ioc= b, struct iov_iter *from, if (ret) goto out; =20 + ret =3D f2fs_convert_inline_tail(inode); + if (ret) + goto out; + f2fs_down_read(&fi->i_gc_rwsem[WRITE]); if (do_opu) f2fs_down_read(&fi->i_gc_rwsem[READ]); --=20 2.35.3