From patchwork Sat Jan 27 01:58:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533904 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AFD6C47422 for ; Sat, 27 Jan 2024 02:03:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3858E6B009A; Fri, 26 Jan 2024 21:02:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2BB6F6B009B; Fri, 26 Jan 2024 21:02:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3D9F6B009C; Fri, 26 Jan 2024 21:02:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D3C5B6B009A for ; Fri, 26 Jan 2024 21:02:54 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8787A1C0FBB for ; Sat, 27 Jan 2024 02:02:54 +0000 (UTC) X-FDA: 81723442668.19.37AFACC Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf23.hostedemail.com (Postfix) with ESMTP id 15D79140003 for ; Sat, 27 Jan 2024 02:02:51 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320972; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ibzvTDQvbHWpuZlSBRam506AV7dGjs5LmZoPW0q5Qsg=; b=aqXtJ2FbnpTCXqomphWDR/EEJoi2iUJq/nKw4G45ERM8zzgR37GwLCwYE+Almx2/XmaKsr HNl0vgk+16PBcrVMg4B1TemRTqEiWWCA1KLq9XXkzFZN0f0y0vGK6AnK0eYj/x4iojJhcV wDywgIaVULBg7I8/Eeujv8JpyIkmrGY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf23.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320972; a=rsa-sha256; cv=none; b=Gt/n1UOG3/uNz9P6yShOxofEw3pNtAfFquWmlICkEZfGUlva7C5ZaoRBAbJPZiFB3Bau2W OkLpo3XshH9+DI10t3iaj3ivUyH4HzHyEOBqrxQ14cjsvgqc3uf3mNHwhyHl5eQlEH81cQ 4arip0y9LYqit2hO1vW4Wxn3Pnm0tfs= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrd6mHGz4f3lwr for ; Sat, 27 Jan 2024 10:02:41 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id EA5F51A0272 for ; Sat, 27 Jan 2024 10:02:45 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S14; Sat, 27 Jan 2024 10:02:45 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [RFC PATCH v3 10/26] ext4: correct delalloc extent length Date: Sat, 27 Jan 2024 09:58:09 +0800 Message-Id: <20240127015825.1608160-11-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S14 X-Coremail-Antispam: 1UD129KBjvJXoW7CryfAry5Zw1Uuw1kXr1fJFb_yoW8Gw1Up3 93CF1kGr4fuw1UuayxtF13XF1rK3W5K3y7Jr95tw1rZas5Gw1Iga1kA3W7ta40qFWfJF4r XFW7tw1xAw4SyrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr 0_Cr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: 15D79140003 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: j6d1enmwdt6oz1jxtrrbn4cfy85q91jb X-HE-Tag: 1706320971-21333 X-HE-Meta: U2FsdGVkX1+ObBF1iLpFIJ46mBW+EGSMtgVzQO+jYT5cQsyI/80HLNuSWxUPAvMh1dzNBpH/ktMGq36gShdmFjnkDWIo5OWr7J4VtYQ7KGqK22ZhK4ZfZ+jzIEUp5uqlIIh2aeP24hxw2Kaea/6GfZYjdu9zJtpI2StLBlN2CtTZVjGqEJX1sqXOY2xEqWbZl6Bkht/BSJmMhrcIL0itVLOMDvYzLfPKYYGVJLg26ejQXS6kuutk3shP99YxM4t6oF5sczvL0zTT7gN/e2lOCBFH0RCU3ObnHLCMgYsrM9VAOSApGYPSjMBHM07QBSt+6uOoje9ifMohC9mRAZ/xVHjIdFGfZaZo1AsCqGOATQDo5I2R6ChuxbwjOka392QHG5K6i3gLIug+LZ6Gzmg2ddgRDC3kTF/7+ooy4IBoRcZUWX1m4EH+/jIWToGsIgJ335GJ2gjvGAyo8VNKXVytMeL1x4EWVdbTlCsRXpQRWEbg2j93FwMMw+Du9wdaP0s6tmtIAjoj+aH5YC18crx7H2n/mo+oAy8R3CZAI5LkXvKiURtWVrj2WEfG/F6eSqaEykfoJAag4ABKp/vC3HWhERxGK2fPWiI2u5QWmF3e8ua1zJVRvfbNiYcyrCANPLzF0C9xui6VeLc/M9cuRbKbkKxN+MUIP9+HTfSwsEE5TXTozQgBumTOm7CBRxfcIxM6bmBYvyAdZKfWSpfAHoX6AVGWMEn91guaB7E1hgsQ3TmplR32zPLNQR1p3RPUD0Mo+73E0Jjdfw2I/PH8m9bBAtmOrSMsVqyRABBrkJXexH2Sd8glwW7M65cSj/kscjCRokVUtFHBYL4wlZO4e4JxeLR+cRKZS2kdf+YkXS+ILg/sKHp/vnhN2z8aKdC4Xz0cdPCjUtC5HE04fzpMkMmF8E9Kcr2xlrqHCIKZnKzZjcK1Vvs4zNlfYNDyD7QZDVtOlogKmW9eT0+Lpk4RnwD 8TEvK8ZC DWC1VP16dPnO5LGtV/I00tEKF+NfetDq91Bdh2OdKwuxWaitenIAIuWex++9wet3ZaZV7Jit7MQV7DPTiQJGXP+2Gta7on9PJkDztntFeXiGsC5syFu0StwwwHNhcgZfd42maYX/HgZg4tQc3KBC6/A/aSbfiROgm0mrQ8qPTAKMfkAvloGTp+Shj6o6v3dyEjj60GhhY7n45yLY3OV4xzxnWAjiC4UAYgphNyzs777+uARAO7/SU7jAGVWHXuKis4cQR X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi When adding a delalloc extent in ext4_da_map_blocks(), the extent length can be incorrect if we found a cached hole extent entry and the hole length is smaller than the origin map->m_len. Fortunately, it should not be able to trigger any issue now because the map->m_len is always 1. Fix this by adjust length before inserting delalloc extent. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index bc29c2e92750..44033828db44 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1712,6 +1712,11 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, /* Lookup extent status tree firstly */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { + retval = es.es_len - (iblock - es.es_lblk); + if (retval > map->m_len) + retval = map->m_len; + map->m_len = retval; + if (ext4_es_is_hole(&es)) goto add_delayed; @@ -1727,10 +1732,6 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, } map->m_pblk = ext4_es_pblock(&es) + iblock - es.es_lblk; - retval = es.es_len - (iblock - es.es_lblk); - if (retval > map->m_len) - retval = map->m_len; - map->m_len = retval; if (ext4_es_is_written(&es)) map->m_flags |= EXT4_MAP_MAPPED; else if (ext4_es_is_unwritten(&es))