NFS: Add a helper to sync both O_DIRECT and buffered writes
Subsystems (2)
PATCH 1/3 NFS: Add a helper to sync both O_DIRECT and buffered writes
Then apply it to nfs_setattr() and nfs_getattr().
Signed-off-by Trond Myklebust <[email protected]>
--- fs/nfs/inode.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
fs/nfs/inode.c +9 -6
@@ -133,6 +133,12 @@ void nfs_evict_inode(struct inode *inode)nfs_clear_inode (inode); } +static int nfs_sync_inode (struct inode *inode) +{ +nfs_inode_dio_wait (inode); +return nfs_wb_all (inode); +} +/** * nfs_sync_mapping - helper to flush all mmapped dirty data to disk */
@@ -525,10 +531,8 @@ nfs_setattr(struct dentry *dentry, struct iattr *attr)trace_nfs_setattr_enter (inode);/* Write all dirty data */ -if (S_ISREG (inode->i_mode)) { -nfs_inode_dio_wait (inode); -nfs_wb_all (inode); - } +if (S_ISREG (inode->i_mode)) +nfs_sync_inode (inode); fattr =nfs_alloc_fattr ();if (fattr ==NULL )
@@ -644,8 +648,7 @@ int nfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)trace_nfs_getattr_enter (inode);/* Flush out writes to the server in order to update c/mtime. */ if (S_ISREG (inode->i_mode)) { -nfs_inode_dio_wait (inode); - err =filemap_write_and_wait (inode->i_mapping); + err =nfs_sync_inode (inode);if (err) goto out; }
Signature · 1 line
2.1.0
PATCH 2/3 NFS: File unlock needs to be a metadata synchronisation point
File unlock needs to update both data and metadata on the NFS server in order to act as a synchronisation point for other clients.
Signed-off-by Trond Myklebust <[email protected]>
--- fs/nfs/file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/nfs/file.c +1 -1
@@ -780,7 +780,7 @@ do_unlk(struct file *filp, int cmd, struct file_lock *fl, int is_local)* Flush all pending writes before doing anything * with locks.. */ -nfs_sync_mapping (filp->f_mapping); +vfs_fsync (filp,0 ); l_ctx =nfs_get_lock_context (nfs_file_open_context (filp));if (!IS_ERR (l_ctx)) {
Signature · 1 line
2.1.0
PATCH 3/3 NFSv4: Truncating file opens should also sync O_DIRECT writes
We don't just want to sync out buffered writes, but also O_DIRECT ones.
Signed-off-by Trond Myklebust <[email protected]>
--- fs/nfs/inode.c | 3 ++- fs/nfs/nfs4file.c | 2 +- include/linux/nfs_fs.h | 1 + 3 files changed, 4 insertions(+), 2 deletions(-)
fs/nfs/inode.c +2 -1
@@ -133,11 +133,12 @@ void nfs_evict_inode(struct inode *inode)nfs_clear_inode (inode); } -static int nfs_sync_inode (struct inode *inode) +int nfs_sync_inode (struct inode *inode) {nfs_inode_dio_wait (inode);return nfs_wb_all (inode); } +EXPORT_SYMBOL_GPL (nfs_sync_inode);/** * nfs_sync_mapping - helper to flush all mmapped dirty data to disk
fs/nfs/nfs4file.c +1 -1
@@ -59,7 +59,7 @@ nfs4_file_open(struct inode *inode, struct file *filp)if (openflags &O_TRUNC ) { attr.ia_valid |=ATTR_SIZE ; attr.ia_size =0 ; -nfs_wb_all (inode); +nfs_sync_inode (inode); } inode =NFS_PROTO (dir)->open_context (dir, ctx, openflags, &attr, &opened);
include/linux/nfs_fs.h +1 -0
@@ -512,6 +512,7 @@ extern int nfs_updatepage(struct file *, struct page *, unsigned int, unsigned* Try to write back everything synchronously (but check the * return value!) */ +extern int nfs_sync_inode (struct inode *inode);extern int nfs_wb_all (struct inode *inode);extern int nfs_wb_page (struct inode *inode,struct page * page);extern int nfs_wb_page_cancel (struct inode *inode,struct page * page);
Signature · 1 line
2.1.0