Need advices for development back-up Samba module
idra at samba.org
Fri Jun 25 07:58:01 GMT 2004
On Thu, 2004-06-24 at 23:08, Igor Yu. Zhbanov wrote:
> The current idea is to write module for Samba that will copy changed
> files to the back-up server (on-the-fly) by the means of rsync utility.
> 1) Should module be integrated deeply into smbd or should it be written
> as a VFS module?
VFS moduls should be the right place, every disk operation go through it
so you can intercept everything happens on the files opened by the
> The idea is to copy changed files when it will be closed or when file
> was changed (and still open) and some time of inactivity (about 5 minutes)
> was passed.
> 2) If I intercept VSF write operation, do I have exclusively lock on file
> to be changed? Or only on region to be changed?
No, you do not need to, locks are advisory on posix (by default), so you
will have no problems reading files with rsync.
> 3) Can two Samba users change the same file simultaneously? This may
> be important because in the case of VFS module each connection will
> be served by its own forked child smbd process.
Yes this is indeed one of your biggest problems. A file can be opened by
more processes and modification may be also kept in a cache by the
So you should really copy only on close, but you should also raise some
sort of lock so that nobody touches the file until your copy on close is
> Also I need to copy files that was changed and still open (after some
> time passed after last write).
I think this would be a problem, you may have inconsistent data on disk,
because the client cache modifications. You may disable oplocks to avoid
client caching, but your performances will suck then.
> 4) How can I do this? Should I make it by setting alarm() signal handler
> in VFS module in child process?
Uhmmm a VFS module should not playwith signals imo.
> 5) Should I (and how?) acquire lock for changed file?
You could try to get a write lock on the file to be closed.
Once you get the lock you start your copy of the file.
As soon as you finish operations you release the lock and close the
But locking is very delicate in samba, you should ask Jeremy if it is ok
to do the locking inside the VFS module, or if it is better to first
fork-exec a new process and do it from there, while just wait()ing
inside the VFS module. That woud make probably easier to handle
exception by way of simply killing the forked process if the VFS module
feel something no going the right way.
> 6) Or is it easier to copy changed files from main smbd process
> (opposite to childs serving users connections)?
No, probably worse, that would make you change smbd itself. Try to keep
everything in you VFS module, will be much easier for you.
Simo Sorce - idra at samba.org
Samba Team - http://www.samba.org
Italian Site - http://samba.xsec.it
More information about the samba-technical