RFR: 8316304: (fs) Add support for BasicFileAttributes.creationTime() for Linux

Severin Gehwolf sgehwolf at openjdk.org
Fri Sep 29 16:35:15 UTC 2023


On Sun, 24 Sep 2023 17:18:38 GMT, Alan Bateman <alanb at openjdk.org> wrote:

>> @AlanBateman @gnu-andrew Thanks for your input! Here is an updated patch, now using LinuxFileSystemProvider and the logic to use `statx` is now in the linux specific directory trees. The fallback code is unchanged (using `UnixNativeDispatcher`). This version never uses both `stat64` and `statx`. It only uses `statx` if its available and uses the older `stat64` otherwise. 
>> 
>> On a Linux system that has `statx` (using `LastModified` from the bug):
>> 
>> # grep test.txt strace_out.log 
>> execve("./jdk-22.0.0+0/bin/java", ["./jdk-22.0.0+0/bin/java", "LastModified", "test.txt"], 0xffffe07f0b98 /* 42 vars */) = 0
>> [pid 17058] statx(AT_FDCWD, "test.txt", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0
>> # stat test.txt 
>>   File: test.txt
>>   Size: 0         	Blocks: 0          IO Block: 65536  regular empty file
>> Device: fd00h/64768d	Inode: 100734611   Links: 1
>> Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
>> Context: unconfined_u:object_r:admin_home_t:s0
>> Access: 2023-09-21 13:14:00.464356794 -0400
>> Modify: 2000-01-01 01:01:00.000000000 -0500
>> Change: 2023-09-21 13:17:13.835434277 -0400
>>  Birth: 2023-09-21 13:12:13.033760507 -0400
>> 
>> 
>> On a Linux system that doesn't have `statx`:
>> 
>> # grep 'stat' strace_out.log  | grep testme
>> [pid  8302] stat("testme.txt", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
>> # stat testme.txt 
>>   File: ‘testme.txt’
>>   Size: 0         	Blocks: 0          IO Block: 65536  regular empty file
>> Device: fd00h/64768d	Inode: 100822778   Links: 1
>> Access: (0644/-rw-r--r--)  Uid: (    0/    root)   Gid: (    0/    root)
>> Context: unconfined_u:object_r:admin_home_t:s0
>> Access: 2023-09-21 13:09:46.459640944 -0400
>> Modify: 2000-01-01 01:01:00.000000000 -0500
>> Change: 2023-09-21 13:16:08.142395814 -0400
>>  Birth: -
>> 
>> Please let me know what you think!
>> 
>> FWIW, I've compiled this fine on Alpine Linux, so there aren't any glibc guards anymore.
>
>> Thanks for your input! Here is an updated patch, now using LinuxFileSystemProvider and the logic to use `statx` is now in the linux specific directory trees. The fallback code is unchanged (using `UnixNativeDispatcher`). This version never uses both `stat64` and `statx`. It only uses `statx` if its available and uses the older `stat64` otherwise.
> 
> I was chatting with @bplb about this change, mostly about testing and maintainability. We both agreed that this PR isn't the right place to do the refactoring, there is a lot disruptive changes needed to allow overriding of what is currently in the Unix* code. So if it's okay with you, we think go back the original/smaller change in UnixNativeDispatcher.c but use stat or statx, before both, as you have in the second iteration. Would that be okay with you?

@AlanBateman Please take another look. It's now back with using the native only. It only does a single `statx` or `stat64` call depending on support of the underlying system.

Example:

$ strace -f ./java LastModified test.txt 2>&1 | grep stat | grep test.txt
[pid 200843] stat("test.txt", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
$ strace -f ./java LastModified test.txt 2>&1 | grep stat | grep test.txt
[pid 200879] statx(AT_FDCWD, "test.txt", AT_STATX_SYNC_AS_STAT, STATX_ALL, {stx_mask=STATX_ALL|STATX_MNT_ID, stx_attributes=0, stx_mode=S_IFREG|0644, stx_size=0, ...}) = 0


Long term something like the [v2 patch](https://github.com/jerboaa/jdk/compare/d75d9774c806e4bf73caa69cd78c31a132e4c812..JDK-8316304-statx-create-time-new-v2) seems more appropriate, IMO.

Thoughts?

-------------

PR Comment: https://git.openjdk.org/jdk/pull/15792#issuecomment-1741010079


More information about the nio-dev mailing list