[Linux-cachefs] [PATCH 1/2] netfs: refactor arguments for netfs_alloc_read_request
David Howells
dhowells at redhat.com
Thu Aug 26 15:00:58 UTC 2021
Below is my take on this. I've moved it earlier in the patchset, so some bits
have migrated to other patches.
---
commit b32c31951d58c605a0993da59de0132cb5ef0723
Author: Jeff Layton <jlayton at kernel.org>
Date: Thu Aug 26 09:24:42 2021 -0400
netfs: refactor arguments for netfs_alloc_read_request
Pass start and len to the rreq allocator. This should ensure that the
fields are set so that init_rreq can use them.
Also add a parameter to indicates the origin of the request. Ceph can use
this to tell whether to get caps.
Signed-off-by: Jeff Layton <jlayton at kernel.org>
Signed-off-by: David Howells <dhowells at redhat.com>
diff --git a/fs/netfs/read_helper.c b/fs/netfs/read_helper.c
index b4122653c259..19eb114ebf2a 100644
--- a/fs/netfs/read_helper.c
+++ b/fs/netfs/read_helper.c
@@ -29,8 +29,11 @@ MODULE_PARM_DESC(netfs_debug, "Netfs support debugging mask");
static void netfs_rreq_work(struct work_struct *);
static void netfs_rreq_clear_buffer(struct netfs_read_request *);
-static struct netfs_read_request *netfs_alloc_read_request(struct address_space *mapping,
- struct file *file)
+static struct netfs_read_request *netfs_alloc_read_request(
+ struct address_space *mapping,
+ struct file *file,
+ loff_t start, size_t len,
+ enum netfs_read_origin origin)
{
static atomic_t debug_ids;
struct inode *inode = file ? file_inode(file) : mapping->host;
@@ -39,8 +42,11 @@ static struct netfs_read_request *netfs_alloc_read_request(struct address_space
rreq = kzalloc(sizeof(struct netfs_read_request), GFP_KERNEL);
if (rreq) {
+ rreq->start = start;
+ rreq->len = len;
rreq->mapping = mapping;
rreq->inode = inode;
+ rreq->origin = origin;
rreq->netfs_ops = ctx->ops;
rreq->i_size = i_size_read(inode);
rreq->debug_id = atomic_inc_return(&debug_ids);
@@ -1026,11 +1032,12 @@ void netfs_readahead(struct readahead_control *ractl)
if (readahead_count(ractl) == 0)
return;
- rreq = netfs_alloc_read_request(ractl->mapping, ractl->file);
+ rreq = netfs_alloc_read_request(ractl->mapping, ractl->file,
+ readahead_pos(ractl),
+ readahead_length(ractl),
+ NETFS_READAHEAD);
if (!rreq)
return;
- rreq->start = readahead_pos(ractl);
- rreq->len = readahead_length(ractl);
ret = netfs_begin_cache_operation(rreq, ctx);
if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS)
@@ -1091,11 +1098,10 @@ int netfs_readpage(struct file *file, struct page *subpage)
_enter("%lx", folio_index(folio));
- rreq = netfs_alloc_read_request(mapping, file);
+ rreq = netfs_alloc_read_request(mapping, file, folio_file_pos(folio),
+ folio_size(folio), NETFS_SYNC_READ);
if (!rreq)
goto nomem;
- rreq->start = folio_file_pos(folio);
- rreq->len = folio_size(folio);
ret = netfs_begin_cache_operation(rreq, ctx);
if (ret == -ENOMEM || ret == -EINTR || ret == -ERESTARTSYS) {
@@ -1272,7 +1278,8 @@ int netfs_write_begin(struct file *file, struct address_space *mapping,
}
ret = -ENOMEM;
- rreq = netfs_alloc_read_request(mapping, file);
+ rreq = netfs_alloc_read_request(mapping, file, folio_file_pos(folio),
+ folio_size(folio), NETFS_READ_FOR_WRITE);
if (!rreq)
goto error;
rreq->start = folio_file_pos(folio);
diff --git a/include/linux/netfs.h b/include/linux/netfs.h
index cd572bf1dfa3..210f9414747c 100644
--- a/include/linux/netfs.h
+++ b/include/linux/netfs.h
@@ -168,6 +168,12 @@ struct netfs_read_subrequest {
#define NETFS_SREQ_NO_PROGRESS 4 /* Set if we didn't manage to read any data */
};
+enum netfs_read_origin {
+ NETFS_READAHEAD, /* This read was triggered by readahead */
+ NETFS_SYNC_READ, /* This read is a synchronous read */
+ NETFS_READ_FOR_WRITE, /* This read is to prepare a write */
+} __mode(byte);
+
/*
* Descriptor for a read helper request. This is used to make multiple I/O
* requests on a variety of sources and then stitch the result together.
@@ -186,6 +192,7 @@ struct netfs_read_request {
size_t submitted; /* Amount submitted for I/O so far */
size_t len; /* Length of the request */
short error; /* 0 or error that occurred */
+ enum netfs_read_origin origin; /* Origin of the read */
loff_t i_size; /* Size of the file */
loff_t start; /* Start position */
pgoff_t no_unlock_folio; /* Don't unlock this folio after read */
More information about the Linux-cachefs
mailing list