From b7c992f410098ae53409329cf02ddc2935aed03a Mon Sep 17 00:00:00 2001 From: chrislu Date: Sat, 5 Mar 2022 22:10:43 -0800 Subject: [PATCH] add flag to enforce quota --- weed/mount/weedfs.go | 1 + weed/mount/weedfs_attr.go | 4 ++++ weed/mount/weedfs_dir_mkrm.go | 4 ++++ weed/mount/weedfs_file_mkrm.go | 4 ++++ weed/mount/weedfs_file_sync.go | 12 +++++++++--- weed/mount/weedfs_file_write.go | 4 ++++ weed/mount/weedfs_link.go | 4 ++++ weed/mount/weedfs_rename.go | 4 ++++ weed/mount/weedfs_symlink.go | 3 +++ weed/mount/weedfs_xattr.go | 5 +++++ 10 files changed, 42 insertions(+), 3 deletions(-) diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.go index 0e5489198..25a203044 100644 --- a/weed/mount/weedfs.go +++ b/weed/mount/weedfs.go @@ -66,6 +66,7 @@ type WFS struct { fhmap *FileHandleToInode dhmap *DirectoryHandleToInode fuseServer *fuse.Server + IsOverQuota bool } func NewSeaweedFileSystem(option *Option) *WFS { diff --git a/weed/mount/weedfs_attr.go b/weed/mount/weedfs_attr.go index 3a5fb756d..64e9cb5f5 100644 --- a/weed/mount/weedfs_attr.go +++ b/weed/mount/weedfs_attr.go @@ -35,6 +35,10 @@ func (wfs *WFS) GetAttr(cancel <-chan struct{}, input *fuse.GetAttrIn, out *fuse func (wfs *WFS) SetAttr(cancel <-chan struct{}, input *fuse.SetAttrIn, out *fuse.AttrOut) (code fuse.Status) { + if wfs.IsOverQuota { + return fuse.EPERM + } + path, fh, entry, status := wfs.maybeReadEntry(input.NodeId) if status != fuse.OK { return status diff --git a/weed/mount/weedfs_dir_mkrm.go b/weed/mount/weedfs_dir_mkrm.go index b23245555..3872102df 100644 --- a/weed/mount/weedfs_dir_mkrm.go +++ b/weed/mount/weedfs_dir_mkrm.go @@ -21,6 +21,10 @@ import ( * */ func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out *fuse.EntryOut) (code fuse.Status) { + if wfs.IsOverQuota { + return fuse.EPERM + } + if s := checkName(name); s != fuse.OK { return s } diff --git a/weed/mount/weedfs_file_mkrm.go b/weed/mount/weedfs_file_mkrm.go index 52e15bc53..81186da0a 100644 --- a/weed/mount/weedfs_file_mkrm.go +++ b/weed/mount/weedfs_file_mkrm.go @@ -35,6 +35,10 @@ func (wfs *WFS) Create(cancel <-chan struct{}, in *fuse.CreateIn, name string, o */ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out *fuse.EntryOut) (code fuse.Status) { + if wfs.IsOverQuota { + return fuse.EPERM + } + if s := checkName(name); s != fuse.OK { return s } diff --git a/weed/mount/weedfs_file_sync.go b/weed/mount/weedfs_file_sync.go index 4c6dda6eb..99403fc52 100644 --- a/weed/mount/weedfs_file_sync.go +++ b/weed/mount/weedfs_file_sync.go @@ -100,15 +100,21 @@ func (wfs *WFS) doFlush(fh *FileHandle, uid, gid uint32) fuse.Status { // send the data to the OS glog.V(4).Infof("doFlush %s fh %d", fileFullPath, fh.handle) - if err := fh.dirtyPages.FlushData(); err != nil { - glog.Errorf("%v doFlush: %v", fileFullPath, err) - return fuse.EIO + if !wfs.IsOverQuota { + if err := fh.dirtyPages.FlushData(); err != nil { + glog.Errorf("%v doFlush: %v", fileFullPath, err) + return fuse.EIO + } } if !fh.dirtyMetadata { return fuse.OK } + if wfs.IsOverQuota { + return fuse.EPERM + } + err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error { entry := fh.entry diff --git a/weed/mount/weedfs_file_write.go b/weed/mount/weedfs_file_write.go index efdf39386..ff0adcf75 100644 --- a/weed/mount/weedfs_file_write.go +++ b/weed/mount/weedfs_file_write.go @@ -33,6 +33,10 @@ import ( */ func (wfs *WFS) Write(cancel <-chan struct{}, in *fuse.WriteIn, data []byte) (written uint32, code fuse.Status) { + if wfs.IsOverQuota { + return 0, fuse.EPERM + } + fh := wfs.GetHandle(FileHandleId(in.Fh)) if fh == nil { return 0, fuse.ENOENT diff --git a/weed/mount/weedfs_link.go b/weed/mount/weedfs_link.go index 9468b1fb1..36dc93b2f 100644 --- a/weed/mount/weedfs_link.go +++ b/weed/mount/weedfs_link.go @@ -23,6 +23,10 @@ When creating a link: /** Create a hard link to a file */ func (wfs *WFS) Link(cancel <-chan struct{}, in *fuse.LinkIn, name string, out *fuse.EntryOut) (code fuse.Status) { + if wfs.IsOverQuota { + return fuse.EPERM + } + if s := checkName(name); s != fuse.OK { return s } diff --git a/weed/mount/weedfs_rename.go b/weed/mount/weedfs_rename.go index 5446c7ed1..c36130faa 100644 --- a/weed/mount/weedfs_rename.go +++ b/weed/mount/weedfs_rename.go @@ -131,6 +131,10 @@ const ( ) func (wfs *WFS) Rename(cancel <-chan struct{}, in *fuse.RenameIn, oldName string, newName string) (code fuse.Status) { + if wfs.IsOverQuota { + return fuse.EPERM + } + if s := checkName(newName); s != fuse.OK { return s } diff --git a/weed/mount/weedfs_symlink.go b/weed/mount/weedfs_symlink.go index 787a015b6..81bfe8c95 100644 --- a/weed/mount/weedfs_symlink.go +++ b/weed/mount/weedfs_symlink.go @@ -14,6 +14,9 @@ import ( /** Create a symbolic link */ func (wfs *WFS) Symlink(cancel <-chan struct{}, header *fuse.InHeader, target string, name string, out *fuse.EntryOut) (code fuse.Status) { + if wfs.IsOverQuota { + return fuse.EPERM + } if s := checkName(name); s != fuse.OK { return s } diff --git a/weed/mount/weedfs_xattr.go b/weed/mount/weedfs_xattr.go index 09cd2e980..aa95e8c8b 100644 --- a/weed/mount/weedfs_xattr.go +++ b/weed/mount/weedfs_xattr.go @@ -69,6 +69,11 @@ func (wfs *WFS) GetXAttr(cancel <-chan struct{}, header *fuse.InHeader, attr str // Perform a pure replace operation, which fails if the named // attribute does not already exist. func (wfs *WFS) SetXAttr(cancel <-chan struct{}, input *fuse.SetXAttrIn, attr string, data []byte) fuse.Status { + + if wfs.IsOverQuota { + return fuse.EPERM + } + //validate attr name if len(attr) > MAX_XATTR_NAME_SIZE { if runtime.GOOS == "darwin" {