From patchwork Wed Apr 10 13:28:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13624582 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 C91F4CD1299 for ; Wed, 10 Apr 2024 13:38:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4EB6C6B00AA; Wed, 10 Apr 2024 09:37:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 49B676B00AB; Wed, 10 Apr 2024 09:37:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2EDEF6B00AC; Wed, 10 Apr 2024 09:37:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0F6496B00AA for ; Wed, 10 Apr 2024 09:37:13 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id DAB5EA0678 for ; Wed, 10 Apr 2024 13:37:12 +0000 (UTC) X-FDA: 81993723504.26.7F3172D Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf27.hostedemail.com (Postfix) with ESMTP id BDC3240008 for ; Wed, 10 Apr 2024 13:37:10 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1712756231; 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=1rfO3bDUWjwaLs+wdCUIuN/1ZGWNGlnDZNmsSH0BvMA=; b=DAtM4EzH9kCcF/0taJDuG4uewGCQsDi6soGB74IPwvojSw3D/3hZrBn6g31PKoNbIHb4m7 E10m9xcfUx/pWSf5x3yp77oA/pG+PS5x4cuOzenOb6WUgnhbxVcBOqD/W49G0LfXol7EP5 6lxyWQM4j5Njl2nxsIhAAJEBmqLosNQ= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1712756231; a=rsa-sha256; cv=none; b=AV8u7l9kTw5r7TzE/cmLzW3h+cDuEKtCmu5UEqvmJHmaPdXgvyQknB+lK9E8U7dO6dTZ5i bizOM4/XpoWME963+B5eJNLwotAKPWmRG/TMiJxNUT/JYqnuwuLnmDRrneP5ZZ40mtEOJU 36129lzt/SYbFZtxfBid4AIS6n9wuRs= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lZ33f8z4f3kjJ for ; Wed, 10 Apr 2024 21:36:58 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 427C41A0568 for ; Wed, 10 Apr 2024 21:37:05 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn+RHolRZmeCl4Jg--.8806S32; Wed, 10 Apr 2024 21:37:05 +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 v4 28/34] ext4: writeback partial blocks before zeroing out range Date: Wed, 10 Apr 2024 21:28:12 +0800 Message-Id: <20240410132818.2812377-29-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> References: <20240410132818.2812377-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAn+RHolRZmeCl4Jg--.8806S32 X-Coremail-Antispam: 1UD129KBjvdXoW7JrW5Aw4UXw1DtFy5XF47Jwb_yoWkZrc_Xa 4rJr1kWrWftr92g3s7Cry3ArWIyw409r1fuFy0y3s5ZFy5Kws2k3s5Ar4xZrZ5WFy2gry3 Cr4qqF48WF9rujkaLaAFLSUrUUUUUb8apTn2vfkv8UJUUUU8Yxn0WfASr-VFAUDa7-sFnT 9fnUUIcSsGvfJTRUUUbDAFF20E14v26rWj6s0DM7CY07I20VC2zVCF04k26cxKx2IYs7xG 6rWj6s0DM7CIcVAFz4kK6r1j6r18M28IrcIa0xkI8VA2jI8067AKxVWUAVCq3wA2048vs2 IY020Ec7CjxVAFwI0_Xr0E3s1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28E F7xvwVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJr0_Gc Wl84ACjcxK6I8E87Iv67AKxVW0oVCq3wA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_GcCE3s1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqx4xG64xvF2IEw4CE5I8CrVC2j2WlYx0E2Ix0cI 8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwAC jcxG0xvY0x0EwIxGrwACjI8F5VA0II8E6IAqYI8I648v4I1lFIxGxcIEc7CjxVA2Y2ka0x kIwI1l42xK82IYc2Ij64vIr41l4I8I3I0E4IkC6x0Yz7v_Jr0_Gr1lx2IqxVAqx4xG67AK xVWUJVWUGwC20s026x8GjcxK67AKxVWUGVWUWwC2zVAF1VAY17CE14v26r4a6rW5MIIYrx kI7VAKI48JMIIF0xvE2Ix0cI8IcVAFwI0_Xr0_Ar1lIxAIcVC0I7IYx2IY6xkF7I0E14v2 6r4UJVWxJr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F 4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdYxBIdaVFxhVjvjDU0xZFpf9x0JUArcfU UUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspamd-Queue-Id: BDC3240008 X-Rspam-User: X-Stat-Signature: e5z8no88qgexw3i89dwpyhtihd3uut3k X-Rspamd-Server: rspam01 X-HE-Tag: 1712756230-161733 X-HE-Meta: U2FsdGVkX191qc8Wx4CjzJylPQXqJWhmY+mhnIERHetQs67enTG5XXGQpHpasDuSQ9T0Ai06EwkJ+r23hlEqyl8+qzTVh5gsOipA8S8beaVp0wU4grMWmJraDjUe3coii6tM17rrZYN6nDNCmKH8ca0Jh4LrTAXDnieSiqw6To4tFBebHTk6iSCSqa7otceigO3ROvoQvksHW9Y2RCU2TeGDXohLIrpeW2dspUKfPpJjbEjKL0wihnY+sKDo2iPazTKexB3XHLjFZ3L7bl95O97hA4mmWzIrKMnbPt5yUDyJ2VrOgZrIS6VqZINZREKMHW/ZQDVIz4zcI38YGoHvLV+5TGsMwWHohx6sZBGSga3zCBOocRtMZfCGtEdMvVfHbw3vrSB1JfyecUSm4KrCNu5+Y5rEkmaZ6H8o8rUliFakFwuE2Z27/ipWU2MCPTHnsTSnYIp2vUB8EDJ8eqJRVEbyE7J+OM1TIAp2MgKsWtEAj0qd33664cOrlwcCAPpZecijLKdwzw//e7WDuKOo2eQC+B0C4Z3qOiw5KlBt9DIp/hDyr4yUJMCrmYFGK5M30olahxn2lyYfz9/6oWeJewqkwqnX2eWTiAp8wcBpEZ0XfOyBVN63ScykKiVOlH8hgen4CjermCYiok3uUtDZbgdVhd0vcYubvdsvXqbzb9Wbga25dOJYds0tnd/UV907je4J8ZN5UTFyRKVXcOE/UMZXfNtHrpECzdqfxBqS9Ng4C+QoP+0bsp6JeBWtLpmHOiKi7SJjFycA/hou/aY9gH0DQjRkbZeTRAsiAIvswGu5mgGpymYMaQKQLqHzbvO9PhT1SBFU0JAgVtqU8XrAver3/wiRMWZSjmvJkY6M8WIqSNXSuflIGsp9/UuCykSKB9Hpd3qOzDPXe/7UuDUrNF1kZrpV1r9izR51VcnYhQO6KWrU/pOZUPykRvm2Y0XyLO2ThzgqxzsExgRGM0/ 5S2xElWv ogECZc5qzc5iqfhPAYWPcDyBHCPyqvGkmDfm0IBR6c/LorVQZyJrC8DrzP/hNCAygLSA6SZMT2WZ2PP1uB30TCCF4dVJEEtRoqexq1H7cKC9C9HSFodIce3kvyppX/K7DIHOPirdyoOa7mUiQm3bDOYReHEZDJUACPhx6m3V0b5n5U6RaAw9nmFQuUjfIsTkXQ1U6k+XPfcbIKHW36Q7gghOQnnvvOC4AAuZbBoMhySH8kmqZAYZaLKDPG5k+Z14HoidX 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 If we zero partial blocks, iomap_zero_iter() will skip zeroing out the IOMAP_UNWRITTEN srcmap, it works fine in xfs because this type means the block is pure unwritten and doesn't contain any delayed data. But it doesn't work in ext4, because IOMAP_UNWRITTEN may contain delayed data in ext4. For now it's hard to unify the meaning of this flag, so just fix it by writeback partial blocks before zeroing out. Signed-off-by: Zhang Yi --- fs/ext4/extents.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 9849947cec56..c4c38a323ff7 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4580,6 +4580,15 @@ static long ext4_zero_range(struct file *file, loff_t offset, if (ret) goto out_mutex; + ret = filemap_write_and_wait_range(mapping, + round_down(offset, 1 << blkbits), offset); + if (ret) + goto out_mutex; + + ret = filemap_write_and_wait_range(mapping, offset + len, + round_up((offset + len), 1 << blkbits)); + if (ret) + goto out_mutex; } /* Zero range excluding the unaligned edges */