26aaeffcaf
Add an alternate API by which the cache can be accessed through a kiocb, doing async DIO, rather than using the current API that tells the cache where all the pages are. The new API is intended to be used in conjunction with the netfs helper library. A filesystem must pick one or the other and not mix them. Filesystems wanting to use the new API must #define FSCACHE_USE_NEW_IO_API before #including the header. This prevents them from continuing to use the old API at the same time as there are incompatibilities in how the PG_fscache page bit is used. Changes: v6: - Provide a routine to shape a write so that the start and length can be aligned for DIO[3]. v4: - Use the vfs_iocb_iter_read/write() helpers[1] - Move initial definition of fscache_begin_read_operation() here. - Remove a commented-out line[2] - Combine ki->term_func calls in cachefiles_read_complete()[2]. - Remove explicit NULL initialiser[2]. - Remove extern on func decl[2]. - Put in param names on func decl[2]. - Remove redundant else[2]. - Fill out the kdoc comment for fscache_begin_read_operation(). - Rename fs/fscache/page2.c to io.c to match later patches. Signed-off-by: David Howells <dhowells@redhat.com> Reviewed-and-tested-by: Jeff Layton <jlayton@kernel.org> Tested-by: Dave Wysochanski <dwysocha@redhat.com> Tested-By: Marc Dionne <marc.dionne@auristor.com> cc: Christoph Hellwig <hch@lst.de> cc: linux-cachefs@redhat.com cc: linux-afs@lists.infradead.org cc: linux-nfs@vger.kernel.org cc: linux-cifs@vger.kernel.org cc: ceph-devel@vger.kernel.org cc: v9fs-developer@lists.sourceforge.net cc: linux-fsdevel@vger.kernel.org Link: https://lore.kernel.org/r/20210216102614.GA27555@lst.de/ [1] Link: https://lore.kernel.org/r/20210216084230.GA23669@lst.de/ [2] Link: https://lore.kernel.org/r/161781047695.463527.7463536103593997492.stgit@warthog.procyon.org.uk/ [3] Link: https://lore.kernel.org/r/161118142558.1232039.17993829899588971439.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/161161037850.2537118.8819808229350326503.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/161340402057.1303470.8038373593844486698.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/161539545919.286939.14573472672781434757.stgit@warthog.procyon.org.uk/ # v4 Link: https://lore.kernel.org/r/161653801477.2770958.10543270629064934227.stgit@warthog.procyon.org.uk/ # v5 Link: https://lore.kernel.org/r/161789084517.6155.12799689829859169640.stgit@warthog.procyon.org.uk/ # v6
117 lines
3.2 KiB
C
117 lines
3.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
/* Cache data I/O routines
|
|
*
|
|
* Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
|
|
* Written by David Howells (dhowells@redhat.com)
|
|
*/
|
|
|
|
#define FSCACHE_DEBUG_LEVEL PAGE
|
|
#include <linux/module.h>
|
|
#define FSCACHE_USE_NEW_IO_API
|
|
#include <linux/fscache-cache.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/netfs.h>
|
|
#include "internal.h"
|
|
|
|
/*
|
|
* Start a cache read operation.
|
|
* - we return:
|
|
* -ENOMEM - out of memory, some pages may be being read
|
|
* -ERESTARTSYS - interrupted, some pages may be being read
|
|
* -ENOBUFS - no backing object or space available in which to cache any
|
|
* pages not being read
|
|
* -ENODATA - no data available in the backing object for some or all of
|
|
* the pages
|
|
* 0 - dispatched a read on all pages
|
|
*/
|
|
int __fscache_begin_read_operation(struct netfs_read_request *rreq,
|
|
struct fscache_cookie *cookie)
|
|
{
|
|
struct fscache_retrieval *op;
|
|
struct fscache_object *object;
|
|
bool wake_cookie = false;
|
|
int ret;
|
|
|
|
_enter("rr=%08x", rreq->debug_id);
|
|
|
|
fscache_stat(&fscache_n_retrievals);
|
|
|
|
if (hlist_empty(&cookie->backing_objects))
|
|
goto nobufs;
|
|
|
|
if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
|
|
_leave(" = -ENOBUFS [invalidating]");
|
|
return -ENOBUFS;
|
|
}
|
|
|
|
ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
|
|
|
|
if (fscache_wait_for_deferred_lookup(cookie) < 0)
|
|
return -ERESTARTSYS;
|
|
|
|
op = fscache_alloc_retrieval(cookie, NULL, NULL, NULL);
|
|
if (!op)
|
|
return -ENOMEM;
|
|
trace_fscache_page_op(cookie, NULL, &op->op, fscache_page_op_retr_multi);
|
|
|
|
spin_lock(&cookie->lock);
|
|
|
|
if (!fscache_cookie_enabled(cookie) ||
|
|
hlist_empty(&cookie->backing_objects))
|
|
goto nobufs_unlock;
|
|
object = hlist_entry(cookie->backing_objects.first,
|
|
struct fscache_object, cookie_link);
|
|
|
|
__fscache_use_cookie(cookie);
|
|
atomic_inc(&object->n_reads);
|
|
__set_bit(FSCACHE_OP_DEC_READ_CNT, &op->op.flags);
|
|
|
|
if (fscache_submit_op(object, &op->op) < 0)
|
|
goto nobufs_unlock_dec;
|
|
spin_unlock(&cookie->lock);
|
|
|
|
fscache_stat(&fscache_n_retrieval_ops);
|
|
|
|
/* we wait for the operation to become active, and then process it
|
|
* *here*, in this thread, and not in the thread pool */
|
|
ret = fscache_wait_for_operation_activation(
|
|
object, &op->op,
|
|
__fscache_stat(&fscache_n_retrieval_op_waits),
|
|
__fscache_stat(&fscache_n_retrievals_object_dead));
|
|
if (ret < 0)
|
|
goto error;
|
|
|
|
/* ask the cache to honour the operation */
|
|
ret = object->cache->ops->begin_read_operation(rreq, op);
|
|
|
|
error:
|
|
if (ret == -ENOMEM)
|
|
fscache_stat(&fscache_n_retrievals_nomem);
|
|
else if (ret == -ERESTARTSYS)
|
|
fscache_stat(&fscache_n_retrievals_intr);
|
|
else if (ret == -ENODATA)
|
|
fscache_stat(&fscache_n_retrievals_nodata);
|
|
else if (ret < 0)
|
|
fscache_stat(&fscache_n_retrievals_nobufs);
|
|
else
|
|
fscache_stat(&fscache_n_retrievals_ok);
|
|
|
|
fscache_put_retrieval(op);
|
|
_leave(" = %d", ret);
|
|
return ret;
|
|
|
|
nobufs_unlock_dec:
|
|
atomic_dec(&object->n_reads);
|
|
wake_cookie = __fscache_unuse_cookie(cookie);
|
|
nobufs_unlock:
|
|
spin_unlock(&cookie->lock);
|
|
fscache_put_retrieval(op);
|
|
if (wake_cookie)
|
|
__fscache_wake_unused_cookie(cookie);
|
|
nobufs:
|
|
fscache_stat(&fscache_n_retrievals_nobufs);
|
|
_leave(" = -ENOBUFS");
|
|
return -ENOBUFS;
|
|
}
|
|
EXPORT_SYMBOL(__fscache_begin_read_operation);
|