Browse Source

generate inode via path and time

pull/2756/head
chrislu 3 years ago
parent
commit
bd5c5586b5
  1. 13
      weed/mount/inode_to_path.go
  2. 2
      weed/mount/weedfs_dir_lookup.go
  3. 2
      weed/mount/weedfs_dir_mkrm.go
  4. 4
      weed/mount/weedfs_dir_read.go
  5. 9
      weed/mount/weedfs_file_mkrm.go
  6. 2
      weed/mount/weedfs_link.go
  7. 2
      weed/mount/weedfs_symlink.go
  8. 25
      weed/util/fullpath.go

13
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]
}

2
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))

2
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)

4
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 {

9
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)

2
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)

2
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)

25
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
}

Loading…
Cancel
Save