alistair23-linux/fs
Neil Brown 83672d392f NFS: Fix directory caching problem - with test case and patch.
Try running this script in an NFS mounted directory (Client relatively
recent - 2.6.18 has the problem as does 2.6.20).

------------------------------------------------------
#!/bin/bash
#
# This script will produce the following errormessage from tar:
#
#   tar: newdir/innerdir/innerfile: file changed as we read it

# create dirs
rm -rf nfstest
mkdir -p nfstest/dir/innerdir

# create files (should not be empty)
echo "Hello World!" >nfstest/dir/file
echo "Hello World!" >nfstest/dir/innerdir/innerfile

# problem only happens if we sleep before chmod
sleep 1

# change file modes
chmod -R a+r nfstest

# rename dir
mv nfstest/dir nfstest/newdir

# tar it
tar -cf nfstest/nfstest.tar -C nfstest newdir

# restore old dir name
mv nfstest/newdir nfstest/dir
--------------------------------------------------------

What happens:

The 'chmod -R' does a readdir_plus in each directory and the results
get cached in the page cache.  It then updates the ctime on each file
by one second.  When this happens, the post-op attributes are used to
update the ctime stored on the client to match the value in the kernel.

The 'mv' calls shrink_dcache_parent on the directory tree which
flushes all the dentries (so a new lookup will be required) but
doesn't flush the inodes or pagecache.

The 'tar' does a readdir on each directory, but (in the case of
'innerdir' at least) satisfies it from the pagecache and uses the
READDIRPLUS data to update all the inodes.  In the case of
'innerdir/innerfile', the ctime is out of date.

'tar' then calls 'lstat' on innerdir/innerfile getting an old ctime.
It then opens the file (triggering a GETATTR), reads the content, and
then calls fstat to see if anything has changed.  It finds that ctime
has changed and so complains.

The problem seems to be that the cache readdirplus info is kept around
for too long.

My patch below discards pagecache data for directories when
dentry_iput is called on them.  This effectively removes the symptom
which convinces me that I correctly understand the problem.  However
I'm not convinced that is a proper solution, as there could easily be
other races that trigger the same problem without being affected by
this 'fix'.

One possibility would be to require that readdirplus pagecache data be
only used *once* to instantiate an inode.  Somehow it should then be
invalidated so that if the dentry subsequently disappears, it will
cause a new request to the server to fill in the stat data.

Another possibility is to compare the cache_change_attribute on the
inode with something similar for the readdirplus info and reject the
info from readdirplus if it is too old.

I haven't tried to implement these and would value other opinions
before I do.

