Skip to content

Commit eb49794

Browse files
dhowellsmartinetd
authored andcommitted
9p: Convert to using the netfs helper lib to do reads and caching
Convert the 9p filesystem to use the netfs helper lib to handle readpage, readahead and write_begin, converting those into a common issue_op for the filesystem itself to handle. The netfs helper lib also handles reading from fscache if a cache is available, and interleaving reads from both sources. This change also switches from the old fscache I/O API to the new one, meaning that fscache no longer keeps track of netfs pages and instead does async DIO between the backing files and the 9p file pagecache. As a part of this change, the handling of PG_fscache changes. It now just means that the cache has a write I/O operation in progress on a page (PG_locked is used for a read I/O op). Note that this is a cut-down version of the fscache rewrite and does not change any of the cookie and cache coherency handling. Changes ======= ver #4: - Rebase on top of folios. - Don't use wait_on_page_bit_killable(). ver #3: - v9fs_req_issue_op() needs to terminate the subrequest. - v9fs_write_end() needs to call SetPageUptodate() a bit more often. - It's not CONFIG_{AFS,V9FS}_FSCACHE[1] - v9fs_init_rreq() should take a ref on the p9_fid and the cleanup should drop it [from Dominique Martinet]. Signed-off-by: David Howells <[email protected]> Reviewed-and-tested-by: Dominique Martinet <[email protected]> cc: [email protected] cc: [email protected] Link: https://lore.kernel.org/r/[email protected]/ [1] Link: https://lore.kernel.org/r/163162772646.438332.16323773205855053535.stgit@warthog.procyon.org.uk/ # rfc Link: https://lore.kernel.org/r/163189109885.2509237.7153668924503399173.stgit@warthog.procyon.org.uk/ # rfc v2 Link: https://lore.kernel.org/r/163363943896.1980952.1226527304649419689.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/163551662876.1877519.14706391695553204156.stgit@warthog.procyon.org.uk/ # v4 Link: https://lore.kernel.org/r/163584179557.4023316.11089762304657644342.stgit@warthog.procyon.org.uk # rebase on folio Signed-off-by: Dominique Martinet <[email protected]>
1 parent 0dc54bd commit eb49794

File tree

6 files changed

+122
-334
lines changed

6 files changed

+122
-334
lines changed

fs/9p/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
config 9P_FS
33
tristate "Plan 9 Resource Sharing Support (9P2000)"
44
depends on INET && NET_9P
5+
select NETFS_SUPPORT
56
help
67
If you say Y here, you will get experimental support for
78
Plan 9 resource sharing via the 9P2000 protocol.

fs/9p/cache.c

Lines changed: 0 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -199,140 +199,3 @@ void v9fs_cache_inode_reset_cookie(struct inode *inode)
199199

