diff options
author | David Howells <dhowells@redhat.com> | 2022-01-20 21:55:46 +0000 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2022-03-18 09:24:00 +0000 |
commit | 2de160417315b8d64455fe03e9bb7d3308ac3281 (patch) | |
tree | fe7a61cba73b3f0e025e859c2bb7609818086da3 /fs/netfs/objects.c | |
parent | 663dfb65c3b3ea4b8e1944680352992d58f3aa22 (diff) | |
download | lwn-2de160417315b8d64455fe03e9bb7d3308ac3281.tar.gz lwn-2de160417315b8d64455fe03e9bb7d3308ac3281.zip |
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/objects.c')
-rw-r--r-- | fs/netfs/objects.c | 41 |
1 files changed, 24 insertions, 17 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; } |