mount: answer ESTALE for an inode whose name the filer no longer has (#13447)

* mount: answer ESTALE for an inode whose name the filer no longer has

A job that writes a status file through a tmp name retried a failed
round by opening the tmp name again. The kernel still resolved the name
to the failed round's inode, and the mount still mapped it, but the filer
had no such file: the open failed with ENOENT although it asked for
O_CREAT, and the job exited.

lookupEntry already logged such a tracked name ("filer ErrNotFound for
tracked path"). It now drops the name from the inode table when no open
handle and no pending flush owns the inode, and requests for the inode by
node id answer ESTALE (maybeReadEntry, AcquireHandle), as
pathlessInodeStatus already does for an inode without a name. The kernel
looks the name up again and, for an open with O_CREAT, creates the file,
which gets an inode of its own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: drop a vanished name only while it maps to the inode looked up

lookupEntry read the name's inode after the filer answered. A rename
that gave the name to another inode while the request was in flight, a
directory say, had that inode's name dropped on the strength of an answer
about the name as it was. The inode is now taken before the request, and
the name is dropped only while it still maps to that one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* mount: keep the vanished name mapped; ESTALE alone has the kernel look again

Dropping the name raced with an open of the same inode: a handle
published between the check for one and the removal, or just after it,
had no name left, so a peer's rename of that name no longer reached it
and its flush went to the old name. pathlessInodeStatus answers ESTALE
for any inode the kernel still holds, so maybeReadEntry and AcquireHandle
get the kernel to look the name up again without the table losing it.
A file created at the name meanwhile reuses the inode number, as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Yip LeoandClaude Opus 5.5 authored and GitHub committed 2026-12-05 11:13:51 -08:00
1 parent 68f99dc114
commit 2637ff09c5
3 files changed
+102

No files matched your search

+5
View File
@@ -801,6 +801,11 @@ func (wfs *WFS) maybeReadEntry(ctx context.Context, inode uint64) (path util.Ful
return "", nil, nil, wfs.pathlessInodeStatus(inode, status)
}
entry, _, status = wfs.maybeLoadEntry(ctx, path)
if status == fuse.ENOENT {
// The filer no longer has the inode's name: the kernel looks the name
// up again on ESTALE.
status = wfs.pathlessInodeStatus(inode, status)
}
return
}
+6
View File
@@ -48,6 +48,12 @@ func (wfs *WFS) AcquireHandle(ctx context.Context, inode uint64, flags, uid, gid
entryVersionTsNs = entryVersion{tsNs: existingFh.entryVersionTsNs.Load(), signature: existingFh.entryVersionSignature.Load()}
} else {
entry, entryVersionTsNs, status = wfs.maybeLoadEntry(ctx, path)
if status == fuse.ENOENT {
// The name the kernel resolved is gone from the filer: ESTALE
// has the open look it up again (with O_CREAT, create it),
// where ENOENT failed it.
return nil, 0, wfs.pathlessInodeStatus(inode, status)
}
if status != fuse.OK {
return nil, 0, status
}
+91
View File
@@ -0,0 +1,91 @@
package mount
import (
"context"
"runtime"
"syscall"
"testing"
"github.com/seaweedfs/go-fuse/v2/fuse"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
)
// staleStatus is the answer for an inode whose name is gone: ESTALE, which has
// Linux walk the path again; elsewhere ENOENT (see pathlessInodeStatus).
func staleStatus() fuse.Status {
if runtime.GOOS != "linux" {
return fuse.ENOENT
}
return fuse.Status(syscall.ESTALE)
}
// vanishedNameFiler has the directory /dir and nothing in it.
type vanishedNameFiler struct {
filer_pb.UnimplementedSeaweedFilerServer
}
func (s *vanishedNameFiler) LookupDirectoryEntry(ctx context.Context, r *filer_pb.LookupDirectoryEntryRequest) (*filer_pb.LookupDirectoryEntryResponse, error) {
if r.Directory == "/" && r.Name == "dir" {
return &filer_pb.LookupDirectoryEntryResponse{Entry: &filer_pb.Entry{Name: "dir", IsDirectory: true, Attributes: &filer_pb.FuseAttributes{FileMode: uint32(0o777) | 1<<31}}}, nil
}
return nil, status.Error(codes.NotFound, filer_pb.ErrNotFound.Error())
}
func (s *vanishedNameFiler) CreateEntry(ctx context.Context, r *filer_pb.CreateEntryRequest) (*filer_pb.CreateEntryResponse, error) {
return &filer_pb.CreateEntryResponse{}, nil
}
func (s *vanishedNameFiler) UpdateEntry(ctx context.Context, r *filer_pb.UpdateEntryRequest) (*filer_pb.UpdateEntryResponse, error) {
return &filer_pb.UpdateEntryResponse{}, nil
}
// A job retried a failed round by opening its tmp name again, which the
// kernel still resolved to the failed round's inode. The filer had no such
// file, and the open failed with ENOENT, O_CREAT notwithstanding. ESTALE has
// the kernel look the name up again and create the file.
func TestOpenOfVanishedNameAnswersEstale(t *testing.T) {
wfs := newInvalidateTestWFS(t)
wfs.option.FilerMountRootPath = "/"
startFakeFiler(t, wfs, &vanishedNameFiler{})
dirInode := wfs.inodeToPath.Lookup("/dir", 1, true, false, 0, true)
const stale = uint64(197923552737547634)
wfs.inodeToPath.Lookup("/dir/0115.json.tmp-7", 1796393673, false, false, stale, true)
caller := fuse.Caller{Owner: fuse.Owner{Uid: 1000, Gid: 20}}
var opened fuse.OpenOut
code := wfs.Open(make(chan struct{}), &fuse.OpenIn{InHeader: fuse.InHeader{NodeId: stale, Caller: caller}, Flags: syscall.O_WRONLY}, &opened)
if code != staleStatus() {
t.Fatalf("open of the vanished name's inode: %v, want %v", code, staleStatus())
}
// The name stays mapped, so a handle another opener publishes meanwhile
// still follows a rename event about it.
if got, found := wfs.inodeToPath.GetInode("/dir/0115.json.tmp-7"); !found || got != stale {
t.Fatalf("name mapped to %d (%v), want it kept on %d", got, found, stale)
}
// The kernel looks the name up again, finds nothing and creates it.
var out fuse.CreateOut
if code := wfs.Create(make(chan struct{}), &fuse.CreateIn{InHeader: fuse.InHeader{NodeId: dirInode, Caller: caller}, Flags: syscall.O_WRONLY | syscall.O_CREAT | syscall.O_TRUNC, Mode: 0o644}, "0115.json.tmp-7", &out); code != fuse.OK {
t.Fatalf("create after ESTALE: %v", code)
}
wfs.ReleaseHandle(FileHandleId(out.Fh))
}
// A stat of the inode, as the first request after the file went away, gets
// ESTALE too.
func TestGetAttrOfVanishedNameAnswersEstale(t *testing.T) {
wfs := newInvalidateTestWFS(t)
wfs.option.FilerMountRootPath = "/"
startFakeFiler(t, wfs, &vanishedNameFiler{})
wfs.inodeToPath.Lookup("/dir", 1, true, false, 0, true)
const stale = uint64(197923552737547634)
wfs.inodeToPath.Lookup("/dir/0115.json.tmp-7", 1796393673, false, false, stale, true)
var attr fuse.AttrOut
if code := wfs.GetAttr(make(chan struct{}), &fuse.GetAttrIn{InHeader: fuse.InHeader{NodeId: stale}}, &attr); code != staleStatus() {
t.Fatalf("getattr of the vanished name's inode: %v, want %v", code, staleStatus())
}
}