Re: smbfs: "rm -rf" dircache problems

Petr Vandrovec Ing. VTEI (VANDROVE@vc.cvut.cz)
Fri, 12 Nov 1999 11:58:16 MET-1


On 12 Nov 99 at 0:32, Urban Widmark wrote:
> > all important inode data). We set dentry's d_fsdata to position in directory
> > and as this field is revalidated only if directory is reread, it will
> > work for 'rm -rf' too (it is NOT revalidated/invalidated on unlink/rmdir).
> Does the inodes matter here, or is it just that you need it for the rest
> of what you do? smbfs could read all the info at once as well and create
> the inodes, if that is necessary. (I think there are 5 or 6 variations of
> directory scan functions ... :)
Probably not, but as we are still using good old NW3.11 call which can
retrieve only one item at a call, we get it for free without increasing
network traffic. I do not know about SMB.
> > 2) if you do 'rm -f dir' together with 'while true; do ls dir; done',
> > 'ls' can (and will) cause renumbering of directory entries.
> Does this describe how it works?
Almost.
> % ls
> (fills the cache)
> % rm some_file
> (removes the file but does not invalidate the cache)
> % ls
> (reread the cache beacuse the mtime has changed)
rm -rf: while true; do ls; done
seek(directory, 0, SEEK_SET);
[fill first X entries in dircache]
getdents(....) returned first
X entries
libc passes Y (< X) entries to user
unlink first Y items
seek(directory, 0, SEEK_SET)
[mtime differs, invalidate cache]
getdents(...) returns
new directory state
seek(directory, Y, SEEK_SET)
[and now oops, it is Y position
now, but Y+Y position in old directory]
getdents(....) returns next X items...

If invalidate does not occur, dentries still have their old numbers.
BTW in correct caching implementation there must not be need to
invalidate cache on unlink/mkdir, you must be able to notice change
from other clients too, so why do it twice.
And as we have pointers to dentries in dircache, even if 'ls' occurs
in time window, when directory change is not checked (configurable
0-20000ms), readdir (fs/ncpfs/dir.c:ncp_d_validate, taken from nfs)
notices that dentry in cache is invalid and whole directory cache is
invalidated and reread. So getdents with position after unlinked files
are still cached, but getdents with position before unlinked files
cause cache invalidation.
> smbfs invalidates the cache when adding or removing files or dirs,
> on rename and (sometimes) when refreshing/revalidating an inode. Changing
> it to use the dirs mtime should be as simple as ... no, I can't get it to
> work now. It keeps invalidating the cache for me :(
Then remove all cache invalidation calls except one when mtime differs.
It must then work :-)
Best regards,
Petr Vandrovec
vandrove@vc.cvut.cz

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/