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.

59 lines
1.6 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. println("lookup", name, "dir inode", header.NodeId)
  17. fullFilePath := dirPath.Child(name)
  18. visitErr := meta_cache.EnsureVisited(wfs.metaCache, wfs, dirPath)
  19. if visitErr != nil {
  20. glog.Errorf("dir Lookup %s: %v", dirPath, visitErr)
  21. return fuse.EIO
  22. }
  23. localEntry, cacheErr := wfs.metaCache.FindEntry(context.Background(), fullFilePath)
  24. if cacheErr == filer_pb.ErrNotFound {
  25. return fuse.ENOENT
  26. }
  27. if localEntry == nil {
  28. // glog.V(3).Infof("dir Lookup cache miss %s", fullFilePath)
  29. entry, err := filer_pb.GetEntry(wfs, fullFilePath)
  30. if err != nil {
  31. glog.V(1).Infof("dir GetEntry %s: %v", fullFilePath, err)
  32. return fuse.ENOENT
  33. }
  34. localEntry = filer.FromPbEntry(string(dirPath), entry)
  35. } else {
  36. glog.V(4).Infof("dir Lookup cache hit %s", fullFilePath)
  37. }
  38. if localEntry == nil {
  39. return fuse.ENOENT
  40. }
  41. inode := wfs.inodeToPath.GetInode(fullFilePath)
  42. println("found", name, "inode", inode)
  43. wfs.outputEntry(out, inode, localEntry)
  44. return fuse.OK
  45. }