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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
ensure inodes are not duplicating unless hardlinked
chrislu63a9d8f01d0e
diff --git a/weed/mount/inode_to_path.go b/weed/mount/inode_to_path.goindex 1e914dccde..91934a4a8b 100644--- a/weed/mount/inode_to_path.go+++ b/weed/mount/inode_to_path.go@@ -31,18 +31,20 @@ func NewInodeToPath() *InodeToPath {return t}-func (i *InodeToPath) Lookup(path util.FullPath, mode os.FileMode, isCreate bool, possibleInode uint64, isLookup bool) uint64 {+func (i *InodeToPath) Lookup(path util.FullPath, mode os.FileMode, 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)+ } else {+ inode = possibleInode+ }+ if !isHardlink {for _, found := i.inode2path[inode]; found; inode++ {_, found = i.inode2path[inode]}- } else {- inode = possibleInode}}i.path2inode[path] = inode@@ -62,6 +64,19 @@ func (i *InodeToPath) Lookup(path util.FullPath, mode os.FileMode, isCreate boolreturn inode}+func (i *InodeToPath) AllocateInode(path util.FullPath, mode os.FileMode) uint64 {+ if path == "/" {+ return 1+ }+ i.Lock()+ defer i.Unlock()+ inode := path.AsInode(mode)+ for _, found := i.inode2path[inode]; found; inode++ {+ _, found = i.inode2path[inode]+ }+ return inode+}+func (i *InodeToPath) GetInode(path util.FullPath) uint64 {if path == "/" {return 1diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.goindex d7e6d8a30b..7f2821a94c 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 strinreturn fuse.ENOENT}- inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.Mode, false, localEntry.Inode, true)+ inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.Mode, len(localEntry.HardLinkId) > 0, localEntry.Inode, true)if fh, found := wfs.fhmap.FindFileHandle(inode); found {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.goindex 9cf968baf9..b23245555f 100644--- a/weed/mount/weedfs_dir_mkrm.go+++ b/weed/mount/weedfs_dir_mkrm.go@@ -74,7 +74,7 @@ func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, outreturn fuse.EIO}- inode := wfs.inodeToPath.Lookup(entryFullPath, os.ModeDir, true, 0, true)+ inode := wfs.inodeToPath.Lookup(entryFullPath, os.ModeDir, false, 0, true)wfs.outputPbEntry(out, inode, newEntry)diff --git a/weed/mount/weedfs_dir_read.go b/weed/mount/weedfs_dir_read.goindex 4862167dc0..f7cbae7f78 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, isPldirEntry.Name = entry.Name()dirEntry.Mode = toSyscallMode(entry.Mode)if !isPlusMode {- inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Mode, false, entry.Inode, false)+ inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Mode, len(entry.HardLinkId) > 0, entry.Inode, false)dirEntry.Ino = inodeif !out.AddDirEntry(dirEntry) {isEarlyTerminated = truereturn false}} else {- inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Mode, false, entry.Inode, true)+ inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Mode, len(entry.HardLinkId) > 0, entry.Inode, true)dirEntry.Ino = inodeentryOut := out.AddDirLookupEntry(dirEntry)if entryOut == nil {diff --git a/weed/mount/weedfs_file_mkrm.go b/weed/mount/weedfs_file_mkrm.goindex b679d81785..52e15bc539 100644--- a/weed/mount/weedfs_file_mkrm.go+++ b/weed/mount/weedfs_file_mkrm.go@@ -46,6 +46,7 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, outentryFullPath := dirFullPath.Child(name)fileMode := toOsFileMode(in.Mode)+ inode := wfs.inodeToPath.AllocateInode(entryFullPath, fileMode)newEntry := &filer_pb.Entry{Name: name,@@ -60,7 +61,7 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, outReplication: wfs.option.Replication,TtlSec: wfs.option.TtlSec,Rdev: in.Rdev,- Inode: entryFullPath.AsInode(fileMode),+ Inode: inode,},}@@ -94,7 +95,8 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, outreturn fuse.EIO}- inode := wfs.inodeToPath.Lookup(entryFullPath, newEntry.FileMode(), true, 0, true)+ // this is to increase nlookup counter+ inode = wfs.inodeToPath.Lookup(entryFullPath, fileMode, false, inode, true)wfs.outputPbEntry(out, inode, newEntry)diff --git a/weed/mount/weedfs_link.go b/weed/mount/weedfs_link.goindex 99d19cf4df..9468b1fb19 100644--- a/weed/mount/weedfs_link.go+++ b/weed/mount/weedfs_link.go@@ -97,7 +97,7 @@ func (wfs *WFS) Link(cancel <-chan struct{}, in *fuse.LinkIn, name string, out *return fuse.EIO}- inode := wfs.inodeToPath.Lookup(newEntryPath, oldEntry.FileMode(), false, oldEntry.Attributes.Inode, true)+ inode := wfs.inodeToPath.Lookup(newEntryPath, oldEntry.FileMode(), true, oldEntry.Attributes.Inode, true)wfs.outputPbEntry(out, inode, request.Entry)