Skip to content

Commit a6b5a28

Browse files
DaveWysochanskiRHdhowells
authored andcommitted
nfs: Convert to new fscache volume/cookie API
Change the nfs filesystem to support fscache's indexing rewrite and reenable caching in nfs. The following changes have been made: (1) The fscache_netfs struct is no more, and there's no need to register the filesystem as a whole. (2) The session cookie is now an fscache_volume cookie, allocated with fscache_acquire_volume(). That takes three parameters: a string representing the "volume" in the index, a string naming the cache to use (or NULL) and a u64 that conveys coherency metadata for the volume. For nfs, I've made it render the volume name string as: "nfs,<ver>,<family>,<address>,<port>,<fsidH>,<fsidL>*<,param>[,<uniq>]" (3) The fscache_cookie_def is no more and needed information is passed directly to fscache_acquire_cookie(). The cache no longer calls back into the filesystem, but rather metadata changes are indicated at other times. fscache_acquire_cookie() is passed the same keying and coherency information as before. (4) fscache_enable/disable_cookie() have been removed. Call fscache_use_cookie() and fscache_unuse_cookie() when a file is opened or closed to prevent a cache file from being culled and to keep resources to hand that are needed to do I/O. If a file is opened for writing, we invalidate it with FSCACHE_INVAL_DIO_WRITE in lieu of doing writeback to the cache, thereby making it cease caching until all currently open files are closed. This should give the same behaviour as the uptream code. Making the cache store local modifications isn't straightforward for NFS, so that's left for future patches. (5) fscache_invalidate() now needs to be given uptodate auxiliary data and a file size. It also takes a flag to indicate if this was due to a DIO write. (6) Call nfs_fscache_invalidate() with FSCACHE_INVAL_DIO_WRITE on a file to which a DIO write is made. (7) Call fscache_note_page_release() from nfs_release_page(). (8) Use a killable wait in nfs_vm_page_mkwrite() when waiting for PG_fscache to be cleared. (9) The functions to read and write data to/from the cache are stubbed out pending a conversion to use netfslib. Changes ======= ver #3: - Added missing =n fallback for nfs_fscache_release_file()[1][2]. ver #2: - Use gfpflags_allow_blocking() rather than using flag directly. - fscache_acquire_volume() now returns errors. - Remove NFS_INO_FSCACHE as it's no longer used. - Need to unuse a cookie on file-release, not inode-clear. Signed-off-by: Dave Wysochanski <[email protected]> Co-developed-by: David Howells <[email protected]> Signed-off-by: David Howells <[email protected]> Tested-by: Dave Wysochanski <[email protected]> Acked-by: Jeff Layton <[email protected]> cc: Trond Myklebust <[email protected]> cc: Anna Schumaker <[email protected]> cc: [email protected] cc: [email protected] Link: https://lore.kernel.org/r/[email protected]/ [1] Link: https://lore.kernel.org/r/[email protected]/ [2] Link: https://lore.kernel.org/r/163819668938.215744.14448852181937731615.stgit@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/163906979003.143852.2601189243864854724.stgit@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/163967182112.1823006.7791504655391213379.stgit@warthog.procyon.org.uk/ # v3 Link: https://lore.kernel.org/r/164021575950.640689.12069642327533368467.stgit@warthog.procyon.org.uk/ # v4
1 parent 93c8461 commit a6b5a28

File tree

14 files changed

+172
-603
lines changed

14 files changed

+172
-603
lines changed

fs/nfs/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ config ROOT_NFS
170170

171171
config NFS_FSCACHE
172172
bool "Provide NFS client caching support"
173-
depends on NFS_FS=m && FSCACHE_OLD_API || NFS_FS=y && FSCACHE_OLD_API=y
173+
depends on NFS_FS=m && FSCACHE || NFS_FS=y && FSCACHE=y
174174
help
175175
Say Y here if you want NFS data to be cached locally on disc through
176176
the general filesystem cache manager

