Project

General

Profile

Feature #3252

Need a proper flock() implementation

Added by Robert Mustacchi about 8 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
kernel
Start date:
2012-10-02
Due date:
% Done:

100%

Estimated time:
Difficulty:
Hard
Tags:
Gerrit CR:

Description

Several pieces of software look for and require support for flock(). While this issue was originally about bringing in the version in libucb, it was obviously toxic because it didn't actually honor flock's semantics. This has instead been repurposed to add native support for flock.

#1

Updated by Gary Mills about 8 years ago

I hope it's defined in terms of lockf(). Most configure scripts test for the presence of flock() before lockf() and then adjust the code to call the one that they find.

#3

Updated by Joseph Holsten about 6 years ago

Looks like the one in libc isn't supporting non-blocking locks:
http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libbc/libc/sys/common/flock.c

Also, it's not possible to implement flock(2) with lockf(3c) because lockf doesn't support shared logs.

#4

Updated by Robert Mustacchi about 6 years ago

  • Assignee changed from Robert Mustacchi to Joshua M. Clulow
  • % Done changed from 80 to 0

There are a lot more fundamental problems with this which is why this has stalled, which is that the semantics the libucb version has are unsafe at any speed for folks who are trying to use flock properly. This is something that Josh has been looking at in great detail.

#5

Updated by Joseph Holsten about 6 years ago

Ah, that's not fun. I'm trying to add illumos support to a flock(1) impl. I was going to attempt reimplementing the version I've got working on darwin, freebsd & linux to just use fcntl(2). But perhaps I should help investigate.

I'm starting over at http://code.metager.de/source/xref/linux/stable/fs/locks.c which discusses the reason they implement flock() as its own syscall instead of a wrapper around fcntl().

I'll probably look into freebsd's implementation next.

#6

Updated by Joseph Holsten about 6 years ago

looks like freebsd's got a contrib doc on "BSD to HP-UX Porting Tricks" with a flock impl
http://code.metager.de/source/xref/freebsd/usr.sbin/cron/lib/compat.c#142

and here's the syscall implementation:
https://github.com/freebsd/freebsd/blob/master/sys/kern/kern_descrip.c#L2668

#7

Updated by Robert Mustacchi over 5 years ago

  • Subject changed from Move flock from libucb to libc to Need a proper flock() implementation
  • Category changed from lib - userland libraries to kernel
  • Status changed from New to In Progress
  • Assignee changed from Joshua M. Clulow to Jerry Jelinek
  • Priority changed from Low to Normal
  • % Done changed from 0 to 90
  • Difficulty changed from Medium to Hard
#8

Updated by Robert Mustacchi over 5 years ago

As part of this Keith Wesolowski originally did a survey of the various differences between POSIX locks set through fcntl, lockf, flock, and the newer GNU OFD (open file descriptor) locks which are trying to tackle and more broadly standardize the notion of locks being set upon an open file descriptor. Based on this, he determined that a flock is basically a specialized type of OFD, hence implementation of similar APIs here.

#9

Updated by Electric Monk almost 5 years ago

  • Status changed from In Progress to Closed
  • % Done changed from 90 to 100

git commit 7a5aac98bc37534537d4896efd4efd30627d221e

commit  7a5aac98bc37534537d4896efd4efd30627d221e
Author: Jerry Jelinek <jerry.jelinek@joyent.com>
Date:   2015-11-25T00:26:22.000Z

    3252 Need a proper flock() implementation
    Reviewed by: Robert Mustacchi <rm@joyent.com>
    Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
    Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
    Reviewed by: Jason King <jason.brian.king@gmail.com>
    Approved by: Garrett D'Amore <garrett@damore.org>

Also available in: Atom PDF