Skip to content

Commit

Permalink
Add PollOp
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Mar 28, 2023
1 parent ac7ca2c commit 54ad710
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
20 changes: 20 additions & 0 deletions conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,22 @@ func convertInMessage(
Pid: inMsg.Header().Pid},
}

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

o = &fuseops.PollOp{
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
Handle: fuseops.HandleID(in.Fh),
Kh: in.Kh,
Flags: fusekernel.PollFlags(in.Flags),
Events: fusekernel.PollEvents(in.Events),
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
}

default:
o = &unknownOp{
OpCode: inMsg.Header().Opcode,
Expand Down Expand Up @@ -944,6 +960,10 @@ func (c *Connection) kernelResponseForOp(
out.TimeGran = 1
out.MaxPages = o.MaxPages

case *fuseops.PollOp:
out := (*fusekernel.PollOut)(m.Grow(int(unsafe.Sizeof(fusekernel.PollOut{}))))
out.Revents = uint32(o.Revents)

default:
panic(fmt.Sprintf("Unexpected op: %#v", op))
}
Expand Down
25 changes: 25 additions & 0 deletions fuseops/ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -965,3 +965,28 @@ type FallocateOp struct {
Mode uint32
OpContext OpContext
}

// Request notifications when the file system user calls poll/select or
// similar operations on a file.
type PollOp struct {
// The inode and handle the user wants to poll
Inode InodeID
Handle HandleID

// Kh is the "kernel handle". The reason behind it is that it's allocated
// by the kernel on file allocation and guaranteed to be unique as opposed
// to regular file handles (HandleID) generated by the userland server
// (by us). Kh has to be used in NotifyPollWakeupOut replies.
Kh uint64

// Poll flags
Flags fusekernel.PollFlags

// Requested events
Events fusekernel.PollEvents

// Set by the file system: the actual events that have happened
// since the last poll
Revents fusekernel.PollEvents
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
Poll(context.Context, *fuseops.PollOp) 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.PollOp:
err = s.fs.Poll(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) Poll(
ctx context.Context,
op *fuseops.PollOp) error {
return fuse.ENOSYS
}

func (fs *NotImplementedFileSystem) Destroy() {
}

0 comments on commit 54ad710

Please sign in to comment.