From patchwork Thu Nov 2 09:58:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yuezhang.Mo@sony.com" X-Patchwork-Id: 13443561 Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 68533125BD for ; Thu, 2 Nov 2023 09:59:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="TAICW6i1" Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7BAC5112 for ; Thu, 2 Nov 2023 02:59:11 -0700 (PDT) Received: from pps.filterd (m0209320.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3A25cgY4023067; Thu, 2 Nov 2023 09:59:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : mime-version : content-type : content-transfer-encoding; s=S1; bh=3uIPvyGMUc34q3xm+SNWbdRV5KP5nxH0fiUVoKgnqT4=; b=TAICW6i1nibtvDyqpLWy1ujSkvi4Nsi519jCS5Flvx2fbg0gju4Vc5RbPM1OTuvWfUR9 5iOK3Zj8kiTRORwQW8glvjal0IuA3a7aidS1jZEhFfPj/I6XBUtVzSjcs4q/n/cEs5lc EmLQc3V8zXluP4Oc1SbXzLuCmDNlnHwu6VR2UnuVLE6Nst/pnJ1/DPMTPAWeJmgKNdG5 hiIfBGQm56qda0Y69NFyeP6f+qqC4DJDGjZ73SHIkFyNqUY3RzX3RdD+GP4pUvDSzfZd 2lo7trHQp+c736Od9OSPKwjF3NSio1tzz65ncJaQzTxUXTLKuVNSPR2WAYxEC6vDMmTj /w== Received: from apc01-psa-obe.outbound.protection.outlook.com (mail-psaapc01lp2040.outbound.protection.outlook.com [104.47.26.40]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3u0r6mdhtc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 02 Nov 2023 09:58:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d7vOitjVpk1col/6JyXDQUfyN8WhpiHgxBlja53ebUH6fMM/I3IpceOaG/AF7yi1E1s/sAQEj4dQbMil+p3M7fuNyZWjQWfIysJp9Tw/eth0TT2Ek1C2/wbrdeGdXXqB7y7tRuLDjacJ6SR242nvjMmn0VX7SfOQP+dW+D5hxPyQldN5IeWpbgrvpC4eTETkpb2UdI33KB//4nrTACEX4tVQZVM8LiZ54OSL5DPBxRUDM6Ep5LD11R7igVSbcshSD8nEmOvchCwW7aI/AudgK0xLkg0SjtQkYJrVoQ9l1YhCrBGAwnZLILylhwthLiipginSb2VNtBQvez2eSaA2rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; 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=3uIPvyGMUc34q3xm+SNWbdRV5KP5nxH0fiUVoKgnqT4=; b=NHDLN2HQJ2P1Q0YrELv8O8Fw6bUvgK4MaTURhenyqdWYlPqjrorhw9BDvnIWVphiXuunKz7fUHzA2HufplFAPPqUHuduHgZRezCpP+lHvkU7ZGCb9NoywrTsTC+XWG6IgbUX3cklbKbEcUjLDRWL3oOiJfgFzT5JHrRru7GGy200kTJEpEyc6/uyOEQeHg0s6+e3FC689Dvo4FWVVWvNbHR9EFevCu6ncUmfcw9PDcTO4GXHWSGXKQNBLxEjzRb44G2tvTnOiN5N6Ys2Z5Z9ankdqcz9/mLL/2BGxLuekU9Fa+MlNIMQilquG0hoDKOwh8CsF//UKNi5Ys+8NV4D+w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=sony.com; dmarc=pass action=none header.from=sony.com; dkim=pass header.d=sony.com; arc=none Received: from PUZPR04MB6316.apcprd04.prod.outlook.com (2603:1096:301:fc::7) by TYZPR04MB7934.apcprd04.prod.outlook.com (2603:1096:405:a9::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6954.19; Thu, 2 Nov 2023 09:58:51 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::2fd0:f20f:14a9:a95a]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::2fd0:f20f:14a9:a95a%4]) with mapi id 15.20.6907.025; Thu, 2 Nov 2023 09:58:51 +0000 From: "Yuezhang.Mo@sony.com" To: "linkinjeon@kernel.org" , "sj1557.seo@samsung.com" CC: "linux-fsdevel@vger.kernel.org" , "Andy.Wu@sony.com" , "Wataru.Aoyama@sony.com" Subject: [PATCH v4 2/2] exfat: do not zeroed the extended part Thread-Topic: [PATCH v4 2/2] exfat: do not zeroed the extended part Thread-Index: AdoNcu9nRDbe3wI6SL2iRFBJj5Gtdg== Date: Thu, 2 Nov 2023 09:58:51 +0000 Message-ID: Accept-Language: zh-CN, en-US Content-Language: zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PUZPR04MB6316:EE_|TYZPR04MB7934:EE_ x-ms-office365-filtering-correlation-id: 71c1e13c-6f20-4dea-47f0-08dbdb8a510c x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: N8uJuXyMQDjYteQw+q5qfqtgQ8RyWPuY1OgP5FiwCC29DjfLWvAM+Tg/T287ZfiT5n1ycHh+vNpxLyOYROmLY9s2g2HtJIjU37zgtRn9l0RXxKluTkKa9mDKy+tTWJfhp6IfWdy+a/tk25cNWkC6FK73wF1mQVv5R0a5MEnevSeNMxNAM8h74lasaO2yeRWnYmf6Vwiiul9DgpArLWU3LA6Fu2xMz+yN5SQMJLmUnndvay0iqq4VKPcn3hz1acwM8h2+3VLia+zum4oTbNSPNSy/jRVsp4vpIFvqg6nIBkaHm0QaSM8VSDgzDtttXiXc5xmOEYh/4nIfawqUMNrp+fWVUX+INEMJ6sNgkbXTrmD/E77puuHRjY9r4wf+DSVFxRqc6HXpDzqHL0ul02ygljs9p0uWK1WDqeD7tZW2iG50hTSWm6dOAKARzRlaUO/gziivdZ6Uw50hDogONk9XLIPKFjx99M9/RPR4ApFrri8SGFN16l0XClOizKtb0JxKRpRAnUMpk+I36bvGxlrcPPr6XmaABKtp7RWFcMTmS3mcEghunYMWwJyOyTzUPsP6D3+gFBr+HzZT3ofTDqetgPvXonXQlCRD3q5uVs5LdbTo+CECbK1fypsneJZbMNN6 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PUZPR04MB6316.apcprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(376002)(39860400002)(396003)(366004)(346002)(136003)(230922051799003)(186009)(451199024)(64100799003)(1800799009)(38100700002)(83380400001)(41300700001)(4326008)(8936002)(8676002)(5660300002)(38070700009)(52536014)(2906002)(122000001)(86362001)(9686003)(478600001)(55016003)(82960400001)(7696005)(6506007)(71200400001)(316002)(76116006)(66446008)(66476007)(54906003)(107886003)(66556008)(110136005)(64756008)(66946007)(26005)(33656002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?1ubq/4fjQqKY1SqHXeNLwmk6ojdj?= =?utf-8?q?ctq2iz4Bek+cIxTzVfPyyd37VUTYGVSRdkpRnwMyaaXSmKA8lX2GVzTZnuGQvnS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?utf-8?q?lcOQOBhsATozBGqH+vZoVWNB15n7+R63KrEGb63dgZUcH79KzM157LfsD4DgS0RXd?= =?utf-8?q?IuQsasRsDHKqhU15jufvQRUummXYUGVikeYIr0zgO1jxCl09NB+GJc3uiFTULeQEc?= =?utf-8?q?MwloJ2ICNRuLNaFw1k93TEi9YWCRYBe5X2nkz/jZFAKqTJI6MQNQ63TQ1+ElpC6+N?= =?utf-8?q?q0V33W8T8RQG7siQeSGFdvVZL0R2ZKuyCqGItCXCWpscDzsSGBvPDUaHpymX6h/OO?= =?utf-8?q?ANIMyiRlMUb+upBcF8aFksd1brAj5Ek9G3sHS1/bg7C7CX5FodZ5TAfowe4jH+rBp?= =?utf-8?q?FNs2PFt2U8zke9CyfNqP02ZspjDxOqyQx0BeSPanumXTdzA4oiYLSOjImwKVaSX9m?= =?utf-8?q?gXD9CO05kgBjUp7wFXgOsrOmLMnICx8+uvplNULqdtOjQIpQBrxUfJkb21JvQz62U?= =?utf-8?q?aaWs0m8PO5bks6uKxF7Tj3EB5OKaIouT/kgX7cElM/OgGlvH35HhUMVSFJy/tvOFP?= =?utf-8?q?abiepeWggvu1QeBhPMgp7t5CHr8E0n74yB8pruDHsFdpGkrlibtcC0RplH4ZP0+ih?= =?utf-8?q?6ewh2/X2Ga4p?= Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: CWDPXRdc+Ec9Sx+SdPMtCe0FJqaQEIl9/bDIumLiXWWvO2fcFPYG10wRJz3/IItkcM6mJXXFTH8jeUHfDdTWgg0ogQp1iGc7lxEdrxe4X+9CioFrxNGrAGLZPxPMFXj0PXKOowDyg0KLpbvv7WP3B/A7inWW/PogE4i+DgInRHdFLSiUESU+si9Zf7FPCjmqh9oW7lcbL0Fgydn3NZVeKfNYlSUny4GoVWLdA3DmQzieIrG9eJ26ifwihuCnvb3SzfMLhyLEvyLbMnkZKCcLNneWqtew8pzqZl3w4R4TK0kyqbC8roN2zd3Fweyj4ZEcZV6ijdmi88o6MawcCv5vQxaBnDYRBrgjLTgCbhw+9HrnKmm2YQXv8BhPsf+i2WWfCTjjjfZvnolBpj+Vv1eCgmg4hmn4JZudIMr04SJZLLn31skVRH+oJGy76Kd2NkCavrLKZNcBjzrBHn97waTl+j2voW+1Qszyb3csJcQWergi+5GVbvejeGG1ueQKc9w8RLk6o0caNXLleGdkFEv9Iin/PLOROjfXIJfR9j/IhteL1YUcjeX6r56ugrnW/t9zjOSy0xcywj+WIZrw0jWsuSuib6/A2hW9nIRp1Gsl0HuiPZ73jwvK/OZy9I/kmO+uoLTWgldvmgdcNk2kK+1fMKmqQJFnwxTXKmkWRxh1xwBGTaufQ6YS00XrRQHoCOScV4ZPKNf4zXTKK6kopZ+6cg7xW31zyKIlAWSgjsFe1KiOp5IUGqukovybuR7/EhDfaOwRvBDbfnC2xPdvFVSgzixPlt0cY645PP6JUEsrCzlbhyBrqpsbclPjHsALnH4rdp7y2BvbQtAlh67xazozMA== X-OriginatorOrg: sony.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PUZPR04MB6316.apcprd04.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71c1e13c-6f20-4dea-47f0-08dbdb8a510c X-MS-Exchange-CrossTenant-originalarrivaltime: 02 Nov 2023 09:58:51.4424 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 66c65d8a-9158-4521-a2d8-664963db48e4 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 6YT+WW4uUA9uqJS0l7EfZcTtbHvBMqty7QHItvtxL08wkL/UY+WhInB5Le0CdKX1jwpA/7wNMFDXO3QB6LJDdQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYZPR04MB7934 X-Proofpoint-ORIG-GUID: 8_D0yQGngi-5g-LDvNoCdITEL0vd4rqV X-Proofpoint-GUID: 8_D0yQGngi-5g-LDvNoCdITEL0vd4rqV X-Sony-Outbound-GUID: 8_D0yQGngi-5g-LDvNoCdITEL0vd4rqV X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-01_23,2023-11-01_02,2023-05-22_02 Since the read operation beyond the ValidDataLength returns zero, if we just extend the size of the file, we don't need to zero the extended part, but only change the DataLength without changing the ValidDataLength. Signed-off-by: Yuezhang Mo Reviewed-by: Andy Wu Reviewed-by: Aoyama Wataru --- fs/exfat/file.c | 77 +++++++++++++++++++++++++++++++++++------------- fs/exfat/inode.c | 16 +++++++++- 2 files changed, 72 insertions(+), 21 deletions(-) diff --git a/fs/exfat/file.c b/fs/exfat/file.c index 7fec9a660734..f954125a545a 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -18,32 +18,69 @@ static int exfat_cont_expand(struct inode *inode, loff_t size) { - struct address_space *mapping = inode->i_mapping; - loff_t start = i_size_read(inode), count = size - i_size_read(inode); - int err, err2; + int ret; + unsigned int num_clusters, new_num_clusters, last_clu; + struct exfat_inode_info *ei = EXFAT_I(inode); + struct super_block *sb = inode->i_sb; + struct exfat_sb_info *sbi = EXFAT_SB(sb); + struct exfat_chain clu; - err = generic_cont_expand_simple(inode, size); - if (err) - return err; + ret = inode_newsize_ok(inode, size); + if (ret) + return ret; + + num_clusters = EXFAT_B_TO_CLU_ROUND_UP(ei->i_size_ondisk, sbi); + new_num_clusters = EXFAT_B_TO_CLU_ROUND_UP(size, sbi); + + if (new_num_clusters == num_clusters) + goto out; + + exfat_chain_set(&clu, ei->start_clu, num_clusters, ei->flags); + ret = exfat_find_last_cluster(sb, &clu, &last_clu); + if (ret) + return ret; + clu.dir = (last_clu == EXFAT_EOF_CLUSTER) ? + EXFAT_EOF_CLUSTER : last_clu + 1; + clu.size = 0; + clu.flags = ei->flags; + + ret = exfat_alloc_cluster(inode, new_num_clusters - num_clusters, + &clu, IS_DIRSYNC(inode)); + if (ret) + return ret; + + /* Append new clusters to chain */ + if (clu.flags != ei->flags) { + exfat_chain_cont_cluster(sb, ei->start_clu, num_clusters); + ei->flags = ALLOC_FAT_CHAIN; + } + if (clu.flags == ALLOC_FAT_CHAIN) + if (exfat_ent_set(sb, last_clu, clu.dir)) + goto free_clu; + + if (num_clusters == 0) + ei->start_clu = clu.dir; + +out: inode_set_mtime_to_ts(inode, inode_set_ctime_current(inode)); - EXFAT_I(inode)->valid_size = size; - mark_inode_dirty(inode); + /* Expanded range not zeroed, do not update valid_size */ + i_size_write(inode, size); - if (!IS_SYNC(inode)) - return 0; + ei->i_size_aligned = round_up(size, sb->s_blocksize); + ei->i_size_ondisk = ei->i_size_aligned; + inode->i_blocks = round_up(size, sbi->cluster_size) >> 9; - err = filemap_fdatawrite_range(mapping, start, start + count - 1); - err2 = sync_mapping_buffers(mapping); - if (!err) - err = err2; - err2 = write_inode_now(inode, 1); - if (!err) - err = err2; - if (err) - return err; + if (IS_DIRSYNC(inode)) + return write_inode_now(inode, 1); + + mark_inode_dirty(inode); + + return 0; - return filemap_fdatawait_range(mapping, start, start + count - 1); +free_clu: + exfat_free_cluster(inode, &clu); + return -EIO; } static bool exfat_allow_set_time(struct exfat_sb_info *sbi, struct inode *inode) diff --git a/fs/exfat/inode.c b/fs/exfat/inode.c index 4a06df3ed4b7..d0ee860f16e2 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -84,7 +84,15 @@ int __exfat_write_inode(struct inode *inode, int sync) ep2->dentry.stream.start_clu = EXFAT_FREE_CLUSTER; } - ep2->dentry.stream.valid_size = cpu_to_le64(ei->valid_size); + /* + * mmap write does not use exfat_write_end(), valid_size may be + * extended to the sector-aligned length in exfat_get_block(). + * So we need to fixup valid_size to the writren length. + */ + if (on_disk_size < ei->valid_size) + ep2->dentry.stream.valid_size = ep2->dentry.stream.size; + else + ep2->dentry.stream.valid_size = cpu_to_le64(ei->valid_size); exfat_update_dir_chksum_with_entry_set(&es); return exfat_put_dentry_set(&es, sync); @@ -333,6 +341,12 @@ static int exfat_get_block(struct inode *inode, sector_t iblock, pos, ei->i_size_aligned); goto unlock_ret; } + + pos -= sb->s_blocksize; + if (pos + bh_result->b_size > ei->valid_size) { + ei->valid_size = pos + bh_result->b_size; + mark_inode_dirty(inode); + } } else { size_t b_size = EXFAT_BLK_TO_B(max_blocks, sb);