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.

generate inode via path and time

chrislubd5c5586b5c3
diff --git a/weed/mount/inode_to_path.go b/weed/mount/inode_to_path.go
index cae0144bc9..e465158e8f 100644
--- a/weed/mount/inode_to_path.go
+++ b/weed/mount/inode_to_path.go
@@ -4,7 +4,6 @@ import (
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/util"
"github.com/hanwen/go-fuse/v2/fuse"
- "os"
"sync"
)
@@ -31,13 +30,13 @@ func NewInodeToPath(root util.FullPath) *InodeToPath {
return t
}
-func (i *InodeToPath) Lookup(path util.FullPath, mode os.FileMode, isHardlink bool, possibleInode uint64, isLookup bool) uint64 {
+func (i *InodeToPath) Lookup(path util.FullPath, unixTime int64, isDirectory bool, isHardlink bool, possibleInode uint64, isLookup bool) uint64 {
i.Lock()
defer i.Unlock()
inode, found := i.path2inode[path]
if !found {
if possibleInode == 0 {
- inode = path.AsInode(mode)
+ inode = path.AsInode(unixTime)
} else {
inode = possibleInode
}
@@ -55,22 +54,22 @@ func (i *InodeToPath) Lookup(path util.FullPath, mode os.FileMode, isHardlink bo
}
} else {
if !isLookup {
- i.inode2path[inode] = &InodeEntry{path, 0, mode&os.ModeDir > 0, false}
+ i.inode2path[inode] = &InodeEntry{path, 0, isDirectory, false}
} else {
- i.inode2path[inode] = &InodeEntry{path, 1, mode&os.ModeDir > 0, false}
+ i.inode2path[inode] = &InodeEntry{path, 1, isDirectory, false}
}
}
return inode
}
-func (i *InodeToPath) AllocateInode(path util.FullPath, mode os.FileMode) uint64 {
+func (i *InodeToPath) AllocateInode(path util.FullPath, unixTime int64) uint64 {
if path == "/" {
return 1
}
i.Lock()
defer i.Unlock()
- inode := path.AsInode(mode)
+ inode := path.AsInode(unixTime)
for _, found := i.inode2path[inode]; found; inode++ {
_, found = i.inode2path[inode]
}
diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.go
index 02fc9f0d8e..381bbe2231 100644
--- a/weed/mount/weedfs_dir_lookup.go
+++ b/weed/mount/weedfs_dir_lookup.go
@@ -53,7 +53,7 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strin
return fuse.ENOENT
}
- inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.Mode, len(localEntry.HardLinkId) > 0, localEntry.Inode, true)
+ inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.Crtime.Unix(), localEntry.IsDirectory(), len(localEntry.HardLinkId) > 0, localEntry.Inode, true)
if fh, found := wfs.fhmap.FindFileHandle(inode); found && fh.entry != nil {
glog.V(4).Infof("lookup opened file %s size %d", dirPath.Child(localEntry.Name()), filer.FileSize(fh.entry))
diff --git a/weed/mount/weedfs_dir_mkrm.go b/weed/mount/weedfs_dir_mkrm.go
index a8ede0ecb8..289a0bc2cb 100644
--- a/weed/mount/weedfs_dir_mkrm.go
+++ b/weed/mount/weedfs_dir_mkrm.go
@@ -78,7 +78,7 @@ func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out
return fuse.EIO
}
- inode := wfs.inodeToPath.Lookup(entryFullPath, os.ModeDir, false, 0, true)
+ inode := wfs.inodeToPath.Lookup(entryFullPath, newEntry.Attributes.Crtime, true, false, 0, true)
wfs.outputPbEntry(out, inode, newEntry)
diff --git a/weed/mount/weedfs_dir_read.go b/weed/mount/weedfs_dir_read.go
index e5acbdd435..a1b4ac0d52 100644
--- a/weed/mount/weedfs_dir_read.go
+++ b/weed/mount/weedfs_dir_read.go
@@ -162,14 +162,14 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
dirEntry.Name = entry.Name()
dirEntry.Mode = toSyscallMode(entry.Mode)
if !isPlusMode {
- inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Mode, len(entry.HardLinkId) > 0, entry.Inode, false)
+ inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Crtime.Unix(), entry.IsDirectory(), len(entry.HardLinkId) > 0, entry.Inode, false)
dirEntry.Ino = inode
if !out.AddDirEntry(dirEntry) {
isEarlyTerminated = true
return false
}
} else {
- inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Mode, len(entry.HardLinkId) > 0, entry.Inode, true)
+ inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Crtime.Unix(), entry.IsDirectory(), len(entry.HardLinkId) > 0, entry.Inode, true)
dirEntry.Ino = inode
entryOut := out.AddDirLookupEntry(dirEntry)
if entryOut == nil {
diff --git a/weed/mount/weedfs_file_mkrm.go b/weed/mount/weedfs_file_mkrm.go
index aed9545d00..b5676eb028 100644
--- a/weed/mount/weedfs_file_mkrm.go
+++ b/weed/mount/weedfs_file_mkrm.go
@@ -51,14 +51,15 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out
entryFullPath := dirFullPath.Child(name)
fileMode := toOsFileMode(in.Mode)
- inode := wfs.inodeToPath.AllocateInode(entryFullPath, fileMode)
+ now := time.Now().Unix()
+ inode := wfs.inodeToPath.AllocateInode(entryFullPath, now)
newEntry := &filer_pb.Entry{
Name: name,
IsDirectory: false,
Attributes: &filer_pb.FuseAttributes{
- Mtime: time.Now().Unix(),
- Crtime: time.Now().Unix(),
+ Mtime: now,
+ Crtime: now,
FileMode: uint32(fileMode),
Uid: in.Uid,
Gid: in.Gid,
@@ -101,7 +102,7 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out
}
// this is to increase nlookup counter
- inode = wfs.inodeToPath.Lookup(entryFullPath, fileMode, false, inode, true)
+ inode = wfs.inodeToPath.Lookup(entryFullPath, newEntry.Attributes.Crtime, false, false, inode, true)
wfs.outputPbEntry(out, inode, newEntry)
diff --git a/weed/mount/weedfs_link.go b/weed/mount/weedfs_link.go
index ac5a4baf1d..2ab412fd5b 100644
--- a/weed/mount/weedfs_link.go
+++ b/weed/mount/weedfs_link.go
@@ -102,7 +102,7 @@ func (wfs *WFS) Link(cancel <-chan struct{}, in *fuse.LinkIn, name string, out *
return fuse.EIO
}
- inode := wfs.inodeToPath.Lookup(newEntryPath, oldEntry.FileMode(), true, oldEntry.Attributes.Inode, true)
+ inode := wfs.inodeToPath.Lookup(newEntryPath, oldEntry.Attributes.Crtime, oldEntry.IsDirectory, true, oldEntry.Attributes.Inode, true)
wfs.outputPbEntry(out, inode, request.Entry)
diff --git a/weed/mount/weedfs_symlink.go b/weed/mount/weedfs_symlink.go
index e165307c7e..b8be55011b 100644
--- a/weed/mount/weedfs_symlink.go
+++ b/weed/mount/weedfs_symlink.go
@@ -63,7 +63,7 @@ func (wfs *WFS) Symlink(cancel <-chan struct{}, header *fuse.InHeader, target st
return fuse.EIO
}
- inode := wfs.inodeToPath.Lookup(entryFullPath, os.ModeSymlink, false, 0, true)
+ inode := wfs.inodeToPath.Lookup(entryFullPath, request.Entry.Attributes.Crtime, false, false, 0, true)
wfs.outputPbEntry(out, inode, request.Entry)
diff --git a/weed/util/fullpath.go b/weed/util/fullpath.go
index 6c4f5c6ae5..f52d4d1d01 100644
--- a/weed/util/fullpath.go
+++ b/weed/util/fullpath.go
@@ -1,7 +1,6 @@
package util
import (
- "os"
"path/filepath"
"strings"
)
@@ -43,29 +42,9 @@ func (fp FullPath) Child(name string) FullPath {
}
// AsInode an in-memory only inode representation
-func (fp FullPath) AsInode(fileMode os.FileMode) uint64 {
+func (fp FullPath) AsInode(unixTime int64) uint64 {
inode := uint64(HashStringToLong(string(fp)))
- inode = inode - inode%16
- if fileMode == 0 {
- } else if fileMode&os.ModeDir > 0 {
- inode += 1
- } else if fileMode&os.ModeSymlink > 0 {
- inode += 2
- } else if fileMode&os.ModeDevice > 0 {
- if fileMode&os.ModeCharDevice > 0 {
- inode += 6
- } else {
- inode += 3
- }
- } else if fileMode&os.ModeNamedPipe > 0 {
- inode += 4
- } else if fileMode&os.ModeSocket > 0 {
- inode += 5
- } else if fileMode&os.ModeCharDevice > 0 {
- inode += 6
- } else if fileMode&os.ModeIrregular > 0 {
- inode += 7
- }
+ inode = inode + uint64(unixTime)*37
return inode
}