Browse Source

add flag to enforce quota

pull/2727/head
chrislu 3 years ago
parent
commit
b7c992f410
  1. 1
      weed/mount/weedfs.go
  2. 4
      weed/mount/weedfs_attr.go
  3. 4
      weed/mount/weedfs_dir_mkrm.go
  4. 4
      weed/mount/weedfs_file_mkrm.go
  5. 12
      weed/mount/weedfs_file_sync.go
  6. 4
      weed/mount/weedfs_file_write.go
  7. 4
      weed/mount/weedfs_link.go
  8. 4
      weed/mount/weedfs_rename.go
  9. 3
      weed/mount/weedfs_symlink.go
  10. 5
      weed/mount/weedfs_xattr.go

1
weed/mount/weedfs.go

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

4
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) { 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) path, fh, entry, status := wfs.maybeReadEntry(input.NodeId)
if status != fuse.OK { if status != fuse.OK {
return status return status

4
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) { 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 { if s := checkName(name); s != fuse.OK {
return s return s
} }

4
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) { 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 { if s := checkName(name); s != fuse.OK {
return s return s
} }

12
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 // send the data to the OS
glog.V(4).Infof("doFlush %s fh %d", fileFullPath, fh.handle) 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 { if !fh.dirtyMetadata {
return fuse.OK return fuse.OK
} }
if wfs.IsOverQuota {
return fuse.EPERM
}
err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error { err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
entry := fh.entry entry := fh.entry

4
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) { 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)) fh := wfs.GetHandle(FileHandleId(in.Fh))
if fh == nil { if fh == nil {
return 0, fuse.ENOENT return 0, fuse.ENOENT

4
weed/mount/weedfs_link.go

@ -23,6 +23,10 @@ When creating a link:
/** Create a hard link to a file */ /** 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) { 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 { if s := checkName(name); s != fuse.OK {
return s return s
} }

4
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) { 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 { if s := checkName(newName); s != fuse.OK {
return s return s
} }

3
weed/mount/weedfs_symlink.go

@ -14,6 +14,9 @@ import (
/** Create a symbolic link */ /** Create a symbolic link */
func (wfs *WFS) Symlink(cancel <-chan struct{}, header *fuse.InHeader, target string, name string, out *fuse.EntryOut) (code fuse.Status) { 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 { if s := checkName(name); s != fuse.OK {
return s return s
} }

5
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 // Perform a pure replace operation, which fails if the named
// attribute does not already exist. // attribute does not already exist.
func (wfs *WFS) SetXAttr(cancel <-chan struct{}, input *fuse.SetXAttrIn, attr string, data []byte) fuse.Status { 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 //validate attr name
if len(attr) > MAX_XATTR_NAME_SIZE { if len(attr) > MAX_XATTR_NAME_SIZE {
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {

Loading…
Cancel
Save