Commit 40a81101 authored by David Howells's avatar David Howells

netfs: Rename the netfs_io_request cleanup op and give it an op pointer

The netfs_io_request cleanup op is now always in a position to be given a
pointer to a netfs_io_request struct, so this can be passed in instead of
the mapping and private data arguments (both of which are included in the
struct).

So rename the ->cleanup op to ->free_request (to match ->init_request) and
pass in the I/O pointer.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
cc: linux-cachefs@redhat.com
parent e81fb419
...@@ -158,9 +158,10 @@ The helpers manage the read request, calling back into the network filesystem ...@@ -158,9 +158,10 @@ The helpers manage the read request, calling back into the network filesystem
through the suppplied table of operations. Waits will be performed as through the suppplied table of operations. Waits will be performed as
necessary before returning for helpers that are meant to be synchronous. necessary before returning for helpers that are meant to be synchronous.
If an error occurs and netfs_priv is non-NULL, ops->cleanup() will be called to If an error occurs, the ->free_request() will be called to clean up the
deal with it. If some parts of the request are in progress when an error netfs_io_request struct allocated. If some parts of the request are in
occurs, the request will get partially completed if sufficient data is read. progress when an error occurs, the request will get partially completed if
sufficient data is read.
Additionally, there is:: Additionally, there is::
...@@ -208,8 +209,7 @@ The above fields are the ones the netfs can use. They are: ...@@ -208,8 +209,7 @@ The above fields are the ones the netfs can use. They are:
* ``netfs_priv`` * ``netfs_priv``
The network filesystem's private data. The value for this can be passed in The network filesystem's private data. The value for this can be passed in
to the helper functions or set during the request. The ->cleanup() op will to the helper functions or set during the request.
be called if this is non-NULL at the end.
* ``start`` * ``start``
* ``len`` * ``len``
...@@ -294,6 +294,7 @@ through which it can issue requests and negotiate:: ...@@ -294,6 +294,7 @@ through which it can issue requests and negotiate::
struct netfs_request_ops { struct netfs_request_ops {
void (*init_request)(struct netfs_io_request *rreq, struct file *file); void (*init_request)(struct netfs_io_request *rreq, struct file *file);
void (*free_request)(struct netfs_io_request *rreq);
int (*begin_cache_operation)(struct netfs_io_request *rreq); int (*begin_cache_operation)(struct netfs_io_request *rreq);
void (*expand_readahead)(struct netfs_io_request *rreq); void (*expand_readahead)(struct netfs_io_request *rreq);
bool (*clamp_length)(struct netfs_io_subrequest *subreq); bool (*clamp_length)(struct netfs_io_subrequest *subreq);
...@@ -302,7 +303,6 @@ through which it can issue requests and negotiate:: ...@@ -302,7 +303,6 @@ through which it can issue requests and negotiate::
int (*check_write_begin)(struct file *file, loff_t pos, unsigned len, int (*check_write_begin)(struct file *file, loff_t pos, unsigned len,
struct folio *folio, void **_fsdata); struct folio *folio, void **_fsdata);
void (*done)(struct netfs_io_request *rreq); void (*done)(struct netfs_io_request *rreq);
void (*cleanup)(struct address_space *mapping, void *netfs_priv);
}; };
The operations are as follows: The operations are as follows:
...@@ -310,7 +310,12 @@ The operations are as follows: ...@@ -310,7 +310,12 @@ The operations are as follows:
* ``init_request()`` * ``init_request()``
[Optional] This is called to initialise the request structure. It is given [Optional] This is called to initialise the request structure. It is given
the file for reference and can modify the ->netfs_priv value. the file for reference.
* ``free_request()``
[Optional] This is called as the request is being deallocated so that the
filesystem can clean up any state it has attached there.
* ``begin_cache_operation()`` * ``begin_cache_operation()``
...@@ -384,11 +389,6 @@ The operations are as follows: ...@@ -384,11 +389,6 @@ The operations are as follows:
[Optional] This is called after the folios in the request have all been [Optional] This is called after the folios in the request have all been
unlocked (and marked uptodate if applicable). unlocked (and marked uptodate if applicable).
* ``cleanup``
[Optional] This is called as the request is being deallocated so that the
filesystem can clean up ->netfs_priv.
Read Helper Procedure Read Helper Procedure
......
...@@ -66,13 +66,12 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file) ...@@ -66,13 +66,12 @@ static int v9fs_init_request(struct netfs_io_request *rreq, struct file *file)
} }
/** /**
* v9fs_req_cleanup - Cleanup request initialized by v9fs_init_request * v9fs_free_request - Cleanup request initialized by v9fs_init_rreq
* @mapping: unused mapping of request to cleanup * @rreq: The I/O request to clean up
* @priv: private data to cleanup, a fid, guaranted non-null.
*/ */
static void v9fs_req_cleanup(struct address_space *mapping, void *priv) static void v9fs_free_request(struct netfs_io_request *rreq)
{ {
struct p9_fid *fid = priv; struct p9_fid *fid = rreq->netfs_priv;
p9_client_clunk(fid); p9_client_clunk(fid);
} }
...@@ -94,9 +93,9 @@ static int v9fs_begin_cache_operation(struct netfs_io_request *rreq) ...@@ -94,9 +93,9 @@ static int v9fs_begin_cache_operation(struct netfs_io_request *rreq)
const struct netfs_request_ops v9fs_req_ops = { const struct netfs_request_ops v9fs_req_ops = {
.init_request = v9fs_init_request, .init_request = v9fs_init_request,
.free_request = v9fs_free_request,
.begin_cache_operation = v9fs_begin_cache_operation, .begin_cache_operation = v9fs_begin_cache_operation,
.issue_read = v9fs_issue_read, .issue_read = v9fs_issue_read,
.cleanup = v9fs_req_cleanup,
}; };
/** /**
......
...@@ -382,17 +382,17 @@ static int afs_check_write_begin(struct file *file, loff_t pos, unsigned len, ...@@ -382,17 +382,17 @@ static int afs_check_write_begin(struct file *file, loff_t pos, unsigned len,
return test_bit(AFS_VNODE_DELETED, &vnode->flags) ? -ESTALE : 0; return test_bit(AFS_VNODE_DELETED, &vnode->flags) ? -ESTALE : 0;
} }
static void afs_priv_cleanup(struct address_space *mapping, void *netfs_priv) static void afs_free_request(struct netfs_io_request *rreq)
{ {
key_put(netfs_priv); key_put(rreq->netfs_priv);
} }
const struct netfs_request_ops afs_req_ops = { const struct netfs_request_ops afs_req_ops = {
.init_request = afs_init_request, .init_request = afs_init_request,
.free_request = afs_free_request,
.begin_cache_operation = afs_begin_cache_operation, .begin_cache_operation = afs_begin_cache_operation,
.check_write_begin = afs_check_write_begin, .check_write_begin = afs_check_write_begin,
.issue_read = afs_issue_read, .issue_read = afs_issue_read,
.cleanup = afs_priv_cleanup,
}; };
int afs_write_inode(struct inode *inode, struct writeback_control *wbc) int afs_write_inode(struct inode *inode, struct writeback_control *wbc)
......
...@@ -394,11 +394,10 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file) ...@@ -394,11 +394,10 @@ static int ceph_init_request(struct netfs_io_request *rreq, struct file *file)
return 0; return 0;
} }
static void ceph_readahead_cleanup(struct address_space *mapping, void *priv) static void ceph_netfs_free_request(struct netfs_io_request *rreq)
{ {
struct inode *inode = mapping->host; struct ceph_inode_info *ci = ceph_inode(rreq->inode);
struct ceph_inode_info *ci = ceph_inode(inode); int got = (uintptr_t)rreq->netfs_priv;
int got = (uintptr_t)priv;
if (got) if (got)
ceph_put_cap_refs(ci, got); ceph_put_cap_refs(ci, got);
...@@ -406,12 +405,12 @@ static void ceph_readahead_cleanup(struct address_space *mapping, void *priv) ...@@ -406,12 +405,12 @@ static void ceph_readahead_cleanup(struct address_space *mapping, void *priv)
const struct netfs_request_ops ceph_netfs_ops = { const struct netfs_request_ops ceph_netfs_ops = {
.init_request = ceph_init_request, .init_request = ceph_init_request,
.free_request = ceph_netfs_free_request,
.begin_cache_operation = ceph_begin_cache_operation, .begin_cache_operation = ceph_begin_cache_operation,
.issue_read = ceph_netfs_issue_read, .issue_read = ceph_netfs_issue_read,
.expand_readahead = ceph_netfs_expand_readahead, .expand_readahead = ceph_netfs_expand_readahead,
.clamp_length = ceph_netfs_clamp_length, .clamp_length = ceph_netfs_clamp_length,
.check_write_begin = ceph_netfs_check_write_begin, .check_write_begin = ceph_netfs_check_write_begin,
.cleanup = ceph_readahead_cleanup,
}; };
#ifdef CONFIG_CEPH_FSCACHE #ifdef CONFIG_CEPH_FSCACHE
......
...@@ -75,10 +75,10 @@ static void netfs_free_request(struct work_struct *work) ...@@ -75,10 +75,10 @@ static void netfs_free_request(struct work_struct *work)
struct netfs_io_request *rreq = struct netfs_io_request *rreq =
container_of(work, struct netfs_io_request, work); container_of(work, struct netfs_io_request, work);
netfs_clear_subrequests(rreq, false);
if (rreq->netfs_priv)
rreq->netfs_ops->cleanup(rreq->mapping, rreq->netfs_priv);
trace_netfs_rreq(rreq, netfs_rreq_trace_free); trace_netfs_rreq(rreq, netfs_rreq_trace_free);
netfs_clear_subrequests(rreq, false);
if (rreq->netfs_ops->free_request)
rreq->netfs_ops->free_request(rreq);
if (rreq->cache_resources.ops) if (rreq->cache_resources.ops)
rreq->cache_resources.ops->end_operation(&rreq->cache_resources); rreq->cache_resources.ops->end_operation(&rreq->cache_resources);
kfree(rreq); kfree(rreq);
......
...@@ -206,7 +206,9 @@ struct netfs_io_request { ...@@ -206,7 +206,9 @@ struct netfs_io_request {
*/ */
struct netfs_request_ops { struct netfs_request_ops {
int (*init_request)(struct netfs_io_request *rreq, struct file *file); int (*init_request)(struct netfs_io_request *rreq, struct file *file);
void (*free_request)(struct netfs_io_request *rreq);
int (*begin_cache_operation)(struct netfs_io_request *rreq); int (*begin_cache_operation)(struct netfs_io_request *rreq);
void (*expand_readahead)(struct netfs_io_request *rreq); void (*expand_readahead)(struct netfs_io_request *rreq);
bool (*clamp_length)(struct netfs_io_subrequest *subreq); bool (*clamp_length)(struct netfs_io_subrequest *subreq);
void (*issue_read)(struct netfs_io_subrequest *subreq); void (*issue_read)(struct netfs_io_subrequest *subreq);
...@@ -214,7 +216,6 @@ struct netfs_request_ops { ...@@ -214,7 +216,6 @@ struct netfs_request_ops {
int (*check_write_begin)(struct file *file, loff_t pos, unsigned len, int (*check_write_begin)(struct file *file, loff_t pos, unsigned len,
struct folio *folio, void **_fsdata); struct folio *folio, void **_fsdata);
void (*done)(struct netfs_io_request *rreq); void (*done)(struct netfs_io_request *rreq);
void (*cleanup)(struct address_space *mapping, void *netfs_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