From: Jeffle Xu <jefflexu@linux.alibaba.com>
To: dhowells@redhat.com, linux-cachefs@redhat.com, xiang@kernel.org,
chao@kernel.org, linux-erofs@lists.ozlabs.org
Cc: linux-fsdevel@vger.kernel.org, joseph.qi@linux.alibaba.com,
bo.liu@linux.alibaba.com, tao.peng@linux.alibaba.com,
gerry@linux.alibaba.com, eguan@linux.alibaba.com,
linux-kernel@vger.kernel.org
Subject: [RFC 16/19] erofs: implement fscache-based data read
Date: Fri, 10 Dec 2021 15:36:16 +0800 [thread overview]
Message-ID: <20211210073619.21667-17-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20211210073619.21667-1-jefflexu@linux.alibaba.com>
Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
---
fs/erofs/fscache.c | 73 +++++++++++++++++++++++++++++++++++++++++++++
fs/erofs/inode.c | 6 +++-
fs/erofs/internal.h | 1 +
3 files changed, 79 insertions(+), 1 deletion(-)
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index 6fe31d410cbd..c849d3a89520 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -1,5 +1,78 @@
#include "internal.h"
+/*
+ * erofs_fscache_readpage
+ *
+ * Copy data from backpage (bootstrap) to page of files among erofs.
+ */
+static int erofs_fscache_readpage(struct file *file, struct page *page)
+{
+ struct inode *inode = page->mapping->host;
+ struct super_block *sb = inode->i_sb;
+ erofs_off_t pos = page->index << PAGE_SHIFT;
+ struct erofs_map_blocks map = { .m_la = pos };
+ erofs_blk_t blkaddr;
+ struct page *backpage;
+ u64 total, batch, copied = 0;
+ char *vsrc, *vdst; /* virtual address of mapped src/dst page */
+ char *psrc, *pdst; /* cursor inside src/dst page */
+ u64 osrc; /* offset inside src page */
+ int err;
+
+ err = erofs_map_blocks(inode, &map, EROFS_GET_BLOCKS_RAW);
+ if (err)
+ goto out;
+
+ total = min_t(u64, PAGE_SIZE, map.m_plen - (pos - map.m_la));
+ blkaddr = map.m_pa >> PAGE_SHIFT;
+ osrc = map.m_pa & (PAGE_SIZE - 1);
+
+ while (total) {
+ backpage = erofs_get_meta_page(sb, blkaddr);
+ if (IS_ERR(backpage)) {
+ err = PTR_ERR(backpage);
+ goto out;
+ }
+
+ vsrc = psrc = kmap_atomic(backpage);
+ vdst = pdst = kmap_atomic(page);
+
+ psrc += osrc;
+ pdst += copied;
+ batch = min_t(u64, PAGE_SIZE - osrc, total);
+
+ memcpy(pdst, psrc, batch);
+
+ copied += batch;
+ total -= batch;
+ blkaddr++;
+ osrc = 0; /* copy from the beginning of the next backpage */
+
+ /*
+ * Avoid 'scheduling while atomic' error. Unmap before going
+ * into the next turn, since we may schedule inside
+ * erofs_get_meta_page().
+ * */
+ kunmap_atomic(vsrc);
+ kunmap_atomic(vdst);
+
+ unlock_page(backpage);
+ put_page(backpage);
+ }
+
+out:
+ if (err)
+ SetPageError(page);
+ else
+ SetPageUptodate(page);
+ unlock_page(page);
+ return err;
+}
+
+const struct address_space_operations erofs_fscache_access_aops = {
+ .readpage = erofs_fscache_readpage,
+};
+
static int erofs_begin_cache_operation(struct netfs_read_request *rreq)
{
return fscache_begin_read_operation(&rreq->cache_resources,
diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index 2345f1de438e..452d147277c4 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -299,7 +299,11 @@ static int erofs_fill_inode(struct inode *inode, int isdir)
err = z_erofs_fill_inode(inode);
goto out_unlock;
}
- inode->i_mapping->a_ops = &erofs_raw_access_aops;
+
+ if (inode->i_sb->s_bdev)
+ inode->i_mapping->a_ops = &erofs_raw_access_aops;
+ else
+ inode->i_mapping->a_ops = &erofs_fscache_access_aops;
out_unlock:
unlock_page(page);
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index d60d9ffaef2a..dd3f2edae603 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -353,6 +353,7 @@ struct page *erofs_grab_cache_page_nowait(struct address_space *mapping,
extern const struct super_operations erofs_sops;
extern const struct address_space_operations erofs_raw_access_aops;
+extern const struct address_space_operations erofs_fscache_access_aops;
extern const struct address_space_operations z_erofs_aops;
/*
--
2.27.0
next prev parent reply other threads:[~2021-12-10 7:37 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-10 7:36 [RFC 00/19] fscache,erofs: fscache-based demand-read semantics Jeffle Xu
2021-12-10 7:36 ` [RFC 01/19] cachefiles: add mode command Jeffle Xu
2021-12-10 7:36 ` [RFC 02/19] cachefiles: implement key scheme for demand-read mode Jeffle Xu
2021-12-10 7:36 ` [RFC 03/19] cachefiles: refactor cachefiles_adjust_size() Jeffle Xu
2021-12-10 7:36 ` [RFC 04/19] netfs: make ops->init_rreq() optional Jeffle Xu
2021-12-10 7:36 ` [RFC 05/19] netfs: refactor netfs_alloc_read_request Jeffle Xu
2021-12-10 7:36 ` [RFC 06/19] netfs: add type field to struct netfs_read_request Jeffle Xu
2021-12-10 7:36 ` [RFC 07/19] netfs: add netfs_readpage_demand() Jeffle Xu
2021-12-10 7:36 ` [RFC 08/19] netfs: refactor netfs_clear_unread() Jeffle Xu
2021-12-10 7:36 ` [RFC 09/19] netfs: refactor netfs_rreq_unlock() Jeffle Xu
2021-12-10 7:36 ` [RFC 10/19] netfs: refactor netfs_rreq_prepare_read Jeffle Xu
2021-12-10 7:36 ` [RFC 11/19] cachefiles: refactor cachefiles_prepare_read Jeffle Xu
2021-12-10 7:36 ` [RFC 12/19] erofs: export erofs_map_blocks Jeffle Xu
2021-12-10 7:36 ` [RFC 13/19] erofs: add bootstrap_path mount option Jeffle Xu
2021-12-10 7:36 ` [RFC 14/19] erofs: introduce fscache support Jeffle Xu
2021-12-10 7:36 ` [RFC 15/19] erofs: implement fscache-based metadata read Jeffle Xu
2021-12-10 7:36 ` Jeffle Xu [this message]
2021-12-10 7:36 ` [RFC 17/19] netfs: support on demand read Jeffle Xu
2021-12-10 7:36 ` [RFC 18/19] cachefiles: " Jeffle Xu
2021-12-10 7:36 ` [RFC 19/19] erofs: " Jeffle Xu
2021-12-10 11:04 ` [RFC 02/19] cachefiles: implement key scheme for demand-read mode David Howells
2021-12-11 5:32 ` JeffleXu
2021-12-10 11:05 ` [RFC 01/19] cachefiles: add mode command David Howells
2021-12-11 5:23 ` JeffleXu
2021-12-10 15:41 ` [RFC 09/19] netfs: refactor netfs_rreq_unlock() David Howells
2021-12-11 5:23 ` JeffleXu
2021-12-11 5:44 ` [Linux-cachefs] " JeffleXu
2021-12-11 6:57 ` Gao Xiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211210073619.21667-17-jefflexu@linux.alibaba.com \
--to=jefflexu@linux.alibaba.com \
--cc=bo.liu@linux.alibaba.com \
--cc=chao@kernel.org \
--cc=dhowells@redhat.com \
--cc=eguan@linux.alibaba.com \
--cc=gerry@linux.alibaba.com \
--cc=joseph.qi@linux.alibaba.com \
--cc=linux-cachefs@redhat.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tao.peng@linux.alibaba.com \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).