Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

mount: fix k8s pvc and os mount directory permission bug

limdcbca14edc562
diff --git a/weed/command/mount_std.go b/weed/command/mount_std.go
index cbac353510..7c0f56d3ae 100644
--- a/weed/command/mount_std.go
+++ b/weed/command/mount_std.go
@@ -7,7 +7,6 @@ import (
"fmt"
"github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
"os"
- "os/user"
"path"
"runtime"
"strconv"
@@ -87,35 +86,11 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
fuse.Unmount(dir)
- uid, gid := uint32(0), uint32(0)
-
// detect mount folder mode
if *option.dirAutoCreate {
os.MkdirAll(dir, os.FileMode(0777)&^umask)
- os.Chmod(dir, os.FileMode(0777)&^umask)
}
- mountMode := os.ModeDir | 0777
fileInfo, err := os.Stat(dir)
- if err == nil {
- mountMode = os.ModeDir | fileInfo.Mode()
- uid, gid = util.GetFileUidGid(fileInfo)
- fmt.Printf("mount point owner uid=%d gid=%d mode=%s\n", uid, gid, fileInfo.Mode())
- } else {
- fmt.Printf("can not stat %s\n", dir)
- return false
- }
-
- if uid == 0 {
- if u, err := user.Current(); err == nil {
- if parsedId, pe := strconv.ParseUint(u.Uid, 10, 32); pe == nil {
- uid = uint32(parsedId)
- }
- if parsedId, pe := strconv.ParseUint(u.Gid, 10, 32); pe == nil {
- gid = uint32(parsedId)
- }
- fmt.Printf("current uid=%d gid=%d\n", uid, gid)
- }
- }
// mapping uid, gid
uidGidMapper, err := meta_cache.NewUidGidMapper(*option.uidMap, *option.gidMap)
@@ -175,9 +150,6 @@ func RunMount(option *MountOptions, umask os.FileMode) bool {
CacheSizeMB: *option.cacheSizeMB,
DataCenter: *option.dataCenter,
EntryCacheTtl: 3 * time.Second,
- MountUid: uid,
- MountGid: gid,
- MountMode: mountMode,
MountCtime: fileInfo.ModTime(),
MountMtime: time.Now(),
Umask: umask,
diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go
index fd16d74b95..cef0d6e3b1 100644
--- a/weed/filesys/dir.go
+++ b/weed/filesys/dir.go
@@ -82,9 +82,9 @@ func (dir *Dir) Getxattr(ctx context.Context, req *fuse.GetxattrRequest, resp *f
func (dir *Dir) setRootDirAttributes(attr *fuse.Attr) {
attr.Inode = 1 // filer2.FullPath(dir.Path).AsInode()
attr.Valid = time.Hour
- attr.Uid = dir.wfs.option.MountUid
- attr.Gid = dir.wfs.option.MountGid
- attr.Mode = dir.wfs.option.MountMode
+ attr.Uid = dir.entry.Attributes.Uid
+ attr.Gid = dir.entry.Attributes.Gid
+ attr.Mode = os.FileMode(dir.entry.Attributes.FileMode)
attr.Crtime = dir.wfs.option.MountCtime
attr.Ctime = dir.wfs.option.MountCtime
attr.Mtime = dir.wfs.option.MountMtime
diff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.go
index 0335d5d98d..fa491138ee 100644
--- a/weed/filesys/wfs.go
+++ b/weed/filesys/wfs.go
@@ -37,9 +37,6 @@ type Option struct {
EntryCacheTtl time.Duration
Umask os.FileMode
- MountUid uint32
- MountGid uint32
- MountMode os.FileMode
MountCtime time.Time
MountMtime time.Time
@@ -88,7 +85,7 @@ func NewSeaweedFileSystem(option *Option) *WFS {
cacheUniqueId := util.Md5String([]byte(option.FilerGrpcAddress + option.FilerMountRootPath + util.Version()))[0:4]
cacheDir := path.Join(option.CacheDir, cacheUniqueId)
if option.CacheSizeMB > 0 {
- os.MkdirAll(cacheDir, os.FileMode(0777) &^ option.Umask)
+ os.MkdirAll(cacheDir, os.FileMode(0777)&^option.Umask)
wfs.chunkCache = chunk_cache.NewTieredChunkCache(256, cacheDir, option.CacheSizeMB)
}
@@ -99,7 +96,8 @@ func NewSeaweedFileSystem(option *Option) *WFS {
wfs.metaCache.Shutdown()
})
- wfs.root = &Dir{name: wfs.option.FilerMountRootPath, wfs: wfs}
+ entry, _ := filer_pb.GetEntry(wfs, util.FullPath(wfs.option.FilerMountRootPath))
+ wfs.root = &Dir{name: wfs.option.FilerMountRootPath, wfs: wfs, entry: entry}
wfs.fsNodeCache = newFsCache(wfs.root)
return wfs