RFR: JDK-8262957 (fs) Fail fast in UnixFileStore.isExtendedAttributesEnabled
Alan Bateman
alanb at openjdk.java.net
Thu Mar 4 15:17:40 UTC 2021
On Wed, 3 Mar 2021 22:15:38 GMT, Sebastian Stenzel <github.com+1204330+overheadhunter at openjdk.org> wrote:
> Added new capability flag `UnixNativeDispatcher.SUPPORTS_XATTR`, which gets set `#ifdef _SYS_XATTR_H_`.
>
> Note that `_SYS_XATTR_H_` is defined in `xattr.h` in both [macOS/Darwin](https://github.com/apple/darwin-xnu/blob/main/bsd/sys/xattr.h), [Linux and GNU-based BSD systems using glibc](https://github.com/bminor/glibc/blob/master/misc/sys/xattr.h). It might not be defined for other operating systems that still support xattr. So if OpenJDK eventually adds support for further platforms, this might need to be adjusted as well.
>
> If xattr capabilities are missing, `UnixFileStore.isExtendedAttributesEnabled` will return false immediately, avoiding any I/O.
>
> As a side effect of this change, I redefined some other (private) capabilities. Strictly speaking, this change is not required but keeps the code consistent, as [previously discussed in the mailing list](https://mail.openjdk.java.net/pipermail/nio-dev/2021-February/008133.html).
src/java.base/unix/classes/sun/nio/fs/UnixFileStore.java line 186:
> 184: return false;
> 185: }
> 186:
Add SUPPORTS_XATTR is a good idea.
Style-wise, it might be a bit neater to use if (UnixNativeDispatcher.xattrSupported()) { ...} so there will only one "return false" code path.
Looking at this code now make me wonder about the close(fd) for the case that the open fails. It should be checking if fd or there should be a nested try-finally so that close is only invoked when the open succeeds.
-------------
PR: https://git.openjdk.java.net/jdk/pull/2816
More information about the nio-dev
mailing list