diff options
| author | chrislu <chris.lu@gmail.com> | 2024-09-04 02:25:07 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2024-09-04 02:25:07 -0700 |
| commit | eb02946c977be57a0325d9ed86847699e99661c1 (patch) | |
| tree | 2111c09d45e608fa0ef2a1fa3ff0e2f3f3392183 /weed/mount | |
| parent | 18afdb15b6df2835ca600d566997fa7410e1ec9b (diff) | |
| download | seaweedfs-eb02946c977be57a0325d9ed86847699e99661c1.tar.xz seaweedfs-eb02946c977be57a0325d9ed86847699e99661c1.zip | |
support write once read many
fix https://github.com/seaweedfs/seaweedfs/issues/5954
Diffstat (limited to 'weed/mount')
| -rw-r--r-- | weed/mount/weedfs.go | 2 | ||||
| -rw-r--r-- | weed/mount/weedfs_file_io.go | 2 | ||||
| -rw-r--r-- | weed/mount/weedfs_filehandle.go | 10 |
3 files changed, 12 insertions, 2 deletions
diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.go index a9fbd9380..3ad938699 100644 --- a/weed/mount/weedfs.go +++ b/weed/mount/weedfs.go @@ -46,6 +46,8 @@ type Option struct { Quota int64 DisableXAttr bool + WriteOnceReadMany bool + MountUid uint32 MountGid uint32 MountMode os.FileMode diff --git a/weed/mount/weedfs_file_io.go b/weed/mount/weedfs_file_io.go index 7039b14ec..c6fcb8a14 100644 --- a/weed/mount/weedfs_file_io.go +++ b/weed/mount/weedfs_file_io.go @@ -62,7 +62,7 @@ import ( */ func (wfs *WFS) Open(cancel <-chan struct{}, in *fuse.OpenIn, out *fuse.OpenOut) (status fuse.Status) { var fileHandle *FileHandle - fileHandle, status = wfs.AcquireHandle(in.NodeId, in.Uid, in.Gid) + fileHandle, status = wfs.AcquireHandle(in.NodeId, in.Flags, in.Uid, in.Gid) if status == fuse.OK { out.Fh = uint64(fileHandle.fh) // TODO https://github.com/libfuse/libfuse/blob/master/include/fuse_common.h#L64 diff --git a/weed/mount/weedfs_filehandle.go b/weed/mount/weedfs_filehandle.go index 4845654ed..99b54850a 100644 --- a/weed/mount/weedfs_filehandle.go +++ b/weed/mount/weedfs_filehandle.go @@ -3,12 +3,20 @@ package mount import ( "github.com/hanwen/go-fuse/v2/fuse" "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" + "time" ) -func (wfs *WFS) AcquireHandle(inode uint64, uid, gid uint32) (fileHandle *FileHandle, status fuse.Status) { +func (wfs *WFS) AcquireHandle(inode uint64, flags, uid, gid uint32) (fileHandle *FileHandle, status fuse.Status) { var entry *filer_pb.Entry _, _, entry, status = wfs.maybeReadEntry(inode) if status == fuse.OK { + if entry != nil && wfs.option.WriteOnceReadMany { + if entry.Attributes.Mtime+10 < time.Now().Unix() { + if flags&fuse.O_ANYWRITE != 0 { + return nil, fuse.EPERM + } + } + } // need to AcquireFileHandle again to ensure correct handle counter fileHandle = wfs.fhmap.AcquireFileHandle(wfs, inode, entry) } |
