add flag to enforce quota

This commit is contained in:
chrislu 2022-03-05 22:10:43 -08:00
parent f1713c96ae
commit b7c992f410
10 changed files with 42 additions and 3 deletions

View file

@ -66,6 +66,7 @@ type WFS struct {
fhmap *FileHandleToInode
dhmap *DirectoryHandleToInode
fuseServer *fuse.Server
IsOverQuota bool
}
func NewSeaweedFileSystem(option *Option) *WFS {

View file

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

View file

@ -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
}

View file

@ -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
}

View file

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

View file

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

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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" {