return fuse.Status when looking up by inode

This commit is contained in:
chrislu 2022-02-18 00:45:43 -08:00
parent b9cf4f12fc
commit f9d33f70b0
10 changed files with 59 additions and 17 deletions

View file

@ -49,7 +49,8 @@ func newFileHandle(wfs *WFS, handleId FileHandleId, inode uint64, entry *filer_p
} }
func (fh *FileHandle) FullPath() util.FullPath { func (fh *FileHandle) FullPath() util.FullPath {
return fh.wfs.inodeToPath.GetPath(fh.inode) fp, _ := fh.wfs.inodeToPath.GetPath(fh.inode)
return fp
} }
func (fh *FileHandle) addChunks(chunks []*filer_pb.FileChunk) { func (fh *FileHandle) addChunks(chunks []*filer_pb.FileChunk) {

View file

@ -3,6 +3,7 @@ package mount
import ( import (
"github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/util" "github.com/chrislusf/seaweedfs/weed/util"
"github.com/hanwen/go-fuse/v2/fuse"
"sync" "sync"
) )
@ -65,14 +66,14 @@ func (i *InodeToPath) GetInode(path util.FullPath) uint64 {
return inode return inode
} }
func (i *InodeToPath) GetPath(inode uint64) util.FullPath { func (i *InodeToPath) GetPath(inode uint64) (util.FullPath, fuse.Status) {
i.RLock() i.RLock()
defer i.RUnlock() defer i.RUnlock()
path, found := i.inode2path[inode] path, found := i.inode2path[inode]
if !found { if !found {
glog.Fatalf("not found inode %d", inode) return "", fuse.ENOENT
} }
return path.FullPath return path.FullPath, fuse.OK
} }
func (i *InodeToPath) HasPath(path util.FullPath) bool { func (i *InodeToPath) HasPath(path util.FullPath) bool {

View file

@ -2,6 +2,7 @@ package mount
import ( import (
"context" "context"
"fmt"
"github.com/chrislusf/seaweedfs/weed/filer" "github.com/chrislusf/seaweedfs/weed/filer"
"github.com/chrislusf/seaweedfs/weed/mount/meta_cache" "github.com/chrislusf/seaweedfs/weed/mount/meta_cache"
"github.com/chrislusf/seaweedfs/weed/pb" "github.com/chrislusf/seaweedfs/weed/pb"
@ -110,7 +111,10 @@ func (wfs *WFS) String() string {
} }
func (wfs *WFS) maybeReadEntry(inode uint64) (path util.FullPath, fh *FileHandle, entry *filer_pb.Entry, status fuse.Status) { func (wfs *WFS) maybeReadEntry(inode uint64) (path util.FullPath, fh *FileHandle, entry *filer_pb.Entry, status fuse.Status) {
path = wfs.inodeToPath.GetPath(inode) path, status = wfs.inodeToPath.GetPath(inode)
if status != fuse.OK {
return
}
var found bool var found bool
if fh, found = wfs.fhmap.FindFileHandle(inode); found { if fh, found = wfs.fhmap.FindFileHandle(inode); found {
return path, fh, fh.entry, fuse.OK return path, fh, fh.entry, fuse.OK

View file

@ -20,7 +20,10 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strin
return s return s
} }
dirPath := wfs.inodeToPath.GetPath(header.NodeId) dirPath, code := wfs.inodeToPath.GetPath(header.NodeId)
if code != fuse.OK {
return
}
fullFilePath := dirPath.Child(name) fullFilePath := dirPath.Child(name)

View file

@ -37,7 +37,10 @@ func (wfs *WFS) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string, out
}, },
} }
dirFullPath := wfs.inodeToPath.GetPath(in.NodeId) dirFullPath, code := wfs.inodeToPath.GetPath(in.NodeId)
if code != fuse.OK {
return
}
entryFullPath := dirFullPath.Child(name) entryFullPath := dirFullPath.Child(name)
@ -89,7 +92,10 @@ func (wfs *WFS) Rmdir(cancel <-chan struct{}, header *fuse.InHeader, name string
return fuse.Status(syscall.ENOTEMPTY) return fuse.Status(syscall.ENOTEMPTY)
} }
dirFullPath := wfs.inodeToPath.GetPath(header.NodeId) dirFullPath, code := wfs.inodeToPath.GetPath(header.NodeId)
if code != fuse.OK {
return
}
entryFullPath := dirFullPath.Child(name) entryFullPath := dirFullPath.Child(name)
glog.V(3).Infof("remove directory: %v", entryFullPath) glog.V(3).Infof("remove directory: %v", entryFullPath)

View file

@ -142,7 +142,10 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
} }
isEarlyTerminated := false isEarlyTerminated := false
dirPath := wfs.inodeToPath.GetPath(input.NodeId) dirPath, code := wfs.inodeToPath.GetPath(input.NodeId)
if code != fuse.OK {
return code
}
var dirEntry fuse.DirEntry var dirEntry fuse.DirEntry
if input.Offset == 0 { if input.Offset == 0 {

View file

@ -54,7 +54,10 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out
}, },
} }
dirFullPath := wfs.inodeToPath.GetPath(in.NodeId) dirFullPath, code := wfs.inodeToPath.GetPath(in.NodeId)
if code != fuse.OK {
return
}
entryFullPath := dirFullPath.Child(name) entryFullPath := dirFullPath.Child(name)
@ -99,7 +102,10 @@ func (wfs *WFS) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string, out
/** Remove a file */ /** Remove a file */
func (wfs *WFS) Unlink(cancel <-chan struct{}, header *fuse.InHeader, name string) (code fuse.Status) { func (wfs *WFS) Unlink(cancel <-chan struct{}, header *fuse.InHeader, name string) (code fuse.Status) {
dirFullPath := wfs.inodeToPath.GetPath(header.NodeId) dirFullPath, code := wfs.inodeToPath.GetPath(header.NodeId)
if code != fuse.OK {
return
}
entryFullPath := dirFullPath.Child(name) entryFullPath := dirFullPath.Child(name)
entry, status := wfs.maybeLoadEntry(entryFullPath) entry, status := wfs.maybeLoadEntry(entryFullPath)

View file

@ -21,8 +21,14 @@ func (wfs *WFS) Link(cancel <-chan struct{}, in *fuse.LinkIn, name string, out *
return s return s
} }
newParentPath := wfs.inodeToPath.GetPath(in.NodeId) newParentPath, code := wfs.inodeToPath.GetPath(in.NodeId)
oldEntryPath := wfs.inodeToPath.GetPath(in.Oldnodeid) if code != fuse.OK {
return
}
oldEntryPath, code := wfs.inodeToPath.GetPath(in.Oldnodeid)
if code != fuse.OK {
return
}
oldParentPath, _ := oldEntryPath.DirAndName() oldParentPath, _ := oldEntryPath.DirAndName()
oldEntry, status := wfs.maybeLoadEntry(oldEntryPath) oldEntry, status := wfs.maybeLoadEntry(oldEntryPath)

View file

@ -145,9 +145,15 @@ func (wfs *WFS) Rename(cancel <-chan struct{}, in *fuse.RenameIn, oldName string
return fuse.EINVAL return fuse.EINVAL
} }
oldDir := wfs.inodeToPath.GetPath(in.NodeId) oldDir, code := wfs.inodeToPath.GetPath(in.NodeId)
if code != fuse.OK {
return
}
oldPath := oldDir.Child(oldName) oldPath := oldDir.Child(oldName)
newDir := wfs.inodeToPath.GetPath(in.Newdir) newDir, code := wfs.inodeToPath.GetPath(in.Newdir)
if code != fuse.OK {
return
}
newPath := newDir.Child(newName) newPath := newDir.Child(newName)
glog.V(4).Infof("dir Rename %s => %s", oldPath, newPath) glog.V(4).Infof("dir Rename %s => %s", oldPath, newPath)

