NFS: flush data when locking a file to ensure cache coherence for mmap.
Subsystems (2)
PATCH 1/1 NFS: flush data when locking a file to ensure cache coherence for mmap.
When a byte range lock (or flock) is taken out on an NFS file, the validity of the cached data is checked and the inode is marked NFS_INODE_INVALID_DATA. However the cached data isn't flushed from the page cache.
This is sufficient for future read() requests or mmap() requests as they call nfs_revalidate_mapping() which performs the flush if necessary.
However an existing mapping is not affected. Accessing data through that mapping will continue to return old data even though the inode is marked NFS_INODE_INVALID_DATA.
This can easily be confirmed using the 'nfs' tool in
git://github.com/okirch/twopence-nfs.git
and running
nfs coherence FILENAME
on one client, and
nfs coherence -r FILENAME
on another client.
It appears that prior to Linux 2.6.0 this worked correctly.
However commit:
removed the call to inode_invalidate_pages() from nfs_zap_caches(). I haven't tested this code, but inspection suggests that prior to this commit, file locking would invalidate all inode pages.
This patch adds a call to nfs_revalidate_mapping_protected() after a successful SETLK so that invalid data is flushed. With this patch the above test passes.
--- fs/nfs/file.c | 1 + 1 file changed, 1 insertion(+)
fs/nfs/file.c +1 -0
@@ -822,6 +822,7 @@ do_setlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)__nfs_revalidate_inode (NFS_SERVER (inode), inode); elsenfs_zap_caches (inode ); +nfs_revalidate_mapping_protected (inode, filp->f_mapping); } out:return status;
Signature · 1 line
2.8.3
PING .... any comments on this patch, or the problem it tries to address?
Thanks,
NeilBrown
Quoted 56 lines · NeilBrown
When a byte range lock (or flock) is taken out on an NFS file, the validity of the cached data is checked and the inode is marked
NFS_INODE_INVALID_DATA. However the cached data isn't flushed from the page cache.This is sufficient for future
read()requests ormmap()requests as they callnfs_revalidate_mapping()which performs the flush if necessary.However an existing mapping is not affected. Accessing data through that mapping will continue to return old data even though the inode is marked
NFS_INODE_INVALID_DATA.This can easily be confirmed using the 'nfs' tool in
git://github.com/okirch/twopence-nfs.git
and runningnfs coherence FILENAME
on one client, and
nfs coherence -r FILENAME
on another client.It appears that prior to Linux 2.6.0 this worked correctly.
However commit:
removed the call to
inode_invalidate_pages()fromnfs_zap_caches(). I haven't tested this code, but inspection suggests that prior to this commit, file locking would invalidate all inode pages.This patch adds a call to
nfs_revalidate_mapping_protected()after a successful SETLK so that invalid data is flushed. With this patch the above test passes.Cc Olaf Kirch <[email protected]>Signed-off-by NeilBrown <[email protected]>--- fs/nfs/file.c | 1 + 1 file changed, 1 insertion(+)fs/nfs/file.c +1
-0@@ -822,6 +822,7 @@ do_setlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)__nfs_revalidate_inode (NFS_SERVER (inode), inode); elsenfs_zap_caches (inode ); +nfs_revalidate_mapping_protected (inode, filp->f_mapping); } out:return status;Signature · 1 line
2.8.3
PING again
Thanks,
NeilBrown
Quoted 65 lines · NeilBrown
PING .... any comments on this patch, or the problem it tries to address?
Thanks,
NeilBrownQuoted 56 lines · NeilBrown
When a byte range lock (or flock) is taken out on an NFS file, the validity of the cached data is checked and the inode is marked
NFS_INODE_INVALID_DATA. However the cached data isn't flushed from the page cache.This is sufficient for future
read()requests ormmap()requests as they callnfs_revalidate_mapping()which performs the flush if necessary.However an existing mapping is not affected. Accessing data through that mapping will continue to return old data even though the inode is marked
NFS_INODE_INVALID_DATA.This can easily be confirmed using the 'nfs' tool in
git://github.com/okirch/twopence-nfs.git
and runningnfs coherence FILENAME
on one client, and
nfs coherence -r FILENAME
on another client.It appears that prior to Linux 2.6.0 this worked correctly.
However commit:
removed the call to
inode_invalidate_pages()fromnfs_zap_caches(). I haven't tested this code, but inspection suggests that prior to this commit, file locking would invalidate all inode pages.This patch adds a call to
nfs_revalidate_mapping_protected()after a successful SETLK so that invalid data is flushed. With this patch the above test passes.Cc Olaf Kirch <[email protected]>Signed-off-by NeilBrown <[email protected]>--- fs/nfs/file.c | 1 + 1 file changed, 1 insertion(+)fs/nfs/file.c +1
-0@@ -822,6 +822,7 @@ do_setlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)__nfs_revalidate_inode (NFS_SERVER (inode), inode); elsenfs_zap_caches (inode ); +nfs_revalidate_mapping_protected (inode, filp->f_mapping); } out:return status;Signature · 1 line
2.8.3