fs/nfs/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ nfs-y := client.o dir.o file.o getroot.o inode.o super.o \
1212
export.o sysfs.o fs_context.o
1313
nfs-$(CONFIG_ROOT_NFS) += nfsroot.o
1414
nfs-$(CONFIG_SYSCTL) += sysctl.o
15-
nfs-$(CONFIG_NFS_FSCACHE) += fscache.o fscache-index.o
15+
nfs-$(CONFIG_NFS_FSCACHE) += fscache.o
1616

1717
obj-$(CONFIG_NFS_V2) += nfsv2.o
1818
nfsv2-y := nfs2super.o proc.o nfs2xdr.o

fs/nfs/client.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
183183
clp->cl_net = get_net(cl_init->net);
184184

185185
clp->cl_principal = "*";
186-
nfs_fscache_get_client_cookie(clp);
187-
188186
return clp;
189187

190188
error_cleanup:
@@ -238,8 +236,6 @@ static void pnfs_init_server(struct nfs_server *server)
238236
*/
239237
void nfs_free_client(struct nfs_client *clp)
240238
{
241-
nfs_fscache_release_client_cookie(clp);
242-
243239
/* -EIO all pending I/O */
244240
if (!IS_ERR(clp->cl_rpcclient))
245241
rpc_shutdown_client(clp->cl_rpcclient);

fs/nfs/direct.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
#include "internal.h"
6060
#include "iostat.h"
6161
#include "pnfs.h"
62+
#include "fscache.h"
6263

6364
#define NFSDBG_FACILITY NFSDBG_VFS
6465

@@ -959,6 +960,7 @@ ssize_t nfs_file_direct_write(struct kiocb *iocb, struct iov_iter *iter)
959960
} else {
960961
result = requested;
961962
}
963+
nfs_fscache_invalidate(inode, FSCACHE_INVAL_DIO_WRITE);
962964
out_release:
963965
nfs_direct_req_release(dreq);
964966
out:

fs/nfs/file.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ nfs_file_release(struct inode *inode, struct file *filp)
8484

8585
nfs_inc_stats(inode, NFSIOS_VFSRELEASE);
8686
nfs_file_clear_open_context(filp);
87+
nfs_fscache_release_file(inode, filp);
8788
return 0;
8889
}
8990
EXPORT_SYMBOL_GPL(nfs_file_release);
@@ -415,8 +416,7 @@ static void nfs_invalidate_page(struct page *page, unsigned int offset,
415416
return;
416417
/* Cancel any unstarted writes on this page */
417418
nfs_wb_page_cancel(page_file_mapping(page)->host, page);
418-
419-
nfs_fscache_invalidate_page(page, page->mapping->host);
419+
wait_on_page_fscache(page);
420420
}
421421

422422
/*
@@ -475,12 +475,11 @@ static void nfs_check_dirty_writeback(struct page *page,
475475
static int nfs_launder_page(struct page *page)
476476
{
477477
struct inode *inode = page_file_mapping(page)->host;
478-
struct nfs_inode *nfsi = NFS_I(inode);
479478

480479
dfprintk(PAGECACHE, "NFS: launder_page(%ld, %llu)\n",
481480
inode->i_ino, (long long)page_offset(page));
482481

483-
nfs_fscache_wait_on_page_write(nfsi, page);
482+
wait_on_page_fscache(page);
484483
return nfs_wb_page(inode, page);
485484
}
486485

@@ -555,7 +554,11 @@ static vm_fault_t nfs_vm_page_mkwrite(struct vm_fault *vmf)
555554
sb_start_pagefault(inode->i_sb);
556555

557556
/* make sure the cache has finished storing the page */
558-
nfs_fscache_wait_on_page_write(NFS_I(inode), page);
557+
if (PageFsCache(page) &&
558+
wait_on_page_fscache_killable(vmf->page) < 0) {
559+
ret = VM_FAULT_RETRY;
560+
goto out;
561+
}
559562

560563
wait_on_bit_action(&NFS_I(inode)->flags, NFS_INO_INVALIDATING,
561564
nfs_wait_bit_killable, TASK_KILLABLE);

fs/nfs/fscache-index.c

Lines changed: 0 additions & 140 deletions
This file was deleted.

0 commit comments

Comments
 (0)