Skip to content

Commit c7b4d30

Browse files
committed
Add --fsync-on-close option for close-to-open mode, much slower, but similar to Goofys and s3fs
1 parent 07dc026 commit c7b4d30

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

internal/cfg/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ type FlagStorage struct {
7979
SinglePartMB uint64
8080
MaxMergeCopyMB uint64
8181
IgnoreFsync bool
82+
FsyncOnClose bool
8283
EnablePerms bool
8384
EnableSpecials bool
8485
EnableMtime bool

internal/cfg/flags.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,11 @@ MISC OPTIONS:
403403
Usage: "Do not wait until changes are persisted to the server on fsync() call (default: off)",
404404
},
405405

406+
cli.BoolFlag{
407+
Name: "fsync-on-close",
408+
Usage: "Wait until changes are persisted to the server when closing file (default: off)",
409+
},
410+
406411
cli.BoolFlag{
407412
Name: "enable-perms",
408413
Usage: "Enable permissions, user and group ID." +
@@ -759,6 +764,7 @@ func PopulateFlags(c *cli.Context) (ret *FlagStorage) {
759764
SinglePartMB: uint64(singlePart),
760765
MaxMergeCopyMB: uint64(c.Int("max-merge-copy")),
761766
IgnoreFsync: c.Bool("ignore-fsync"),
767+
FsyncOnClose: c.Bool("fsync-on-close"),
762768
EnablePerms: c.Bool("enable-perms"),
763769
EnableSpecials: c.Bool("enable-specials"),
764770
EnableMtime: c.Bool("enable-mtime"),

internal/goofys_fuse.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -523,19 +523,19 @@ func (fs *GoofysFuse) FlushFile(
523523
func (fs *GoofysFuse) ReleaseFileHandle(
524524
ctx context.Context,
525525
op *fuseops.ReleaseFileHandleOp) (err error) {
526+
526527
fs.mu.Lock()
527-
defer fs.mu.Unlock()
528528
fh := fs.fileHandles[op.Handle]
529529
fh.Release()
530-
531530
atomic.AddInt64(&fs.stats.noops, 1)
532-
533531
fuseLog.Debugln("ReleaseFileHandle", fh.inode.FullName(), op.Handle, fh.inode.Id)
534-
535532
delete(fs.fileHandles, op.Handle)
533+
fs.mu.Unlock()
534+
535+
if fh.inode.fs.flags.FsyncOnClose {
536+
return fh.inode.SyncFile()
537+
}
536538

537-
// try to compact heap
538-
//fs.bufferPool.MaybeGC()
539539
return
540540
}
541541

@@ -598,14 +598,13 @@ func (fs *GoofysFuse) MkNode(
598598
if (op.Mode & os.ModeDir) != 0 {
599599
inode, err = parent.MkDir(op.Name)
600600
if err != nil {
601-
err = mapAwsError(err)
602-
return err
601+
return mapAwsError(err)
603602
}
604603
} else {
605604
var fh *FileHandle
606605
inode, fh, err = parent.Create(op.Name)
607606
if err != nil {
608-
return err
607+
return mapAwsError(err)
609608
}
610609
fh.Release()
611610
}
@@ -618,6 +617,13 @@ func (fs *GoofysFuse) MkNode(
618617
op.Entry.EntryExpiration = op.Entry.AttributesExpiration
619618
inode.SetExpireLocked(op.Entry.AttributesExpiration)
620619

620+
if fs.flags.FsyncOnClose {
621+
err = inode.SyncFile()
622+
if err != nil {
623+
return mapAwsError(err)
624+
}
625+
}
626+
621627
return
622628
}
623629

internal/goofys_windows.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ func (fs *GoofysWin) Mknod(path string, mode uint32, dev uint64) (ret int) {
184184
inode.Attributes.Rdev = uint32(dev)
185185
inode.setFileMode(fuseops.ConvertFileMode(mode))
186186

187+
if fs.flags.FsyncOnClose {
188+
err = inode.SyncFile()
189+
if err != nil {
190+
return mapWinError(err)
191+
}
192+
}
193+
187194
return 0
188195
}
189196

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

657+
if fs.flags.FsyncOnClose {
658+
err := fh.inode.SyncFile()
659+
if err != nil {
660+
return mapWinError(err)
661+
}
662+
}
663+
650664
return 0
651665
}
652666

0 commit comments

Comments
 (0)