[31bb2e1] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2020 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // iocall.cfa -- |
---|
| 8 | // |
---|
| 9 | // Author : Thierry Delisle |
---|
| 10 | // Created On : Wed Jul 1 14:51:00 2020 |
---|
| 11 | // Last Modified By : |
---|
| 12 | // Last Modified On : |
---|
| 13 | // Update Count : |
---|
| 14 | // |
---|
| 15 | |
---|
[5877b3e] | 16 | #include "bits/defs.hfa" |
---|
| 17 | |
---|
[4b84e35] | 18 | //============================================================================================= |
---|
| 19 | // I/O uring backend |
---|
| 20 | //============================================================================================= |
---|
| 21 | |
---|
[31bb2e1] | 22 | #if defined(HAVE_LINUX_IO_URING_H) |
---|
| 23 | #include <stdint.h> |
---|
| 24 | #include <linux/io_uring.h> |
---|
| 25 | |
---|
| 26 | #include "kernel_private.hfa" |
---|
| 27 | |
---|
| 28 | extern [* struct io_uring_sqe, uint32_t] __submit_alloc( struct __io_data & ring, uint64_t data ); |
---|
| 29 | extern void __submit( struct __io_data & ring, uint32_t idx ); |
---|
| 30 | |
---|
[4b84e35] | 31 | static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd) { |
---|
| 32 | this.opcode = opcode; |
---|
| 33 | #if !defined(IOSQE_ASYNC) |
---|
| 34 | this.flags = 0; |
---|
| 35 | #else |
---|
| 36 | this.flags = IOSQE_ASYNC; |
---|
| 37 | #endif |
---|
| 38 | this.ioprio = 0; |
---|
| 39 | this.fd = fd; |
---|
| 40 | this.off = 0; |
---|
| 41 | this.addr = 0; |
---|
| 42 | this.len = 0; |
---|
| 43 | this.rw_flags = 0; |
---|
| 44 | this.__pad2[0] = this.__pad2[1] = this.__pad2[2] = 0; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | static inline void ?{}(struct io_uring_sqe & this, uint8_t opcode, int fd, void * addr, uint32_t len, uint64_t off ) { |
---|
| 48 | (this){ opcode, fd }; |
---|
| 49 | this.off = off; |
---|
| 50 | this.addr = (uint64_t)(uintptr_t)addr; |
---|
| 51 | this.len = len; |
---|
| 52 | } |
---|
[31bb2e1] | 53 | |
---|
| 54 | #define __submit_prelude \ |
---|
| 55 | __io_user_data_t data = { 0, active_thread() }; \ |
---|
| 56 | struct __io_data & ring = *data.thrd->curr_cluster->io; \ |
---|
| 57 | struct io_uring_sqe * sqe; \ |
---|
| 58 | uint32_t idx; \ |
---|
| 59 | [sqe, idx] = __submit_alloc( ring, (uint64_t)(uintptr_t)&data ); |
---|
| 60 | |
---|
| 61 | #define __submit_wait \ |
---|
| 62 | /*__cfaabi_bits_print_safe( STDERR_FILENO, "Preparing user data %p for %p\n", &data, data.thrd );*/ \ |
---|
| 63 | verify( sqe->user_data == (uint64_t)(uintptr_t)&data ); \ |
---|
| 64 | __submit( ring, idx ); \ |
---|
| 65 | park( __cfaabi_dbg_ctx ); \ |
---|
| 66 | return data.result; |
---|
[4b84e35] | 67 | #endif |
---|
[31bb2e1] | 68 | |
---|
[4b84e35] | 69 | //============================================================================================= |
---|
| 70 | // I/O Forwards |
---|
| 71 | //============================================================================================= |
---|
[31bb2e1] | 72 | |
---|
[4b84e35] | 73 | // Some forward declarations |
---|
[cf48a14] | 74 | #include <errno.h> |
---|
[4b84e35] | 75 | #include <unistd.h> |
---|
| 76 | |
---|
| 77 | extern "C" { |
---|
| 78 | #include <sys/types.h> |
---|
| 79 | #include <sys/socket.h> |
---|
| 80 | #include <sys/syscall.h> |
---|
| 81 | |
---|
| 82 | #if defined(HAVE_PREADV2) |
---|
| 83 | struct iovec; |
---|
| 84 | extern ssize_t preadv2 (int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); |
---|
| 85 | #endif |
---|
| 86 | #if defined(HAVE_PWRITEV2) |
---|
| 87 | struct iovec; |
---|
| 88 | extern ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); |
---|
| 89 | #endif |
---|
| 90 | |
---|
| 91 | extern int fsync(int fd); |
---|
| 92 | extern int sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags); |
---|
| 93 | |
---|
| 94 | struct msghdr; |
---|
| 95 | struct sockaddr; |
---|
| 96 | extern ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags); |
---|
| 97 | extern ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags); |
---|
| 98 | extern ssize_t send(int sockfd, const void *buf, size_t len, int flags); |
---|
| 99 | extern ssize_t recv(int sockfd, void *buf, size_t len, int flags); |
---|
| 100 | extern int accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags); |
---|
| 101 | extern int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); |
---|
| 102 | |
---|
| 103 | extern int fallocate(int fd, int mode, uint64_t offset, uint64_t len); |
---|
| 104 | extern int posix_fadvise(int fd, uint64_t offset, uint64_t len, int advice); |
---|
| 105 | extern int madvise(void *addr, size_t length, int advice); |
---|
| 106 | |
---|
| 107 | extern int openat(int dirfd, const char *pathname, int flags, mode_t mode); |
---|
| 108 | extern int close(int fd); |
---|
| 109 | |
---|
| 110 | extern ssize_t read (int fd, void *buf, size_t count); |
---|
[0a92c78] | 111 | |
---|
| 112 | extern ssize_t splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags); |
---|
| 113 | extern ssize_t tee(int fd_in, int fd_out, size_t len, unsigned int flags); |
---|
[4b84e35] | 114 | } |
---|
[31bb2e1] | 115 | |
---|
[4b84e35] | 116 | //============================================================================================= |
---|
| 117 | // I/O Interface |
---|
| 118 | //============================================================================================= |
---|
[31bb2e1] | 119 | |
---|
[4b84e35] | 120 | //----------------------------------------------------------------------------- |
---|
| 121 | // Asynchronous operations |
---|
| 122 | #if defined(HAVE_PREADV2) |
---|
| 123 | ssize_t cfa_preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) { |
---|
| 124 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READV) |
---|
| 125 | return preadv2(fd, iov, iovcnt, offset, flags); |
---|
[31bb2e1] | 126 | #else |
---|
| 127 | __submit_prelude |
---|
| 128 | |
---|
[4b84e35] | 129 | (*sqe){ IORING_OP_READV, fd, iov, iovcnt, offset }; |
---|
[31bb2e1] | 130 | |
---|
| 131 | __submit_wait |
---|
| 132 | #endif |
---|
| 133 | } |
---|
[20ab637] | 134 | |
---|
| 135 | ssize_t cfa_preadv2_fixed(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) { |
---|
| 136 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READV) |
---|
| 137 | return preadv2(fd, iov, iovcnt, offset, flags); |
---|
| 138 | #else |
---|
| 139 | __submit_prelude |
---|
| 140 | |
---|
| 141 | (*sqe){ IORING_OP_READV, fd, iov, iovcnt, offset }; |
---|
| 142 | sqe->flags |= IOSQE_FIXED_FILE; |
---|
| 143 | |
---|
| 144 | __submit_wait |
---|
| 145 | #endif |
---|
| 146 | } |
---|
[4b84e35] | 147 | #endif |
---|
[31bb2e1] | 148 | |
---|
[4b84e35] | 149 | #if defined(HAVE_PWRITEV2) |
---|
| 150 | ssize_t cfa_pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags) { |
---|
| 151 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITEV) |
---|
| 152 | return pwritev2(fd, iov, iovcnt, offset, flags); |
---|
[31bb2e1] | 153 | #else |
---|
| 154 | __submit_prelude |
---|
| 155 | |
---|
[4b84e35] | 156 | (*sqe){ IORING_OP_WRITEV, fd, iov, iovcnt, offset }; |
---|
[31bb2e1] | 157 | |
---|
| 158 | __submit_wait |
---|
| 159 | #endif |
---|
| 160 | } |
---|
[4b84e35] | 161 | #endif |
---|
[31bb2e1] | 162 | |
---|
[4b84e35] | 163 | int cfa_fsync(int fd) { |
---|
| 164 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FSYNC) |
---|
| 165 | return fsync(fd); |
---|
| 166 | #else |
---|
| 167 | __submit_prelude |
---|
[31bb2e1] | 168 | |
---|
[4b84e35] | 169 | (*sqe){ IORING_OP_FSYNC, fd }; |
---|
[31bb2e1] | 170 | |
---|
[4b84e35] | 171 | __submit_wait |
---|
| 172 | #endif |
---|
| 173 | } |
---|
[31bb2e1] | 174 | |
---|
[4b84e35] | 175 | int cfa_sync_file_range(int fd, int64_t offset, int64_t nbytes, unsigned int flags) { |
---|
| 176 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SYNC_FILE_RANGE) |
---|
| 177 | return sync_file_range(fd, offset, nbytes, flags); |
---|
| 178 | #else |
---|
| 179 | __submit_prelude |
---|
[31bb2e1] | 180 | |
---|
[4b84e35] | 181 | (*sqe){ IORING_OP_SYNC_FILE_RANGE, fd }; |
---|
| 182 | sqe->off = offset; |
---|
| 183 | sqe->len = nbytes; |
---|
| 184 | sqe->sync_range_flags = flags; |
---|
[31bb2e1] | 185 | |
---|
[4b84e35] | 186 | __submit_wait |
---|
| 187 | #endif |
---|
| 188 | } |
---|
[31bb2e1] | 189 | |
---|
| 190 | |
---|
[4b84e35] | 191 | ssize_t cfa_sendmsg(int sockfd, const struct msghdr *msg, int flags) { |
---|
| 192 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SENDMSG) |
---|
| 193 | return sendmsg(sockfd, msg, flags); |
---|
| 194 | #else |
---|
| 195 | __submit_prelude |
---|
[31bb2e1] | 196 | |
---|
[4b84e35] | 197 | (*sqe){ IORING_OP_SENDMSG, sockfd, msg, 1, 0 }; |
---|
| 198 | sqe->msg_flags = flags; |
---|
[31bb2e1] | 199 | |
---|
[4b84e35] | 200 | __submit_wait |
---|
| 201 | #endif |
---|
| 202 | } |
---|
[31bb2e1] | 203 | |
---|
[4b84e35] | 204 | ssize_t cfa_recvmsg(int sockfd, struct msghdr *msg, int flags) { |
---|
| 205 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECVMSG) |
---|
| 206 | return recvmsg(sockfd, msg, flags); |
---|
| 207 | #else |
---|
| 208 | __submit_prelude |
---|
[31bb2e1] | 209 | |
---|
[4b84e35] | 210 | (*sqe){ IORING_OP_RECVMSG, sockfd, msg, 1, 0 }; |
---|
| 211 | sqe->msg_flags = flags; |
---|
[31bb2e1] | 212 | |
---|
[4b84e35] | 213 | __submit_wait |
---|
| 214 | #endif |
---|
| 215 | } |
---|
[31bb2e1] | 216 | |
---|
[4b84e35] | 217 | ssize_t cfa_send(int sockfd, const void *buf, size_t len, int flags) { |
---|
| 218 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SEND) |
---|
| 219 | return send( sockfd, buf, len, flags ); |
---|
| 220 | #else |
---|
| 221 | __submit_prelude |
---|
[31bb2e1] | 222 | |
---|
[4b84e35] | 223 | (*sqe){ IORING_OP_SEND, sockfd }; |
---|
| 224 | sqe->addr = (uint64_t)buf; |
---|
| 225 | sqe->len = len; |
---|
| 226 | sqe->msg_flags = flags; |
---|
[31bb2e1] | 227 | |
---|
[4b84e35] | 228 | __submit_wait |
---|
| 229 | #endif |
---|
| 230 | } |
---|
[31bb2e1] | 231 | |
---|
[4b84e35] | 232 | ssize_t cfa_recv(int sockfd, void *buf, size_t len, int flags) { |
---|
| 233 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_RECV) |
---|
| 234 | return recv( sockfd, buf, len, flags ); |
---|
| 235 | #else |
---|
| 236 | __submit_prelude |
---|
[31bb2e1] | 237 | |
---|
[4b84e35] | 238 | (*sqe){ IORING_OP_RECV, sockfd }; |
---|
| 239 | sqe->addr = (uint64_t)buf; |
---|
| 240 | sqe->len = len; |
---|
| 241 | sqe->msg_flags = flags; |
---|
[31bb2e1] | 242 | |
---|
[4b84e35] | 243 | __submit_wait |
---|
| 244 | #endif |
---|
| 245 | } |
---|
[31bb2e1] | 246 | |
---|
[4b84e35] | 247 | int cfa_accept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags) { |
---|
| 248 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_ACCEPT) |
---|
| 249 | return accept4( sockfd, addr, addrlen, flags ); |
---|
| 250 | #else |
---|
| 251 | __submit_prelude |
---|
[31bb2e1] | 252 | |
---|
[4b84e35] | 253 | (*sqe){ IORING_OP_ACCEPT, sockfd }; |
---|
| 254 | sqe->addr = addr; |
---|
| 255 | sqe->addr2 = addrlen; |
---|
| 256 | sqe->accept_flags = flags; |
---|
[31bb2e1] | 257 | |
---|
[4b84e35] | 258 | __submit_wait |
---|
| 259 | #endif |
---|
| 260 | } |
---|
[31bb2e1] | 261 | |
---|
[4b84e35] | 262 | int cfa_connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { |
---|
| 263 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CONNECT) |
---|
| 264 | return connect( sockfd, addr, addrlen ); |
---|
| 265 | #else |
---|
| 266 | __submit_prelude |
---|
[31bb2e1] | 267 | |
---|
[4b84e35] | 268 | (*sqe){ IORING_OP_CONNECT, sockfd }; |
---|
| 269 | sqe->addr = (uint64_t)addr; |
---|
| 270 | sqe->off = addrlen; |
---|
[31bb2e1] | 271 | |
---|
[4b84e35] | 272 | __submit_wait |
---|
| 273 | #endif |
---|
| 274 | } |
---|
[31bb2e1] | 275 | |
---|
[4b84e35] | 276 | int cfa_fallocate(int fd, int mode, uint64_t offset, uint64_t len) { |
---|
| 277 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FALLOCATE) |
---|
| 278 | return fallocate( fd, mode, offset, len ); |
---|
| 279 | #else |
---|
| 280 | __submit_prelude |
---|
[31bb2e1] | 281 | |
---|
[4b84e35] | 282 | (*sqe){ IORING_OP_FALLOCATE, fd }; |
---|
| 283 | sqe->off = offset; |
---|
| 284 | sqe->len = length; |
---|
| 285 | sqe->mode = mode; |
---|
[31bb2e1] | 286 | |
---|
[4b84e35] | 287 | __submit_wait |
---|
| 288 | #endif |
---|
| 289 | } |
---|
[31bb2e1] | 290 | |
---|
[4b84e35] | 291 | int cfa_fadvise(int fd, uint64_t offset, uint64_t len, int advice) { |
---|
| 292 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_FADVISE) |
---|
| 293 | return posix_fadvise( fd, offset, len, advice ); |
---|
| 294 | #else |
---|
| 295 | __submit_prelude |
---|
[31bb2e1] | 296 | |
---|
[4b84e35] | 297 | (*sqe){ IORING_OP_FADVISE, fd }; |
---|
| 298 | sqe->off = (uint64_t)offset; |
---|
| 299 | sqe->len = length; |
---|
| 300 | sqe->fadvise_advice = advice; |
---|
[31bb2e1] | 301 | |
---|
[4b84e35] | 302 | __submit_wait |
---|
| 303 | #endif |
---|
| 304 | } |
---|
[31bb2e1] | 305 | |
---|
[4b84e35] | 306 | int cfa_madvise(void *addr, size_t length, int advice) { |
---|
| 307 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_MADVISE) |
---|
| 308 | return madvise( addr, length, advice ); |
---|
| 309 | #else |
---|
| 310 | __submit_prelude |
---|
[31bb2e1] | 311 | |
---|
[4b84e35] | 312 | (*sqe){ IORING_OP_MADVISE, 0 }; |
---|
| 313 | sqe->addr = (uint64_t)addr; |
---|
| 314 | sqe->len = length; |
---|
| 315 | sqe->fadvise_advice = advice; |
---|
[31bb2e1] | 316 | |
---|
[4b84e35] | 317 | __submit_wait |
---|
| 318 | #endif |
---|
| 319 | } |
---|
[31bb2e1] | 320 | |
---|
[4b84e35] | 321 | int cfa_openat(int dirfd, const char *pathname, int flags, mode_t mode) { |
---|
| 322 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_OPENAT) |
---|
| 323 | return openat( dirfd, pathname, flags, mode ); |
---|
| 324 | #else |
---|
| 325 | __submit_prelude |
---|
[31bb2e1] | 326 | |
---|
[4b84e35] | 327 | (*sqe){ IORING_OP_OPENAT, dirfd }; |
---|
| 328 | sqe->addr = (uint64_t)pathname; |
---|
| 329 | sqe->open_flags = flags; |
---|
| 330 | sqe->mode = mode; |
---|
[31bb2e1] | 331 | |
---|
[4b84e35] | 332 | __submit_wait |
---|
| 333 | #endif |
---|
| 334 | } |
---|
[31bb2e1] | 335 | |
---|
[4b84e35] | 336 | int cfa_close(int fd) { |
---|
| 337 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_CLOSE) |
---|
| 338 | return close( fd ); |
---|
| 339 | #else |
---|
| 340 | __submit_prelude |
---|
[31bb2e1] | 341 | |
---|
[4b84e35] | 342 | (*sqe){ IORING_OP_CLOSE, fd }; |
---|
| 343 | |
---|
| 344 | __submit_wait |
---|
| 345 | #endif |
---|
| 346 | } |
---|
[31bb2e1] | 347 | |
---|
[519f11c] | 348 | int cfa_statx(int dirfd, const char *pathname, int flags, unsigned int mask, struct statx *statxbuf) { |
---|
| 349 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_STATX) |
---|
[5db836e] | 350 | #if defined(__NR_statx) |
---|
| 351 | return syscall( __NR_statx, dirfd, pathname, flags, mask, statxbuf ); |
---|
| 352 | #else |
---|
| 353 | errno = ENOTSUP; |
---|
| 354 | return -1; |
---|
| 355 | #endif |
---|
[519f11c] | 356 | #else |
---|
| 357 | __submit_prelude |
---|
| 358 | |
---|
| 359 | (*sqe){ IORING_OP_STATX, dirfd, pathname, mask, (uint64_t)statxbuf }; |
---|
| 360 | sqe->flags = flags; |
---|
| 361 | |
---|
| 362 | __submit_wait |
---|
| 363 | #endif |
---|
| 364 | } |
---|
| 365 | |
---|
[4b84e35] | 366 | ssize_t cfa_read(int fd, void *buf, size_t count) { |
---|
| 367 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_READ) |
---|
| 368 | return read( fd, buf, count ); |
---|
| 369 | #else |
---|
| 370 | __submit_prelude |
---|
| 371 | |
---|
| 372 | (*sqe){ IORING_OP_READ, fd, buf, count, 0 }; |
---|
| 373 | |
---|
| 374 | __submit_wait |
---|
| 375 | #endif |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | ssize_t cfa_write(int fd, void *buf, size_t count) { |
---|
| 379 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_WRITE) |
---|
| 380 | return read( fd, buf, count ); |
---|
| 381 | #else |
---|
| 382 | __submit_prelude |
---|
| 383 | |
---|
| 384 | (*sqe){ IORING_OP_WRITE, fd, buf, count, 0 }; |
---|
| 385 | |
---|
| 386 | __submit_wait |
---|
| 387 | #endif |
---|
| 388 | } |
---|
| 389 | |
---|
[0a92c78] | 390 | ssize_t cfa_splice(int fd_in, loff_t *off_in, int fd_out, loff_t *off_out, size_t len, unsigned int flags) { |
---|
| 391 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_SPLICE) |
---|
| 392 | return splice( fd_in, off_in, fd_out, off_out, len, flags ); |
---|
| 393 | #else |
---|
| 394 | __submit_prelude |
---|
| 395 | |
---|
| 396 | (*sqe){ IORING_OP_SPLICE, fd_out, 0p, len, off_out }; |
---|
| 397 | sqe->splice_fd_in = fd_in; |
---|
| 398 | sqe->splice_off_in = off_in; |
---|
| 399 | sqe->splice_flags = flags; |
---|
| 400 | |
---|
| 401 | __submit_wait |
---|
| 402 | #endif |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | ssize_t cfa_tee(int fd_in, int fd_out, size_t len, unsigned int flags) { |
---|
| 406 | #if !defined(HAVE_LINUX_IO_URING_H) || !defined(IORING_OP_TEE) |
---|
| 407 | return tee( fd_in, fd_out, len, flags ); |
---|
| 408 | #else |
---|
| 409 | __submit_prelude |
---|
| 410 | |
---|
| 411 | (*sqe){ IORING_OP_TEE, fd_out, 0p, len, 0 }; |
---|
| 412 | sqe->splice_fd_in = fd_in; |
---|
| 413 | sqe->splice_flags = flags; |
---|
| 414 | |
---|
| 415 | __submit_wait |
---|
| 416 | #endif |
---|
| 417 | } |
---|
| 418 | |
---|
[4b84e35] | 419 | //----------------------------------------------------------------------------- |
---|
| 420 | // Check if a function is asynchronous |
---|
| 421 | |
---|
| 422 | // Macro magic to reduce the size of the following switch case |
---|
| 423 | #define IS_DEFINED_APPLY(f, ...) f(__VA_ARGS__) |
---|
| 424 | #define IS_DEFINED_SECOND(first, second, ...) second |
---|
| 425 | #define IS_DEFINED_TEST(expansion) _CFA_IO_FEATURE_##expansion |
---|
| 426 | #define IS_DEFINED(macro) IS_DEFINED_APPLY( IS_DEFINED_SECOND,IS_DEFINED_TEST(macro) false, true) |
---|
| 427 | |
---|
| 428 | bool has_user_level_blocking( fptr_t func ) { |
---|
| 429 | #if defined(HAVE_LINUX_IO_URING_H) |
---|
| 430 | #if defined(HAVE_PREADV2) |
---|
| 431 | if( /*func == (fptr_t)preadv2 || */ |
---|
| 432 | func == (fptr_t)cfa_preadv2 ) |
---|
| 433 | #define _CFA_IO_FEATURE_IORING_OP_READV , |
---|
| 434 | return IS_DEFINED(IORING_OP_READV); |
---|
[31bb2e1] | 435 | #endif |
---|
| 436 | |
---|
[4b84e35] | 437 | #if defined(HAVE_PWRITEV2) |
---|
| 438 | if( /*func == (fptr_t)pwritev2 || */ |
---|
| 439 | func == (fptr_t)cfa_pwritev2 ) |
---|
| 440 | #define _CFA_IO_FEATURE_IORING_OP_WRITEV , |
---|
| 441 | return IS_DEFINED(IORING_OP_WRITEV); |
---|
[31bb2e1] | 442 | #endif |
---|
| 443 | |
---|
[4b84e35] | 444 | if( /*func == (fptr_t)fsync || */ |
---|
| 445 | func == (fptr_t)cfa_fsync ) |
---|
| 446 | #define _CFA_IO_FEATURE_IORING_OP_FSYNC , |
---|
| 447 | return IS_DEFINED(IORING_OP_FSYNC); |
---|
| 448 | |
---|
| 449 | if( /*func == (fptr_t)ync_file_range || */ |
---|
| 450 | func == (fptr_t)cfa_sync_file_range ) |
---|
| 451 | #define _CFA_IO_FEATURE_IORING_OP_SYNC_FILE_RANGE , |
---|
| 452 | return IS_DEFINED(IORING_OP_SYNC_FILE_RANGE); |
---|
| 453 | |
---|
| 454 | if( /*func == (fptr_t)sendmsg || */ |
---|
| 455 | func == (fptr_t)cfa_sendmsg ) |
---|
| 456 | #define _CFA_IO_FEATURE_IORING_OP_SENDMSG , |
---|
| 457 | return IS_DEFINED(IORING_OP_SENDMSG); |
---|
| 458 | |
---|
| 459 | if( /*func == (fptr_t)recvmsg || */ |
---|
| 460 | func == (fptr_t)cfa_recvmsg ) |
---|
| 461 | #define _CFA_IO_FEATURE_IORING_OP_RECVMSG , |
---|
| 462 | return IS_DEFINED(IORING_OP_RECVMSG); |
---|
| 463 | |
---|
| 464 | if( /*func == (fptr_t)send || */ |
---|
| 465 | func == (fptr_t)cfa_send ) |
---|
| 466 | #define _CFA_IO_FEATURE_IORING_OP_SEND , |
---|
| 467 | return IS_DEFINED(IORING_OP_SEND); |
---|
| 468 | |
---|
| 469 | if( /*func == (fptr_t)recv || */ |
---|
| 470 | func == (fptr_t)cfa_recv ) |
---|
| 471 | #define _CFA_IO_FEATURE_IORING_OP_RECV , |
---|
| 472 | return IS_DEFINED(IORING_OP_RECV); |
---|
| 473 | |
---|
| 474 | if( /*func == (fptr_t)accept4 || */ |
---|
| 475 | func == (fptr_t)cfa_accept4 ) |
---|
| 476 | #define _CFA_IO_FEATURE_IORING_OP_ACCEPT , |
---|
| 477 | return IS_DEFINED(IORING_OP_ACCEPT); |
---|
| 478 | |
---|
| 479 | if( /*func == (fptr_t)connect || */ |
---|
| 480 | func == (fptr_t)cfa_connect ) |
---|
| 481 | #define _CFA_IO_FEATURE_IORING_OP_CONNECT , |
---|
| 482 | return IS_DEFINED(IORING_OP_CONNECT); |
---|
| 483 | |
---|
| 484 | if( /*func == (fptr_t)fallocate || */ |
---|
| 485 | func == (fptr_t)cfa_fallocate ) |
---|
| 486 | #define _CFA_IO_FEATURE_IORING_OP_FALLOCATE , |
---|
| 487 | return IS_DEFINED(IORING_OP_FALLOCATE); |
---|
| 488 | |
---|
| 489 | if( /*func == (fptr_t)posix_fadvise || */ |
---|
| 490 | func == (fptr_t)cfa_fadvise ) |
---|
| 491 | #define _CFA_IO_FEATURE_IORING_OP_FADVISE , |
---|
| 492 | return IS_DEFINED(IORING_OP_FADVISE); |
---|
| 493 | |
---|
| 494 | if( /*func == (fptr_t)madvise || */ |
---|
| 495 | func == (fptr_t)cfa_madvise ) |
---|
| 496 | #define _CFA_IO_FEATURE_IORING_OP_MADVISE , |
---|
| 497 | return IS_DEFINED(IORING_OP_MADVISE); |
---|
| 498 | |
---|
| 499 | if( /*func == (fptr_t)openat || */ |
---|
| 500 | func == (fptr_t)cfa_openat ) |
---|
| 501 | #define _CFA_IO_FEATURE_IORING_OP_OPENAT , |
---|
| 502 | return IS_DEFINED(IORING_OP_OPENAT); |
---|
| 503 | |
---|
| 504 | if( /*func == (fptr_t)close || */ |
---|
| 505 | func == (fptr_t)cfa_close ) |
---|
| 506 | #define _CFA_IO_FEATURE_IORING_OP_CLOSE , |
---|
| 507 | return IS_DEFINED(IORING_OP_CLOSE); |
---|
| 508 | |
---|
| 509 | if( /*func == (fptr_t)read || */ |
---|
| 510 | func == (fptr_t)cfa_read ) |
---|
| 511 | #define _CFA_IO_FEATURE_IORING_OP_READ , |
---|
| 512 | return IS_DEFINED(IORING_OP_READ); |
---|
| 513 | |
---|
| 514 | if( /*func == (fptr_t)write || */ |
---|
| 515 | func == (fptr_t)cfa_write ) |
---|
| 516 | #define _CFA_IO_FEATURE_IORING_OP_WRITE , |
---|
| 517 | return IS_DEFINED(IORING_OP_WRITE); |
---|
[0a92c78] | 518 | |
---|
| 519 | if( /*func == (fptr_t)splice || */ |
---|
[5db836e] | 520 | func == (fptr_t)cfa_splice ) |
---|
[0a92c78] | 521 | #define _CFA_IO_FEATURE_IORING_OP_SPLICE , |
---|
| 522 | return IS_DEFINED(IORING_OP_SPLICE); |
---|
| 523 | |
---|
| 524 | if( /*func == (fptr_t)tee || */ |
---|
| 525 | func == (fptr_t)cfa_tee ) |
---|
| 526 | #define _CFA_IO_FEATURE_IORING_OP_TEE , |
---|
| 527 | return IS_DEFINED(IORING_OP_TEE); |
---|
[4b84e35] | 528 | #endif |
---|
| 529 | |
---|
| 530 | return false; |
---|
| 531 | } |
---|