2018-05-23 03:08:46 -07:00
|
|
|
package filesys
|
|
|
|
|
|
|
|
import (
|
2018-05-27 11:52:26 -07:00
|
|
|
"context"
|
2018-05-23 03:08:46 -07:00
|
|
|
"fmt"
|
2020-06-09 18:04:40 -07:00
|
|
|
"io"
|
2020-04-14 11:32:31 -07:00
|
|
|
"net/http"
|
2021-03-16 02:59:26 -07:00
|
|
|
"os"
|
2020-08-23 15:48:02 -07:00
|
|
|
"sync"
|
2019-05-03 00:24:35 -07:00
|
|
|
"time"
|
|
|
|
|
2020-08-06 10:04:17 -07:00
|
|
|
"github.com/seaweedfs/fuse"
|
|
|
|
"github.com/seaweedfs/fuse/fs"
|
|
|
|
|
2020-09-01 00:21:19 -07:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/filer"
|
2018-05-23 03:08:46 -07:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/glog"
|
2018-05-27 11:52:26 -07:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
2018-05-23 03:08:46 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
type FileHandle struct {
|
|
|
|
// cache file has been written to
|
2021-12-28 01:10:35 -08:00
|
|
|
dirtyPages *PageWriter
|
2021-04-14 00:29:58 -07:00
|
|
|
entryViewCache []filer.VisibleInterval
|
|
|
|
reader io.ReaderAt
|
|
|
|
contentType string
|
|
|
|
handle uint64
|
2021-03-22 22:32:47 -07:00
|
|
|
sync.Mutex
|
2018-06-06 02:09:57 -07:00
|
|
|
|
2018-05-25 00:57:25 -07:00
|
|
|
f *File
|
2022-01-17 03:19:11 -08:00
|
|
|
NodeId fuse.NodeID // file or directory the request is about
|
|
|
|
Uid uint32 // user ID of process making request
|
|
|
|
Gid uint32 // group ID of process making request
|
2021-06-15 12:45:20 -07:00
|
|
|
isDeleted bool
|
2018-05-23 03:08:46 -07:00
|
|
|
}
|
|
|
|
|
2021-12-20 01:11:43 -08:00
|
|
|
func newFileHandle(file *File, uid, gid uint32) *FileHandle {
|
2020-04-08 12:50:59 -07:00
|
|
|
fh := &FileHandle{
|
2022-01-17 13:53:30 -08:00
|
|
|
f: file,
|
|
|
|
Uid: uid,
|
|
|
|
Gid: gid,
|
2018-06-06 02:09:57 -07:00
|
|
|
}
|
2022-01-17 13:53:30 -08:00
|
|
|
// dirtyPages: newContinuousDirtyPages(file, writeOnly),
|
|
|
|
fh.dirtyPages = newPageWriter(fh, file.wfs.option.ChunkSizeLimit)
|
2021-03-09 23:08:38 -08:00
|
|
|
entry := fh.f.getEntry()
|
|
|
|
if entry != nil {
|
2021-03-16 02:59:26 -07:00
|
|
|
entry.Attributes.FileSize = filer.FileSize(entry)
|
2020-04-08 12:50:59 -07:00
|
|
|
}
|
2020-08-23 15:48:02 -07:00
|
|
|
|
2020-04-08 12:50:59 -07:00
|
|
|
return fh
|
2018-06-06 02:09:57 -07:00
|
|
|
}
|
|
|
|
|
2018-05-23 03:08:46 -07:00
|
|
|
var _ = fs.Handle(&FileHandle{})
|
2018-05-27 11:52:26 -07:00
|
|
|
|
2018-05-24 01:22:37 -07:00
|
|
|
// var _ = fs.HandleReadAller(&FileHandle{})
|
|
|
|
var _ = fs.HandleReader(&FileHandle{})
|
2018-05-23 03:08:46 -07:00
|
|
|
var _ = fs.HandleFlusher(&FileHandle{})
|
|
|
|
var _ = fs.HandleWriter(&FileHandle{})
|
|
|
|
var _ = fs.HandleReleaser(&FileHandle{})
|
|
|
|
|
2018-05-24 01:22:37 -07:00
|
|
|
func (fh *FileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error {
|
2018-05-23 03:08:46 -07:00
|
|
|
|
2021-03-22 22:32:47 -07:00
|
|
|
fh.Lock()
|
|
|
|
defer fh.Unlock()
|
2020-08-23 15:48:02 -07:00
|
|
|
|
2021-12-19 22:43:14 -08:00
|
|
|
glog.V(4).Infof("%s read fh %d: [%d,%d) size %d resp.Data cap=%d", fh.f.fullpath(), fh.handle, req.Offset, req.Offset+int64(req.Size), req.Size, cap(resp.Data))
|
|
|
|
|
2020-08-23 15:48:02 -07:00
|
|
|
if req.Size <= 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2018-05-23 03:08:46 -07:00
|
|
|
|
2020-08-16 16:24:40 -07:00
|
|
|
buff := resp.Data[:cap(resp.Data)]
|
|
|
|
if req.Size > cap(resp.Data) {
|
|
|
|
// should not happen
|
|
|
|
buff = make([]byte, req.Size)
|
|
|
|
}
|
2020-01-22 13:42:03 -08:00
|
|
|
|
2022-01-17 22:24:44 -08:00
|
|
|
fh.lockForRead(req.Offset, len(buff))
|
|
|
|
defer fh.unlockForRead(req.Offset, len(buff))
|
2020-02-25 22:23:59 -08:00
|
|
|
totalRead, err := fh.readFromChunks(buff, req.Offset)
|
2021-01-18 01:14:42 -08:00
|
|
|
if err == nil || err == io.EOF {
|
2020-08-16 23:47:34 -07:00
|
|
|
maxStop := fh.readFromDirtyPages(buff, req.Offset)
|
2020-08-23 15:48:02 -07:00
|
|
|
totalRead = max(maxStop-req.Offset, totalRead)
|
2020-01-22 13:42:03 -08:00
|
|
|
}
|
|
|
|
|
2020-10-17 11:03:46 -07:00
|
|
|
if err == io.EOF {
|
|
|
|
err = nil
|
|
|
|
}
|
|
|
|
|
2020-01-22 13:42:03 -08:00
|
|
|
if err != nil {
|
2020-08-30 21:01:44 -07:00
|
|
|
glog.Warningf("file handle read %s %d: %v", fh.f.fullpath(), totalRead, err)
|
2020-10-10 15:43:22 -07:00
|
|
|
return fuse.EIO
|
2020-01-22 13:42:03 -08:00
|
|
|
}
|
|
|
|
|
2020-08-17 16:04:56 -07:00
|
|
|
if totalRead > int64(len(buff)) {
|
|
|
|
glog.Warningf("%s FileHandle Read %d: [%d,%d) size %d totalRead %d", fh.f.fullpath(), fh.handle, req.Offset, req.Offset+int64(req.Size), req.Size, totalRead)
|
|
|
|
totalRead = min(int64(len(buff)), totalRead)
|
|
|
|
}
|
2021-01-22 22:39:46 -08:00
|
|
|
if err == nil {
|
|
|
|
resp.Data = buff[:totalRead]
|
|
|
|
}
|
2020-08-16 23:49:10 -07:00
|
|
|
|
2020-01-22 13:42:03 -08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-17 22:24:44 -08:00
|
|
|
func (fh *FileHandle) lockForRead(startOffset int64, size int) {
|
|
|
|
fh.dirtyPages.LockForRead(startOffset, startOffset+int64(size))
|
|
|
|
}
|
|
|
|
func (fh *FileHandle) unlockForRead(startOffset int64, size int) {
|
|
|
|
fh.dirtyPages.UnlockForRead(startOffset, startOffset+int64(size))
|
|
|
|
}
|
|
|
|
|
2020-08-16 23:47:34 -07:00
|
|
|
func (fh *FileHandle) readFromDirtyPages(buff []byte, startOffset int64) (maxStop int64) {
|
2020-08-23 15:48:02 -07:00
|
|
|
maxStop = fh.dirtyPages.ReadDirtyDataAt(buff, startOffset)
|
|
|
|
return
|
2020-01-22 13:42:03 -08:00
|
|
|
}
|
|
|
|
|
2020-02-25 22:23:59 -08:00
|
|
|
func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) {
|
2020-01-22 13:42:03 -08:00
|
|
|
|
2021-03-09 23:08:38 -08:00
|
|
|
entry := fh.f.getEntry()
|
|
|
|
if entry == nil {
|
|
|
|
return 0, io.EOF
|
|
|
|
}
|
|
|
|
|
2021-08-09 22:11:57 -07:00
|
|
|
if entry.IsInRemoteOnly() {
|
|
|
|
glog.V(4).Infof("download remote entry %s", fh.f.fullpath())
|
|
|
|
newEntry, err := fh.f.downloadRemoteEntry(entry)
|
|
|
|
if err != nil {
|
|
|
|
glog.V(1).Infof("download remote entry %s: %v", fh.f.fullpath(), err)
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
entry = newEntry
|
|
|
|
}
|
|
|
|
|
2021-03-16 02:59:26 -07:00
|
|
|
fileSize := int64(filer.FileSize(entry))
|
2021-03-11 14:08:20 -08:00
|
|
|
fileFullPath := fh.f.fullpath()
|
2020-08-16 00:49:08 -07:00
|
|
|
|
|
|
|
if fileSize == 0 {
|
2021-03-11 14:08:20 -08:00
|
|
|
glog.V(1).Infof("empty fh %v", fileFullPath)
|
2020-08-16 00:49:08 -07:00
|
|
|
return 0, io.EOF
|
2018-05-23 03:08:46 -07:00
|
|
|
}
|
|
|
|
|
2021-03-09 23:08:38 -08:00
|
|
|
if offset+int64(len(buff)) <= int64(len(entry.Content)) {
|
|
|
|
totalRead := copy(buff, entry.Content[offset:])
|
2021-03-11 14:08:20 -08:00
|
|
|
glog.V(4).Infof("file handle read cached %s [%d,%d] %d", fileFullPath, offset, offset+int64(totalRead), totalRead)
|
2020-11-30 04:34:04 -08:00
|
|
|
return int64(totalRead), nil
|
|
|
|
}
|
|
|
|
|
2020-07-19 17:59:43 -07:00
|
|
|
var chunkResolveErr error
|
2022-01-17 23:02:30 -08:00
|
|
|
if fh.entryViewCache == nil {
|
2022-02-26 03:00:08 -08:00
|
|
|
fh.entryViewCache, chunkResolveErr = filer.NonOverlappingVisibleIntervals(fh.f.wfs.LookupFn(), entry.Chunks, 0, fileSize)
|
2020-07-19 17:59:43 -07:00
|
|
|
if chunkResolveErr != nil {
|
|
|
|
return 0, fmt.Errorf("fail to resolve chunk manifest: %v", chunkResolveErr)
|
|
|
|
}
|
2021-04-14 00:29:58 -07:00
|
|
|
fh.reader = nil
|
2020-03-22 01:00:36 -07:00
|
|
|
}
|
2020-03-27 04:50:51 -07:00
|
|
|
|
2021-04-14 00:29:58 -07:00
|
|
|
reader := fh.reader
|
2021-01-24 17:19:35 -08:00
|
|
|
if reader == nil {
|
2022-02-26 03:00:08 -08:00
|
|
|
chunkViews := filer.ViewFromVisibleIntervals(fh.entryViewCache, 0, fileSize)
|
2022-01-22 12:35:09 -08:00
|
|
|
glog.V(4).Infof("file handle read %s [%d,%d) from %d views", fileFullPath, offset, offset+int64(len(buff)), len(chunkViews))
|
2022-01-17 14:02:37 -08:00
|
|
|
for _, chunkView := range chunkViews {
|
|
|
|
glog.V(4).Infof(" read %s [%d,%d) from chunk %+v", fileFullPath, chunkView.LogicOffset, chunkView.LogicOffset+int64(chunkView.Size), chunkView.FileId)
|
|
|
|
}
|
2021-01-24 19:03:02 -08:00
|
|
|
reader = filer.NewChunkReaderAtFromClient(fh.f.wfs.LookupFn(), chunkViews, fh.f.wfs.chunkCache, fileSize)
|
2018-12-30 00:51:44 -08:00
|
|
|
}
|
2021-04-14 00:29:58 -07:00
|
|
|
fh.reader = reader
|
2018-12-30 00:51:44 -08:00
|
|
|
|
2021-01-24 17:19:35 -08:00
|
|
|
totalRead, err := reader.ReadAt(buff, offset)
|
2018-05-24 01:22:37 -07:00
|
|
|
|
2020-10-24 20:12:04 -07:00
|
|
|
if err != nil && err != io.EOF {
|
2021-03-11 14:08:20 -08:00
|
|
|
glog.Errorf("file handle read %s: %v", fileFullPath, err)
|
2019-06-20 23:45:30 -07:00
|
|
|
}
|
|
|
|
|
2022-01-17 20:41:00 -08:00
|
|
|
glog.V(4).Infof("file handle read %s [%d,%d] %d : %v", fileFullPath, offset, offset+int64(totalRead), totalRead, err)
|
2020-03-22 01:00:36 -07:00
|
|
|
|
|
|
|
return int64(totalRead), err
|
2018-05-23 03:08:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Write to the file handle
|
|
|
|
func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
|
2018-05-23 20:55:24 -07:00
|
|
|
|
2021-12-28 01:10:35 -08:00
|
|
|
fh.dirtyPages.writerPattern.MonitorWriteAt(req.Offset, len(req.Data))
|
|
|
|
|
2020-08-23 15:48:02 -07:00
|
|
|
fh.Lock()
|
|
|
|
defer fh.Unlock()
|
|
|
|
|
2018-05-23 03:08:46 -07:00
|
|
|
// write the request to volume servers
|
2020-10-20 22:54:21 -07:00
|
|
|
data := req.Data
|
2021-12-19 23:13:36 -08:00
|
|
|
if len(data) <= 512 && req.Offset == 0 {
|
2020-10-23 11:31:57 -07:00
|
|
|
// fuse message cacheable size
|
|
|
|
data = make([]byte, len(req.Data))
|
|
|
|
copy(data, req.Data)
|
|
|
|
}
|
2018-05-23 20:55:24 -07:00
|
|
|
|
2021-03-09 23:08:38 -08:00
|
|
|
entry := fh.f.getEntry()
|
|
|
|
if entry == nil {
|
|
|
|
return fuse.EIO
|
|
|
|
}
|
|
|
|
|
|
|
|
entry.Content = nil
|
2021-03-16 02:59:26 -07:00
|
|
|
entry.Attributes.FileSize = uint64(max(req.Offset+int64(len(data)), int64(entry.Attributes.FileSize)))
|
2021-05-10 21:47:51 -07:00
|
|
|
// glog.V(4).Infof("%v write [%d,%d) %d", fh.f.fullpath(), req.Offset, req.Offset+int64(len(req.Data)), len(req.Data))
|
2020-01-23 21:59:58 -08:00
|
|
|
|
2020-10-14 23:28:03 -07:00
|
|
|
fh.dirtyPages.AddPage(req.Offset, data)
|
2018-05-23 03:08:46 -07:00
|
|
|
|
2020-04-08 22:31:19 -07:00
|
|
|
resp.Size = len(data)
|
2018-05-23 03:08:46 -07:00
|
|
|
|
2018-05-30 20:24:57 -07:00
|
|
|
if req.Offset == 0 {
|
2019-03-27 14:25:18 -07:00
|
|
|
// detect mime type
|
2020-04-14 11:32:31 -07:00
|
|
|
fh.contentType = http.DetectContentType(data)
|
2020-08-15 09:32:47 -07:00
|
|
|
fh.f.dirtyMetadata = true
|
2018-05-30 20:24:57 -07:00
|
|
|
}
|
|
|
|
|
2020-10-14 23:28:03 -07:00
|
|
|
fh.f.dirtyMetadata = true
|
2018-05-23 03:08:46 -07:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fh *FileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) error {
|
|
|
|
|
2021-04-17 10:48:22 -07:00
|
|
|
glog.V(4).Infof("Release %v fh %d open=%d", fh.f.fullpath(), fh.handle, fh.f.isOpen)
|
2018-06-06 02:09:57 -07:00
|
|
|
|
2021-08-11 22:58:35 +09:00
|
|
|
fh.f.wfs.handlesLock.Lock()
|
2021-04-17 10:48:22 -07:00
|
|
|
fh.f.isOpen--
|
2021-08-11 22:58:35 +09:00
|
|
|
fh.f.wfs.handlesLock.Unlock()
|
2021-04-17 10:48:22 -07:00
|
|
|
|
2021-04-20 19:56:51 -07:00
|
|
|
if fh.f.isOpen <= 0 {
|
2021-04-14 20:49:15 -07:00
|
|
|
fh.f.entry = nil
|
2021-04-14 00:29:58 -07:00
|
|
|
fh.entryViewCache = nil
|
|
|
|
fh.reader = nil
|
2020-11-02 14:20:38 -08:00
|
|
|
|
2020-01-22 13:42:03 -08:00
|
|
|
fh.f.wfs.ReleaseHandle(fh.f.fullpath(), fuse.HandleID(fh.handle))
|
2021-12-23 17:17:32 -08:00
|
|
|
fh.dirtyPages.Destroy()
|
2020-01-22 13:42:03 -08:00
|
|
|
}
|
2018-05-25 01:27:21 -07:00
|
|
|
|
2021-04-20 19:56:51 -07:00
|
|
|
if fh.f.isOpen < 0 {
|
|
|
|
glog.V(0).Infof("Release reset %s open count %d => %d", fh.f.Name, fh.f.isOpen, 0)
|
|
|
|
fh.f.isOpen = 0
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-05-23 03:08:46 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (fh *FileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error {
|
2020-08-23 15:48:02 -07:00
|
|
|
|
2021-01-28 04:46:37 -08:00
|
|
|
glog.V(4).Infof("Flush %v fh %d", fh.f.fullpath(), fh.handle)
|
|
|
|
|
2021-06-15 12:45:20 -07:00
|
|
|
if fh.isDeleted {
|
|
|
|
glog.V(4).Infof("Flush %v fh %d skip deleted", fh.f.fullpath(), fh.handle)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-23 15:48:02 -07:00
|
|
|
fh.Lock()
|
|
|
|
defer fh.Unlock()
|
|
|
|
|
2021-01-28 04:46:37 -08:00
|
|
|
if err := fh.doFlush(ctx, req.Header); err != nil {
|
|
|
|
glog.Errorf("Flush doFlush %s: %v", fh.f.Name, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2020-08-19 01:27:10 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
func (fh *FileHandle) doFlush(ctx context.Context, header fuse.Header) error {
|
2020-10-14 23:28:03 -07:00
|
|
|
// flush works at fh level
|
2018-05-23 03:08:46 -07:00
|
|
|
// send the data to the OS
|
2020-08-29 11:56:22 -07:00
|
|
|
glog.V(4).Infof("doFlush %s fh %d", fh.f.fullpath(), fh.handle)
|
2018-05-23 03:08:46 -07:00
|
|
|
|
2021-05-09 15:15:18 -07:00
|
|
|
if err := fh.dirtyPages.FlushData(); err != nil {
|
|
|
|
glog.Errorf("%v doFlush: %v", fh.f.fullpath(), err)
|
2021-01-28 04:46:37 -08:00
|
|
|
return fuse.EIO
|
2020-01-22 23:00:04 -08:00
|
|
|
}
|
2018-05-28 12:30:17 -07:00
|
|
|
|
2020-08-15 09:32:47 -07:00
|
|
|
if !fh.f.dirtyMetadata {
|
2018-05-23 03:08:46 -07:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-26 00:15:03 -08:00
|
|
|
err := fh.f.wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {
|
2018-05-23 03:08:46 -07:00
|
|
|
|
2021-03-09 23:08:38 -08:00
|
|
|
entry := fh.f.getEntry()
|
|
|
|
if entry == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-16 02:59:26 -07:00
|
|
|
if entry.Attributes != nil {
|
|
|
|
entry.Attributes.Mime = fh.contentType
|
|
|
|
if entry.Attributes.Uid == 0 {
|
|
|
|
entry.Attributes.Uid = header.Uid
|
|
|
|
}
|
|
|
|
if entry.Attributes.Gid == 0 {
|
|
|
|
entry.Attributes.Gid = header.Gid
|
|
|
|
}
|
|
|
|
if entry.Attributes.Crtime == 0 {
|
|
|
|
entry.Attributes.Crtime = time.Now().Unix()
|
|
|
|
}
|
|
|
|
entry.Attributes.Mtime = time.Now().Unix()
|
|
|
|
entry.Attributes.FileMode = uint32(os.FileMode(entry.Attributes.FileMode) &^ fh.f.wfs.option.Umask)
|
2021-05-09 15:28:54 -07:00
|
|
|
entry.Attributes.Collection, entry.Attributes.Replication = fh.dirtyPages.GetStorageOptions()
|
2018-07-05 23:16:34 -07:00
|
|
|
}
|
|
|
|
|
2018-09-22 00:11:46 -07:00
|
|
|
request := &filer_pb.CreateEntryRequest{
|
2020-08-28 23:48:48 -07:00
|
|
|
Directory: fh.f.dir.FullPath(),
|
2021-03-16 02:59:26 -07:00
|
|
|
Entry: entry,
|
2020-08-28 23:48:48 -07:00
|
|
|
Signatures: []int32{fh.f.wfs.signature},
|
2018-05-23 03:08:46 -07:00
|
|
|
}
|
|
|
|
|
2021-03-09 23:08:38 -08:00
|
|
|
glog.V(4).Infof("%s set chunks: %v", fh.f.fullpath(), len(entry.Chunks))
|
|
|
|
for i, chunk := range entry.Chunks {
|
2020-08-15 19:55:28 -07:00
|
|
|
glog.V(4).Infof("%s chunks %d: %v [%d,%d)", fh.f.fullpath(), i, chunk.GetFileIdString(), chunk.Offset, chunk.Offset+int64(chunk.Size))
|
2019-06-21 12:14:40 -07:00
|
|
|
}
|
2019-01-01 02:33:57 -08:00
|
|
|
|
2021-03-09 23:08:38 -08:00
|
|
|
manifestChunks, nonManifestChunks := filer.SeparateManifestChunks(entry.Chunks)
|
2020-08-23 16:59:01 -07:00
|
|
|
|
2021-01-24 19:01:58 -08:00
|
|
|
chunks, _ := filer.CompactFileChunks(fh.f.wfs.LookupFn(), nonManifestChunks)
|
2021-12-20 01:11:43 -08:00
|
|
|
chunks, manifestErr := filer.MaybeManifestize(fh.f.wfs.saveDataAsChunk(fh.f.fullpath()), chunks)
|
2020-07-19 17:59:43 -07:00
|
|
|
if manifestErr != nil {
|
|
|
|
// not good, but should be ok
|
|
|
|
glog.V(0).Infof("MaybeManifestize: %v", manifestErr)
|
|
|
|
}
|
2021-03-09 23:08:38 -08:00
|
|
|
entry.Chunks = append(chunks, manifestChunks...)
|
2020-08-06 10:04:17 -07:00
|
|
|
|
2020-09-03 00:07:22 -07:00
|
|
|
fh.f.wfs.mapPbIdFromLocalToFiler(request.Entry)
|
|
|
|
defer fh.f.wfs.mapPbIdFromFilerToLocal(request.Entry)
|
|
|
|
|
2020-02-25 21:50:12 -08:00
|
|
|
if err := filer_pb.CreateEntry(client, request); err != nil {
|
|
|
|
glog.Errorf("fh flush create %s: %v", fh.f.fullpath(), err)
|
|
|
|
return fmt.Errorf("fh flush create %s: %v", fh.f.fullpath(), err)
|
2018-05-23 03:08:46 -07:00
|
|
|
}
|
|
|
|
|
2020-09-01 00:21:19 -07:00
|
|
|
fh.f.wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, request.Entry))
|
2020-04-22 15:40:47 -07:00
|
|
|
|
2018-05-23 03:08:46 -07:00
|
|
|
return nil
|
|
|
|
})
|
2020-01-22 13:42:03 -08:00
|
|
|
|
|
|
|
if err == nil {
|
2020-08-15 09:32:47 -07:00
|
|
|
fh.f.dirtyMetadata = false
|
2020-01-22 13:42:03 -08:00
|
|
|
}
|
|
|
|
|
2020-01-24 01:41:31 -08:00
|
|
|
if err != nil {
|
|
|
|
glog.Errorf("%v fh %d flush: %v", fh.f.fullpath(), fh.handle, err)
|
|
|
|
return fuse.EIO
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
2018-05-23 03:08:46 -07:00
|
|
|
}
|