worm grace period and retention time support (#6404)
Signed-off-by: lou <alex1988@outlook.com>
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
package mount
|
||||
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/hanwen/go-fuse/v2/fuse"
|
||||
"github.com/seaweedfs/seaweedfs/weed/filer"
|
||||
"github.com/seaweedfs/seaweedfs/weed/glog"
|
||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func (wfs *WFS) GetAttr(cancel <-chan struct{}, input *fuse.GetAttrIn, out *fuse.AttrOut) (code fuse.Status) {
|
||||
@@ -42,7 +43,7 @@ func (wfs *WFS) SetAttr(cancel <-chan struct{}, input *fuse.SetAttrIn, out *fuse
|
||||
}
|
||||
|
||||
path, fh, entry, status := wfs.maybeReadEntry(input.NodeId)
|
||||
if status != fuse.OK {
|
||||
if status != fuse.OK || entry == nil {
|
||||
return status
|
||||
}
|
||||
if fh != nil {
|
||||
@@ -50,7 +51,12 @@ func (wfs *WFS) SetAttr(cancel <-chan struct{}, input *fuse.SetAttrIn, out *fuse
|
||||
defer fh.entryLock.Unlock()
|
||||
}
|
||||
|
||||
if size, ok := input.GetSize(); ok && entry != nil {
|
||||
wormEnforced, wormEnabled := wfs.wormEnforcedForEntry(path, entry)
|
||||
if wormEnforced {
|
||||
return fuse.EPERM
|
||||
}
|
||||
|
||||
if size, ok := input.GetSize(); ok {
|
||||
glog.V(4).Infof("%v setattr set size=%v chunks=%d", path, size, len(entry.GetChunks()))
|
||||
if size < filer.FileSize(entry) {
|
||||
// fmt.Printf("truncate %v \n", fullPath)
|
||||
@@ -85,6 +91,11 @@ func (wfs *WFS) SetAttr(cancel <-chan struct{}, input *fuse.SetAttrIn, out *fuse
|
||||
}
|
||||
|
||||
if mode, ok := input.GetMode(); ok {
|
||||
// commit the file to worm when it is set to readonly at the first time
|
||||
if entry.WormEnforcedAtTsNs == 0 && wormEnabled && !hasWritePermission(mode) {
|
||||
entry.WormEnforcedAtTsNs = time.Now().UnixNano()
|
||||
}
|
||||
|
||||
// glog.V(4).Infof("setAttr mode %o", mode)
|
||||
entry.Attributes.FileMode = chmod(entry.Attributes.FileMode, mode)
|
||||
if input.NodeId == 1 {
|
||||
@@ -216,6 +227,14 @@ func chmod(existing uint32, mode uint32) uint32 {
|
||||
return existing&^07777 | mode&07777
|
||||
}
|
||||
|
||||
const ownerWrite = 0o200
|
||||
const groupWrite = 0o020
|
||||
const otherWrite = 0o002
|
||||
|
||||
func hasWritePermission(mode uint32) bool {
|
||||
return (mode&ownerWrite != 0) || (mode&groupWrite != 0) || (mode&otherWrite != 0)
|
||||
}
|
||||
|
||||
func toSyscallMode(mode os.FileMode) uint32 {
|
||||
return toSyscallType(mode) | uint32(mode)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user