From: Steve French Subject: CIFS caching problem Date: 25 Nov 2003 17:05:02 -0600 Sender: linux-fsdevel-owner@vger.kernel.org Message-ID: <1069801502.1343.26.camel@stevef95.austin.ibm.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit Cc: linux-fsdevel@vger.kernel.org Return-path: Received: from e5.ny.us.ibm.com ([32.97.182.105]:4591 "EHLO e5.ny.us.ibm.com") by vger.kernel.org with ESMTP id S263822AbTKYXIn (ORCPT ); Tue, 25 Nov 2003 18:08:43 -0500 To: maciej@apathy.killer-robot.net List-Id: linux-fsdevel.vger.kernel.org > CIFS doesn't seem to ever invalidate cached pages associated with its > inodes. The result is that when a file is modified server-side It looks like you are right, I am missing a call to invalidate pages. The CIFS mechanism should be somewhat different than NFSv3 or smbfs which don't really support safe distributed caching and rely on timers (the cifs vfs case probably would be somewhat similar to NFSv4 client case if it were finished). When a file is opened via SMB/CIFS an oplock (distributed caching token) is potentially granted (if the server supports it which Samba on most versions of Linux does and also Windows and other CIFS filers usually support). If oplock is not granted no readahead or writebehind should be done on the client (although I should probably add a configuration option for those who want to do caching based on a timer anyway - even at the risk of writes from multiple clients being written out of order on the server such as the case with nfs v3 or smbfs). I don't know whether invalidating cached pages in practice always is possible in Linux (at least for the mmap case) without change to the kernel mm directory or implementing the vmops as XFS does. I keep in the cifs inode flags ClientCanCacheRead and ClientCanCacheAll whether the open of the file granted readahead (level 2 oplock) or readahead & writebehind (total file oplock) permission for distributed caching. If an "oplock_break" is received (see cifs_oplock_thread) then I flush the writebehind data and then depending on whether writebehind permission or all caching permission (readahead & writebehind) in "is_valid_oplock_break" in misc.c I change the cifs inode caching flags and queue a request to the oplock thread to flush the inode (so I don't block the socket reads - holding up other incoming server responses for unrelated files). Although the read_wrapper routine (cifs_read_wrapper in cifsfs.c) should work for reading new pages that have not been read yet, presumably the kernel on the client will continue to use stale ones unless they are pushed out of cache or I explicitly invalidate them. What I didn't do was to call invalidate_cache_pages when total file oplock (writebehind AND readahead permission) is revoked for this file by the server, although I do the reverse and flush writebehind data when the server revokes the oplock.