Commit Graph
517 Commits
Author SHA1 Message Date
Yip LeoandClaude Opus 5.5 71b1911e44 mount: answer statfs from the stats at hand, refresh them in the background (#13337)
StatFs asked the filer for Statistics whenever its stats were older than
20 s and waited for the answer, up to the 20 s filer RPC timeout, so a
slow filer or master held statfs for that long. A node agent that probes
mounts with a bounded statfs, as the CSI driver's health monitor does
with 5 s, took such a mount for hung and restarted it, on every node at
once when the filer was slow for all of them. Every concurrent statfs
also sent its own request while the stats were stale.

StatFs now answers from the stats it has and starts a refresh in the
background when they are older than 20 s, one at a time. Only the first
statfs waits, for the first refresh. A refresh the filer does not answer
keeps the last known stats, as before, and the next one starts 20 s after
it.

The stats are now read and written under a lock: the refresh and the
quota check write them while statfs and the quota check read them.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 10:39:23 -08:00
5dafe56a63 mount: let SEEK_DATA and SEEK_HOLE see data that is not in the chunks (#13335)
* mount: let SEEK_DATA and SEEK_HOLE see data that is not in the chunks

Lseek searched only the file's uploaded chunks. Writes not uploaded yet,
inline content and the data of a remote file that is not cached are not
in them, so for such a file SEEK_DATA answered ENXIO and SEEK_HOLE found
a hole at the offset. A program that copies by data ranges, such as
qemu-img, takes the data for a hole and writes zeros in its place.

A file whose data is not all in its chunks is now answered as one data
range without holes, as lseek(2) allows: SEEK_DATA returns the offset and
SEEK_HOLE the end of the file. The upload pipeline attaches a chunk
before it counts the upload as done, and writes hold the handle lock
that lseek shares, so a file with no pending upload has all its written
data in its chunks.

Lseek also read the file size without the entry lock, while upload
workers append chunks under it. It now holds the lock for that read.

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

* mount: answer lseek from the chunks of a cached remote file

A remote file keeps its RemoteEntry once cached, so checking only for
RemoteEntry reported every such file as one data range. Use
IsInRemoteOnly, as Read does, so the holes of a cached file are found.

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

* mount: trim the lseek comments

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-12-03 10:31:58 -08:00
Yip LeoandClaude Opus 5.5 34d36e599a mount: drop a directory's listing when the cache refuses an entry update (#13336)
* mount: drop a directory's listing when the cache refuses an entry update

UpdateEntry and UpdateEntryChecked returned the store's error and left
the entry in the local store as it was. The mount uses them to refresh
the other names of a hard-linked file after a link or an unlink
(syncHardLinkSiblings), which only logged the error at V(4). With a full
cache disk the siblings kept their old link count and ctime until their
directory was read again.

A refused update now drops the listing of the entry's directory, as
dropListingsOf does for an event the store cannot take (#13141), so the
next lookup there goes to the filer. The listing is dropped after the
cache lock is released, as dropListingsOf does.

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

* mount: shut the meta caches of the refused update test down

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 10:30:23 -08:00
c96636ecd0 filer: fold chunk lists for scoped commits (#13281)
* filer: fold chunk lists for scoped commits

A filer serving a keep-only scoped token never folded chunk lists, and
refused any new chunk for an entry holding manifests, so scoped clients
kept their lists flat. On a store with a value size limit, such as
FoundationDB, a scoped file stopped fitting at about 1000 chunks.

The filer now folds scoped commits and reuses stored manifests as it does
for unscoped ones. Folding runs after the retained-data check, so the only
manifests a scoped commit stores are ones the filer wrote:

- a scoped request may keep a manifest stored at the target, sent as
  stored; any other manifest is refused, with or without a proof, and a
  stored manifest cannot be kept as a data chunk;
- the chunks held by the stored manifests count as stored at the target
  and join the identity map, so they may be retained flat but not under
  another spelling of their file id;
- those chunks are read under the handler's path lock, not at admission;
  admission still refuses a manifest the target does not store and leaves
  the checks that depend on the held chunks to the locked check. A
  manifest that cannot be read refuses the write as Unavailable. An update
  rechecking inside its store transaction reuses the chunks it already
  read, so it does no volume I/O there.

Appends to a folded entry are allowed under the same rules: an append
keeps every stored chunk, and the locked check refuses aliases of the
chunks the stored manifests hold.

* mount: explain why a scoped mount keeps chunk lists flat

A filer serving a scoped token now folds scoped commits itself and keeps
only the manifests it wrote. The mount's flat rule is unchanged; only the
reason given for it was out of date.

* filer: test a scoped truncate through a stored manifest

* filer: refuse manifest chunks in a scoped append

An append moves each chunk it carries to the end of the file. A manifest
cannot be moved that way: the chunks it holds keep their own offsets, so
the appended range would read no data and the manifest's bytes would still
read at their old place. Before this series a scoped request could carry no
manifest at all; now that a scoped commit may keep a stored manifest, an
append still takes data chunks only.

* filer: read only the stored manifests a scoped commit drops

The locked retained-data check read every stored manifest whenever a
scoped request had chunks, so each flush of a folded file and each append
cost one volume read per manifest under the path lock. The unscoped path
reads only the manifests a commit drops.

Read the same way for a keep-only scope: only the stored manifests the
request does not keep unchanged, and none for an append, which keeps every
stored chunk. A kept manifest keeps its chunks referenced, and garbage
comparisons match chunk identities, so another spelling of one of its
chunks cannot get the needle deleted; such a chunk now needs its own proof
like any new chunk. Truncating through a manifest and listing its chunks
flat still work, since both drop it.

* filer: find the dropped manifests of a scoped commit in one pass

Index the manifests the request keeps by file id instead of scanning the
request for each stored manifest, which compared and cloned chunks
quadratically in the number of manifests.

* filer: rewrap the scopeManifestReader comment

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 04:22:12 -08:00
d715c4e28f mount: buffer a write in memory when the swap file cannot take it (#13205)
* mount: buffer a write in memory when the swap file cannot take it

The dirty pages of a random write, or of more files than the memory budget
holds, go to a swap file under -cacheDirWrite (by default -cacheDir). On a
full cache disk the swap file cannot be created, or a write into it fails,
and the FUSE write failed with EIO (#12655; before it the mount panicked or
acknowledged a write it had not kept). The data was still in hand.

Such a chunk now stays in memory. A chunk whose swap write fails is sealed
with what it holds, so its upload keeps that, and the data goes into a
chunk in memory. The file then keeps chunks in memory for a 10s backoff
before it tries its swap file again. The sealed chunk uploads through the
swap read-back of #13198: if its earlier bytes cannot be read back either,
the flush fails, while the data written again into memory still uploads.

Memory stays bounded, as the sequential path bounds it: past 8 writable
chunks in the file, or past the shared memory-chunk ceiling, the file seals
a chunk before it creates another. Sealing waits for an upload slot, so a
writer that outpaces its uploads slows down instead of filling memory.

The #12655 tests made a write fail through an unusable swap directory. They
now make the dirty pages refuse the write directly, and a new test checks
that an unusable swap directory no longer fails it. A pipeline test covers
a sealed chunk whose swap file can no longer be read.

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

* mount: move a refused swap chunk into memory instead of sealing it

When the swap file refused a write, the first commit sealed the swap chunk
with what it held and wrote the data again into a new chunk in memory at
the same index. Two chunks at one index fail in two ways:

- A disk that takes part of an overwrite, as a full copy-on-write disk can,
  leaves the swap chunk with the new first half and the old second half.
  Its upload joins the two under the overwrite's timestamp, and the memory
  chunk uploads the new bytes under the same timestamp. Equal timestamps
  resolve to the chunk the entry lists last, so when the swap upload
  finished last the old bytes came back.
- Sealing the memory chunk while the swap chunk was still uploading
  replaced the swap chunk in the sealed slot. Until its upload finished,
  reads of the bytes only it held found nothing.

Now the swap chunk's ranges are read back into the new memory chunk, each
under its own timestamp, before the write goes in. The swap chunk then gives
back its slot without an upload, so the index keeps one chunk. When the swap
file cannot be read back either, or memory holds the shared ceiling of
chunks, the write stores only what the swap file took and reports a short
write, as master does.

Memory now stays under the shared ceiling of memory chunks. Before, a file
with no chunk of its own to seal allocated a new chunk past the ceiling
anyway, so memory grew with the number of open files writing sparse
chunks. Now that write fails. A file that has a chunk seals it to make room
for the new one, as before. The per-file bound is also checked again after
each seal, since a seal releases the lock.

refusingDirtyPages moves to a test file built on every platform, because
the copy range test also uses it on FreeBSD.

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

* mount: seal a memory chunk at the shared ceiling and recheck both bounds

At the shared ceiling, a file made room for a new chunk in memory by
sealing any one of its writable chunks. A swap chunk left by a refused
write frees no memory when it uploads, so memory went past the ceiling by
one chunk for each file in that state. At the ceiling a file now seals
one of its memory chunks, and if it has none the write fails.

Sealing releases the lock, and other writers may create chunks meanwhile.
The per-file bound was checked again after a seal made for it, but not
after a seal made for the shared ceiling. One loop now checks both bounds
again after every seal.

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

* mount: drop an empty swap chunk the swap file refused at the shared ceiling

At the shared ceiling, a swap chunk created for a write that the swap file
then refuses cannot move into memory. It was left in place, holding
nothing. Such chunks count against the file's bound, but nothing can seal
an empty chunk, so after enough refused writes a later write found nothing
to seal and created a chunk past the bound anyway. The empty chunk is now
dropped, giving back its slot and its write budget. A write that still
finds nothing to seal at the bound fails instead of going past it.

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

* mount: seal a memory chunk of the file before moving a refused swap chunk at the ceiling

At the shared memory ceiling a new chunk seals one of the file's memory
chunks and carries on, but a swap chunk whose write the swap file refused
failed the write instead. That is the first write after every backoff on
a full cache disk, and every write into an existing swap chunk.

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

* mount: keep the per-file bound when a refused swap chunk moves into memory

A file may hold more swap chunks than swapRefusedWritableChunks. When the
swap file refuses a write into a chunk created past that count, moving it
into memory left the file over the bound with every chunk in memory.
Seal another chunk of the file first, as a new chunk does.

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

* mount: write again when a refused swap chunk is sealed during a seal

Moving a refused swap chunk into memory may first seal another chunk,
which releases the lock. If another writer or the flusher sealed the
swap chunk meanwhile, the write failed although a new chunk could take
it. Write into the chunk now at the index instead.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-12-01 16:01:52 -08:00
Chris LuandClaude Opus 5.5 e84c3f9ada mount, filer: a content change clears the stored content MD5 (#13238)
* mount: a content change clears the stored content MD5

Attributes.Md5 is the whole content's MD5: the S3 and WebDAV ETags and
WebDAV's oc:checksums report it. A write, a size change, a grown
fallocate, an O_TRUNC open or a copy_file_range into the file kept it, so
those reported the old content's MD5 and an ETag that did not change.

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

* filer: AppendToEntry clears the stored content MD5

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

* mount: copy_file_range clears the MD5 once it buffers bytes

A cancelled copy or a later read error returned before the clear, leaving
the bytes already buffered under the old MD5.

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

* filer: an empty AppendToEntry keeps the content MD5

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 13:22:56 -08:00
Chris LuandClaude Opus 5.5 0872953b81 mount: resolve NFS file handles across a weed mount restart (-nfsExport) (#13020)
* mount: persist a created file's entry at create time under -nfsExport

A file created over NFS gets a handle at create time. With creation
deferred to flush, a mount that stops before the flush leaves no entry for
the next mount to resolve that handle to.

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

* mount: resolve NFS file handles of files an earlier mount had open

With -nfsExport, the mount records on the filer the path of each file it
has open, keyed by inode, and drops the record a minute after the last
close. A "." lookup on a node id the mount does not know reads that
record, so the NFS server can reopen its files after the mount restarts or
another mount takes over. A failed read answers EIO rather than ESTALE.

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

* mount: record NFS handles at open, not on every path refresh

A writeback close flushes after the last release, and the flush refreshes
the handle's path. Recording there renewed the record of a file no longer
open, so it was never removed. Opens and creates now record, and a path
refresh only moves an existing record.

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

* mount: leave writeback creates deferred under -nfsExport

With writeback caching an eager create runs as an async filer RPC that an
unlink does not wait for, so a quick create+unlink could bring the name
back. Writeback mounts already accept losing unflushed files on a crash.

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

* mount: retain a recorded handle path only once it matches the file

A path read from the filer record was retained before the lookup checked
it, so a stale one kept answering ESTALE without reading the record again.
It is now retained right before LookupHandle, and never over a forgotten
inode or path the table already holds.

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

* mount: count NFS handle opens, keep other mounts' records, retry writes

A reopen that attached a new handle before the close registered its
release left a removal pending for an open file; opens are now counted.
Records carry the writing mount's signature, so a delayed removal leaves
a record another mount wrote since. A failed write is retried while the
inode's state is unchanged, and the put runs under the attempt context.

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

* mount: keep one NFS handle registration per mount in an inode's record

Two mounts with the same file open shared one record, so the one that
closed last removed the path the other still had open. Each mount now
replaces or drops only its own registration, and a lookup uses the newest.

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

* 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>

* mount: take turns on an NFS handle record through the lock manager under -dlm

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

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

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

* mount: renew an NFS handle record's lock for the whole update

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

* mount: resolve an NFS handle record to the newest path under the mount root

Another mount rooted elsewhere could hold the newest registration of a
hard-linked inode, hiding this mount's own valid path.

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

* mount: register an NFS handle at the path the mount knows now

A rename could move the inode after an opener read its path but before
the new handle was registered, so the record kept the old path; a stale
opener could also move an existing record back.

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

* mount: keep no NFS handle records with -filer.tokenFile

The filer refuses KvGet and KvPut to scoped tokens, so the records would
only fail: log at startup instead, and keep the in-process handle support.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 12:31:17 -08:00
Yip LeoandClaude Opus 5.5 e8fef6bdfd mount: fail a read of dirty pages that cannot be read back from the swap file (#13215)
Dirty pages that weed mount buffers in the swap file (non-sequential
writes, or when the memory chunks run out) also serve reads until they
upload. SwapFileChunk.ReadDataAt logged a read error and stopped,
returning only how far it had read; UploadPipeline.MaybeReadDataAt and
DirtyPages.ReadDirtyDataAt passed that offset up. The mount read path
then served the rest of the range from the stored chunks or from zeros,
and the read returned OK. A read error on the cache disk, or a swap file
truncated by an outside cleanup, is enough: the application reads back
bytes it was told were written and gets other bytes, with no error
anywhere. This is the read-side twin of #13198, which made the upload
of those bytes fail.

PageChunk.ReadDataAt, UploadPipeline.MaybeReadDataAt and
DirtyPages.ReadDirtyDataAt now return an error besides the offset. A
swap chunk that cannot read back an interval overlapping the requested
range returns it, wrapping the new ErrDirtyDataUnreadable and the read
error (a short read is io.ErrUnexpectedEOF). Intervals outside the range
are not read, so a read that does not touch the lost bytes still
succeeds. MemChunk cannot fail. The read handler and copy_file_range
turn the error into EIO. Read does not refresh the filer entry and retry
for this error, since the entry has no say over bytes that only exist in
the swap file.

A failed read does not mark the handle failed. Reads of other ranges and
writes keep working, and the upload path already records the failure
when it cannot read the same bytes, so flush, fsync and close return EIO.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 11:58:05 -08:00
Yip LeoandClaude Opus 5.5 82a435c468 mount: list a directory from the filer when the cache disk cannot hold it (#13204)
* mount: list a directory from the filer when the cache disk cannot hold it

A listing builds the directory into the mount's local metadata cache, a
leveldb store under -cacheDir, and serves it from there. Once that disk is
full the build fails at its first write, and the listing failed with it:
readdir returned EIO for every directory the mount had not cached, and for
one whose cached listing a refused event had just dropped (#13141). Files
could still be opened, read and written; only listing them broke.

A build the store refuses now reports a LocalStoreError, and the listing
reads the directory through from the filer, the way it already does for a
directory too large to cache. Builds then wait out a 10s backoff instead of
re-listing a directory from the filer only to fail at its first insert
again; once the disk has room the next build caches the directory. While
the store refuses, at most 4 listings per mount read through at once, so a
burst of them reaches the filer spread out rather than all together.

The hand-over from a walk served from the cache to one read through from
the filer resumed at the request's offset, so the entries the cached walk
had just put in the same reply were sent again and the client listed them
twice. A directory found too large partway through a walk took that path
rarely; a full cache disk takes it on every request. The direct walk now
resumes past the entries already in the reply.

Lookups needed no change: in a directory the cache does not hold, a lookup
already asks the filer for the one entry.

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

* mount: list unflushed creates and every page when reading a directory through

Listings read through from the filer are now the common path on a full
cache disk. This fixes three gaps in them:

- A file created on this mount is not on the filer until its first flush.
  Until then the local store holds a placeholder for it, which a rebuild
  keeps. A cached listing showed such a file; a listing read through from
  the filer left it out. The read-through now merges in, page by page and
  in name order, the children the local store keeps for a rebuild
  (MetaCache.LocalOnlyChildren, which asks the same pinnedChildFn as the
  rebuild's wipe). Each page takes the ones after its start and up to its
  last name; the last page takes every one past its start. A name the
  filer also has by now is listed once. Directories too large to cache
  read through the same way, so they get the fix as well.
- The filer applies the page limit before the loader leaves out the root's
  hidden system entries (etc, topics). A full page that held one came back
  short, and the listing ended there. The end of the directory is now read
  from the number of entries the filer sent. If a failover reruns a page,
  the loader starts its entries and that count over.
- A walk served from the cache also hands over to the filer when
  refreshing a stale section would list too many entries
  (ErrRefreshRangeTooLarge). That hand-over still resumed at the request's
  offset, so it sent again the entries already in the reply. It now
  resumes where the cached walk reached, like the other hand-over.

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

* mount: keep the rest of a read-through page on the directory handle

A page listed from the filer went onto the directory handle only up to the
entry the reply had no room for. The next request listed the filer again
from there and merged the unflushed creates again, so with small replies
each filer page was listed, and the local store scanned, once per reply.
Now the whole page goes onto the handle, and later requests take what is
left from it, as they do from the cache. The unflushed creates are also
looked up without decoding chunk lists.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 10:57:29 -08:00
Yip LeoandClaude Opus 5.5 e3e3bacf10 mount: read an open file's extended attributes under its entry lock (#13194)
* mount: read an open file's extended attributes under its entry lock

getxattr and listxattr on an open file read the Extended map of the
handle's live entry with no lock, while setxattr and removexattr change
that map in place. Go ends the process on a concurrent map read and
write, so weed mount exits with "fatal error: concurrent map read and
map write" (GetXAttr) or "concurrent map iteration and map write"
(ListXAttr), and every file open on the mount returns ENOTCONN. The
kernel asks for security.capability on each write(), so a program that
writes a file while another process sets or removes its attributes
reaches this.

The entry's own lock, LockedEntry.RWMutex, is the one every other
writer of the handle's entry takes: truncate to zero, the metadata
merges of a flush, SetEntry and the acknowledged-attribute retention.
setxattr and removexattr changed the map under the handle lock and
entryLock only. They now also take the entry lock, in the documented
order after those two, and re-read the handle's entry under it, as
SetAttr does, in case SetEntry swapped it. GetXAttr and ListXAttr read
the handle's current entry under the entry's read lock and copy what
they return before releasing it. The read lock is a leaf: it waits for
no other lock and does not wait for the handle lock, so a getxattr is
not held up by a write in progress.

TestXAttrReadsAgainstSetAndRemoveOnOpenFile and
TestXAttrReadsAgainstTruncateToZeroOnOpenFile abort the test binary with
the fatal errors above without the change, and all three race tests
report data races under -race.

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

* mount: remove the attributes the xattr race test sets

The writer of TestXAttrReadsAgainstSetAndRemoveOnOpenFile set even
keys and removed odd ones, so every RemoveXAttr found no key and
returned ENOATTR before deleting anything. Each name is now set and
then removed, and both calls must succeed. With RemoveXAttr's entry
lock taken out, -race reports its delete against GetXAttr's read.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 23:13:23 -08:00
Yip LeoandClaude Opus 5.5 de76148f54 mount: fail the flush when dirty pages cannot be read back from the swap file (#13198)
* mount: fail the flush when dirty pages cannot be read back from the swap file

Dirty pages that weed mount buffers in the swap file (non-sequential
writes, or when the memory chunks run out) are read back when they
upload. SwapFileChunk.SaveContent ignored the error of that read: an
interval it could not read in full was uploaded short, or not at all,
and flush, fsync and close still succeeded. The writes the application
had been told succeeded became a hole in the stored file, with no error
anywhere. A read error on the cache disk, or a swap file truncated by an
outside cleanup, is enough.

SaveContent now hands the upload a reader that fails with the read
error. The upload fails like any other failed chunk upload: the handle
records it, rejects further writes, and flush, fsync and close return
EIO without publishing the entry. The remaining intervals of that chunk
are not saved, since the handle cannot flush cleanly. The chunk, its
write budget and its swap slot are released as before.

The test in weed/mount cuts the swap file after the write was
acknowledged: on master fsync returns OK and the filer is never told.
The pipeline tests cover a closed and a truncated swap file, and a swap
file cut inside the second of two intervals.

SwapFileChunk.ReadDataAt, which serves reads of pages not yet uploaded,
still logs a read error and returns what it has read so far; that is
left for a follow-up since it needs an error path through the read side.

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

* mount: require a failed fsync to leave the filer entry unchanged

TestFsyncFailsWhenSwapFileCannotBeReadBack accepted any filer entry
backed by stored bytes that left out the lost range, so an entry
published with the readable interval (the original 256 bytes plus the
"A" write) would also have passed. It now records the filer's entry
before the writes and requires the same entry and the same 256 bytes
after the failed fsync.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 21:55:31 -08:00
Yip LeoandClaude Opus 5.5 265b3aae0f mount: take the two handle locks of CopyFileRange in one order (#13197)
CopyFileRange locked the destination handle exclusively and then the
source handle shared. Two copy_file_range calls in opposite directions
between the same pair of files (A to B and B to A, which coreutils cp
issues by default) each held their destination and waited for their
source, and neither could go on. Every operation that needs either
handle's lock then waits behind them: reads, writes, flush, release,
and the invalidation of the handle by a metadata event. The processes
using the two files hang until the mount is restarted.

The two locks are now taken in ascending FileHandleId order, whichever
of the two handles is the destination; the destination is still locked
exclusive and the source shared. A copy whose source and destination are
the same handle takes the one lock exclusive, as before. CopyFileRange
is the only place that holds the fhLockTable locks of two handles at
once, which the nested lock order comment in filehandle.go now says.

The test queues the first copy behind a handle lock held by the test and
starts the opposite copy while it waits; the lock order is the only
thing that lets both finish. It fails on master with both copies parked
in the lock queue.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 21:54:37 -08:00
394e9d247e mount: keep assignment proofs until the filer stores their chunks (#13186)
* operation: return the assignment proof of an upload

A filer serving a scoped token returns an assignment proof with
AssignVolume and stores a new chunk in an entry only when the request
presents that proof in chunk_auth. UploadWithRetry dropped it, so a
client had no way to commit the chunks it uploaded.

UploadResult.AssignAuth now carries the proof of the assignment the data
was finally stored under. A proof from an assignment the upload abandoned
after a failed attempt is never returned. The field is not serialized and
stays empty when the filer sends none, so existing callers are unchanged.

* mount: keep assignment proofs until the filer stores their chunks

A mount with a scoped filer token was refused whenever it wrote new
chunks: the filer asks for the assignment proof of every chunk the stored
entry does not hold, and the mount never kept it.

The mount now keeps the proof of every chunk it uploads and attaches the
proofs of the chunks a request names to each create, update and append
it sends, over the mutation stream and over unary calls, on every
attempt. A proof is released only once a filer acknowledged an entry that
names the chunk, or a manifest that holds it. A failed, refused or timed
out commit releases nothing, since it may have been stored: the retry
still carries the proof, and a filer ignores proofs for chunks it holds.
Proofs are stateless, so a commit retried on another filer of the cluster
is accepted there.

The store is bounded. When it is full an upload waits for commits to make
room before it is assigned a file id, and fails after a minute instead of
evicting a proof a pending commit still needs. Only proofs well past their
expiry, which a filer refuses anyway, are dropped to make room.

Without a filer token the mount keeps no store: its requests and chunk
lists are as before. A token without path grants is given no proofs, so
nothing is attached either.

* mount: keep chunk lists flat with a filer token file

A filer serving a scoped token stores no new chunk in an entry that holds
manifests, so once a mount folded a file's small chunks into a manifest,
every later write to that file was refused. A mount with a filer token now
keeps chunk lists flat; mounts without one fold as before.

* mount: test the unscoped-token path with a signed token

GenJwtForFilerScope returns an empty token when it is given no path
grants, so both cases of TestUnscopedMountRequestsCarryNoProofs ran a
tokenless mount. Sign an unscoped filer token instead and check that it
is not empty, so the test covers a mount holding a token the filer issues
no proofs for.

* mount: fold chunk lists unless the filer scopes the mount's token

A mount with -filer.tokenFile kept every chunk list flat, also when the
token is an unscoped one the filer issues no proofs for. Such a mount
stopped folding chunks into manifests, so its small-chunk runs were never
folded and, on FoundationDB, a file past about 1000 chunks no longer fit
its entry. Keep lists flat only while the current token has path grants
or a method list, which the filer scopes; fold as before otherwise.

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 18:18:29 -08:00
Chris LuandClaude Opus 5.5 5815d13881 mount: keep in-place updates at a listed entry's commit stamp (follow-up to #13152) (#13189)
* mount: keep an entry whose in-place update is already reflected

A listed entry carries its own commit stamp, so the update event that made
it arrives at exactly that stamp. The removal half passed the strict check
while the write half was fenced, and the entry was deleted and tombstoned.
An in-place update is one change: when its write is fenced, so is the
removal of the same path.

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

* mount: report a cached entry's own commit as its version

FindEntry still versioned a listed entry at the listing floor, below the
commit it carries. An open handle compares invalidations against that
version, so a delayed event the cache fenced out could still replace the
handle's content with the older state.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 16:05:41 -08:00
df2fa630c1 mount: fence events below a cached entry's own commit stamp (#13152)
A listing snapshot capped at the peers' delivery watermark can trail
entries already in the store. A delayed event older than the listed
version then rolled the entry back, e.g. a completed file to its empty
create, until the newer event arrived. A live entry now counts as
versioned at least at its CommitTsNs.

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 15:28:08 -08:00
bcd678271e mount: authorize filer calls with a pre-issued token file (#13118)
* security: filer token source read from a file

FilerTokenFile is the token source of a client that holds a pre-issued
filer token rather than a signing key. It reads the file on every call,
so an atomic replacement that keeps size and mtime takes effect on the
next attempt, and trims surrounding whitespace. A missing, unreadable,
empty or malformed file fails the call: there is no fallback to anonymous
or admin authority, and errors name the path but not the contents.

FilerTokenClaims decodes a token's claims without a key, and
FilerTokenGrantCovers compares two grants, so a client can plan
reconnects before expiry and know when a replacement narrows what it
may see.

* mount: -filer.tokenFile authorizes filer calls with a pre-issued token

A mount that should not hold a filer signing key can now present a
token issued for it. -filer.tokenFile (or -o filer.tokenFile=) names the
file; it is read for every filer gRPC attempt, so a replaced file takes
effect on the next call or retry without a restart, and a missing or
empty file fails the call locally.

The source reaches every filer client the mount builds: the startup
handshake, each attempt of WithFilerClient, the volume location client,
the SSE-S3 reader's configuration call, the peer registrar dial and the
lock client. It is attached per call, never to the cached channel, and
never to master, volume or peer mount RPCs.

The filer refuses MountRegister, MountList and distributed locks to
scoped tokens, so the mount refuses to start when -filer.tokenFile is
combined with -peer.enable or -dlm instead of failing at run time.
Server-side copy_file_range signs its filer HTTP request with the HTTP
key, not this token, and is unsupported with it.

Without the flag the mount behaves as before.

* mount: resubscribe metadata with a replaced filer token

A metadata subscription keeps the authority it opened with, so a mount
reading -filer.tokenFile would follow with the old token until the filer
ended the stream at expiry, and every such end took the gap path that
distrusts all cached listings.

SubscribeMetaEvents now takes the credentials of each attempt. The mount
opens each subscription with the token current at that moment and
watches the file; once it holds a different token the attempt ends and
the follow resubscribes at once from its checkpoint. This planned
resubscribe is not a gap: cached listings stay, unless the new grant may
show less than the old one or either token cannot be decoded, in which
case they are read again so nothing the old grant showed outlives it.

The filer walk treats a resubscribe like a stopped follow, so the same
attempt is not replayed on the next filer. Without a token file nothing
changes.

* mount: hand the mutation stream over to a replaced filer token

The mutation stream keeps the token it opened with, and a filer refuses
to send on a scoped stream once that token has expired. A mutation
applied at that moment loses its reply, the mount reads that as a
transport failure, and the unary fallback sends it again.

The stream now opens with a snapshot of the token source. Before
admitting a request it checks the source: when the file holds another
token, or the stream's token would expire before a reply could come
back, the stream is retired. New requests wait while the admitted ones
are answered, the stream is half-closed so the filer finishes it, and a
successor opens with the new token. The waits give up only after
filerRPCWait without a response, so a rename that keeps answering is not
cut short. A request is never resent by the handover: one still
unanswered when the wait gives up fails as on any lost stream, as
before.

A token too close to expiry to open a stream with is refused before
anything is sent, so the request goes out once as a unary call, which
the filer checks when it starts. Without a token file nothing changes.

* mount: review fixes for the filer token file

- A distrust of cached listings now also discards the directory builds in
  flight, in the meta cache's apply loop: such a build publishes nothing,
  its entries are wiped and the visit lists the directory again, so a
  listing read under a grant that has since narrowed is never cached after
  the distrust. The cached flags are reset again in the loop, after any
  build that completed before it.
- Retiring the mutation stream runs in the background, and a request that
  waits for the retirement gives up on its own context, unadmitted.
- With a token file and no filer signing key, server-side whole-file copy
  is not tried: its filer HTTP request would go out unsigned and fail as
  ambiguous. The copy streams through the chunk path instead.
- On Windows the token file is opened with delete sharing, so a renewer
  can replace it by rename while a read holds it open; the missing-file
  test checks os.ErrNotExist instead of Unix wording.

* mount: review fixes for the mutation stream handover

A request admitted to the mutation stream with just over one RPC wait
left on its token could wait behind a slow send until that margin was
gone; its reply could then be refused at expiry and the request was
resent over unary. The send loop now checks the margin again right
before sending and holds back a request that no longer has it, which is
safe to send over unary because the filer never saw it. A sent request
whose reply is lost while the token has one RPC wait or less left now
fails with EIO instead of a transport error: the filer may have applied
it, so it is not resent. Losses with the margin intact fall back to
unary as before.

A newly opened stream now admits its first request through the same
checks as an open one, so a token file replaced, or a token that neared
expiry, while the stream opened is caught before anything is sent.

A retirement keeps a cancel handle for its stream. Close uses it, so
unmount no longer waits for admitted requests to be answered, and a
waiter that gives up on a retiring stream stops it as it would stop an
open one, so a request still queued there is never sent after that
waiter fell back to unary. An ordinary rotation still drains admitted
requests.

* mount: drop kernel listings when the filer token's grant narrows

A replacement token whose grant may not cover the old one already
distrusts the mount's own cached listings. The kernel kept its own copy:
OpenDir sets FOPEN_CACHE_DIR | FOPEN_KEEP_CACHE, so a directory still
reachable under the new grant was listed again from the page cache with
names the new grant may hide, until something else invalidated it.

On a narrowed or undecodable grant the mount now also notifies the
kernel for every directory inode it holds, from the subscription
goroutine as the metadata apply path already does, so the next readdir
reaches the mount. A readdir already under way on an open handle still
finishes from what it read.

* mount: drop kernel listings after a subscription gap too

distrustCachedListings serves both the narrowed-grant path and the gap
path. A gap can lose the very events that would have dropped the kernel's
cached listings one directory at a time, and with FOPEN_KEEP_CACHE on
OpenDir the kernel then serves those listings on every reopen. Move the
kernel drop into distrustCachedListings so both paths get it.

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 13:02:28 -08:00
Yip LeoandClaude Opus 5.5 c3f7f24684 mount: wake an upload parked on a read when the read ends (#13123)
* mount: wake an upload parked on a read when the read ends

An upload that finishes while a read holds its chunk waits in its own
goroutine until the read lets go (`for up.IsLocked(index) {
up.readerCountCond.Wait() }`), and only then drops the sealed chunk and
returns its executor slot. The only wake-up came from MaybeReadDataAt,
which a read calls before it lets go of the chunk. UnlockForRead, where
the read does let go, woke nobody. So:

- A read that returns before its dirty-page pass never wakes the
  upload. readDataByFileHandleWithContext skips readFromDirtyPages when
  the chunk read fails, and the kernel interrupts a FUSE read, which
  cancels it, whenever a signal reaches the reading thread.
- A read that does call MaybeReadDataAt wakes the upload while it still
  holds the chunk, so the upload goes back to waiting unless the read
  releases the chunk before the upload gets the lock back.

Only a later read of the same file then moves the upload on. When none
comes, because the file was closed or is no longer read, the upload
stays parked for good. It keeps its sealed chunk (and its share of
-writeBufferSizeMB, when that is set) and a slot of the
concurrentWriters executor, which every file of the mount shares (128
by default). Once parked uploads hold every slot, each new upload of
the mount waits for one, and writes and flushes behind them hang.

UnlockForRead now broadcasts when the last read of a chunk ends, which
is the only place the condition changes, and MaybeReadDataAt no longer
signals. It broadcasts rather than signals: a read across a chunk
boundary releases two chunks, and an upload may be parked on each.

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

* mount: wait for the uploads to park instead of sleeping in the wake-up tests

parkUploads slept 100ms and assumed the uploads were waiting on the read
by then. An upload that had not got there yet would find the read gone
and go on without a wake-up, so the tests could pass with the wake-up
missing. It now watches the goroutines' stacks until each upload waits
on readerCountCond, counting out uploads an earlier test left waiting.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 10:49:25 -08:00
576eb98ce9 mount: leave -cacheMinFreeSpace free on the chunk cache's disk (#13124)
* mount: leave -cacheMinFreeSpace free on the chunk cache's disk

weed mount sizes its on-disk chunk cache by -cacheCapacityMB alone and
preallocates each cache file in full when it creates it. With a capacity
larger than the free space of the disk holding -cacheDir, the cache takes
that disk down to nothing: the preallocations run until fallocate fails,
and chunk writes fill the rest. The mount's metadata cache (a leveldb
store under -cacheDir) and the swap files of dirty pages (-cacheDirWrite,
which defaults to -cacheDir) live on the same disk, so once it is full
their writes fail with ENOSPC, and writes whose dirty pages spill to
swap return EIO to the application. The same happens when several mounts
share a cache disk and together are configured beyond it.

-cacheMinFreeSpace is the free space the cache leaves on that disk,
written like the volume server's -minFreeSpace: a percentage like 1 or a
size like 10GiB, 1 by default, as for volume servers.

- When the cache opens, its disk layers shrink to the space above the
  floor, counting the cache files already in the directory as the cache's
  own. With no room the disk tier keeps no files.
- Each new cache file preallocates only what the disk holds above the
  floor at that moment, so the files of one cache, or the caches of
  several mounts opening together, stop reserving at the floor.
- A chunk write that lands in blocks its file already holds, preallocated
  or written, goes ahead as before, even with the disk under the floor.
  A write that takes new disk space, into a file a rotation truncated or
  where nothing could be preallocated, goes ahead only while the space
  above the floor covers it. The disk is read at most once a second, and
  the cache counts what it takes in between, so it cannot run past the
  floor between readings. A rotation gives the truncated file's blocks
  back, so the write after it reads the disk again.

A chunk the cache cannot place is not cached, like any other miss. The
webdav server's cache passes no floor and behaves as before.

* mount: read the cache disk on every write that takes space, leave the index files room

Review follow-ups.

- take reads the disk each time, instead of once a second less what the
  cache took since, so a write sees what other mounts sharing the disk
  wrote, and what a rotation gave back. It runs only for writes past the
  blocks a file already holds, and a statfs costs little next to the
  write.
- The index files (.idx and the leveldb maps) grow by a few dozen bytes a
  chunk beside the data files that the cache size counts. Sizing leaves
  them a sixteenth of the room above the floor.
- The cache's own files count as room by the blocks they hold, so a file
  that was preallocated but not yet written when the mount exited counts
  in full when the cache reopens.
- weed fuse checks -o cacheMinFreeSpace in the parent as well: the parent
  waits for the child's signal, and a child that rejects the value never
  sends it.

* mount: keep the resolveCacheDirs doc comment on resolveCacheDirs

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

* mount: say -cacheMinFreeSpace stops new disk space, not every chunk

Under the floor the cache still fills the blocks its files already hold.

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 10:48:28 -08:00
Yip LeoandClaude Opus 5.5 ecd0493906 mount: keep following the metadata log when the cache refuses an event (#13141)
* mount: keep following the metadata log when the cache refuses an event

The mount applies each event of the filer's metadata log to its local
metadata cache, a leveldb store under -cacheDir. Once that disk is full
every write to the store fails, and an event the cache refuses goes one
of two ways:

- An event the stream delivers fails the follow, which the mount runs
  with FatalOnError: glog.Fatalf ends the process, every file open on
  the mount goes with it, and the mount does not come back when the disk
  has room again.
- An event replayed from the persisted log is returned to the follow
  loop, which resubscribes from it and fails on it again: the mount
  stays up, but no later event reaches its cache, so its listings stop
  changing.

A local change whose apply fails (create, mkdir, unlink, rmdir) drops
its directory's cached listing with InvalidateChildrenCache and goes on.
An event from the log now does the same: the cached listings it
changes, the parents it leaves and enters and a directory it creates,
moves or deletes, are dropped, so the next lookup reads the filer and
the next listing rebuilds them, and the event's kernel invalidations
still go out. The follow goes on. A warning reports the first such
event and then at most one a minute.

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

* mount: handle a refused event in the apply step that refused it

Review of the previous commit found two gaps.

A rename into a directory whose listing is being built applies the part
leaving the source at once and keeps the part entering the building
directory for the build to replay. When the part applied at once was
refused, the other part was not kept, and the build published its
listing without the renamed file. It is now kept whatever happens to
the part applied at once.

The listings a refused event changes were dropped, and its kernel
invalidations sent, by the follow's event function after the apply
returned. By then the apply loop could have taken a later request, such
as this mount's own create of the name a rename left, and the rename's
invalidation would then move the new file. The apply step that fails
now does both before it returns, as it sends the side effects of an
event the store takes, and on the apply loop, which owns buildingDirs
and is the only one to feed the invalidate worker. A local change whose
apply fails gets the same; its caller still drops its directory's
listing as before.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 10:42:25 -08:00
3c7b3fc16f mount: fail an unlink or rename the filer did not apply (#13140)
* mount: fail an unlink the filer did not apply

* mount: hold an unlinked handle's flushes until the filer answers

* mount: mark a rename's replaced handle once the filer answers

* mount: read a draining handle's unlink mark under its lock

Unlink now sets the mark after the delete answers, while a close queued
before it can be draining, so the worker's bare read raced the write.

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

* mount: drop the unlink comment about marking before the delete

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

* mount: wait for the close to block on the handle lock in the unlink and rename tests

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

* mount: wait on the handle lock with the untagged helper in the rename close test

waitAttributeReadFrame lives in a !freebsd test file, so the FreeBSD test
build failed on weedfs_rename_publish_test.go.

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 10:41:22 -08:00
Chris LuandClaude Opus 5.5 bd9e9a37c2 mount: send an open's truncate to the write owner as a conditional update (#13113)
An open with O_TRUNC over an existing file stored the empty entry with an
unconditional UpdateEntry. The filer only routes conditional writes to the
path's write owner, so the truncate landed on the filer the mount talks to,
which deleted the chunks it dropped, while a peer's conditional chmod could
still commit at the owner over the entry it had not yet seen truncated. The
owner's write then brought the deleted chunks back into the entry.

The truncate now goes through saveEntryAttributes: guarded by the entry the
open found, routed to the owner, and replayed on the owner's entry when
refused.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 17:44:06 -08:00
760f88e294 filer: bind scoped POSIX locks to the verified token id (#13047)
* filer/posixlock: key lock owners and leases by principal

A lock's owner becomes (Principal, Sid, Owner). The principal is server-side
state, empty for unscoped callers, so owners with equal client-chosen sid and
owner under different principals conflict and never match on unlock, release,
reassertion or coalescing. The session index and leases key on
(Principal, Sid).

Scoped sessions are leased per key from their first acquisition: the lease
ends at the earlier of TTL after the last acquisition or renewal on that key
and Lease.NotAfter. Expired scoped locks are dropped before any operation on
their key as well as by ReapExpired. Unscoped sessions keep their current
whole-session lease, started by the first keepalive.

The handler passes the unscoped session for now, so behaviour is unchanged.
NewManagerWithClock lets tests drive lease boundaries.

* filer: bind scoped POSIX locks to the verified token id

PosixLock trusted the client-supplied sid. GET_LK reports a conflicting
lock's sid and owner, so a scoped caller with a write grant on the same path
could reuse them to unlock or release another holder's lock, keep it alive,
or replace it through a KEEP_ALIVE reassertion. A tokenless request with the
same identity could do the same.

A request admitted for a scoped token now acts for that token's verified jti,
derived in posixLockAuthority from the interceptor's authority. It controls
only the locks it took, whatever sid or owner it names. Its lease on each key
ends at the earlier of the 15s TTL after its last acquisition or renewal and
the token's expiry plus the clock leeway. Each renewal passes admission for
its key, so a narrower token cannot extend keys outside its grant. Tokenless
and unscoped calls keep the unscoped namespace and behaviour, and can no
longer match a scoped lock. Scoped TRY_LOCK and reassertion ranges must be
well-formed read or write ranges, checked before any state changes.

GET_LK, the protobuf and forwarding are unchanged; the principal is never
returned or logged. A renewed token with a new jti is a new owner: the old
locks expire and are reacquired.

* filer/posixlock: release an expired session once, however many ranges it holds

* posix locks: report a lock lost on re-assertion to the mount

A mount whose lease lapsed, for example when its scoped token expired or
was replaced by one with a new id, kept re-asserting locks that another
session had since taken. The filer logged the loss but returned success,
and the mount discarded the reply, so nothing on the mount side showed it.

KEEP_ALIVE now returns the first conflicting lock in the existing
has_conflict and conflict fields, which older mounts ignore. The mount
warns once per key when it learns of a loss and forgets it once a
re-assertion succeeds or the key is no longer held. Writes are not fenced.

* filer/posixlock: drop every expired session's ranges in one pass

* filer/posixlock: renew a scoped session's same-grant leases together

Scoped leases expire per key and a keepalive renewed only the key it named.
A mount renews its keys one keepalive at a time, so with many keys and slow
keepalives a round could outlast the 15s lease and a healthy mount lost
locks; unscoped sessions never had this problem because any keepalive
renews the whole session.

Each scoped lease now records a fingerprint of the verified grants it was
acquired or re-asserted under: a SHA-256 over the sorted, deduplicated
(access level, path) entries. A keepalive, bare or re-assertion, extends
every live lease of the same session (principal and sid) held under the
same fingerprint, each to the request's lease (the earlier of the TTL and
the token's expiry plus leeway). Leases taken under other grants, such as
a narrower token reusing the jti, are still renewed only by name, and a
lease that already ended is not revived before the sweep drops it. No
extra filer lookups; unscoped sessions are unchanged.

* filer/posixlock: bound same-grant renewal and refuse ended-lease grants

A scoped keepalive scanned every key of its session to renew those held
under the same grant, so a mount renewing N keys one by one did N^2 lease
visits per round under the manager's mutex. The scan now runs at most once
per quarter lease TTL per grant; every key under the grant still ends no
earlier than three quarters of a TTL after the latest renewal, and the named
key is always renewed in full.

TryLock now refuses a scoped grant whose lease has already ended, such as a
request admitted just before its token expired that then waited on the
manager, instead of granting a lock the next operation would drop. The filer
returns Unauthenticated, which the mount reports as EIO.

* filer/posixlock: skip same-grant scans by deadline floor, not by time

The scan throttle remembered when a grant was last renewed, not how long
that renewal made its keys last. A replacement token with the same id and
grants but a later expiry could then renew one key while the others kept
ending at the old token's expiry.

Each session now keeps, per grant, the deadline the last scan gave every
live key under it, lowered whenever a key is leased for less. A renewal
skips the scan only while that floor already reaches the earlier of its
own deadline and three quarters of a TTL from now, so a mount renewing
keys one by one still costs linear work.

A keepalive from a session holding no leases records nothing, and a
session's floors go with its last lease, so lock-less keepalives with
changing session ids no longer accumulate state the sweeper never sees.

* filer/posixlock: never move a scoped lease's deadline earlier

Renew, a re-assertion, a same-grant scan and a re-lock all set the key's
deadline to the request's own bound. A request under the old token of a
principal that already renews under a replacement (same id and grants,
later expiry) can land after the replacement's renewal, for example one
of the 32 concurrent keepalives in flight when the mount switched
credentials. It then cut the key back to the old token's expiry, and the
lock was dropped before the next round although the replacement had
renewed it. Keep the later of the current and the requested deadline:
every deadline still comes from an admitted request of the same
principal, so a lease never outlives the latest of its tokens.

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

* filer/posixlock: keep each session's index and leases in one map

bySession, lastSeen, leases and floors were four maps keyed by Session that
had to be created and pruned together. They become one sessions map whose
sessionState holds the session's keys (with each key's lease), its last
keepalive and its grant floors, so a session's state is dropped in one place.
The release loop shared by ReapExpired and ReleaseSession becomes releaseOn.

ReleaseSession now also forgets an unscoped session's last keepalive, so a
session it released is not reported again by the next sweep.

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:58:42 -08:00
Chris LuandClaude Opus 5.5 46b10efcce mount: refuse a stale truncate over a peer's chunks and keep later times when merging a flush (#13100)
* mount: refuse a merge whose local truncate cuts chunks a peer wrote

A flush refused by IF_ENTRY_EQUAL replays the handle's truncate onto the
stored entry. The truncate was made over the handle's base, so a chunk a
peer committed after that base was dropped or clipped silently, losing
data the peer had already fsynced. Like a stale whole-file rewrite over a
peer's chunk change, it now fails the merge. A base chunk the peer only
shortened carries no peer data and is still cut.

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

* mount: keep the later mtime and ctime when merging a delayed flush

The merge took every attribute the handle changed from the handle, so a
flush that waited behind a peer's commit moved mtime and ctime back to
the handle's older write. Each time is now merged as one value (seconds
and nanoseconds were merged field by field, so a moved second could take
the peer's nanoseconds): the handle's time stands unless a peer moved it
too and later.

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

* mount: let a truncate merge pass the handle's own committed chunks

A flush whose commit answer was lost finds its own chunks in the stored
entry while its base is still the older one. Those chunks are the
handle's writes, not a peer's, so they do not refuse the merge.

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

* mount: do not keep a stored copy of a chunk the merge re-adds from the handle

A stored chunk the base lacks but the handle holds is the handle's own
commit whose answer was lost. The merge appends the handle's chunks after
the stored ones, so keeping the stored copy referenced the chunk twice.

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

* mount: take the manifests of a failed flush's fold for the handle's own chunks

A flush can commit its folded manifests and lose the answer. The handle
reverts to the member chunks and keeps its old base, so the next merge
found the stored manifest, knew neither its file id nor its key, and
refused it as a peer write across the handle's truncate.

The handle now remembers the folds of flushes that failed over its base,
and a merge unfolds them in the stored entry before comparing, so the
members match the handle's chunks. A peer's manifest is still refused.

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

* mount: take a retried flush's own stored fold for its own chunks

The client retries a request whose connection dropped, and the first try
may have stored the flush's folded manifests. The retry is then refused
over them before the fold is recorded as failed, and the merge took the
manifest for a peer's write across the handle's truncate. The merge now
unfolds the flush's own fold in the stored entry as well; the condition
still names the entry as stored.

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

* mount: keep every fold the filer may hold instead of the last four

Dropping the oldest of four could forget the fold the filer committed,
and the merge then refused that manifest again. A fold is now kept only
when the flush failed without the filer's answer, or when the refusal
lookup shows it stored, so a refused flush no longer adds one, and the
list ends with the base.

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

* mount: keep a flush's fold when its first request may have been stored

A precondition verdict on a retried send does not prove the first send
stored nothing, and a failed refusal lookup then hid that it had. The
create now counts the sends of the request that carries the fold and
keeps the fold whenever the flush fails and that request was sent more
than once or never got the filer's answer. That covers both flush paths,
so revert is back to only restoring the chunks.

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

* mount: drop the failed folds a refused create shows were not stored

A refusal means the stored entry moved off the handle's base, so no
request guarded by that base can store another fold. After the refusal
lookup the handle keeps only the folds whose manifests the stored entry
holds, at most one, which bounds the list over a base.

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

* mount: bound the failed folds a handle keeps over one base

Flushes that keep failing with no filer answer each saved a new fold the
filer may hold, so the list grew for as long as the outage lasted. Once a
handle keeps maxFailedFolds folds over its base, its flushes send their
chunks unfolded for the filer to fold, and no kept fold is dropped.

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

* mount: keep the failed folds a refusal lookup does not show

The refusal comes from the file's write owner, but the lookup after it can
read a filer that lags behind and still shows the base. Pruning the folds
against that read forgot a fold the owner had stored, and once its manifest
showed up a pending truncate took it for a peer's chunk on every flush. The
maxFailedFolds limit bounds the list, so the folds stay until the base moves.

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

* mount: drop the chunks a failed flush sent that the handle has cut since

A flush that commits with its answer lost, then a truncate of the handle,
left the next merge with the handle's own committed chunks in the stored
entry, outside both base and the handle. The truncate check took them for
a peer's writes and refused every later flush over the base. A failed
flush now records the file ids of the chunks it sent that base lacks, and
the merge drops those the handle no longer holds: it cut or replaced them.

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

* mount: copy the failed flush's sent set with a loop

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

* mount: keep folding past maxFailedFolds instead of sending chunks unfolded

The filer folds a flat chunk list itself, into manifests the handle does
not know: a lost answer then left one of them across a pending truncate,
and an acknowledged one gave the handle flat chunks under a folded base.
Flushes fold as before, and the handle stops keeping folds past the limit
while it still records the chunks they sent.

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

* mount: read the stored manifests a refused merge cannot name

A fold changes no content, but a manifest the handle does not know sat in
the stored entry as one chunk: across a pending truncate it refused the
merge, though it can hold the handle's own chunks (a fold it did not keep,
or one the filer made). When the merge is refused, the flush reads those
manifests, replaces them with the chunks they hold and merges again.

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

* mount: hold the chunks the filer stored after a plain acknowledged flush

The filer folds a flat chunk list (the mount's own fold failed), and the
acknowledgement makes the stored entry the base while the handle kept the
flat chunks. A later merge took them for writes of the handle, which can
bring back chunks a peer's truncate removed. As after a merge, the handle
now takes the stored chunks, keeping those attached since the request.

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

* mount: keep a bounded record per failed flush instead of a growing set

The set of chunk ids failed flushes sent grew with every overwrite while
commits failed, and each failure copied it whole. Each failed flush the
filer may have stored (a send got no verdict) now keeps one record, its
fold and the ids it sent, built once and at most maxFailedFlushes over a
base. Past that, a merge refuses the chunks of a flush it did not keep
that the handle has cut since, as a peer's.

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

* mount: register the chunks a rebase or install gives the handle for reads

A handle that takes the stored chunks after a flush (or a peer's, after a
merge) can get manifests the filer made, and resolving them needs the
file's read token. rebaseEntry and installRewrittenChunks now record the
chunks under the file's path before the read view resolves them.

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

* mount: keep every chunk id a failed flush sent, cap only the folds

Past four failed flushes over one base the handle stopped recording what a
later flush sent. If that flush was stored with its answer lost, a truncate
of its chunks was refused as a peer's write and kept failing after the
filer came back. The ids now go into one set shared by the base's marks,
each kept once and never copied, until the base moves. Only the folds stay
capped: a stored manifest past the cap is read when a refused merge cannot
place it.

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

* mount: fail a flush over a peer's chunk change unless -concurrentWriteMerge

A content flush refused because another mount committed first used to
merge the handle's writes onto the stored entry. That merge now runs
only with the new -concurrentWriteMerge mount option (off by default).
By default a stored chunk change that neither the base nor the handle
holds fails the flush with EIO, and a peer's chunk event no longer
rebases a dirty handle. Attribute-only changes and the handle's own
commits (a lost answer, its own truncate) still merge.

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

* mount: recognize the shortened references a failed flush sent

A truncate shrinks a base chunk in place, keeping its file id. A failed
flush that may have stored such a reference recorded only file ids base
lacks, so a later truncate saw its own stored reference as a peer's
change and failed with EIO by default.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 12:34:30 -08:00
Chris LuandClaude Opus 5.5 663af6fccb mount: review fixes for the metadata follow shutdown (on top of #13092) (#13097)
* mount: drop the issue number from the shutdown test comment

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

* mount: end the filer walk when the consumer stopped following

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

* pb: end the follow when a retried event reports a stop

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

* mount: check the subscriber is gone before the late event can end it

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

* mount: never retry a filer call whose consumer stopped following

The walk already stopped on pb.ErrStopFollowing, but RetryOnError still
classified the wrapped error by its cause, so a transport-looking cause
reran the whole filer walk.

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

* pb: keep the cursor behind an event whose retry the follow ended

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

* mount: close the meta cache after the follow-cancel test joins it

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 16:10:26 -08:00
Konstantin Lebedevandwhitefox 63ab6c6190 mount: stop the metadata follow before closing the meta cache (#13092)
* test(mount): reproduce the #5289 mount abort on a late metadata event

A metadata event that arrives after metaCache.Shutdown() reaches
glog.Fatalf through FatalOnError, so the mount dumps every goroutine and
exits 255 instead of unmounting cleanly — the signature reported in
issue #5289, still reachable on current master.

The subscriber has no way to stop: its context is rooted at
context.Background() and util.RetryUntil always retries, while unmount
closes the cache underneath it.

glog.Fatalf cannot be intercepted from another package (glog's
logExitFunc is unexported), so the reproduction runs the mount in a child
process and reads its exit code.

* mount,pb: stop following metadata when the cache closes

The mount follows metadata with FatalOnError, so an event that arrives
after metaCache.Shutdown() — which unmount guarantees, since the
subscriber is never stopped — was logged as a fatal and aborted the
process with a goroutine dump.

Report a closed cache as pb.ErrStopFollowing, a class the follow loop
ends on instead of routing through the per-event error modes. It is not
a failed event but the end of the subscription: no later event can land
either. SubscribeMetaEvents then leaves its retry loop rather than
reconnecting onto a store that no longer exists.

Also export the meta_cache sentinel as ErrClosed so consumers can tell a
closed cache from a storage failure.

* mount: end the metadata follow before closing the meta cache

The subscription goroutine had no owner: its context was rooted at
context.Background() and util.RetryUntil retried forever, while unmount
closed the cache underneath it. Every unmount left a window in which a
filer event landed on a closed store, and the mount survived it only
because the previous commit demoted that error.

Give the follow a context the mount owns, and stop it — cancel, then
join — before metaCache.Shutdown() in both teardown paths. MetadataFollowOption
takes a ParentContext so cancelling the caller ends the stream, which is
the ordering the filer already got in #11363 and #11663; the mount had no
equivalent.

Verified that the new assertion catches the ordering on its own: making
stopMetadataFollow a no-op fails it with the subscriber still running,
even with the fatal path already demoted.

* mount,pb: make a cancelled follow a stop, and cover the new seams

Review findings on the previous commits:

Cancelling the follow context surfaced as a bare gRPC Canceled, which
matched neither terminal condition, so every clean unmount logged an
ERROR, ran the retry callback — which wipes every cached listing on the
assumption that events were missed — and slept a second before the loop
stopped itself. Test the context instead of the error text.

Also assert the two new weed/pb seams where they are defined rather than
only through a mount exit code: ErrStopFollowing ends the stream without
reaching the per-event error modes and leaves the cursor behind the
event, and a cancelled ParentContext ends the stream. Publishing the
cancel handle and bumping the WaitGroup happen under one lock, so a
start racing a stop cannot let the join report success too early.

All four new tests were mutation-checked: dropping the early return,
ignoring ParentContext, removing stopMetadataFollow from ClearCacheDir,
and making stopMetadataFollow a no-op each fail their own test.

---------

Co-authored-by: whitefox <whitefox@mayflower.work>
2026-11-28 16:04:59 -08:00
Chris LuandClaude Opus 5.5 889af96779 mount: store a truncate through an open handle before answering (#13089)
* mount: store a truncate through an open handle before answering

SetAttr with a new size and an open handle only marked the handle dirty,
so the size reached the filer at the next flush or release. A mount that
died before then brought the old size and data back, and an NFS export
answered SETATTR, which no COMMIT follows, with a size it had not stored.
Flush the handle once the entry locks are released, as a truncate
without a handle saves the entry. The writeback cache still defers it,
except under an NFS export.

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

* mount: test that a truncate through an open handle is stored

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

* mount: refuse a truncate up past the quota before the file grows

The size is now stored before SetAttr answers, so a growth the quota
cannot take was installed and charged, then refused by the flush,
leaving the grown size on the handle. Check the growth first.

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

* mount: compare a truncate's growth with the quota headroom

The used size, the uncommitted writes and the growth were summed in
int64, so a truncate up to near 2^63 wrapped the sum negative and passed
the check. Take the growth as uint64 and compare it with what is left.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 09:53:42 -08:00
a9fda6b50f filer clients: authenticate filer gRPC calls with per-call admin tokens (#13039)
* Add per-call filer authentication sources and pooled client wrappers

* Authenticate gateway filer calls with per-call admin tokens

* Authenticate shell admin and synchronization filer calls

* Authenticate workers MQ and remaining filer client paths

* Cache filer client signing keys and sign subscriptions with the shared key

Re-reading security.toml on every filer RPC cost about 125us against 8us for
signing. Keep the keys for up to a second, re-reading at once when a WEED_
override or the configuration directory changes. When the file exists but
cannot be read, keep the last keys read, else the startup keys, as
FilerAdminKeys does, so a process without a key stays tokenless. Metadata
subscriptions prefer the shared key, as filer peers do, because older filers
verify subscription admin tokens only with it.

* Authenticate admin-script, maintenance and filer.conf shell paths

Plugin worker admin scripts and master maintenance scripts build their own
shell options and carried no filer token source; fs.configure and
s3.bucket.quota.check read filer.conf without it.

* filer.cat: report a failed read; isolate key overrides in the admin-script test

filer.cat ignored the error from its filer call and exited successfully,
leaving a truncated -output file. Report the error and exit with failure.
The admin-script token test now clears the WEED_ signing-key overrides,
which take precedence over security.toml.

* security: refuse gRPC keys too short to sign; query engine uses client TLS

Under GODEBUG=fips140=only, hmac.New panics on keys under 14 bytes. The
startup check now covers jwt.filer_signing.grpc_key and grpc_previous_key,
and filer client token sources check the keys they read, so a reloaded or
per-endpoint security file with a short key is refused instead of
panicking when the next RPC signs.

The query engine's broker client dialed every master, filer and broker in
plaintext, so the admin token it now sends could cross the network in the
clear. It dials with the grpc.client TLS settings instead, and weed-sql
loads security.toml as weed-db does.

* security: per-endpoint admin tokens ignore WEED_ key overrides

FilerAdminTokenFromFile honored WEED_JWT_FILER_SIGNING_GRPC_KEY and
WEED_JWT_FILER_SIGNING_KEY. Those are process-wide, so filer.sync with
-a.security and -b.security signed both clusters' admin tokens with the
one key, handing each cluster a token valid on the other. A per-endpoint
file now supplies its own keys only.

* weed-sql, weed-db: refuse to start on an unreadable security.toml

Both only warned when security.toml was present but could not be read or
parsed. They then dialed without the grpc.client TLS settings while the
filer token source could still sign admin tokens from WEED_ environment
keys, so the tokens could travel in plaintext. They now exit with an
error that does not quote the file; a missing file is still fine.

* pb: take the filer token source in WithGrpcFilerClient and WithOneOfGrpcFilerClients

Fold WithGrpcFilerClientAuth and WithOneOfGrpcFilerClientsAuth into the
existing helpers instead of keeping two names for each. Callers without a
token source pass nil.

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

* util: return the read error from ReadConfiguration

Fold ReadConfigurationWithError into ReadConfiguration. The error is
returned and not logged, since parser errors can quote values; the
existing reload callers already warn when no file was read.

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

* security: keep the test-only filerAdminToken helper in the test

It had no production caller. The test helper now resolves keys through
filerClientKeysFrom, as the token sources do.

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

* util: read security.toml once in LoadSecurityConfigurationOrError

It validated the file, then merged it with a second read whose failure
was ignored and whose parser error was logged. It now merges with one
read and logs nothing from the parser. Viper's search also treats a
directory the process cannot search as holding no file; a candidate
that cannot be checked for lack of permission is now refused too.

* security: verify admin subscription tokens with the gRPC clock leeway

CheckGrpcMetadataSubscription checked admin tokens strictly, while unary
filer calls allow jwt.filer_signing.clock_leeway_seconds. With ten-second
client admin tokens, a subscriber whose clock trailed the filer's by more
than ten seconds was refused with a matching key. It now takes the leeway,
and the filer passes its configured one. The leeway check moves from the
server package to security.IsFilerAdminTokenWithLeeway so both use it.

* util: start without security.toml only when every candidate is confirmed absent

A candidate whose check fails for any reason other than not existing,
such as a symlink loop, is refused like one the process cannot search.

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 18:53:59 -08:00
c7fc40c76c filer, mount: read a manifest's chunks only within its span (#13048)
* filer, mount: read a manifest's chunks only within its span

Until #13042, a truncate through a manifest only shortened the manifest
chunk; the chunks it holds stayed whole. Reads resolve those chunks at
their own offsets and sizes, so once such a file grows over the cut again
without writing it, by an extending truncate or a write past the end, the
cut bytes come back where zeros belong. #13042 keeps new truncates from
leaving such manifests, but files a mount truncated between #12462 and
#13042 still have them.

Reproduced with weed mount on a local cluster: a mount from before #13042
appends 700 lines with one close() each, so the first 256 fold into a
manifest, and truncates the file to 100 lines; a mount from current master
then extends it past its old end with ftruncate. The extended range read
8,580 bytes of the cut lines instead of zeros, through that mount and
through the filer.

Reads now cut each manifest's chunks to the manifest's span:
ResolveChunkManifestForRead, used by NonOverlappingVisibleIntervals (filer
and S3 streaming, WebDAV, the mount's merge reads), the S3 ranged reads and
the mount's peer reads, and ChunkGroup for the mount's reads. A manifest
made by MaybeManifestize spans its chunks exactly, so only shortened ones
change. ResolveChunkManifest still returns the chunks whole: MinusChunks,
deletions and the other chunk-list comparisons need every chunk a manifest
references, or the chunks past the cut would never be deleted.

* sw-client: read a manifest's chunks only within its span

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

* java client: read a manifest's chunks only within its span

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

* filer: drop PR numbers from the manifest span comments

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

* filer: fold ResolveChunkManifestForRead into ResolveChunkManifest

ResolveChunkManifest takes cutToSpan: the read paths pass true, the
deletion and chunk-list comparison paths pass false.

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

* s3api: cut manifests to their span when flattening an object's chunks

A full-object SSE GET, CopyObject and UploadPartCopy flatten the
source's manifests into a plain chunk list, which drops each manifest's
span, so the chunks a truncate left past a shortened manifest came back
as object data.

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

* shell: purge a volume.fsck path only for chunks within a manifest's span

A chunk past a shortened manifest's span is still referenced but never
read, so a missing volume under it loses nothing. The purge decision now
uses the span-cut chunks while the inventory keeps every reference.

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

* shell: cut manifests to their span in fs.distribute_chunks

The entry is rewritten with the resolved chunks as a flat list or a new
manifest that spans them, so chunks past a shortened manifest's span
became readable again. The filer's update still deletes them, since it
compares against the old entry's uncut chunks.

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

* shell: verify only the chunks within a manifest's span in fs.verify

A chunk past a shortened manifest's span is never read, so a missing
needle under it failed the entry and, with -pruneEntries, deleted a file
whose readable bytes were intact.

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

* shell: mark the chunks past a manifest's span instead of allowing the visible ones

The purge gate now skips only the resolved chunks that the span cut drops,
so chunks that come from outside the manifests keep their purge behavior.

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

* shell: skip the purge for a missing past-span chunk on a listed volume

volume.fsck -findMissingChunksInFiler queued a path for deletion when a
listed volume's index lacked any chunk the uncut inventory recorded,
including a chunk past a shortened manifest's span that no read reaches.
Record those chunks per path during the filer walk and let only a missing
chunk within the span queue the purge. The path is still reported.

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 18:51:15 -08:00
Yip Leo 50ac729a71 filer: fold only runs of small chunks that lie end to end (#13041)
* filer: fold only runs of small chunks that lie end to end

#12462 folds every chunk under 1 MiB into manifests, 256 at a time in
list order. Two things go wrong when those chunks are not plain appends:

- A manifest's chunks are not compacted again. A small chunk that a
  later write covers stays stored and referenced after the write hid it.
- weed mount's bloat check sums chunk sizes and counts a manifest by its
  span. A manifest over chunks that are not next to each other spans
  bytes other chunks hold, so the file looks bloated and the flush reads
  it back and stores it again, whole.

With weed mount on a local cluster, a writer that appends 300-byte
records and rewrites a 4 KiB header at the front after each one (open,
two pwrites, close): after 766 records the mount logged "2.0x chunk
bloat detected ... (2 chunks, 475684 stored vs 233896 content),
merging" and rewrote the file, and did it again at 2.5x (1164184 stored
vs 463396 content); 1,600 records cost two whole-file rewrites. Each
rewrite reads and stores the whole file, and the next one comes a few
hundred flushes later. Random small writes fold their overwritten pages
the same way.

Only small chunks that no other chunk overlaps now fold, and only in
runs that lie end to end, so a manifest spans exactly the bytes it
holds. Appends make such runs and fold as before. Chunks between
full-size ones, chunks that overlap others and chunks with a hole
between them stay flat, as they did before #12462. What is left of a
run stays flat until the run grows.

* filer: size the small-chunk fold's result by its input

CodeQL alert 446 (go/allocation-size-overflow) flagged the capacity
len(inputChunks)-len(folded)+len(manifests). It cannot overflow, but the
input's length bounds the result anyway: each manifest takes the place of
SmallChunkManifestBatch chunks.
2026-11-27 18:49:20 -08:00
Chris LuandClaude Opus 5.5 2e81c0b7c0 filer: route a rename whose source misses locally to the write owner (#13064)
* filer.proto: mark a forwarded StreamRenameEntry with is_moved

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

* filer: send a rename whose source misses locally to the write owner

Exclusive and conditional creates are stored on the path's write owner. With
separate filer stores, a rename sent to another filer before it has replayed
the create found no source and failed, so a mount that flushed a deferred
create and renamed the file right after got EIO. Such a rename now goes to
the source's write owner, which moves the entry and whose events are relayed
to the caller, unless the owner runs on this filer's store. A forwarded
rename is applied only by the filer its own ring names as the owner.

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

* filer: send an AtomicRenameEntry whose source misses locally to the write owner

The same race reaches the unary rename that S3, WebDAV, SFTP and fs.mv use:
an object or file created through the owner and renamed through another
filer before replication found no source. It is forwarded like the stream
rename, with is_moved bounding it to one hop.

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

* rename: report a missing source as ENOENT

A rename whose source is absent fails with the store's "no entry is found"
error, which neither the filer's errno mapping nor the mount's message
mapping recognized, so the client got EIO instead of ENOENT.

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

* filer.proto: report a forwarded AtomicRenameEntry's last event position

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

* filer: answer a forwarded rename once the owner's events are replayed here

The rename's target is stored on the owner only until this filer replays
it, so an unlink of that name sent here right after the rename would miss
it and report success. The owner now reports the log position of the
rename's last event, and the forwarding filer holds its answer (bounded)
until its stream from the owner has delivered that far.

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

* filer: refuse a forwarded no-replace rename over a target this filer has

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

* filer: wait for an owner this filer no longer follows before answering a forwarded rename

PeersCaughtUpTo counts an untracked peer as caught up. An owner whose
stream was down long enough to be dropped has replayed nothing here, so a
forwarded rename answered then could leave a follow-up unlink through this
filer missing the target. Require the owner to be tracked with a watermark
at or past the rename, still bounded by ownerEventsCatchUpCap.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 17:54:48 -08:00
397a156104 security: a fips.mode setting that Go checks against GODEBUG and the Rust binaries apply to TLS (#13029)
* util: refuse to start when fips.mode in security.toml disagrees with GODEBUG

security.toml gains [fips] mode = "off" | "on" | "strict", also settable
as WEED_FIPS_MODE: one setting that states the FIPS 140-3 mode of every
process in a deployment, so the Rust binaries, which do not run on the Go
runtime, can follow it. Go processes keep taking their behaviour from
GODEBUG=fips140 and now check it against the setting:
LoadSecurityConfiguration and `weed worker` exit when "off" runs without
fips140=off, "on" without fips140=on, or "strict" without fips140=only,
naming the setting and the GODEBUG value it needs. An unknown value is
refused; unset or empty changes nothing.

Refs #12839

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

* rust: fips.mode with FIPS-mode TLS in weed-volume, weed-worker and weed-vector

seaweed-common gains a fips module: FipsMode resolved from fips.mode in
the security.toml a binary uses, with WEED_FIPS_MODE over it. Each binary
resolves it once at startup, logs it and installs the matching rustls
provider as the process default, refusing to start on an unknown value or
when another provider was installed first.

Under "on" and "strict" the provider is aws-lc-rs filtered to the lists
Go's crypto/tls applies in FIPS mode: TLS 1.3 AES-GCM suites and TLS 1.2
ECDHE AES-GCM suites (no ChaCha20-Poly1305), X25519MLKEM768,
SecP256r1MLKEM768, P-256 and P-384 (no plain X25519), Go's ten signature
schemes (no ML-DSA). Configurations SeaweedFS builds require the Extended
Master Secret in that mode, and the volume server refuses a non-FIPS suite
in tls.cipher_suites instead of falling back. sw-client installs the same
provider instead of ring. Unset or "off" keeps aws-lc-rs's default
provider unchanged.

This is behavioural parity only: the provider still runs on the
non-validated aws-lc-rs build.

Refs #12839

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

* util: refuse a fips.mode that is not a string

viper's GetString turns an array or a table into "", so mode = ["strict"]
under [fips] skipped the GODEBUG check while the Rust binaries refused the
same file. RequireFipsMode now reads the raw value (ViperProxy.Get, under
its lock) and exits when it is not a string, naming its source; an absent
or empty value still means unset, and WEED_FIPS_MODE still wins.

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

* rust: read fips.mode with the parser that reads the JWT keys

seaweed_common::fips::resolve parsed security.toml with the toml crate,
while the volume server reads the rest of the file with its own lenient
loader. A file with [fips] mode = "on" beside an unquoted value the loader
accepts resolved to off and logged "fips.mode unset", although the JWT
keys from the same file were applied. Each binary now reads fips.mode
with the loader it uses for everything else and hands the value to
resolve: the volume server through its line parser, the worker and vector
engine through their parsed Security table, which already refuses a file
that is not TOML. A security.toml the volume server finds but cannot read
stops startup. A missing setting is still off, and WEED_FIPS_MODE still
wins. seaweed-common no longer depends on toml.

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

* sw-client: offer only FIPS signature schemes with insecure_skip_verify

With https.client.insecure_skip_verify, reqwest installs its own verifier,
which advertises a fixed scheme list including SHA-1 and Ed448 whatever
the process provider allows. In FIPS mode the volume transport now builds
its rustls configuration itself on the process provider: the server
certificate and host name are not checked, as the setting asks, but
handshake signatures are verified with the provider's algorithms, only its
schemes are offered, and TLS 1.2 requires the Extended Master Secret.
Outside FIPS mode the reqwest path is unchanged.

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

* seaweed-common: sign only with Go 1.27's FIPS schemes, allow ML-DSA

The FIPS provider kept aws-lc-rs's key provider, so a FIPS-mode listener
signed handshakes with whatever scheme its key and the peer agreed on,
outside the list the provider verifies with. Keys now load through a
provider that limits each key to the FIPS signature schemes and refuses a
key that can sign none of them, such as Ed448; the volume server and the
worker's gRPC TLS name the certificate and key files in that error.

The lists follow Go 1.27.4, which go.mod now requires: its
defaults_fips140.go allows ML-DSA-44, -65 and -87 as signature schemes and
ML-DSA certificate keys (for Go's native module only), so they are allowed
here as well. Go also allows MLKEM1024 but does not enable it by default,
so it stays out of the key exchange list as in Go's defaults. "off" keeps
the default key provider.

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

* mount: skip the truncate manifest test on freebsd like its fake filer

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
2026-11-27 12:47:44 -08:00
Yip Leo eb655f46ba mount: merge a flush's folded chunks as the chunks, not as a new manifest (#13043)
* mount: merge a flush's folded chunks as the chunks, not as a new manifest

A flush folds the handle's chunks into manifests before it commits, and
installs the folded list in the handle. When the commit finds that a
peer changed the entry, mergeContentEntry replays the handle's changes
since its base onto the peer's entry: a chunk not in the base counts as
the handle's own write, a base chunk missing from the handle as one it
dropped. A manifest the flush just made of base chunks therefore goes in
as a write of the handle's, with every chunk it holds:

- after a peer rewrote the whole file (a bloat merge, stamped with the
  oldest data it holds) or dropped chunks, the manifest brings the old
  chunks back, and where their stamps are newer they hide the peer's
  bytes;
- after a peer folded the same chunks, the entry holds both manifests.

Since #12462 a flush folds every 256 small chunks, so two mounts that
append to one file, as the ranks of a training job often do with its
log, reach this.

The flush now records what its fold packed (chunkFold). The merge sees
the folded chunks instead of the new manifests, so the fold is no change
at all; the merged entry goes out unfolded, and the next flush folds it
again. When the commit fails, the fold is taken back out of the handle,
whose base still has the chunks, so a later merge or flush does not take
the manifests for writes either. Their blobs are left unreferenced, as a
failed fold leaves them.

* mount: rebase a merged flush onto the entry the filer stored

Review follow-up. A merged commit sends the merged chunks unfolded, and the
filer can fold them before it stores the entry (cleanupChunks). The flush
installed the request in the handle, but took the stored entry as the
handle's base (ackedBase), so the handle held flat chunks against a base
that lists a manifest. A later merge, such as a peer's truncate reaching the
dirty handle, would take those chunks for writes of the handle's and
publish them again.

The handle is now rebased onto the stored entry it takes as its base, in
both flush paths. rebaseEntry still gets the request, so chunks attached
after it was taken are kept.

TestFlushMergeInstallsTheEntryTheFilerStored: a peer's chmod refuses the
first commit, the merged retry sends 256 flat chunks, and a filer that folds
them stores a manifest; the handle and its base must both hold the stored
entry. It fails with the request installed.
2026-11-26 22:48:58 -08:00
424c67ad06 mount: truncate a manifest the cut goes through as the chunks it holds (#13042)
* mount: truncate a manifest the cut goes through as the chunks it holds

Truncating a file shortens every chunk the new size cuts through, a
manifest chunk included. A manifest's span only says where its chunks
lie: reads resolve the chunks inside it at their own offsets and sizes,
so the bytes past the cut stay readable. Once the file grows over them
again without writing them, by an extending truncate or a write past the
end, they come back where zeros belong.

Reproduced with weed mount on a local cluster: 700 lines appended with
one close() each, so the small-chunk fold put the first 256 into a
manifest; then a truncate to the first 100 lines and an ftruncate past
the old end. The extended range read 8,580 bytes of the cut lines
instead of zeros, through both mounts of the file. Since #12462 any file
grown by a few hundred small appends has manifests; before it, only
files of 10,000 chunks did.

A truncate now opens each manifest the cut goes through, nested ones
too, and cuts the chunks it holds. The manifest leaves the entry, and
the filer deletes it with the chunks past the cut when the entry is
stored. A manifest shortened by an earlier truncate first gives up the
chunks past its own span. If a manifest cannot be read, the truncate
fails with EIO and the file is left as it was.

* mount: keep a truncate's expanded chunks from merges, read its manifests with a token

Review follow-ups:

- The chunks a truncate takes out of a manifest are not in the handle's
  base, which lists the manifest. A merge onto a peer's entry took them for
  writes of the handle's, so after a peer cut the file shorter and the filer
  queued the rest for deletion, the handle could publish references to
  those chunks again; the gap check passed because plain chunks covered the
  range. Before the expansion, the manifest across the cut refused that
  merge. A truncate that expands a manifest now marks the handle as having
  rewritten its chunks, so the merge is refused when the peer changed
  chunks, at the next flush and when the peer's event reaches the handle.
- A truncate by path, with no open handle, read the manifest before its file
  id was registered for a filer-issued read token, so a mount reading with
  -volumeReadAuth sent the read without one and the truncate failed with
  EIO. The entry's chunks are registered under its path first.
- All manifest reads of one truncate share one one-minute deadline, instead
  of a minute each.

TestTruncateThroughManifestCutsItsChunks runs SetAttr with and without an
open handle: it fails without the registration (no handle) and without the
rewrite mark (open handle). TestMergeRefusesTruncateExpansionOverPeerTruncate
shows the merge that published a peer-dropped chunk, and its refusal.

* mount: answer a truncate interrupted while reading a manifest with EINTR

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 22:47:52 -08:00
Chris LuandClaude Opus 5.5 d0661afad8 mount: refuse SSE-KMS and SSE-C objects the native read path cannot decrypt (#13027)
* mount: refuse SSE-KMS and SSE-C objects the native read path cannot decrypt

The native read check only recognized SSE-S3, so objects the S3 gateway
stored with SSE-KMS or SSE-C were read chunk by chunk and the mount
returned their ciphertext with success. Detect every S3 server-side
encryption type, from the object metadata or any chunk, and answer
open, read and copy_file_range with ENOTSUP unless the object is SSE-S3
and -sseS3Read routes it through a gateway.

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

* mount: drop S3 encryption markers when a file is truncated to zero

A full truncate removes the encrypted payload, but the object metadata
still named SSE-C, SSE-KMS or SSE-S3, so the plaintext the mount wrote
afterwards was refused on read. Clear those markers in SetAttr and
truncateEntry when the size becomes zero, and reset the handle's cached
classification.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-26 08:41:20 -08:00
a1764358cf filer, mount: keep a hard-linked file to one link id and count its names on the filer (#13006)
* filer, mount: keep a hard-linked file to one link id and count its names on the filer

A hard link's bookkeeping was done by the client. To link a file a mount
reads its entry and sends two writes, an update of the source and a create
of the new name, both with a link id and a count of the file's names. Two
clients that link one file at the same moment each worked from the entry
as it was before the other's writes:

- With no link id on the entry yet, each made one up. The second update
  moved the source to its id, the store took the name off the first, and
  the first client's new name was left alone on it: one file's chunks
  under two link ids.
- With a link id there, both read the same count and sent it plus one.
  The record counted one name fewer than the file had. Any write through
  a name carried the client's copy of the count and replaced the record
  the same way.

Either way the delete of the last counted name deleted the record and the
chunks while another name still read them.

The filer's own store now counts the names of a hard-linked file itself
(countLink): one more when the name written did not hold the link before,
the same when it did or when a rename moves it there (WithMovedLink), one
for a record that starts. The count sent is not used, and the entry gets
the count stored, so the response and the event carry it. The lookup of
the name, the count, the record and the name are stored as one change of
the record (changeLinkRecord), which DeleteHardLink goes through as well:
under a lock per link id, and in a transaction where the store refuses a
commit over a change made since it began, run again when it does. A
wrapper around a copy of some entries, such as a mount's metadata cache,
sees only some of the names and stores the count it is given.

UpdateEntry refuses to give a name that holds a hard link another link id
that no file has yet (refuseSecondHardLink). The mount sends a file's
first link's update as a unary RPC, which keeps that refusal apart from
an I/O failure, reads the entry again and links under the id the file has
by now.

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

* filer: take a replicated update's link id without refusing it

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

* filer: look a path-specific name up outside the record's transaction

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

* filer: check the leveldb open and close it in the hard link test

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

* mount: send a refused first link again from the entry as stored

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

* mount: keep a first link's refusal over the next filer's error

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

* filer: count a hard link's names next to the clients' count instead of in its place

The filer's count replaced the one clients send, which lost two things
that count did by being worked out ahead:

- A link's first write, the update of the source, carries the count with
  the new name in it already. While the second write is on its way that
  kept a delete of the source from being taken for the delete of the
  file's last name (lastLinkDropped goes by the count it read), and the
  chunks from being deleted under the name about to come. Counted only
  when it arrived, the new name was stored with chunks that were gone:
  104 of 300 rounds of a mount linking a file while another deletes it.
- A write of a name the store refused had counted the name already, and
  sent again counted it once more.

The filer now keeps its count of the names in a key of its own next to
the record (linkNames), written once the name is stored, and the record
gets whichever is higher: the count the client sent or the names counted.
It is never lower than what the client alone would have left, and never
lower than the names the file has. A record from before has its count
recorded as the names when it is first written again.

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

* mount: send a refused first link again with the file's inline content

The second attempt builds the new name's create from the entry as the
filer has it by now: attributes, chunks and extended attributes. A file
the filer keeps inside its entry has its bytes in Content, and the create
is what the filer writes the link's shared record from, so without them
the record lost the file's content.

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

* filer: store a path-specific name before the record's lock is let go

A second create of the same new name on this filer took the lock between
the first one's count and its name write, missed the name, and counted it
again: the file's record and chunks then outlived its last name.

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

* filer: keep a link's names key out of the keys of a directory's entries

The key began with the link's random id. One that began as the root's
entry keys do in a store keyed by path put the names' 4 bytes in the
root's listing, and it failed to decode: listing / and the etcd scan
under fsck failed.

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

* filer: record a hard link's name before it is stored, and take it off if it is not

The names counted for a hard link were recorded once the name was stored.
On a store without transactions a failure of that write left the name
stored and not counted, and the write sent again found the name there and
did not count it either: the names recorded stayed one below the names
stored, the side a file is deleted under a name from.

They are recorded first now, inside the change of the record that counted
them, and a name the store then does not take is counted off again
(storeCountedName). A failure halfway leaves them one above the names
stored, and the file leaked. A name in a path-specific store is recorded
with the record as well, and counted off in a change of its own.

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

* filer: keep a hard link's name counted when a failed write stored it

A write whose deadline passes after the store took the name returns an
error, and counting the name off then left the names one below the names
stored. A later write with the count from before the link lowered the
record to them, and the file was deleted under a name it still had. Read
the name back first, and keep it counted where that cannot be told.

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

* mount: carry the stored RemoteEntry into the name a retried first link adds

The retry rebuilds the new name from the entry the file has once another
client linked it, but kept the RemoteEntry of the entry first read.

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

---------

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>
2026-11-25 17:54:56 -08:00
5e796fa985 mount: keep a file's inline content when it is written to or resized (#13009)
* mount: keep a file's inline content when it is written to or resized

A small file the filer keeps inside its entry (-saveToFilerLimit, or
?saveInside=true on the upload) has its bytes in the entry's content and
no chunks. A mount dropped the content at the first write to the file, or
copy into it, and published the write's chunk alone: the bytes the write
did not cover read as zeros from then on, for an append as for two bytes
in the middle. A change of size left the content as it was. Grown, the
file read no further than its content on the mount and as zeros through
the filer; cut and grown again, it had the bytes that were cut off back.

The content now becomes a write of the handle's own, older than the one
about to change the file, and is flushed with it as a chunk
(bufferInlineContent: Write, CopyFileRange, Fallocate). SetAttr cuts it to
a smaller size, and stores it as a chunk before the file grows past it
(resizeInlineContent).

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

* mount: store resized inline content in chunks of the mount's chunk size

A file that grows past its inline content had the content stored as one
chunk, whatever its length, where a buffered write is split at the
mount's chunk size: content longer than a volume server takes in one
upload could not be stored, and the file could not grow.

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

---------

Co-authored-by: MapleWhiteZZZ <18653045+MapleWhiteZZZ@users.noreply.github.com>
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-25 17:29:28 -08:00
bd1f24a09b mount: carry a file's inline content into the name a hard link adds (#13008)
* mount: carry a file's inline content into the name a hard link adds

A small file the filer keeps inside its entry (-saveToFilerLimit, or
?saveInside=true on the upload) has content and no chunks. To link it a
mount updates the source and creates the new name, and the filer writes
the link's shared record from each of the two. The create carried the
source's attributes, chunks and extended attributes but not its content,
so the record was left with a size and nothing behind it: both names read
zeros from then on, through the mounts and through the filer.

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

* mount: carry a remote-only file's RemoteEntry into the name a hard link adds

A file under a remote mount that is not cached yet has no chunks and no
content; its RemoteEntry is what sends a read to fetch the object. The
create of the new name left it out, so the hard link's shared record lost
it and both names read zeros.

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

* mount: cache a remote-only file before a hard link gives it a new name

The filer resolves a remote object from the name a read goes through, and
the new name has no object of its own, so a read through it failed until
the source name had been read. The link now has the filer cache the
object first, so every name shares its local chunks.

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

* mount: cache a linked remote-only file through its open handle

The cache moved the stored entry off the base of a handle open on the
source, so the handle refused the link change and its next flush failed.
A handle with buffered writes now publishes them first, and the cache
goes through the handle as a read does, which moves its base along.

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

---------

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>
2026-11-25 17:28:56 -08:00
Chris LuandClaude Opus 5.5 7638cf2f66 mount: keep the data past a sparse file's first hole when merging chunks (#12978)
* mount: merge each run of a sparse file's data, not just the run before its first hole

The chunk stream reader ends at a hole, so the merge stopped there and
replaced every chunk with ones covering only the data before the first
hole. Read and save each contiguous run of visible data on its own, and
leave the holes between runs unwritten.

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

* filer: skip the small-chunk merge for a sparse file

The merge reads the chunks through the stream reader to its end, which
stops at a hole, and keeps only the chunks before its start offset, so
an append to a sparse file lost the data past the first hole after it.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 13:07:45 -08:00
Chris LuandClaude Opus 5.5 dbc64144ca mount: support NFS re-export file handles after inode eviction (-nfsExport) (#12979)
* mount: update go-fuse for the export support option

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

* mount: optionally retain the paths of forgotten inodes

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

* mount: answer lookups of "." and ".." for file handle decoding

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

* mount: add -nfsExport to negotiate export support and retain forgotten inodes

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

* mount: test file handle lookups of "." and ".."

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

* mount: fail a file handle lookup when its path now holds another file

A "." lookup resolved a forgotten inode by its remembered path, so a
file created at that path since was served to the old handle. Compare
the entry's inode with the handle's and answer ESTALE on a mismatch.

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

* mount: register a file handle's inode under the table lock

A "." lookup checked the file at the remembered path and then registered
it with Lookup, which hands back whatever inode holds the path by then.
LookupHandle takes the reference on the handle's own inode, or enters it
at the path only while no other inode holds it.

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

* mount: keep a forgotten inode's retained path across a rename

A rename whose source inode the kernel had already forgotten left the
retained path at the old name, so its file handle failed with ESTALE.
An index from retained path to inode lets MovePath move it.

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

* mount: register a file handle only at its current retained path

A rename between resolving a forgotten inode's path and registering it
moved the retained entry, yet LookupHandle still entered the old path.
It now compares the path with the retained one under the table lock.

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

* mount: drop the target a forgotten inode is renamed over

Moving a forgotten inode's retained path onto a live name left the
replaced inode mapped there. Once a retained entry moves, the target is
taken apart as for a live source and reported as replaced.

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

* mount: test that a renamed path-inode file fails its file handle closed

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

* go.mod: use the go-fuse v2.9.5 release

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 12:58:56 -08:00
Chris LuandClaude Opus 5.5 d95f5e67fb mount: refuse an exclusive create of a name another mount holds (#12966)
* mount: create at the filer only where no entry is stored

A create sent to the filer at open time (mknod, and every create under
EagerFilerCreate) went without OExcl, so the filer stored it as an update
of a file another mount had created there: open without O_EXCL emptied
that file and mknod replaced it. Send OExcl, report EEXIST, and drop the
cached listing so the reopen finds the stored entry.

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

* mount: store an exclusive create at open

A create is deferred to the first flush and checks only this mount's
view, so two mounts could both open the same new name with
O_CREAT|O_EXCL. Send an exclusive create to the filer at open instead,
where OExcl refuses the name another mount already stored. Writeback
keeps deferring: it assumes one writer.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 12:50:12 -08:00
Chris LuandClaude Opus 5.5 fe816eaac8 mount, filer: stamp merged and manifest chunks instead of leaving them at 0 (#12962)
* filer: stamp a manifest chunk with the newest chunk it folds

mergeIntoManifest saved the manifest with tsNs 0, so manifest chunks
carried no modification time. Give it the newest ModifiedTsNs of the
chunks it holds.

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

* mount: stamp merged chunks with the newest chunk they replace

maybeMergeChunks uploaded the rewritten chunks with tsNs 0, so any
older chunk that overlaps them later, like a covered chunk sent with the
commit, outranked the merge. Give them the newest ModifiedTsNs of the
chunks they replace.

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

* mount: stamp a merged chunk with the oldest data it holds

The newest stamp of the whole merge outranked a peer's pending write
that is newer than the bytes the merge carries for its range but older
than the newest of them. Stamp each merged chunk with the oldest visible
data in its range, or 0 over a hole, so such a write still shows while
chunks older than all of its data lose to it.

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

* mount: find a merged chunk's range by binary search

Each uploaded chunk scanned the visible intervals from the front.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 15:53:32 -08:00
07e1299f98 mount: add -idmap to allow ID-mapped bind mounts (#12922)
* mount: add -idmap to allow ID-mapped bind mounts

FUSE allows ID-mapped mounts only for a server that announces FUSE_ALLOW_IDMAP.
Once announced, the kernel sends uid and gid 0xFFFFFFFF on most requests after checking permissions itself, so the checks that read the caller treat that value as already checked.

* fuse: refuse an unsupported -o idmap before starting the child

The child exits on checkIdmap, but the parent waits for its readiness signal
and never returns, so weed fuse -o idmap hung on macOS and FreeBSD.

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

* mount: refuse -idmap on Windows instead of ignoring it

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

* fuse: take -o defaultPermissions as the mount flag

-o defaultPermissions=false was forwarded to the kernel as an unknown
option, which failed the mount, and left the flag at true, so
-o idmap,defaultPermissions=false passed the idmap check.

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 15:25:34 -08:00
Chris LuandClaude Opus 5.5 5f97a9d088 mount: keep an unpublished create's writes, unpublished, when a peer renames onto its name (#12960)
* mount: publish an unpublished create's writeback drain after a peer rename onto its name

With -writebackCache, the drain flushes metadata only while the saved path
still maps to the handle's inode. Another mount renaming its file onto the
name of a file this mount created and has not published moves that path to
the peer's inode, so the drain skipped the flush and dropped the writes
without an error or a failed-metadata record.

A local rename or unlink of a draining handle waits for the drain or marks
it, so for an unpublished create a lost mapping means another mount's file
took the name. Skip the guard for it: the create-if-not-exists commit then
keeps a recovery record when the name is taken and publishes when it is free.

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

* test(fuse_dlm): accept only EEXIST on O_EXCL as an early second-create refusal

The concurrent create test returned early on any error from the second open,
so an EIO, or an open failure in the O_TRUNC case, passed without writing
either payload.

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

* mount: refuse publishing an unpublished create after a peer renames onto its name

Another mount's rename onto the name of a file this mount created but has
not published takes that name. The create used to publish there later with
create-if-not-exists as soon as the name was free again: after a local unlink
of what the name showed, it reappeared, and after a move of its directory it
landed under a path no longer reachable. markHandleReplaced now records that
the name was taken, and the publication check refuses the handle from then
on: a writeback drain keeps a recovery record and default mode fails close.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 14:09:19 -08:00
Chris LuandClaude Opus 5.5 dbbf2907a6 webdav: refuse to delete, move or overwrite entries under Object Lock or WORM (#12959)
* webdav: refuse to delete entries under Object Lock or WORM

DELETE removed versions under legal hold or retention and WORM files that
the S3 API and the filer HTTP API refuse to delete. Check the entry, and
for a collection everything below it, then pin the delete to the Object
Lock state that was checked.

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

* webdav: refuse to move entries under Object Lock or WORM

MOVE could rename a locked version or WORM file away, move a directory
holding them, or replace a protected target. Check the source, a source
directory's contents and the target before the rename.

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

* webdav: refuse to overwrite entries under Object Lock or WORM

PUT and COPY replaced a locked or WORM file with a fresh entry, dropping
its content and its lock. Check an existing file before creating over it.

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

* webdav: pin an upload's final update to the Object Lock state it read

An upload writes the whole entry back when it closes. A hold or retention
set on the new object while the upload was buffering would be dropped, so
the filer now refuses the update if that state changed.

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

* webdav: recheck an upload's target when it commits instead of pinning it

The precondition on the final update sent it to the path's write owner,
while the placeholder create stayed on the connected filer. With
separate filer stores the owner could miss the placeholder and refuse
the update, leaving an empty file. The upload now rechecks the target
right before the update, as the SFTP upload does, and the update stays
local.

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

* filer: share the WORM retention and subtree checks

FilerConf.WormEnforced and IntersectsWorm replace the copies in the filer
server and mount; ReadFilerConfFromClient reads filer.conf over a filer client.

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

* sftp, webdav: use the shared Object Lock and WORM helpers

Both servers now call FilerConf.WormEnforced, IntersectsWorm,
ReadFilerConfFromClient and s3_objectlock.ObjectLockState instead of
keeping their own copies.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 14:08:06 -08:00
Chris LuandClaude Opus 5.5 488bdafbbb mount: decide chown's set-id clearing by the caller, keep it on directories (#12955)
* mount: decide chown's set-id clearing by the caller, keep it on directories

SetAttr read input.Uid as the caller, but in SetAttrIn that field is the new
owner; the caller is input.Caller.Uid. Root giving a file away cleared its
SUID/SGID bits, a user giving a file to root kept them, and every chown to a
non-root owner cleared the SGID bit of a directory, which Linux keeps so new
entries go on inheriting the group.

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

* mount: let Linux decide chown's set-id clearing

The mount does not handle killpriv, so Linux sends the cleared mode with a
chown that must drop the set-id bits. Clearing them again by caller dropped
the SGID bit Linux keeps on a file without group execute when a user changes
only its group. Other systems keep the caller rule.

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

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 12:36:05 -08:00
Dean Chen ae60559da9 mount: keep the furthest dirty stop when a read spans chunks (#12957)
PageWriter.ReadDirtyDataAt walks the requested range one chunk at a
time but overwrote maxStop with each chunk's result. When an earlier
chunk had dirty data and a later chunk in the same read was clean, the
clean chunk's 0 replaced the earlier stop, so the caller under-reported
how much of the buffer the dirty pages filled.

Take the maximum across chunks instead.

Fixes #12946
2026-11-24 12:34:58 -08:00
Yip Leo da9518718f mount: keep an unpublished create's writes when another mount takes its name (#12943)
A file created on a mount is published to the filer at flush; until then its
handle is dirty and has no base. When another mount creates the same name and
its event arrives first, invalidateOpenFileHandle skips the branch that keeps
a dirty handle's writes, because that branch needs a base. It falls through,
destroys the handle's dirty pages and installs the other mount's entry as the
base. The flush then has nothing to publish, and close() returns 0 although
the writes are gone. A delete or rename of the name by another mount marks the
handle deleted or moves it, with the same result, and a rename onto the name
has onEntryInvalidation mark it deleted.

The filer holds nothing of such a file, so an event at its name is about
another file. Leave the handle alone. Its create-if-not-exists commit then
reports a taken name as a conflict (close() fails with EIO, or with
-writebackCache the request is kept in failed-metadata), and publishes as
usual when the name is free.

Part of #12941.
2026-11-24 12:33:10 -08:00
caeadb2db2 mount: refuse RENAME_EXCHANGE instead of renaming over the target (#12921)
* mount: refuse RENAME_EXCHANGE instead of renaming over the target

renameat2(a, b, RENAME_EXCHANGE) asks for the two names to be swapped
atomically. Rename let the flag through and went on as a plain rename, so
a was moved over b, b's content was gone, and the call reported success.

The filer's rename moves one entry and cannot swap two, so the mount now
answers EINVAL, which is what renameat2(2) returns for a flag the file
system does not support, and callers fall back on it.

RenameWhiteout was 3, which is RENAME_NOREPLACE|RENAME_EXCHANGE; the flag
is 1<<2. Both values, and any other flag the mount does not implement,
now get the same EINVAL (3 answered ENOTSUP, 4 already EINVAL).

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

* mount: trim the rename flag comments

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

---------

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>
2026-11-24 12:24:39 -08:00
Chris LuandClaude Opus 5.5 93e7a81b01 mount: refuse names that are not valid UTF-8 instead of rewriting them (#12952)
The mount replaced every invalid UTF-8 run in a name with "_" so the name
could go into proto string fields. That mapped different names to one entry:
two legacy-encoded names shared one file, a write or unlink through an
invalid name hit an existing file with "_" in its place, and O_EXCL failed
with EEXIST for a name that did not exist.

Making such a name (create, mknod, mkdir, symlink, link, rename target) now
fails with EILSEQ, and looking one up or removing it answers ENOENT, before
anything is sent to the filer. Entries stored earlier under a rewritten name
stay reachable by that name.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 10:40:58 -08:00
9fc8a6aec2 mount: read SSE-S3 objects through the S3 gateway (#12909)
* mount: read SSE-S3 objects through an authenticated S3 gateway

* mount: check each comma-joined mount option against -sseS3ReadEndpoint

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

* mount: read a mounted version file by its object key and version id

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

* mount: read a current null-version object without s3:GetObjectVersion

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

* mount: declare -sseS3ReadEndpoint with the other mount options so weed fuse accepts it

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

* mount: require the canonical bucket path as the root of an SSE-S3 read mount

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

* mount: fall back to the null version when the current object is another version

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

* master: list the S3 endpoint each S3 gateway advertises

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

* s3: advertise the gateway's S3 endpoint to the master

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

* mount: find the S3 gateway through the masters instead of -sseS3ReadEndpoint

-sseS3Read turns gateway reads on. The reader lists the S3 endpoints the
filer's masters have registered, prefers HTTPS, and picks another gateway
when the current one cannot be reached.

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

* mount: retry an unreachable S3 gateway read on a different gateway

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

* mount: warn when -sseS3Read falls back to a plain-HTTP gateway

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

* mount: do not retry an unreachable HTTPS gateway over plain HTTP

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

* mount: tell HTTPS gateways apart by the parsed URL scheme

An S3 gateway advertised as HTTPS://host lost the HTTPS preference and
the plain-HTTP fallback guard, since the check matched the raw string.

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

---------

Co-authored-by: Chris Lu <chrislusf@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 10:32:18 -08:00