Skip to content

Commit

Permalink
Add SyncFS support (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
socketpair authored Sep 9, 2024
1 parent bc4b1b5 commit 80d6127
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
17 changes: 16 additions & 1 deletion conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func convertInMessage(
type input fusekernel.FsyncIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
return nil, errors.New("Corrupt OpFsync")
return nil, errors.New("Corrupt OpFsync/OpFsyncdir")
}

o = &fuseops.SyncFileOp{
Expand All @@ -502,6 +502,18 @@ func convertInMessage(
},
}

case fusekernel.OpSyncFS:
type input fusekernel.SyncFSIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
if in == nil {
return nil, errors.New("Corrupt OpSyncFS")
}

o = &fuseops.SyncFSOp{
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
}

case fusekernel.OpFlush:
type input fusekernel.FlushIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
Expand Down Expand Up @@ -969,6 +981,9 @@ func (c *Connection) kernelResponseForOp(
case *fuseops.FallocateOp:
// Empty response

case *fuseops.SyncFSOp:
// Empty response

case *initOp:
out := (*fusekernel.InitOut)(m.Grow(int(unsafe.Sizeof(fusekernel.InitOut{}))))

Expand Down
5 changes: 5 additions & 0 deletions fuseops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -1004,3 +1004,8 @@ type FallocateOp struct {
Mode uint32
OpContext OpContext
}

type SyncFSOp struct {
Inode InodeID
OpContext OpContext
}
4 changes: 4 additions & 0 deletions fuseutil/file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type FileSystem interface {
ListXattr(context.Context, *fuseops.ListXattrOp) error
SetXattr(context.Context, *fuseops.SetXattrOp) error
Fallocate(context.Context, *fuseops.FallocateOp) error
SyncFS(context.Context, *fuseops.SyncFSOp) error

// Regard all inodes (including the root inode) as having their lookup counts
// decremented to zero, and clean up any resources associated with the file
Expand Down Expand Up @@ -236,6 +237,9 @@ func (s *fileSystemServer) handleOp(

case *fuseops.FallocateOp:
err = s.fs.Fallocate(ctx, typed)

case *fuseops.SyncFSOp:
err = s.fs.SyncFS(ctx, typed)
}

c.Reply(ctx, err)
Expand Down
6 changes: 6 additions & 0 deletions fuseutil/not_implemented_file_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,11 @@ func (fs *NotImplementedFileSystem) Fallocate(
return fuse.ENOSYS
}

func (fs *NotImplementedFileSystem) SyncFS(
ctx context.Context,
op *fuseops.SyncFSOp) error {
return fuse.ENOSYS
}

func (fs *NotImplementedFileSystem) Destroy() {
}
14 changes: 13 additions & 1 deletion internal/fusekernel/fuse_kernel.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const (
ProtoVersionMinMajor = 7
ProtoVersionMinMinor = 18
ProtoVersionMaxMajor = 7
ProtoVersionMaxMinor = 31
ProtoVersionMaxMinor = 34
)

const (
Expand Down Expand Up @@ -391,6 +391,14 @@ const (
OpPoll = 40 // Linux?
OpBatchForget = 42
OpFallocate = 43
OpReaddirplus = 44
//
OpRename2 = 45
OpLseek = 46
OpCopyFileRange = 47
OpSetupMapping = 48
OpRemoveMapping = 49
OpSyncFS = 50

// OS X
OpSetvolname = 61
Expand Down Expand Up @@ -803,3 +811,7 @@ type NotifyInvalEntryOut struct {
Namelen uint32
padding uint32
}

type SyncFSIn struct {
Padding uint64
}

0 comments on commit 80d6127

Please sign in to comment.