mount: name a mount's NFS handle registrations by host and mount directory

A restarted mount drew a new random signature, so it never replaced or
removed the registrations its predecessor left for files it had open.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-25 23:34:38 -08:00
1 parent 0eaa1f84c8
commit 997f72c59d
2 files changed
+23 -1

No files matched your search

+9 -1
View File
@@ -4,6 +4,7 @@ import (
"context"
"encoding/binary"
"errors"
"os"
"sync"
"syscall"
"time"
@@ -249,8 +250,15 @@ func (h *exportedHandles) GetPath(ctx context.Context, inode uint64) (util.FullP
return registrations[len(registrations)-1].path, fuse.OK
}
// newExportedHandles names the mount's registrations after its host and mount
// directory, so a mount restarted in the same place takes over, and in time
// removes, those its predecessor left.
func (wfs *WFS) newExportedHandles() *exportedHandles {
return newExportedHandles(uint32(wfs.signature), func(key, value []byte) error {
owner := uint32(wfs.signature)
if hostname, err := os.Hostname(); err == nil {
owner = uint32(util.HashToInt32([]byte(hostname + ":" + wfs.option.MountDirectory)))
}
return newExportedHandles(owner, func(key, value []byte) error {
return wfs.withFilerClient(context.Background(), false, wfs.filerRPCWait(), func(ctx context.Context, client filer_pb.SeaweedFilerClient) error {
resp, err := client.KvPut(ctx, &filer_pb.KvPutRequest{Key: key, Value: value})
if err != nil {
+14
View File
@@ -140,6 +140,20 @@ func TestExportedHandlesRemovalKeepsAnotherMountsRegistration(t *testing.T) {
kv.waitForRegistrations(t, 8, exportedHandleRegistration{2, "/buckets/b.txt"})
}
func TestExportedHandlesRestartedMountTakesOverItsRegistration(t *testing.T) {
kv := &fakeKv{values: map[string][]byte{}}
newExportedHandlesForTest(kv, 1, time.Minute).AcquireHandle(7, "/buckets/a.txt")
kv.waitFor(t, 7, "/buckets/a.txt")
newExportedHandlesForTest(kv, 2, time.Minute).AcquireHandle(7, "/buckets/a.txt")
kv.waitForRegistrations(t, 7, exportedHandleRegistration{1, "/buckets/a.txt"}, exportedHandleRegistration{2, "/buckets/a.txt"})
restarted := newExportedHandlesForTest(kv, 1, 10*time.Millisecond)
restarted.AcquireHandle(7, "/buckets/b.txt")
kv.waitForRegistrations(t, 7, exportedHandleRegistration{2, "/buckets/a.txt"}, exportedHandleRegistration{1, "/buckets/b.txt"})
restarted.ReleaseHandle(7)
kv.waitForRegistrations(t, 7, exportedHandleRegistration{2, "/buckets/a.txt"})
}
func TestExportedHandlesRecordKeepsNewestRegistrations(t *testing.T) {
kv := &fakeKv{values: map[string][]byte{}}
var want []exportedHandleRegistration