Thanks,
NeilBrown


Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
2007-04-30 22:17:19 -07:00
..
9p v9fs: don't use primary fid when removing file 2007-04-24 08:23:08 -07:00
adfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
affs [PATCH] affs: implement ->drop_inode 2007-02-20 17:10:15 -08:00
afs [AF_RXRPC/AFS]: Arch-specific fixes. 2007-04-27 15:28:45 -07:00
autofs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
autofs4 [PATCH] autofs4: fix race in unhashed dentry code 2007-04-12 15:31:42 -07:00
befs [PATCH] mark struct inode_operations const 1 2007-02-12 09:48:46 -08:00
bfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
cifs Merge git://git.kernel.org/pub/scm/linux/kernel/git/sfrench/cifs-2.6 2007-03-22 19:47:09 -07:00
coda [PATCH] sysctl: remove insert_at_head from register_sysctl 2007-02-14 08:09:59 -08:00
configfs configfs: add missing mutex_unlock() 2007-03-14 14:37:21 -07:00
cramfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
debugfs debugfs: Add debugfs_create_u64() 2007-04-27 10:57:31 -07:00
devpts [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
dlm [DLM] fs/dlm/user.c should #include "user.h" 2007-03-07 13:58:21 -05:00
ecryptfs [NETLINK]: Switch cb_lock spinlock to mutex and allow to override it 2007-04-25 22:29:03 -07:00
efs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
exportfs [PATCH] VFS: Make filldir_t and struct kstat deal in 64-bit inode numbers 2006-10-03 08:03:40 -07:00
ext2 [PATCH] ext[234]: update documentation 2007-02-20 17:10:14 -08:00
ext3 [PATCH] revert "retries in ext3_prepare_write() violate ordering requirements" 2007-04-02 10:06:08 -07:00
ext4 [PATCH] revert "retries in ext4_prepare_write() violate ordering requirements" 2007-04-02 10:06:08 -07:00
fat [PATCH] FAT: DIO-write fallback to normal buffered 2007-02-20 17:10:14 -08:00
freevxfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
fuse [PATCH] fuse: validate rootmode mount option 2007-04-08 19:47:55 -07:00
gfs2 [GFS2] Fix bz 229873, alternate test: assertion "!ip->i_inode.i_mapping->nrpages" failed 2007-03-07 14:03:53 -05:00
hfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
hfsplus [PATCH] remove many unneeded #includes of sched.h 2007-02-14 08:09:54 -08:00
hostfs [PATCH] uml: hostfs variable renaming 2007-03-29 08:22:25 -07:00
hpfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
hppfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
hugetlbfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
isofs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
jbd [PATCH] jbd: wait for already submitted t_sync_datalist buffer to complete 2006-12-22 08:55:51 -08:00
jbd2 [PATCH] jbd2: wait for already submitted t_sync_datalist buffer to complete 2006-12-07 08:39:42 -08:00
jffs2 Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 2007-04-27 19:16:19 +01:00
jfs Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/shaggy/jfs-2.6 2007-02-26 11:44:51 -08:00
lockd SUNRPC: RPC buffer size estimates are too large 2007-04-30 22:17:10 -07:00
minix [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
msdos [PATCH] mark struct inode_operations const 2 2007-02-12 09:48:46 -08:00
ncpfs ncpfs: make sure server connection survives a kill 2007-03-06 13:26:27 +01:00
nfs NFS: Fix directory caching problem - with test case and patch. 2007-04-30 22:17:19 -07:00
nfs_common [PATCH] nfs_common endianness annotations 2006-10-20 10:26:41 -07:00
nfsd SUNRPC: RPC buffer size estimates are too large 2007-04-30 22:17:10 -07:00
nls [PATCH] fs: make nls_cp936.c handle some U00XY characters and U20AC correctly 2006-12-07 08:39:46 -08:00
ntfs [PATCH] sysctl: remove the proc_dir_entry member for the sysctl tables 2007-02-14 08:10:00 -08:00
ocfs2 ocfs2: Cache extent records 2007-04-26 15:10:40 -07:00
openpromfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
partitions [PATCH] change misleading EFI partition support description 2007-03-16 19:25:06 -07:00
proc [POWERPC] Make struct property's value a void * 2007-04-13 03:55:18 +10:00
qnx4 [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
ramfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
reiserfs reiserfs: suppress lockdep warning 2007-04-30 16:40:40 -07:00
romfs [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
smbfs [PATCH] smbfs: double free memory corruption 2007-03-16 19:25:05 -07:00
sysfs security: prevent permission checking of file removal via sysfs_remove_group() 2007-04-27 10:57:33 -07:00
sysv [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
udf [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
ufs ufs proper handling of zero link case 2007-04-17 16:36:27 -07:00
vfat [PATCH] mark struct inode_operations const 3 2007-02-12 09:48:46 -08:00
xfs [PATCH] Make XFS workqueues nonfreezable 2007-03-22 19:39:06 -07:00
aio.c [PATCH] aio: remove bare user-triggerable error printk 2007-03-27 17:53:25 -07:00
attr.c
bad_inode.c [PATCH] mark struct inode_operations const 1 2007-02-12 09:48:46 -08:00
binfmt_aout.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
binfmt_elf.c [PATCH] fix page leak during core dump 2007-04-02 10:06:08 -07:00
binfmt_elf_fdpic.c [PATCH] fix page leak during core dump 2007-04-02 10:06:08 -07:00
binfmt_em86.c
binfmt_flat.c [PATCH] uclinux: correctly remap bin_fmtflat exe allocated mem regions 2007-02-09 10:45:33 -08:00
binfmt_misc.c [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
binfmt_script.c
binfmt_som.c [PARISC] Fix fs/binfmt_som.c 2006-10-04 06:51:26 -06:00
bio.c [BLOCK] Don't pin lots of memory in mempools 2007-04-30 09:08:17 +02:00
block_dev.c [PATCH] lockdep: annotate BLKPG_DEL_PARTITION 2007-02-20 17:10:16 -08:00
buffer.c [PATCH] fs: nobh_truncate_page() fix 2007-03-06 09:30:25 -08:00
char_dev.c [PATCH] remove protection of LANANA-reserved majors 2007-04-04 21:12:47 -07:00
compat.c [PATCH] Add epoll compat_ code to fs/compat.c 2007-03-08 07:38:22 -08:00
compat_ioctl.c [NET]: Introduce SIOCGSTAMPNS ioctl to get timestamps with nanosec resolution 2007-04-25 22:24:04 -07:00
dcache.c Revert "[PATCH] Fix d_path for lazy unmounts" 2007-02-13 12:08:18 -08:00
dcookies.c [PATCH] slab: remove kmem_cache_t 2006-12-07 08:39:25 -08:00
direct-io.c [PATCH] dio: lock refcount operations 2006-12-10 09:57:21 -08:00
dnotify.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
dquot.c [PATCH] sysctl: remove insert_at_head from register_sysctl 2007-02-14 08:09:59 -08:00
drop_caches.c [PATCH] remove invalidate_inode_pages() 2007-02-11 10:51:31 -08:00
eventpoll.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
exec.c exec.c: fix coredump to pipe problem and obscure "security hole" 2007-04-17 16:36:26 -07:00
fcntl.c [PATCH] fdtable: Make fdarray and fdsets equal in size 2006-12-10 09:57:22 -08:00
fifo.c
file.c [PATCH] fdtable: Provide free_fdtable() wrapper 2006-12-22 08:55:50 -08:00
file_table.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
filesystems.c [PATCH] remove many unneeded #includes of sched.h 2007-02-14 08:09:54 -08:00
fs-writeback.c Write back inode data pages even when the inode itself is locked 2007-01-26 12:53:20 -08:00
generic_acl.c [PATCH] Generic infrastructure for acls 2006-09-29 09:18:24 -07:00
inode.c [PATCH] Mark struct super_operations const 2007-02-12 09:48:47 -08:00
inotify.c [PATCH] severing fs.h, radix-tree.h -> sched.h 2006-12-04 02:00:24 -05:00
inotify_user.c [PATCH] inotify: read return val fix 2007-02-12 09:48:28 -08:00
internal.h [PATCH] CONFIG_BLOCK internal.h cleanups 2006-09-30 20:52:32 +02:00
ioctl.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
ioprio.c [PATCH] pid: replace do/while_each_task_pid with do/while_each_pid_task 2007-02-12 09:48:32 -08:00
Kconfig SUNRPC: RPC client should retry with different versions of rpcbind 2007-04-30 22:17:16 -07:00
Kconfig.binfmt
libfs.c [PATCH] shmem and simple const super_operations 2007-03-05 07:57:51 -08:00
locks.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
Makefile Remove JFFS (version 1), as scheduled. 2007-02-17 16:10:59 -05:00
mbcache.c [PATCH] slab: remove kmem_cache_t 2006-12-07 08:39:25 -08:00
mpage.c [PATCH] BLOCK: Dissociate generic_writepages() from mpage stuff [try #6] 2006-09-30 20:52:26 +02:00
namei.c security: prevent permission checking of file removal via sysfs_remove_group() 2007-04-27 10:57:33 -07:00
namespace.c [PATCH] Transform kmem_cache_alloc()+memset(0) -> kmem_cache_zalloc(). 2007-02-11 10:51:27 -08:00
nfsctl.c Remove obsolete #include <linux/config.h> 2006-06-30 19:25:36 +02:00
no-block.c [PATCH] BLOCK: Make it possible to disable the block layer [try #6] 2006-09-30 20:52:31 +02:00
open.c [PATCH] fdtable: Make fdarray and fdsets equal in size 2006-12-10 09:57:22 -08:00
pipe.c [PATCH] AUDIT_FD_PAIR 2007-02-17 21:30:15 -05:00
pnode.c [PATCH] rename struct namespace to struct mnt_namespace 2006-12-08 08:28:51 -08:00
pnode.h [PATCH] rename struct namespace to struct mnt_namespace 2006-12-08 08:28:51 -08:00
posix_acl.c [PATCH] kmemdup: some users 2006-10-01 00:39:19 -07:00
quota.c [PATCH] BLOCK: Make it possible to disable the block layer [try #6] 2006-09-30 20:52:31 +02:00
quota_v1.c
quota_v2.c
read_write.c [PATCH] FS: speed up rw_verify_area() 2007-02-12 09:48:29 -08:00
read_write.h [PATCH] Remove readv/writev methods and use aio_read/aio_write instead 2006-10-01 00:39:28 -07:00
readdir.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
select.c [PATCH] fdtable: Make fdarray and fdsets equal in size 2006-12-10 09:57:22 -08:00
seq_file.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
splice.c [PATCH] splice: partial write fix 2007-03-29 14:26:42 +02:00
stack.c [PATCH] fs/stack.c: Copy i_nlink after all other attributes are copied 2007-02-19 14:21:50 -08:00
stat.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
super.c the overdue removal of the mount/umount uevents 2007-04-27 10:57:31 -07:00
sync.c [PATCH] Turn do_sync_file_range() into do_sync_mapping_range() 2007-04-26 15:02:26 -07:00
utimes.c [PATCH] severing fs.h, radix-tree.h -> sched.h 2006-12-04 02:00:24 -05:00
xattr.c [PATCH] VFS: change struct file to use struct path 2006-12-08 08:28:41 -08:00
xattr_acl.c [PATCH] remove many unneeded #includes of sched.h 2007-02-14 08:09:54 -08:00