github.com/pawelgaczynski/giouring@v0.0.0-20230826085535-69588b89acb9/prepare.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 ( 27 "syscall" 28 "time" 29 "unsafe" 30 31 "golang.org/x/sys/unix" 32 ) 33 34 // liburing: __io_uring_set_target_fixed_file 35 func (entry *SubmissionQueueEntry) setTargetFixedFile(fileIndex uint32) { 36 entry.SpliceFdIn = int32(fileIndex + 1) 37 } 38 39 // liburing: io_uring_prep_rw 40 func (entry *SubmissionQueueEntry) prepareRW(opcode uint8, fd int, addr uintptr, length uint32, offset uint64) { 41 entry.OpCode = opcode 42 entry.Flags = 0 43 entry.IoPrio = 0 44 entry.Fd = int32(fd) 45 entry.Off = offset 46 entry.Addr = uint64(addr) 47 entry.Len = length 48 entry.UserData = 0 49 entry.BufIG = 0 50 entry.Personality = 0 51 entry.SpliceFdIn = 0 52 } 53 54 // liburing: io_uring_prep_accept - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_accept.3.en.html 55 func (entry *SubmissionQueueEntry) PrepareAccept(fd int, addr uintptr, addrLen uint64, flags uint32) { 56 entry.prepareRW(OpAccept, fd, addr, 0, addrLen) 57 entry.OpcodeFlags = flags 58 } 59 60 // liburing: io_uring_prep_accept_direct - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_accept_direct.3.en.html 61 func (entry *SubmissionQueueEntry) PrepareAcceptDirect( 62 fd int, addr uintptr, addrLen uint64, flags uint32, fileIndex uint32, 63 ) { 64 entry.PrepareAccept(fd, addr, addrLen, flags) 65 66 if fileIndex == FileIndexAlloc { 67 fileIndex-- 68 } 69 70 entry.setTargetFixedFile(fileIndex) 71 } 72 73 // liburing: io_uring_prep_cancel - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_cancel.3.en.html 74 func (entry *SubmissionQueueEntry) PrepareCancel(userData uintptr, flags int) { 75 entry.PrepareCancel64(uint64(userData), flags) 76 } 77 78 // liburing: io_uring_prep_cancel64 - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_cancel64.3.en.html 79 func (entry *SubmissionQueueEntry) PrepareCancel64(userData uint64, flags int) { 80 entry.prepareRW(OpAsyncCancel, -1, 0, 0, 0) 81 entry.Addr = userData 82 entry.OpcodeFlags = uint32(flags) 83 } 84 85 // liburing: io_uring_prep_cancel_fd 86 func (entry *SubmissionQueueEntry) PrepareCancelFd(fd int, flags uint32) { 87 entry.prepareRW(OpAsyncCancel, fd, 0, 0, 0) 88 entry.OpcodeFlags = flags | AsyncCancelFd 89 } 90 91 // liburing: io_uring_prep_close - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_close.3.en.html 92 func (entry *SubmissionQueueEntry) PrepareClose(fd int) { 93 entry.prepareRW(OpClose, fd, 0, 0, 0) 94 } 95 96 // liburing: io_uring_prep_close_direct - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_close_direct.3.en.html 97 func (entry *SubmissionQueueEntry) PrepareCloseDirect(fileIndex uint32) { 98 entry.PrepareClose(0) 99 entry.setTargetFixedFile(fileIndex) 100 } 101 102 // liburing: io_uring_prep_connect - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_connect.3.en.html 103 func (entry *SubmissionQueueEntry) PrepareConnect(fd int, addr *syscall.Sockaddr, addrLen uint64) { 104 entry.prepareRW(OpConnect, fd, uintptr(unsafe.Pointer(addr)), 0, addrLen) 105 } 106 107 // io_uring_prep_fadvise - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_fadvise.3.en.html 108 func (entry *SubmissionQueueEntry) PrepareFadvise(fd int, offset uint64, length int, advise uint32) { 109 entry.prepareRW(OpFadvise, fd, 0, uint32(length), offset) 110 entry.OpcodeFlags = advise 111 } 112 113 // liburing: io_uring_prep_fallocate - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_fallocate.3.en.html 114 func (entry *SubmissionQueueEntry) PrepareFallocate(fd int, mode int, offset, length uint64) { 115 entry.prepareRW(OpFallocate, fd, 0, uint32(mode), offset) 116 entry.Addr = length 117 } 118 119 // liburing: io_uring_prep_fgetxattr - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_fgetxattr.3.en.html 120 func (entry *SubmissionQueueEntry) PrepareFgetxattr(fd int, name, value []byte) { 121 entry.prepareRW(OpFgetxattr, fd, uintptr(unsafe.Pointer(&name)), 122 uint32(len(value)), uint64(uintptr(unsafe.Pointer(&value)))) 123 } 124 125 // liburing: io_uring_prep_files_update - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_files_update.3.en.html 126 func (entry *SubmissionQueueEntry) PrepareFilesUpdate(fds []int, offset int) { 127 entry.prepareRW(OpFilesUpdate, -1, uintptr(unsafe.Pointer(&fds)), uint32(len(fds)), uint64(offset)) 128 } 129 130 // liburing: io_uring_prep_fsetxattr - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_fsetxattr.3.en.html 131 func (entry *SubmissionQueueEntry) PrepareFsetxattr(fd int, name, value []byte, flags int) { 132 entry.prepareRW( 133 OpFsetxattr, fd, uintptr(unsafe.Pointer(&name)), uint32(len(value)), uint64(uintptr(unsafe.Pointer(&value)))) 134 entry.OpcodeFlags = uint32(flags) 135 } 136 137 // liburing: io_uring_prep_fsync - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_fsync.3.en.html 138 func (entry *SubmissionQueueEntry) PrepareFsync(fd int, flags uint32) { 139 entry.prepareRW(OpFsync, fd, 0, 0, 0) 140 entry.OpcodeFlags = flags 141 } 142 143 // liburing: io_uring_prep_getxattr - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_getxattr.3.en.html 144 func (entry *SubmissionQueueEntry) PrepareGetxattr(name, value, path []byte) { 145 entry.prepareRW(OpGetxattr, 0, uintptr(unsafe.Pointer(&name)), 146 uint32(len(value)), uint64(uintptr(unsafe.Pointer(&value)))) 147 entry.Addr3 = uint64(uintptr(unsafe.Pointer(&path))) 148 entry.OpcodeFlags = 0 149 } 150 151 // liburing: io_uring_prep_link - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_link.3.en.html 152 func (entry *SubmissionQueueEntry) PrepareLink(oldPath, newPath []byte, flags int) { 153 entry.PrepareLinkat(unix.AT_FDCWD, oldPath, unix.AT_FDCWD, newPath, flags) 154 } 155 156 // liburing: io_uring_prep_link_timeout - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_link_timeout.3.en.html 157 func (entry *SubmissionQueueEntry) PrepareLinkTimeout(duration time.Duration, flags uint32) { 158 spec := syscall.NsecToTimespec(duration.Nanoseconds()) 159 entry.prepareRW(OpLinkTimeout, -1, uintptr(unsafe.Pointer(&spec)), 1, 0) 160 entry.OpcodeFlags = flags 161 } 162 163 // liburing: io_uring_prep_linkat - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_linkat.3.en.html 164 func (entry *SubmissionQueueEntry) PrepareLinkat(oldFd int, oldPath []byte, newFd int, newPath []byte, flags int) { 165 entry.prepareRW(OpLinkat, oldFd, uintptr(unsafe.Pointer(&oldPath)), 166 uint32(newFd), uint64(uintptr(unsafe.Pointer(&newPath)))) 167 entry.OpcodeFlags = uint32(flags) 168 } 169 170 // liburing: io_uring_prep_madvise - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_madvise.3.en.html 171 func (entry *SubmissionQueueEntry) PrepareMadvise(addr uintptr, length uint, advice int) { 172 entry.prepareRW(OpMadvise, -1, addr, uint32(length), 0) 173 entry.OpcodeFlags = uint32(advice) 174 } 175 176 // liburing: io_uring_prep_mkdir - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_mkdir.3.en.html 177 func (entry *SubmissionQueueEntry) PrepareMkdir(path []byte, mode uint32) { 178 entry.PrepareMkdirat(unix.AT_FDCWD, path, mode) 179 } 180 181 // liburing: io_uring_prep_mkdirat - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_mkdirat.3.en.html 182 func (entry *SubmissionQueueEntry) PrepareMkdirat(dfd int, path []byte, mode uint32) { 183 entry.prepareRW(OpMkdirat, dfd, uintptr(unsafe.Pointer(&path)), mode, 0) 184 } 185 186 // liburing: io_uring_prep_msg_ring - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_msg_ring.3.en.html 187 func (entry *SubmissionQueueEntry) PrepareMsgRing(fd int, length uint32, data uint64, flags uint32) { 188 entry.prepareRW(OpMsgRing, fd, 0, length, data) 189 entry.OpcodeFlags = flags 190 } 191 192 // liburing: io_uring_prep_msg_ring_cqe_flags - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_msg_ring_cqe_flags.3.en.html 193 func (entry *SubmissionQueueEntry) PrepareMsgRingCqeFlags(fd int, length uint32, data uint64, flags, cqeFlags uint32) { 194 entry.prepareRW(OpMsgRing, fd, 0, length, data) 195 entry.OpcodeFlags = MsgRingFlagsPass | flags 196 entry.SpliceFdIn = int32(cqeFlags) 197 } 198 199 // liburing: io_uring_prep_msg_ring_fd - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_msg_ring_fd.3.en.html 200 func (entry *SubmissionQueueEntry) PrepareMsgRingFd(fd int, sourceFd int, targetFd int, data uint64, flags uint32) { 201 entry.prepareRW(OpMsgRing, fd, uintptr(unsafe.Pointer(&msgDataVar)), 0, data) 202 entry.Addr3 = uint64(sourceFd) 203 if uint32(targetFd) == FileIndexAlloc { 204 targetFd-- 205 } 206 entry.setTargetFixedFile(uint32(targetFd)) 207 entry.OpcodeFlags = flags 208 } 209 210 // liburing: io_uring_prep_msg_ring_fd_alloc - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_msg_ring_fd_alloc.3.en.html 211 func (entry *SubmissionQueueEntry) PrepareMsgRingFdAlloc(fd int, sourceFd int, data uint64, flags uint32) { 212 entry.PrepareMsgRingFd(fd, sourceFd, int(FileIndexAlloc), data, flags) 213 } 214 215 // liburing: io_uring_prep_multishot_accept - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_multishot_accept.3.en.html 216 func (entry *SubmissionQueueEntry) PrepareMultishotAccept(fd int, addr uintptr, addrLen uint64, flags int) { 217 entry.PrepareAccept(fd, addr, addrLen, uint32(flags)) 218 entry.IoPrio |= AcceptMultishot 219 } 220 221 // liburing: io_uring_prep_multishot_accept_direct - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_multishot_accept_direct.3.en.html 222 func (entry *SubmissionQueueEntry) PrepareMultishotAcceptDirect(fd int, addr uintptr, addrLen uint64, flags int) { 223 entry.PrepareMultishotAccept(fd, addr, addrLen, flags) 224 entry.setTargetFixedFile(FileIndexAlloc - 1) 225 } 226 227 // liburing: io_uring_prep_nop - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_nop.3.en.html 228 func (entry *SubmissionQueueEntry) PrepareNop() { 229 entry.prepareRW(OpNop, -1, 0, 0, 0) 230 } 231 232 // liburing: io_uring_prep_openat - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_openat.3.en.html 233 func (entry *SubmissionQueueEntry) PrepareOpenat(dfd int, path []byte, flags int, mode uint32) { 234 entry.prepareRW(OpOpenat, dfd, uintptr(unsafe.Pointer(&path)), mode, 0) 235 entry.OpcodeFlags = uint32(flags) 236 } 237 238 // liburing: io_uring_prep_openat2 - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_openat2.3.en.html 239 func (entry *SubmissionQueueEntry) PrepareOpenat2(dfd int, path []byte, openHow *unix.OpenHow) { 240 entry.prepareRW(OpOpenat, dfd, uintptr(unsafe.Pointer(&path)), 241 uint32(unsafe.Sizeof(*openHow)), uint64(uintptr(unsafe.Pointer(openHow)))) 242 } 243 244 // liburing: io_uring_prep_openat2_direct - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_openat2_direct.3.en.html 245 func (entry *SubmissionQueueEntry) PrepareOpenat2Direct(dfd int, path []byte, openHow *unix.OpenHow, fileIndex uint32) { 246 entry.PrepareOpenat2(dfd, path, openHow) 247 if fileIndex == FileIndexAlloc { 248 fileIndex-- 249 } 250 entry.setTargetFixedFile(fileIndex) 251 } 252 253 // liburing: io_uring_prep_openat_direct - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_openat_direct.3.en.html 254 func (entry *SubmissionQueueEntry) PrepareOpenatDirect(dfd int, path []byte, flags int, mode uint32, fileIndex uint32) { 255 entry.PrepareOpenat(dfd, path, flags, mode) 256 if fileIndex == FileIndexAlloc { 257 fileIndex-- 258 } 259 entry.setTargetFixedFile(fileIndex) 260 } 261 262 // liburing: io_uring_prep_poll_add - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_poll_add.3.en.html 263 func (entry *SubmissionQueueEntry) PreparePollAdd(fd int, pollMask uint32) { 264 entry.prepareRW(OpPollAdd, fd, 0, 0, 0) 265 entry.OpcodeFlags = pollMask 266 } 267 268 // liburing: io_uring_prep_poll_multishot - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_poll_multishot.3.en.html 269 func (entry *SubmissionQueueEntry) PreparePollMultishot(fd int, pollMask uint32) { 270 entry.PreparePollAdd(fd, pollMask) 271 entry.Len = PollAddMulti 272 } 273 274 // liburing: io_uring_prep_poll_remove - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_poll_remove.3.en.html 275 func (entry *SubmissionQueueEntry) PreparePollRemove(userData uint64) { 276 entry.prepareRW(OpPollRemove, -1, 0, 0, 0) 277 entry.Addr = userData 278 } 279 280 // liburing: io_uring_prep_poll_update - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_poll_update.3.en.html 281 func (entry *SubmissionQueueEntry) PreparePollUpdate(oldUserData, newUserData uint64, pollMask, flags uint32) { 282 entry.prepareRW(OpPollRemove, -1, 0, flags, newUserData) 283 entry.Addr = oldUserData 284 entry.OpcodeFlags = pollMask 285 } 286 287 // liburing: io_uring_prep_provide_buffers - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_provide_buffers.3.en.html 288 func (entry *SubmissionQueueEntry) PrepareProvideBuffers(addr uintptr, length, nr, bgid, bid int) { 289 entry.prepareRW(OpProvideBuffers, nr, addr, uint32(length), uint64(bid)) 290 entry.BufIG = uint16(bgid) 291 } 292 293 // liburing: io_uring_prep_read - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_read.3.en.html 294 func (entry *SubmissionQueueEntry) PrepareRead(fd int, buf uintptr, nbytes uint32, offset uint64) { 295 entry.prepareRW(OpRead, fd, buf, nbytes, offset) 296 } 297 298 // liburing: io_uring_prep_read_fixed - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_read_fixed.3.en.html 299 func (entry *SubmissionQueueEntry) PrepareReadFixed( 300 fd int, 301 buf uintptr, 302 nbytes uint32, 303 offset uint64, 304 bufIndex int, 305 ) { 306 entry.prepareRW(OpReadFixed, fd, buf, nbytes, offset) 307 entry.BufIG = uint16(bufIndex) 308 } 309 310 // liburing: io_uring_prep_readv - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_readv.3.en.html 311 func (entry *SubmissionQueueEntry) PrepareReadv(fd int, iovecs uintptr, nrVecs uint32, offset uint64) { 312 entry.prepareRW(OpReadv, fd, iovecs, nrVecs, offset) 313 } 314 315 // liburing: io_uring_prep_readv2 - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_readv2.3.en.html 316 func (entry *SubmissionQueueEntry) PrepareReadv2(fd int, iovecs uintptr, nrVecs uint32, offset uint64, flags int) { 317 entry.PrepareReadv(fd, iovecs, nrVecs, offset) 318 entry.OpcodeFlags = uint32(flags) 319 } 320 321 // liburing: io_uring_prep_recv - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_recv.3.en.html 322 func (entry *SubmissionQueueEntry) PrepareRecv( 323 fd int, 324 buf uintptr, 325 length uint32, 326 flags int, 327 ) { 328 entry.prepareRW(OpRecv, fd, buf, length, 0) 329 entry.OpcodeFlags = uint32(flags) 330 } 331 332 // liburing: io_uring_prep_recv_multishot - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_recv_multishot.3.en.html 333 func (entry *SubmissionQueueEntry) PrepareRecvMultishot( 334 fd int, 335 addr uintptr, 336 length uint32, 337 flags int, 338 ) { 339 entry.PrepareRecv(fd, addr, length, flags) 340 entry.IoPrio |= RecvMultishot 341 } 342 343 // liburing: io_uring_prep_recvmsg - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_recvmsg.3.en.html 344 func (entry *SubmissionQueueEntry) PrepareRecvMsg( 345 fd int, 346 msg *syscall.Msghdr, 347 flags uint32, 348 ) { 349 entry.prepareRW(OpRecvmsg, fd, uintptr(unsafe.Pointer(msg)), 1, 0) 350 entry.OpcodeFlags = flags 351 } 352 353 // liburing: io_uring_prep_recvmsg_multishot - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_recvmsg_multishot.3.en.html 354 func (entry *SubmissionQueueEntry) PrepareRecvMsgMultishot( 355 fd int, 356 msg *syscall.Msghdr, 357 flags uint32, 358 ) { 359 entry.PrepareRecvMsg(fd, msg, flags) 360 entry.IoPrio |= RecvMultishot 361 } 362 363 // liburing: io_uring_prep_remove_buffers - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_remove_buffers.3.en.html 364 func (entry *SubmissionQueueEntry) PrepareRemoveBuffers(nr int, bgid int) { 365 entry.prepareRW(OpRemoveBuffers, nr, 0, 0, 0) 366 entry.BufIG = uint16(bgid) 367 } 368 369 // liburing: io_uring_prep_rename - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_rename.3.en.html 370 func (entry *SubmissionQueueEntry) PrepareRename(oldPath, netPath []byte) { 371 entry.PrepareRenameat(unix.AT_FDCWD, oldPath, unix.AT_FDCWD, netPath, 0) 372 } 373 374 // liburing: io_uring_prep_renameat - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_renameat.3.en.html 375 func (entry *SubmissionQueueEntry) PrepareRenameat( 376 oldFd int, oldPath []byte, newFd int, newPath []byte, flags uint32, 377 ) { 378 entry.prepareRW(OpRenameat, oldFd, 379 uintptr(unsafe.Pointer(&oldPath)), uint32(newFd), uint64(uintptr(unsafe.Pointer(&newPath)))) 380 entry.OpcodeFlags = flags 381 } 382 383 // liburing: io_uring_prep_send - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_send.3.en.html 384 func (entry *SubmissionQueueEntry) PrepareSend( 385 fd int, 386 addr uintptr, 387 length uint32, 388 flags int, 389 ) { 390 entry.prepareRW(OpSend, fd, addr, length, 0) 391 entry.OpcodeFlags = uint32(flags) 392 } 393 394 // liburing: io_uring_prep_send_set_addr - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_send_set_addr.3.en.html 395 func (entry *SubmissionQueueEntry) PrepareSendSetAddr(destAddr *syscall.Sockaddr, addrLen uint16) { 396 entry.Off = uint64(uintptr(unsafe.Pointer(destAddr))) 397 // FIXME? 398 entry.SpliceFdIn = int32(addrLen) 399 } 400 401 // liburing: io_uring_prep_send_zc - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_send_zc.3.en.html 402 func (entry *SubmissionQueueEntry) PrepareSendZC(sockFd int, buf []byte, flags int, zcFlags uint32) { 403 entry.prepareRW(OpSendZC, sockFd, uintptr(unsafe.Pointer(&buf)), uint32(len(buf)), 0) 404 entry.OpcodeFlags = uint32(flags) 405 entry.IoPrio = uint16(zcFlags) 406 } 407 408 // liburing: io_uring_prep_send_zc_fixed - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_send_zc_fixed.3.en.html 409 func (entry *SubmissionQueueEntry) PrepareSendZCFixed(sockFd int, buf []byte, flags int, zcFlags, bufIndex uint32) { 410 entry.PrepareSendZC(sockFd, buf, flags, zcFlags) 411 entry.IoPrio |= RecvsendFixedBuf 412 entry.BufIG = uint16(bufIndex) 413 } 414 415 // liburing: io_uring_prep_sendmsg - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_sendmsg.3.en.html 416 func (entry *SubmissionQueueEntry) PrepareSendMsg( 417 fd int, 418 msg *syscall.Msghdr, 419 flags uint32, 420 ) { 421 entry.prepareRW(OpSendmsg, fd, uintptr(unsafe.Pointer(msg)), 1, 0) 422 entry.OpcodeFlags = flags 423 } 424 425 // liburing: io_uring_prep_sendmsg_zc - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_sendmsg_zc.3.en.html 426 func (entry *SubmissionQueueEntry) PrepareSendmsgZC(fd int, msg *syscall.Msghdr, flags uint32) { 427 entry.PrepareSendMsg(fd, msg, flags) 428 entry.OpCode = OpSendMsgZC 429 } 430 431 // liburing: io_uring_prep_sendto - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_sendto.3.en.html 432 func (entry *SubmissionQueueEntry) PrepareSendto( 433 sockFd int, buf []byte, flags int, addr *syscall.Sockaddr, addrLen uint32, 434 ) { 435 entry.PrepareSend(sockFd, uintptr(unsafe.Pointer(&buf)), uint32(len(buf)), flags) 436 entry.PrepareSendSetAddr(addr, uint16(addrLen)) 437 } 438 439 // liburing: io_uring_prep_setxattr - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_setxattr.3.en.html 440 func (entry *SubmissionQueueEntry) PrepareSetxattr(name, value, path []byte, flags int, length uint32) { 441 entry.prepareRW(OpSetxattr, 0, uintptr(unsafe.Pointer(&name)), length, uint64(uintptr(unsafe.Pointer(&value)))) 442 entry.Addr3 = uint64(uintptr(unsafe.Pointer(&path))) 443 entry.OpcodeFlags = uint32(flags) 444 } 445 446 // liburing: io_uring_prep_shutdown - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_shutdown.3.en.html 447 func (entry *SubmissionQueueEntry) PrepareShutdown(fd, how int) { 448 entry.prepareRW(OpShutdown, fd, 0, uint32(how), 0) 449 } 450 451 // liburing: io_uring_prep_socket - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_socket.3.en.html 452 func (entry *SubmissionQueueEntry) PrepareSocket(domain, socketType, protocol int, flags uint32) { 453 entry.prepareRW(OpSocket, domain, 0, uint32(protocol), uint64(socketType)) 454 entry.OpcodeFlags = flags 455 } 456 457 // liburing: io_uring_prep_socket_direct - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_socket_direct.3.en.html 458 func (entry *SubmissionQueueEntry) PrepareSocketDirect(domain, socketType, protocol int, fileIndex, flags uint32) { 459 entry.PrepareSocket(domain, socketType, protocol, flags) 460 if fileIndex == FileIndexAlloc { 461 fileIndex-- 462 } 463 entry.setTargetFixedFile(fileIndex) 464 } 465 466 // liburing: io_uring_prep_socket_direct_alloc - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_socket_direct_alloc.3.en.html 467 func (entry *SubmissionQueueEntry) PrepareSocketDirectAlloc(domain, socketType, protocol int, flags uint32) { 468 entry.PrepareSocket(domain, socketType, protocol, flags) 469 entry.setTargetFixedFile(FileIndexAlloc - 1) 470 } 471 472 // liburing: io_uring_prep_splice - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_splice.3.en.html 473 func (entry *SubmissionQueueEntry) PrepareSplice( 474 fdIn int, offIn int64, fdOut int, offOut int64, nbytes, spliceFlags uint32, 475 ) { 476 entry.prepareRW(OpSplice, fdOut, 0, nbytes, uint64(offOut)) 477 entry.Addr = uint64(offIn) 478 entry.SpliceFdIn = int32(fdIn) 479 entry.OpcodeFlags = spliceFlags 480 } 481 482 // liburing: io_uring_prep_statx - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_statx.3.en.html 483 func (entry *SubmissionQueueEntry) PrepareStatx(dfd int, path []byte, flags int, mask uint32, statx *unix.Statx_t) { 484 entry.prepareRW(OpStatx, dfd, uintptr(unsafe.Pointer(&path)), mask, uint64(uintptr(unsafe.Pointer(statx)))) 485 entry.OpcodeFlags = uint32(flags) 486 } 487 488 // liburing: io_uring_prep_symlink - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_symlink.3.en.html 489 func (entry *SubmissionQueueEntry) PrepareSymlink(target, linkpath []byte) { 490 entry.PrepareSymlinkat(target, unix.AT_FDCWD, linkpath) 491 } 492 493 // liburing: io_uring_prep_symlinkat - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_symlinkat.3.en.html 494 func (entry *SubmissionQueueEntry) PrepareSymlinkat(target []byte, newdirfd int, linkpath []byte) { 495 entry.prepareRW(OpSymlinkat, newdirfd, uintptr(unsafe.Pointer(&target)), 0, uint64(uintptr(unsafe.Pointer(&linkpath)))) 496 } 497 498 // liburing: io_uring_prep_sync_file_range - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_sync_file_range.3.en.html 499 func (entry *SubmissionQueueEntry) PrepareSyncFileRange(fd int, length uint32, offset uint64, flags int) { 500 entry.prepareRW(OpSyncFileRange, fd, 0, length, offset) 501 entry.OpcodeFlags = uint32(flags) 502 } 503 504 // liburing: io_uring_prep_tee - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_tee.3.en.html 505 func (entry *SubmissionQueueEntry) PrepareTee(fdIn, fdOut int, nbytes, spliceFlags uint32) { 506 entry.prepareRW(OpTee, fdOut, 0, nbytes, 0) 507 entry.Addr = 0 508 entry.SpliceFdIn = int32(fdIn) 509 entry.OpcodeFlags = spliceFlags 510 } 511 512 // liburing: io_uring_prep_timeout - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_timeout.3.en.html 513 func (entry *SubmissionQueueEntry) PrepareTimeout(spec *syscall.Timespec, count, flags uint32) { 514 entry.prepareRW(OpTimeout, -1, uintptr(unsafe.Pointer(&spec)), 1, uint64(count)) 515 entry.OpcodeFlags = flags 516 } 517 518 // liburing: io_uring_prep_timeout_remove - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_timeout_remove.3.en.html 519 func (entry *SubmissionQueueEntry) PrepareTimeoutRemove(duration time.Duration, count uint64, flags uint32) { 520 spec := syscall.NsecToTimespec(duration.Nanoseconds()) 521 entry.prepareRW(OpTimeoutRemove, -1, uintptr(unsafe.Pointer(&spec)), 1, count) 522 entry.OpcodeFlags = flags 523 } 524 525 // liburing: io_uring_prep_timeout_update - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_timeout_update.3.en.html 526 func (entry *SubmissionQueueEntry) PrepareTimeoutUpdate(duration time.Duration, count uint64, flags uint32) { 527 spec := syscall.NsecToTimespec(duration.Nanoseconds()) 528 entry.prepareRW(OpTimeoutRemove, -1, uintptr(unsafe.Pointer(&spec)), 1, count) 529 entry.OpcodeFlags = flags | TimeoutUpdate 530 } 531 532 // liburing: io_uring_prep_unlink - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_unlink.3.en.html 533 func (entry *SubmissionQueueEntry) PrepareUnlink(path uintptr, flags int) { 534 entry.PrepareUnlinkat(unix.AT_FDCWD, path, flags) 535 } 536 537 // liburing: io_uring_prep_unlinkat - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_unlinkat.3.en.html 538 func (entry *SubmissionQueueEntry) PrepareUnlinkat(dfd int, path uintptr, flags int) { 539 entry.prepareRW(OpUnlinkat, dfd, path, 0, 0) 540 entry.OpcodeFlags = uint32(flags) 541 } 542 543 // liburing: io_uring_prep_write - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_write.3.en.html 544 func (entry *SubmissionQueueEntry) PrepareWrite(fd int, buf uintptr, nbytes uint32, offset uint64) { 545 entry.prepareRW(OpWrite, fd, buf, nbytes, offset) 546 } 547 548 // liburing: io_uring_prep_write_fixed - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_write_fixed.3.en.html 549 func (entry *SubmissionQueueEntry) PrepareWriteFixed( 550 fd int, 551 vectors uintptr, 552 length uint32, 553 offset uint64, 554 index int, 555 ) { 556 entry.prepareRW(OpWriteFixed, fd, vectors, length, offset) 557 entry.BufIG = uint16(index) 558 } 559 560 // liburing: io_uring_prep_writev - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_writev.3.en.html 561 func (entry *SubmissionQueueEntry) PrepareWritev( 562 fd int, 563 iovecs uintptr, 564 nrVecs uint32, 565 offset uint64, 566 ) { 567 entry.prepareRW(OpWritev, fd, iovecs, nrVecs, offset) 568 } 569 570 // liburing: io_uring_prep_writev2 - https://manpages.debian.org/unstable/liburing-dev/io_uring_prep_writev2.3.en.html 571 func (entry *SubmissionQueueEntry) PrepareWritev2( 572 fd int, 573 iovecs uintptr, 574 nrVecs uint32, 575 offset uint64, 576 flags int, 577 ) { 578 entry.PrepareWritev(fd, iovecs, nrVecs, offset) 579 entry.OpcodeFlags = uint32(flags) 580 } 581 582 const bit32Offset = 32 583 584 // liburing: io_uring_prep_cmd_sock 585 func (entry *SubmissionQueueEntry) PrepareCmdSock( 586 cmdOp int, fd int, _ int, _ int, _ unsafe.Pointer, _ int, 587 ) { 588 // This will be removed once the get/setsockopt() patches land 589 // var unused uintptr 590 // unused = uintptr(optlen) 591 // unused = uintptr(optval) 592 // unused = uintptr(level) 593 // unused = uintptr(optname) 594 // io_uring_prep_rw(IORING_OP_URING_CMD, sqe, fd, nil, 0, 0) 595 entry.prepareRW(OpUringCmd, fd, 0, 0, 0) 596 entry.Off = uint64(cmdOp << bit32Offset) 597 }