FUSE: require valid file/dir handle; drop open_files fallback

Several FUSE ops fell back to looking up a FileInfo via
state.open_files when the kernel-provided fh was zero, returning
-ENOENT if the lookup failed. This path papered over handle-tracking
bugs and added cost on every call. Use the handle directly and
return -EBADF when it is invalid - the kernel should always hand us
a valid fh for an open resource.

Also simplify FileInfo::from_fh / DirInfo::from_fh and their to_fh
helpers: callers now handle the null-pointer case explicitly so the
ASSERT_NOT_NULL checks are redundant.

Covers fallocate, fchmod, fchown, fgetattr, flock, ftruncate,
futimens, read, release, releasedir, write, statx, ioctl (file +
dir), readdir (sequential, concurrent-on-read,
concurrent-on-search), and the passthrough fast paths in
create/open.
This commit is contained in:
Antonio S. Musumeci 2026-04-18 00:53:11 -04:00 • committed by trapexit
parent 0dcca0f1a3
commit 98648ae44b
21 changed files with 74 additions and 143 deletions

View file

@ -43,22 +43,10 @@ FUSE::fchmod(const fuse_req_ctx_t *ctx_,
cu64 fh_,
const mode_t mode_)
{
u64 fh;
FileInfo *fi = FileInfo::from_fh(fh_);
fh = fh_;
if(fh == 0)
{
state.open_files.cvisit(ctx_->nodeid,
[&](auto &val_)
{
fh = val_.second.fi->to_fh();
});
}
if(fh == 0)
return -ENOENT;
FileInfo *fi = FileInfo::from_fh(fh);
if(not fi)
return -EBADF;
return ::_fchmod(fi->fd,mode_);
}