fix: improve mount quota enforcement to prevent overflow (#7804)
* fix: improve mount quota enforcement to prevent overflow (fixes seaweedfs-csi-driver#218) * test: add unit tests for quota enforcement
This commit is contained in:
@@ -36,7 +36,8 @@ import (
|
||||
*/
|
||||
func (wfs *WFS) Write(cancel <-chan struct{}, in *fuse.WriteIn, data []byte) (written uint32, code fuse.Status) {
|
||||
|
||||
if wfs.IsOverQuota {
|
||||
// Check quota including uncommitted writes for real-time enforcement
|
||||
if wfs.IsOverQuotaWithUncommitted() {
|
||||
return 0, fuse.Status(syscall.ENOSPC)
|
||||
}
|
||||
|
||||
@@ -59,7 +60,16 @@ func (wfs *WFS) Write(cancel <-chan struct{}, in *fuse.WriteIn, data []byte) (wr
|
||||
|
||||
entry.Content = nil
|
||||
offset := int64(in.Offset)
|
||||
entry.Attributes.FileSize = uint64(max(offset+int64(len(data)), int64(entry.Attributes.FileSize)))
|
||||
oldFileSize := int64(entry.Attributes.FileSize)
|
||||
newFileSize := max(offset+int64(len(data)), oldFileSize)
|
||||
entry.Attributes.FileSize = uint64(newFileSize)
|
||||
|
||||
// Track uncommitted bytes for real-time quota enforcement.
|
||||
// Only count the new bytes being added beyond the current file size.
|
||||
if newFileSize > oldFileSize {
|
||||
wfs.AddUncommittedBytes(newFileSize - oldFileSize)
|
||||
}
|
||||
|
||||
// glog.V(4).Infof("%v write [%d,%d) %d", fh.f.fullpath(), req.Offset, req.Offset+int64(len(req.Data)), len(req.Data))
|
||||
|
||||
fh.dirtyPages.AddPage(offset, data, fh.dirtyPages.writerPattern.IsSequentialMode(), tsNs)
|
||||
|
||||
Reference in New Issue
Block a user