Skip to content

Commit 88a4d7b

Browse files
DaveWysochanskiRHamschuma-ntap
authored andcommitted
NFS: Configure support for netfs when NFS fscache is configured
As first steps for support of the netfs library when NFS_FSCACHE is configured, add NETFS_SUPPORT to Kconfig and add the required netfs_inode into struct nfs_inode. Using netfs requires we move the VFS inode structure to be stored inside struct netfs_inode, along with the fscache_cookie. Thus, if NFS_FSCACHE is configured, place netfs_inode inside an anonymous union so the vfs_inode memory is the same and we do not need to modify other non-fscache areas of NFS. In addition, inside the NFS fscache code, use the new helpers, netfs_inode() and netfs_i_cookie() helpers, and remove our own helper, nfs_i_fscache(). Later patches will convert NFS fscache to fully use netfs. Signed-off-by: Dave Wysochanski <[email protected]> Tested-by: Daire Byrne <[email protected]> Signed-off-by: Anna Schumaker <[email protected]>
1 parent 01c3a40 commit 88a4d7b

File tree

4 files changed

+26
-34
lines changed

4 files changed

+26
-34
lines changed

fs/nfs/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ config ROOT_NFS
170170
config NFS_FSCACHE
171171
bool "Provide NFS client caching support"
172172
depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y
173+
select NETFS_SUPPORT
173174
help
174175
Say Y here if you want NFS data to be cached locally on disc through
175176
the general filesystem cache manager

fs/nfs/fscache.c

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,14 @@ void nfs_fscache_init_inode(struct inode *inode)
163163
struct nfs_server *nfss = NFS_SERVER(inode);
164164
struct nfs_inode *nfsi = NFS_I(inode);
165165

166-
nfsi->fscache = NULL;
166+
netfs_inode(inode)->cache = NULL;
167167
if (!(nfss->fscache && S_ISREG(inode->i_mode)))
168168
return;
169169

170170
nfs_fscache_update_auxdata(&auxdata, inode);
171171

