From 6ac066d1dc03335adeacf17b923b8208418c9124 Mon Sep 17 00:00:00 2001 From: chrislu Date: Wed, 16 Feb 2022 16:49:03 -0800 Subject: [PATCH] count lookup or not --- weed/mount/inode_to_path.go | 12 +++++++++--- weed/mount/weedfs_dir_lookup.go | 2 +- weed/mount/weedfs_dir_mkrm.go | 2 +- weed/mount/weedfs_file_mkrm.go | 2 +- weed/mount/weedfs_link.go | 2 +- weed/mount/weedfs_symlink.go | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/weed/mount/inode_to_path.go b/weed/mount/inode_to_path.go index ffb0cc02f..edea91a5d 100644 --- a/weed/mount/inode_to_path.go +++ b/weed/mount/inode_to_path.go @@ -30,7 +30,7 @@ func NewInodeToPath() *InodeToPath { return t } -func (i *InodeToPath) Lookup(path util.FullPath, isDirectory bool) uint64 { +func (i *InodeToPath) Lookup(path util.FullPath, isDirectory bool, isLookup bool) uint64 { i.Lock() defer i.Unlock() inode, found := i.path2inode[path] @@ -38,9 +38,15 @@ func (i *InodeToPath) Lookup(path util.FullPath, isDirectory bool) uint64 { inode = i.nextInodeId i.nextInodeId++ i.path2inode[path] = inode - i.inode2path[inode] = &InodeEntry{path, 1, isDirectory, false} + if !isLookup { + i.inode2path[inode] = &InodeEntry{path, 0, isDirectory, false} + } else { + i.inode2path[inode] = &InodeEntry{path, 1, isDirectory, false} + } } else { - i.inode2path[inode].nlookup++ + if isLookup { + i.inode2path[inode].nlookup++ + } } return inode } diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.go index 30b61d75f..a4befa7fa 100644 --- a/weed/mount/weedfs_dir_lookup.go +++ b/weed/mount/weedfs_dir_lookup.go @@ -50,7 +50,7 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strin return fuse.ENOENT } - inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.IsDirectory()) + inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.IsDirectory(), true) wfs.outputFilerEntry(out, inode, localEntry) diff --git a/weed/mount/weedfs_dir_mkrm.go b/weed/mount/weedfs_dir_mkrm.go index 4022f8e87..17b70cacd 100644 --- a/weed/mount/weedfs_dir_mkrm.go +++ b/weed/mount/weedfs_dir_mkrm.go @@ -71,7 +71,7 @@ func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out return fuse.EIO } - inode := wfs.inodeToPath.Lookup(entryFullPath, true) + inode := wfs.inodeToPath.Lookup(entryFullPath, true, true) wfs.outputPbEntry(out, inode, newEntry) diff --git a/weed/mount/weedfs_file_mkrm.go b/weed/mount/weedfs_file_mkrm.go index 03d38ebf6..032008a85 100644 --- a/weed/mount/weedfs_file_mkrm.go +++ b/weed/mount/weedfs_file_mkrm.go @@ -88,7 +88,7 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out return fuse.EIO } - inode := wfs.inodeToPath.Lookup(entryFullPath, false) + inode := wfs.inodeToPath.Lookup(entryFullPath, false, true) wfs.outputPbEntry(out, inode, newEntry) diff --git a/weed/mount/weedfs_link.go b/weed/mount/weedfs_link.go index ca252d639..7cc98b3e6 100644 --- a/weed/mount/weedfs_link.go +++ b/weed/mount/weedfs_link.go @@ -85,7 +85,7 @@ func (wfs *WFS) Link(cancel <-chan struct{}, in *fuse.LinkIn, name string, out * return fuse.EIO } - inode := wfs.inodeToPath.Lookup(newEntryPath, false) + inode := wfs.inodeToPath.Lookup(newEntryPath, false, true) wfs.outputPbEntry(out, inode, request.Entry) diff --git a/weed/mount/weedfs_symlink.go b/weed/mount/weedfs_symlink.go index c47ad0a2e..66d956a91 100644 --- a/weed/mount/weedfs_symlink.go +++ b/weed/mount/weedfs_symlink.go @@ -56,7 +56,7 @@ func (wfs *WFS) Symlink(cancel <-chan struct{}, header *fuse.InHeader, target st return fuse.EIO } - inode := wfs.inodeToPath.Lookup(entryFullPath, false) + inode := wfs.inodeToPath.Lookup(entryFullPath, false, true) wfs.outputPbEntry(out, inode, request.Entry)