From nobody Sat Nov 30 07:32:40 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 575AA130A54 for ; Wed, 11 Sep 2024 03:43:55 +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=1726026236; cv=fail; b=eDH9ialYGlkmTxJirBji9IaYsrFcKYlwNXjeshtDjbX4+GS9rkm3DUJIVDPdcZ+UMAqLnxkL0+BNUhuvOVNFMkR/2LXCv9aYB5Yho/eFuA5G4JJQ51ayGdN87scuHmAiFv4JB1SN1nmb3xxrN7HfsQmuxTC09IwT72AdrJ/ww5o= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726026236; c=relaxed/simple; bh=sPwhHRrQKPW7G8PdPrtZ2iMW8M+G5Q+xTJppa6iDR0w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=UXoUthC9+KYwiU51fyXVbI6NbyrvzelN2HF6fZJEVvtk2rZvGKJhRdNyAHgNt+rruIFA6SOvJKN3lVsrdUuMKivBEw3IbkiZQ/cUyz0O819aN/RWWVDMGJhWfk8Oe8T5nT7+QGNDipbV12/so0IvJip1Ne4QMMtgf8OYwOrMIsA= 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=cIc+vm4/; 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="cIc+vm4/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=VPN9g04UWuRoJDuuT8RXZLIMrtASbw6gp79MMXjewalSBGyWQQPjwsJIiCVlflzEsoBA48PMkcXMGHF57Lsm7Ua6ldRUD4JPuFnMX9gdU6EUVwMxYnO+GCrMRyD5jIQxId+hNfu99lRrVDkC4swruQbKiF12UxROSr50jJzAvfreshC9ibHqqCD3Fe6fVXf18K+bXNA/lD3Tn7IfGWk/2wavAwWGdgIpeQokvVGmWnqKFoIprqljvxS16bbrzctHxDuq4VkE0W2xpfhPEC61KWTSCKXYEI84RxYfXRpj5nqm+VuUNulkZcWFr9JHS6EKmKg82Hh0LIMLAPyQOsyETQ== 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=6YkUHWkSyaZim2/FraKiN+n8vb8EDsmqhJ3U8NImOxA=; b=MF333iz5aWPf78NA2cA9FN2niA+KmewWORZ9obpIUt7yCK4PLcx/pxlKyZAcL+qTHJwy+DutCWHd6hwOmbQiNqN9N141/99PRFUiv+0tAua/DIx44hY4Jq5prIDctN4CE5qJCHiGrYzGRnVLKrepBE+ZoiU7UC4wF5XLhYFRYa7+QUfY+VyX/vhpMtVp7NdJ3bxWucyI2lKpdTyg45OpcJdbobjnmigZwT+z48EXj0gRedAULsOZ0Vej7CP0A5eBUm+ilRWg/9Plp7RZf+ql/9y1sTqdpzXBQNSBpq0mcjZAL/Yjpwc3XYTv2QqDQwSqbaeMkArtjOxoaj02xx2pOg== 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=6YkUHWkSyaZim2/FraKiN+n8vb8EDsmqhJ3U8NImOxA=; b=cIc+vm4/P/nlxJLGWkcMkebqw9uyZQBvNxueCMy9EEs/M6LEARXSbei7T/Sqn8sHlU499dTH8FotecWKVYRUJD8l3uwQG+XY9ymsG8VsWSn75Z5gU/andlAsK63A9rJzI8uwrJEk+UGS8cUql3VvF/STYLOLo9voY8TTxHOk82XFWnYVnDVK3M8wv+imI/CI8Ihm9X5tBEVPaHtz57ojIoLvvmIyBP8lnRwDZaZa12r5DPwhU7fN/ytARPMyIxjoVCSRfeLkh57dknzhR5yBxV0W7DOssur7kqtWEMQAFD4LciDzae7m9DLiKi409n5S3ebRWUyIpzreQyDStXdIMQ== 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:45 +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:45 +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 11/13] f2fs: fix inline tail data lost Date: Tue, 10 Sep 2024 21:57:24 -0600 Message-Id: <64857ac35515abdb00cfad877094131b471a8776.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: 92b06946-a1cd-4812-a468-08dcd213f03e 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?lYhdtRgMgvXuU1+GCgFjaneo4y515buEbARLMsPJDQ8gKzW4MEtYBk8H2gKb?= =?us-ascii?Q?S/7M0DCLmhZUedGLl8Kdnhc+VNVXP8LkHCI0CxTb2skeKsBlvlizHKp5knrA?= =?us-ascii?Q?6HxR6aY2BO+FlJXFybQ89Zi/OxQGS2IGg1JuyDC8hNUaplUSwRrsbvnb4D4j?= =?us-ascii?Q?Vk/3MGK+Tu1mNrDTmkHYG8F7wtKem19iEPC8syU+o0BivQ2t1L9Tsyrk0MLZ?= =?us-ascii?Q?MTycPc0qwlFWe3WEcrlI3bie8263vNCQG11/QTEM2GQAJQZztsiMB07DP6lv?= =?us-ascii?Q?1gkmL9F2dxzlOwPM3AbNeZtTANf19r7W8MKonjKDC+bF0Cs4TqwqMGNWZNVZ?= =?us-ascii?Q?2JrTXA0V/+n9DT4VFIkKE3aeUaWL2QU1hEHVSA5DMDSJNvPINUmIwyPIp23o?= =?us-ascii?Q?0cmVK5YQjuMSaHC52mcJnKHEWz9dQMdwaoLoaQ/0yT5JdQnxiu3O/lqbPTYx?=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wwEOlYWNlWq/yUI1tpQhk46do?= =?us-ascii?Q?elUWYyVNHauAbUnbINNWN0OE+CU0s9BgTAVzrsYQUynur8jk5Q=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?Mst4N0yhhAmnixpWmf0QCKKBiwki1aXWcX6nCohRvoFiTLDBhr+0OkKVNlVR?= =?us-ascii?Q?9SrApU98iuL/QSDZZbUfAlE8F9a0a3iKVEi0HWpkzr71jriHY7UDoO3X0s3n?= =?us-ascii?Q?oz3a8WFUOdG/MiMzP8+h3Nlrn0eNm541DODcek0pGyel8wnXYxA0+ssSuh2D?= =?us-ascii?Q?HQfKpXMPW+iaU3S1YcmNLGCSZW2ttQze+bpj/2/B40ETxDEhHcHmeJzqQHaa?= =?us-ascii?Q?4yRe+T/URts7510IIyfb/DW2El6j3qeXUWQOWQiKqfu8YWUXbWyhiDbbFSur?= =?us-ascii?Q?qXXsKolwPyL/yK6BFaBEBpAVbLmwkUJIzeezTPO1ubnngFCcNv2L0HWuMDG9?= =?us-ascii?Q?oBexbQ66s+Xjgk5u+bXv2CqBiurfk2kf1O6juOL6jh+EhuIrFr/JkJRSWEXJ?= =?us-ascii?Q?5IeBfsJT8jc60VszxyNTF5XB0zuV8FtcSLMRzOcv+YoA7t3z3XZ+m4Hu1esf?= =?us-ascii?Q?74gfKLjgr8pmMbuGiz3lKj8mPN/s9jEL0V/EXDVZZJ35vQH0M+HkQCUhtRkh?= =?us-ascii?Q?I9tTQ5NF3CcnidGwhTP4VTHtBaLwst0U+/1x1VN7dv/QQ+VtJ4fWAg0dha3W?= =?us-ascii?Q?XsFPO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LLKjaNJKviU4X3Vk?= =?us-ascii?Q?KSEm82xyHYaFvaqyDETDYZoaNfndPNcYaYIWuQ3HWHpUWcy4YvN0+zNzd1pd?= =?us-ascii?Q?IclSweyIcwWufb1KgmwleRYoJ4iX+6QRbkxC1ygK?= X-OriginatorOrg: vivo.com X-MS-Exchange-CrossTenant-Network-Message-Id: 92b06946-a1cd-4812-a468-08dcd213f03e 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:45.8218 (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: jVKthDJ6ImnDk8fWmU09NIOh845/6tlBmPFIk41/LkWooa38CNiDi05ZDlLpuVbC6kLDwAOwPm3+gBKEDMpqeA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: JH0PR06MB6917 Content-Type: text/plain; charset="utf-8" Before adding a new page to the tail, the old inlined tail page must be converted first; otherwise, the data on that page could be lost. Signed-off-by: Wu Bo --- fs/f2fs/data.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 6d7b6074763f..f52834c1cacd 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3418,7 +3418,9 @@ static int prepare_write_begin(struct f2fs_sb_info *s= bi, block_t *blk_addr, bool *node_changed) { struct inode *inode =3D page->mapping->host; + loff_t i_size =3D i_size_read(inode); pgoff_t index =3D page->index; + pgoff_t end_index =3D i_size >> PAGE_SHIFT; struct dnode_of_data dn; struct page *ipage; bool locked =3D false; @@ -3438,12 +3440,12 @@ static int prepare_write_begin(struct f2fs_sb_info = *sbi, flag =3D F2FS_GET_BLOCK_DEFAULT; f2fs_map_lock(sbi, flag); locked =3D true; - } else if (f2fs_has_inline_tail(inode)) { + } else if (f2fs_has_inline_tail(inode) && index >=3D end_index) { if (!support_tail_inline(inode, pos + len)) { f2fs_map_lock(sbi, flag); locked =3D true; } - } else if ((pos & PAGE_MASK) >=3D i_size_read(inode)) { + } else if ((pos & PAGE_MASK) >=3D i_size) { f2fs_map_lock(sbi, flag); locked =3D true; } @@ -3471,14 +3473,28 @@ static int prepare_write_begin(struct f2fs_sb_info = *sbi, goto out; } =20 - if (f2fs_has_inline_tail(inode)) { + if (f2fs_has_inline_tail(inode) && index >=3D end_index) { + if (index > end_index && f2fs_exist_data(inode)) { + struct page *tail_page =3D f2fs_grab_cache_page( + inode->i_mapping, end_index, false); + if (!page) { + err =3D -ENOMEM; + goto out; + } + err =3D f2fs_convert_inline_page(&dn, tail_page); + f2fs_put_page(tail_page, 1); + if (err || dn.data_blkaddr !=3D NULL_ADDR) + goto out; + } if (support_tail_inline(inode, pos + len)) { f2fs_do_read_inline_data(page_folio(page), ipage); 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); + } + err =3D f2fs_convert_inline_page(&dn, page); + if (err || dn.data_blkaddr !=3D NULL_ADDR) + goto out; } =20 if (!f2fs_lookup_read_extent_cache_block(inode, index, --=20 2.35.3