Emmanuel Dreyfus <m...@netbsd.org> wrote:

> Now let us see the locking scenario:
> - process 1 opens file foo O_RDWR
> - process 2 opens file foo O_RDWR|O_NONBLOCK
> - process 1 locks a part of the file
> - process 2 atteemps to write to the locked part
> 
> With advisory locks (what we have in our filesystems),  the code above
> VFS has no reason to block process 2 write operation. The filesystem
> could notice there is a lock on the written area, but it cannot enforce
> it because it does not distinguish the file descriptors. Hence the write
> on locked area succeeds, but this is not a huge problem since the
> locks are adivsory.
> 
> With mandatory locks, the filesystem must block process 2 when it
> writes. 

The word "block" is unfortunate here: I meant the filesystem must deny
process 2 when it attempts to write. Since process 2 used O_NONBLOCK,
this means write() must return with EAGAIN.

-- 
Emmanuel Dreyfus
http://hcpnet.free.fr/pubz
m...@netbsd.org

Reply via email to