aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-03-14 00:03:29 -0700
committerchrislu <chris.lu@gmail.com>2022-03-14 00:03:29 -0700
commitbd5c5586b5c30389b57e26cc1675044ce1ab3883 (patch)
tree9810cc54608f8e1fb02812d51b5572341203ce73
parent5cba8e51c5bb8925b3676b03a368f7816215cc68 (diff)
downloadseaweedfs-bd5c5586b5c30389b57e26cc1675044ce1ab3883.tar.xz
seaweedfs-bd5c5586b5c30389b57e26cc1675044ce1ab3883.zip
generate inode via path and time
-rw-r--r--weed/mount/inode_to_path.go13
-rw-r--r--weed/mount/weedfs_dir_lookup.go2
-rw-r--r--weed/mount/weedfs_dir_mkrm.go2
-rw-r--r--weed/mount/weedfs_dir_read.go4
-rw-r--r--weed/mount/weedfs_file_mkrm.go9
-rw-r--r--weed/mount/weedfs_link.go2
-rw-r--r--weed/mount/weedfs_symlink.go2
-rw-r--r--weed/util/fullpath.go25
8 files changed, 19 insertions, 40 deletions
diff --git a/weed/mount/inode_to_path.go b/weed/mount/inode_to_path.go
index cae0144bc..e465158e8 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 02fc9f0d8..381bbe223 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 a8ede0ecb..289a0bc2c 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 e5acbdd43..a1b4ac0d5 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 aed9545d0..b5676eb02 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 ac5a4baf1..2ab412fd5 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 e165307c7..b8be55011 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 6c4f5c6ae..f52d4d1d0 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
}