locking samba during critical VFS file operations?

Sean Dunn sean at troublemakerstudios.com
Tue Sep 27 22:57:01 GMT 2005

Thanks for your reply James! Yeah, I thought about doing this, but
figured the constant lock checking for every operation may slow things
down. What do you think about doing locking via flock versus through
System V semaphores (semget(), semctl(), etc)? Is Linux flock
implemented as a memory access or a file access?


-----Original Message-----
From: James Peach [mailto:jpeach at samba.org] 
Sent: Tuesday, September 27, 2005 5:44 PM
To: Sean Dunn
Cc: samba-technical at lists.samba.org
Subject: Re: locking samba during critical VFS file operations?

On Mon, 2005-09-26 at 18:00 -0500, Sean Dunn wrote:
> In the rename operation of my VFS, I have to do some recursive
> of symbolic links in the file system that the samba share sits on top
> of. 
> Because this relinking could cause the view of the filesystem to
> inconsistent (only during this operation), I believe I need to lock
> samba for all accesses to subdirectories of the directory being
> It'd like to wait until all pending operations have finished, do my
> critical section of code, and then unlock. Operations that happen
> I request the lock should wait until I've unlocked. Is it possible to
> achieve this level of mutual exclusion in the samba API, or is it a
> feature that I need to implement myself using mutexes?

AFAIK there is no internal Samba API to do what you want so you will
have to implement something yourself. One easy thing to do would be to
use flock against file named (say) .vfs_mutex in each directory. You
would be able to hide its existence from clients since you are
overriding readdir.
James Peach | jpeach at samba.org

More information about the samba-technical mailing list