Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use F_OFD_SETLK instead of exfile_api() #5489

Open
alandekok opened this issue Jan 7, 2025 · 5 comments
Open

Use F_OFD_SETLK instead of exfile_api() #5489

alandekok opened this issue Jan 7, 2025 · 5 comments
Labels
feature enhancement category: a new feature (an extension of functionality)

Comments

@alandekok
Copy link
Member

Message

Linux and apparently OSX support F_OFD_SETLK, which is what you would really expect from F_SETLK.

https://lwn.net/Articles/586904/

https://www.gnu.org/software/libc/manual/html_node/Open-File-Description-Locks.html

https://man7.org/linux/man-pages/man2/fcntl.2.html

https://github.com/apple/darwin-xnu/blob/main/bsd/sys/fcntl.h

It's not clear if FreeBSD has them.

This would let us get rid of most of exfile.c(), and replace it with just open / lock / close.

The issue with normal F_SETLK is that they are process specific. So two threads can't lock the same file. With F_OFD_SETLK, different threads should be able to lock the same file without an issue.

@alandekok alandekok added the feature enhancement category: a new feature (an extension of functionality) label Jan 7, 2025
@arr2036
Copy link
Member

arr2036 commented Jan 7, 2025

The linux man page states:

F_OFD_SETLK (struct flock *)
              Acquire an open file description lock (when l_type is
              F_RDLCK or F_WRLCK) or release an open file description
              lock (when l_type is F_UNLCK) on the bytes specified by
              the l_whence, l_start, and l_len fields of lock.  If a
              conflicting lock is held by another process, this call
              returns -1 and sets [errno](https://man7.org/linux/man-pages/man3/errno.3.html) to EAGAIN.

@arr2036
Copy link
Member

arr2036 commented Jan 7, 2025

The key bit being "held by another process".

@alandekok
Copy link
Member Author

From the GNU page:

Open file description locks are useful in the same sorts of situations as process-associated locks. They can also be used to synchronize file access between threads within the same process by having each thread perform its own open of the file, to obtain its own open file description.

@arr2036
Copy link
Member

arr2036 commented Jan 7, 2025

Would be very useful if they work :)

@arr2036
Copy link
Member

arr2036 commented Jan 7, 2025

https://www.austingroupbugs.net/view.php?id=768 - Potentially made it into FreeBSD in 2022?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature enhancement category: a new feature (an extension of functionality)
Projects
None yet
Development

No branches or pull requests

2 participants