From patchwork Tue Dec 5 10:16:31 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: 13479882 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sony.com header.i=@sony.com header.b="VQolO8gd" Received: from mx08-001d1705.pphosted.com (mx08-001d1705.pphosted.com [185.183.30.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D07E1707 for ; Tue, 5 Dec 2023 02:16:49 -0800 (PST) Received: from pps.filterd (m0209319.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3B56Qawi013397; Tue, 5 Dec 2023 10:16:37 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=ITZgvUeR24PxtiCoVh5bk7z35mnk8a/6uDYKvWct7BY=; b=VQolO8gdPbQrRhKvYzamcQPKJbeDgHqxbnyisMFlvDJzFKh3RfnZ2xtqUkZVtZTZCuPW eXakaOYbBKGc31m/lXVK0P7MONwVh2aO73AnB/zDdNPBcALvDFXTwsgEcyyxFb8khj9S pjEXCqIBD8GjGWmo17UioUurMM9+CNvQONw+0sVTwQQJIPOwOBEc5yQX1fxVSUmJ+KXW PCK6Ah93KD4i2PS+H2QFibrx/G4hlariNEHnm/BdbLGogczyikpL3+Devoigniz/1Io+ BcBMo2gF98uEXFkrPTl3fGOp+PDhmVTVVGCGQni1IKZ0j20mQecpiZCM5fdpX28qMliS sA== Received: from apc01-tyz-obe.outbound.protection.outlook.com (mail-tyzapc01lp2041.outbound.protection.outlook.com [104.47.110.41]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3uqvytjnux-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 05 Dec 2023 10:16:36 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jdfDZjrjxgMR7i1r0fFitlb/QW5OwfoUb6u0SJm3dRm3jCDzytsgOGovq0Sf2KeBzvqRt37H9WMAxaT4SmHCYsB+ZYvjMR4R8ZlUGCzVfPDpQo7b6xpllJG1gZRKg5vCdMWtR0xI5g81QWPNe4OyNRiT6Gw6oGfpd6ipXOFAQx5iTNlC5ItFvS1s+Os6GeT7DNQz2Q68YDouHY5zgbCor+tDj0SrI5k5BvlxABv+1PHvxA+yASLcyyAnm0qmt6f+W+GvKHjmPT9USiQT9wORYcWW3p8jjZzXZfsh3VGxLlWfW/US3mOtr+7FfNXVmP9tBqMA+HEt3g8VS2BkLLMmJA== 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=ITZgvUeR24PxtiCoVh5bk7z35mnk8a/6uDYKvWct7BY=; b=RuL7Ezcomlr/x8aDi48D4CekmKIwneIMs8vNbJfERZ2B4qAvLnyRjJ80tepHpUUUToGaCUjTElzfcpsHgLWz4Iscq2Q106Q5EWFlHW+BejcznOh+knuRpRwOi1eB5K/FRAp5QkcW5J6dnVNSulcyXPW1YuoMEE8BqE7SxlZstCMqEI5LJ0OEltEXxC2w9gKC1cYwal1yvbb1BTd9zNIo9lbLqZizw8p8MVsWmdJAR/bfLAVRoNGyKjM1y5DiovWV9awS2gJM8us42Vf0SunPonPVPHV2R9V5nJEexDy1NACmI87zw+pkd63w6ULdBRSkzKnuvciq3LcByb2URB0czQ== 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 TY0PR04MB5633.apcprd04.prod.outlook.com (2603:1096:400:1ae::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7046.34; Tue, 5 Dec 2023 10:16:31 +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.7046.034; Tue, 5 Dec 2023 10:16:31 +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" , Dan Carpenter Subject: [PATCH v6 2/2] exfat: do not zero the extended part Thread-Topic: [PATCH v6 2/2] exfat: do not zero the extended part Thread-Index: AQHaJ2Qdtym2rS1EE0O6pSv/WwmGAg== Date: Tue, 5 Dec 2023 10:16:31 +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_|TY0PR04MB5633:EE_ x-ms-office365-filtering-correlation-id: 80086963-2332-4d8e-20c9-08dbf57b404e x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 26JXjnBoNVPuHz9ve9y2zZ/1r13c4q7Bo3C9VCQUc5VOS1TPaffR6pNcZn7TVgYnZOP9x1ixZR54xS+Ehc2S45EwosoZimjVyitTjaHRdwBeowHY2NQTxt8JPVPSjEsZJ589kMfDSf6q2Ma2jOeV16q/H85yC9ORkBK7bxWxH5352ToF9DDg4KI5XQXc3fU3Yhl1YfGAY9d3Sr7z9JqDrbeEVJeDUY3Sb/ByYecrGimfMayeHsqGSnuJ5uGNxuK+B00gWvu7KoUWMK75pynCXRZ8cV6cl8jOBIKooEQTjGZ1bpwqNNomrC3m1ta4rppWQpf8gsruXeJ1BG5bB0KKCdXTQ772ipnEyCwXsbyNSpv8fUc9Xt0Uad+7zySdbnQW+Uwt9xCdv/d08q9UaOADTkHDRhyjszEav0d/ckEWPfWCJNtVPYfj46D4pKqIPls3jo26Dnpyl8yk6kk4+Llo1kT6AcD6/bEVeVGCRUjhsvkZ885N6iOTssYdu2sP//6s1ddJb2k3gqH3kZwXoTZmDb0uUyhLhYnWcrHGSS6Xa1HvGWwmuR5TNTGwaVTOuLAW7VHt8uNJNKanSPzpBeTffAUlVRXXveCxeV7Kr6vSQM0FLPdoz/ZJ/teyVpuYzPqq 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)(346002)(396003)(366004)(136003)(230922051799003)(64100799003)(186009)(1800799012)(451199024)(76116006)(110136005)(122000001)(83380400001)(71200400001)(478600001)(6506007)(7696005)(82960400001)(66446008)(38100700002)(8936002)(8676002)(4326008)(66556008)(54906003)(66476007)(64756008)(316002)(9686003)(55016003)(26005)(66946007)(86362001)(52536014)(5660300002)(2906002)(41300700001)(38070700009)(33656002);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?utf-8?q?eCDkSFWDg77CGkfN7gonJtjRC3qF?= =?utf-8?q?L7J0ZmD3wpXLLXKDrAndlu6bNTUAfaubYvZ2M3Uu5aseXSlVsG2j5vx912On+whl5?= =?utf-8?q?SZLtpQQ4o+dIrlWBRdVOeE290kFpSZI1CklGF1xLz11SN+hCJR2fiGkgpFrI4wJbV?= =?utf-8?q?T2yg064POqEzRlaNcU0et//C7caOVJbPDPOSWO9Usf43zLnWl1ZC3s17IA+k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KRk?= =?utf-8?q?rUEtBapz3J5KSfSUZCEbyhEzvO4LkhRE3Gw/EYNHgqiSPCKnIfuCbCC5vQte3ia2d?= =?utf-8?q?5m8zJl39pvpFQKiDnmddSpO3X8TuNJnPFYnYiNOVwWNlzvcLm3CZx+bmUj303DWZd?= =?utf-8?q?i1JoiC86hBXw6MKf0QqBSm4Qs+9+cj3rSuUDe5JfVKOMN9iv2cam5vPeHxlQVTLv7?= =?utf-8?q?DF3IerkIhP9i6TKt/bYfYj0dsUhytZIS+7u4IasLDKN+aMRfjtNSZUXARJFR0twwD?= =?utf-8?q?X/+c001l3lkQwzYDb2U25LZipAjJY492Hj1OyrV6eLYeKOhbihJoe6LHyq1OkdfM3?= =?utf-8?q?XYk9bVcxrXNPAg88VSgHep11LdQn5GdalJ3b284gE0523bsbHmWw2tkc77dG1OWn4?= =?utf-8?q?od21bz8AuvgS+pGUbRjYyV4rirl131iqEUY3uGVoObNTN5ZxUo7b7jDq3CQQWb3uZ?= =?utf-8?q?h0nWyeT7B/09?= 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: WTVcqTA4CJFSimLJA0dR5Spu7ugHkPXEpfMf82uXWqt4a6GQlRAfO9PaydH4CoTj5k8ZJaUW9zEGowxpglJXaBTTQ27iegRWLVl9SYYEudL7KFlxr0qj+QPlcMfdIOiHQTPSVtwmWSY1xq27Ik3jqWvJon7RZcSvv9PXCAezYIRRtNTpjUCUb8JSuZWLAO4BwfaXoNcXWFFCY+LJLGul7oKUBFI+XmRTQIOahU4v5qgcxjaXPpFmyeoDu3nrmgaqWMdkv/b35ktUY/f35V/gzGapGvK879ji9agK2FbryVvl2oA/yX8oSXFzYp+h0a20A1Z02Sp7Qc8l6C/Hl8ASiw5VBjWFYMhcIeEOMm86R0Ih7vhrgyTC+lWiZcNlOq+7HknsnDGHcgvCuvW58RQgXYZyLPWLX074HiQKuvp15+Iw0dXa+V7JTe4cOop6pEi15nnBSYC9K7fvUq9b8zQSt2AAnMYc/dh2hFJySOZDSVFS9LKbBGQ0ndb5zkcL9jnAeXmwWnFA24ekWacjRw4VqWiEirNL+00v4gf5ZaYTdCEa3+fdU5Q7eSlP7XIzLdJ6SOsvjdMP9/8p+Zvq+Aoq51ZvgneJIxGsCqE/USwuS1rWQwuI1hKp2RjpPShDeEbO6RgOm/B+ow6WoGa8Z8NW6UiCsJFIvFzygmRvGSKXpc/0tgRRj+pfBKm2O1Y4tBt4swGoPyEuiBw4QZiGMJ3I3yFu2eR29v9aBPoS6WaVdu9ond6ao/ZvB7/Dk54vL78nEuxKSWHtCT2tP095njMBuWh+eaFZwBG1tRR/wP2I3SwJrZoY9gEDNzake4D0hh1lrDtU3/LbRQtCs4em4V/Chlfwn37LQzA2SuHmXnJYtBPCEfIt/Ehp3klEmYpRwUSY 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: 80086963-2332-4d8e-20c9-08dbf57b404e X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Dec 2023 10:16:31.1496 (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: ECkqXe2YBNOYlD4VoW9RX+70T8JTFjAwn8JP53CItWWjeh0xP4UOaXTFs9P6OUk7WjIQqiVkS48oNGiWKf+zxg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TY0PR04MB5633 X-Proofpoint-GUID: cDzq66cGDkv8Z5DM9J4sxnnyT4V-sjai X-Proofpoint-ORIG-GUID: cDzq66cGDkv8Z5DM9J4sxnnyT4V-sjai X-Sony-Outbound-GUID: cDzq66cGDkv8Z5DM9J4sxnnyT4V-sjai 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-12-05_04,2023-12-05_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 270e2f934124..d25a96a148af 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 b02677c9fd45..522edcbb2ce4 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);