Files
seaweedfs/weed
6f248fc190 mount: keep a clean handle off the file a peer renamed over the one it has open (#12920)
* mount: keep a clean handle off the file a peer renamed over the one it has open

A peer renames another file over the one a handle has open here. When this
mount has looked the rename's source up, MovePath reports the handle's inode
as replaced and the handle is marked deleted. When it has not, which is the
usual case for "write a temp file, rename it over the real one" done on
another mount, MovePath has nothing to move and reports nothing. The event
for the target path then reaches the handle as an update: a dirty handle
refuses it, but a clean one installs the newcomer's entry, and everything
the descriptor does afterwards lands in the replacement: writes, mmap
writes, ftruncate, fchmod, fsetxattr.

A clean handle now takes an entry with another inode at its path for what it
is. The handle is marked deleted, as after a delete, and its inode gives the
name up as a replaced rename target does, so the kernel gets ESTALE for the
old inode, walks the path again and reaches the newcomer under an inode of
its own. An entry or a handle without an inode cannot tell and installs as
before, and so does an update in place, which keeps the inode.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* mount: a replaced handle keeps a surviving hard link, a renamed one ignores its old name

From the review of a4c9a89a6.

- A hard-linked file replaced under one of its names lives on under the
  others. The handle follows it to a name this mount knows, as after a
  peer's unlink of one name, instead of being marked deleted.
- A handle that just followed its file's rename no longer reads the cache
  at the path it left. When another file had taken that name before the
  rename was applied to the handle, the handle was marked deleted (and
  before this branch, installed that file's entry).
- The replaced name is taken from the inode only while it is still the
  inode's (RemovePathOf): a rename on this mount may have handed it to
  another inode in between.
- The kernel keeps resolving the name to the old inode for as long as it
  trusts its lookup (entryValidSec). A chmod by path in that window went to
  the detached handle and reported success. The lookup is dropped with
  EntryNotify, from the invalidation worker after the handle's locks are
  released.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* mount: mark a replaced handle deleted only once its inode gives up the name

The worker looks the inode up by name before it takes the handle's lock,
so a rename on this mount can move the inode off that name in between.
The handle was then marked deleted while its file lived on under the new
name, and its flushes were dropped. RemovePathOf now decides: when the
name is no longer the inode's, the event is another file's and the
handle is left alone.

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

* mount: release the worker gate on every exit of the renamed-handle test

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

* mount: check alias ownership before following surviving links

---------

Co-authored-by: MapleWhiteZZZ <18653045+MapleWhiteZZZ@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Chris Lu <chris.lu@gmail.com>
2026-11-23 14:19:08 -08:00
..
2026-04-14 20:48:24 -07:00
2026-04-23 10:05:51 -07:00