diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go index 9df43e40a..2474cf7dd 100644 --- a/weed/command/mount_std.go +++ b/weed/command/mount_std.go @@ -167,6 +167,9 @@ func RunMount(option *MountOptions, umask os.FileMode) bool { if *option.nonempty { options = append(options, fuse.AllowNonEmptyMount()) } + if *option.readOnly { + options = append(options, fuse.ReadOnly()) + } // find mount point mountRoot := filerMountRootPath @@ -200,7 +203,6 @@ func RunMount(option *MountOptions, umask os.FileMode) bool { VolumeServerAccess: *mountOptions.volumeServerAccess, Cipher: cipher, UidGidMapper: uidGidMapper, - ReadOnly: *option.readOnly, }) // mount diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go index f177c940b..9eba4066d 100644 --- a/weed/filesys/dir.go +++ b/weed/filesys/dir.go @@ -128,10 +128,6 @@ func (dir *Dir) newDirectory(fullpath util.FullPath) fs.Node { func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fs.Node, fs.Handle, error) { - if dir.wfs.option.ReadOnly { - return nil, nil, fuse.EPERM - } - request, err := dir.doCreateEntry(req.Name, req.Mode, req.Uid, req.Gid, req.Flags&fuse.OpenExclusive != 0) if err != nil { @@ -152,10 +148,6 @@ func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest, func (dir *Dir) Mknod(ctx context.Context, req *fuse.MknodRequest) (fs.Node, error) { - if dir.wfs.option.ReadOnly { - return nil, fuse.EPERM - } - _, err := dir.doCreateEntry(req.Name, req.Mode, req.Uid, req.Gid, false) if err != nil { @@ -214,10 +206,6 @@ func (dir *Dir) doCreateEntry(name string, mode os.FileMode, uid, gid uint32, ex func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, error) { - if dir.wfs.option.ReadOnly { - return nil, fuse.EPERM - } - glog.V(4).Infof("mkdir %s: %s", dir.FullPath(), req.Name) newEntry := &filer_pb.Entry{ @@ -376,10 +364,6 @@ func findFileType(mode uint16) fuse.DirentType { func (dir *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error { - if dir.wfs.option.ReadOnly { - return fuse.EPERM - } - if !req.Dir { return dir.removeOneFile(req) } @@ -455,10 +439,6 @@ func (dir *Dir) removeFolder(req *fuse.RemoveRequest) error { func (dir *Dir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error { - if dir.wfs.option.ReadOnly { - return fuse.EPERM - } - glog.V(4).Infof("%v dir setattr %+v", dir.FullPath(), req) entry, err := dir.maybeLoadEntry() @@ -488,10 +468,6 @@ func (dir *Dir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fus func (dir *Dir) Setxattr(ctx context.Context, req *fuse.SetxattrRequest) error { - if dir.wfs.option.ReadOnly { - return fuse.EPERM - } - glog.V(4).Infof("dir Setxattr %s: %s", dir.FullPath(), req.Name) entry, err := dir.maybeLoadEntry() @@ -509,10 +485,6 @@ func (dir *Dir) Setxattr(ctx context.Context, req *fuse.SetxattrRequest) error { func (dir *Dir) Removexattr(ctx context.Context, req *fuse.RemovexattrRequest) error { - if dir.wfs.option.ReadOnly { - return fuse.EPERM - } - glog.V(4).Infof("dir Removexattr %s: %s", dir.FullPath(), req.Name) entry, err := dir.maybeLoadEntry() diff --git a/weed/filesys/dir_link.go b/weed/filesys/dir_link.go index de330e7a4..acdcd2de4 100644 --- a/weed/filesys/dir_link.go +++ b/weed/filesys/dir_link.go @@ -24,10 +24,6 @@ const ( func (dir *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fs.Node) (fs.Node, error) { - if dir.wfs.option.ReadOnly { - return nil, fuse.EPERM - } - oldFile, ok := old.(*File) if !ok { glog.Errorf("old node is not a file: %+v", old) @@ -106,10 +102,6 @@ func (dir *Dir) Link(ctx context.Context, req *fuse.LinkRequest, old fs.Node) (f func (dir *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (fs.Node, error) { - if dir.wfs.option.ReadOnly { - return nil, fuse.EPERM - } - glog.V(4).Infof("Symlink: %v/%v to %v", dir.FullPath(), req.NewName, req.Target) request := &filer_pb.CreateEntryRequest{ diff --git a/weed/filesys/dir_rename.go b/weed/filesys/dir_rename.go index 28316c3bd..d2acad4b2 100644 --- a/weed/filesys/dir_rename.go +++ b/weed/filesys/dir_rename.go @@ -13,10 +13,6 @@ import ( func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirectory fs.Node) error { - if dir.wfs.option.ReadOnly { - return fuse.EPERM - } - newDir := newDirectory.(*Dir) newPath := util.NewFullPath(newDir.FullPath(), req.NewName) diff --git a/weed/filesys/file.go b/weed/filesys/file.go index 00a5ac279..2a991d7db 100644 --- a/weed/filesys/file.go +++ b/weed/filesys/file.go @@ -105,10 +105,6 @@ func (file *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.Op func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error { - if file.wfs.option.ReadOnly { - return fuse.EPERM - } - glog.V(4).Infof("%v file setattr %+v", file.fullpath(), req) entry, err := file.maybeLoadEntry(ctx) @@ -197,10 +193,6 @@ func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *f func (file *File) Setxattr(ctx context.Context, req *fuse.SetxattrRequest) error { - if file.wfs.option.ReadOnly { - return fuse.EPERM - } - glog.V(4).Infof("file Setxattr %s: %s", file.fullpath(), req.Name) entry, err := file.maybeLoadEntry(ctx) @@ -218,10 +210,6 @@ func (file *File) Setxattr(ctx context.Context, req *fuse.SetxattrRequest) error func (file *File) Removexattr(ctx context.Context, req *fuse.RemovexattrRequest) error { - if file.wfs.option.ReadOnly { - return fuse.EPERM - } - glog.V(4).Infof("file Removexattr %s: %s", file.fullpath(), req.Name) entry, err := file.maybeLoadEntry(ctx) diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go index 240d25a3d..5b9a1748a 100644 --- a/weed/filesys/filehandle.go +++ b/weed/filesys/filehandle.go @@ -156,10 +156,6 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) { // Write to the file handle func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error { - if fh.f.wfs.option.ReadOnly { - return fuse.EPERM - } - fh.Lock() defer fh.Unlock() diff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.go index 7bacfb114..2034354f5 100644 --- a/weed/filesys/wfs.go +++ b/weed/filesys/wfs.go @@ -42,7 +42,6 @@ type Option struct { CacheSizeMB int64 DataCenter string Umask os.FileMode - ReadOnly bool MountUid uint32 MountGid uint32