Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp160756lqj; Wed, 10 Apr 2024 07:06:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVZehiS8LfFQw1hJIi5XKM2fnZjmqA+xTUiUPIopw1TPHMKYQn+y7E0tERMdZ/hL4zDApnYEZf0HhruNEwgR0UJv6BLz3kc8LEsTBFNow== X-Google-Smtp-Source: AGHT+IHM7Rx5+M6utyd3fWUVTsEwqKycB7JeocIEEM3gXVjASGSD9u2VxzkFJrPiWWN4TX4XJWZM X-Received: by 2002:a50:aa9c:0:b0:566:f5d6:4b4 with SMTP id q28-20020a50aa9c000000b00566f5d604b4mr1868416edc.12.1712757999593; Wed, 10 Apr 2024 07:06:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712757999; cv=pass; d=google.com; s=arc-20160816; b=R2mgizQCiJfdUKSBo7KYosPGC0AI5p0QExZT9UFbOIOEFSqTao8Mvsvobyty3MDFOa 8nURNrwV/QuKmCeZVi91tEz3QVA4vOBfuQTqN9VrlsUdNVgE+hW2Bl+oELIhiQRsV/9d 67tJ8xiLcJuTK3vu1TGTyK5Em6rvFL8ZoiExjeoD6pEJIJqimmnOugBc9qp/G6wGlOq4 2SwLKIEzXbskb9qsDTmKy4DbEZVLe+IOBTLMc/TC5c9lJ3mJnc/CxEYH+1Ph6bWxgkgp KXoFGbY5Uor8DT+RvLQbmexo6cfFf9UfJpRwf2er5wP+G2uDp3AoMpLdjMdiD4k494f7 Nmtw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=1rfO3bDUWjwaLs+wdCUIuN/1ZGWNGlnDZNmsSH0BvMA=; fh=UhGiR19HeAIu8tzXykjZgtAKLLMPZj8YX6gPScUOsdE=; b=OnE+y4m7H0y8Su+7qE9rNMwz7mcffmhSiegyuAGWr+AlM7soPB4QL0FZyrP/qQAMgv Szcemj9DNg3a/x/+YHGoTpxfh+roqEHK+o/MLsMLNmXtGPNjunCSGGjWoYyqBlb+7gZU Y5jN4yDKu/1HkRBjzRST3ruycRABuhwBnEWdB8zwbPKcdcZsPTbSG/O/yLowqOFN3OAZ xRjK0DEe9wo46Lq+rJRJjiT6ImexM8z63+7LVf623pZofp9BTAyP1+dVgof+O7L61WhR CqtpJPJuOgCEwAIWX9gR/Itfip+2wzvJAQbPacb0UfMwpZnXtxSvpGp8eNtav+6ZuKjQ Korg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1969-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id g25-20020a50d5d9000000b0056c0d76d6c1si6021639edj.238.2024.04.10.07.06.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:06:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-1969-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1969-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 834631F310A2 for ; Wed, 10 Apr 2024 13:44:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A1C4317B514; Wed, 10 Apr 2024 13:37:11 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D627117965A; Wed, 10 Apr 2024 13:37:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.56 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712756231; cv=none; b=ADbRizN0YxaNTo+fDCykm4eAi75XiHrMxAsKANfIHQHcvZPC1BPT6gMB1XPVpGXA7b5ITRkm+cz/XR+FGDxNYqyx4w9127wloNFClNl5scKWjW7VqDBJOeEnBgmSRYSHkHUmK/C+s0IM9+WoyzcIqMvrcfPs959fmc9ImQfefM4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712756231; c=relaxed/simple; bh=rE9Rcx+buyMmwsXHYp7x2evEfE+Nh2dJdCHXPJa71C8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MUOXm8MWeAkKAMw0BMcaSC91d2wixe6mJHi+BZ0iWhDmDbrrN5oBiLsswfkxsBnQOYG0LhwwxD4/jCAqdPHW8Q4JywyOzB1o5860Rf8JGdC4ktwI0gbwKlqjolgvauhskEv5TsJeNKX9BzsFSWSQW8v72/R6e6MLLwyQxyJ2KYM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com; spf=pass smtp.mailfrom=huaweicloud.com; arc=none smtp.client-ip=45.249.212.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4VF3lZ3NfRz4f3kjM; 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 512461A058D; 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> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAn+RHolRZmeCl4Jg--.8806S32 X-Coremail-Antispam: 1UD129KBjvdXoW7JrW5Aw4UXw1DtFy5XF47Jwb_yoWkZrc_Xa 4rJr1kWrWftr92g3s7Cry3ArWIyw409r1fuFy0y3s5ZFy5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hang 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 */ -- 2.39.2