feat(vfs): implement flock advisory file locking#1785
feat(vfs): implement flock advisory file locking#1785fslongjin merged 1 commit intoDragonOS-Community:masterfrom
Conversation
fslongjin
commented
Feb 11, 2026
- Add flock syscall support with shared/exclusive locks and nonblocking mode
- Introduce open file description ID for flock owner tracking
- Add flock manager with sharded hashmap for lock state management
- Support lock inheritance across dup/fork and release on last close
- Add comprehensive test suite covering basic operations and edge cases
- Fix SCM_RIGHTS fd passing to share open file description instead of cloning
- Add flock syscall support with shared/exclusive locks and nonblocking mode - Introduce open file description ID for flock owner tracking - Add flock manager with sharded hashmap for lock state management - Support lock inheritance across dup/fork and release on last close - Add comprehensive test suite covering basic operations and edge cases - Fix SCM_RIGHTS fd passing to share open file description instead of cloning Signed-off-by: longjin <longjin@DragonOS.org>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 007f65fdfa
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if operation != FlockOperation::Unlock | ||
| && !file | ||
| .mode() | ||
| .intersects(FileMode::FMODE_READ | FileMode::FMODE_WRITE) | ||
| { |
There was a problem hiding this comment.
Enforce EBADF for LOCK_UN on O_PATH descriptors
flock() on an O_PATH fd should fail with EBADF for all operations, including LOCK_UN (Linux behaves this way), but this guard skips validation when operation == Unlock. As a result, flock(opath_fd, LOCK_UN) incorrectly returns success, which breaks Linux compatibility and can mask invalid-fd bugs in userspace code that expects an error.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
This comment is incorrect. The current code intentionally matches Linux behavior.
Looking at Linux 6.6.21 fs/locks.c:2097:
if (type != F_UNLCK && !(f.file->f_mode & (FMODE_READ | FMODE_WRITE)))
goto out_putf;
Linux skips the EBADF check for LOCK_UN — only LOCK_SH/LOCK_EX on O_PATH fds return EBADF.
flock(opath_fd, LOCK_UN) is allowed through and is effectively a no-op (no lock was ever acquired).
Our code operation != FlockOperation::Unlock && !file.mode().intersects(...) is a direct translation of
the same logic. No change needed here.