github.com/pawelgaczynski/giouring@v0.0.0-20230826085535-69588b89acb9/include.go (about)

     1  // MIT License
     2  //
     3  // Copyright (c) 2023 Paweł Gaczyński
     4  //
     5  // Permission is hereby granted, free of charge, to any person obtaining a
     6  // copy of this software and associated documentation files (the
     7  // "Software"), to deal in the Software without restriction, including
     8  // without limitation the rights to use, copy, modify, merge, publish,
     9  // distribute, sublicense, and/or sell copies of the Software, and to
    10  // permit persons to whom the Software is furnished to do so, subject to
    11  // the following conditions:
    12  //
    13  // The above copyright notice and this permission notice shall be included
    14  // in all copies or substantial portions of the Software.
    15  //
    16  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    17  // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    18  // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    19  // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    20  // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    21  // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    22  // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    23  
    24  package giouring
    25  
    26  import "syscall"
    27  
    28  // liburing: io_uring_sqe
    29  type SubmissionQueueEntry struct {
    30  	OpCode uint8
    31  	Flags  uint8
    32  	IoPrio uint16
    33  	Fd     int32
    34  	// union {
    35  	// 	__u64	off;	/* offset into file */
    36  	// 	__u64	addr2;
    37  	// 	struct {
    38  	// 		__u32	cmd_op;
    39  	// 		__u32	__pad1;
    40  	// 	};
    41  	// };
    42  	Off uint64
    43  	// union {
    44  	// 	__u64	addr;	/* pointer to buffer or iovecs */
    45  	// 	__u64	splice_off_in;
    46  	// };
    47  	Addr uint64
    48  	Len  uint32
    49  	// union {
    50  	// 	__kernel_rwf_t	rw_flags;
    51  	// 	__u32		fsync_flags;
    52  	// 	__u16		poll_events;	/* compatibility */
    53  	// 	__u32		poll32_events;	/* word-reversed for BE */
    54  	// 	__u32		sync_range_flags;
    55  	// 	__u32		msg_flags;
    56  	// 	__u32		timeout_flags;
    57  	// 	__u32		accept_flags;
    58  	// 	__u32		cancel_flags;
    59  	// 	__u32		open_flags;
    60  	// 	__u32		statx_flags;
    61  	// 	__u32		fadvise_advice;
    62  	// 	__u32		splice_flags;
    63  	// 	__u32		rename_flags;
    64  	// 	__u32		unlink_flags;
    65  	// 	__u32		hardlink_flags;
    66  	// 	__u32		xattr_flags;
    67  	// 	__u32		msg_ring_flags;
    68  	// 	__u32		uring_cmd_flags;
    69  	// };
    70  	OpcodeFlags uint32
    71  	UserData    uint64
    72  	// union {
    73  	// 	/* index into fixed buffers, if used */
    74  	// 	__u16	buf_index;
    75  	// 	/* for grouped buffer selection */
    76  	// 	__u16	buf_group;
    77  	// } __attribute__((packed));
    78  	BufIG       uint16
    79  	Personality uint16
    80  	// union {
    81  	// 	__s32	splice_fd_in;
    82  	// 	__u32	file_index;
    83  	// 	struct {
    84  	// 		__u16	addr_len;
    85  	// 		__u16	__pad3[1];
    86  	// 	};
    87  	// };
    88  	SpliceFdIn int32
    89  	Addr3      uint64
    90  	_pad2      [1]uint64
    91  	// TODO: add __u8	cmd[0];
    92  }
    93  
    94  const FileIndexAlloc uint32 = 4294967295
    95  
    96  const (
    97  	SqeFixedFile uint8 = 1 << iota
    98  	SqeIODrain
    99  	SqeIOLink
   100  	SqeIOHardlink
   101  	SqeAsync
   102  	SqeBufferSelect
   103  	SqeCQESkipSuccess
   104  )
   105  
   106  const (
   107  	SetupIOPoll uint32 = 1 << iota
   108  	SetupSQPoll
   109  	SetupSQAff
   110  	SetupCQSize
   111  	SetupClamp
   112  	SetupAttachWQ
   113  	SetupRDisabled
   114  	SetupSubmitAll
   115  	SetupCoopTaskrun
   116  	SetupTaskrunFlag
   117  	SetupSQE128
   118  	SetupCQE32
   119  	SetupSingleIssuer
   120  	SetupDeferTaskrun
   121  	SetupNoMmap
   122  	SetupRegisteredFdOnly
   123  )
   124  
   125  const (
   126  	OpNop uint8 = iota
   127  	OpReadv
   128  	OpWritev
   129  	OpFsync
   130  	OpReadFixed
   131  	OpWriteFixed
   132  	OpPollAdd
   133  	OpPollRemove
   134  	OpSyncFileRange
   135  	OpSendmsg
   136  	OpRecvmsg
   137  	OpTimeout
   138  	OpTimeoutRemove
   139  	OpAccept
   140  	OpAsyncCancel
   141  	OpLinkTimeout
   142  	OpConnect
   143  	OpFallocate
   144  	OpOpenat
   145  	OpClose
   146  	OpFilesUpdate
   147  	OpStatx
   148  	OpRead
   149  	OpWrite
   150  	OpFadvise
   151  	OpMadvise
   152  	OpSend
   153  	OpRecv
   154  	OpOpenat2
   155  	OpEpollCtl
   156  	OpSplice
   157  	OpProvideBuffers
   158  	OpRemoveBuffers
   159  	OpTee
   160  	OpShutdown
   161  	OpRenameat
   162  	OpUnlinkat
   163  	OpMkdirat
   164  	OpSymlinkat
   165  	OpLinkat
   166  	OpMsgRing
   167  	OpFsetxattr
   168  	OpSetxattr
   169  	OpFgetxattr
   170  	OpGetxattr
   171  	OpSocket
   172  	OpUringCmd
   173  	OpSendZC
   174  	OpSendMsgZC
   175  
   176  	OpLast
   177  )
   178  
   179  const UringCmdFixed uint32 = 1 << 0
   180  
   181  const FsyncDatasync uint32 = 1 << 0
   182  
   183  const (
   184  	TimeoutAbs uint32 = 1 << iota
   185  	TimeoutUpdate
   186  	TimeoutBoottime
   187  	TimeoutRealtime
   188  	LinkTimeoutUpdate
   189  	TimeoutETimeSuccess
   190  	TimeoutMultishot
   191  	TimeoutClockMask  = TimeoutBoottime | TimeoutRealtime
   192  	TimeoutUpdateMask = TimeoutUpdate | LinkTimeoutUpdate
   193  )
   194  
   195  const SpliceFFdInFixed uint32 = 1 << 31
   196  
   197  const (
   198  	PollAddMulti uint32 = 1 << iota
   199  	PollUpdateEvents
   200  	PollUpdateUserData
   201  	PollAddLevel
   202  )
   203  
   204  const (
   205  	AsyncCancelAll uint32 = 1 << iota
   206  	AsyncCancelFd
   207  	AsyncCancelAny
   208  	AsyncCancelFdFixed
   209  )
   210  
   211  const (
   212  	RecvsendPollFirst uint16 = 1 << iota
   213  	RecvMultishot
   214  	RecvsendFixedBuf
   215  	SendZCReportUsage
   216  )
   217  
   218  const NotifUsageZCCopied uint32 = 1 << 31
   219  
   220  const (
   221  	AcceptMultishot uint16 = 1 << iota
   222  )
   223  
   224  const (
   225  	MsgData uint32 = iota
   226  	MsgSendFd
   227  )
   228  
   229  var msgDataVar = MsgData
   230  
   231  const (
   232  	MsgRingCQESkip uint32 = 1 << iota
   233  	MsgRingFlagsPass
   234  )
   235  
   236  // liburing: io_uring_cqe
   237  type CompletionQueueEvent struct {
   238  	UserData uint64
   239  	Res      int32
   240  	Flags    uint32
   241  
   242  	// FIXME
   243  	// 	__u64 big_cqe[];
   244  }
   245  
   246  const (
   247  	CQEFBuffer uint32 = 1 << iota
   248  	CQEFMore
   249  	CQEFSockNonempty
   250  	CQEFNotif
   251  )
   252  
   253  const CQEBufferShift uint32 = 16
   254  
   255  // Magic offsets for the application to mmap the data it needs.
   256  const (
   257  	offsqRing    uint64 = 0
   258  	offcqRing    uint64 = 0x8000000
   259  	offSQEs      uint64 = 0x10000000
   260  	offPbufRing  uint64 = 0x80000000
   261  	offPbufShift uint64 = 16
   262  	offMmapMask  uint64 = 0xf8000000
   263  )
   264  
   265  // liburing: io_sqring_offsets
   266  type SQRingOffsets struct {
   267  	head        uint32
   268  	tail        uint32
   269  	ringMask    uint32
   270  	ringEntries uint32
   271  	flags       uint32
   272  	dropped     uint32
   273  	array       uint32
   274  	resv1       uint32
   275  	userAddr    uint64
   276  }
   277  
   278  const (
   279  	SQNeedWakeup uint32 = 1 << iota
   280  	SQCQOverflow
   281  	SQTaskrun
   282  )
   283  
   284  // liburing: io_cqring_offsets
   285  type CQRingOffsets struct {
   286  	head        uint32
   287  	tail        uint32
   288  	ringMask    uint32
   289  	ringEntries uint32
   290  	overflow    uint32
   291  	cqes        uint32
   292  	flags       uint32
   293  	resv1       uint32
   294  	userAddr    uint64
   295  }
   296  
   297  const CQEventFdDisabled uint32 = 1 << 0
   298  
   299  const (
   300  	EnterGetEvents uint32 = 1 << iota
   301  	EnterSQWakeup
   302  	EnterSQWait
   303  	EnterExtArg
   304  	EnterRegisteredRing
   305  )
   306  
   307  // liburing: io_uring_params
   308  type Params struct {
   309  	sqEntries    uint32
   310  	cqEntries    uint32
   311  	flags        uint32
   312  	sqThreadCPU  uint32
   313  	sqThreadIdle uint32
   314  	features     uint32
   315  	wqFd         uint32
   316  	resv         [3]uint32
   317  
   318  	sqOff SQRingOffsets
   319  	cqOff CQRingOffsets
   320  }
   321  
   322  const (
   323  	FeatSingleMMap uint32 = 1 << iota
   324  	FeatNoDrop
   325  	FeatSubmitStable
   326  	FeatRWCurPos
   327  	FeatCurPersonality
   328  	FeatFastPoll
   329  	FeatPoll32Bits
   330  	FeatSQPollNonfixed
   331  	FeatExtArg
   332  	FeatNativeWorkers
   333  	FeatRcrcTags
   334  	FeatCQESkip
   335  	FeatLinkedFile
   336  	FeatRegRegRing
   337  )
   338  
   339  const (
   340  	RegisterBuffers uint32 = iota
   341  	UnregisterBuffers
   342  
   343  	RegisterFiles
   344  	UnregisterFiles
   345  
   346  	RegisterEventFD
   347  	UnregisterEventFD
   348  
   349  	RegisterFilesUpdate
   350  	RegisterEventFDAsync
   351  	RegisterProbe
   352  
   353  	RegisterPersonality
   354  	UnregisterPersonality
   355  
   356  	RegisterRestrictions
   357  	RegisterEnableRings
   358  
   359  	RegisterFiles2
   360  	RegisterFilesUpdate2
   361  	RegisterBuffers2
   362  	RegisterBuffersUpdate
   363  
   364  	RegisterIOWQAff
   365  	UnregisterIOWQAff
   366  
   367  	RegisterIOWQMaxWorkers
   368  
   369  	RegisterRingFDs
   370  	UnregisterRingFDs
   371  
   372  	RegisterPbufRing
   373  	UnregisterPbufRing
   374  
   375  	RegisterSyncCancel
   376  
   377  	RegisterFileAllocRange
   378  
   379  	RegisterLast
   380  
   381  	RegisterUseRegisteredRing = 1 << 31
   382  )
   383  
   384  const (
   385  	IOWQBound uint = iota
   386  	IOWQUnbound
   387  )
   388  
   389  // liburing: io_uring_files_update
   390  type FilesUpdate struct {
   391  	Offset uint32
   392  	Resv   uint32
   393  	Fds    uint64
   394  }
   395  
   396  const (
   397  	RsrcRegisterSparse uint32 = 1 << iota
   398  )
   399  
   400  // liburing: io_uring_rsrc_register
   401  type RsrcRegister struct {
   402  	Nr    uint32
   403  	Flags uint32
   404  	Resv2 uint64
   405  	Data  uint64
   406  	Tags  uint64
   407  }
   408  
   409  // liburing: io_uring_rsrc_update
   410  type RsrcUpdate struct {
   411  	Offset uint32
   412  	Resv   uint32
   413  	Data   uint64
   414  }
   415  
   416  // liburing: io_uring_rsrc_update2
   417  type RsrcUpdate2 struct {
   418  	Offset uint32
   419  	Resv   uint32
   420  	Data   uint64
   421  	Tags   uint64
   422  	Nr     uint32
   423  	Resv2  uint32
   424  }
   425  
   426  const RegisterFilesSkip int = -2
   427  
   428  const opSupported uint16 = 1 << 0
   429  
   430  // liburing: io_uring_probe_op
   431  type ProbeOp struct {
   432  	Op    uint8
   433  	Res   uint8
   434  	Flags uint16
   435  	Res2  uint32
   436  }
   437  
   438  // liburing: io_uring_probe
   439  type Probe struct {
   440  	LastOp uint8
   441  	OpsLen uint8
   442  	Res    uint16
   443  	Res2   [3]uint32
   444  	Ops    [probeOpsSize]ProbeOp
   445  }
   446  
   447  // liburing: io_uring_restriction
   448  type Restriction struct {
   449  	OpCode uint16
   450  	// union {
   451  	// 	__u8 register_op; /* IORING_RESTRICTION_REGISTER_OP */
   452  	// 	__u8 sqe_op;      /* IORING_RESTRICTION_SQE_OP */
   453  	// 	__u8 sqe_flags;   /* IORING_RESTRICTION_SQE_FLAGS_* */
   454  	// };
   455  	OpFlags uint8
   456  	Resv    uint8
   457  	Resv2   [3]uint32
   458  }
   459  
   460  // liburing: io_uring_buf
   461  // liburing: io_uring_buf_ring
   462  type BufAndRing struct {
   463  	Addr uint64
   464  	Len  uint32
   465  	Bid  uint16
   466  	Tail uint16
   467  }
   468  
   469  const PbufRingMMap = 1
   470  
   471  // liburing: io_uring_buf_reg
   472  type BufReg struct {
   473  	RingAddr    uint64
   474  	RingEntries uint32
   475  	Bgid        uint16
   476  	Pad         uint16
   477  	Resv        [3]uint64
   478  }
   479  
   480  const (
   481  	RestrictionRegisterOp uint32 = iota
   482  	RestrictionSQEOp
   483  	RestrictionSQEFlagsAllowed
   484  	RestrictionSQEFlagsRequired
   485  
   486  	RestrictionLast
   487  )
   488  
   489  // liburing: io_uring_getevents_arg
   490  type GetEventsArg struct {
   491  	sigMask   uint64
   492  	sigMaskSz uint32
   493  	pad       uint32
   494  	ts        uint64
   495  }
   496  
   497  // liburing: io_uring_sync_cancel_reg
   498  type SyncCancelReg struct {
   499  	Addr    uint64
   500  	Fd      int32
   501  	Flags   uint32
   502  	Timeout syscall.Timespec
   503  	Pad     [4]uint64
   504  }
   505  
   506  // liburing: io_uring_file_index_range
   507  type FileIndexRange struct {
   508  	Off  uint32
   509  	Len  uint32
   510  	Resv uint64
   511  }
   512  
   513  // liburing: io_uring_recvmsg_out
   514  type RecvmsgOut struct {
   515  	Namelen    uint32
   516  	ControlLen uint32
   517  	PayloadLen uint32
   518  	Flags      uint32
   519  }
   520  
   521  const (
   522  	SocketUringOpSiocinq = iota
   523  	SocketUringOpSiocoutq
   524  )