mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jingbo Xu <jefflexu@linux.alibaba.com>
To: dhowells@redhat.com, linux-cachefs@redhat.com
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] fscache: introduce fscache_begin_wait_operation() helper
Date: Tue, 21 Feb 2023 18:33:13 +0800	[thread overview]
Message-ID: <20230221103313.120834-3-jefflexu@linux.alibaba.com> (raw)
In-Reply-To: <20230221103313.120834-1-jefflexu@linux.alibaba.com>

This is a variant of fscache_wait_for_operation() except that it's
exported for users of FsCache, and thus cookie->lock is held when
checking cookie's state.

Exporting fscache_begin_operation() directly is not acceptable as it
would introduce dependency of <trace/events/fscache.h> for users of
FsCache.

Signed-off-by: Jingbo Xu <jefflexu@linux.alibaba.com>
---
 fs/fscache/io.c         |  9 +++++++++
 include/linux/fscache.h | 22 ++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/fs/fscache/io.c b/fs/fscache/io.c
index 0d2b8dec8f82..6ccc5aadf151 100644
--- a/fs/fscache/io.c
+++ b/fs/fscache/io.c
@@ -158,6 +158,15 @@ int __fscache_begin_write_operation(struct netfs_cache_resources *cres,
 }
 EXPORT_SYMBOL(__fscache_begin_write_operation);
 
+int __fscache_begin_wait_operation(struct netfs_cache_resources *cres,
+				   struct fscache_cookie *cookie,
+				   enum fscache_want_state want_state)
+{
+	return fscache_begin_operation(cres, cookie, want_state,
+				       fscache_access_io_wait);
+}
+EXPORT_SYMBOL(__fscache_begin_wait_operation);
+
 /**
  * fscache_dirty_folio - Mark folio dirty and pin a cache object for writeback
  * @mapping: The mapping the folio belongs to.
diff --git a/include/linux/fscache.h b/include/linux/fscache.h
index 8e312c8323a8..708cf8db7f46 100644
--- a/include/linux/fscache.h
+++ b/include/linux/fscache.h
@@ -171,6 +171,8 @@ extern void __fscache_resize_cookie(struct fscache_cookie *, loff_t);
 extern void __fscache_invalidate(struct fscache_cookie *, const void *, loff_t, unsigned int);
 extern int __fscache_begin_read_operation(struct netfs_cache_resources *, struct fscache_cookie *);
 extern int __fscache_begin_write_operation(struct netfs_cache_resources *, struct fscache_cookie *);
+extern int __fscache_begin_wait_operation(struct netfs_cache_resources *, struct fscache_cookie *,
+					  enum fscache_want_state want_state);
 
 extern void __fscache_write_to_cache(struct fscache_cookie *, struct address_space *,
 				     loff_t, size_t, loff_t, netfs_io_terminated_t, void *,
@@ -543,6 +545,26 @@ int fscache_begin_write_operation(struct netfs_cache_resources *cres,
 	return -ENOBUFS;
 }
 
+/**
+ * fscache_begin_wait_operation - Wait for an object become accessible
+ * @cres: The cache resources for the operation being performed
+ * @cookie: The cookie representing the cache object
+ *
+ * Returns:
+ * * 0		- Success
+ * * -ENOBUFS	- No caching available
+ * * Other error code from the cache, such as -ENOMEM.
+ */
+static inline
+int fscache_begin_wait_operation(struct netfs_cache_resources *cres,
+				 struct fscache_cookie *cookie,
+				 enum fscache_want_state want_state)
+{
+	if (fscache_cookie_enabled(cookie))
+		return __fscache_begin_wait_operation(cres, cookie, want_state);
+	return -ENOBUFS;
+}
+
 /**
  * fscache_write - Start a write to the cache.
  * @cres: The cache resources to use
-- 
2.19.1.6.gb485710b


      parent reply	other threads:[~2023-02-21 10:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 10:33 [PATCH 0/2] fscache/cachefiles: some work for on-demand mode Jingbo Xu
2023-02-21 10:33 ` [PATCH 1/2] cachefiles: don't align the write IO in ondemand mode Jingbo Xu
2023-02-21 10:33 ` Jingbo Xu [this message]

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=20230221103313.120834-3-jefflexu@linux.alibaba.com \
    --to=jefflexu@linux.alibaba.com \
    --cc=dhowells@redhat.com \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-kernel@vger.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

all inboxes | Powered by JetHome®