From patchwork Fri Jun 3 03:26:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: NeilBrown X-Patchwork-Id: 9151573 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EE3FE6074E for ; Fri, 3 Jun 2016 03:26:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D474F28309 for ; Fri, 3 Jun 2016 03:26:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7B382832D; Fri, 3 Jun 2016 03:26:22 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_TVD_MIME_EPI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38C2428309 for ; Fri, 3 Jun 2016 03:26:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750997AbcFCD0U (ORCPT ); Thu, 2 Jun 2016 23:26:20 -0400 Received: from mx2.suse.de ([195.135.220.15]:32810 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750910AbcFCD0T (ORCPT ); Thu, 2 Jun 2016 23:26:19 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id A9B14AAB7; Fri, 3 Jun 2016 03:26:17 +0000 (UTC) From: NeilBrown To: Trond Myklebust Date: Fri, 03 Jun 2016 13:26:10 +1000 Cc: Olaf Kirch , NFS List Subject: [PATCH] NFS: flush data when locking a file to ensure cache coherence for mmap. User-Agent: Notmuch/0.20.2 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-suse-linux-gnu) Message-ID: <871t4fosvh.fsf@notabene.neil.brown.name> MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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: http://git.kernel.org/cgit/linux/kernel/git/history/history.git/commit/?id=ca9268fe3ddd075714005adecd4afbd7f9ab87d0 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. Cc: Olaf Kirch Signed-off-by: NeilBrown --- fs/nfs/file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 717a8d6af52d..781cc6c9c60b 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c @@ -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); else nfs_zap_caches(inode); + nfs_revalidate_mapping_protected(inode, filp->f_mapping); } out: return status;