Commit 3a11b3a8 authored by David Howells's avatar David Howells

netfs: Pass more information on how to deal with a hole in the cache

Pass more information to the cache on how to deal with a hole if it
encounters one when trying to read from the cache.  Three options are
provided:

 (1) NETFS_READ_HOLE_IGNORE.  Read the hole along with the data, assuming
     it to be a punched-out extent by the backing filesystem.

 (2) NETFS_READ_HOLE_CLEAR.  If there's a hole, erase the requested region
     of the cache and clear the read buffer.

 (3) NETFS_READ_HOLE_FAIL.  Fail the read if a hole is detected.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
cc: linux-cachefs@redhat.com
Link: https://lore.kernel.org/r/163819612321.215744.9738308885948264476.stgit@warthog.procyon.org.uk/ # v1
Link: https://lore.kernel.org/r/163906914460.143852.6284247083607910189.stgit@warthog.procyon.org.uk/ # v2
Link: https://lore.kernel.org/r/163967119923.1823006.15637375885194297582.stgit@warthog.procyon.org.uk/ # v3
Link: https://lore.kernel.org/r/164021519762.640689.16994364383313159319.stgit@warthog.procyon.org.uk/ # v4
parent ed1235eb
...@@ -170,7 +170,7 @@ static void netfs_cache_read_terminated(void *priv, ssize_t transferred_or_error ...@@ -170,7 +170,7 @@ static void netfs_cache_read_terminated(void *priv, ssize_t transferred_or_error
*/ */
static void netfs_read_from_cache(struct netfs_read_request *rreq, static void netfs_read_from_cache(struct netfs_read_request *rreq,
struct netfs_read_subrequest *subreq, struct netfs_read_subrequest *subreq,
bool seek_data) enum netfs_read_from_hole read_hole)
{ {
struct netfs_cache_resources *cres = &rreq->cache_resources; struct netfs_cache_resources *cres = &rreq->cache_resources;
struct iov_iter iter; struct iov_iter iter;
...@@ -180,7 +180,7 @@ static void netfs_read_from_cache(struct netfs_read_request *rreq, ...@@ -180,7 +180,7 @@ static void netfs_read_from_cache(struct netfs_read_request *rreq,
subreq->start + subreq->transferred, subreq->start + subreq->transferred,
subreq->len - subreq->transferred); subreq->len - subreq->transferred);
cres->ops->read(cres, subreq->start, &iter, seek_data, cres->ops->read(cres, subreq->start, &iter, read_hole,
netfs_cache_read_terminated, subreq); netfs_cache_read_terminated, subreq);
} }
...@@ -461,7 +461,7 @@ static void netfs_rreq_short_read(struct netfs_read_request *rreq, ...@@ -461,7 +461,7 @@ static void netfs_rreq_short_read(struct netfs_read_request *rreq,
netfs_get_read_subrequest(subreq); netfs_get_read_subrequest(subreq);
atomic_inc(&rreq->nr_rd_ops); atomic_inc(&rreq->nr_rd_ops);
if (subreq->source == NETFS_READ_FROM_CACHE) if (subreq->source == NETFS_READ_FROM_CACHE)
netfs_read_from_cache(rreq, subreq, true); netfs_read_from_cache(rreq, subreq, NETFS_READ_HOLE_CLEAR);
else else
netfs_read_from_server(rreq, subreq); netfs_read_from_server(rreq, subreq);
} }
...@@ -789,7 +789,7 @@ static bool netfs_rreq_submit_slice(struct netfs_read_request *rreq, ...@@ -789,7 +789,7 @@ static bool netfs_rreq_submit_slice(struct netfs_read_request *rreq,
netfs_read_from_server(rreq, subreq); netfs_read_from_server(rreq, subreq);
break; break;
case NETFS_READ_FROM_CACHE: case NETFS_READ_FROM_CACHE:
netfs_read_from_cache(rreq, subreq, false); netfs_read_from_cache(rreq, subreq, NETFS_READ_HOLE_IGNORE);
break; break;
default: default:
BUG(); BUG();
......
...@@ -196,6 +196,15 @@ struct netfs_read_request_ops { ...@@ -196,6 +196,15 @@ struct netfs_read_request_ops {
void (*cleanup)(struct address_space *mapping, void *netfs_priv); void (*cleanup)(struct address_space *mapping, void *netfs_priv);
}; };
/*
* How to handle reading from a hole.
*/
enum netfs_read_from_hole {
NETFS_READ_HOLE_IGNORE,
NETFS_READ_HOLE_CLEAR,
NETFS_READ_HOLE_FAIL,
};
/* /*
* Table of operations for access to a cache. This is obtained by * Table of operations for access to a cache. This is obtained by
* rreq->ops->begin_cache_operation(). * rreq->ops->begin_cache_operation().
...@@ -208,7 +217,7 @@ struct netfs_cache_ops { ...@@ -208,7 +217,7 @@ struct netfs_cache_ops {
int (*read)(struct netfs_cache_resources *cres, int (*read)(struct netfs_cache_resources *cres,
loff_t start_pos, loff_t start_pos,
struct iov_iter *iter, struct iov_iter *iter,
bool seek_data, enum netfs_read_from_hole read_hole,
netfs_io_terminated_t term_func, netfs_io_terminated_t term_func,
void *term_func_priv); void *term_func_priv);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment