All of lore.kernel.org
 help / color / mirror / Atom feed
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: tao.peng@linux.alibaba.com, linux-kernel@vger.kernel.org,
	joseph.qi@linux.alibaba.com, bo.liu@linux.alibaba.com,
	linux-fsdevel@vger.kernel.org, eguan@linux.alibaba.com,
	gerry@linux.alibaba.com
Subject: [RFC 15/19] erofs: implement fscache-based metadata read
Date: Fri, 10 Dec 2021 15:36:15 +0800	[thread overview]
Message-ID: <20211210073619.21667-16-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/data.c     |  5 +++--
 fs/erofs/fscache.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 fs/erofs/internal.h |  3 +++
 fs/erofs/super.c    | 10 ++++++----
 4 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index cf71082bd52f..47bd3d0ae94c 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -12,6 +12,7 @@
 struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr)
 {
 	struct address_space * mapping;
+	struct erofs_sb_info *sbi;
 	struct page *page;
 
 	if (sb->s_bdev) {
@@ -19,8 +20,8 @@ struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr)
 		page = read_cache_page_gfp(mapping, blkaddr,
 				mapping_gfp_constraint(mapping, ~__GFP_FS));
 	} else {
-		/* TODO: fscache based data path */
-		page = ERR_PTR(-EINVAL);
+		sbi = EROFS_SB(sb);
+		page = erofs_readpage_from_fscache(sbi->bootstrap, blkaddr);
 	}
 
 	/* should already be PageUptodate */
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index cf550fdedd1e..6fe31d410cbd 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -1,5 +1,50 @@
 #include "internal.h"
 
