From: NeilBrown Date: Tue, 6 Mar 2007 16:40:29 +1100 Avoid flush-when-locking when interclient consistency not needed. If nolock and nocto mount options are set, then the implication is that cache consistency with other clients is not desired. This is likely to be the case when the filesystem is only access by the one client - as a nfs-mounted root might be. In that case, there is no benefit in flushing writes and invalidating caches around lock/unlock requests. This patch makes those flushes and invalidates conditional on either nolock or nocto being clear. Signed-off-by: Neil Brown Signed-off-by: Trond Myklebust --- fs/nfs/file.c | 46 +++++++++++++++++++++++++++------------------- 1 files changed, 27 insertions(+), 19 deletions(-) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 8e66b5a..c7b36d2 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -445,11 +445,14 @@ static int do_unlk(struct file *filp, int cmd, struct file_lock *fl) struct inode *inode = filp->f_mapping->host; int status; - /* - * Flush all pending writes before doing anything - * with locks.. - */ - nfs_sync_mapping(filp->f_mapping); + if (!((NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM) && + (NFS_SERVER(inode)->flags & NFS_MOUNT_NOCTO))) { + /* + * Flush all pending writes before doing anything + * with locks.. + */ + nfs_sync_mapping(filp->f_mapping); + } /* NOTE: special case * If we're signalled while cleaning up locks on process exit, we @@ -470,14 +473,16 @@ static int do_setlk(struct file *filp, int cmd, struct file_lock *fl) struct inode *inode = filp->f_mapping->host; int status; - /* - * Flush all pending writes before doing anything - * with locks.. - */ - status = nfs_sync_mapping(filp->f_mapping); - if (status != 0) - goto out; - + if (!((NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM) && + (NFS_SERVER(inode)->flags & NFS_MOUNT_NOCTO))) { + /* + * Flush all pending writes before doing anything + * with locks.. + */ + status = nfs_sync_mapping(filp->f_mapping); + if (status != 0) + goto out; + } lock_kernel(); /* Use local locking if mounted with "-onolock" */ if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)) { @@ -495,12 +500,15 @@ static int do_setlk(struct file *filp, int cmd, struct file_lock *fl) unlock_kernel(); if (status < 0) goto out; - /* - * Make sure we clear the cache whenever we try to get the lock. - * This makes locking act as a cache coherency point. - */ - nfs_sync_mapping(filp->f_mapping); - nfs_zap_caches(inode); + if (!((NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM) && + (NFS_SERVER(inode)->flags & NFS_MOUNT_NOCTO))) { + /* + * Make sure we clear the cache whenever we try to get the lock. + * This makes locking act as a cache coherency point. + */ + nfs_sync_mapping(filp->f_mapping); + nfs_zap_caches(inode); + } out: return status; }