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