summaryrefslogtreecommitdiff
path: root/fs/netfs
diff options
context:
space:
mode:
authorDavid Howells <dhowells@redhat.com>2022-01-20 21:55:46 +0000
committerDavid Howells <dhowells@redhat.com>2022-03-18 09:24:00 +0000
commit2de160417315b8d64455fe03e9bb7d3308ac3281 (patch)
treefe7a61cba73b3f0e025e859c2bb7609818086da3 /fs/netfs
parent663dfb65c3b3ea4b8e1944680352992d58f3aa22 (diff)
netfs: Change ->init_request() to return an error code
Change the request initialisation function to return an error code so that the network filesystem can return a failure (ENOMEM, for example). This will also allow ceph to abort a ->readahead() op if the server refuses to give it a cap allowing local caching from within the netfslib framework (errors aren't passed back through ->readahead(), so returning, say, -ENOBUFS will cause the op to be aborted). Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> cc: linux-cachefs@redhat.com Link: https://lore.kernel.org/r/164678212401.1200972.16537041523832944934.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/164692905398.2099075.5238033621684646524.stgit@warthog.procyon.org.uk/ # v3
Diffstat (limited to 'fs/netfs')
-rw-r--r--fs/netfs/objects.c41
-rw-r--r--fs/netfs/read_helper.c20
2 files changed, 36 insertions, 25 deletions
diff --git a/fs/netfs/objects.c b/fs/netfs/objects.c
index 986d7a9d25dd..ae18827e156b 100644
--- a/fs/netfs/objects.c
+++ b/fs/netfs/objects.c
@@ -20,27 +20,34 @@ struct netfs_io_request *netfs_alloc_request(struct address_space *mapping,
{
static atomic_t debug_ids;
struct netfs_io_request *rreq;
+ int ret;
rreq = kzalloc(sizeof(struct netfs_io_request), GFP_KERNEL);
- if (rreq) {
- rreq->start = start;
- rreq->len = len;
- rreq->origin = origin;
- rreq->netfs_ops = ops;
- rreq->netfs_priv = netfs_priv;
- rreq->mapping = mapping;
- rreq->inode = file_inode(file);
- rreq->i_size = i_size_read(rreq->inode);
- rreq->debug_id = atomic_inc_return(&debug_ids);
- INIT_LIST_HEAD(&rreq->subrequests);
- INIT_WORK(&rreq->work, netfs_rreq_work);
- refcount_set(&rreq->ref, 1);
- __set_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags);
- if (ops->init_request)
- ops->init_request(rreq, file);
- netfs_stat(&netfs_n_rh_rreq);
+ if (!rreq)
+ return ERR_PTR(-ENOMEM);
+
+ rreq->start = start;
+ rreq->len = len;
+ rreq->origin = origin;
+ rreq->netfs_ops = ops;
+ rreq->netfs_priv = netfs_priv;
+ rreq->mapping = mapping;
+ rreq->inode = file_inode(file);
+ rreq->i_size = i_size_read(rreq->inode);
+ rreq->debug_id = atomic_inc_return(&debug_ids);
+ INIT_LIST_HEAD(&rreq->subrequests);
+ INIT_WORK(&rreq->work, netfs_rreq_work);
+ refcount_set(&rreq->ref, 1);
+ __set_bit(NETFS_RREQ_IN_PROGRESS, &rreq->flags);
+ if (rreq->netfs_ops->init_request) {
+ ret = rreq->netfs_ops->init_request(rreq, file);
+ if (ret < 0) {
+ kfree(rreq);
+ return ERR_PTR(ret);
+ }
}
+ netfs_stat(&netfs_n_rh_rreq);
return rreq;
}
diff --git a/fs/netfs/read_helper.c b/fs/netfs/read_helper.c
index dea085715286..b5176f4320f4 100644
--- a/fs/netfs/read_helper.c
+++ b/fs/netfs/read_helper.c
@@ -768,7 +768,7 @@ void netfs_readahead(struct readahead_control *ractl,
readahead_pos(ractl),
readahead_length(ractl),
NETFS_READAHEAD);
- if (!rreq)
+ if (IS_ERR(rreq))
goto cleanup;
if (ops->begin_cache_operation) {
@@ -842,11 +842,9 @@ int netfs_readpage(struct file *file,
rreq = netfs_alloc_request(folio->mapping, file, ops, netfs_priv,
folio_file_pos(folio), folio_size(folio),
NETFS_READPAGE);
- if (!rreq) {
- if (netfs_priv)
- ops->cleanup(folio_file_mapping(folio), netfs_priv);
- folio_unlock(folio);
- return -ENOMEM;
+ if (IS_ERR(rreq)) {
+ ret = PTR_ERR(rreq);
+ goto alloc_error;
}
if (ops->begin_cache_operation) {
@@ -887,6 +885,11 @@ int netfs_readpage(struct file *file,
out:
netfs_put_request(rreq, false, netfs_rreq_trace_put_hold);
return ret;
+alloc_error:
+ if (netfs_priv)
+ ops->cleanup(folio_file_mapping(folio), netfs_priv);
+ folio_unlock(folio);
+ return ret;
}
EXPORT_SYMBOL(netfs_readpage);
@@ -1007,12 +1010,13 @@ retry:
goto have_folio_no_wait;
}
- ret = -ENOMEM;
rreq = netfs_alloc_request(mapping, file, ops, netfs_priv,
folio_file_pos(folio), folio_size(folio),
NETFS_READ_FOR_WRITE);
- if (!rreq)
+ if (IS_ERR(rreq)) {
+ ret = PTR_ERR(rreq);
goto error;
+ }
rreq->no_unlock_folio = folio_index(folio);
__set_bit(NETFS_RREQ_NO_UNLOCK_FOLIO, &rreq->flags);
netfs_priv = NULL;