@@ -7,6 +7,8 @@ Network Filesystem Helper Library
77.. Contents:
88
99 - Overview.
10+ - Per-inode context.
11+ - Inode context helper functions.
1012 - Buffered read helpers.
1113 - Read helper functions.
1214 - Read helper structures.
@@ -28,6 +30,69 @@ Note that the library module doesn't link against local caching directly, so
2830access must be provided by the netfs.
2931
3032
33+ Per-Inode Context
34+ =================
35+
36+ The network filesystem helper library needs a place to store a bit of state for
37+ its use on each netfs inode it is helping to manage. To this end, a context
38+ structure is defined::
39+
40+ struct netfs_i_context {
41+ const struct netfs_request_ops *ops;
42+ struct fscache_cookie *cache;
43+ };
44+
45+ A network filesystem that wants to use netfs lib must place one of these
46+ directly after the VFS ``struct inode `` it allocates, usually as part of its
47+ own struct. This can be done in a way similar to the following::
48+
49+ struct my_inode {
50+ struct {
51+ /* These must be contiguous */
52+ struct inode vfs_inode;
53+ struct netfs_i_context netfs_ctx;
54+ };
55+ ...
56+ };
57+
58+ This allows netfslib to find its state by simple offset from the inode pointer,
59+ thereby allowing the netfslib helper functions to be pointed to directly by the
60+ VFS/VM operation tables.
61+
62+ The structure contains the following fields:
63+
64+ * ``ops ``
65+
66+ The set of operations provided by the network filesystem to netfslib.
67+
68+ * ``cache ``
69+
70+ Local caching cookie, or NULL if no caching is enabled. This field does not
71+ exist if fscache is disabled.
72+
73+
74+ Inode Context Helper Functions
75+ ------------------------------
76+
77+ To help deal with the per-inode context, a number helper functions are
78+ provided. Firstly, a function to perform basic initialisation on a context and
79+ set the operations table pointer::
80+
81+ void netfs_i_context_init(struct inode *inode,
82+ const struct netfs_request_ops *ops);
83+
84+ then two functions to cast between the VFS inode structure and the netfs
85+ context::
86+
87+ struct netfs_i_context *netfs_i_context(struct inode *inode);
88+ struct inode *netfs_inode(struct netfs_i_context *ctx);
89+
90+ and finally, a function to get the cache cookie pointer from the context
91+ attached to an inode (or NULL if fscache is disabled)::
92+
93+ struct fscache_cookie *netfs_i_cookie(struct inode *inode);
94+
95+
3196Buffered Read Helpers
3297=====================
3398
@@ -70,38 +135,22 @@ Read Helper Functions
70135
71136Three read helpers are provided::
72137
73- void netfs_readahead(struct readahead_control *ractl,
74- const struct netfs_request_ops *ops,
75- void *netfs_priv);
138+ void netfs_readahead(struct readahead_control *ractl);
76139 int netfs_readpage(struct file *file,
77- struct folio *folio,
78- const struct netfs_request_ops *ops,
79- void *netfs_priv);
140+ struct page *page);
80141 int netfs_write_begin(struct file *file,
81142 struct address_space *mapping,
82143 loff_t pos,
83144 unsigned int len,
84145 unsigned int flags,
85146 struct folio **_folio,
86- void **_fsdata,
87- const struct netfs_request_ops *ops,
88- void *netfs_priv);
89-
90- Each corresponds to a VM operation, with the addition of a couple of parameters
91- for the use of the read helpers:
147+ void **_fsdata);
92148
93- * ``ops ``
94-
95- A table of operations through which the helpers can talk to the filesystem.
96-
97- * ``netfs_priv ``
149+ Each corresponds to a VM address space operation. These operations use the
150+ state in the per-inode context.
98151
99- Filesystem private data (can be NULL).
100-
101- Both of these values will be stored into the read request structure.
102-
103- For ->readahead() and ->readpage(), the network filesystem should just jump
104- into the corresponding read helper; whereas for ->write_begin(), it may be a
152+ For ->readahead() and ->readpage(), the network filesystem just point directly
153+ at the corresponding read helper; whereas for ->write_begin(), it may be a
105154little more complicated as the network filesystem might want to flush
106155conflicting writes or track dirty data and needs to put the acquired folio if
107156an error occurs after calling the helper.
@@ -246,7 +295,6 @@ through which it can issue requests and negotiate::
246295
247296 struct netfs_request_ops {
248297 void (*init_request)(struct netfs_io_request *rreq, struct file *file);
249- bool (*is_cache_enabled)(struct inode *inode);
250298 int (*begin_cache_operation)(struct netfs_io_request *rreq);
251299 void (*expand_readahead)(struct netfs_io_request *rreq);
252300 bool (*clamp_length)(struct netfs_io_subrequest *subreq);
@@ -265,11 +313,6 @@ The operations are as follows:
265313 [Optional] This is called to initialise the request structure. It is given
266314 the file for reference and can modify the ->netfs_priv value.
267315
268- * ``is_cache_enabled() ``
269-
270- [Required] This is called by netfs_write_begin() to ask if the file is being
271- cached. It should return true if it is being cached and false otherwise.
272-
273316 * ``begin_cache_operation() ``
274317
275318 [Optional] This is called to ask the network filesystem to call into the
0 commit comments