mount: retry an NFS handle record update when its lock is not granted

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Chris LuandClaude Opus 5.5 committed 2026-11-26 00:08:33 -08:00
1 parent 508caf6a34
commit e474c9e1fc
2 files changed
+37 -10

No files matched your search

+13 -8
View File
@@ -53,10 +53,10 @@ type exportedHandles struct {
wake chan struct{}
put func(key, value []byte) error
get func(ctx context.Context, key []byte) ([]byte, error)
lock func(inode uint64) (unlock func())
lock func(inode uint64) (unlock func(), err error)
}
func newExportedHandles(owner uint32, put func(key, value []byte) error, get func(ctx context.Context, key []byte) ([]byte, error), lock func(inode uint64) (unlock func())) *exportedHandles {
func newExportedHandles(owner uint32, put func(key, value []byte) error, get func(ctx context.Context, key []byte) ([]byte, error), lock func(inode uint64) (unlock func(), err error)) *exportedHandles {
h := &exportedHandles{
owner: owner,
paths: make(map[uint64]util.FullPath),
@@ -118,7 +118,11 @@ func (h *exportedHandles) loop() {
// under -dlm; without it, mounts that update the same inode at the same moment
// can still overwrite each other's.
func (h *exportedHandles) write(inode uint64, path util.FullPath) error {
defer h.lock(inode)()
unlock, err := h.lock(inode)
if err != nil {
return err
}
defer unlock()
key := exportedHandleKey(inode)
value, err := h.get(context.Background(), key)
if err != nil {
@@ -287,14 +291,15 @@ func (wfs *WFS) newExportedHandles() *exportedHandles {
return nil
})
return
}, func(inode uint64) func() {
}, func(inode uint64) (func(), error) {
if wfs.lockClient == nil {
return func() {}
return func() {}, nil
}
lock := wfs.lockClient.NewShortLivedLock(fmt.Sprintf("%s%d", exportedHandleKeyPrefix, inode), fmt.Sprintf("mount-%d", wfs.signature))
key := fmt.Sprintf("%s%d", exportedHandleKeyPrefix, inode)
lock := wfs.lockClient.NewShortLivedLock(key, fmt.Sprintf("mount-%d", wfs.signature))
if lock == nil {
return func() {}
return nil, fmt.Errorf("lock %s", key)
}
return func() { lock.StopShortLivedLock() }
return func() { lock.StopShortLivedLock() }, nil
})
}
+24 -2
View File
@@ -20,12 +20,19 @@ type fakeKv struct {
values map[string][]byte
err error
getDelay time.Duration
lockErr error
turn sync.Mutex
}
func (kv *fakeKv) lock(uint64) func() {
func (kv *fakeKv) lock(uint64) (func(), error) {
kv.Lock()
err := kv.lockErr
kv.Unlock()
if err != nil {
return nil, err
}
kv.turn.Lock()
return kv.turn.Unlock
return kv.turn.Unlock, nil
}
func (kv *fakeKv) put(key, value []byte) error {
@@ -160,6 +167,21 @@ func TestExportedHandlesConcurrentMountsKeepBothRegistrations(t *testing.T) {
})
}
func TestExportedHandlesWriteWaitsForTheLock(t *testing.T) {
kv := &fakeKv{values: map[string][]byte{
string(exportedHandleKey(7)): formatExportedHandle([]exportedHandleRegistration{{2, "/buckets/a.txt"}}),
}, lockErr: errors.New("no lock server")}
h := newExportedHandlesForTest(kv, 1, time.Minute)
h.AcquireHandle(7, "/buckets/a.txt")
time.Sleep(100 * time.Millisecond)
kv.waitForRegistrations(t, 7, exportedHandleRegistration{2, "/buckets/a.txt"})
kv.Lock()
kv.lockErr = nil
kv.Unlock()
kv.waitForRegistrations(t, 7, exportedHandleRegistration{2, "/buckets/a.txt"}, exportedHandleRegistration{1, "/buckets/a.txt"})
}
func TestExportedHandlesRestartedMountTakesOverItsRegistration(t *testing.T) {
kv := &fakeKv{values: map[string][]byte{}}
newExportedHandlesForTest(kv, 1, time.Minute).AcquireHandle(7, "/buckets/a.txt")