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 07/19] netfs: add netfs_readpage_demand()
Date: Fri, 10 Dec 2021 15:36:07 +0800 [thread overview]
Message-ID: <20211210073619.21667-8-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20211210073619.21667-1-jefflexu@linux.alibaba.com>
netfs_readpage_demand() is the demand-read version of
netfs_readpage().
When netfs API works in demand-read mode, fs using fscache shall call
netfs_readpage_demand() instead.
Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
---
fs/netfs/read_helper.c | 63 ++++++++++++++++++++++++++++++++++++++++++
include/linux/netfs.h | 3 ++
2 files changed, 66 insertions(+)
diff --git a/fs/netfs/read_helper.c b/fs/netfs/read_helper.c
index 9240b85548e4..26fa688f6300 100644
--- a/fs/netfs/read_helper.c
+++ b/fs/netfs/read_helper.c
@@ -1022,6 +1022,69 @@ int netfs_readpage(struct file *file,
}
EXPORT_SYMBOL(netfs_readpage);
+int netfs_readpage_demand(struct folio *folio,
+ const struct netfs_read_request_ops *ops,
+ void *netfs_priv)
+{
+ struct netfs_read_request *rreq;
+ unsigned int debug_index = 0;
+ int ret;
+
+ _enter("%lx", folio_index(folio));
+
+ rreq = __netfs_alloc_read_request(ops, netfs_priv, NULL);
+ if (!rreq) {
+ if (netfs_priv)
+ ops->cleanup(netfs_priv, folio_file_mapping(folio));
+ folio_unlock(folio);
+ return -ENOMEM;
+ }
+ rreq->type = NETFS_TYPE_DEMAND;
+ rreq->folio = folio;
+ rreq->start = folio_file_pos(folio);
+ rreq->len = folio_size(folio);
+ __set_bit(NETFS_RREQ_DONT_UNLOCK_FOLIOS, &rreq->flags);
+
+ if (ops->begin_cache_operation) {
+ ret = ops->begin_cache_operation(rreq);
+ if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS) {
+ folio_unlock(folio);
+ goto out;
+ }
+ }
+
+ netfs_stat(&netfs_n_rh_readpage);
+ trace_netfs_read(rreq, rreq->start, rreq->len, netfs_read_trace_readpage);
+
+ netfs_get_read_request(rreq);
+
+ atomic_set(&rreq->nr_rd_ops, 1);
+ do {
+ if (!netfs_rreq_submit_slice(rreq, &debug_index))
+ break;
+
+ } while (rreq->submitted < rreq->len);
+
+ /* Keep nr_rd_ops incremented so that the ref always belongs to us, and
+ * the service code isn't punted off to a random thread pool to
+ * process.
+ */
+ do {
+ wait_var_event(&rreq->nr_rd_ops, atomic_read(&rreq->nr_rd_ops) == 1);
+ netfs_rreq_assess(rreq, false);
+ } while (test_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags));
+
+ ret = rreq->error;
+ if (ret == 0 && rreq->submitted < rreq->len) {
+ trace_netfs_failure(rreq, NULL, ret, netfs_fail_short_readpage);
+ ret = -EIO;
+ }
+out:
+ netfs_put_read_request(rreq, false);
+ return ret;
+}
+EXPORT_SYMBOL(netfs_readpage_demand);
+
/*
* Prepare a folio for writing without reading first
* @folio: The folio being prepared
diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index 638ea5d63869..de6948bcc80a 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -261,6 +261,9 @@ extern int netfs_readpage(struct file *,
struct folio *,
const struct netfs_read_request_ops *,
void *);
+extern int netfs_readpage_demand(struct folio *,
+ const struct netfs_read_request_ops *,
+ void *);
extern int netfs_write_begin(struct file *, struct address_space *,
loff_t, unsigned int, unsigned int, struct folio **,
void **,
--
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 07/19] netfs: add netfs_readpage_demand()
Date: Fri, 10 Dec 2021 15:36:07 +0800 [thread overview]
Message-ID: <20211210073619.21667-8-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20211210073619.21667-1-jefflexu@linux.alibaba.com>
netfs_readpage_demand() is the demand-read version of
netfs_readpage().
When netfs API works in demand-read mode, fs using fscache shall call
netfs_readpage_demand() instead.
Signed-off-by: Jeffle Xu <jefflexu@linux.alibaba.com>
---
fs/netfs/read_helper.c | 63 ++++++++++++++++++++++++++++++++++++++++++
include/linux/netfs.h | 3 ++
2 files changed, 66 insertions(+)
diff --git a/fs/netfs/read_helper.c b/fs/netfs/read_helper.c
index 9240b85548e4..26fa688f6300 100644
--- a/fs/netfs/read_helper.c
+++ b/fs/netfs/read_helper.c
@@ -1022,6 +1022,69 @@ int netfs_readpage(struct file *file,
}
EXPORT_SYMBOL(netfs_readpage);
+int netfs_readpage_demand(struct folio *folio,
+ const struct netfs_read_request_ops *ops,
+ void *netfs_priv)
+{
+ struct netfs_read_request *rreq;
+ unsigned int debug_index = 0;
+ int ret;
+
+ _enter("%lx", folio_index(folio));
+
+ rreq = __netfs_alloc_read_request(ops, netfs_priv, NULL);
+ if (!rreq) {
+ if (netfs_priv)
+ ops->cleanup(netfs_priv, folio_file_mapping(folio));
+ folio_unlock(folio);
+ return -ENOMEM;
+ }
+ rreq->type = NETFS_TYPE_DEMAND;
+ rreq->folio = folio;
+ rreq->start = folio_file_pos(folio);
+ rreq->len = folio_size(folio);
+ __set_bit(NETFS_RREQ_DONT_UNLOCK_FOLIOS, &rreq->flags);
+
+ if (ops->begin_cache_operation) {
+ ret = ops->begin_cache_operation(rreq);
+ if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS) {
+ folio_unlock(folio);
+ goto out;
+ }
+ }
+
+ netfs_stat(&netfs_n_rh_readpage);
+ trace_netfs_read(rreq, rreq->start, rreq->len, netfs_read_trace_readpage);
+
+ netfs_get_read_request(rreq);
+
+ atomic_set(&rreq->nr_rd_ops, 1);
+ do {
+ if (!netfs_rreq_submit_slice(rreq, &debug_index))
+ break;
+
+ } while (rreq->submitted < rreq->len);
+
+ /* Keep nr_rd_ops incremented so that the ref always belongs to us, and
+ * the service code isn't punted off to a random thread pool to
+ * process.
+ */
+ do {
+ wait_var_event(&rreq->nr_rd_ops, atomic_read(&rreq->nr_rd_ops) == 1);
+ netfs_rreq_assess(rreq, false);
+ } while (test_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags));
+
+ ret = rreq->error;
+ if (ret == 0 && rreq->submitted < rreq->len) {
+ trace_netfs_failure(rreq, NULL, ret, netfs_fail_short_readpage);
+ ret = -EIO;
+ }
+out:
+ netfs_put_read_request(rreq, false);
+ return ret;
+}
+EXPORT_SYMBOL(netfs_readpage_demand);
+
/*
* Prepare a folio for writing without reading first
* @folio: The folio being prepared
diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index 638ea5d63869..de6948bcc80a 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -261,6 +261,9 @@ extern int netfs_readpage(struct file *,
struct folio *,
const struct netfs_read_request_ops *,
void *);
+extern int netfs_readpage_demand(struct folio *,
+ const struct netfs_read_request_ops *,
+ void *);
extern int netfs_write_begin(struct file *, struct address_space *,
loff_t, unsigned int, unsigned int, struct folio **,
void **,
--
2.27.0
next prev 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 ` Jeffle Xu [this message]
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 ` 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 ` [RFC 15/19] erofs: implement fscache-based metadata read Jeffle Xu
2021-12-10 7:36 ` 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-8-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.