Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp205748lqj; Wed, 10 Apr 2024 08:12:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX3ih4Ap/nVy5up2m0eocmlANvuHnB9W4QdLLOQQ8qdKkvvCr5W1xZV63IaNLGmqOFYpnaAc2w5MGwY7tKBbVgCmGg5X5kbidsxzeyGIw== X-Google-Smtp-Source: AGHT+IGjMsE6KbrpGxCG1GcYB46KjG+mgSJKu/fQoHh9E6voY8UIgD0r0unsjHM2u2nwfOcOrqqZ X-Received: by 2002:a2e:9e57:0:b0:2d8:7266:ae74 with SMTP id g23-20020a2e9e57000000b002d87266ae74mr2516018ljk.26.1712761937195; Wed, 10 Apr 2024 08:12:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712761937; cv=pass; d=google.com; s=arc-20160816; b=Dui58IedYogHKGWaoPqEUhRgJTy/E8L0quq75MxldrwkG6UigqEQAYai50mbmKIRsC zA0Cd/AqHZGu0/9+kpx+5LY0AaWI0Yrjo9iBl2AFFXqKl/Y0DsHqIy2/OLFU6x3voJ/O xNjGXa8TvaSS4zN7u8lkB7DaUC8iPC88wF/oTVbStD6Po0MZ2+Pxr9rkb1+vTiL1t/ej H/XkFh8+DW08NQB8xccN4vsQgMhxh2AG31u4p5jisMj5SkGTqrhvumAjMRU/fYtpIuaB 3IDF3Mj39PGqNPrS/Qx6LRhZ7YweGZRexv4v7cWZwVmiV+PJ8GGXzVx0oCDOFzHggaA4 phAg== 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=RZrNAfKqPKEAjMF5Y3M7foneYQpwHm5h4BORCNdEvbw=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=c9iOm5BfL4wsxONU84/zPZsgikSpLDxTSAs2SU/HSIWmis0TcrQtOzm4COvzfgY9Gm iV6QQoc13YPVmoTEmZKj5mnKrxhFhJwecsm/l3i2e0gwT+KxkRnxIOCw3xRUuf0F9eiQ i0iECN1rSFGAHb4BMWW8xHGFIDXRHDv5D0JdNiSCXcuJ6Gwig/pTP0CCZ5ON8a+lXgd9 MMifnqy8ll93xQjgNO08VSw0mEqyaVa9nQWnF+EdJ0on9ceC0oOtjX0J4y+APe8KM7Rh 3k+roJhGRFjqYy8h25zpHCwN8H82f1hQgznFVEoVFrvyTmch1UldtJcvKrKJyGXsy4xz mdOQ==; 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-2002-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2002-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id nc13-20020a1709071c0d00b00a51c9790350si3864933ejc.976.2024.04.10.08.12.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 08:12:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-2002-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-ext4+bounces-2002-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-ext4+bounces-2002-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 754F71F2F11B for ; Wed, 10 Apr 2024 15:12:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C1C6116EBF0; Wed, 10 Apr 2024 15:11:55 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (dggsgout11.his.huawei.com [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 634BF16DEBE; Wed, 10 Apr 2024 15:11:52 +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=1712761915; cv=none; b=lW63SnlOSS+A1V/iodabdWQW/icLXmCWKOcRkuoi/zgjoP8LtIGoFKb4dMs/z04fhm/19VjQ9blDq17mruFq2Lpmr/d5KZgkXOQA2xu5RerApzMbbZs1XLObU6RFfkYHtAgS0nZS55WKqxI6gVjUOC53vi6/Nu9/fKiDBeE2I1k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712761915; c=relaxed/simple; bh=e380bcGvC+0GXftRaUh0mc9IjrgCk3wJCKvPfnu6cRE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kUOZrphxSY0df9+37qcOnX8ZP3c4BW4CdwxnqdFzjoz0vlEKHnDijH8WkXoq0jYjntQAXPXTiBbnDKS1AtBVqc4wV7oDqkwIzhvXzN2CgiKqlxvXBitse1pPsqfdjRM5Eryho72WVSfx/LFNEaVv7yLM/sjszWkT5Gk82kPBJAU= 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 4VF5rw5xrcz4f3kKt; Wed, 10 Apr 2024 23:11:44 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 3EA0F1A0175; Wed, 10 Apr 2024 23:11:49 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAn9g4orBZmFSt+Jg--.51485S5; Wed, 10 Apr 2024 23:11:48 +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, david@fromorbit.com, 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 30/34] ext4: partial enable iomap for regular file's buffered IO path Date: Wed, 10 Apr 2024 23:03:09 +0800 Message-Id: <20240410150313.2820364-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240410142948.2817554-1-yi.zhang@huaweicloud.com> References: <20240410142948.2817554-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:cCh0CgAn9g4orBZmFSt+Jg--.51485S5 X-Coremail-Antispam: 1UD129KBjvJXoWxGw1kKrWrCw1DtF43GFW7Jwb_yoWrGr4UpF ZIkryrJr4Y93s29a1ftF48Zr1Sv3WxKw4UG3yS9wn5X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xVAFwI0_GcCE3s UvcSsGvfC2KfnxnUUI43ZEXa7IUbuWlDUUUUU== X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ From: Zhang Yi Partial enable iomap for regular file's buffered IO path on default mount option, support default filesystem features and bigalloc feature, doesn't support inline data, fs_verity, fs_crypt, defrag and data=journal mode yet (these would be supported gradually in the future). ext4 will fallback to buffered_head path automatically if these options or features are enable. Signed-off-by: Zhang Yi --- fs/ext4/ext4.h | 1 + fs/ext4/ialloc.c | 3 +++ fs/ext4/inode.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 2ec6c7884e9a..4e7667b21c2f 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -2972,6 +2972,7 @@ int ext4_walk_page_buffers(handle_t *handle, struct buffer_head *bh)); int do_journal_get_write_access(handle_t *handle, struct inode *inode, struct buffer_head *bh); +bool ext4_should_use_buffered_iomap(struct inode *inode); int ext4_nonda_switch(struct super_block *sb); #define FALL_BACK_TO_NONDELALLOC 1 #define CONVERT_INLINE_DATA 2 diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c index e9bbb1da2d0a..956b9d69c559 100644 --- a/fs/ext4/ialloc.c +++ b/fs/ext4/ialloc.c @@ -1336,6 +1336,9 @@ struct inode *__ext4_new_inode(struct mnt_idmap *idmap, } } + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (ext4_handle_valid(handle)) { ei->i_sync_tid = handle->h_transaction->t_tid; ei->i_datasync_tid = handle->h_transaction->t_tid; diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 5af3b8acf1b9..624eac0cc705 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -770,6 +770,8 @@ static int _ext4_get_block(struct inode *inode, sector_t iblock, if (ext4_has_inline_data(inode)) return -ERANGE; + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; map.m_lblk = iblock; map.m_len = bh->b_size >> inode->i_blkbits; @@ -2567,6 +2569,9 @@ static int ext4_do_writepages(struct mpage_da_data *mpd) trace_ext4_writepages(inode, wbc); + if (WARN_ON(ext4_test_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP))) + return -EINVAL; + /* * No pages to write? This is mainly a kludge to avoid starting * a transaction for special inodes like journal inode on last iput() @@ -5107,6 +5112,30 @@ static const char *check_igot_inode(struct inode *inode, ext4_iget_flags flags) return NULL; } +bool ext4_should_use_buffered_iomap(struct inode *inode) +{ + struct super_block *sb = inode->i_sb; + + if (ext4_has_feature_inline_data(sb)) + return false; + if (ext4_has_feature_verity(sb)) + return false; + if (test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA) + return false; + if (!S_ISREG(inode->i_mode)) + return false; + if (IS_DAX(inode)) + return false; + if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_EA_INODE)) + return false; + if (ext4_test_inode_flag(inode, EXT4_INODE_ENCRYPT)) + return false; + + return true; +} + struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, ext4_iget_flags flags, const char *function, unsigned int line) @@ -5371,6 +5400,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino, if (ret) goto bad_inode; + if (ext4_should_use_buffered_iomap(inode)) + ext4_set_inode_state(inode, EXT4_STATE_BUFFERED_IOMAP); + if (S_ISREG(inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; inode->i_fop = &ext4_file_operations; -- 2.39.2