weedfs_dir_lookup.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package mount
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/filer"
  5. "github.com/chrislusf/seaweedfs/weed/glog"
  6. "github.com/chrislusf/seaweedfs/weed/mount/meta_cache"
  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. if s := checkName(name); s != fuse.OK {
  16. return s
  17. }
  18. dirPath := wfs.inodeToPath.GetPath(header.NodeId)
  19. fullFilePath := dirPath.Child(name)
  20. visitErr := meta_cache.EnsureVisited(wfs.metaCache, wfs, dirPath)
  21. if visitErr != nil {
  22. glog.Errorf("dir Lookup %s: %v", dirPath, visitErr)
  23. return fuse.EIO
  24. }
  25. localEntry, cacheErr := wfs.metaCache.FindEntry(context.Background(), fullFilePath)
  26. if cacheErr == filer_pb.ErrNotFound {
  27. return fuse.ENOENT
  28. }
  29. if localEntry == nil {
  30. // glog.V(3).Infof("dir Lookup cache miss %s", fullFilePath)
  31. entry, err := filer_pb.GetEntry(wfs, fullFilePath)
  32. if err != nil {
  33. glog.V(1).Infof("dir GetEntry %s: %v", fullFilePath, err)
  34. return fuse.ENOENT
  35. }
  36. localEntry = filer.FromPbEntry(string(dirPath), entry)
  37. } else {
  38. glog.V(4).Infof("dir Lookup cache hit %s", fullFilePath)
  39. }
  40. if localEntry == nil {
  41. return fuse.ENOENT
  42. }
  43. inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.IsDirectory())
  44. wfs.outputFilerEntry(out, inode, localEntry)
  45. return fuse.OK
  46. }