From ca8c4538c16aac911664226d78abfa82648baf85 Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Tue, 29 Sep 2020 13:09:04 +0200 Subject: [PATCH] Ensure we can compile io_uring transport on systems that have linux kernel < 5.1 (#10619) Motivation: While we need to have a very recent kernel to run the io_uring transport itself we should allow to compile it with earlier versions to help with our build story. Modifications: - Ensure we can compile on "older systems" - Just enable the profile when we build on linux Result: Less complicated to build io_uring transport --- transport-native-io_uring/pom.xml | 8 ++++++-- transport-native-io_uring/src/main/c/io_uring.h | 5 ++++- .../src/main/c/netty_io_uring_native.c | 3 ++- transport-native-io_uring/src/main/c/syscall.c | 11 +++++++++++ 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/transport-native-io_uring/pom.xml b/transport-native-io_uring/pom.xml index cf8a5043a7..8044bf0d97 100644 --- a/transport-native-io_uring/pom.xml +++ b/transport-native-io_uring/pom.xml @@ -45,11 +45,15 @@ - iouring-native + linux + + + linux + + false - diff --git a/transport-native-io_uring/src/main/c/io_uring.h b/transport-native-io_uring/src/main/c/io_uring.h index 005e674f81..f4e0a8b64a 100644 --- a/transport-native-io_uring/src/main/c/io_uring.h +++ b/transport-native-io_uring/src/main/c/io_uring.h @@ -48,7 +48,10 @@ struct io_uring_sqe { }; __u32 len; /* buffer size or number of iovecs */ union { - __kernel_rwf_t rw_flags; + // IMPORTANT: + // We explicit use 'int __bitwise' here and not ' __kernel_rwf_t' as this may not be present in the + // kernel headers that are used on the system. + int __bitwise rw_flags; __u32 fsync_flags; __u16 poll_events; /* compatibility */ __u32 poll32_events; /* word-reversed for BE */ diff --git a/transport-native-io_uring/src/main/c/netty_io_uring_native.c b/transport-native-io_uring/src/main/c/netty_io_uring_native.c index 02bd7186bd..70314504a5 100644 --- a/transport-native-io_uring/src/main/c/netty_io_uring_native.c +++ b/transport-native-io_uring/src/main/c/netty_io_uring_native.c @@ -201,7 +201,8 @@ static jboolean netty_io_uring_probe(JNIEnv *env, jclass clazz, jint ring_fd, ji jsize opsLen = (*env)->GetArrayLength(env, ops); jint *opsElements = (*env)->GetIntArrayElements(env, ops, 0); - for (int i = 0; i < opsLen; i++) { + int i; + for (i = 0; i < opsLen; i++) { int op = opsElements[i]; if (op > probe->last_op || (probe->ops[op].flags & IO_URING_OP_SUPPORTED) == 0) { goto done; diff --git a/transport-native-io_uring/src/main/c/syscall.c b/transport-native-io_uring/src/main/c/syscall.c index e83bd5021d..01346a7710 100644 --- a/transport-native-io_uring/src/main/c/syscall.c +++ b/transport-native-io_uring/src/main/c/syscall.c @@ -20,6 +20,17 @@ #include #include +// Define syscall numbers if not exists as these are "stable". +#ifndef __NR_io_uring_setup +#define __NR_io_uring_setup 425 +#endif +#ifndef __NR_io_uring_enter +#define __NR_io_uring_enter 426 +#endif +#ifndef __NR_io_uring_register +#define __NR_io_uring_register 427 +#endif + int sys_io_uring_setup(unsigned entries, struct io_uring_params *p) { return syscall(__NR_io_uring_setup, entries, p); }