Skip to content

Commit 95a8302

Browse files
authored
Probe for statx availability even when statx returns ENOSYS. (#1048)
Following rust-lang/rust#123928, check whether the system supports `statx` even when the initial call returns `NOSYS`, because that can come from a faulty FUSE driver.
1 parent 76143e1 commit 95a8302

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

src/fs/statx.rs

+11-17
Original file line numberDiff line numberDiff line change
@@ -102,34 +102,28 @@ mod compat {
102102
mask: StatxFlags,
103103
) -> io::Result<Statx> {
104104
match backend::fs::syscalls::statx(dirfd, path, flags, mask) {
105-
Err(io::Errno::NOSYS) => statx_error_nosys(),
106-
Err(io::Errno::PERM) => statx_error_perm(),
105+
Err(err) => statx_error(err),
107106
result => {
108107
STATX_STATE.store(2, Ordering::Relaxed);
109108
result
110109
}
111110
}
112111
}
113112

114-
/// The first `statx` call failed with `NOSYS` (or something we're treating
115-
/// like `NOSYS`).
113+
/// The first `statx` call failed. We can get a variety of error codes
114+
/// from seccomp configs or faulty FUSE drivers, so we don't trust
115+
/// `ENOSYS` or `EPERM` to tell us whether statx is available.
116116
#[cold]
117-
fn statx_error_nosys() -> io::Result<Statx> {
118-
STATX_STATE.store(1, Ordering::Relaxed);
119-
Err(io::Errno::NOSYS)
120-
}
121-
122-
/// The first `statx` call failed with `PERM`.
123-
#[cold]
124-
fn statx_error_perm() -> io::Result<Statx> {
125-
// Some old versions of Docker have `statx` fail with `PERM` when it
126-
// isn't recognized. Check whether `statx` really is available, and if
127-
// so, fail with `PERM`, and if not, treat it like `NOSYS`.
117+
fn statx_error(err: io::Errno) -> io::Result<Statx> {
128118
if backend::fs::syscalls::is_statx_available() {
119+
// Statx is available. Record this, and fail with the error
120+
// code of the initial `statx` call.
129121
STATX_STATE.store(2, Ordering::Relaxed);
130-
Err(io::Errno::PERM)
122+
Err(err)
131123
} else {
132-
statx_error_nosys()
124+
// Statx is not available. Record this, and fail with `NOSYS`.
125+
STATX_STATE.store(1, Ordering::Relaxed);
126+
Err(io::Errno::NOSYS)
133127
}
134128
}
135129
}

0 commit comments

Comments
 (0)