From patchwork Wed Jun 28 01:52:52 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: 13295135 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA298EB64DC for ; Wed, 28 Jun 2023 01:53:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231172AbjF1BxR (ORCPT ); Tue, 27 Jun 2023 21:53:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231133AbjF1BxP (ORCPT ); Tue, 27 Jun 2023 21:53:15 -0400 Received: from mx07-001d1705.pphosted.com (mx07-001d1705.pphosted.com [185.132.183.11]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CA94297B for ; Tue, 27 Jun 2023 18:53:14 -0700 (PDT) Received: from pps.filterd (m0209325.ppops.net [127.0.0.1]) by mx08-001d1705.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35RMvwAt030254; Wed, 28 Jun 2023 01:52:58 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=hkaYrArXpofIodO/hHnl8rhYT7ma2jWFcJZWfdphFJo=; b=E4405+ecoQQdEFwHTES4zIXrum1TffrlJ6p/OXmc8G6S9Rr94+cveBM3+ZWx1u85bR7j TFILwZSEmdMqLW38FTjFwnl8og/nBTjY4RYPyHmJ/4bgsDqtnSRYbtpHQcxtQ0rStamt kBVlb3ssRk6CvfyJf9SDLX4kB4cv63qcKOEQI36446O1NqtnKmxB2BLMLUvTX/wx4UP4 Dw1YKZYjhXyWxDpLea1EvbvEkKTeLRqWVX9f5qKwtSXsP4PpWvT+u827qgy1vEr5OHcS c5ijvkFZiK8yiU1FAoeA88TNd0w64+RYuiDyT7UEy4yOc2KAyaVN7Q/Tie/kqZWWGHta HQ== Received: from apc01-psa-obe.outbound.protection.outlook.com (mail-psaapc01lp2047.outbound.protection.outlook.com [104.47.26.47]) by mx08-001d1705.pphosted.com (PPS) with ESMTPS id 3rdnqy3mq2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 28 Jun 2023 01:52:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GkRxHuJB7zDfpUy5nmBvCFKjK0s6LjyXcgJ7JFkN4dekAsuVEv5jXOTiua/hqpEj+/xTqyBl1DObNoT8WRHjERz3F5P/sdpRzTfhzcNunpXSPUp4N/HRZ6mO94MBd+rmnead1om7tesctFoSzC3QOOcA6HjkfM+YC4l1c535qEasuGeRtmnpZ8teaQr89dNh8VVsdjvk+2Op/PkIkSqq5Q5NGfYqGXWHpgqJvwliJknei4xXG+/ziMROGkRufrpK3ZPsvGoIg4GjiKZa2WBtCSnY0GgEz/jTChHbgLBHL3mREhYUmI+L27TPsGcdTNMAjTRbQk7J3GMdOzwAon18BA== 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=hkaYrArXpofIodO/hHnl8rhYT7ma2jWFcJZWfdphFJo=; b=gxMibElQQ4Rz62DCaYWbsrnJ5RICoHXB34wykCFq0HD4I24LsQcwfDyOvPcht0x7EMEyt/3ukz4lIJfjN52yvlbmpr4f3pt0isP1aRUguRdeyzqQlJ9Zqq5E9nfuHC+aQALxOwXlD315gE2hHkpM2Z7YSaa4fAN367WV3wUvfhjE33d9MXCJn7DTa8YErp7/RNF5eSRWypwuMoigwzOI67xNG0OezJ+gwlG26TFkND7KK32/HB3sAsOmq+UBB3NdGU1K27BZeX57tCFmd9hxttq6FhdjJRkHquQedjHeCfLMvtD+6hHQ9/qMvwVaf37SbduR7AuvM0rFuX4J8ZI6GQ== 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 PSAPR04MB4389.apcprd04.prod.outlook.com (2603:1096:301:3f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.15; Wed, 28 Jun 2023 01:52:53 +0000 Received: from PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::ce2d:a9dc:4955:5275]) by PUZPR04MB6316.apcprd04.prod.outlook.com ([fe80::ce2d:a9dc:4955:5275%5]) with mapi id 15.20.6521.026; Wed, 28 Jun 2023 01:52:53 +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 v2 2/2] exfat: do not zeroed the extended part Thread-Topic: [PATCH v2 2/2] exfat: do not zeroed the extended part Thread-Index: AdmpYxJaQT0eJpq9S2qk9+xpIeN52Q== Date: Wed, 28 Jun 2023 01:52:52 +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_|PSAPR04MB4389:EE_ x-ms-office365-filtering-correlation-id: ee4826d8-7cc1-4f97-5ed5-08db777a62c2 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: PpH0fyK6V9cqk9P++HN6PwKdOoCdsNELwInIlZYYqQ5ld7PXv6jGJd1eSav70yxzBartKkK6tpY9l0a7t30k2YZ5uq78FIaA3vF0iWN+0+YzYDs6r5yQZ2tIltixB1m1mGN4pFhv1L4qOOjbjtJI8MZ4Npai3x+N+s74oToyoiKFlWYFQauuHP0oMdMMXviXxVG5B37BxxYFnz9bd5Ad2YHlH4WzEWfmHB+M9BPHzelvGmspPzEgD7Pi8Q/8wOgjkRbRUNHpzUtnXZabFXJh22CaFPEr3xstUhF5P/c9dp4bUyw8U+H7L5raUUU8BLgDV5oXr4OfWIDwsxWbsKlxFEo4dw5OEhJ/ES5argjw1CtzgGe+V13nJJLT3PmQfOdOFjwJoED4A3nYetOEJ4W545vnNgKRQNfu+MmxkwAhp3qNYXmO+4yC0VQpBQ7aGi2UvhfPrEbmX21qM5zozzoV05u6LBMVa8KslPVrEH/4T/CLydlCjmq0ahCcdF+4fyn+zqpvRw1VkrdYy2/5U0MSnvqG8WXvX6zVX1O8KdY6jTy2GpHmba6Moa0LfPmF2CUV7b2kA9vA5n4CxdNqkix853RkXPIhcQLh5IzYRfXX6pgQUDR2bsUVgelL625ZFB8H 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:(13230028)(4636009)(396003)(136003)(346002)(366004)(376002)(39860400002)(451199021)(5660300002)(66946007)(41300700001)(52536014)(76116006)(64756008)(66446008)(66476007)(66556008)(8936002)(8676002)(4326008)(316002)(478600001)(83380400001)(38070700005)(55016003)(26005)(6506007)(2906002)(33656002)(107886003)(9686003)(186003)(54906003)(110136005)(122000001)(38100700002)(86362001)(82960400001)(71200400001)(7696005);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-mess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3kBaEZz1iGqZR+MRvCfXiyeLAXy?= =?utf-8?q?MFBSu25cLewY1O0OZ8fyHUpjYgNbD1byZM/1nWQ7GdwH1tEnM6PcpendxsGsWs9v8?= =?utf-8?q?egXeJwNcS8DUyV7r97hWGbbGD3bBt74ckOFw17IPsGvWOLqy6KaeM5tPB18Ba1cvH?= =?utf-8?q?aicyCIPXQLpIy56vVFQa4AireuZdzBCC28WfZoAV7Gu1oWwyiZaz3sQQxX/R2HL/2?= =?utf-8?q?3SZq78/FAzVA8BhpBbP7+fG4/2oHH+KDIgmk8c3A7nUPuqEWJQrgfWqs5AEG4KA8f?= =?utf-8?q?nk+s/xQMbXzcue7dDaB4D9/KyZHomATzxUZE7EOJgCvLow4s3eLQVrk8Lyrqdpqtr?= =?utf-8?q?6W6fzMP9yDs6LdMfCFJdtRMsuDuGef5wmHqKWK7ESTsfQIJTisAd9TGvX+NDXmJhR?= =?utf-8?q?lZX07bLOA7gstNny9jqIhbT8vvCoJ8asRrOvRJ0mffs0mE05PnSGx4KaLrCbbqgDn?= =?utf-8?q?VFHMO1uqoTanLWG6EYKEsWQn64/BrJaWcXBF9/tABGbjCNfl+CQo7rSa1IFmnfnV4?= =?utf-8?q?yvq+3r8M10tB0vKNOlwu1cVc3QYDEsr0l7TtF8zpUkb5+/rhc+mkA7HjnG1BcybT8?= =?utf-8?q?SLSuzniFIXy+nzzORKwgJQ+PRRRYOHTCvEjGN7LlXgVYTypzCDwgzzub818mzj/iG?= =?utf-8?q?aTf4p+VA9P15?= MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: MKDxVOurGhkR3IkS3bcygor6q/9RNKivRtZD7AoybLuT3fO0UopZMKLuC6GHq5giVR7IZe8FBx+QBA09ojbUp4oZJQeaiMK1w/6i0WsJKfgNhQMf4rDXLRewyf4FG+fV4q2NLO3lmHEWa8NITsB3rMHJSNZBpcAG9n6BKmea6MskMBZBO9AszlRZqoTbKtq2LnveHjaD7+QT4VtZD7VWLlwBxWUvHRI4VCIM74wPS8iOw7LNXjRrDzHO0WaYz2esZwec5wh3jrgRD4VwQqrzqz+jt340VlKnvCfa4JUu14J9X55fPPi5oqW5bRn09bTaC8WeO9Cll0ZOcOAS0FARwh//MlHowGLEb5dOZ5vz2MNt2nYwwW9/+j8FWwEWZQZnO/SULBt8wKF/FpT6flgzemgvy79vsM703KPjMmUD+yPifbWZOO7wQCwprw3Njfq92kPiqGgxFLMLKHEqybVBz59lpFXPA8+sDL7sywaFNSJebTaH+v5XVcELicuRNoGsfU9lMtZt0V6Hs+DxDQIOQWx5FDgPbdtZv3chHisNSP9KaI79PdKTev5dtgE1Xu61wAiq8acfOVMwL/wtGByU6eOMhWAgpFEBHEoCav3Oasj3ESc9aTSw43bwzckUYmsf8c+y3GYq+VF9ngx0k4Ur99KMeuAeOOrzNRic1z+YiipvSMgnQPtXGHpmJeDGAnQ3ocPc5GhOVXHk3zdYJUqQbQzMzkpM9QwVXdUXhLsqtAaFumMGDeAoe9j4tCf8zame2puwGmUgyliZ0AzX1M1wSwWvb/qRNTNU7FGOZDQ/fET7fIWNqO+mpkdiCF8xj+j4eIvU6AMeTK7RyFoQcjIbGA== 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: ee4826d8-7cc1-4f97-5ed5-08db777a62c2 X-MS-Exchange-CrossTenant-originalarrivaltime: 28 Jun 2023 01:52:52.9154 (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: rQTjZ88VVESzHrpNbPxceYjA6+TnOPjUVk608O4IkAT6OCmnrVyd3z4D+Zt9awFTIPCNORRxTsMwOdfZHy5Gdw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PSAPR04MB4389 X-Proofpoint-GUID: xgKxvZL3wO7dXfllLqzk4F-st6QEpLsa X-Proofpoint-ORIG-GUID: xgKxvZL3wO7dXfllLqzk4F-st6QEpLsa X-Sony-Outbound-GUID: xgKxvZL3wO7dXfllLqzk4F-st6QEpLsa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-06-27_16,2023-06-27_01,2023-05-22_02 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org 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 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 76 insertions(+), 1 deletion(-) diff --git a/fs/exfat/file.c b/fs/exfat/file.c index 8cd14bc16857..62a21c45517d 100644 --- a/fs/exfat/file.c +++ b/fs/exfat/file.c @@ -13,7 +13,7 @@ #include "exfat_raw.h" #include "exfat_fs.h" -static int exfat_cont_expand(struct inode *inode, loff_t size) +static int exfat_expand_and_zero(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); @@ -43,6 +43,81 @@ static int exfat_cont_expand(struct inode *inode, loff_t size) return filemap_fdatawait_range(mapping, start, start + count - 1); } +static int exfat_expand(struct inode *inode, loff_t size) +{ + 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; + + ret = inode_newsize_ok(inode, size); + if (ret) + return ret; + + num_clusters = EXFAT_B_TO_CLU_ROUND_UP(i_size_read(inode), 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->i_ctime = inode->i_mtime = current_time(inode); + /* Expanded range not zeroed, do not update valid_size */ + i_size_write(inode, size); + + 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; + + if (IS_DIRSYNC(inode)) + return write_inode_now(inode, 1); + + mark_inode_dirty(inode); + + return 0; + +free_clu: + exfat_free_cluster(inode, &clu); + return -EIO; +} + +static int exfat_cont_expand(struct inode *inode, loff_t size) +{ + if (mapping_writably_mapped(inode->i_mapping)) + return exfat_expand_and_zero(inode, size); + + return exfat_expand(inode, size); +} + static bool exfat_allow_set_time(struct exfat_sb_info *sbi, struct inode *inode) { mode_t allow_utime = sbi->options.allow_utime;