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

fcntl update following up with F_GETPATH but with FreeBSD's F_KINFO f… #2152

Merged
merged 1 commit into from
Oct 6, 2023

Conversation

devnexen
Copy link
Contributor

@devnexen devnexen commented Oct 3, 2023

…lag support instead

@devnexen devnexen force-pushed the fcntl_upd_fbsd branch 11 times, most recently from 070f7d9 to f387353 Compare October 3, 2023 21:32
src/fcntl.rs Outdated Show resolved Hide resolved
src/fcntl.rs Show resolved Hide resolved
test/test_fcntl.rs Outdated Show resolved Hide resolved
@devnexen devnexen force-pushed the fcntl_upd_fbsd branch 2 times, most recently from 4f6808a to 32578dd Compare October 4, 2023 11:52
@asomers
Copy link
Member

asomers commented Oct 5, 2023

I was able to reproduce the test failure when I set TMPDIR to UFS, but not ZFS or TMPFS. I believe the CI environment uses UFS. Then I found this gem on the mailing list:

When open(2) creates a new file, the vnode name is not entered into
the name cache.  I believe this is done to smoother the case like
untarring large set of files, which would replace existing cached
entries with probably not too useful new entries.

F_KINFO uses name cache to reconstruct the last element of the path,
on most real file systems like UFS.  If this last element is not cached,
F_KINFO is unable to return the path.

And indeed, if I reopen the tempfile by its path, then the test passes on UFS. Like this:

    let tmp = NamedTempFile::new().unwrap();
    let tmp2 = File::open(tmp.path()).unwrap();
    let fd = tmp2.as_raw_fd();
    let mut path = PathBuf::new();
    let res = fcntl(fd, FcntlArg::F_KINFO(&mut path)).expect("get path failed");

https://lists.freebsd.org/archives/freebsd-hackers/2022-May/001108.html

@devnexen
Copy link
Contributor Author

devnexen commented Oct 5, 2023

I was able to reproduce the test failure when I set TMPDIR to UFS, but not ZFS or TMPFS. I believe the CI environment uses UFS. Then I found this gem on the mailing list:

When open(2) creates a new file, the vnode name is not entered into
the name cache.  I believe this is done to smoother the case like
untarring large set of files, which would replace existing cached
entries with probably not too useful new entries.

F_KINFO uses name cache to reconstruct the last element of the path,
on most real file systems like UFS.  If this last element is not cached,
F_KINFO is unable to return the path.

And indeed, if I reopen the tempfile by its path, then the test passes on UFS. Like this:

    let tmp = NamedTempFile::new().unwrap();
    let tmp2 = File::open(tmp.path()).unwrap();
    let fd = tmp2.as_raw_fd();
    let mut path = PathBuf::new();
    let res = fcntl(fd, FcntlArg::F_KINFO(&mut path)).expect("get path failed");

https://lists.freebsd.org/archives/freebsd-hackers/2022-May/001108.html

Nice find ! I no longer use UFS since ages I did not think of it.

Copy link
Member

@asomers asomers left a comment

Choose a reason for hiding this comment

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

Could you please add a CHANGELOG entry? And add a comment to the test explaining why it opens the file twice? That part looks very non-obvious.

@devnexen devnexen force-pushed the fcntl_upd_fbsd branch 2 times, most recently from efe0379 to 97b5403 Compare October 5, 2023 23:40
@SteveLauC SteveLauC added this pull request to the merge queue Oct 6, 2023
Merged via the queue into nix-rust:master with commit ed3ed6b Oct 6, 2023
35 checks passed
@SteveLauC
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants