Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757408Ab0HKXDG (ORCPT ); Wed, 11 Aug 2010 19:03:06 -0400 Received: from mail-px0-f174.google.com ([209.85.212.174]:55230 "EHLO mail-px0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757165Ab0HKXDC (ORCPT ); Wed, 11 Aug 2010 19:03:02 -0400 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:cc:date:message-id:mime-version:content-type; b=DGhNF/f0pVG3t4KmGt1sopDLNndnRsjZ3gtXDgWsEGg/K5cb6c4d+99bRQnh8x4CM3 omKiGRgLd/eHxPMIDHgYTKzqlbbtOnG+GKFeNf/Kweslh/bLYeY9u3HJtTnj+Qdpi2E2 3U/fCF3I2WxHusBX7NjjoapXPNBdZH44mX+Qk= From: "Patrick J. LoPresti" To: linux-nfs@vger.kernel.org Subject: [PATCH] nfs: lookupcache coherence bugs in WCC update path CC: linux-kernel@vger.kernel.org Date: Wed, 11 Aug 2010 16:02:53 -0700 Message-ID: <87lj8ckb1e.fsf@patl.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2803 Lines: 64 This patch fixes some coherence bugs in the NFS "dentry lookup cache". The NFS dentry lookup cache provides the nfs_force_lookup_revalidate() call to invalidate all cached dentries associated with an inode. In general, the NFS client uses the ctime and mtime in the inode to detect when changes are made on the server. Therefore, to maintain cache coherence, nfs_force_lookup_revalidate() must be called whenever the ctime or mtime of a directory inode is updated with fresh data from the server. There are a few spots in nfs_wcc_update_inode() where this rule is violated, making it possible for the lookup cache to return arbitrarily stale data. This actually bit me in practice. I have an application where a negative dentry results in -ENOENT for a file that was created 30+ minutes earlier (despite the "noac" mount option). Unfortunately I cannot share my test case, but I believe the following simple patch is "obviously correct", and I can confirm that it fixes my issue. CC: stable Signed-off-by: Patrick LoPresti --- --- linux-2.6.35/fs/nfs/inode.c.orig 2010-08-01 15:11:14.000000000 -0700 +++ linux-2.6.35/fs/nfs/inode.c 2010-08-11 14:19:56.000000000 -0700 @@ -819,21 +819,28 @@ static void nfs_wcc_update_inode(struct && (fattr->valid & NFS_ATTR_FATTR_CHANGE) && nfsi->change_attr == fattr->pre_change_attr) { nfsi->change_attr = fattr->change_attr; - if (S_ISDIR(inode->i_mode)) + if (S_ISDIR(inode->i_mode)) { nfsi->cache_validity |= NFS_INO_INVALID_DATA; + nfs_force_lookup_revalidate(inode); + } } /* If we have atomic WCC data, we may update some attributes */ if ((fattr->valid & NFS_ATTR_FATTR_PRECTIME) && (fattr->valid & NFS_ATTR_FATTR_CTIME) - && timespec_equal(&inode->i_ctime, &fattr->pre_ctime)) - memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime)); + && timespec_equal(&inode->i_ctime, + &fattr->pre_ctime)) { + if (S_ISDIR(inode->i_mode)) + nfs_force_lookup_revalidate(inode); + memcpy(&inode->i_ctime, &fattr->ctime, sizeof(inode->i_ctime)); + } if ((fattr->valid & NFS_ATTR_FATTR_PREMTIME) && (fattr->valid & NFS_ATTR_FATTR_MTIME) && timespec_equal(&inode->i_mtime, &fattr->pre_mtime)) { memcpy(&inode->i_mtime, &fattr->mtime, sizeof(inode->i_mtime)); - if (S_ISDIR(inode->i_mode)) + if (S_ISDIR(inode->i_mode)) { nfsi->cache_validity |= NFS_INO_INVALID_DATA; + nfs_force_lookup_revalidate(inode); } if ((fattr->valid & NFS_ATTR_FATTR_PRESIZE) && (fattr->valid & NFS_ATTR_FATTR_SIZE) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/