On Wed, 02 Feb 2022, inoguchi.yuki@xxxxxxxxxxx wrote: > > I don't think that case adds anything interesting. When the file is > > closed, the lock is dropped. If there were any writes without a > > delegation, then the changeid isn't a reliable indication that no other > > client wrote. So the cache must be dropped. > > I've understood it. > > I've made the patch based on your idea. It invalidates the cache > after a client without write-delegation sends CLOSE call. > My Open MPI test program confirmed that this fix resolves the problem. > > The patch is as follows. What do you think? This is a bit too heavy-handed. It invalidates too often. I would make 2 changes. 1/ invalidate when opening a file, rather than when closing. This fits better with the understanding of close-to-open consistency that we flush writes when closing and verify the cache when opening 2/ I would be more careful about determining exactly when the invalidation might be needed. In nfs_post_op_updatE_inode() there is the code: if ((fattr->valid & NFS_ATTR_FATTR_CHANGE) != 0 && (fattr->valid & NFS_ATTR_FATTR_PRECHANGE) == 0) { fattr->pre_change_attr = inode_peek_iversion_raw(inode); fattr->valid |= NFS_ATTR_FATTR_PRECHANGE; } This effectively says "if we don't have the PRECHANGE number, then take the current version number, and pretend that we do have the PRECHANGE number. NFSv3 can provide a PRECHANGE number because the protocol allows pre/post attrs to be atomic. NFSv4 never sets PRECHANGE because the protocol never guarantees atomicity of pre/post attrs (For files). So it is at the point in the code where the cache on the client might become inconsistent with the data on the server. This is not a serious inconsistency and doesn't need to be resolved immediately. But I think it should be handled the next time some application opens the file. I think that when this branch of code is run, we should set a flag on the inode "NFS_ATTR_MIGHT_BE_INCONSISTENT" (or something like that). Then when we open a file, if that flag is set then we clear it and set NFS_INO_INVALID_DATA and maybe NFS_INO_REVAL_PAGECACHE (I don't recall how those two relate to each other). I assume that code doesn't end up running when you write to a file for which you have a delegation, but I'm not at all certain - we would have to check. NeilBrown