Added native unix common module

Motivation:

unix common tools native C modules were not loaded in netty_io_uring_native.c

```
Caused by: java.lang.UnsatisfiedLinkError: io.netty.channel.unix.LimitsStaticallyReferencedJniMethods.udsSunPathSize()I
        at io.netty.channel.unix.LimitsStaticallyReferencedJniMethods.udsSunPathSize(Native Method)
        at io.netty.channel.unix.Socket.<clinit>(Socket.java:49)
        at io.netty.channel.uring.IOUringServerSocketChannel.<init>(IOUringServerSocketChannel.java:29)
        ... 11 more

```

Modification:

Added unix common tools native in netty_io_uring_native.c and small cleanup

Result:

fix UnsatisfiedLinkError exception
This commit is contained in:
Josef Grieb 2020-07-16 03:03:36 +02:00
parent 247e14a2b1
commit 339d5f1565
5 changed files with 30 additions and 97 deletions

View File

@ -1,34 +0,0 @@
/* SPDX-License-Identifier: MIT */
#ifndef LIBURING_BARRIER_H
#define LIBURING_BARRIER_H
#include <stdatomic.h>
/*
From the kernel documentation file refcount-vs-atomic.rst:
A RELEASE memory ordering guarantees that all prior loads and
stores (all po-earlier instructions) on the same CPU are completed
before the operation. It also guarantees that all po-earlier
stores on the same CPU and all propagated stores from other CPUs
must propagate to all other CPUs before the release operation
(A-cumulative property). This is implemented using
:c:func:`smp_store_release`.
An ACQUIRE memory ordering guarantees that all post loads and
stores (all po-later instructions) on the same CPU are
completed after the acquire operation. It also guarantees that all
po-later stores on the same CPU must propagate to all other CPUs
after the acquire operation executes. This is implemented using
:c:func:`smp_acquire__after_ctrl_dep`.
*/
#define IO_URING_WRITE_ONCE(var, val) \
atomic_store_explicit(&(var), (val), memory_order_relaxed)
#define IO_URING_READ_ONCE(var) \
atomic_load_explicit(&(var), memory_order_relaxed)
#define io_uring_smp_store_release(p, v) \
atomic_store_explicit((p), (v), memory_order_release)
#define io_uring_smp_load_acquire(p) \
atomic_load_explicit((p), memory_order_acquire)
#endif /* defined(LIBURING_BARRIER_H) */

View File

@ -1,5 +1,4 @@
/* SPDX-License-Identifier: MIT */
#include "barrier.h"
#include <linux/io_uring.h>
#include <stddef.h>
#include <stdint.h>
@ -44,39 +43,4 @@ struct io_uring {
int ring_fd;
};
#define io_uring_for_each_cqe(ring, head, cqe) \
/* \
* io_uring_smp_load_acquire() enforces the order of tail \
* and CQE reads. \
*/ \
for (head = *(ring)->cq.khead; \
(cqe = (head != io_uring_smp_load_acquire((ring)->cq.ktail) \
? &(ring)->cq.cqes[head & (*(ring)->cq.kring_mask)] \
: NULL)); \
head++)
/*
* Must be called after io_uring_for_each_cqe()
*/
static inline void io_uring_cq_advance(struct io_uring *ring, unsigned nr) {
if (nr) {
struct io_uring_cq *cq = &ring->cq;
/*
* Ensure that the kernel only sees the new value of the head
* index after the CQEs have been read.
*/
io_uring_smp_store_release(cq->khead, *cq->khead + nr);
}
}
/*
* Must be called after io_uring_{peek,wait}_cqe() after the cqe has
* been processed by the application.
*/
static void io_uring_cqe_seen(struct io_uring *ring, struct io_uring_cqe *cqe) {
if (cqe)
io_uring_cq_advance(ring, 1);
}
#endif

View File

@ -46,6 +46,14 @@
#include <sys/stat.h>
#include <sys/types.h>
#include "netty_unix_buffer.h"
#include "netty_unix_errors.h"
#include "netty_unix_filedescriptor.h"
#include "netty_unix_jni.h"
#include "netty_unix_limits.h"
#include "netty_unix_socket.h"
#include "netty_unix_util.h"
static jmethodID ringBufferMethodId = NULL;
static jmethodID ioUringSubmissionQueueMethodId = NULL;
static jmethodID ioUringCommpletionQueueMethodId = NULL;
@ -223,12 +231,34 @@ JNIEXPORT jint JNI_OnLoad(JavaVM *vm, void *reserved) {
dlinfo.dli_fname);
return JNI_ERR;
}
if (netty_unix_util_register_natives(env, packagePrefix,
"io/netty/channel/uring/Native",
method_table, method_table_size) != 0) {
printf("netty register natives error\n");
}
// Load all c modules that we depend upon
if (netty_unix_limits_JNI_OnLoad(env, packagePrefix) == JNI_ERR) {
goto done;
}
if (netty_unix_errors_JNI_OnLoad(env, packagePrefix) == JNI_ERR) {
goto done;
}
if (netty_unix_filedescriptor_JNI_OnLoad(env, packagePrefix) == JNI_ERR) {
goto done;
}
if (netty_unix_socket_JNI_OnLoad(env, packagePrefix) == JNI_ERR) {
goto done;
}
if (netty_unix_buffer_JNI_OnLoad(env, packagePrefix) == JNI_ERR) {
goto done;
}
NETTY_PREPEND(packagePrefix, "io/netty/channel/uring/RingBuffer",
nettyClassName, done);
NETTY_LOAD_CLASS(env, ringBufferClass, nettyClassName, done);

View File

@ -8,32 +8,6 @@
#include <sys/uio.h>
#include <unistd.h>
#ifdef __alpha__
/*
* alpha is the only exception, all other architectures
* have common numbers for new system calls.
*/
#ifndef __NR_io_uring_setup
#define __NR_io_uring_setup 535
#endif
#ifndef __NR_io_uring_enter
#define __NR_io_uring_enter 536
#endif
#ifndef __NR_io_uring_register
#define __NR_io_uring_register 537
#endif
#else /* !__alpha__ */
#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
#endif
int sys_io_uring_register(int fd, unsigned opcode, const void *arg,
unsigned nr_args) {
return syscall(__NR_io_uring_register, fd, opcode, arg, nr_args);

View File

@ -7,7 +7,6 @@
/*
* System calls
*/
// extern int sys_io_uring_setup(unsigned entries, struct io_uring_params *p);
extern int sys_io_uring_setup(unsigned entries, struct io_uring_params *p);
extern int sys_io_uring_enter(int fd, unsigned to_submit, unsigned min_complete,
unsigned flags, sigset_t *sig);