flock possibly missing in SMB3 POSIX extensions?

Jeremy Allison jra at samba.org
Fri Feb 26 18:17:02 UTC 2021

On Fri, Feb 26, 2021 at 05:17:51PM +0100, Aurélien Aptel via samba-technical wrote:
>While debugging cifs.ko customer issues we found that flock(2) seems to
>be impossible to properly emulate using SMB.
>On first sight it looks like they could be emulated with SMB locks but
>the main difference is that FLOCKs are completely advisory, the application
>is free to ignore them and sucessfully do read/write, whereas with SMB
>locks WRITE/READ will fail on locked areas.
>The flock syscall is avaible on most unixes so it would make sense to
>support it I think. Maybe via a special flag for LOCK.
>Given the number of options to control locking behaviour in Samba and
>given how NFS doesn't support it properly either maybe there are
>problems I'm not seeing.

Yes, flock has historically not been part of UNIX
extensions. I think you *could* emulate it by converting
them into UNIX extension fcntl locks over the whole

Indeed, from man 2 flock:

        Since  Linux 2.6.12, NFS clients support flock() locks by emulating them as fcntl(2) byte-range locks
        on the entire file.  This means that fcntl(2) and flock() locks do interact  with  one  another  over
        NFS.  It also means that in order to place an exclusive lock, the file must be opened for writing.

More information about the samba-technical mailing list