diff --git a/weed/mount/inode_to_path.go b/weed/mount/inode_to_path.go index 1e914dccd..91934a4a8 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 bool return 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 1 diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.go index d7e6d8a30..7f2821a94 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, 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.go index 9cf968baf..b23245555 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, out return 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.go index 4862167dc..f7cbae7f7 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, false, entry.Inode, false) + inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Mode, 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, false, entry.Inode, true) + inode := wfs.inodeToPath.Lookup(dirPath.Child(dirEntry.Name), entry.Mode, 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 b679d8178..52e15bc53 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, out entryFullPath := 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, out Replication: 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, out return 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.go index 99d19cf4d..9468b1fb1 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)