Skip to content

Commit

Permalink
Add --fsync-on-close option for close-to-open mode, much slower, but …
Browse files Browse the repository at this point in the history
…similar to Goofys and s3fs
  • Loading branch information
vitalif committed Sep 13, 2023
1 parent 07dc026 commit 3b76753
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions internal/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ type FlagStorage struct {
SinglePartMB uint64
MaxMergeCopyMB uint64
IgnoreFsync bool
FsyncOnClose bool
EnablePerms bool
EnableSpecials bool
EnableMtime bool
Expand Down
6 changes: 6 additions & 0 deletions internal/cfg/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@ MISC OPTIONS:
Usage: "Do not wait until changes are persisted to the server on fsync() call (default: off)",
},

cli.BoolFlag{
Name: "fsync-on-close",
Usage: "Wait until changes are persisted to the server when closing file (default: off)",
},

cli.BoolFlag{
Name: "enable-perms",
Usage: "Enable permissions, user and group ID." +
Expand Down Expand Up @@ -759,6 +764,7 @@ func PopulateFlags(c *cli.Context) (ret *FlagStorage) {
SinglePartMB: uint64(singlePart),
MaxMergeCopyMB: uint64(c.Int("max-merge-copy")),
IgnoreFsync: c.Bool("ignore-fsync"),
FsyncOnClose: c.Bool("fsync-on-close"),
EnablePerms: c.Bool("enable-perms"),
EnableSpecials: c.Bool("enable-specials"),
EnableMtime: c.Bool("enable-mtime"),
Expand Down
24 changes: 15 additions & 9 deletions internal/goofys_fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,19 +523,19 @@ func (fs *GoofysFuse) FlushFile(
func (fs *GoofysFuse) ReleaseFileHandle(
ctx context.Context,
op *fuseops.ReleaseFileHandleOp) (err error) {

fs.mu.Lock()
defer fs.mu.Unlock()
fh := fs.fileHandles[op.Handle]
fh.Release()

atomic.AddInt64(&fs.stats.noops, 1)

fuseLog.Debugln("ReleaseFileHandle", fh.inode.FullName(), op.Handle, fh.inode.Id)

delete(fs.fileHandles, op.Handle)
fs.mu.Unlock()

if fh.inode.fs.flags.FsyncOnClose {
return fh.inode.SyncFile()
}

// try to compact heap
//fs.bufferPool.MaybeGC()
return
}

Expand Down Expand Up @@ -598,14 +598,13 @@ func (fs *GoofysFuse) MkNode(
if (op.Mode & os.ModeDir) != 0 {
inode, err = parent.MkDir(op.Name)
if err != nil {
err = mapAwsError(err)
return err
return mapAwsError(err)
}
} else {
var fh *FileHandle
inode, fh, err = parent.Create(op.Name)
if err != nil {
return err
return mapAwsError(err)
}
fh.Release()
}
Expand All @@ -618,6 +617,13 @@ func (fs *GoofysFuse) MkNode(
op.Entry.EntryExpiration = op.Entry.AttributesExpiration
inode.SetExpireLocked(op.Entry.AttributesExpiration)

if fs.flags.FsyncOnClose {
err = inode.SyncFile()
if err != nil {
return mapAwsError(err)
}
}

return
}

Expand Down
14 changes: 14 additions & 0 deletions internal/goofys_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,13 @@ func (fs *GoofysWin) Mknod(path string, mode uint32, dev uint64) (ret int) {
inode.Attributes.Rdev = uint32(dev)
inode.setFileMode(fuseops.ConvertFileMode(mode))

if fs.flags.FsyncOnClose {
err = inode.SyncFile()
if err != nil {
return mapWinError(err)
}
}

return 0
}

Expand Down Expand Up @@ -647,6 +654,13 @@ func (fs *GoofysWin) Release(path string, fhId uint64) (ret int) {
delete(fs.fileHandles, fuseops.HandleID(fhId))
fs.mu.Unlock()

if fs.flags.FsyncOnClose {
err = fh.inode.SyncFile()
if err != nil {
return mapWinError(err)
}
}

return 0
}

Expand Down

0 comments on commit 3b76753

Please sign in to comment.