200200
mutex_unlock(&v9inode->fscache_lock);
201201
}
202-
203-
int __v9fs_fscache_release_page(struct page *page, gfp_t gfp)
204-
{
205-
struct inode *inode = page->mapping->host;
206-
struct v9fs_inode *v9inode = V9FS_I(inode);
207-
208-
BUG_ON(!v9inode->fscache);
209-
210-
return fscache_maybe_release_page(v9inode->fscache, page, gfp);
211-
}
212-
213-
void __v9fs_fscache_invalidate_page(struct page *page)
214-
{
215-
struct inode *inode = page->mapping->host;
216-
struct v9fs_inode *v9inode = V9FS_I(inode);
217-
218-
BUG_ON(!v9inode->fscache);
219-
220-
if (PageFsCache(page)) {
221-
fscache_wait_on_page_write(v9inode->fscache, page);
222-
BUG_ON(!PageLocked(page));
223-
fscache_uncache_page(v9inode->fscache, page);
224-
}
225-
}
226-
227-
static void v9fs_vfs_readpage_complete(struct page *page, void *data,
228-
int error)
229-
{
230-
if (!error)
231-
SetPageUptodate(page);
232-
233-
unlock_page(page);
234-
}
235-
236-
/*
237-
* __v9fs_readpage_from_fscache - read a page from cache
238-
*
239-
* Returns 0 if the pages are in cache and a BIO is submitted,
240-
* 1 if the pages are not in cache and -error otherwise.
241-
*/
242-
243-
int __v9fs_readpage_from_fscache(struct inode *inode, struct page *page)
244-
{
245-
int ret;
246-
const struct v9fs_inode *v9inode = V9FS_I(inode);
247-
248-
p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
249-
if (!v9inode->fscache)
250-
return -ENOBUFS;
251-
252-
ret = fscache_read_or_alloc_page(v9inode->fscache,
253-
page,
254-
v9fs_vfs_readpage_complete,
255-
NULL,
256-
GFP_KERNEL);
257-
switch (ret) {
258-
case -ENOBUFS:
259-
case -ENODATA:
260-
p9_debug(P9_DEBUG_FSC, "page/inode not in cache %d\n", ret);
261-
return 1;
262-
case 0:
263-
p9_debug(P9_DEBUG_FSC, "BIO submitted\n");
264-
return ret;
265-
default:
266-
p9_debug(P9_DEBUG_FSC, "ret %d\n", ret);
267-
return ret;
268-
}
269-
}
270-
271-
/*
272-
* __v9fs_readpages_from_fscache - read multiple pages from cache
273-
*
274-
* Returns 0 if the pages are in cache and a BIO is submitted,
275-
* 1 if the pages are not in cache and -error otherwise.
276-
*/
277-
278-
int __v9fs_readpages_from_fscache(struct inode *inode,
279-
struct address_space *mapping,
280-
struct list_head *pages,
281-
unsigned *nr_pages)
282-
{
283-
int ret;
284-
const struct v9fs_inode *v9inode = V9FS_I(inode);
285-
286-
p9_debug(P9_DEBUG_FSC, "inode %p pages %u\n", inode, *nr_pages);
287-
if (!v9inode->fscache)
288-
return -ENOBUFS;
289-
290-
ret = fscache_read_or_alloc_pages(v9inode->fscache,
291-
mapping, pages, nr_pages,
292-
v9fs_vfs_readpage_complete,
293-
NULL,
294-
mapping_gfp_mask(mapping));
295-
switch (ret) {
296-
case -ENOBUFS:
297-
case -ENODATA:
298-
p9_debug(P9_DEBUG_FSC, "pages/inodes not in cache %d\n", ret);
299-
return 1;
300-
case 0:
301-
BUG_ON(!list_empty(pages));
302-
BUG_ON(*nr_pages != 0);
303-
p9_debug(P9_DEBUG_FSC, "BIO submitted\n");
304-
return ret;
305-
default:
306-
p9_debug(P9_DEBUG_FSC, "ret %d\n", ret);
307-
return ret;
308-
}
309-
}
310-
311-
/*
312-
* __v9fs_readpage_to_fscache - write a page to the cache
313-
*
314-
*/
315-
316-
void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page)
317-
{
318-
int ret;
319-
const struct v9fs_inode *v9inode = V9FS_I(inode);
320-
321-
p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
322-
ret = fscache_write_page(v9inode->fscache, page,
323-
i_size_read(&v9inode->vfs_inode), GFP_KERNEL);
324-
p9_debug(P9_DEBUG_FSC, "ret = %d\n", ret);
325-
if (ret != 0)
326-
v9fs_uncache_page(inode, page);
327-
}
328-
329-
/*
330-
* wait for a page to complete writing to the cache
331-
*/
332-
void __v9fs_fscache_wait_on_page_write(struct inode *inode, struct page *page)
333-
{
334-
const struct v9fs_inode *v9inode = V9FS_I(inode);
335-
p9_debug(P9_DEBUG_FSC, "inode %p page %p\n", inode, page);
336-
if (PageFsCache(page))
337-
fscache_wait_on_page_write(v9inode->fscache, page);
338-
}

fs/9p/cache.h

Lines changed: 3 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
#ifndef _9P_CACHE_H
99
#define _9P_CACHE_H
10-
#ifdef CONFIG_9P_FSCACHE
10+
#define FSCACHE_USE_NEW_IO_API
1111
#include <linux/fscache.h>
12-
#include <linux/spinlock.h>
12+
13+
#ifdef CONFIG_9P_FSCACHE
1314

1415
extern struct fscache_netfs v9fs_cache_netfs;
1516
extern const struct fscache_cookie_def v9fs_cache_session_index_def;
@@ -27,64 +28,6 @@ extern void v9fs_cache_inode_reset_cookie(struct inode *inode);
2728
extern int __v9fs_cache_register(void);
2829
extern void __v9fs_cache_unregister(void);
2930

