From 80d6127f109744750d575a78ddd3124cb35be308 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D1=80=D0=B5=D0=BD=D0=B1=D0=B5=D1=80=D0=B3=20?= =?UTF-8?q?=D0=9C=D0=B0=D1=80=D0=BA?= Date: Mon, 9 Sep 2024 17:58:51 +0500 Subject: [PATCH] Add SyncFS support (#160) --- conversions.go | 17 ++++++++++++++++- fuseops/ops.go | 5 +++++ fuseutil/file_system.go | 4 ++++ fuseutil/not_implemented_file_system.go | 6 ++++++ internal/fusekernel/fuse_kernel.go | 14 +++++++++++++- 5 files changed, 44 insertions(+), 2 deletions(-) diff --git a/conversions.go b/conversions.go index 02ce121b..72dee195 100644 --- a/conversions.go +++ b/conversions.go @@ -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{ @@ -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{}))) @@ -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{})))) diff --git a/fuseops/ops.go b/fuseops/ops.go index f6df6d42..9f75541d 100644 --- a/fuseops/ops.go +++ b/fuseops/ops.go @@ -1004,3 +1004,8 @@ type FallocateOp struct { Mode uint32 OpContext OpContext } + +type SyncFSOp struct { + Inode InodeID + OpContext OpContext +} diff --git a/fuseutil/file_system.go b/fuseutil/file_system.go index 43f17918..107e4279 100644 --- a/fuseutil/file_system.go +++ b/fuseutil/file_system.go @@ -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 @@ -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) diff --git a/fuseutil/not_implemented_file_system.go b/fuseutil/not_implemented_file_system.go index cfb116c6..e47e02b0 100644 --- a/fuseutil/not_implemented_file_system.go +++ b/fuseutil/not_implemented_file_system.go @@ -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() { } diff --git a/internal/fusekernel/fuse_kernel.go b/internal/fusekernel/fuse_kernel.go index 3f173512..47d5795e 100644 --- a/internal/fusekernel/fuse_kernel.go +++ b/internal/fusekernel/fuse_kernel.go @@ -46,7 +46,7 @@ const ( ProtoVersionMinMajor = 7 ProtoVersionMinMinor = 18 ProtoVersionMaxMajor = 7 - ProtoVersionMaxMinor = 31 + ProtoVersionMaxMinor = 34 ) const ( @@ -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 @@ -803,3 +811,7 @@ type NotifyInvalEntryOut struct { Namelen uint32 padding uint32 } + +type SyncFSIn struct { + Padding uint64 +}