From patchwork Wed Sep 11 03:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu Bo X-Patchwork-Id: 13799654 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.sourceforge.net (lists.sourceforge.net [216.105.38.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5EEDCEDE997 for ; Wed, 11 Sep 2024 03:43:54 +0000 (UTC) Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1soEGo-0001uE-Jp; Wed, 11 Sep 2024 03:43:54 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1soEGm-0001ty-Vf for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 Sep 2024 03:43:52 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=MIME-Version:Content-Type:Content-Transfer-Encoding :References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=6YkUHWkSyaZim2/FraKiN+n8vb8EDsmqhJ3U8NImOxA=; b=EXQ8duLJX0ovTs9TT0PmNPzadm 3N3fsDcjojDaEQRf213XJFadLY/IUaqWln+gaTYfkSPygwZk+SLdLAPUCOkhS9wzhD46DHLCfpqmn 3/UVP+SesGLDwpKo2dbLzUCKxNswq3Yb8dbK6Xhh2I6EM9+eJfzwyYfprSht/V7hPooM=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=MIME-Version:Content-Type:Content-Transfer-Encoding:References: In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=6YkUHWkSyaZim2/FraKiN+n8vb8EDsmqhJ3U8NImOxA=; b=MJ7zMz0CDgF5CjoqSyXOSJcH7c x1XcoyZEfUrk/RDJopVUw2SlRihRPJ0rYr6gseDkbqul0Ar8CBzz0i3Fpi6YcYeGG/lAlb8IHGJPL B9A9NUn5BPY84m1RhMnPqFaVORoD1y9ZWPZ2FcPimLPPoqKqctXQhxF1ek/1tyvkZfYw=; Received: from mail-psaapc01on2082.outbound.protection.outlook.com ([40.107.255.82] helo=APC01-PSA-obe.outbound.protection.outlook.com) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1soEGl-0000Nz-ON for linux-f2fs-devel@lists.sourceforge.net; Wed, 11 Sep 2024 03:43:52 +0000 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 To: linux-kernel@vger.kernel.org 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: X-ClientProxiedBy: SI2PR02CA0049.apcprd02.prod.outlook.com (2603:1096:4:196::7) To PSAPR06MB4486.apcprd06.prod.outlook.com (2603:1096:301:89::11) 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: lYhdtRgMgvXuU1+GCgFjaneo4y515buEbARLMsPJDQ8gKzW4MEtYBk8H2gKbS/7M0DCLmhZUedGLl8Kdnhc+VNVXP8LkHCI0CxTb2skeKsBlvlizHKp5knrA6HxR6aY2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xSsnVOcJgPrpeNMlEhXmSnUNHT+b0TeQP/HuOUznfX4Kvf2Mz6fmmlKmJYbs+vDouKJztpKBQ8bcmaxJIPNKrr917jn1dLJwdRjv32MkxVIcGIKiMJLQANswtZEI6h5xu/Y2ymlJ+6wPJgBa7R8cwwEOlYWNlWq/yUI1tpQhk46doelUWYyVNHauAbUnbINNWN0OE+CU0s9BgTAVzrsYQUynur8jk5Q== 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: Mst4N0yhhAmnixpWmf0QCKKBiwki1aXWcX6nCohRvoFiTLDBhr+0OkKVNlVR9SrApU98iuL/QSDZZbUfAlE8F9a0a3iKVEi0HWpkzr71jriHY7UDoO3X0s3noz3a8WFUOdG/MiMzP8+h3Nlrn0eNm541DODcek0pGyel8wnXYxA0+ssSuh2DHQfKpXMPW+iaU3S1YcmNLGCSZW2ttQze+bpj/2/B40ETxDEhHcHmeJzqQHaa4yRe+T/URts7510IIyfb/DW2El6j3qeXUWQOWQiKqfu8YWUXbWyhiDbbFSurqXXsKolwPyL/yK6BFaBEBpAVbLmwkUJIzeezTPO1ubnngFCcNv2L0HWuMDG9oBexbQ66s+Xjgk5u+bXv2CqBiurfk2kf1O6juOL6jh+EhuIrFr/JkJRSWEXJ5IeBfsJT8jc60VszxyNTF5XB0zuV8FtcSLMRzOcv+YoA7t3z3XZ+m4Hu1esf74gfKLjgr8pmMbuGiz3lKj8mPN/s9jEL0V/EXDVZZJ35vQH0M+HkQCUhtRkhI9tTQ5NF3CcnidGwhTP4VTHtBaLwst0U+/1x1VN7dv/QQ+VtJ4fWAg0dha3WXsFPOS6fFg17VVYuSkIbidhY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SAPR06MB4486.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 X-Headers-End: 1soEGl-0000Nz-ON Subject: [f2fs-dev] [PATCH v2 11/13] f2fs: fix inline tail data lost X-BeenThere: linux-f2fs-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Wu Bo via Linux-f2fs-devel From: Wu Bo Reply-To: Wu Bo Cc: Wu Bo , Jaegeuk Kim , Wu Bo , linux-f2fs-devel@lists.sourceforge.net Errors-To: linux-f2fs-devel-bounces@lists.sourceforge.net 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 *sbi, block_t *blk_addr, bool *node_changed) { struct inode *inode = page->mapping->host; + loff_t i_size = i_size_read(inode); pgoff_t index = page->index; + pgoff_t end_index = i_size >> PAGE_SHIFT; struct dnode_of_data dn; struct page *ipage; bool locked = false; @@ -3438,12 +3440,12 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, flag = F2FS_GET_BLOCK_DEFAULT; f2fs_map_lock(sbi, flag); locked = true; - } else if (f2fs_has_inline_tail(inode)) { + } else if (f2fs_has_inline_tail(inode) && index >= end_index) { if (!support_tail_inline(inode, pos + len)) { f2fs_map_lock(sbi, flag); locked = true; } - } else if ((pos & PAGE_MASK) >= i_size_read(inode)) { + } else if ((pos & PAGE_MASK) >= i_size) { f2fs_map_lock(sbi, flag); locked = true; } @@ -3471,14 +3473,28 @@ static int prepare_write_begin(struct f2fs_sb_info *sbi, goto out; } - if (f2fs_has_inline_tail(inode)) { + if (f2fs_has_inline_tail(inode) && index >= end_index) { + if (index > end_index && f2fs_exist_data(inode)) { + struct page *tail_page = f2fs_grab_cache_page( + inode->i_mapping, end_index, false); + if (!page) { + err = -ENOMEM; + goto out; + } + err = f2fs_convert_inline_page(&dn, tail_page); + f2fs_put_page(tail_page, 1); + if (err || dn.data_blkaddr != 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 = f2fs_convert_inline_page(&dn, page); + if (err || dn.data_blkaddr != NULL_ADDR) + goto out; } if (!f2fs_lookup_read_extent_cache_block(inode, index,