Files
seaweedfs/weed/mount/weedfs_file_fallocate.go
T
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

80 lines
2.4 KiB
Go

package mount
import (
"syscall"
"time"
"github.com/seaweedfs/go-fuse/v2/fuse"
"github.com/seaweedfs/seaweedfs/weed/filer"
"github.com/seaweedfs/seaweedfs/weed/glog"
"github.com/seaweedfs/seaweedfs/weed/util"
)
// See https://man7.org/linux/man-pages/man2/fallocate.2.html
const FALLOC_FL_KEEP_SIZE uint32 = 0x01
// Fallocate allocates space for an open file. Volume space is assigned when a
// write is flushed, so nothing can be reserved up front; only a range past the
// end of the file has an effect, growing it the way a truncate would.
func (wfs *WFS) Fallocate(cancel <-chan struct{}, in *fuse.FallocateIn) (code fuse.Status) {
// ENOSYS makes the kernel stop sending FUSE_FALLOCATE for every mode, so a
// mode we cannot honor has to be refused on its own.
if in.Mode&^FALLOC_FL_KEEP_SIZE != 0 {
return fuse.ENOTSUP
}
fh := wfs.GetHandle(FileHandleId(in.Fh))
if fh == nil {
return fuse.EBADF
}
fhActiveLock := fh.wfs.fhLockTable.AcquireLock("Fallocate", fh.fh, util.ExclusiveLock)
defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)
entry := fh.GetEntry().GetEntry()
if entry == nil {
return fuse.ENOENT
}
oldFileSize := filer.FileSize(entry)
newFileSize := in.Offset + in.Length
if in.Mode&FALLOC_FL_KEEP_SIZE != 0 || newFileSize <= oldFileSize {
return fuse.OK
}
if wfs.IsOverQuotaWithUncommitted() {
return fuse.Status(syscall.ENOSPC)
}
if wormEnforced, _ := wfs.wormEnforcedForEntry(fh.FullPath(), entry); wormEnforced {
return fuse.EPERM
}
glog.V(4).Infof("Fallocate %s fh %d grow to %d", fh.FullPath(), fh.fh, newFileSize)
// Content inside the entry reads no further than itself: it becomes a
// write of the handle's, before the file grows past it.
now := time.Now()
if err := fh.bufferInlineContent(entry, now.UnixNano()); err != nil {
glog.Errorf("%v", err)
return writeErrorToFuseStatus(err)
}
entry.Attributes.FileSize = newFileSize
entry.Attributes.Md5 = nil
// The writes that fill the range will not grow the file, so they charge
// nothing; the growth is counted here or the quota never sees it.
wfs.AddUncommittedBytes(int64(newFileSize - oldFileSize))
entry.Attributes.Mtime = now.Unix()
entry.Attributes.MtimeNs = int32(now.Nanosecond())
entry.Attributes.Ctime = now.Unix()
entry.Attributes.CtimeNs = int32(now.Nanosecond())
fh.dirtyMetadata = true
wfs.invalidateOpenMtimeCache(in.NodeId)
return fuse.OK
}