lockf() vs. flock() -- lockf() not locking?

Guy Helmer guy.helmer at gmail.com
Mon Apr 6 23:19:37 UTC 2015


> On Apr 6, 2015, at 4:51 PM, Conrad Meyer <cse.cem at gmail.com> wrote:
> 
> On Mon, Apr 6, 2015 at 5:18 PM, Guy Helmer <guy.helmer at gmail.com> wrote:
>> From my reading of the lockf(3) man page and reviewing the implementation in lib/libc/gen/lockf.c, and corresponding code in sys/kern/kern_descrip.c, it appears the lockf() call should be successfully obtaining an advisory lock over the whole file like a successful flock() did. However, I have a stress test that quickly corrupts the target file using the lockf() implementation, and the test fails to cause corruption using the flock() implementation. I’ve instrumented the code, and it's clear that multiple processes are simultaneously in the block of code after the “lockf(fd, F_LOCK, 0)” line.
>> 
>> Am I missing something obvious? Any ideas?
> 
> 
> We have switched from a whole file lock to a range lock. I think it
> should still make access exclusive, so this sounds like a bug. But
> just note that it is a slightly different mutual exclusion mechanism.
> 
> Are the locked files on NFS?

No, this involves files on local filesystems.

Regards,
Guy



More information about the freebsd-hackers mailing list