30-
extern int __v9fs_fscache_release_page(struct page *page, gfp_t gfp);
31-
extern void __v9fs_fscache_invalidate_page(struct page *page);
32-
extern int __v9fs_readpage_from_fscache(struct inode *inode,
33-
struct page *page);
34-
extern int __v9fs_readpages_from_fscache(struct inode *inode,
35-
struct address_space *mapping,
36-
struct list_head *pages,
37-
unsigned *nr_pages);
38-
extern void __v9fs_readpage_to_fscache(struct inode *inode, struct page *page);
39-
extern void __v9fs_fscache_wait_on_page_write(struct inode *inode,
40-
struct page *page);
41-
42-
static inline int v9fs_fscache_release_page(struct page *page,
43-
gfp_t gfp)
44-
{
45-
return __v9fs_fscache_release_page(page, gfp);
46-
}
47-
48-
static inline void v9fs_fscache_invalidate_page(struct page *page)
49-
{
50-
__v9fs_fscache_invalidate_page(page);
51-
}
52-
53-
static inline int v9fs_readpage_from_fscache(struct inode *inode,
54-
struct page *page)
55-
{
56-
return __v9fs_readpage_from_fscache(inode, page);
57-
}
58-
59-
static inline int v9fs_readpages_from_fscache(struct inode *inode,
60-
struct address_space *mapping,
61-
struct list_head *pages,
62-
unsigned *nr_pages)
63-
{
64-
return __v9fs_readpages_from_fscache(inode, mapping, pages,
65-
nr_pages);
66-
}
67-
68-
static inline void v9fs_readpage_to_fscache(struct inode *inode,
69-
struct page *page)
70-
{
71-
if (PageFsCache(page))
72-
__v9fs_readpage_to_fscache(inode, page);
73-
}
74-
75-
static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
76-
{
77-
struct v9fs_inode *v9inode = V9FS_I(inode);
78-
fscache_uncache_page(v9inode->fscache, page);
79-
BUG_ON(PageFsCache(page));
80-
}
81-
82-
static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
83-
struct page *page)
84-
{
85-
return __v9fs_fscache_wait_on_page_write(inode, page);
86-
}
87-
8831
#else /* CONFIG_9P_FSCACHE */
8932

9033
static inline void v9fs_cache_inode_get_cookie(struct inode *inode)
@@ -99,39 +42,5 @@ static inline void v9fs_cache_inode_set_cookie(struct inode *inode, struct file
9942
{
10043
}
10144

102-
static inline int v9fs_fscache_release_page(struct page *page,
103-
gfp_t gfp) {
104-
return 1;
105-
}
106-
107-
static inline void v9fs_fscache_invalidate_page(struct page *page) {}
108-
109-
static inline int v9fs_readpage_from_fscache(struct inode *inode,
110-
struct page *page)
111-
{
112-
return -ENOBUFS;
113-
}
114-
115-
static inline int v9fs_readpages_from_fscache(struct inode *inode,
116-
struct address_space *mapping,
117-
struct list_head *pages,
118-
unsigned *nr_pages)
119-
{
120-
return -ENOBUFS;
121-
}
122-
123-
static inline void v9fs_readpage_to_fscache(struct inode *inode,
124-
struct page *page)
125-
{}
126-
127-
static inline void v9fs_uncache_page(struct inode *inode, struct page *page)
128-
{}
129-
130-
static inline void v9fs_fscache_wait_on_page_write(struct inode *inode,
131-
struct page *page)
132-
{
133-
return;
134-
}
135-
13645
#endif /* CONFIG_9P_FSCACHE */
13746
#endif /* _9P_CACHE_H */

fs/9p/v9fs.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ static inline struct v9fs_inode *V9FS_I(const struct inode *inode)
124124
return container_of(inode, struct v9fs_inode, vfs_inode);
125125
}
126126

127+
static inline struct fscache_cookie *v9fs_inode_cookie(struct v9fs_inode *v9inode)
128+
{
129+
#ifdef CONFIG_9P_FSCACHE
130+
return v9inode->fscache;
131+
#else
132+
return NULL;
133+
#endif
134+
}
135+
127136
extern int v9fs_show_options(struct seq_file *m, struct dentry *root);
128137

129138
struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *,

0 commit comments

Comments
 (0)