View file

@ -18,7 +18,10 @@ func (wfs *WFS) Symlink(cancel <-chan struct{}, header *fuse.InHeader, target st
return s return s
} }
dirPath := wfs.inodeToPath.GetPath(header.NodeId) dirPath, code := wfs.inodeToPath.GetPath(header.NodeId)
if code != fuse.OK {
return
}
entryFullPath := dirPath.Child(name) entryFullPath := dirPath.Child(name)
request := &filer_pb.CreateEntryRequest{ request := &filer_pb.CreateEntryRequest{
@ -64,7 +67,10 @@ func (wfs *WFS) Symlink(cancel <-chan struct{}, header *fuse.InHeader, target st
} }
func (wfs *WFS) Readlink(cancel <-chan struct{}, header *fuse.InHeader) (out []byte, code fuse.Status) { func (wfs *WFS) Readlink(cancel <-chan struct{}, header *fuse.InHeader) (out []byte, code fuse.Status) {
entryFullPath := wfs.inodeToPath.GetPath(header.NodeId) entryFullPath, code := wfs.inodeToPath.GetPath(header.NodeId)
if code != fuse.OK {
return
}
entry, status := wfs.maybeLoadEntry(entryFullPath) entry, status := wfs.maybeLoadEntry(entryFullPath)
if status != fuse.OK { if status != fuse.OK {