Skip to content

feat(vfs): implement flock advisory file locking#1785

Merged
fslongjin merged 1 commit intoDragonOS-Community:masterfrom
fslongjin:feat-add-flock-support
Feb 11, 2026
Merged

feat(vfs): implement flock advisory file locking#1785
fslongjin merged 1 commit intoDragonOS-Community:masterfrom
fslongjin:feat-add-flock-support

Conversation

@fslongjin
Copy link
Member

  • 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>
@fslongjin
Copy link
Member Author

@codex review

@github-actions github-actions bot added the enhancement New feature or request label Feb 11, 2026
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +54 to +58
if operation != FlockOperation::Unlock
&& !file
.mode()
.intersects(FileMode::FMODE_READ | FileMode::FMODE_WRITE)
{

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@fslongjin fslongjin merged commit 2140513 into DragonOS-Community:master Feb 11, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant