Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp189149lqj; Wed, 10 Apr 2024 07:48:54 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWxCWqVJ5Fd7OPOiVc5x+XxGlrAl0yl5dIxc54qHzy72uMDTF31Q/w/rKDXpPGlUIWkw8QMkzIa6Wkxti1RGTRC4miZmarDqgM34kfSwA== X-Google-Smtp-Source: AGHT+IHUWKaExjKmGTYxyKR2zp1PO7HGKwYvTGOq8YpGE5reYLJtGrQt1GGu5YUYXCy/r9vwkPYd X-Received: by 2002:a17:903:2b06:b0:1e2:bfd4:b83 with SMTP id mc6-20020a1709032b0600b001e2bfd40b83mr3825912plb.44.1712760533688; Wed, 10 Apr 2024 07:48:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712760533; cv=pass; d=google.com; s=arc-20160816; b=WH7ScYoNkC4ul8Z3tBkVAxRPNQuigL2KBDq2VFjU3ndydnRJKQzl5SR7FwW1dFGewx 4xcFvBOJbuSmTqBGoPj9gfCYP49/BcFYhTXK9o+6RRAWd4/zJtHkbol5P3KCSmTS2jvu cMm/Llgql6WZnSxGXeBcOZxhw+FJSw2ofHi4Wu73K0twypCooh7jDPolZwMeJR9mu98O lBL1pI+A5IZaicU6OtG2qOfwopCRfiVv/YxO3e+U4/juYLBOD3YdiWYH48+F1SELmM82 QgwADe/Tf+lUqsHP7W5EMrkpV9go/Kk+qddYU4zoW6Q+7XmvusnFCn57H1XRtiuQJlp5 wNTg== 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=fpA/4lqRQbydf8z9xn3F9nf8xQRgGteQQM2P1EKzZvU=; fh=VCdyVZCUh9R8dltaA9/RWs/hxQzWhc63WX0fta2PQtE=; b=EIOF/cxydxgLayYDNtnXydIHsomzJZ34TbNCb1tiQi4Hjs7hvLNLJyo5Q9+9ybCon/ fLXfPcrFd2kZL3mvRBayQwcQ9KZNdBZofE4+5vRImZvsCLvFE7u+/HlHn2/dHnGDTpZZ cgnF39/UVPgoWt9ozrpqS7o/rlPDqFBi+Aqf9uHNPzxOqEmrHXFq1sJJeYfEp8TOxpXs JjL+EKojNJGjqQDuwT53Kq7mcSrQkHdzF090ZaERa7GmZE3VfVPGAbBCLfOs78WAcWYT vtKIXVEx4T5ugX/BqiB4GhTZRhCty7XzwUaoDknsVWn8HhzK2UXcmljC3QmvUfz13cs/ V7cA==; 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-kernel+bounces-138792-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138792-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id jj5-20020a170903048500b001ddcc1543d4si10439646plb.64.2024.04.10.07.48.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 07:48:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-138792-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huaweicloud.com); spf=pass (google.com: domain of linux-kernel+bounces-138792-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-138792-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id EA0AC285796 for ; Wed, 10 Apr 2024 14:48:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B2C28181B9F; Wed, 10 Apr 2024 14:38:47 +0000 (UTC) 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 C9E74177984; Wed, 10 Apr 2024 14:38:43 +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=1712759926; cv=none; b=niHd6H3Rm6QIX256JXjJNfsDEcMzRlaaYytknOvJTgW1jHGH0eDctnEBqmeM8BauthryW1ZcZUTE8gJteYkGNxQDLpxJUqRfvBEJvHG/1xsWgYBEQH6VqiPje00hwGYM0tDzm2TM9/bt6Qkb4KylD++rofMce9xuwZk8UqnjWUM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712759926; c=relaxed/simple; bh=T4TB4BlTlfvVUzY1La73B6Y/zTjSnI4NYR/8BDSwrc8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TaiLupBW7af84jnHceb9U/UmQ4Z8/iljWKhUOBCn5SRy2WEvz3puZWO8Dr7rzTauPMwCTijJtdPnKrx5xxNKK6Vf0nFDiblWbdfIw7Ba1hb7/sCI4yfKQqUNU1o8vbZp2ddloNvp2AlR2Bh2DZMJ9lAsAyf9hKP29BBlFE/vaew= 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.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4VF56h25dqz4f3k6L; Wed, 10 Apr 2024 22:38:36 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id ACF081A0568; Wed, 10 Apr 2024 22:38:40 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX6RFSpBZmcwR8Jg--.63000S27; Wed, 10 Apr 2024 22:38:40 +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 23/34] ext4: implement buffered read iomap path Date: Wed, 10 Apr 2024 22:29:37 +0800 Message-Id: <20240410142948.2817554-24-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-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:cCh0CgAX6RFSpBZmcwR8Jg--.63000S27 X-Coremail-Antispam: 1UD129KBjvJXoW7urW3XF4fAFy7KF1UXrW7XFb_yoW8uFy3pF 98KFy5GF47XrnI9F4SgFZrJr1Yk3Wxtr4UZrWfWasxGFyYkrW2gayjgFyYyF1Yq3y7Ary8 WF1jkr18GF4UArDanT9S1TB71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iomap_buffered_io_begin() for the iomap read path, it call ext4_map_blocks() to query map status and call ext4_set_iomap() to convert ext4 map to iomap. Signed-off-by: Zhang Yi --- fs/ext4/inode.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4c1fed516d9e..20eb772f4f62 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3523,14 +3523,46 @@ const struct iomap_ops ext4_iomap_report_ops = { .iomap_begin = ext4_iomap_begin_report, }; -static int ext4_iomap_read_folio(struct file *file, struct folio *folio) +static int ext4_iomap_buffered_io_begin(struct inode *inode, loff_t offset, + loff_t length, unsigned int iomap_flags, + struct iomap *iomap, struct iomap *srcmap) { + int ret; + struct ext4_map_blocks map; + u8 blkbits = inode->i_blkbits; + + if (unlikely(ext4_forced_shutdown(inode->i_sb))) + return -EIO; + if ((offset >> blkbits) > EXT4_MAX_LOGICAL_BLOCK) + return -EINVAL; + if (WARN_ON_ONCE(ext4_has_inline_data(inode))) + return -ERANGE; + + /* Calculate the first and last logical blocks respectively. */ + map.m_lblk = offset >> blkbits; + map.m_len = min_t(loff_t, (offset + length - 1) >> blkbits, + EXT4_MAX_LOGICAL_BLOCK) - map.m_lblk + 1; + + ret = ext4_map_blocks(NULL, inode, &map, 0); + if (ret < 0) + return ret; + + ext4_set_iomap(inode, iomap, &map, offset, length, iomap_flags); return 0; } -static void ext4_iomap_readahead(struct readahead_control *rac) +const struct iomap_ops ext4_iomap_buffered_read_ops = { + .iomap_begin = ext4_iomap_buffered_io_begin, +}; + +static int ext4_iomap_read_folio(struct file *file, struct folio *folio) { + return iomap_read_folio(folio, &ext4_iomap_buffered_read_ops); +} +static void ext4_iomap_readahead(struct readahead_control *rac) +{ + iomap_readahead(rac, &ext4_iomap_buffered_read_ops); } static int ext4_iomap_writepages(struct address_space *mapping, -- 2.39.2