172-
nfsi->fscache = fscache_acquire_cookie(NFS_SB(inode->i_sb)->fscache,
172+
netfs_inode(inode)->cache = fscache_acquire_cookie(
173+
nfss->fscache,
173174
0,
174175
nfsi->fh.data, /* index_key */
175176
nfsi->fh.size,
@@ -183,11 +184,8 @@ void nfs_fscache_init_inode(struct inode *inode)
183184
*/
184185
void nfs_fscache_clear_inode(struct inode *inode)
185186
{
186-
struct nfs_inode *nfsi = NFS_I(inode);
187-
struct fscache_cookie *cookie = nfs_i_fscache(inode);
188-
189-
fscache_relinquish_cookie(cookie, false);
190-
nfsi->fscache = NULL;
187+
fscache_relinquish_cookie(netfs_i_cookie(netfs_inode(inode)), false);
188+
netfs_inode(inode)->cache = NULL;
191189
}
192190

193191
/*
@@ -212,7 +210,7 @@ void nfs_fscache_clear_inode(struct inode *inode)
212210
void nfs_fscache_open_file(struct inode *inode, struct file *filp)
213211
{
214212
struct nfs_fscache_inode_auxdata auxdata;
215-
struct fscache_cookie *cookie = nfs_i_fscache(inode);
213+
struct fscache_cookie *cookie = netfs_i_cookie(netfs_inode(inode));
216214
bool open_for_write = inode_is_open_for_write(inode);
217215

218216
if (!fscache_cookie_valid(cookie))
@@ -230,7 +228,7 @@ EXPORT_SYMBOL_GPL(nfs_fscache_open_file);
230228
void nfs_fscache_release_file(struct inode *inode, struct file *filp)
231229
{
232230
struct nfs_fscache_inode_auxdata auxdata;
233-
struct fscache_cookie *cookie = nfs_i_fscache(inode);
231+
struct fscache_cookie *cookie = netfs_i_cookie(netfs_inode(inode));
234232
loff_t i_size = i_size_read(inode);
235233

236234
nfs_fscache_update_auxdata(&auxdata, inode);
@@ -243,7 +241,7 @@ void nfs_fscache_release_file(struct inode *inode, struct file *filp)
243241
static int fscache_fallback_read_page(struct inode *inode, struct page *page)
244242
{
245243
struct netfs_cache_resources cres;
246-
struct fscache_cookie *cookie = nfs_i_fscache(inode);
244+
struct fscache_cookie *cookie = netfs_i_cookie(&NFS_I(inode)->netfs);
247245
struct iov_iter iter;
248246
struct bio_vec bvec;
249247
int ret;
@@ -269,7 +267,7 @@ static int fscache_fallback_write_page(struct inode *inode, struct page *page,
269267
bool no_space_allocated_yet)
270268
{
271269
struct netfs_cache_resources cres;
272-
struct fscache_cookie *cookie = nfs_i_fscache(inode);
270+
struct fscache_cookie *cookie = netfs_i_cookie(&NFS_I(inode)->netfs);
273271
struct iov_iter iter;
274272
struct bio_vec bvec;
275273
loff_t start = page_offset(page);

fs/nfs/fscache.h

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static inline bool nfs_fscache_release_folio(struct folio *folio, gfp_t gfp)
5454
if (current_is_kswapd() || !(gfp & __GFP_FS))
5555
return false;
5656
folio_wait_fscache(folio);
57-
fscache_note_page_release(nfs_i_fscache(folio->mapping->host));
57+
fscache_note_page_release(netfs_i_cookie(&NFS_I(folio->mapping->host)->netfs));
5858
nfs_inc_fscache_stats(folio->mapping->host,
5959
NFSIOS_FSCACHE_PAGES_UNCACHED);
6060
}
@@ -66,7 +66,7 @@ static inline bool nfs_fscache_release_folio(struct folio *folio, gfp_t gfp)
6666
*/
6767
static inline int nfs_fscache_read_page(struct inode *inode, struct page *page)
6868
{
69-
if (nfs_i_fscache(inode))
69+
if (netfs_inode(inode)->cache)
7070
return __nfs_fscache_read_page(inode, page);
7171
return -ENOBUFS;
7272
}
@@ -78,7 +78,7 @@ static inline int nfs_fscache_read_page(struct inode *inode, struct page *page)
7878
static inline void nfs_fscache_write_page(struct inode *inode,
7979
struct page *page)
8080
{
81-
if (nfs_i_fscache(inode))
81+
if (netfs_inode(inode)->cache)
8282
__nfs_fscache_write_page(inode, page);
8383
}
8484

@@ -101,13 +101,10 @@ static inline void nfs_fscache_update_auxdata(struct nfs_fscache_inode_auxdata *
101101
static inline void nfs_fscache_invalidate(struct inode *inode, int flags)
102102
{
103103
struct nfs_fscache_inode_auxdata auxdata;
104-
struct nfs_inode *nfsi = NFS_I(inode);
104+
struct fscache_cookie *cookie = netfs_i_cookie(&NFS_I(inode)->netfs);
105105

106-
if (nfsi->fscache) {
107-
nfs_fscache_update_auxdata(&auxdata, inode);
108-
fscache_invalidate(nfsi->fscache, &auxdata,
109-
i_size_read(inode), flags);
110-
}
106+
nfs_fscache_update_auxdata(&auxdata, inode);
107+
fscache_invalidate(cookie, &auxdata, i_size_read(inode), flags);
111108
}
112109

113110
/*

include/linux/nfs_fs.h

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
#include <linux/sunrpc/auth.h>
3232
#include <linux/sunrpc/clnt.h>
3333

34+
#ifdef CONFIG_NFS_FSCACHE
35+
#include <linux/netfs.h>
36+
#endif
37+
3438
#include <linux/nfs.h>
3539
#include <linux/nfs2.h>
3640
#include <linux/nfs3.h>
@@ -204,14 +208,15 @@ struct nfs_inode {
204208
/* how many bytes have been written/read and how many bytes queued up */
205209
__u64 write_io;
206210
__u64 read_io;
207-
#ifdef CONFIG_NFS_FSCACHE
208-
struct fscache_cookie *fscache;
209-
#endif
210-
struct inode vfs_inode;
211-
212211
#ifdef CONFIG_NFS_V4_2
213212
struct nfs4_xattr_cache *xattr_cache;
214213
#endif
214+
union {
215+
struct inode vfs_inode;
216+
#ifdef CONFIG_NFS_FSCACHE
217+
struct netfs_inode netfs; /* netfs context and VFS inode */
218+
#endif
219+
};
215220
};
216221

217222
struct nfs4_copy_state {
@@ -329,15 +334,6 @@ static inline int NFS_STALE(const struct inode *inode)
329334
return test_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
330335
}
331336

332-
static inline struct fscache_cookie *nfs_i_fscache(struct inode *inode)
333-
{
334-
#ifdef CONFIG_NFS_FSCACHE
335-
return NFS_I(inode)->fscache;
336-
#else
337-
return NULL;
338-
#endif
339-
}
340-
341337
static inline __u64 NFS_FILEID(const struct inode *inode)
342338
{
343339
return NFS_I(inode)->fileid;

0 commit comments

Comments
 (0)