Browse Source

mount: add umask option

related to https://github.com/chrislusf/seaweedfs/issues/978
pull/1020/head
Chris Lu 5 years ago
parent
commit
5956dfd08d
  1. 2
      weed/command/mount.go
  2. 10
      weed/command/mount_std.go
  3. 4
      weed/filesys/dir.go
  4. 2
      weed/filesys/dir_link.go
  5. 2
      weed/filesys/filehandle.go
  6. 1
      weed/filesys/wfs.go

2
weed/command/mount.go

@ -17,6 +17,7 @@ type MountOptions struct {
chunkSizeLimitMB *int chunkSizeLimitMB *int
dataCenter *string dataCenter *string
allowOthers *bool allowOthers *bool
umaskString *string
} }
var ( var (
@ -37,6 +38,7 @@ func init() {
mountOptions.chunkSizeLimitMB = cmdMount.Flag.Int("chunkSizeLimitMB", 4, "local write buffer size, also chunk large files") mountOptions.chunkSizeLimitMB = cmdMount.Flag.Int("chunkSizeLimitMB", 4, "local write buffer size, also chunk large files")
mountOptions.dataCenter = cmdMount.Flag.String("dataCenter", "", "prefer to write to the data center") mountOptions.dataCenter = cmdMount.Flag.String("dataCenter", "", "prefer to write to the data center")
mountOptions.allowOthers = cmdMount.Flag.Bool("allowOthers", true, "allows other users to access the file system") mountOptions.allowOthers = cmdMount.Flag.Bool("allowOthers", true, "allows other users to access the file system")
mountOptions.umaskString = cmdMount.Flag.String("umask", "022", "octal umask, e.g., 022, 0111")
mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file") mountCpuProfile = cmdMount.Flag.String("cpuprofile", "", "cpu profile output file")
mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file") mountMemProfile = cmdMount.Flag.String("memprofile", "", "memory profile output file")
} }

10
weed/command/mount_std.go

@ -27,6 +27,12 @@ func runMount(cmd *Command, args []string) bool {
util.SetupProfiling(*mountCpuProfile, *mountMemProfile) util.SetupProfiling(*mountCpuProfile, *mountMemProfile)
umask, umaskErr := strconv.ParseUint(*mountOptions.umaskString, 8, 64)
if umaskErr != nil {
fmt.Printf("can not parse umask %s", *mountOptions.umaskString)
return false
}
return RunMount( return RunMount(
*mountOptions.filer, *mountOptions.filer,
*mountOptions.filerMountRootPath, *mountOptions.filerMountRootPath,
@ -38,11 +44,12 @@ func runMount(cmd *Command, args []string) bool {
*mountOptions.allowOthers, *mountOptions.allowOthers,
*mountOptions.ttlSec, *mountOptions.ttlSec,
*mountOptions.dirListingLimit, *mountOptions.dirListingLimit,
os.FileMode(umask),
) )
} }
func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCenter string, chunkSizeLimitMB int, func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCenter string, chunkSizeLimitMB int,
allowOthers bool, ttlSec int, dirListingLimit int) bool {
allowOthers bool, ttlSec int, dirListingLimit int, umask os.FileMode) bool {
util.LoadConfiguration("security", false) util.LoadConfiguration("security", false)
@ -146,6 +153,7 @@ func RunMount(filer, filerMountRootPath, dir, collection, replication, dataCente
MountMode: mountMode, MountMode: mountMode,
MountCtime: fileInfo.ModTime(), MountCtime: fileInfo.ModTime(),
MountMtime: time.Now(), MountMtime: time.Now(),
Umask: umask,
})) }))
if err != nil { if err != nil {
fuse.Unmount(dir) fuse.Unmount(dir)

4
weed/filesys/dir.go

@ -101,7 +101,7 @@ func (dir *Dir) Create(ctx context.Context, req *fuse.CreateRequest,
Attributes: &filer_pb.FuseAttributes{ Attributes: &filer_pb.FuseAttributes{
Mtime: time.Now().Unix(), Mtime: time.Now().Unix(),
Crtime: time.Now().Unix(), Crtime: time.Now().Unix(),
FileMode: uint32(req.Mode),
FileMode: uint32(req.Mode &^ dir.wfs.option.Umask),
Uid: req.Uid, Uid: req.Uid,
Gid: req.Gid, Gid: req.Gid,
Collection: dir.wfs.option.Collection, Collection: dir.wfs.option.Collection,
@ -146,7 +146,7 @@ func (dir *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fs.Node, err
Attributes: &filer_pb.FuseAttributes{ Attributes: &filer_pb.FuseAttributes{
Mtime: time.Now().Unix(), Mtime: time.Now().Unix(),
Crtime: time.Now().Unix(), Crtime: time.Now().Unix(),
FileMode: uint32(req.Mode),
FileMode: uint32(req.Mode &^ dir.wfs.option.Umask),
Uid: req.Uid, Uid: req.Uid,
Gid: req.Gid, Gid: req.Gid,
}, },

2
weed/filesys/dir_link.go

@ -27,7 +27,7 @@ func (dir *Dir) Symlink(ctx context.Context, req *fuse.SymlinkRequest) (fs.Node,
Attributes: &filer_pb.FuseAttributes{ Attributes: &filer_pb.FuseAttributes{
Mtime: time.Now().Unix(), Mtime: time.Now().Unix(),
Crtime: time.Now().Unix(), Crtime: time.Now().Unix(),
FileMode: uint32(os.FileMode(0755) | os.ModeSymlink),
FileMode: uint32((os.FileMode(0777) | os.ModeSymlink) &^ dir.wfs.option.Umask),
Uid: req.Uid, Uid: req.Uid,
Gid: req.Gid, Gid: req.Gid,
SymlinkTarget: req.Target, SymlinkTarget: req.Target,

2
weed/filesys/filehandle.go

@ -148,7 +148,7 @@ func (fh *FileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error {
fh.f.entry.Attributes.Gid = req.Gid fh.f.entry.Attributes.Gid = req.Gid
fh.f.entry.Attributes.Mtime = time.Now().Unix() fh.f.entry.Attributes.Mtime = time.Now().Unix()
fh.f.entry.Attributes.Crtime = time.Now().Unix() fh.f.entry.Attributes.Crtime = time.Now().Unix()
fh.f.entry.Attributes.FileMode = uint32(0770)
fh.f.entry.Attributes.FileMode = uint32(0777 &^ fh.f.wfs.option.Umask)
} }
request := &filer_pb.CreateEntryRequest{ request := &filer_pb.CreateEntryRequest{

1
weed/filesys/wfs.go

@ -28,6 +28,7 @@ type Option struct {
DataCenter string DataCenter string
DirListingLimit int DirListingLimit int
EntryCacheTtl time.Duration EntryCacheTtl time.Duration
Umask os.FileMode
MountUid uint32 MountUid uint32
MountGid uint32 MountGid uint32

Loading…
Cancel
Save