From patchwork Thu Nov 30 03:09:56 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: 13474034 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="kUWrJ0zK" Received: from mx07-001d1705.pphosted.com (mx07-001d1705.pphosted.com [185.132.183.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C062210C2 for ; Wed, 29 Nov 2023 19:10:09 -0800 (PST) Received: from pps.filterd (m0209326.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3AU0GcFF005456; Thu, 30 Nov 2023 03:10:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sony.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : mime-version : content-type : content-transfer-encoding; s=S1; bh=njTA1K9IEubiI/kq/FpFWTg00khYaVYsMiM3zPJnTvA=; b=kUWrJ0zK1Xh7e7l/QkTMDTSaPwSZnmeOTJoDFxgjo66mtg/Gzz7eY8kTVl25ZSlWSByJ biRAIUDX01m1XSMtnK2WJ2cmlkf/a7VJgymApVW35zQGWT6AnR6Y+OPce2M1InnnARZ+ 6vfVbAX05kYGM5sxae2bVcmas16u2PQC6Jmvbq0msE3FEtRCL+Zy8q0nmSfqkIURXwRf skHSkzvcCU7kC+gR4ciDrJZOKFB0F2cC86RDFE5rg1ZrY1PVEczQps9yS2DytaIs6QbN K3nIKXHDKXrfaVqxchdB91x+YrRymIo1eCVsmgM4OwvXuWo+uYzSuY+phrW0qiryDVHO gQ== Received: from apc01-sg2-obe.outbound.protection.outlook.com (mail-sgaapc01lp2110.outbound.protection.outlook.com [104.47.26.110]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3uk74k51c1-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 30 Nov 2023 03:10:00 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hoA9rQ3KwpwHjrQ+0dkGRVBh/TDoYRwCh8M3zIUruf8Z5AMKYcLXjKc5Vk2Vl6yNGvlKx1eEwnUjquWFCkvOiQXfXDhjMGsE6i+CMVtkbbOmFRDDYoPq/WiH2X+bFCPntajDMZBuKIyqguqh9gin2WYI6fqphSLOsgMY+o+Qoso04uweDyZ/eceqPNSaZagSDE4Qieo7NQt4+kL5k/A1BL0U0TvdGKH8YHtLEZsZAGBAS0STo23ZKYsLeki5AENs3R7PFkGZl1lfQMveZugxsMgiAwLFARXcjIV3KDV7JmeY1uP5rO9KbMaYWCzsn+8GE0T72KBrLOsle3yriGbCjQ== 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=njTA1K9IEubiI/kq/FpFWTg00khYaVYsMiM3zPJnTvA=; b=IFKNUUjhNhgt7STb5upREuE4jMKZgFveUIIawuJnYhXq2k+tmF/JRxywc/kjxbVgoxCmGYkKhyC6lyvmK+rkjLzrxWljdTwWcRZ5mhl7/kZLSdOvO44Z+Q5eb8s8yRAisOkCBUpIEpfknjuOzBK24OhjSiypAn2jEnh4lyp9XPPvegCWLmh1N1iFBcg8PQoxiHaxdca8NtrngsSJ/agApHSoGFdAIJTblUuoXmESWhff8PwObsm/NNLlWyyhJwYJMc3ZKXuBUnz9JwOKfq0qK/ZrOApNn3sEpA++1DzliKYmDKNTAD9dmmjr3a8AGisI0UzKVifaee8tDHb3eBsMkw== 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 SI6PR04MB7955.apcprd04.prod.outlook.com (2603:1096:4:249::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.24; Thu, 30 Nov 2023 03:09:56 +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.7025.022; Thu, 30 Nov 2023 03:09:56 +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" , "cpgs@samsung.com" Subject: [PATCH v5 2/2] exfat: do not zero the extended part Thread-Topic: [PATCH v5 2/2] exfat: do not zero the extended part Thread-Index: AQHaIzqx2EwE8CcrTEWOX6kqOI98NQ== Date: Thu, 30 Nov 2023 03:09:56 +0000 Message-ID: References: In-Reply-To: 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_|SI6PR04MB7955:EE_ x-ms-office365-filtering-correlation-id: 09aeeb64-1738-4875-ee8b-08dbf151d477 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: hXgzP16w7Xlyjpit+/XXJ8eTt0KCpgYu8rZrOeCxLdAJ0jPrIooo7iHC9sb2RDiHRNHASd+9bvt2vlPKLnFg6xoP9sNlXhy77HiFdrMCE2IV3wvUghGKiM21geyJZmIzwMMtzyWDrIn5MmYUJnpqWVvns2+U4G8yITissXnZnDpFo0zvenW2xA1/B3qxJMedOUWu1A7Py0pyPUFSHFP9lSN2A/1+maVMUDuIyQvmg49W6NWYjmvatPFRfS2gEsaT/MRjSO7b3bkFb08LKRjRt+2yFtsKJX96XJVDYK61HG8WU4t0K9tH/Wjy+bMzzZbQM9qENnCsE5z1hw7iP0AuSKwj+w0qSTAE8OZhRKu5cFSq+aVMyWPqUaVYIwIuTXV9/QZAmU3G7FXsULs5hTu74vcF87t76Cr8VU5fzeAobrlAiDVsnWs25+u3PRNadEhG8NL2IAeCl4UBdoU98kQmgi0ddJ86yeMv3tXOkl4qj4Hy6O2NLGOpBawK/3tjyxLhmdD11jMoTH8Wy7VAOAmtsWpZx1dXEt1kCYqErDiuZmDuJyP4EPE/7LzEQl2w3hv37Z6TApRbJc2zcuG3tcsQmQKPnxde/KW7c9EiavVhpQmKtqkQRfbVeulrPosMF3+5IV6ByvzsFLCY09MY9lSyafW2LfVeffKuKUTOIpN7Cxo= 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)(39860400002)(376002)(366004)(346002)(396003)(136003)(230922051799003)(451199024)(1800799012)(186009)(64100799003)(5660300002)(478600001)(26005)(9686003)(33656002)(7696005)(6506007)(41300700001)(38070700009)(38100700002)(122000001)(83380400001)(86362001)(71200400001)(82960400001)(2906002)(202311291699003)(66946007)(52536014)(110136005)(76116006)(55016003)(66446008)(316002)(64756008)(66476007)(54906003)(66556008)(4326008)(8676002)(8936002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?2Xy2MxjmKQfIqAIcNDb5Imk47RWV?= =?utf-8?q?WYgj3hD88XsXObPV7F68C2ClepvtleH/Z/Q9gmMCmCeqWD71xEzi3crGD7QyQm+cY?= =?utf-8?q?B8CwhJfN2LAqL3SfF+8160BVQHkaYA+ZF3M7Uzss3pvlnbrooYFkz+Qn4smMyDPJK?= =?utf-8?q?KGnJY/aa2M/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KkGvkoj6cpPeL+6Q0fjEUsUVjLumEslC9Hn7PXRPec5reABa?= =?utf-8?q?JdWqz3h444BrsWLUVTImnvgI7igZX2INQbB7j3cS74X4byxs1p53Csl7xDbOKanmy?= =?utf-8?q?qLFYJb7YZsAYABNx8NJlDYGKVouoZpPvw1Yh7xeBLbW6Or0feqfKcGrhLZZDw4DCA?= =?utf-8?q?kSVRUuPi5VyorJkeWInNQ5sPut7lBfs1V1Xx9vR/hCckQKOTbiuWhl9GHlOUpWfW5?= =?utf-8?q?P7p56xPqvXwa1h6WiarOHcIrLTOkP2fXLWMvZ+PlqM4rvmqRoZuNZpaXRzN1dry8f?= =?utf-8?q?jFqDRz4+TKAX4IzSpUDTvvOz6GSTFWFlpFI3cKkoXYHjIenDVK9pE0D5u1pZXpEQZ?= =?utf-8?q?0f/FsAgJy9JfL9rg58RvUetiIAy0wGFViXUr2Tpsgq4rVHFIUuAwSJffjUVB3qgWq?= =?utf-8?q?c9DDiw/aAj8JzUO6tIAiFEJQaU4md7gARV/w8y1qZImiqwoZZGBpj9wX6s6we9xju?= =?utf-8?q?/2DmPvqPKoRg?= 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: WprjsCYzv/truNzKr1yzFwpLLrLjPuXe3Fp6oiYMOhQPBFLBV1lydGtIpfOKGwUgRYIuZMsQSIwTKp4asF+Rj10CpB2N/A/xwoGHLm3rFdPyYssiMCmPYdplytJjh72K9109egc1fobQUbqTNqiUs/TeEoDeM1WcndKwIgAiFs5jJviW5+VGe3xRB8FOTAB0gMIuavXmfuHLu8aY0QbJrjH8mumy2SN3kA90JncvO+dWqzaNg54i9cR6xRU7LW0ldTE5+WKdopZG8GVeyer7EXXp4px6XRD1eX9snzNZbBzr+gT0lbDjIwXDRuX+c0y80qbY2HUXV7OguFgag/qmXWoIPo0SnDh9s/pIVLqwz8aT/96YXOWaATnbxGkvmkPOHH4CFGmqttBWKNl2wRfPaBJ/cBbwueGyMFALRSVEz/vCUUd3Anbug8PSMp0VlFbExs0yHeuuiHrT3GkV9n8aicAplxBXQ0vMAuJKfxDsGL3z2ekWfLt+D4zswhCDSFjdiPqSeJsvEo3h/xyymAXsb+raV43Znn1aRIazkncoOF2LdPSIViVJzdWdLBnSgWkSrnxOn1sQfgcKK94medeuSykCRaaWEc0SpstGi+owI5L3tPYv0zAXdqanNcxY4e8Tuc7a936RBq0jR58pM1kXGXwisTW33Wn+F43Kh9782aaXEN93ZsQezx+DQ1DB+bnb8ENCPZYbzB4CCAH5ZheKQm0q2waUNhiU+eS7CRo3lwHo/V9eGCGJxOHqimX5MsjDKVLValI/f8Fd/sZlMuycsi4H5Wsa1gzCGxUiDjbeOTyJu30NU+uJrGYjF7+5I27ZIVgL6MiWsho3WboxKOL1KA== 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: 09aeeb64-1738-4875-ee8b-08dbf151d477 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Nov 2023 03:09:56.1782 (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: RHC44U/Fa+/Jbzm+iKmKhgZpkRL3Z3qb8dgxXRg2VoW4N+W32oCdn/RLJqyudhnecQq50Z8EzLr3qtAH2fY6iw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SI6PR04MB7955 X-Proofpoint-GUID: wQty-wx7GzeW_fWNSecezAelooq3QHLn X-Proofpoint-ORIG-GUID: wQty-wx7GzeW_fWNSecezAelooq3QHLn X-Sony-Outbound-GUID: wQty-wx7GzeW_fWNSecezAelooq3QHLn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-29_21,2023-11-29_01,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 | 14 ++++++++- 2 files changed, 70 insertions(+), 21 deletions(-) diff --git a/fs/exfat/file.c b/fs/exfat/file.c index 154f39a03a69..3d01a4eefc11 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 a7bb234c8bb1..9793c64f4ad6 100644 --- a/fs/exfat/inode.c +++ b/fs/exfat/inode.c @@ -75,8 +75,17 @@ int __exfat_write_inode(struct inode *inode, int sync) if (ei->start_clu == EXFAT_EOF_CLUSTER) on_disk_size = 0; - ep2->dentry.stream.valid_size = cpu_to_le64(ei->valid_size); ep2->dentry.stream.size = cpu_to_le64(on_disk_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); + if (on_disk_size) { ep2->dentry.stream.flags = ei->flags; ep2->dentry.stream.start_clu = cpu_to_le32(ei->start_clu); @@ -340,6 +349,9 @@ static int exfat_get_block(struct inode *inode, sector_t iblock, pos, ei->i_size_aligned); goto unlock_ret; } + + ei->valid_size = EXFAT_BLK_TO_B(iblock + max_blocks, sb); + mark_inode_dirty(inode); } else { valid_blks = EXFAT_B_TO_BLK(ei->valid_size, sb);