Commit 4e5298c2 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Really flush fd in LoopbackFile.Flush.

This will catch potential data loss when the underlying storage is
full or faulty.
parent 0c3881b5
......@@ -122,7 +122,6 @@ func (f *LoopbackFile) Write(data []byte, off int64) (uint32, Status) {
return uint32(n), ToStatus(err)
}
// TODO - should bring back close error back to user space.
func (f *LoopbackFile) Release() {
f.lock.Lock()
f.File.Close()
......@@ -130,7 +129,19 @@ func (f *LoopbackFile) Release() {
}
func (f *LoopbackFile) Flush() Status {
return OK
f.lock.Lock()
// Since Flush() may be called for each dup'd fd, we don't
// want to really close the file, we just want to flush. This
// is achieved by closing a dup'd fd.
newFd, err := syscall.Dup(int(f.File.Fd()))
f.lock.Unlock()
if err != nil {
return ToStatus(err)
}
err = syscall.Close(newFd)
return ToStatus(err)
}
func (f *LoopbackFile) Fsync(flags int) (code Status) {
......
......@@ -43,6 +43,7 @@ func (fs *LoopbackFileSystem) GetAttr(name string, context *Context) (a *Attr, c
} else {
err = syscall.Lstat(fullPath, &st)
}
if err != nil {
return nil, ToStatus(err)
}
......
......@@ -5,6 +5,7 @@ import (
"log"
"os"
"sync"
"syscall"
"time"
)
......@@ -147,11 +148,16 @@ func (n *memNodeFile) InnerFile() File {
func (n *memNodeFile) Flush() Status {
code := n.LoopbackFile.Flush()
var a Attr
n.LoopbackFile.GetAttr(&a)
n.node.info.Size = a.Size
n.node.info.Blocks = a.Blocks
return code
if !code.Ok() {
return code
}
st := syscall.Stat_t{}
err := syscall.Stat(n.node.filename(), &st)
n.node.info.Size = uint64(st.Size)
n.node.info.Blocks = uint64(st.Blocks)
return ToStatus(err)
}
func (n *memNode) newFile(f *os.File) File {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment