Propagating file locks across network
dom.layfield at gmail.com
Wed Jul 11 21:10:36 GMT 2007
I expect that this issue has been debated extensively in the clustered
samba discussions, but I did a quick search of the samba-technical
archives, and couldn't find anything directly relevant.
I'm using Samba as an interface to a distributed file system. Each
node in the filesystem has its own Samba server, and I would like to
propagate locks across the network so that Samba server B is aware
that a user on Samba server A has file f open.
The goal, ultimately, is for a user opening f on B to be informed that
another user currently has the file open. (i.e. the Windows "File In Use"
There are two parts to this:
1. Recognizing that a file is locked on A, and
2. Making server B recognize that lock.
So my question is: how do I achieve both 1 and 2?
In regard to part 1, I can see two approaches. First, I can have the
filesystem recognize the kernel locks that Samba applies to the file.
I.e. catch and handle the fcntl(fd, F_SETLEASE, F_WRLCK) call. The
second approach would be to monitor Samba's locking.tdb file.
The former would be much cleaner: no need for the distributed
filesystem to be aware of anything outside of its own mount-point, or
really even to be explicitly Samba-aware at all. But in this case,
there is a lot less information available about the lock.
The latter approach (monitoring locking.tdb) is uglier, but at least
complete lock information is available. Having said that, I haven't
thought through the details. Presumably I would have a thread that
used inotify/select/poll or somesuch to wait for locking.tdb to be
modified, and then would use a library routine to parse the file.
Seems inefficient, though.
In regard to part 2 (making second server recognize the lock), I'm
even more lost at sea. If I get a (posix) write-lock on the file
(from a non-samba process), then Samba just treats this as an "access
denied". Alternatively, with a Linux lease write-lock, Samba just
waits for the lease to be released. Either way, a Windows user
doesn't get an intelligible error. So propagating the lock via the
available kernel locking mechanisms seems to be a non-starter.
That leaves the locking.tdb file. Is there a way for an external
process to add an entry into locking.tdb? (And if so, will smbd
recognize it? i.e. does smbd actually read information from locking.tdb, or is
this just an smbd output?)
If anyone has any thoughts or suggestions, I really appreciate some
help. I'm still highly ignorant of Samba internals.
More information about the samba-technical