Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp872904lqo; Fri, 17 May 2024 04:25:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOWwupU48br7103Mcf/3shOV4TKH5vXn2y3G5jS/5DEHkUuE0058Jx51FBLFD2cAFGxIIocigdo2U3sHT7py5bJvxxizfi8UySzkkMcw== X-Google-Smtp-Source: AGHT+IHFlcSZSuf851ydE65arotzraHmqRWDmNTzR4zILhSIctk0joMu+60lfBte1JFGdjUyX28N X-Received: by 2002:a50:cdd5:0:b0:572:f71:8030 with SMTP id 4fb4d7f45d1cf-5734d590400mr15029062a12.8.1715945148899; Fri, 17 May 2024 04:25:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715945148; cv=pass; d=google.com; s=arc-20160816; b=HsxJ59fHaEHSQYQ1/a3y4GYRApOZzQ4b1ATRGNZGRdwKh8wwg16FEYtDtLquXYlUxU 32x95ksQu+JtXs6FQFiCE1AEwHJG+uZSnaTEsnOUE1oFL1JTvZrJba541HNKIcPYFGKb lssvvecY8z1Uh7VK7W8rPGUW/CsODmWXXmTdcMnLIcmSdP7lsL4sYNs7m5kmJkmgZ+of NO4MzNYk6MQ88006stmVMayIrDQjX0KccWE7T4DK/lqxAiI7pr6qLQkE3jGLmCtcHwtf 6k9W3Gz+uS5xCXj+MMVF+mybLRNH22t1MI62G2dKQkHU02O7ocUViSERTPF1VZcgGwVZ K6SQ== 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=rqCGx9aIWosW3oecY1K+pyrYakE+8lus3Oh6BRBgTGg=; fh=0HaASOXEjGqpxPrGhdU7uT3vKkOGyiI675Dvy1SUF+c=; b=mfffEAVl1uqG25aaVEm+KwfIqFQvhorJCMRV5oWAWEXEQnsxsKVL7ZUwy8fUM4g5TR 2VyR1wDxF6IKGzObDQZ5zz6OI+8zDDLlzRzLYzedmnfqtlbmpwiozYHAYW3a1+hTtYpr yPGg8+S+sj8AG2Ovh2XdTnpzffESGQePgHKc0kvJSR6Wv+/+qCYZfFiTYwOIzE4J+6AN i3YkS1eqRCohhsOL51H+B0e9STmJPUy+Y1YlPHXeoXWpcfqJLY+V5eAiByUj34PA+W29 gDIjQ0n8BsC7fWdgwSBJjJIt0B9IBp0/BmGbIGhYd1FibjSG//Xnl0p5KBS2hkuCrO5Q c2Aw==; 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-2550-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2550-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 4fb4d7f45d1cf-5733c36d55csi10021410a12.518.2024.05.17.04.25.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 04:25:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2550-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-2550-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2550-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 9A6571F22ACB for ; Fri, 17 May 2024 11:25:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 01F324652D; Fri, 17 May 2024 11:24:52 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (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 EC6913D39B; Fri, 17 May 2024 11:24:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715945091; cv=none; b=s/jKYydyRyc0SNwe3XHFl1Y6sPb2qhrpgI83TI3A6mKGxR/AhcRUkDnwJvSscfrIY03T68k1JJPWHPBYEeKB6EETWZqs4GEEq23LJAtKKu2Cevuvt5LPFQwpzYPxQJfyY0y6Yd7Q5aka7U3SlsDbE9CxAL+EnBcLsNiQvQjEffY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715945091; c=relaxed/simple; bh=m9vypH1gMB/9FErJfl4U0x8qqTLLlpFrkNQYTD2IEyM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TdLHY1t81zMO0j3ksaw1+Zobn2H1DyTYIUqrOka0zRIDWFaEVpbLmSPp5h8akMQMcTqc1mK0EuRAZ+J/bMLK97mQeXeOhkWb/99GHd2i5RSffhfb1wfvafeV1GKA3yP6Kqp1uYA591FtLkNovxBPNYWHo11I/E2x3cGxIs202Bg= 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.51 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.93.142]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Vgl3q0JHtz4f3jpq; Fri, 17 May 2024 19:24:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id A01C81A016E; Fri, 17 May 2024 19:24:44 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgBHGBFrPkdm3V+kMw--.2732S5; Fri, 17 May 2024 19:24:44 +0800 (CST) From: Zhang Yi To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, djwong@kernel.org, hch@infradead.org, brauner@kernel.org, david@fromorbit.com, chandanbabu@kernel.org, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [PATCH v3 1/3] iomap: pass blocksize to iomap_truncate_page() Date: Fri, 17 May 2024 19:13:53 +0800 Message-Id: <20240517111355.233085-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240517111355.233085-1-yi.zhang@huaweicloud.com> References: <20240517111355.233085-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:cCh0CgBHGBFrPkdm3V+kMw--.2732S5 X-Coremail-Antispam: 1UD129KBjvJXoWxuFyrKF15GFykZr47Kr45Jrb_yoW5CFyxpF 1qkF45Gws3Xryj9F1kuFyjvw15tF1DGr40krySgrZxZrnFqr1xtFn2ka1jyF1Yqrs7ur4j qFZ8K3y8Wr15ArJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBK14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Cr0_Gr1UM2 8EF7xvwVC2z280aVAFwI0_GcCE3s1l84ACjcxK6I8E87Iv6xkF7I0E14v26rxl6s0DM2AI xVAIcxkEcVAq07x20xvEncxIr21l5I8CrVACY4xI64kE6c02F40Ex7xfMcIj6xIIjxv20x vE14v26r1j6r18McIj6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xv r2IYc2Ij64vIr41lF7I21c0EjII2zVCS5cI20VAGYxC7M4IIrI8v6xkF7I0E8cxan2IY04 v7MxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_ Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x 0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8 JVWxJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIx AIcVC2z280aVCY1x0267AKxVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7VUjFdgJUUUUU= = X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi iomap_truncate_page() always assumes the block size of the truncating inode is i_blocksize(), this is not always true for some filesystems, e.g. XFS does extent size alignment for realtime inodes. Drop this assumption and pass the block size for zeroing into iomap_truncate_page(), allow filesystems to indicate the correct block size. Suggested-by: Dave Chinner Signed-off-by: Zhang Yi --- fs/iomap/buffered-io.c | 13 +++++++++---- fs/xfs/xfs_iomap.c | 3 ++- include/linux/iomap.h | 4 ++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index 0926d216a5af..a0a0ac2c659c 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "trace.h" #include "../internal.h" @@ -1445,11 +1446,15 @@ iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, EXPORT_SYMBOL_GPL(iomap_zero_range); int -iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops) +iomap_truncate_page(struct inode *inode, loff_t pos, unsigned int blocksize, + bool *did_zero, const struct iomap_ops *ops) { - unsigned int blocksize = i_blocksize(inode); - unsigned int off = pos & (blocksize - 1); + unsigned int off; + + if (is_power_of_2(blocksize)) + off = pos & (blocksize - 1); + else + div_u64_rem(pos, blocksize, &off); /* Block boundary? Nothing to do */ if (!off) diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c index 2857ef1b0272..31ac07bb8425 100644 --- a/fs/xfs/xfs_iomap.c +++ b/fs/xfs/xfs_iomap.c @@ -1467,10 +1467,11 @@ xfs_truncate_page( bool *did_zero) { struct inode *inode = VFS_I(ip); + unsigned int blocksize = i_blocksize(inode); if (IS_DAX(inode)) return dax_truncate_page(inode, pos, did_zero, &xfs_dax_write_iomap_ops); - return iomap_truncate_page(inode, pos, did_zero, + return iomap_truncate_page(inode, pos, blocksize, did_zero, &xfs_buffered_write_iomap_ops); } diff --git a/include/linux/iomap.h b/include/linux/iomap.h index 6fc1c858013d..d67bf86ec582 100644 --- a/include/linux/iomap.h +++ b/include/linux/iomap.h @@ -273,8 +273,8 @@ int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, const struct iomap_ops *ops); int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, bool *did_zero, const struct iomap_ops *ops); -int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, - const struct iomap_ops *ops); +int iomap_truncate_page(struct inode *inode, loff_t pos, unsigned int blocksize, + bool *did_zero, const struct iomap_ops *ops); vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops); int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, -- 2.39.2