Skip to content

Commit 54ad710

Browse files
committed
Add PollOp
1 parent ac7ca2c commit 54ad710

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

conversions.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,22 @@ func convertInMessage(
688688
Pid: inMsg.Header().Pid},
689689
}
690690

691+
case fusekernel.OpPoll:
692+
type input fusekernel.PollIn
693+
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
694+
if in == nil {
695+
return nil, errors.New("Corrupt OpPoll")
696+
}
697+
698+
o = &fuseops.PollOp{
699+
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
700+
Handle: fuseops.HandleID(in.Fh),
701+
Kh: in.Kh,
702+
Flags: fusekernel.PollFlags(in.Flags),
703+
Events: fusekernel.PollEvents(in.Events),
704+
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
705+
}
706+
691707
default:
692708
o = &unknownOp{
693709
OpCode: inMsg.Header().Opcode,
@@ -944,6 +960,10 @@ func (c *Connection) kernelResponseForOp(
944960
out.TimeGran = 1
945961
out.MaxPages = o.MaxPages
946962

963+
case *fuseops.PollOp:
964+
out := (*fusekernel.PollOut)(m.Grow(int(unsafe.Sizeof(fusekernel.PollOut{}))))
965+
out.Revents = uint32(o.Revents)
966+
947967
default:
948968
panic(fmt.Sprintf("Unexpected op: %#v", op))
949969
}

fuseops/ops.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,3 +965,28 @@ type FallocateOp struct {
965965
Mode uint32
966966
OpContext OpContext
967967
}
968+
969+
// Request notifications when the file system user calls poll/select or
970+
// similar operations on a file.
971+
type PollOp struct {
972+
// The inode and handle the user wants to poll
973+
Inode InodeID
974+
Handle HandleID
975+
976+
// Kh is the "kernel handle". The reason behind it is that it's allocated
977+
// by the kernel on file allocation and guaranteed to be unique as opposed
978+
// to regular file handles (HandleID) generated by the userland server
979+
// (by us). Kh has to be used in NotifyPollWakeupOut replies.
980+
Kh uint64
981+
982+
// Poll flags
983+
Flags fusekernel.PollFlags
984+
985+
// Requested events
986+
Events fusekernel.PollEvents
987+
988+
// Set by the file system: the actual events that have happened
989+
// since the last poll
990+
Revents fusekernel.PollEvents
991+
OpContext OpContext
992+
}

fuseutil/file_system.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ type FileSystem interface {
6363
ListXattr(context.Context, *fuseops.ListXattrOp) error
6464
SetXattr(context.Context, *fuseops.SetXattrOp) error
6565
Fallocate(context.Context, *fuseops.FallocateOp) error
66+
Poll(context.Context, *fuseops.PollOp) error
6667

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

237238
case *fuseops.FallocateOp:
238239
err = s.fs.Fallocate(ctx, typed)
240+
241+
case *fuseops.PollOp:
242+
err = s.fs.Poll(ctx, typed)
239243
}
240244

241245
c.Reply(ctx, err)

fuseutil/not_implemented_file_system.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,5 +204,11 @@ func (fs *NotImplementedFileSystem) Fallocate(
204204
return fuse.ENOSYS
205205
}
206206

207+
func (fs *NotImplementedFileSystem) Poll(
208+
ctx context.Context,
209+
op *fuseops.PollOp) error {
210+
return fuse.ENOSYS
211+
}
212+
207213
func (fs *NotImplementedFileSystem) Destroy() {
208214
}

0 commit comments

Comments
 (0)