mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-12-17 17:51:20 +08:00
mount: internals switch to filer.Entry instead of protobuf
This commit is contained in:
@@ -33,7 +33,7 @@ type File struct {
|
||||
Name string
|
||||
dir *Dir
|
||||
wfs *WFS
|
||||
entry *filer_pb.Entry
|
||||
entry *filer.Entry
|
||||
entryLock sync.RWMutex
|
||||
entryViewCache []filer.VisibleInterval
|
||||
isOpen int
|
||||
@@ -58,16 +58,16 @@ func (file *File) Attr(ctx context.Context, attr *fuse.Attr) (err error) {
|
||||
|
||||
// attr.Inode = file.fullpath().AsInode()
|
||||
attr.Valid = time.Second
|
||||
attr.Mode = os.FileMode(entry.Attributes.FileMode)
|
||||
attr.Size = filer.FileSize(entry)
|
||||
attr.Mode = os.FileMode(entry.Attr.Mode)
|
||||
attr.Size = filer.FileSize2(entry)
|
||||
if file.isOpen > 0 {
|
||||
attr.Size = entry.Attributes.FileSize
|
||||
attr.Size = entry.Attr.FileSize
|
||||
glog.V(4).Infof("file Attr %s, open:%v, size: %d", file.fullpath(), file.isOpen, attr.Size)
|
||||
}
|
||||
attr.Crtime = time.Unix(entry.Attributes.Crtime, 0)
|
||||
attr.Mtime = time.Unix(entry.Attributes.Mtime, 0)
|
||||
attr.Gid = entry.Attributes.Gid
|
||||
attr.Uid = entry.Attributes.Uid
|
||||
attr.Crtime = entry.Attr.Crtime
|
||||
attr.Mtime = entry.Attr.Mtime
|
||||
attr.Gid = entry.Attr.Gid
|
||||
attr.Uid = entry.Attr.Uid
|
||||
attr.Blocks = attr.Size/blockSize + 1
|
||||
attr.BlockSize = uint32(file.wfs.option.ChunkSizeLimit)
|
||||
if entry.HardLinkCounter > 0 {
|
||||
@@ -126,7 +126,7 @@ func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *f
|
||||
if req.Valid.Size() {
|
||||
|
||||
glog.V(4).Infof("%v file setattr set size=%v chunks=%d", file.fullpath(), req.Size, len(entry.Chunks))
|
||||
if req.Size < filer.FileSize(entry) {
|
||||
if req.Size < filer.FileSize2(entry) {
|
||||
// fmt.Printf("truncate %v \n", fullPath)
|
||||
var chunks []*filer_pb.FileChunk
|
||||
var truncatedChunks []*filer_pb.FileChunk
|
||||
@@ -149,32 +149,32 @@ func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *f
|
||||
file.entryViewCache, _ = filer.NonOverlappingVisibleIntervals(file.wfs.LookupFn(), chunks)
|
||||
file.reader = nil
|
||||
}
|
||||
entry.Attributes.FileSize = req.Size
|
||||
entry.Attr.FileSize = req.Size
|
||||
file.dirtyMetadata = true
|
||||
}
|
||||
|
||||
if req.Valid.Mode() {
|
||||
entry.Attributes.FileMode = uint32(req.Mode)
|
||||
entry.Attr.Mode = req.Mode
|
||||
file.dirtyMetadata = true
|
||||
}
|
||||
|
||||
if req.Valid.Uid() {
|
||||
entry.Attributes.Uid = req.Uid
|
||||
entry.Attr.Uid = req.Uid
|
||||
file.dirtyMetadata = true
|
||||
}
|
||||
|
||||
if req.Valid.Gid() {
|
||||
entry.Attributes.Gid = req.Gid
|
||||
entry.Attr.Gid = req.Gid
|
||||
file.dirtyMetadata = true
|
||||
}
|
||||
|
||||
if req.Valid.Crtime() {
|
||||
entry.Attributes.Crtime = req.Crtime.Unix()
|
||||
entry.Attr.Crtime = req.Crtime
|
||||
file.dirtyMetadata = true
|
||||
}
|
||||
|
||||
if req.Valid.Mtime() {
|
||||
entry.Attributes.Mtime = req.Mtime.Unix()
|
||||
entry.Attr.Mtime = req.Mtime
|
||||
file.dirtyMetadata = true
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ func (file *File) Forget() {
|
||||
file.wfs.fsNodeCache.DeleteFsNode(t)
|
||||
}
|
||||
|
||||
func (file *File) maybeLoadEntry(ctx context.Context) (entry *filer_pb.Entry, err error) {
|
||||
func (file *File) maybeLoadEntry(ctx context.Context) (entry *filer.Entry, err error) {
|
||||
entry = file.getEntry()
|
||||
if file.isOpen > 0 {
|
||||
return entry, nil
|
||||
@@ -330,7 +330,7 @@ func (file *File) addChunks(chunks []*filer_pb.FileChunk) {
|
||||
entry.Chunks = append(entry.Chunks, newChunks...)
|
||||
}
|
||||
|
||||
func (file *File) setEntry(entry *filer_pb.Entry) {
|
||||
func (file *File) setEntry(entry *filer.Entry) {
|
||||
file.entryLock.Lock()
|
||||
defer file.entryLock.Unlock()
|
||||
file.entry = entry
|
||||
@@ -346,15 +346,17 @@ func (file *File) clearEntry() {
|
||||
file.reader = nil
|
||||
}
|
||||
|
||||
func (file *File) saveEntry(entry *filer_pb.Entry) error {
|
||||
func (file *File) saveEntry(entry *filer.Entry) error {
|
||||
return file.wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
|
||||
|
||||
file.wfs.mapPbIdFromLocalToFiler(entry)
|
||||
defer file.wfs.mapPbIdFromFilerToLocal(entry)
|
||||
pbEntry := entry.ToProtoEntry()
|
||||
|
||||
file.wfs.mapPbIdFromLocalToFiler(pbEntry)
|
||||
defer file.wfs.mapPbIdFromFilerToLocal(pbEntry)
|
||||
|
||||
request := &filer_pb.UpdateEntryRequest{
|
||||
Directory: file.dir.FullPath(),
|
||||
Entry: entry,
|
||||
Entry: pbEntry,
|
||||
Signatures: []int32{file.wfs.signature},
|
||||
}
|
||||
|
||||
@@ -371,7 +373,7 @@ func (file *File) saveEntry(entry *filer_pb.Entry) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (file *File) getEntry() *filer_pb.Entry {
|
||||
func (file *File) getEntry() *filer.Entry {
|
||||
file.entryLock.RLock()
|
||||
defer file.entryLock.RUnlock()
|
||||
return file.entry
|
||||
|
||||
Reference in New Issue
Block a user