From 2de160417315b8d64455fe03e9bb7d3308ac3281 Mon Sep 17 00:00:00 2001 From: David Howells Date: Thu, 20 Jan 2022 21:55:46 +0000 Subject: 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 Reviewed-by: Jeff Layton 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 --- fs/netfs/read_helper.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'fs/netfs/read_helper.c') 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; -- cgit v1.2.3