You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.5 KiB

  1. package mount
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/filer"
  5. "github.com/chrislusf/seaweedfs/weed/filesys/meta_cache"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  8. "github.com/hanwen/go-fuse/v2/fuse"
  9. )
  10. // Lookup is called by the kernel when the VFS wants to know
  11. // about a file inside a directory. Many lookup calls can
  12. // occur in parallel, but only one call happens for each (dir,
  13. // name) pair.
  14. func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name string, out *fuse.EntryOut) (code fuse.Status) {
  15. dirPath := wfs.inodeToPath.GetPath(header.NodeId)
  16. fullFilePath := dirPath.Child(name)
  17. visitErr := meta_cache.EnsureVisited(wfs.metaCache, wfs, dirPath)
  18. if visitErr != nil {
  19. glog.Errorf("dir Lookup %s: %v", dirPath, visitErr)
  20. return fuse.EIO
  21. }
  22. localEntry, cacheErr := wfs.metaCache.FindEntry(context.Background(), fullFilePath)
  23. if cacheErr == filer_pb.ErrNotFound {
  24. return fuse.ENOENT
  25. }
  26. if localEntry == nil {
  27. // glog.V(3).Infof("dir Lookup cache miss %s", fullFilePath)
  28. entry, err := filer_pb.GetEntry(wfs, fullFilePath)
  29. if err != nil {
  30. glog.V(1).Infof("dir GetEntry %s: %v", fullFilePath, err)
  31. return fuse.ENOENT
  32. }
  33. localEntry = filer.FromPbEntry(string(dirPath), entry)
  34. } else {
  35. glog.V(4).Infof("dir Lookup cache hit %s", fullFilePath)
  36. }
  37. if localEntry == nil {
  38. return fuse.ENOENT
  39. }
  40. inode := wfs.inodeToPath.GetInode(fullFilePath)
  41. wfs.outputEntry(out, inode, localEntry)
  42. return fuse.OK
  43. }