diff options
| author | chrislu <chris.lu@gmail.com> | 2022-01-10 00:52:16 -0800 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2022-01-10 00:52:16 -0800 |
| commit | cbc055dc2b1cfdea16ae557780a9476b566899fe (patch) | |
| tree | e45b8381abad4b03e6ab5a966f25728b8805daf4 | |
| parent | 19555385f7b99bce0e1f562f3cd4a4f440dd3d8e (diff) | |
| download | seaweedfs-cbc055dc2b1cfdea16ae557780a9476b566899fe.tar.xz seaweedfs-cbc055dc2b1cfdea16ae557780a9476b566899fe.zip | |
mount: file fsync
fix https://github.com/chrislusf/seaweedfs/issues/2561
| -rw-r--r-- | weed/filesys/dir_rename.go | 2 | ||||
| -rw-r--r-- | weed/filesys/file.go | 5 | ||||
| -rw-r--r-- | weed/filesys/wfs.go | 22 |
3 files changed, 27 insertions, 2 deletions
diff --git a/weed/filesys/dir_rename.go b/weed/filesys/dir_rename.go index f28c8af92..a18ed8243 100644 --- a/weed/filesys/dir_rename.go +++ b/weed/filesys/dir_rename.go @@ -114,7 +114,9 @@ func (dir *Dir) handleRenameResponse(ctx context.Context, resp *filer_pb.StreamR if existingHandle, found := dir.wfs.handles[inodeId]; found && existingHandle != nil { glog.V(4).Infof("opened file handle %s => %s", oldPath, newPath) delete(dir.wfs.handles, inodeId) + existingHandle.handle = newPath.AsInode() existingHandle.f.entry.Name = newName + existingHandle.f.id = newPath.AsInode() dir.wfs.handles[newPath.AsInode()] = existingHandle } dir.wfs.handlesLock.Unlock() diff --git a/weed/filesys/file.go b/weed/filesys/file.go index c7652843c..244ed38ea 100644 --- a/weed/filesys/file.go +++ b/weed/filesys/file.go @@ -248,11 +248,12 @@ func (file *File) Listxattr(ctx context.Context, req *fuse.ListxattrRequest, res } func (file *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error { - // fsync works at OS level + // write the file chunks to the filerGrpcAddress glog.V(4).Infof("%s/%s fsync file %+v", file.dir.FullPath(), file.Name, req) - return nil + return file.wfs.Fsync(file, req.Header) + } func (file *File) Forget() { diff --git a/weed/filesys/wfs.go b/weed/filesys/wfs.go index 127c160c4..c9a7ac0a1 100644 --- a/weed/filesys/wfs.go +++ b/weed/filesys/wfs.go @@ -179,6 +179,28 @@ func (wfs *WFS) AcquireHandle(file *File, uid, gid uint32) (fileHandle *FileHand return } +func (wfs *WFS) Fsync(file *File, header fuse.Header) error { + + inodeId := file.Id() + + wfs.handlesLock.Lock() + existingHandle, found := wfs.handles[inodeId] + wfs.handlesLock.Unlock() + + if found && existingHandle != nil && existingHandle.f.isOpen > 0 { + + existingHandle.Add(1) + defer existingHandle.Done() + + existingHandle.Lock() + defer existingHandle.Unlock() + + return existingHandle.doFlush(context.Background(), header) + } + + return nil +} + func (wfs *WFS) ReleaseHandle(fullpath util.FullPath, handleId fuse.HandleID) { wfs.handlesLock.Lock() defer wfs.handlesLock.Unlock() |
