Skip to content

8343417: (fs) BasicFileAttributeView.setTimes uses microsecond precision with NOFOLLOW_LINKS #21886

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

Closed
wants to merge 3 commits into from

Conversation

bplb
Copy link
Member

@bplb bplb commented Nov 4, 2024

Add support for setting the last access and last modification times of symbolic links with nanosecond precision on Linux where the system call utimensat(2) is available.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8343417: (fs) BasicFileAttributeView.setTimes uses microsecond precision with NOFOLLOW_LINKS (Bug - P4)

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/21886/head:pull/21886
$ git checkout pull/21886

Update a local copy of the PR:
$ git checkout pull/21886
$ git pull https://git.openjdk.org/jdk.git pull/21886/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 21886

View PR using the GUI difftool:
$ git pr show -t 21886

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/21886.diff

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 4, 2024

👋 Welcome back bpb! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Nov 4, 2024

@bplb This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8343417: (fs) BasicFileAttributeView.setTimes uses microsecond precision with NOFOLLOW_LINKS

Reviewed-by: alanb

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 89 new commits pushed to the master branch:

  • d3c042f: 8343770: Build fails due to use of sun.misc.Unsafe in LoopOverRandom
  • 1d117f6: 8343394: Make MemorySessionImpl.state a stable field
  • d2b681d: 8343730: JMX cleanups
  • ac82a8f: 8343610: InOutPathTest jpackage test produces invalid app image on macOS
  • f0b251d: 8343531: Improve print_location for invalid heap pointers
  • 4244682: 8339190: Parameter arrays that are capped during annotation processing report incorrect length
  • 7620b12: 8323803: ConstantOopReadValue::print_on should print 'null' instead of 'nullptr'
  • 592a48b: 8321997: Increase upper limit of LoopOptsCount flag
  • c3df050: 8343726: [BACKOUT] NMT should not use ThreadCritical
  • 0e1c1b7: 8343452: Incorrect WINDOWS build variable is used in macroAssembler_x86.cpp
  • ... and 79 more: https://git.openjdk.org/jdk/compare/ea110c35f5429f1e1de57a301e2256f508a4c324...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the master branch, type /integrate in a new comment.

@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 4, 2024
@openjdk
Copy link

openjdk bot commented Nov 4, 2024

@bplb The following label will be automatically applied to this pull request:

  • nio

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the nio nio-dev@openjdk.org label Nov 4, 2024
@mlbridge
Copy link

mlbridge bot commented Nov 4, 2024

Webrevs

*
* We hard code fd to FD_ATCWD and flags to AT_SYMLINK_NOFOLLOW.
*/
static void utimensat(UnixPath path, long times0, long times1)
Copy link
Contributor

Choose a reason for hiding this comment

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

The *at methods that are supposed to map 1-1 to the similarly named sys calls so I'm a bit uncomfortable having this one work differently and hardcode dirfd to FD_ATCWD. I wonder if we could generate a value for FD_ATCWD in UnixConstants.java.template so that the use site would more closely match the sys call.

Copy link
Member Author

Choose a reason for hiding this comment

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

I wonder if we could generate a value for FD_ATCWD in UnixConstants.java.template so that the use site would more closely match the sys call.

Sure, no problem.

Copy link
Member Author

Choose a reason for hiding this comment

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

So changed in 26feef6.

}
if (!useLutimes) {
if (!useUtimensat && !useLutimes) {
Copy link
Contributor

@AlanBateman AlanBateman Nov 5, 2024

Choose a reason for hiding this comment

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

Changing the utimesat method to match the sys call is good. Now I wonder if we go further and use fd from openForAttribtueAccess(false) with utimesat. That would remove the window between the lstat and utimesat(AT_FDCWD...) where the file may be replaced.

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed UnixFileAttributes.get calls lstat. Calling symlink.openForAttributeAccess(false) however yields

java.nio.file.FileSystemException: symlink: No such file or directory or unable to access attributes of symbolic link

According to symlink(7):

The last access and last modification timestamps of a symbolic link can be changed using utimensat(2) or lutimes(3).

It looks like futimens will not work with a symlink's fd so that utimensat is necessary here to obtain nsec precision. I don't see a way to close the window between lstat and utimensat, which anyway was already there for the lutimes case.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think that the logic in 08f5b7d is quite correct yet. It might be possible if followLinks is false and the file is not a symlink, that lutimes would be used even though futimens is supported, thus decreasing the timestamp resolution.

@AlanBateman
Copy link
Contributor

I think what you have is correct now but it's hard to follow as it's one of 4 sys calls. What would you think about use a local enum class and a switch and get rid of the 4 booleans. Alternatively, invert the setup so that if the follow case is first. The follow case should map to fd+futimens or utimes, no need for futimes. For the !follow case then it should map to lutimesnsat or lutimes. I realise this is adding to the work on this change but right now it's hard for anyone to touch this method due to the many cases.

@bplb
Copy link
Member Author

bplb commented Nov 6, 2024

I think what you have is correct now but it's hard to follow as it's one of 4 sys calls. [...] I realise this is adding to the work on this change but right now it's hard for anyone to touch this method due to the many cases.

It definitely needs reworking but I do not know the details as yet.

Copy link
Contributor

@AlanBateman AlanBateman left a comment

Choose a reason for hiding this comment

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

Discussed with Brian about some refactoring setTimes to make it more maintainable, and maybe drop the use of methods that only support micro seconds precision The AIX port may hold us back, not sure. So approving for now, there will be cleanup to follow.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 7, 2024
@bplb
Copy link
Member Author

bplb commented Nov 7, 2024

/integrate

@openjdk
Copy link

openjdk bot commented Nov 7, 2024

Going to push as commit 56c588b.
Since your change was applied there have been 89 commits pushed to the master branch:

  • d3c042f: 8343770: Build fails due to use of sun.misc.Unsafe in LoopOverRandom
  • 1d117f6: 8343394: Make MemorySessionImpl.state a stable field
  • d2b681d: 8343730: JMX cleanups
  • ac82a8f: 8343610: InOutPathTest jpackage test produces invalid app image on macOS
  • f0b251d: 8343531: Improve print_location for invalid heap pointers
  • 4244682: 8339190: Parameter arrays that are capped during annotation processing report incorrect length
  • 7620b12: 8323803: ConstantOopReadValue::print_on should print 'null' instead of 'nullptr'
  • 592a48b: 8321997: Increase upper limit of LoopOptsCount flag
  • c3df050: 8343726: [BACKOUT] NMT should not use ThreadCritical
  • 0e1c1b7: 8343452: Incorrect WINDOWS build variable is used in macroAssembler_x86.cpp
  • ... and 79 more: https://git.openjdk.org/jdk/compare/ea110c35f5429f1e1de57a301e2256f508a4c324...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Nov 7, 2024
@openjdk openjdk bot closed this Nov 7, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Nov 7, 2024
@openjdk
Copy link

openjdk bot commented Nov 7, 2024

@bplb Pushed as commit 56c588b.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@bplb bplb deleted the utimensat-8343417 branch November 12, 2024 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated nio nio-dev@openjdk.org
Development

Successfully merging this pull request may close these issues.

2 participants