Repository: netty/netty
File: transport-classes-io_uring/src/main/java/io/netty/channel/uring/Native.java (Java)

Code before:

    static void checkAllIOSupported(int ringFd) {
        if (!ioUringProbe(ringFd, REQUIRED_IORING_OPS)) {
            throw new UnsupportedOperationException("Not all operations are supported: "
                    + Arrays.toString(REQUIRED_IORING_OPS));
        }
    }

    static boolean isIOUringCqeFSockNonEmptySupported(int ringFd) {
        // IORING_OP_SOCKET was added in the same release (5.19);
        return ioUringProbe(ringFd, new int[] { Native.IORING_OP_SOCKET });
    }

    static boolean isIOUringSupportSplice(int ringFd) {
        // IORING_OP_SPLICE Available since 5.7
        return ioUringProbe(ringFd, new int[] { Native.IORING_OP_SPLICE });
    }

    static void checkKernelVersion(String kernelVersion) {
        boolean enforceKernelVersion = SystemPropertyUtil.getBoolean(
                "io.netty5.transport.iouring.enforceKernelVersion", true);
        boolean kernelSupported = checkKernelVersion0(kernelVersion);
        if (!kernelSupported) {
            if (enforceKernelVersion) {
                throw new UnsupportedOperationException(
                        "you need at least kernel version 5.9, current kernel version: " + kernelVersion);
            } else {
                logger.debug("Detected kernel " + kernelVersion + " does not match minimum version of 5.9, " +
                        "trying to use io_uring anyway");
            }
        }
    }

    private static boolean checkKernelVersion0(String kernelVersion) {
        String[] versionComponents = kernelVersion.split("\\.");
        if (versionComponents.length < 3) {
            return false;
        }

        int major;
        try {
            major = Integer.parseInt(versionComponents[0]);
        } catch (NumberFormatException e) {
            return false;
        }

        if (major <= 4) {
            return false;
        }
        if (major > 5) {
            return true;

Review comment (suggestion):
```suggestion
        int result = ioUringRegisterIoWqMaxWorkers(ringFd, 0, 0);
```

Code after:

    static void checkAllIOSupported(int ringFd) {
        if (!ioUringProbe(ringFd, REQUIRED_IORING_OPS)) {
            throw new UnsupportedOperationException("Not all operations are supported: "
                    + Arrays.toString(REQUIRED_IORING_OPS));
        }
    }

    static boolean isIOUringCqeFSockNonEmptySupported(int ringFd) {
        // IORING_OP_SOCKET was added in the same release (5.19);
        return ioUringProbe(ringFd, new int[] { Native.IORING_OP_SOCKET });
    }

    static boolean isIOUringSupportSplice(int ringFd) {
        // IORING_OP_SPLICE Available since 5.7
        return ioUringProbe(ringFd, new int[] { Native.IORING_OP_SPLICE });
    }

    /**
     * check current kernel version whether support io_uring_register_io_wq_worker
     * Available since 5.15.
     * @return true if support io_uring_register_io_wq_worker
     */
    static boolean isRegisterIOWQWorkerSupported(int ringFd) {
        // See https://github.com/torvalds/linux/blob/v5.5/fs/io_uring.c#L5488C10-L5488C16
        int result = ioUringRegisterIoWqMaxWorkers(ringFd, 0, 0);
        if (result >= 0) {
            return true;
        }
        // This is not supported and so will return -EINVAL
        return false;
    }

    static void checkKernelVersion(String kernelVersion) {
        boolean enforceKernelVersion = SystemPropertyUtil.getBoolean(
                "io.netty.transport.iouring.enforceKernelVersion", true);
        boolean kernelSupported = checkKernelVersion(kernelVersion, 5, 9);
        if (!kernelSupported) {
            if (enforceKernelVersion) {
                throw new UnsupportedOperationException(
                        "you need at least kernel version 5.9, current kernel version: " + kernelVersion);
            } else {
                logger.debug("Detected kernel " + kernelVersion + " does not match minimum version of 5.9, " +
                        "trying to use io_uring anyway");
            }
        }
    }

    private static boolean checkKernelVersion(String kernelVersion, int major, int minor) {
        String[] versionComponents = kernelVersion.split("\\.");
        if (versionComponents.length < 3) {