2022-02-12 13:27:16 +00:00
|
|
|
package mount
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2022-08-26 23:41:37 +00:00
|
|
|
|
2022-02-12 13:27:16 +00:00
|
|
|
"github.com/hanwen/go-fuse/v2/fuse"
|
2022-08-26 23:41:37 +00:00
|
|
|
|
2022-07-29 07:17:28 +00:00
|
|
|
"github.com/seaweedfs/seaweedfs/weed/filer"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/glog"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/mount/meta_cache"
|
|
|
|
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
2022-02-12 13:27:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Lookup is called by the kernel when the VFS wants to know
|
|
|
|
// about a file inside a directory. Many lookup calls can
|
|
|
|
// occur in parallel, but only one call happens for each (dir,
|
|
|
|
// name) pair.
|
|
|
|
|
|
|
|
func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name string, out *fuse.EntryOut) (code fuse.Status) {
|
|
|
|
|
2022-02-13 09:34:19 +00:00
|
|
|
if s := checkName(name); s != fuse.OK {
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2022-02-18 08:45:43 +00:00
|
|
|
dirPath, code := wfs.inodeToPath.GetPath(header.NodeId)
|
|
|
|
if code != fuse.OK {
|
|
|
|
return
|
|
|
|
}
|
2022-02-12 13:27:16 +00:00
|
|
|
|
|
|
|
fullFilePath := dirPath.Child(name)
|
|
|
|
|
2022-05-25 01:52:04 +00:00
|
|
|
visitErr := meta_cache.EnsureVisited(wfs.metaCache, wfs, dirPath)
|
2022-02-12 13:27:16 +00:00
|
|
|
if visitErr != nil {
|
|
|
|
glog.Errorf("dir Lookup %s: %v", dirPath, visitErr)
|
|
|
|
return fuse.EIO
|
|
|
|
}
|
|
|
|
localEntry, cacheErr := wfs.metaCache.FindEntry(context.Background(), fullFilePath)
|
|
|
|
if cacheErr == filer_pb.ErrNotFound {
|
|
|
|
return fuse.ENOENT
|
|
|
|
}
|
|
|
|
|
|
|
|
if localEntry == nil {
|
|
|
|
// glog.V(3).Infof("dir Lookup cache miss %s", fullFilePath)
|
|
|
|
entry, err := filer_pb.GetEntry(wfs, fullFilePath)
|
|
|
|
if err != nil {
|
|
|
|
glog.V(1).Infof("dir GetEntry %s: %v", fullFilePath, err)
|
|
|
|
return fuse.ENOENT
|
|
|
|
}
|
|
|
|
localEntry = filer.FromPbEntry(string(dirPath), entry)
|
|
|
|
} else {
|
|
|
|
glog.V(4).Infof("dir Lookup cache hit %s", fullFilePath)
|
|
|
|
}
|
|
|
|
|
|
|
|
if localEntry == nil {
|
|
|
|
return fuse.ENOENT
|
|
|
|
}
|
|
|
|
|
2022-03-14 07:03:29 +00:00
|
|
|
inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.Crtime.Unix(), localEntry.IsDirectory(), len(localEntry.HardLinkId) > 0, localEntry.Inode, true)
|
2022-02-12 13:27:16 +00:00
|
|
|
|
2022-08-26 23:41:37 +00:00
|
|
|
if fh, found := wfs.fhmap.FindFileHandle(inode); found {
|
2022-12-05 07:33:05 +00:00
|
|
|
if entry := fh.GetEntry(); entry != nil {
|
|
|
|
glog.V(4).Infof("lookup opened file %s size %d", dirPath.Child(localEntry.Name()), filer.FileSize(entry))
|
|
|
|
localEntry = filer.FromPbEntry(string(dirPath), entry)
|
2022-08-26 23:41:37 +00:00
|
|
|
}
|
2022-02-24 08:37:57 +00:00
|
|
|
}
|
|
|
|
|
2022-02-13 09:34:19 +00:00
|
|
|
wfs.outputFilerEntry(out, inode, localEntry)
|
2022-02-12 13:27:16 +00:00
|
|
|
|
|
|
|
return fuse.OK
|
|
|
|
|
|
|
|
}
|