Fw: Re: Implemented OPLOCK for FreeBsd

Andrew Tridgell tridge at samba.org
Sat Sep 8 19:02:02 GMT 2001


Jonathan wrote:
> Actually, not at all.  The kqueue API already handles this quite nicely:
> 
> 	struct kevent &kev;
> 
> 	fd = open(".", O_RDONLY);		/* open directory */
> 	EV_SET(&kev, fd, EVFILT_VNODE, EV_ADD|EV_ENABLE, NOTE_WRITE, udata);
> 	kevent(kq, kev, 1, NULL, 0, &nullts);
> 		
> Which simply registers an filter on the directory that triggers whenever
> the directory (read: file) has been written.  In order to find out what
> the exact changes are, you have to call stat() or readdir().

That is a good start but it doesn't look like it is flexible enough to
cope well with directory notify events in SMB. In Linux we added the
following event bits:

	DN_ACCESS	A file in the directory was accessed (read)
	DN_MODIFY	A file in the directory was modified (write,truncate)
	DN_CREATE	A file was created in the directory
	DN_DELETE	A file was unlinked from directory
	DN_RENAME	A file in the directory was renamed
	DN_ATTRIB	A file in the directory had its attributes
			changed (chmod,chown)

These match up with similar event types in the SMB protocol. 

The reason you want such fine grained events is access times. You
don't want to trigger an event on every atime update if the client
hasn't asked for it or otherwise you will spend all your CPU time
processing these events on a busy system. Similarly, if the client
wants to know about changes in file sizes within a directory then just
watching for changes in the directory itself isn't sufficient.

> Unfortunately, this is only done on a per-file basis.  There isn't any easy
> way to have a inode notify the parent, since in *BSD, there is no 'd_parent'
> pointer.  This problem is being worked on.

ok, now I understand. Without a parent pointer it would be pretty
tricky to get this right. Once you have that in place then perhaps you
could look at adding the above notify event bits. 

With the parent pointer in Linux it turned out to be a very small and
neat patch to add full dnotify support, particularly as there was
already a function that caught all inode attribute updates.

Cheers, Tridge




More information about the samba-technical mailing list