+static int erofs_begin_cache_operation(struct netfs_read_request *rreq)
+{
+	return fscache_begin_read_operation(&rreq->cache_resources,
+					    rreq->netfs_priv);
+}
+
+static void erofs_priv_cleanup(struct address_space *mapping, void *netfs_priv)
+{
+}
+
+const struct netfs_read_request_ops erofs_req_ops = {
+	.begin_cache_operation  = erofs_begin_cache_operation,
+	.cleanup		= erofs_priv_cleanup,
+};
+
+struct page *erofs_readpage_from_fscache(struct fscache_cookie *cookie,
+					 pgoff_t index)
+{
+	int ret = -ENOMEM;
+	struct folio *folio;
+	struct page *page;
+
+	page = alloc_page(GFP_KERNEL);
+	if (unlikely(!page)) {
+		printk("failed to allocate page\n");
+		goto err;
+	}
+
+	page->index = index;
+	folio = page_folio(page);
+
+	ret = netfs_readpage_demand(folio, &erofs_req_ops, cookie);
+	if (unlikely(ret || !PageUptodate(page))) {
+		printk("failed to read from fscache\n");
+		goto err_page;
+	}
+
+	return page;
+
+err_page:
+	__free_page(page);
+err:
+	return ERR_PTR(ret);
+}
+
 int erofs_fscache_init(struct erofs_sb_info *sbi, char *bootstrap_path)
 {
 	sbi->volume = fscache_acquire_volume("erofs", NULL, 0);
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 8136ec63a9de..d60d9ffaef2a 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -577,6 +577,9 @@ static inline int z_erofs_load_lzma_config(struct super_block *sb,
 int erofs_fscache_init(struct erofs_sb_info *sbi, char *bootstrap_path);
 void erofs_fscache_cleanup(struct erofs_sb_info *sbi);
 
+struct page *erofs_readpage_from_fscache(struct fscache_cookie *cookie,
+					 pgoff_t index);
+
 #define EFSCORRUPTED    EUCLEAN         /* Filesystem is corrupted */
 
 #endif	/* __EROFS_INTERNAL_H */
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index f2a5f4cd53fd..bb68bc81a1a7 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -330,21 +330,23 @@ static int erofs_init_devices(struct super_block *sb,
 
 static int erofs_read_superblock(struct super_block *sb)
 {
-	struct erofs_sb_info *sbi;
+	struct erofs_sb_info *sbi = EROFS_SB(sb);
 	struct page *page;
 	struct erofs_super_block *dsb;
 	unsigned int blkszbits;
 	void *data;
 	int ret;
 
-	page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
+	if (sb->s_bdev)
+		page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
+	else
+		page = erofs_readpage_from_fscache(sbi->bootstrap, 0);
+
 	if (IS_ERR(page)) {
 		erofs_err(sb, "cannot read erofs superblock");
 		return PTR_ERR(page);
 	}
 
-	sbi = EROFS_SB(sb);
-
 	data = kmap(page);
 	dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
 
-- 
2.27.0


WARNING: multiple messages have this Message-ID (diff)
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 15/19] erofs: implement fscache-based metadata read
Date: Fri, 10 Dec 2021 15:36:15 +0800	[thread overview]
Message-ID: <20211210073619.21667-16-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/data.c     |  5 +++--
 fs/erofs/fscache.c  | 45 +++++++++++++++++++++++++++++++++++++++++++++
 fs/erofs/internal.h |  3 +++
 fs/erofs/super.c    | 10 ++++++----
 4 files changed, 57 insertions(+), 6 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index cf71082bd52f..47bd3d0ae94c 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -12,6 +12,7 @@
 struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr)
 {
 	struct address_space * mapping;
+	struct erofs_sb_info *sbi;
 	struct page *page;
 
 	if (sb->s_bdev) {
@@ -19,8 +20,8 @@ struct page *erofs_get_meta_page(struct super_block *sb, erofs_blk_t blkaddr)
 		page = read_cache_page_gfp(mapping, blkaddr,
 				mapping_gfp_constraint(mapping, ~__GFP_FS));
 	} else {
-		/* TODO: fscache based data path */
-		page = ERR_PTR(-EINVAL);
+		sbi = EROFS_SB(sb);
+		page = erofs_readpage_from_fscache(sbi->bootstrap, blkaddr);
 	}
 
 	/* should already be PageUptodate */
diff --git a/fs/erofs/fscache.c b/fs/erofs/fscache.c
index cf550fdedd1e..6fe31d410cbd 100644
--- a/fs/erofs/fscache.c
+++ b/fs/erofs/fscache.c
@@ -1,5 +1,50 @@
 #include "internal.h"
 
+static int erofs_begin_cache_operation(struct netfs_read_request *rreq)
+{
+	return fscache_begin_read_operation(&rreq->cache_resources,
+					    rreq->netfs_priv);
+}
+
+static void erofs_priv_cleanup(struct address_space *mapping, void *netfs_priv)
+{
+}
+
+const struct netfs_read_request_ops erofs_req_ops = {
+	.begin_cache_operation  = erofs_begin_cache_operation,
+	.cleanup		= erofs_priv_cleanup,
+};
+
+struct page *erofs_readpage_from_fscache(struct fscache_cookie *cookie,
+					 pgoff_t index)
+{
+	int ret = -ENOMEM;
+	struct folio *folio;
+	struct page *page;
+
+	page = alloc_page(GFP_KERNEL);
+	if (unlikely(!page)) {
+		printk("failed to allocate page\n");
+		goto err;
+	}
+
+	page->index = index;
+	folio = page_folio(page);
+
+	ret = netfs_readpage_demand(folio, &erofs_req_ops, cookie);
+	if (unlikely(ret || !PageUptodate(page))) {
+		printk("failed to read from fscache\n");
+		goto err_page;
+	}
+
+	return page;
+
+err_page:
+	__free_page(page);
+err:
+	return ERR_PTR(ret);
+}
+
 int erofs_fscache_init(struct erofs_sb_info *sbi, char *bootstrap_path)
 {
 	sbi->volume = fscache_acquire_volume("erofs", NULL, 0);
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 8136ec63a9de..d60d9ffaef2a 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -577,6 +577,9 @@ static inline int z_erofs_load_lzma_config(struct super_block *sb,
 int erofs_fscache_init(struct erofs_sb_info *sbi, char *bootstrap_path);
 void erofs_fscache_cleanup(struct erofs_sb_info *sbi);
 
+struct page *erofs_readpage_from_fscache(struct fscache_cookie *cookie,
+					 pgoff_t index);
+
 #define EFSCORRUPTED    EUCLEAN         /* Filesystem is corrupted */
 
 #endif	/* __EROFS_INTERNAL_H */
diff --git a/fs/erofs/super.c b/fs/erofs/super.c
index f2a5f4cd53fd..bb68bc81a1a7 100644
--- a/fs/erofs/super.c
+++ b/fs/erofs/super.c
@@ -330,21 +330,23 @@ static int erofs_init_devices(struct super_block *sb,
 
 static int erofs_read_superblock(struct super_block *sb)
 {
-	struct erofs_sb_info *sbi;
+	struct erofs_sb_info *sbi = EROFS_SB(sb);
 	struct page *page;
 	struct erofs_super_block *dsb;
 	unsigned int blkszbits;
 	void *data;
 	int ret;
 
-	page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
+	if (sb->s_bdev)
+		page = read_mapping_page(sb->s_bdev->bd_inode->i_mapping, 0, NULL);
+	else
+		page = erofs_readpage_from_fscache(sbi->bootstrap, 0);
+
 	if (IS_ERR(page)) {
 		erofs_err(sb, "cannot read erofs superblock");
 		return PTR_ERR(page);
 	}
 
-	sbi = EROFS_SB(sb);
-
 	data = kmap(page);
 	dsb = (struct erofs_super_block *)(data + EROFS_SUPER_OFFSET);
 
-- 
2.27.0


  parent reply	other threads:[~2021-12-10  7:42 UTC|newest]

Thread overview: 56+ 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 ` Jeffle Xu
2021-12-10  7:36 ` [RFC 01/19] cachefiles: add mode command Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10 11:05   ` David Howells
2021-12-10 11:05     ` David Howells
2021-12-11  5:23     ` JeffleXu
2021-12-11  5:23       ` JeffleXu
2021-12-10  7:36 ` [RFC 02/19] cachefiles: implement key scheme for demand-read mode Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10 11:04   ` David Howells
2021-12-10 11:04     ` David Howells
2021-12-11  5:32     ` JeffleXu
2021-12-11  5:32       ` JeffleXu
2021-12-10  7:36 ` [RFC 03/19] cachefiles: refactor cachefiles_adjust_size() Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 04/19] netfs: make ops->init_rreq() optional Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 05/19] netfs: refactor netfs_alloc_read_request Jeffle Xu
2021-12-10  7:36   ` 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   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 07/19] netfs: add netfs_readpage_demand() Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 08/19] netfs: refactor netfs_clear_unread() Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 09/19] netfs: refactor netfs_rreq_unlock() Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10 15:41   ` David Howells
2021-12-10 15:41     ` David Howells
2021-12-11  5:23     ` JeffleXu
2021-12-11  5:23       ` JeffleXu
2021-12-11  5:44       ` [Linux-cachefs] " JeffleXu
2021-12-11  5:44         ` JeffleXu
2021-12-11  6:57         ` Gao Xiang
2021-12-11  6:57           ` Gao Xiang
2021-12-10  7:36 ` [RFC 10/19] netfs: refactor netfs_rreq_prepare_read Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 11/19] cachefiles: refactor cachefiles_prepare_read Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 12/19] erofs: export erofs_map_blocks Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 13/19] erofs: add bootstrap_path mount option Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 14/19] erofs: introduce fscache support Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` Jeffle Xu [this message]
2021-12-10  7:36   ` [RFC 15/19] erofs: implement fscache-based metadata read Jeffle Xu
2021-12-10  7:36 ` [RFC 16/19] erofs: implement fscache-based data read Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 17/19] netfs: support on demand read Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 18/19] cachefiles: " Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu
2021-12-10  7:36 ` [RFC 19/19] erofs: " Jeffle Xu
2021-12-10  7:36   ` Jeffle Xu

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-16-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.